From 88a2d0007db222c339f0b6a17794a2014a241892 Mon Sep 17 00:00:00 2001 From: Daniel Wilhelm Date: Fri, 18 Apr 2014 17:16:21 +0200 Subject: 4.3 --- comparison.cpp | 127 +++++++++++++++++++++------------------------------------ 1 file changed, 46 insertions(+), 81 deletions(-) (limited to 'comparison.cpp') diff --git a/comparison.cpp b/comparison.cpp index 79b18ae9..f66c291e 100644 --- a/comparison.cpp +++ b/comparison.cpp @@ -5,16 +5,16 @@ // ************************************************************************** #include "comparison.h" +#include +#include +#include +#include #include "lib/parallel_scan.h" #include "lib/resolve_path.h" -#include #include "lib/dir_exist_async.h" -#include -#include #include "lib/binary.h" -#include "algorithm.h" -#include #include "lib/cmp_filetime.h" +#include "algorithm.h" #ifdef FFS_WIN #include @@ -120,39 +120,33 @@ void checkDirectoryExistence(const std::set& dirnames, } -namespace -{ -struct EqualDependentDirectory : public std::binary_function -{ - bool operator()(const Zstring& lhs, const Zstring& rhs) const - { - return EqualFilename()(Zstring(lhs.c_str(), std::min(lhs.length(), rhs.length())), - Zstring(rhs.c_str(), std::min(lhs.length(), rhs.length()))); - } -}; -} - //check whether one side is subdirectory of other side (folder pair wise!) //similar check if one directory is read/written by multiple pairs not before beginning of synchronization -wxString checkFolderDependency(const std::vector& folderPairsForm) //returns warning message, empty if all ok +std::wstring checkFolderDependency(const std::vector& folderPairsForm) //returns warning message, empty if all ok { - typedef std::vector > DirDirList; + typedef std::vector > DirDirList; DirDirList dependentDirs; + auto dependentDir = [](const Zstring& lhs, const Zstring& rhs) + { + return EqualFilename()(Zstring(lhs.c_str(), std::min(lhs.length(), rhs.length())), //note: this is NOT an equivalence relation! + Zstring(rhs.c_str(), std::min(lhs.length(), rhs.length()))); + }; + for (std::vector::const_iterator i = folderPairsForm.begin(); i != folderPairsForm.end(); ++i) if (!i->leftDirectoryFmt.empty() && !i->rightDirectoryFmt.empty()) //empty folders names may be accepted by user { - if (EqualDependentDirectory()(i->leftDirectoryFmt, i->rightDirectoryFmt)) //test wheter leftDirectory begins with rightDirectory or the other way round - dependentDirs.push_back(std::make_pair(toWx(i->leftDirectoryFmt), toWx(i->rightDirectoryFmt))); + if (dependentDir(i->leftDirectoryFmt, i->rightDirectoryFmt)) //test wheter leftDirectory begins with rightDirectory or the other way round + dependentDirs.push_back(std::make_pair(utf8CvrtTo(i->leftDirectoryFmt), utf8CvrtTo(i->rightDirectoryFmt))); } - wxString warningMsg; + std::wstring warningMsg; if (!dependentDirs.empty()) { warningMsg = _("Directories are dependent! Be careful when setting up synchronization rules:"); for (auto i = dependentDirs.begin(); i != dependentDirs.end(); ++i) - warningMsg += wxString(L"\n\n") + + warningMsg += std::wstring(L"\n\n") + L"\"" + i->first + L"\"\n" + L"\"" + i->second + L"\""; } @@ -214,17 +208,17 @@ CompareProcess::CompareProcess(size_t fileTimeTol, m_warnings(warnings), allowUserInteraction_(allowUserInteraction), procCallback(handler) - { -if (runWithBackgroundPriority) -procBackground.reset(new ScheduleForBackgroundProcessing); - } +{ + if (runWithBackgroundPriority) + procBackground.reset(new ScheduleForBackgroundProcessing); +} void CompareProcess::startCompareProcess(const std::vector& cfgList, FolderComparison& output) { - //prevent shutdown while (binary) comparison is in progress - DisableStandby dummy2; - (void)dummy2; + //prevent shutdown while (binary) comparison is in progress + PreventStandby dummy2; + (void)dummy2; /* #ifdef NDEBUG @@ -257,9 +251,9 @@ void CompareProcess::startCompareProcess(const std::vector& cfgLi { //check if folders have dependencies - wxString warningMessage = checkFolderDependency(cfgList); + std::wstring warningMessage = checkFolderDependency(cfgList); if (!warningMessage.empty()) - procCallback.reportWarning(warningMessage.c_str(), m_warnings.warningDependentFolders); + procCallback.reportWarning(warningMessage, m_warnings.warningDependentFolders); } //-------------------end of basic checks------------------------------------------ @@ -364,7 +358,7 @@ void CompareProcess::startCompareProcess(const std::vector& cfgLi warningSyncDatabase_(warningSyncDatabase), procCallback_(procCallback) {} - virtual void reportWarning(const wxString& text) + virtual void reportWarning(const std::wstring& text) { procCallback_.reportWarning(text, warningSyncDatabase_); } @@ -404,25 +398,14 @@ std::wstring getConflictInvalidDate(const Zstring& fileNameFull, Int64 utcTime) namespace { -inline -void makeSameLength(wxString& first, wxString& second) -{ - const size_t maxPref = std::max(first.length(), second.length()); - first.Pad(maxPref - first.length(), wxT(' '), true); - second.Pad(maxPref - second.length(), wxT(' '), true); -} - - //check for changed files with same modification date std::wstring getConflictSameDateDiffSize(const FileMapping& fileObj) { std::wstring msg = _("Files %x have the same date but a different size!"); replace(msg, L"%x", std::wstring(L"\"") + fileObj.getRelativeName() + L"\""); msg += L"\n\n"; - msg += L"<-- \t" + _("Date") + L": " + utcToLocalTimeString(fileObj.getLastWriteTime()) + - L" \t" + _("Size") + L": " + toStringSep(fileObj.getFileSize()) + L"\n"; - msg += L"--> \t" + _("Date") + L": " + utcToLocalTimeString(fileObj.getLastWriteTime()) + - L" \t" + _("Size") + L": " + toStringSep(fileObj.getFileSize()); + msg += L"<-- " + _("Date") + L": " + utcToLocalTimeString(fileObj.getLastWriteTime()) + L" " + _("Size") + L": " + toStringSep(fileObj.getFileSize()) + L"\n"; + msg += L"--> " + _("Date") + L": " + utcToLocalTimeString(fileObj.getLastWriteTime()) + L" " + _("Size") + L": " + toStringSep(fileObj.getFileSize()); return _("Conflict detected:") + L"\n" + msg; } } @@ -625,7 +608,7 @@ void CompareProcess::compareByContent(std::vector -void MergeSides::fillOneSide(const DirContainer& dirCont, HierarchyObject& output) -{ - for (DirContainer::FileList::const_iterator i = dirCont.files.begin(); i != dirCont.files.end(); ++i) - output.addSubFile(i->second, i->first); - - for (DirContainer::LinkList::const_iterator i = dirCont.links.begin(); i != dirCont.links.end(); ++i) - output.addSubLink(i->second, i->first); - - for (DirContainer::DirList::const_iterator i = dirCont.dirs.begin(); i != dirCont.dirs.end(); ++i) - { - DirMapping& newDirMap = output.addSubDir(i->first, Zstring()); - fillOneSide(i->second, newDirMap); //recurse into subdirectories - } -} - - -template <> -void MergeSides::fillOneSide(const DirContainer& dirCont, HierarchyObject& output) +template +void MergeSides::fillOneSide(const DirContainer& dirCont, HierarchyObject& output) { - for (DirContainer::FileList::const_iterator i = dirCont.files.begin(); i != dirCont.files.end(); ++i) - output.addSubFile(i->first, i->second); + for (auto iter = dirCont.files.cbegin(); iter != dirCont.files.cend(); ++iter) + output.addSubFile(iter->first, iter->second); - for (DirContainer::LinkList::const_iterator i = dirCont.links.begin(); i != dirCont.links.end(); ++i) - output.addSubLink(i->first, i->second); + for (auto iter = dirCont.links.cbegin(); iter != dirCont.links.cend(); ++iter) + output.addSubLink(iter->first, iter->second); - for (DirContainer::DirList::const_iterator i = dirCont.dirs.begin(); i != dirCont.dirs.end(); ++i) + for (auto iter = dirCont.dirs.cbegin(); iter != dirCont.dirs.cend(); ++iter) { - DirMapping& newDirMap = output.addSubDir(Zstring(), i->first); - fillOneSide(i->second, newDirMap); //recurse into subdirectories + DirMapping& newDirMap = output.addSubDir(iter->first); + fillOneSide(iter->second, newDirMap); //recurse } } @@ -777,8 +743,8 @@ void MergeSides::execute(const DirContainer& leftSide, const DirContainer& right typedef const DirContainer::FileList::value_type FileData; linearMerge(leftSide.files, rightSide.files, - [&](const FileData& fileLeft) { output.addSubFile(fileLeft.second, fileLeft.first); }, //left only - [&](const FileData& fileRight) { output.addSubFile(fileRight.first, fileRight.second); }, //right only + [&](const FileData& fileLeft) { output.addSubFile (fileLeft.first, fileLeft.second); }, //left only + [&](const FileData& fileRight) { output.addSubFile(fileRight.first, fileRight.second); }, //right only [&](const FileData& fileLeft, const FileData& fileRight) //both sides { @@ -794,8 +760,8 @@ void MergeSides::execute(const DirContainer& leftSide, const DirContainer& right typedef const DirContainer::LinkList::value_type LinkData; linearMerge(leftSide.links, rightSide.links, - [&](const LinkData& linkLeft) { output.addSubLink(linkLeft.second, linkLeft.first); }, //left only - [&](const LinkData& linkRight) { output.addSubLink(linkRight.first, linkRight.second); }, //right only + [&](const LinkData& linkLeft) { output.addSubLink(linkLeft.first, linkLeft.second); }, //left only + [&](const LinkData& linkRight) { output.addSubLink(linkRight.first, linkRight.second); }, //right only [&](const LinkData& linkLeft, const LinkData& linkRight) //both sides { @@ -813,12 +779,12 @@ void MergeSides::execute(const DirContainer& leftSide, const DirContainer& right linearMerge(leftSide.dirs, rightSide.dirs, [&](const DirData& dirLeft) //left only { - DirMapping& newDirMap = output.addSubDir(dirLeft.first, Zstring()); + DirMapping& newDirMap = output.addSubDir(dirLeft.first); this->fillOneSide(dirLeft.second, newDirMap); //recurse into subdirectories }, [&](const DirData& dirRight) //right only { - DirMapping& newDirMap = output.addSubDir(Zstring(), dirRight.first); + DirMapping& newDirMap = output.addSubDir(dirRight.first); this->fillOneSide(dirRight.second, newDirMap); //recurse into subdirectories }, @@ -839,7 +805,7 @@ void processFilteredDirs(HierarchyObject& hierObj, const HardFilter& filterProc) std::for_each(subDirs.begin(), subDirs.end(), [&](DirMapping& dirObj) { - dirObj.setActive(filterProc.passDirFilter(dirObj.getObjRelativeName().c_str(), NULL)); //subObjMightMatch is always true in this context! + dirObj.setActive(filterProc.passDirFilter(dirObj.getObjRelativeName(), NULL)); //subObjMightMatch is always true in this context! processFilteredDirs(dirObj, filterProc); }); @@ -878,7 +844,6 @@ void CompareProcess::performComparison(const FolderPairCfg& fpCfg, const DirectoryValue& bufValueRight = getDirValue(fpCfg.rightDirectoryFmt); procCallback.reportStatus(_("Generating file list...")); - procCallback.forceUiRefresh(); //keep total number of scanned files up to date //PERF_START; MergeSides(undefinedFiles, undefinedLinks).execute(bufValueLeft.dirCont, bufValueRight.dirCont, output); -- cgit