summaryrefslogtreecommitdiff
path: root/shared/standardPaths.cpp
blob: 3c57f5b9fcc1aba70b9b7c2557ff995d57f37137 (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
#include "standardPaths.h"
#include <wx/stdpaths.h>
#include <wx/filename.h>
#include "systemConstants.h"
#include "stringConv.h"

using namespace FreeFileSync;


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

    if (isPortableVersion) //use current working directory
        return wxString(wxT(".")) + zToWx(globalFunctions::FILE_NAME_SEPARATOR) + fileName;
    else //usen OS' standard paths
    {
        wxString userDirectory = wxStandardPathsBase::Get().GetUserDataDir();

        if (!userDirectory.EndsWith(zToWx(globalFunctions::FILE_NAME_SEPARATOR)))
            userDirectory += zToWx(globalFunctions::FILE_NAME_SEPARATOR);

        if (!wxDirExists(userDirectory))
            ::wxMkdir(userDirectory); //only top directory needs to be created: no recursion necessary

        return userDirectory + fileName;
    }
}


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() + zToWx(globalFunctions::FILE_NAME_SEPARATOR);
    return instance;
}


const wxString& FreeFileSync::getConfigDir()
{
    static wxString instance = assembleFileForUserData(wxEmptyString);
    return instance;
}
bgstack15