From 4226e548662339ea1ca37b45385a7cf9b237ff1e Mon Sep 17 00:00:00 2001 From: Daniel Wilhelm Date: Fri, 18 Apr 2014 17:07:43 +0200 Subject: 3.8 --- ui/sorting.h | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) (limited to 'ui/sorting.h') diff --git a/ui/sorting.h b/ui/sorting.h index 9592b36f..1a77ff02 100644 --- a/ui/sorting.h +++ b/ui/sorting.h @@ -15,6 +15,22 @@ namespace FreeFileSync { +namespace +{ +struct CompileTimeReminder : public FSObjectVisitor +{ + virtual void visit(const FileMapping& fileObj) {} + virtual void visit(const SymLinkMapping& linkObj) {} + virtual void visit(const DirMapping& dirObj) {} +} checkDymanicCasts; //just a compile-time reminder to check dynamic casts in this file +} + +inline +bool isDirectoryMapping(const FileSystemObject& fsObj) +{ + return dynamic_cast(&fsObj) != NULL; +} + inline int compareString(const Zstring& stringA, const Zstring& stringB) { @@ -91,12 +107,12 @@ bool sortByRelativeName(const FileSystemObject& a, const FileSystemObject& b) const bool isDirectoryA = isDirectoryMapping(a); const Zstring relDirNameA = isDirectoryA ? a.getRelativeName() : //directory - a.getParentRelativeName(); //file + a.getParentRelativeName(); //file or symlink const bool isDirectoryB = isDirectoryMapping(b); const Zstring relDirNameB = isDirectoryB ? b.getRelativeName() : //directory - b.getParentRelativeName(); //file + b.getParentRelativeName(); //file or symlink //compare relative names without filenames first @@ -124,7 +140,6 @@ bool sortByFileSize(const FileSystemObject& a, const FileSystemObject& b) else if (b.isEmpty()) return true; //empty rows always last - const FileMapping* fileObjA = dynamic_cast(&a); const FileMapping* fileObjB = dynamic_cast(&b); @@ -134,7 +149,7 @@ bool sortByFileSize(const FileSystemObject& a, const FileSystemObject& b) return true; //directories last //return list beginning with largest files first - return Compare().isSmallerThan(fileObjA->getFileSize(), fileObjB->getFileSize()); + return Compare().isSmallerThan(fileObjA->getFileSize(), fileObjB->getFileSize()); } @@ -151,13 +166,19 @@ bool sortByDate(const FileSystemObject& a, const FileSystemObject& b) const FileMapping* fileObjA = dynamic_cast(&a); const FileMapping* fileObjB = dynamic_cast(&b); - if (fileObjA == NULL) + const SymLinkMapping* linkObjA = dynamic_cast(&a); + const SymLinkMapping* linkObjB = dynamic_cast(&b); + + if (!fileObjA && !linkObjA) return false; //directories last - else if (fileObjB == NULL) + else if (!fileObjB && !linkObjB) return true; //directories last + const wxLongLong& dateA = fileObjA ? fileObjA->getLastWriteTime() : linkObjA->getLastWriteTime(); + const wxLongLong& dateB = fileObjB ? fileObjB->getLastWriteTime() : linkObjB->getLastWriteTime(); + //return list beginning with newest files first - return Compare().isSmallerThan(fileObjA->getLastWriteTime(), fileObjB->getLastWriteTime()); + return Compare().isSmallerThan(dateA, dateB); } -- cgit