From d2854834e18443876c8f75e0a7f3b88d1d549fc4 Mon Sep 17 00:00:00 2001 From: Daniel Wilhelm Date: Fri, 18 Apr 2014 17:15:39 +0200 Subject: 4.2 --- algorithm.cpp | 78 +++++++++++++++++++++++++++++++---------------------------- 1 file changed, 41 insertions(+), 37 deletions(-) (limited to 'algorithm.cpp') diff --git a/algorithm.cpp b/algorithm.cpp index d2e40f44..7c6dc5d9 100644 --- a/algorithm.cpp +++ b/algorithm.cpp @@ -385,7 +385,7 @@ std::pair retrieveDataSetDir(const Zstring& obj return std::make_pair(DataSetDir(iter->first), &iter->second); } - return std::make_pair(DataSetDir(), static_cast(NULL)); //object not found + return std::make_pair(DataSetDir(), nullptr); //object not found } //---------------------------------------------------------------------------------------------- @@ -454,7 +454,7 @@ private: catch (FileErrorDatabaseNotExisting&) {} //let's ignore these errors for now... catch (FileError& error) //e.g. incompatible database version { - if (handler_) handler_->reportWarning(error.msg() + wxT(" \n\n") + + if (handler_) handler_->reportWarning(error.toString() + wxT(" \n\n") + _("Setting default synchronization directions: Old files will be overwritten with newer files.")); } return std::pair(); //NULL @@ -1248,7 +1248,7 @@ std::pair zen::deleteFromGridAndHDPreview( //assemble message con }); } - return std::make_pair(cvrtString(filesToDelete), totalDelCount); + return std::make_pair(copyStringTo(filesToDelete), totalDelCount); } @@ -1333,7 +1333,7 @@ void deleteFromGridAndHDOneSide(InputIterator first, InputIterator last, } catch (const FileError& error) { - DeleteFilesHandler::Response rv = statusHandler.reportError(error.msg()); + DeleteFilesHandler::Response rv = statusHandler.reportError(error.toString()); if (rv == DeleteFilesHandler::IGNORE_ERROR) break; @@ -1366,9 +1366,6 @@ void zen::deleteFromGridAndHD(std::vector& rowsToDeleteOnLeft for (auto iter = folderCmp.begin(); iter != folderCmp.end(); ++iter) baseDirCfgs[&** iter] = directCfgs[iter - folderCmp.begin()]; - //ensure cleanup: redetermination of sync-directions and removal of invalid rows - ZEN_ON_BLOCK_EXIT( std::for_each(begin(folderCmp), end(folderCmp), BaseDirMapping::removeEmpty); ); - std::set deleteLeft (rowsToDeleteOnLeft .begin(), rowsToDeleteOnLeft .end()); std::set deleteRight(rowsToDeleteOnRight.begin(), rowsToDeleteOnRight.end()); @@ -1381,44 +1378,51 @@ void zen::deleteFromGridAndHD(std::vector& rowsToDeleteOnLeft set_remove_if(deleteLeft, std::mem_fun(&FileSystemObject::isEmpty)); //remove empty rows to ensure correct statistics set_remove_if(deleteRight, std::mem_fun(&FileSystemObject::isEmpty)); // - - deleteFromGridAndHDOneSide(deleteLeft.begin(), deleteLeft.end(), - useRecycleBin, - statusHandler); - - deleteFromGridAndHDOneSide(deleteRight.begin(), deleteRight.end(), - useRecycleBin, - statusHandler); - - //update sync direction: we cannot do a full redetermination since the user may have committed manual changes - std::set deletedTotal = deleteLeft; - deletedTotal.insert(deleteRight.begin(), deleteRight.end()); - - for (auto iter = deletedTotal.begin(); iter != deletedTotal.end(); ++iter) + //ensure cleanup: redetermination of sync-directions and removal of invalid rows + auto updateDirection = [&]() { - FileSystemObject& fsObj = **iter; //all pointers are required(!) to be bound + //update sync direction: we cannot do a full redetermination since the user may already have entered manual changes + std::set deletedTotal = deleteLeft; + deletedTotal.insert(deleteRight.begin(), deleteRight.end()); - if (fsObj.isEmpty() != fsObj.isEmpty()) //make sure objects exists on one side only + for (auto iter = deletedTotal.begin(); iter != deletedTotal.end(); ++iter) { - auto cfgIter = baseDirCfgs.find(&fsObj.root()); - if (cfgIter != baseDirCfgs.end()) - { - SyncDirection newDir = SYNC_DIR_NONE; + FileSystemObject& fsObj = **iter; //all pointers are required(!) to be bound - if (cfgIter->second.var == DirectionConfig::AUTOMATIC) - newDir = fsObj.isEmpty() ? SYNC_DIR_RIGHT : SYNC_DIR_LEFT; - else + if (fsObj.isEmpty() != fsObj.isEmpty()) //make sure objects exists on one side only + { + auto cfgIter = baseDirCfgs.find(&fsObj.root()); + if (cfgIter != baseDirCfgs.end()) { - DirectionSet dirCfg = extractDirections(cfgIter->second); - newDir = fsObj.isEmpty() ? dirCfg.exRightSideOnly : dirCfg.exLeftSideOnly; - } + SyncDirection newDir = SYNC_DIR_NONE; - setSyncDirectionRec(newDir, fsObj); //set new direction (recursively) + if (cfgIter->second.var == DirectionConfig::AUTOMATIC) + newDir = fsObj.isEmpty() ? SYNC_DIR_RIGHT : SYNC_DIR_LEFT; + else + { + DirectionSet dirCfg = extractDirections(cfgIter->second); + newDir = fsObj.isEmpty() ? dirCfg.exRightSideOnly : dirCfg.exLeftSideOnly; + } + + setSyncDirectionRec(newDir, fsObj); //set new direction (recursively) + } + else + assert(!"this should not happen!"); } - else - assert(!"this should not happen!"); } - } + + //last step: cleanup empty rows: this one invalidates all pointers! + std::for_each(begin(folderCmp), end(folderCmp), BaseDirMapping::removeEmpty); + }; + ZEN_ON_BLOCK_EXIT(updateDirection()); //MSVC: assert is a macro and it doesn't play nice with ZEN_ON_BLOCK_EXIT, surprise... wasn't there something about macros being "evil"? + + deleteFromGridAndHDOneSide(deleteLeft.begin(), deleteLeft.end(), + useRecycleBin, + statusHandler); + + deleteFromGridAndHDOneSide(deleteRight.begin(), deleteRight.end(), + useRecycleBin, + statusHandler); } -- cgit