summaryrefslogtreecommitdiff
path: root/structures.cpp
blob: 6744a2636850881b6013f65623ec3f89c1e861b7 (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
#include "structures.h"
#include "library/fileHandling.h"
#include <wx/intl.h>
#include <wx/stdpaths.h>
#include <wx/filename.h>

using namespace FreeFileSync;


#ifdef FFS_WIN
const wxChar FreeFileSync::FILE_NAME_SEPARATOR = '\\';
#elif defined FFS_LINUX
const wxChar FreeFileSync::FILE_NAME_SEPARATOR = '/';
#else
assert(false);
#endif

//these two global variables are language-dependent => cannot be set constant! See CustomLocale
const wxChar* FreeFileSync::DECIMAL_POINT       = wxEmptyString;
const wxChar* FreeFileSync::THOUSANDS_SEPARATOR = wxEmptyString;


wxString assembleFileForUserData(const wxString fileName)
{
    static const bool isPortableVersion = !wxFileExists(wxT("uninstall.exe")); //this check is a bit lame...

    if (isPortableVersion) //use same directory as executable
        return getInstallationDir() + FILE_NAME_SEPARATOR + fileName;
    else //usen OS' standard paths
    {
        wxString userDirectory = wxStandardPathsBase::Get().GetUserDataDir();

        if (!userDirectory.EndsWith(wxString(FreeFileSync::FILE_NAME_SEPARATOR)))
            userDirectory += FreeFileSync::FILE_NAME_SEPARATOR;

        if (!wxDirExists(userDirectory))
            try
            {
                FreeFileSync::createDirectory(userDirectory.c_str(), wxEmptyString, false);
            }
            catch (FreeFileSync::FileError&)
                {}

        return userDirectory + fileName;
    }
}


//save user configuration in OS' standard application folders
const wxString& FreeFileSync::getLastConfigFile()
{
    static wxString instance = assembleFileForUserData(wxT("LastRun.ffs_gui"));
    return instance;
}


const wxString& FreeFileSync::getGlobalConfigFile()
{
    static wxString instance = assembleFileForUserData(wxT("GlobalSettings.xml"));
    return instance;
}


const wxString& FreeFileSync::getDefaultLogDirectory()
{
    static wxString instance = assembleFileForUserData(wxT("Logs"));
    return instance;
}


const wxString& FreeFileSync::getLastErrorTxtFile()
{
    static wxString instance = assembleFileForUserData(wxT("LastError.txt"));
    return instance;
}


const wxString& FreeFileSync::getInstallationDir()
{
    static wxString instance = wxFileName(wxStandardPaths::Get().GetExecutablePath()).GetPath();
    return instance;
}


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


SyncConfiguration::Variant SyncConfiguration::getVariant()
{
    if (    exLeftSideOnly  == SYNC_DIR_RIGHT &&
            exRightSideOnly == SYNC_DIR_RIGHT &&
            leftNewer       == SYNC_DIR_RIGHT &&
            rightNewer      == SYNC_DIR_RIGHT &&
            different       == SYNC_DIR_RIGHT)
        return MIRROR;    //one way ->

    else if (exLeftSideOnly  == SYNC_DIR_RIGHT &&
             exRightSideOnly == SYNC_DIR_NONE  &&
             leftNewer       == SYNC_DIR_RIGHT &&
             rightNewer      == SYNC_DIR_NONE  &&
             different       == SYNC_DIR_NONE)
        return UPDATE;    //Update ->

    else if (exLeftSideOnly  == SYNC_DIR_RIGHT &&
             exRightSideOnly == SYNC_DIR_LEFT  &&
             leftNewer       == SYNC_DIR_RIGHT &&
             rightNewer      == SYNC_DIR_LEFT  &&
             different       == SYNC_DIR_NONE)
        return TWOWAY;    //two way <->
    else
        return CUSTOM;    //other
}


wxString SyncConfiguration::getVariantName()
{
    switch (getVariant())
    {
    case MIRROR:
        return _("Mirror ->>");
    case UPDATE:
        return _("Update ->");
    case TWOWAY:
        return _("Two way <->");
    case CUSTOM:
        return _("Custom");
    }

    return _("Error");
}


void SyncConfiguration::setVariant(const Variant var)
{
    switch (var)
    {
    case MIRROR:
        exLeftSideOnly  = SYNC_DIR_RIGHT;
        exRightSideOnly = SYNC_DIR_RIGHT;
        leftNewer       = SYNC_DIR_RIGHT;
        rightNewer      = SYNC_DIR_RIGHT;
        different       = SYNC_DIR_RIGHT;
        break;
    case UPDATE:
        exLeftSideOnly  = SYNC_DIR_RIGHT;
        exRightSideOnly = SYNC_DIR_NONE;
        leftNewer       = SYNC_DIR_RIGHT;
        rightNewer      = SYNC_DIR_NONE;
        different       = SYNC_DIR_NONE;
        break;
    case TWOWAY:
        exLeftSideOnly  = SYNC_DIR_RIGHT;
        exRightSideOnly = SYNC_DIR_LEFT;
        leftNewer       = SYNC_DIR_RIGHT;
        rightNewer      = SYNC_DIR_LEFT;
        different       = SYNC_DIR_NONE;
        break;
    case CUSTOM:
        assert(false);
        break;
    }
}
bgstack15