summaryrefslogtreecommitdiff
path: root/FreeFileSync.h
diff options
context:
space:
mode:
authorDaniel Wilhelm <daniel@wili.li>2014-04-18 16:55:14 +0200
committerDaniel Wilhelm <daniel@wili.li>2014-04-18 16:55:14 +0200
commit222024f07e505617aec93dc4837be2be27d18856 (patch)
treec40f400baa6cf1d047205359f80c2b8f74a2b507 /FreeFileSync.h
parent1.12 (diff)
downloadFreeFileSync-222024f07e505617aec93dc4837be2be27d18856.tar.gz
FreeFileSync-222024f07e505617aec93dc4837be2be27d18856.tar.bz2
FreeFileSync-222024f07e505617aec93dc4837be2be27d18856.zip
1.13
Diffstat (limited to 'FreeFileSync.h')
-rw-r--r--FreeFileSync.h335
1 files changed, 136 insertions, 199 deletions
diff --git a/FreeFileSync.h b/FreeFileSync.h
index 22a0f4e1..92d90189 100644
--- a/FreeFileSync.h
+++ b/FreeFileSync.h
@@ -4,240 +4,177 @@
#include <wx/string.h>
#include <set>
#include <vector>
-#include <wx/dir.h>
-#include <wx/log.h>
-#include "library/multithreading.h"
+#include "library/statusHandler.h"
+#include "library/fileHandling.h"
-using namespace std;
-
-enum CompareVariant
-{
- CMP_BY_CONTENT,
- CMP_BY_TIME_SIZE
-};
-
-struct SyncConfiguration
+namespace FreeFileSync
{
- SyncConfiguration() :
- exLeftSideOnly(SYNC_DIR_RIGHT),
- exRightSideOnly(SYNC_DIR_RIGHT),
- leftNewer(SYNC_DIR_RIGHT),
- rightNewer(SYNC_DIR_RIGHT),
- different(SYNC_DIR_RIGHT) {}
-
- enum Direction
+ enum CompareVariant
{
- SYNC_DIR_LEFT,
- SYNC_DIR_RIGHT,
- SYNC_DIR_NONE
+ CMP_BY_CONTENT,
+ CMP_BY_TIME_SIZE
};
- Direction exLeftSideOnly;
- Direction exRightSideOnly;
- Direction leftNewer;
- Direction rightNewer;
- Direction different;
-};
+ struct SyncConfiguration
+ {
+ SyncConfiguration() :
+ exLeftSideOnly(SYNC_DIR_RIGHT),
+ exRightSideOnly(SYNC_DIR_RIGHT),
+ leftNewer(SYNC_DIR_RIGHT),
+ rightNewer(SYNC_DIR_RIGHT),
+ different(SYNC_DIR_RIGHT) {}
+
+ enum Direction
+ {
+ SYNC_DIR_LEFT,
+ SYNC_DIR_RIGHT,
+ SYNC_DIR_NONE
+ };
+
+ Direction exLeftSideOnly;
+ Direction exRightSideOnly;
+ Direction leftNewer;
+ Direction rightNewer;
+ Direction different;
+ };
-struct MainConfiguration
-{
- MainConfiguration();
- //Compare setting
- CompareVariant compareVar;
+ struct MainConfiguration
+ {
+ MainConfiguration() :
+ compareVar(CMP_BY_TIME_SIZE),
+ filterIsActive(false), //do not filter by default
+ includeFilter(wxT("*")), //include all files/folders
+ excludeFilter(wxEmptyString), //exclude nothing
+ useRecycleBin(FreeFileSync::recycleBinExists()), //enable if OS supports it; else user will have to activate first and then get an error message
+ ignoreErrors(false) {}
- //Synchronisation settings
- SyncConfiguration syncConfiguration;
+ //Compare setting
+ CompareVariant compareVar;
- //Filter setting
- bool filterIsActive;
- wxString includeFilter;
- wxString excludeFilter;
+ //Synchronisation settings
+ SyncConfiguration syncConfiguration;
+ //Filter setting
+ bool filterIsActive;
+ wxString includeFilter;
+ wxString excludeFilter;
- //misc options
- bool useRecycleBin; //use Recycle bin when deleting or overwriting files while synchronizing
- bool continueOnError; //hides error messages during synchronization
-};
+ //misc options
+ bool useRecycleBin; //use Recycle bin when deleting or overwriting files while synchronizing
+ bool ignoreErrors; //hides error messages during synchronization
+ };
-struct FileDescrLine
-{
- FileDescrLine() : objType(TYPE_NOTHING) {}
- enum ObjectType
+ struct FileDescrLine
{
- TYPE_NOTHING,
- TYPE_DIRECTORY,
- TYPE_FILE
- };
-
- wxString fullName; // == directory + relativeName
- wxString directory; //directory to be synced
- wxString relativeName; //fullName without directory that is being synchronized
- //Note on performance: Keep redundant information "directory" and "relativeName"! Extracting info from "fullName" results in noticeable performance loss!
- wxString lastWriteTime;
- wxULongLong lastWriteTimeRaw;
- wxULongLong fileSize;
- ObjectType objType; //is it a file or directory or initial?
-
- //the following operators are needed by template class "set"
- //DO NOT CHANGE THESE RELATIONS!!!
+ FileDescrLine() : objType(TYPE_NOTHING) {}
+
+ enum ObjectType
+ {
+ TYPE_NOTHING,
+ TYPE_DIRECTORY,
+ TYPE_FILE
+ };
+
+ wxString fullName; // == directory + relativeName
+ wxString directory; //directory to be synced + separator
+ wxString relativeName; //fullName without directory that is being synchronized
+ //Note on performance: Keep redundant information "directory" and "relativeName"!
+ //Extracting info from "fullName" instead would result in noticeable performance loss, with only limited memory reduction (note ref. counting strings)!
+ wxString lastWriteTime;
+ wxULongLong lastWriteTimeRaw;
+ wxULongLong fileSize;
+ ObjectType objType; //is it a file or directory or initial?
+
+ //the following operators are needed by template class "set"
+ //DO NOT CHANGE THESE RELATIONS!!!
#ifdef FFS_WIN
- //Windows does NOT distinguish between upper/lower-case
- bool operator>(const FileDescrLine& b ) const
- {
- return (relativeName.CmpNoCase(b.relativeName) > 0);
- }
- bool operator<(const FileDescrLine& b) const
- {
- return (relativeName.CmpNoCase(b.relativeName) < 0);
- }
- bool operator==(const FileDescrLine& b) const
- {
- return (relativeName.CmpNoCase(b.relativeName) == 0);
- }
+ //Windows does NOT distinguish between upper/lower-case
+ bool operator>(const FileDescrLine& b ) const
+ {
+ return (relativeName.CmpNoCase(b.relativeName) > 0);
+ }
+ bool operator<(const FileDescrLine& b) const
+ {
+ return (relativeName.CmpNoCase(b.relativeName) < 0);
+ }
+ bool operator==(const FileDescrLine& b) const
+ {
+ return (relativeName.CmpNoCase(b.relativeName) == 0);
+ }
#elif defined FFS_LINUX
- //Linux DOES distinguish between upper/lower-case
- bool operator>(const FileDescrLine& b ) const
- {
- return (relativeName.Cmp(b.relativeName) > 0);
- }
- bool operator<(const FileDescrLine& b) const
- {
- return (relativeName.Cmp(b.relativeName) < 0);
- }
- bool operator==(const FileDescrLine& b) const
- {
- return (relativeName.Cmp(b.relativeName) == 0);
- }
+ //Linux DOES distinguish between upper/lower-case
+ bool operator>(const FileDescrLine& b ) const
+ {
+ return (relativeName.Cmp(b.relativeName) > 0);
+ }
+ bool operator<(const FileDescrLine& b) const
+ {
+ return (relativeName.Cmp(b.relativeName) < 0);
+ }
+ bool operator==(const FileDescrLine& b) const
+ {
+ return (relativeName.Cmp(b.relativeName) == 0);
+ }
#else
- adapt this
+ adapt this
#endif
-};
-typedef set<FileDescrLine> DirectoryDescrType;
-
-
-enum CompareFilesResult
-{
- FILE_LEFT_SIDE_ONLY,
- FILE_RIGHT_SIDE_ONLY,
- FILE_RIGHT_NEWER,
- FILE_LEFT_NEWER,
- FILE_DIFFERENT,
- FILE_EQUAL,
-
- FILE_UNDEFINED
-};
-
-
-struct FileCompareLine
-{
- FileCompareLine() : selectedForSynchronization(true) {}
-
- FileDescrLine fileDescrLeft;
- FileDescrLine fileDescrRight;
-
- CompareFilesResult cmpResult;
- bool selectedForSynchronization;
-};
-typedef vector<FileCompareLine> FileCompareResult;
-
-
-typedef int GridViewLine;
-typedef vector<GridViewLine> GridView; //vector of references to lines in FileCompareResult
-
-
-struct FolderPair
-{
- wxString leftDirectory;
- wxString rightDirectory;
-};
-
-
-class RecycleBin;
-
-namespace FreeFileSync
-{
- //main functions for compare
- bool foldersAreValidForComparison(const vector<FolderPair>& folderPairs, wxString& errorMessage);
- void startCompareProcess(const vector<FolderPair>& directoryPairsFormatted, const CompareVariant cmpVar, FileCompareResult& output, StatusHandler* statusUpdater);
-
- //main function for synchronization
- void startSynchronizationProcess(FileCompareResult& grid, const SyncConfiguration& config, StatusHandler* statusUpdater, const bool useRecycleBin);
-
- bool recycleBinExists(); //test existence of Recycle Bin API on current system
-
- void deleteOnGridAndHD(FileCompareResult& grid, const set<int>& rowsToDelete, ErrorHandler* errorHandler, const bool useRecycleBin);
- void addSubElements(set<int>& subElements, const FileCompareResult& grid, const FileCompareLine& relevantRow);
-
- void filterCurrentGridData(FileCompareResult& currentGridData, const wxString& includeFilter, const wxString& excludeFilter);
- void removeFilterOnCurrentGridData(FileCompareResult& currentGridData);
-
- wxString formatFilesizeToShortString(const wxULongLong& filesize);
- wxString formatFilesizeToShortString(const double filesize);
- wxString getFormattedDirectoryName(const wxString& dirname);
-
- void calcTotalBytesToSync(int& objectsToCreate,
- int& objectsToOverwrite,
- int& objectsToDelete,
- double& dataToProcess,
- const FileCompareResult& fileCmpResult,
- const SyncConfiguration& config);
-
- void swapGrids(FileCompareResult& grid);
-
- void adjustModificationTimes(const wxString& parentDirectory, const int timeInSeconds, ErrorHandler* errorHandler);
+ };
+ typedef set<FileDescrLine> DirectoryDescrType;
- const wxString FfsLastConfigFile = wxT("LastRun.ffs_gui");
- const wxString FfsGlobalSettingsFile = wxT("GlobalSettings.xml");
+ enum CompareFilesResult
+ {
+ FILE_LEFT_SIDE_ONLY,
+ FILE_RIGHT_SIDE_ONLY,
+ FILE_LEFT_NEWER,
+ FILE_RIGHT_NEWER,
+ FILE_DIFFERENT,
+ FILE_EQUAL,
+
+ FILE_UNDEFINED
+ };
-//+++++++++++++++++++SUBROUTINES++++++++++++++++++++++++++
- //create comparison result table and fill relation except for files existing on both sides
- void performBaseComparison(const vector<FolderPair>& directoryPairsFormatted,
- FileCompareResult& output,
- StatusHandler* statusUpdater);
- bool synchronizeFile(const FileCompareLine& cmpLine, const SyncConfiguration& config, const bool useRecycleBin, StatusHandler* statusUpdater); // false if nothing had to be done
- bool synchronizeFolder(const FileCompareLine& cmpLine, const SyncConfiguration& config, const bool useRecycleBin, StatusHandler* statusUpdater); // false if nothing had to be done
+ struct FileCompareLine
+ {
+ FileCompareLine() : selectedForSynchronization(true) {}
- //file functionality
- void removeDirectory(const wxString& directory, const bool useRecycleBin);
- void removeFile(const wxString& filename, const bool useRecycleBin);
- void copyfileMultithreaded(const wxString& source, const wxString& target, StatusHandler* updateClass);
- void createDirectory(const wxString& directory, int level = 0); //level is used internally only
+ FileDescrLine fileDescrLeft;
+ FileDescrLine fileDescrRight;
- //misc
- vector<wxString> compoundStringToFilter(const wxString& filterString); //convert compound string, separated by ';' or '\n' into formatted vector of wxStrings
+ CompareFilesResult cmpResult;
+ bool selectedForSynchronization;
+ };
+ typedef vector<FileCompareLine> FileCompareResult;
- extern RecycleBin recycler;
-}
+ typedef int GridViewLine;
+ typedef vector<GridViewLine> GridView; //vector of references to lines in FileCompareResult
-class FileError //Exception class used to notify file/directory copy/delete errors
-{
-public:
- FileError(const wxString& txt) : errorMessage(txt) {}
- wxString show() const
+ struct FolderPair
{
- return errorMessage;
- }
+ wxString leftDirectory;
+ wxString rightDirectory;
+ };
-private:
- wxString errorMessage;
-};
+ class AbortThisProcess //Exception class used to abort the "compare" and "sync" process
+ {
+ public:
+ AbortThisProcess() {}
+ ~AbortThisProcess() {}
+ };
-class AbortThisProcess //Exception class used to abort the "compare" and "sync" process
-{
-public:
- AbortThisProcess() {}
- ~AbortThisProcess() {}
-};
+ const int FILE_TIME_PRECISION = 2; //file times have precision of 2 seconds due to FAT/FAT32 file systems
+ const wxString LAST_CONFIG_FILE = wxT("LastRun.ffs_gui");
+ const wxString GLOBAL_CONFIG_FILE = wxT("GlobalSettings.xml");
+}
#endif // FREEFILESYNC_H_INCLUDED
bgstack15