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
|
private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e) {
int good = 0 , bad = 0;
bool diffwasfound = false;
std::string mydiff1 , mydiff2;
long filespos = 0;
long file1size = 0 , file2size = 0;
char temp1c , temp2c , next1c , next2c;
System::String ^ fileText1 = textBox1->Text;
System::String ^ fileText2 = textBox2->Text;
std::string converted_fileText1 = msclr::interop::marshal_as< std::string >(fileText1);
std::string converted_fileText2 = msclr::interop::marshal_as< std::string >(fileText2);
FILE * myfile1 = fopen ( converted_fileText1.c_str() ,"rb");
FILE * myfile2 = fopen ( converted_fileText2.c_str() ,"rb");
if (myfile1 == NULL || myfile2 == NULL){MessageBox::Show("Can't open file or files");Application::Exit();}
fseek (myfile1 , 0 , SEEK_END);
fseek (myfile2 , 0 , SEEK_END);
file1size = ftell (myfile1);
file2size = ftell (myfile2);
rewind (myfile1);
rewind (myfile2);
if (file1size != file2size){MessageBox::Show("Files are NOT the same size");Application::Exit();}
if (myfile1 == NULL || myfile2 == NULL){MessageBox::Show("Can't open file or files");Application::Exit();}
else {
String^ my1 = gcnew String(mydiff1.c_str());
String^ my2 = gcnew String(mydiff2.c_str());
listBox1->BeginUpdate();
listBox2->BeginUpdate();
while (temp1c != EOF || temp2c != EOF){
fseek (myfile1,filespos,SEEK_SET);
fseek (myfile2,filespos,SEEK_SET);
temp1c = fgetc (myfile1);
temp2c = fgetc (myfile2);
fseek (myfile1,filespos+1,SEEK_SET);
fseek (myfile2,filespos+1,SEEK_SET);
next1c = fgetc (myfile1);
next2c = fgetc (myfile2);
if (next1c == next2c && diffwasfound == true){
diffwasfound = false;
my1 = gcnew String(mydiff1.c_str());
my2 = gcnew String(mydiff2.c_str());
listBox1->Items->Add( String::Format("{0} ", my1) );
listBox2->Items->Add( String::Format("{0} ", my2) );
mydiff1 = std::string();
mydiff2 = std::string();
my1 = gcnew String(mydiff1.c_str());
my2 = gcnew String(mydiff2.c_str());
}
if (temp1c != temp2c){
diffwasfound = true;
mydiff1 += temp1c;
mydiff2 += temp2c;
filespos++;
}
if (temp1c == temp2c){
diffwasfound = false;
filespos++;
}
}
listBox1->EndUpdate();
listBox2->EndUpdate();
fclose(myfile1);
fclose(myfile2);
}
}
|