Originally committed to SVN as r2450.

This commit is contained in:
Rodrigo Braz Monteiro 2008-11-11 04:10:20 +00:00
parent d8a85d0118
commit 7a9c85d577
3 changed files with 51 additions and 10 deletions

View File

@ -94,6 +94,7 @@ public:
controller->LoadFile(fileFolder+"out_test1.ass","UTF-8");
CPPUNIT_ASSERT_NO_THROW(controller->SaveFile(fileFolder+"out_test2.ass","UTF-8"));
CPPUNIT_ASSERT(AreFilesIdentical(fileFolder+"out_test1.ass",fileFolder+"out_test2.ass"));
CPPUNIT_ASSERT(AreFilesIdentical(fileFolder+"in_test1.ass",fileFolder+"out_test1.ass") == false);
}
};

View File

@ -33,14 +33,42 @@
// Contact: mailto:zeratul@cellosoft.com
//
#include <wx/wxprec.h>
#include <fstream>
#include <iostream>
#include "utils.h"
#include "../../aegisub/md5.h"
bool AreFilesIdentical(std::string file1, std::string file2)
{
return GetFileMD5(file1) == GetFileMD5(file2);
std::string f1 = GetFileMD5(file1);
std::string f2 = GetFileMD5(file2);
return f1 == f2;
}
std::string GetFileMD5(std::string file) {
md5_state_s md5;
md5_byte_t digest[16];
const size_t toRead = 512;
md5_byte_t data[toRead];
std::ifstream fp(file.c_str());
if (fp.is_open()) {
md5_init(&md5);
while (!fp.eof()) {
fp.read((char*)data,toRead);
size_t n = fp.gcount();
md5_append(&md5,data,n);
}
md5_finish(&md5,digest);
unsigned int *res = (unsigned int*) digest;
return std::string(wxString::Format(_T("%08X%08X%08X%08X"),res[0],res[1],res[2],res[3]).mb_str(wxConvUTF8));
}
else {
return "";
}
}

View File

@ -176,14 +176,6 @@
RelativePath=".\src\suites.h"
>
</File>
<File
RelativePath=".\src\utils.cpp"
>
</File>
<File
RelativePath=".\src\utils.h"
>
</File>
</Filter>
<Filter
Name="Athenasub"
@ -201,6 +193,26 @@
>
</File>
</Filter>
<Filter
Name="Utils"
>
<File
RelativePath="..\aegisub\md5.c"
>
</File>
<File
RelativePath="..\aegisub\md5.h"
>
</File>
<File
RelativePath=".\src\utils.cpp"
>
</File>
<File
RelativePath=".\src\utils.h"
>
</File>
</Filter>
</Files>
<Globals>
</Globals>