1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
|
#include<iostream>
#include<fstream>
using namespace std;
const int SIZE=4096;//4KB
unsigned long int File_Size(ifstream& ifile);
short int ProgreSS_PerCeNT(unsigned long int i,unsigned long fsize);
int INTEGER_TRANSFORMATION(char system_number[]);
main()
{
ifstream in_file;
ofstream out_file;
unsigned long int fsize;
short int count=0;
char source_driver;
int c=0;
short int count1=48,count2=48,count3=48,count4=48,count5=49;
int partial=0;
char str_partial[8];
char destination_file[52];
do
{
fflush(stdin);
cout<<"Give parts:";
cin.get( str_partial , 7 );
partial=INTEGER_TRANSFORMATION( str_partial );
}while( partial==-1 );//--controls if the number of parts is greater that 0
fflush(stdin);
cout<<"Give the driver of the parts:";
cin>>source_driver;//--for WindowS only
char source_file[14]={source_driver,':','\\','p','a','r','t','_',count1,count2,count3,count4,count5,'\0'};
fflush(stdin);// cin.ignore(4096,'\n'); for LinuX
cout<<"Give the destination file (up to 50 character):";
cin.get( destination_file , 51 );
int STEP=1;
fflush(stdin);
cout<<"Give progress STEP:";
cin>>STEP;
out_file.open(destination_file,ios::binary);
if( !out_file.is_open() )
{
cerr<<"\nERROR with file destination:["<<destination_file<<"]"<<endl;
for(int i=0; i<5; i++)
{
cerr<<"********************************************************"<<endl;
}
cerr<<"******************PROGRAM TERMINATED********************\n";
exit(1);
}
system("cls");//syste("clear"); for LinuX
cout<<"-------------PLeaSE WaiTE----------------\n"<<endl;
char buf[SIZE];
unsigned long int b=SIZE;
for(int i=0; i<partial; i++)//--KERNEl LOOP
{
source_file[8]=count1;
source_file[9]=count2;
source_file[10]=count3;
source_file[11]=count4;
source_file[12]=count5;
count5++;
if( count5==58 )
{
count5=48;
count4++;
if( count4==58 )
{
count4=48;
count3++;
if( count3==58 )
{
count3=48;
count2++;
if( count2==58 )
{
count2=48;
count1++;
}
}
}
}
in_file.open(source_file,ios::binary);
if( !in_file.is_open() )
{
cerr<<"\nERROR with the part:["<<source_file<<"]---probably NOT FOUND"<<endl;
for(int i=0; i<5; i++)
{
cerr<<"********************************************************"<<endl;
}
cerr<<"******************PROGRAM TERMINATED********************\n";
exit(1);
}
fsize=File_Size(in_file);
cout<<"--copying ["<<source_file<<"] size:"<<fsize<<"bytes to ["<<destination_file<<"] progress -- 0% ";
b=SIZE;
int k=b;
for(unsigned long int j=0; j<fsize; j+=b)
{
/***********************/
/**********************/
if(fsize-j<SIZE)
{
b=fsize-j;
}
in_file.read(buf,b);
out_file.write(buf,b);
/***********************/
/***********************/
short int p=ProgreSS_PerCeNT(j,fsize);
if( p==count )
{
system("cls");
cout<<"-------------PLeaSE WaiTE----------------\n"<<endl;
cout<<"--copying ["<<source_file<<"] size:"<<fsize<<"bytes to ["<<destination_file<<"] progress --"<<p<<"%";
count+=STEP;
}
}
in_file.close();
system("cls");
cout<<"-------------PLeaSE WaiTE----------------\n"<<endl;
cout<<"--copying ["<<source_file<<"] size:"<<fsize<<"bytes to ["<<destination_file<<"] progress --100% ";
cout<<" ---***COMPLETED---***"<<endl;
count=0;
}//end of for
cout<<"\nTOTAL SIZE OF new file=>["<<destination_file<<"]: "<<out_file.tellp()<<"bytes."<<endl;
cout<<"count:"<<count<<endl;
out_file.close();
cout<<"\n\n------------------program ended successfully----------------------\n"<<endl;
system("pause");
}//end of main
/////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
unsigned long int File_Size(ifstream& ifile)
{
ifile.seekg(0,ios::end);
unsigned long int fsize=ifile.tellg();
ifile.seekg(0,ios::beg);
return fsize;
}
//#########################################################
//########################################################
short int ProgreSS_PerCeNT(unsigned long int i,unsigned long fsize)
{
short int percent=0;
float p;
if( i>0 )
{
p=(float)fsize/(float)i;
percent=100/p;
return percent;
}
}
/****************************************************************************/
/***************************************************************************/
int INTEGER_TRANSFORMATION(char system_number[])
{
int sum=0;
for(int i=0; system_number[i]!='\0'; i++)
{
if( (i==0 && system_number[i]==48) || system_number[i]<48 || system_number[i]>57 )
{
return -1;
}
}
sum=atoi(system_number);
return sum;
}
|