summaryrefslogtreecommitdiff
path: root/synchronization.h
blob: 9db4d112df27ff7037438571dbc8c7e18cf1c706 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#ifndef SYNCHRONIZATION_H_INCLUDED
#define SYNCHRONIZATION_H_INCLUDED

#include "fileHierarchy.h"
#include "library/processXml.h"

class StatusHandler;


namespace FreeFileSync
{

class SyncStatistics
{
public:
    SyncStatistics(const HierarchyObject&  hierObj);
    SyncStatistics(const FolderComparison& folderCmp);

    int         getCreate(   bool inclLeft = true, bool inclRight = true) const;
    int         getOverwrite(bool inclLeft = true, bool inclRight = true) const;
    int         getDelete(   bool inclLeft = true, bool inclRight = true) const;
    int         getConflict() const;

    typedef std::vector<std::pair<Zstring, wxString> > ConflictTexts; // Pair(filename/conflict text)
    const ConflictTexts& getFirstConflicts() const; //get first few sync conflicts

    wxULongLong getDataToProcess() const;
    int getRowCount() const;

private:
    void init();

    void getNumbersRecursively(const HierarchyObject& hierObj);

    void getFileNumbers(const FileMapping& fileObj);
    void getDirNumbers(const DirMapping& dirObj);

    int createLeft,    createRight;
    int overwriteLeft, overwriteRight;
    int deleteLeft,    deleteRight;
    int conflict;
    ConflictTexts firstConflicts; //save the first few conflict texts to display as a warning message
    wxULongLong dataToProcess;
    int rowsTotal;
};

bool synchronizationNeeded(const FolderComparison& folderCmp);

class SyncRecursively;

struct FolderPairSyncCfg
{
    FolderPairSyncCfg(bool automaticMode,
                      const DeletionPolicy handleDel,
                      const Zstring& custDelDir) :
        inAutomaticMode(automaticMode),
        handleDeletion(handleDel),
        custDelFolder(custDelDir) {}

    bool inAutomaticMode; //update database if in automatic mode
    DeletionPolicy handleDeletion;
    Zstring custDelFolder;
};
std::vector<FolderPairSyncCfg> extractSyncCfg(const MainConfiguration& mainCfg);


//class handling synchronization process
class SyncProcess
{
public:
    SyncProcess(bool copyFileSymLinks,
                bool traverseDirSymLinks,
                xmlAccess::OptionalDialogs& warnings,
                bool verifyCopiedFiles,
                bool copyLockedFiles,
                StatusHandler& handler);

    //CONTRACT: syncConfig must have SAME SIZE folderCmp and correspond per row!
    void startSynchronizationProcess(const std::vector<FolderPairSyncCfg>& syncConfig, FolderComparison& folderCmp);

private:
    friend class SyncRecursively;

    const bool m_copyFileSymLinks;
    const bool m_traverseDirSymLinks;
    const bool m_verifyCopiedFiles;
    const bool copyLockedFiles_;

    //warnings
    xmlAccess::OptionalDialogs& m_warnings;

    StatusHandler& statusUpdater;
};

}

#endif // SYNCHRONIZATION_H_INCLUDED
bgstack15