void LocalizationTest::TestFunction(TestTemplate<LocalizationTest>::PerfFuncData *data) { FilePath srcFile = srcDir + (files[currentTest] + ".yaml"); FilePath cpyFile = cpyDir + (files[currentTest] + ".yaml"); FileSystem::Instance()->CopyFile(srcFile, cpyFile); LocalizationSystem* localizationSystem = LocalizationSystem::Instance(); localizationSystem->SetCurrentLocale(files[currentTest]); localizationSystem->InitWithDirectory(cpyDir); localizationSystem->SaveLocalizedStrings(); localizationSystem->Cleanup(); bool res = CompareFiles(srcFile, cpyFile); String s = Format("Localization test %d: %s - %s", currentTest, files[currentTest].c_str(), (res ? "passed" : "fail")); Logger::Debug(s.c_str()); data->testData.message = s; TEST_VERIFY(res); ++currentTest; }
void Finalise(const StringData &data) { /* Find the plural form with the most amount of cases. */ int max_plural_forms = 0; for (uint i = 0; i < lengthof(_plural_forms); i++) { max_plural_forms = max(max_plural_forms, _plural_forms[i].plural_count); } fprintf(this->fh, "\n" "static const uint LANGUAGE_PACK_VERSION = 0x%X;\n" "static const uint LANGUAGE_MAX_PLURAL = %d;\n" "static const uint LANGUAGE_MAX_PLURAL_FORMS = %d;\n\n", (uint)data.Version(), (uint)lengthof(_plural_forms), max_plural_forms ); fprintf(this->fh, "#endif /* TABLE_STRINGS_H */\n"); this->FileWriter::Finalise(); if (CompareFiles(this->filename, this->real_filename)) { /* files are equal. tmp.xxx is not needed */ unlink(this->filename); } else { /* else rename tmp.xxx into filename */ #if defined(WIN32) || defined(WIN64) unlink(this->real_filename); #endif if (rename(this->filename, this->real_filename) == -1) error("rename() failed"); } }
void ValidateBaselineFiles(const char* anIndexFilename) { fstream theIndexFile(anIndexFilename,ios::in | ios::nocreate); char theFilename[500]; char theBaselineFilename[500]; char theTempFilename[500]; PRBool done=PR_FALSE; ComputeTempFilename(anIndexFilename,theTempFilename); while(!done) { theIndexFile >> theFilename; theIndexFile >> theBaselineFilename; if(theFilename[0] && theBaselineFilename[0]) { if(NS_SUCCEEDED(GenerateBaselineFile(theFilename,theTempFilename))) { PRBool matches=CompareFiles(theTempFilename,theBaselineFilename); cout << theFilename << kResultMsg[matches] << endl; } } theFilename[0]=0; theBaselineFilename[0]=0; done=PRBool(theIndexFile.ipfx(1)==0); } // Now it's time to compare our output to the baseline... // if(!CompareFiles(aBaselineFilename,aBaselineFilename)){ // cout << "File: \"" << aSourceFilename << "\" does not match baseline." << endl; // } }
//------------------------------------------------------------- // Directory and file comparison engine //------------------------------------------------------------- VOID CompareHeadFiles(LPHEADFILE lpStartHF1, LPHEADFILE lpStartHF2) { LPHEADFILE lpHF1; LPHEADFILE lpHF2; LPFILECONTENT lpFC; // first loop for (lpHF1 = lpStartHF1; NULL != lpHF1; lpHF1 = lpHF1->lpBrotherHF) { // Check that first file name present if (NULL == lpHF1->lpFirstFC) { continue; } if (NULL == lpHF1->lpFirstFC->lpszFileName) { continue; } // Get corresponding headfile in second shot lpHF2 = SearchDirChain(lpHF1->lpFirstFC->lpszFileName, lpStartHF2); lpFC = NULL; if (NULL != lpHF2) { lpHF2->fHeadFileMatch = ISMATCH; lpFC = lpHF2->lpFirstFC; } CompareFiles(lpHF1->lpFirstFC, lpFC); } // second loop, only those that did not match before for (lpHF2 = lpStartHF2; NULL != lpHF2; lpHF2 = lpHF2->lpBrotherHF) { // Check that not compared in first loop if (NOMATCH != lpHF2->fHeadFileMatch) { continue; } // Check that first file name present if (NULL == lpHF2->lpFirstFC) { continue; } if (NULL == lpHF2->lpFirstFC->lpszFileName) { continue; } // Check that there's no corresponding headfile in first shot lpHF1 = SearchDirChain(lpHF2->lpFirstFC->lpszFileName, lpStartHF1); if (NULL == lpHF1) { CompareFiles(NULL, lpHF2->lpFirstFC); } } }
void UnitTestUtil::CheckOutput( const char* masterFileName, const char* outFileName ) { if ( CompareFiles( masterFileName, outFileName ) != 0 ) { char buffer[5000]; sprintf( buffer, "Output file %s differs from expected output file %s", outFileName, masterFileName ); CPPUNIT_FAIL (buffer); } }
///Gets the input file (if any) ///Runs the histogram application by giving this file as input ///compares the result files with expected outputs in the given path bool RunTestsUnderDirectory(std::string dirPath) { std::ifstream expectedErrorsStream; std::ifstream expectedOutputStream; //trying to open expected_errors file std::string expectedErrorsPath = dirPath + "/expected_errors.txt"; expectedErrorsStream.open(expectedErrorsPath); if (!expectedErrorsStream.is_open() || !expectedErrorsStream.good()) { return false; } //trying to open expected output file std::string expectedOutputPath = dirPath + "/expected_output.txt"; expectedOutputStream.open(expectedOutputPath); if (!expectedOutputStream.is_open() || !expectedOutputStream.good()) { return false; } //running the application with input.txt under given folder FileHistogramApplicationCls<float>* app = new FileHistogramApplicationCls<float>(dirPath + "/input.txt"); app->CreateAndReportHistogram(); delete app; std::string receivedErrorsPath = dirPath + "/received_errors.txt"; std::string receivedOutputPath = dirPath + "/received_output.txt"; CopyFileToTestDirectory("error.txt", receivedErrorsPath); CopyFileToTestDirectory("output.txt", receivedOutputPath); //compares outputs with expected results bool hasTestPassed = CompareFiles(receivedErrorsPath, expectedErrorsPath) && CompareFiles(receivedOutputPath, expectedOutputPath); //prints the test results std::cout << "Test result for input under " << dirPath << " is " << (hasTestPassed ? "PASS" : "FAIL") << std::endl; return true; }
void TestXMLProperties::TestConstructionNoFile() { try { XMLProperties xmlProperties(TEST_RESULT_NEW_FILE); } catch(...) { throw CppUnitException(L"Failed to construct the XMLProperties class"); } assertMessage(true == CompareFiles(TEST_NEW_FILE, TEST_RESULT_NEW_FILE), L"The properties file was not created correctly"); }
HRESULT CompareFilesForOnlineChange(LPCTSTR pszFile1, LPCTSTR pszFile2) // Forbid changes in task structure // S_OK = identical, S_FALSE = not identical { TCHAR* tmp; int AllowChangesInField = 1; tmp = _tcsrchr(pszFile1, _T('\\')); if(_tcscmp(tmp, _T("\\retain.4pl")) == 0) return CompareFiles(pszFile1, pszFile2); if(_tcscmp(tmp, _T("\\__custdl.bin")) == 0) return CompareFiles(pszFile1, pszFile2); // TODO: check here all the conditions for online change // pszFile2 is old version of __common.hdr // pszFile1 is new version of __common.hdr // binary compare is not enough because the file contains also // the number of objects (which is allowed to change) return S_OK; }
bool Install() { char installPath[MAX_PATH]; sprintf(installPath,"%s\\DropboxFilter",getenv("ProgramFiles")); char exePath[MAX_PATH]; sprintf(exePath,"%s\\DropboxFilter.exe",installPath); char dllPath[MAX_PATH]; sprintf(dllPath,"%s\\DropboxFilter.dll",installPath); char currExePath[MAX_PATH]; GetModuleFileNameA(NULL,currExePath,sizeof(currExePath)); if(CompareFiles(exePath,currExePath)) { return true; } char msg[1024*10]; sprintf(msg,"First we need to install the DropboxFilter executable and DLL into a program files directory.\n\nWhen you press OK the following will be done.\n\n1. The dropbox process will be terminated\n2. A directory %s will be created.\n3. Executable will be copied to\n\t%s\n4. Dll will be copied to\n\t%s",installPath,exePath,dllPath); if(MessageBox(NULL,msg,"Install",MB_OKCANCEL) != IDOK) { return false; } DWORD id = FindProcessIdByName("dropbox.exe"); if(id) { HANDLE hProcess = OpenProcess(PROCESS_TERMINATE,FALSE,id); if(hProcess != NULL) { TerminateProcess(hProcess,0); CloseHandle(hProcess); } } CreateDirectory(installPath,NULL); if(!CopyFileA(currExePath,exePath,FALSE)) { MessageBox(NULL,"Failed to install executable to Program Files directory.","Failed",MB_OK); return false; } FILE *file = fopen(dllPath,"wb"); int written; HRSRC hResource; if(file) { hResource = FindResource(NULL,"ID_DLL","DLL"); void *resource = LockResource(LoadResource(NULL,hResource)); written = fwrite(resource,1,SizeofResource(NULL,hResource),file); fclose(file); } if(file == NULL || written != SizeofResource(NULL,hResource)) { MessageBox(NULL,"Failed to install dll to Program Files directory.\nYou migh have to run this installer with Administrator privilegies\n\nExit installer right click on installer executable and choose run as administrator.","Failed",MB_OK); } return true; }
static int CompareFolderRefs(const int *p1, const int *p2, void *param) { int i1 = *p1; int i2 = *p2; const CArchiveDatabaseEx &db = *(const CArchiveDatabaseEx *)param; RINOZ(CompareFolders( db.Folders[i1], db.Folders[i2])); RINOZ(MyCompare( db.NumUnPackStreamsVector[i1], db.NumUnPackStreamsVector[i2])); if (db.NumUnPackStreamsVector[i1] == 0) return 0; return CompareFiles( db.Files[db.FolderStartFileIndex[i1]], db.Files[db.FolderStartFileIndex[i2]]); }
int CompareCmd(const vector<string>& args) { if (args.size() != 3) { cerr << args[0] << ": wrong number of arguments" << endl; return 1; } size_t offset = 0; if (!CompareFiles(args[1], args[2], offset)) { cerr << args[0] << ": compare failed" << endl; return 1; } return 0; }
//------------------------------------------------------------- // File comparison engine //------------------------------------------------------------- VOID CompareFiles(LPFILECONTENT lpStartFC1, LPFILECONTENT lpStartFC2) { LPFILECONTENT lpFC1; LPFILECONTENT lpFC2; // Compare dirs/files for (lpFC1 = lpStartFC1; NULL != lpFC1; lpFC1 = lpFC1->lpBrotherFC) { if (ISFILE(lpFC1->nFileAttributes)) { CompareResult.stcCompared.cFiles++; } else { CompareResult.stcCompared.cDirs++; } // Find a matching dir/file for FC1 for (lpFC2 = lpStartFC2; NULL != lpFC2; lpFC2 = lpFC2->lpBrotherFC) { // skip FC2 if already matched if (NOMATCH != lpFC2->fFileMatch) { continue; } // skip FC2 if types do *not* match (even if same name then interpret as deleted+added) if (ISFILE(lpFC1->nFileAttributes) != ISFILE(lpFC2->nFileAttributes)) { continue; } // skip FC2 if names do *not* match if ((NULL == lpFC1->lpszFileName) || (NULL == lpFC2->lpszFileName) || (0 != _tcsicmp(lpFC1->lpszFileName, lpFC2->lpszFileName))) { // 1.8.2 from lstrcmp to strcmp // 1.9.0 to _tcsicmp continue; } // Same file type and (case-insensitive) name of FC1 found in FC2, so compare their attributes and if applicable their dates and sizes if (ISFILE(lpFC1->nFileAttributes)) { // Both are files if ((lpFC1->nWriteDateTimeLow == lpFC2->nWriteDateTimeLow) && (lpFC1->nWriteDateTimeHigh == lpFC2->nWriteDateTimeHigh) && (lpFC1->nFileSizeLow == lpFC2->nFileSizeLow) && (lpFC1->nFileSizeHigh == lpFC2->nFileSizeHigh) && (lpFC1->nFileAttributes == lpFC2->nFileAttributes)) { // Same file of FC1 found in FC2 lpFC2->fFileMatch = ISMATCH; } else { // File data differ, so file is modified lpFC2->fFileMatch = ISMODI; CompareResult.stcChanged.cFiles++; CompareResult.stcModified.cFiles++; CreateNewResult(FILEMODI, lpFC1, lpFC2); } } else { // Both are dirs if (lpFC1->nFileAttributes == lpFC2->nFileAttributes) { // Same dir of FC1 found in FC2 lpFC2->fFileMatch = ISMATCH; } else { // Dir data differ, so dir is modified lpFC2->fFileMatch = ISMODI; CompareResult.stcChanged.cDirs++; CompareResult.stcModified.cDirs++; CreateNewResult(DIRMODI, lpFC1, lpFC2); } // Compare sub files if any if ((NULL != lpFC1->lpFirstSubFC) || (NULL != lpFC2->lpFirstSubFC)) { CompareFiles(lpFC1->lpFirstSubFC, lpFC2->lpFirstSubFC); } } break; } if (NULL == lpFC2) { // FC1 has no matching FC2, so FC1 is a deleted dir/file if (ISFILE(lpFC1->nFileAttributes)) { CompareResult.stcChanged.cFiles++; CompareResult.stcDeleted.cFiles++; CreateNewResult(FILEDEL, lpFC1, NULL); } else { CompareResult.stcChanged.cDirs++; CompareResult.stcDeleted.cDirs++; CreateNewResult(DIRDEL, lpFC1, NULL); // "Compare"/Log sub files if any if (NULL != lpFC1->lpFirstSubFC) { CompareFiles(lpFC1->lpFirstSubFC, NULL); } } } } // After looping all FC1 files, do an extra loop over all FC2 files and check previously set match flags to determine added dirs/files for (lpFC2 = lpStartFC2; NULL != lpFC2; lpFC2 = lpFC2->lpBrotherFC) { // skip FC2 if already matched if (NOMATCH != lpFC2->fFileMatch) { continue; } // FC2 has no matching FC1, so FC2 is an added dir/file if (ISFILE(lpFC2->nFileAttributes)) { CompareResult.stcCompared.cFiles++; CompareResult.stcChanged.cFiles++; CompareResult.stcAdded.cFiles++; CreateNewResult(FILEADD, NULL, lpFC2); } else { CompareResult.stcCompared.cDirs++; CompareResult.stcChanged.cDirs++; CompareResult.stcAdded.cDirs++; CreateNewResult(DIRADD, NULL, lpFC2); // "Compare"/Log sub files if any if (NULL != lpFC2->lpFirstSubFC) { CompareFiles(NULL, lpFC2->lpFirstSubFC); } } } }
void TestCompareFunction() { CPPUNIT_ASSERT_MESSAGE("Checking if csv-file reader is working properly", CompareFiles(pathRead)); //CPPUNIT_ASSERT_MESSAGE("Asserting that compare function for files works correctly - Negative Test", ! CompareFiles(pathWrong) ); }
/** * And the main program (what else?) * @param argc Number of command-line arguments including the program name itself. * @param argv Vector of the command-line arguments. */ int CDECL main(int argc, char *argv[]) { const char *output_file = NULL; const char *before_file = NULL; const char *after_file = NULL; GetOptData mgo(argc - 1, argv + 1, _opts); for (;;) { int i = mgo.GetOpt(); if (i == -1) break; switch (i) { case 'v': puts("$Revision$"); return 0; case 'h': puts("settingsgen - $Revision$\n" "Usage: settingsgen [options] ini-file...\n" "with options:\n" " -v, --version Print version information and exit\n" " -h, -?, --help Print this help message and exit\n" " -b FILE, --before FILE Copy FILE before all settings\n" " -a FILE, --after FILE Copy FILE after all settings\n" " -o FILE, --output FILE Write output to FILE\n"); return 0; case 'o': output_file = mgo.opt; break; case 'a': after_file = mgo.opt; break; case 'b': before_file = mgo.opt; break; case -2: fprintf(stderr, "Invalid arguments\n"); return 1; } } _stored_output.Clear(); for (int i = 0; i < mgo.numleft; i++) ProcessIniFile(mgo.argv[i]); /* Write output. */ if (output_file == NULL) { CopyFile(before_file, stdout); _stored_output.Write(stdout); CopyFile(after_file, stdout); } else { static const char * const tmp_output = "tmp2.xxx"; FILE *fp = fopen(tmp_output, "w"); if (fp == NULL) { fprintf(stderr, "settingsgen: Warning: Cannot open file %s\n", tmp_output); return 1; } CopyFile(before_file, fp); _stored_output.Write(fp); CopyFile(after_file, fp); fclose(fp); if (CompareFiles(tmp_output, output_file)) { /* Files are equal. tmp2.xxx is not needed. */ unlink(tmp_output); } else { /* Rename tmp2.xxx to output file. */ #if defined(WIN32) || defined(WIN64) unlink(output_file); #endif if (rename(tmp_output, output_file) == -1) error("rename() failed"); } } return 0; }
int CompareResult(char *sample, char *result) { return CompareFiles(sample, result); }
/* * ======================================================================= * * In the startup of this program, we look at our executable name and * * replace the ".EXE" with ".DLL" to find the ISAPI DLL we need to load. * * This means that the executable need only be given the same "name" as * * the DLL to load. There is no recompilation required. * * ======================================================================= * */ BOOL stress_main(const char *filename, const char *arg, const char *postdata, const char *matchdata) { EXTENSION_CONTROL_BLOCK ECB; DWORD rc; TIsapiContext context; // open output and input files context.tid = GetCurrentThreadId(); CString fname; fname.Format("%08X.out", context.tid); context.out = CreateFile(fname, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_FLAG_WRITE_THROUGH, NULL); if (context.out==INVALID_HANDLE_VALUE) { printf("failed to open output file %s\n", fname); return 0; } // not using post files context.in = INVALID_HANDLE_VALUE; // // Fill the ECB with the necessary information // if (!FillExtensionControlBlock(&ECB, &context) ) { fprintf(stderr,"Fill Ext Block Failed\n"); return -1; } // check for command line argument, // first arg = filename // this is added for testing php from command line context.env.RemoveAll(); context.env["PATH_TRANSLATED"]= filename; context.env["SCRIPT_MAP"]= filename; context.env["CONTENT_TYPE"]= ""; context.env["CONTENT_LENGTH"]= ""; context.env["QUERY_STRING"]= arg; context.env["METHOD"]="GET"; context.env["PATH_INFO"] = ""; context.waitEvent = CreateEvent(NULL, FALSE, FALSE, NULL); char buf[MAX_PATH]; if (postdata && *postdata !=0) { ECB.cbAvailable = strlen(postdata); ECB.cbTotalBytes = ECB.cbAvailable; ECB.lpbData = (unsigned char *)postdata; context.env["METHOD"]="POST"; _snprintf(buf, sizeof(buf)-1, "%d", ECB.cbTotalBytes); context.env["CONTENT_LENGTH"]=buf; context.env["CONTENT_TYPE"]="application/x-www-form-urlencoded"; } ECB.lpszMethod = strdup(context.env["METHOD"]); ECB.lpszPathTranslated = strdup(filename); ECB.lpszQueryString = strdup(arg); ECB.lpszPathInfo = strdup(context.env["PATH_INFO"]); // Call the DLL // rc = IsapiHttpExtensionProc(&ECB); if (rc == HSE_STATUS_PENDING) { // We will exit in ServerSupportFunction WaitForSingleObject(context.waitEvent, INFINITE); } CloseHandle(context.waitEvent); //Sleep(75); free(ECB.lpszPathTranslated); free(ECB.lpszQueryString); free(ECB.lpszMethod); free(ECB.lpszPathInfo); BOOL ok = TRUE; if (context.out != INVALID_HANDLE_VALUE) CloseHandle(context.out); // compare the output with the EXPECT section if (matchdata && *matchdata != 0) { ok = CompareFiles(fname, matchdata); } DeleteFile(fname); return ok; }
void TestXMLProperties::TestCreateNewProperty() { XMLProperties xmlProperties(TEST_RESULT_FILE); xmlProperties.SetProperty(L"Housten", L"Texas"); assertMessage(CompareFiles(TEST_RESULT_FILE, TEST_NEW_PROPERTY), L"The property was not added to the xml file"); }
void TestXMLProperties::TestDeleteProperty() { XMLProperties xmlProperties(TEST_RESULT_FILE); xmlProperties.DeleteProperty(L"SFR_COMPUTER_NAME"); assertMessage(CompareFiles(TEST_RESULT_FILE, TEST_DELETE_PROPERTY), L"The property was not removed from the xml file"); }
bool CComparisonManager::CompareListings() { if (!m_pLeft || !m_pRight) return false; CFilterManager filters; if (filters.HasActiveFilters() && !filters.HasSameLocalAndRemoteFilters()) { m_pState->NotifyHandlers(STATECHANGE_COMPARISON); wxMessageBoxEx(_("Cannot compare directories, different filters for local and remote directories are enabled"), _("Directory comparison failed"), wxICON_EXCLAMATION); return false; } wxString error; if (!m_pLeft->CanStartComparison(&error)) { m_pState->NotifyHandlers(STATECHANGE_COMPARISON); wxMessageBoxEx(error, _("Directory comparison failed"), wxICON_EXCLAMATION); return false; } if (!m_pRight->CanStartComparison(&error)) { m_pState->NotifyHandlers(STATECHANGE_COMPARISON); wxMessageBoxEx(error, _("Directory comparison failed"), wxICON_EXCLAMATION); return false; } const int mode = COptions::Get()->GetOptionVal(OPTION_COMPARISONMODE); duration const threshold = duration::from_minutes( COptions::Get()->GetOptionVal(OPTION_COMPARISON_THRESHOLD) ); m_pLeft->m_pComparisonManager = this; m_pRight->m_pComparisonManager = this; m_isComparing = true; m_pState->NotifyHandlers(STATECHANGE_COMPARISON); m_pLeft->StartComparison(); m_pRight->StartComparison(); wxString localFile, remoteFile; bool localDir = false; bool remoteDir = false; wxLongLong localSize, remoteSize; CDateTime localDate, remoteDate; const int dirSortMode = COptions::Get()->GetOptionVal(OPTION_FILELIST_DIRSORT); const bool hide_identical = COptions::Get()->GetOptionVal(OPTION_COMPARE_HIDEIDENTICAL) != 0; bool gotLocal = m_pLeft->GetNextFile(localFile, localDir, localSize, localDate); bool gotRemote = m_pRight->GetNextFile(remoteFile, remoteDir, remoteSize, remoteDate); while (gotLocal && gotRemote) { int cmp = CompareFiles(dirSortMode, localFile, remoteFile, localDir, remoteDir); if (!cmp) { if (!mode) { const CComparableListing::t_fileEntryFlags flag = (localDir || localSize == remoteSize) ? CComparableListing::normal : CComparableListing::different; if (!hide_identical || flag != CComparableListing::normal || localFile == _T("..")) { m_pLeft->CompareAddFile(flag); m_pRight->CompareAddFile(flag); } } else { if (!localDate.IsValid() || !remoteDate.IsValid()) { if (!hide_identical || localDate.IsValid() || remoteDate.IsValid() || localFile == _T("..")) { const CComparableListing::t_fileEntryFlags flag = CComparableListing::normal; m_pLeft->CompareAddFile(flag); m_pRight->CompareAddFile(flag); } } else { CComparableListing::t_fileEntryFlags localFlag, remoteFlag; int dateCmp = localDate.Compare(remoteDate); if (dateCmp < 0) { localDate += threshold; } else if (dateCmp > 0 ) { remoteDate += threshold; } int adjustedDateCmp = localDate.Compare(remoteDate); if (dateCmp && dateCmp == -adjustedDateCmp) { dateCmp = 0; } localFlag = CComparableListing::normal; remoteFlag = CComparableListing::normal; if (dateCmp < 0 ) { remoteFlag = CComparableListing::newer; } else if (dateCmp > 0) { localFlag = CComparableListing::newer; } if (!hide_identical || localFlag != CComparableListing::normal || remoteFlag != CComparableListing::normal || localFile == _T("..")) { m_pLeft->CompareAddFile(localFlag); m_pRight->CompareAddFile(remoteFlag); } } } gotLocal = m_pLeft->GetNextFile(localFile, localDir, localSize, localDate); gotRemote = m_pRight->GetNextFile(remoteFile, remoteDir, remoteSize, remoteDate); continue; } if (cmp < 0) { m_pLeft->CompareAddFile(CComparableListing::lonely); m_pRight->CompareAddFile(CComparableListing::fill); gotLocal = m_pLeft->GetNextFile(localFile, localDir, localSize, localDate); } else { m_pLeft->CompareAddFile(CComparableListing::fill); m_pRight->CompareAddFile(CComparableListing::lonely); gotRemote = m_pRight->GetNextFile(remoteFile, remoteDir, remoteSize, remoteDate); } } while (gotLocal) { m_pLeft->CompareAddFile(CComparableListing::lonely); m_pRight->CompareAddFile(CComparableListing::fill); gotLocal = m_pLeft->GetNextFile(localFile, localDir, localSize, localDate); } while (gotRemote) { m_pLeft->CompareAddFile(CComparableListing::fill); m_pRight->CompareAddFile(CComparableListing::lonely); gotRemote = m_pRight->GetNextFile(remoteFile, remoteDir, remoteSize, remoteDate); } m_pRight->FinishComparison(); m_pLeft->FinishComparison(); return true; }
void CDupFileFilter::ApplyFilter() { if (m_pDialog->IsSearchStarted()) // Already searching some files? - Then dont do return; { CFilterDuplicateDialog filterDupDialog(mListCtrl); if (filterDupDialog.DoModal() != IDOK) return; m_uFlags = filterDupDialog.m_uFlag; } mFileHash.RemoveAll(); m_pDialog->SetSearchStartedImpl(); m_pDialog->SetStatusMessage(_T("Sorting list...")); int startIndex = 0; if (m_uFlags & DF_MATCH_FILE_SIZE) { startIndex = 2; } else if (m_uFlags & DF_MATCH_PATH) { startIndex = 1; } mListCtrl->SortItemsEx(startIndex, true); if (m_pDialog->IsSearchCancelled()) return; startIndex = 0; int listItemCount = mListCtrl->GetItemCount(); // Skip all directories if (m_uFlags & DF_MATCH_FILE_SIZE) { for (startIndex = 0; startIndex < listItemCount; startIndex++) { if (mListCtrl->GetFileSize(startIndex) >= 0) break; if (m_pDialog->IsSearchCancelled()) return; } listItemCount -= startIndex; } CAutoDisableNotificaltion autoDisableNotification(mListCtrl); CMD5Init::AutoReleaseInstance initMD5; ULONGLONG itemCount(listItemCount); itemCount *= 2; CPercentage percentage(itemCount, FilterDuplicateUpdateCallback, m_pDialog); itemCount = 0; CArray<FileSizeInfo> fileSizeInfoArray; fileSizeInfoArray.SetSize(listItemCount); // Initialize file size array for (int i = 0; i < listItemCount; i++) { fileSizeInfoArray[i].nItem = startIndex + i; CString fileName = mListCtrl->GetItemText(startIndex + i, 0); if (fileName[0] == '*') { fileName.Delete(0); // Remove exisitn astrik mListCtrl->SetItemText(startIndex + i, 0, fileName); } if (m_pDialog->IsSearchCancelled()) return; } // Now start duplicates for (int i = 0; i < listItemCount && !m_pDialog->IsSearchCancelled(); i++) { percentage.Update(itemCount++); FileSizeInfo &fsInfo = fileSizeInfoArray[i]; if (m_uFlags & DF_PRINT_UNIQUE_ONLY) fsInfo.m_uFlag |= FSIF_OUTPUT; bool bHasDuplicate = false; int next; for (next = i+1; next < listItemCount && !m_pDialog->IsSearchCancelled(); next++) { FileSizeInfo &fsInfoNext = fileSizeInfoArray[next]; if (!FilePartialMatch(fsInfo.nItem, fsInfoNext.nItem)) break; if (CompareFiles(fsInfo.nItem, fsInfoNext.nItem) == 0) { fsInfoNext.m_uFlag |= FSIF_ISDUPLICATE; if (!(m_uFlags & DF_PRINT_UNIQUE_ONLY)) fsInfoNext.m_uFlag |= FSIF_OUTPUT; bHasDuplicate = true; } } i = next-1; // Skip all duplicates found if (bHasDuplicate && !(m_uFlags & DF_PRINT_UNIQUE_ONLY)) { // Add '*' astric to indicate duplicates CString fileName = mListCtrl->GetItemText(fsInfo.nItem, 0); fileName = _T("*")+fileName; mListCtrl->SetItemText(fsInfo.nItem, 0, fileName); fsInfo.m_uFlag |= FSIF_OUTPUT; } } mFileHash.RemoveAll(); m_pDialog->SetStatusMessage(_T("Updating list...")); mListCtrl->DisablePaint(true); // Now Updade the List for (int i = 0; i < startIndex && !m_pDialog->IsSearchCancelled(); i++) { mListCtrl->DeleteItem(0); percentage.Update(itemCount++); } for (int i = 0; i < listItemCount && !m_pDialog->IsSearchCancelled(); i++) { FileSizeInfo &fsInfo = fileSizeInfoArray[i]; if (!(fsInfo.m_uFlag & FSIF_OUTPUT)) { mListCtrl->DeleteItem(fsInfo.nItem-startIndex); startIndex++; } percentage.Update(itemCount++); } mListCtrl->DisablePaint(false); listItemCount = mListCtrl->GetItemCount(); m_pDialog->SetStatusMessage(_T("%d files found"), listItemCount); }