summaryrefslogtreecommitdiff
path: root/structures.h
blob: 212f9557134b1f062eafe5ef2851b2ecc9fd56fd (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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
#ifndef FREEFILESYNC_H_INCLUDED
#define FREEFILESYNC_H_INCLUDED

#include <wx/string.h>
#include <vector>
#include "shared/zstring.h"
#include "shared/systemConstants.h"
#include "shared/staticAssert.h"
#include <boost/shared_ptr.hpp>


namespace FreeFileSync
{
enum CompareVariant
{
    CMP_BY_TIME_SIZE,
    CMP_BY_CONTENT
};

wxString getVariantName(CompareVariant var);


enum SyncDirection
{
    SYNC_DIR_LEFT  = 0,
    SYNC_DIR_RIGHT,
    SYNC_DIR_NONE, //NOTE: align with SyncDirectionIntern before adding anything here!
};


class SyncConfiguration
{
public:
    SyncConfiguration() :
        automatic(true),
        exLeftSideOnly( SYNC_DIR_RIGHT),
        exRightSideOnly(SYNC_DIR_LEFT),
        leftNewer(      SYNC_DIR_RIGHT),
        rightNewer(     SYNC_DIR_LEFT),
        different(      SYNC_DIR_NONE),
        conflict(       SYNC_DIR_NONE) {}

    bool operator==(const SyncConfiguration& other) const
    {
        return exLeftSideOnly  == other.exLeftSideOnly  &&
               exRightSideOnly == other.exRightSideOnly &&
               leftNewer       == other.leftNewer       &&
               rightNewer      == other.rightNewer      &&
               different       == other.different       &&
               conflict        == other.conflict;
    }

    //get/set default configuration variants
    enum Variant
    {
        AUTOMATIC,
        MIRROR,
        UPDATE,
        TWOWAY,
        CUSTOM
    };
    Variant getVariant() const;
    void setVariant(const Variant var);
    wxString getVariantName() const;

    bool automatic; //use sync-database
    SyncDirection exLeftSideOnly;
    SyncDirection exRightSideOnly;
    SyncDirection leftNewer;
    SyncDirection rightNewer;
    SyncDirection different;
    SyncDirection conflict;
};


enum DeletionPolicy
{
    DELETE_PERMANENTLY = 5,
    MOVE_TO_RECYCLE_BIN,
    MOVE_TO_CUSTOM_DIRECTORY
};


struct HiddenSettings
{
    HiddenSettings() :
        fileTimeTolerance(2),  //default 2s: FAT vs NTFS
        traverseDirectorySymlinks(false),
        copyFileSymlinks(true),
        verifyFileCopy(false) {}

    unsigned int fileTimeTolerance; //max. allowed file time deviation
    bool traverseDirectorySymlinks;
    bool copyFileSymlinks; //copy symbolic link instead of target file
    bool verifyFileCopy;   //verify copied files

    bool operator==(const HiddenSettings& other) const
    {
        return fileTimeTolerance         == other.fileTimeTolerance         &&
               traverseDirectorySymlinks == other.traverseDirectorySymlinks &&
               copyFileSymlinks          == other.copyFileSymlinks          &&
               verifyFileCopy            == other.verifyFileCopy;
    }
};


bool recycleBinExistsWrap();


struct AlternateSyncConfig
{
    AlternateSyncConfig(const SyncConfiguration& syncCfg,
                        const DeletionPolicy     handleDel,
                        const wxString&          customDelDir) :
        syncConfiguration(syncCfg),
        handleDeletion(handleDel),
        customDeletionDirectory(customDelDir) {};

    AlternateSyncConfig() :  //construct with default values
        handleDeletion(FreeFileSync::recycleBinExistsWrap() ? MOVE_TO_RECYCLE_BIN : DELETE_PERMANENTLY) {} //enable if OS supports it; else user will have to activate first and then get an error message

    //Synchronisation settings
    SyncConfiguration syncConfiguration;

    //misc options
    DeletionPolicy handleDeletion; //use Recycle, delete permanently or move to user-defined location
    wxString customDeletionDirectory;

    bool operator==(const AlternateSyncConfig& other) const
    {
        return syncConfiguration       == other.syncConfiguration &&
               handleDeletion          == other.handleDeletion    &&
               customDeletionDirectory == other.customDeletionDirectory;
    }
};

//standard exclude filter settings, OS dependent
Zstring standardExcludeFilter();


struct FilterConfig
{
    FilterConfig(const Zstring& include, const Zstring& exclude) :
        includeFilter(include),
        excludeFilter(exclude) {}

    FilterConfig() : //construct with default values
        includeFilter(DefaultStr("*")) {}

    Zstring includeFilter;
    Zstring excludeFilter;

    bool operator==(const FilterConfig& other) const
    {
        return includeFilter == other.includeFilter &&
               excludeFilter == other.excludeFilter;
    }
};


struct FolderPairEnh //enhanced folder pairs with (optional) alternate configuration
{
    FolderPairEnh() {}

    FolderPairEnh(const Zstring& leftDir,
                  const Zstring& rightDir,
                  const boost::shared_ptr<const AlternateSyncConfig>& syncConfig,
                  const FilterConfig& filter) :
        leftDirectory(leftDir),
        rightDirectory(rightDir) ,
        altSyncConfig(syncConfig),
        localFilter(filter) {}

    Zstring leftDirectory;
    Zstring rightDirectory;

    boost::shared_ptr<const AlternateSyncConfig> altSyncConfig; //optional
    FilterConfig localFilter;

    bool operator==(const FolderPairEnh& other) const
    {
        return leftDirectory  == other.leftDirectory  &&
               rightDirectory == other.rightDirectory &&

               (altSyncConfig.get() && other.altSyncConfig.get() ?
                *altSyncConfig == *other.altSyncConfig :
                altSyncConfig.get() == other.altSyncConfig.get()) &&

               localFilter == other.localFilter;
    }
};


struct MainConfiguration
{
    MainConfiguration() :
        compareVar(CMP_BY_TIME_SIZE),
        filterIsActive(true),
        includeFilter(DefaultStr("*")),
        excludeFilter(standardExcludeFilter()),
        handleDeletion(FreeFileSync::recycleBinExistsWrap() ? MOVE_TO_RECYCLE_BIN : DELETE_PERMANENTLY) {} //enable if OS supports it; else user will have to activate first and then get an error message

    FolderPairEnh firstPair; //there needs to be at least one pair!
    std::vector<FolderPairEnh> additionalPairs;

    //Compare setting
    CompareVariant compareVar;

    //Synchronisation settings
    SyncConfiguration syncConfiguration;

    //GLOBAL filter settings
    bool filterIsActive;
    Zstring includeFilter;
    Zstring excludeFilter;

    //misc options
    HiddenSettings hidden; //settings not visible on GUI

    DeletionPolicy handleDeletion; //use Recycle, delete permanently or move to user-defined location
    wxString customDeletionDirectory;

    wxString getSyncVariantName();

    bool operator==(const MainConfiguration& other) const
    {
        return firstPair         == other.firstPair         &&
               additionalPairs   == other.additionalPairs   &&
               compareVar        == other.compareVar        &&
               syncConfiguration == other.syncConfiguration &&
               filterIsActive    == other.filterIsActive    &&
               includeFilter     == other.includeFilter     &&
               excludeFilter     == other.excludeFilter     &&
               hidden            == other.hidden            &&
               handleDeletion    == other.handleDeletion    &&
               customDeletionDirectory == other.customDeletionDirectory;
    }
};


enum CompareFilesResult
{
    FILE_LEFT_SIDE_ONLY = 0,
    FILE_RIGHT_SIDE_ONLY,
    FILE_LEFT_NEWER,
    FILE_RIGHT_NEWER,
    FILE_DIFFERENT,
    FILE_EQUAL,
    FILE_CONFLICT
};
//attention make sure these /|\  \|/ two enums match!!!
enum CompareDirResult
{
    DIR_LEFT_SIDE_ONLY  = FILE_LEFT_SIDE_ONLY,
    DIR_RIGHT_SIDE_ONLY = FILE_RIGHT_SIDE_ONLY,
    DIR_EQUAL           = FILE_EQUAL
};


inline
CompareFilesResult convertToFilesResult(CompareDirResult value)
{
    return static_cast<CompareFilesResult>(value);
}



wxString getDescription(CompareFilesResult cmpRes);
wxString getSymbol(CompareFilesResult cmpRes);


enum SyncOperation
{
    SO_CREATE_NEW_LEFT,
    SO_CREATE_NEW_RIGHT,
    SO_DELETE_LEFT,
    SO_DELETE_RIGHT,
    SO_OVERWRITE_LEFT,
    SO_OVERWRITE_RIGHT,
    SO_DO_NOTHING, //= both sides differ, but nothing will be synced
    SO_EQUAL,      //= both sides are equal, so nothing will be synced
    SO_UNRESOLVED_CONFLICT
};

wxString getDescription(SyncOperation op);
wxString getSymbol(SyncOperation op);


//Exception class used to abort the "compare" and "sync" process
class AbortThisProcess {};
}

#endif // FREEFILESYNC_H_INCLUDED
bgstack15