summaryrefslogtreecommitdiff
path: root/shared/standardPaths.cpp
diff options
context:
space:
mode:
authorDaniel Wilhelm <daniel@wili.li>2014-04-18 17:05:30 +0200
committerDaniel Wilhelm <daniel@wili.li>2014-04-18 17:05:30 +0200
commitc0fce877c478ddbf71a1b651c789e5ea00a00144 (patch)
treede01b0ae8fd296bd24fbca54a80f2f0ba071d461 /shared/standardPaths.cpp
parent3.3 (diff)
downloadFreeFileSync-c0fce877c478ddbf71a1b651c789e5ea00a00144.tar.gz
FreeFileSync-c0fce877c478ddbf71a1b651c789e5ea00a00144.tar.bz2
FreeFileSync-c0fce877c478ddbf71a1b651c789e5ea00a00144.zip
3.4
Diffstat (limited to 'shared/standardPaths.cpp')
-rw-r--r--shared/standardPaths.cpp93
1 files changed, 58 insertions, 35 deletions
diff --git a/shared/standardPaths.cpp b/shared/standardPaths.cpp
index 3c57f5b9..018e31d0 100644
--- a/shared/standardPaths.cpp
+++ b/shared/standardPaths.cpp
@@ -1,3 +1,9 @@
+// **************************************************************************
+// * This file is part of the FreeFileSync project. It is distributed under *
+// * GNU General Public License: http://www.gnu.org/licenses/gpl.html *
+// * Copyright (C) 2008-2010 ZenJu (zhnmju123 AT gmx.de) *
+// **************************************************************************
+//
#include "standardPaths.h"
#include <wx/stdpaths.h>
#include <wx/filename.h>
@@ -6,58 +12,75 @@
using namespace FreeFileSync;
-
-wxString assembleFileForUserData(const wxString fileName)
+bool FreeFileSync::isPortableVersion()
{
- 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;
- }
+#ifdef FFS_WIN
+ static const bool isPortable = !wxFileExists(FreeFileSync::getBinaryDir() + wxT("uninstall.exe")); //this check is a bit lame...
+#elif defined FFS_LINUX
+ static const bool isPortable = !FreeFileSync::getBinaryDir().EndsWith(wxT("/bin/")); //this check is a bit lame...
+#endif
+ return isPortable;
}
-const wxString& FreeFileSync::getGlobalConfigFile()
+const wxString& FreeFileSync::getBinaryDir()
{
- static wxString instance = assembleFileForUserData(wxT("GlobalSettings.xml"));
+ static wxString instance = wxFileName(wxStandardPaths::Get().GetExecutablePath()).GetPath() + zToWx(globalFunctions::FILE_NAME_SEPARATOR);
return instance;
}
-const wxString& FreeFileSync::getDefaultLogDirectory()
+const wxString& FreeFileSync::getResourceDir()
{
- static wxString instance = assembleFileForUserData(wxT("Logs"));
- return instance;
-}
+#ifdef FFS_WIN
+ return getBinaryDir();
+#elif defined FFS_LINUX
+ static wxString resourceDir;
+ static bool isInitalized = false; //poor man's singleton...
+ if (!isInitalized)
+ {
+ isInitalized = true;
-const wxString& FreeFileSync::getLastErrorTxtFile()
-{
- static wxString instance = assembleFileForUserData(wxT("LastError.txt"));
- return instance;
-}
+ if (isPortableVersion())
+ return getBinaryDir();
+ else //use OS' standard paths
+ {
+ resourceDir = wxStandardPathsBase::Get().GetResourcesDir();
+ if (!resourceDir.EndsWith(zToWx(globalFunctions::FILE_NAME_SEPARATOR)))
+ resourceDir += zToWx(globalFunctions::FILE_NAME_SEPARATOR);
+ }
+ }
-const wxString& FreeFileSync::getInstallationDir()
-{
- static wxString instance = wxFileName(wxStandardPaths::Get().GetExecutablePath()).GetPath() + zToWx(globalFunctions::FILE_NAME_SEPARATOR);
- return instance;
+ return resourceDir;
+#endif
}
const wxString& FreeFileSync::getConfigDir()
{
- static wxString instance = assembleFileForUserData(wxEmptyString);
- return instance;
+ static wxString userDirectory;
+
+ static bool isInitalized = false; //poor man's singleton...
+ if (!isInitalized)
+ {
+ isInitalized = true;
+
+ if (isPortableVersion())
+ //userDirectory = wxString(wxT(".")) + zToWx(globalFunctions::FILE_NAME_SEPARATOR); //use current working directory
+ userDirectory = getBinaryDir(); //avoid surprises with GlobalSettings.xml being newly created in each working directory
+ else //use OS' standard paths
+ {
+ userDirectory = wxStandardPathsBase::Get().GetUserDataDir();
+
+ if (!wxDirExists(userDirectory))
+ ::wxMkdir(userDirectory); //only top directory needs to be created: no recursion necessary
+
+ if (!userDirectory.EndsWith(zToWx(globalFunctions::FILE_NAME_SEPARATOR)))
+ userDirectory += zToWx(globalFunctions::FILE_NAME_SEPARATOR);
+ }
+ }
+
+ return userDirectory;
}
bgstack15