diff options
author | Daniel Wilhelm <daniel@wili.li> | 2014-04-18 17:15:39 +0200 |
---|---|---|
committer | Daniel Wilhelm <daniel@wili.li> | 2014-04-18 17:15:39 +0200 |
commit | d2854834e18443876c8f75e0a7f3b88d1d549fc4 (patch) | |
tree | e967b628081e50abc7c34cd264e6586271c7e728 /lib/ffs_paths.h | |
parent | 4.1 (diff) | |
download | FreeFileSync-d2854834e18443876c8f75e0a7f3b88d1d549fc4.tar.gz FreeFileSync-d2854834e18443876c8f75e0a7f3b88d1d549fc4.tar.bz2 FreeFileSync-d2854834e18443876c8f75e0a7f3b88d1d549fc4.zip |
4.2
Diffstat (limited to 'lib/ffs_paths.h')
-rw-r--r-- | lib/ffs_paths.h | 44 |
1 files changed, 26 insertions, 18 deletions
diff --git a/lib/ffs_paths.h b/lib/ffs_paths.h index faecd2e2..0ad02b15 100644 --- a/lib/ffs_paths.h +++ b/lib/ffs_paths.h @@ -9,6 +9,7 @@ #include <wx/stdpaths.h> #include <zen/zstring.h> +#include <zen/file_handling.h> #include <wx+/string_conv.h> namespace zen @@ -16,11 +17,11 @@ namespace zen //------------------------------------------------------------------------------ //global program directories //------------------------------------------------------------------------------ -wxString getResourceDir(); //resource directory WITH path separator at end -wxString getConfigDir(); //config directory WITH path separator at end +Zstring getResourceDir(); //resource directory WITH path separator at end +Zstring getConfigDir(); //config directory WITH path separator at end //------------------------------------------------------------------------------ -wxString getLauncher(); //full path to application launcher C:\...\FreeFileSync.exe +Zstring getLauncher(); //full path to application launcher C:\...\FreeFileSync.exe bool isPortableVersion(); @@ -34,21 +35,22 @@ bool isPortableVersion(); + //---------------- implementation ---------------- namespace impl { inline -const wxString& getBinaryDir() //directory containing executable WITH path separator at end +const Zstring& getBinaryDir() //directory containing executable WITH path separator at end { - static wxString instance = beforeLast(wxStandardPaths::Get().GetExecutablePath(), FILE_NAME_SEPARATOR) + toWx(Zstring(FILE_NAME_SEPARATOR)); //extern linkage! + static Zstring instance = beforeLast(toZ(wxStandardPaths::Get().GetExecutablePath()), FILE_NAME_SEPARATOR) + Zstring(FILE_NAME_SEPARATOR); //extern linkage! return instance; } #ifdef FFS_WIN inline -wxString getInstallDir() //root install directory WITH path separator at end +Zstring getInstallDir() //root install directory WITH path separator at end { - return getBinaryDir().BeforeLast(FILE_NAME_SEPARATOR).BeforeLast(FILE_NAME_SEPARATOR) + FILE_NAME_SEPARATOR; + return beforeLast(beforeLast(getBinaryDir(), FILE_NAME_SEPARATOR), FILE_NAME_SEPARATOR) + FILE_NAME_SEPARATOR; } #endif } @@ -58,25 +60,27 @@ inline bool isPortableVersion() { #ifdef FFS_WIN - static const bool isPortable = !wxFileExists(impl::getInstallDir() + wxT("uninstall.exe")); //this check is a bit lame... + static const bool isPortable = !fileExists(impl::getInstallDir() + L"uninstall.exe"); //this check is a bit lame... + #elif defined FFS_LINUX - static const bool isPortable = !impl::getBinaryDir().EndsWith(wxT("/bin/")); //this check is a bit lame... + static const bool isPortable = !endsWith(impl::getBinaryDir(), "/bin/"); //this check is a bit lame... #endif return isPortable; } inline -wxString getResourceDir() +Zstring getResourceDir() { #ifdef FFS_WIN return impl::getInstallDir(); + #elif defined FFS_LINUX if (isPortableVersion()) return impl::getBinaryDir(); else //use OS' standard paths { - wxString resourceDir = wxStandardPathsBase::Get().GetResourcesDir(); + Zstring resourceDir = toZ(wxStandardPathsBase::Get().GetResourcesDir()); if (!endsWith(resourceDir, FILE_NAME_SEPARATOR)) resourceDir += FILE_NAME_SEPARATOR; @@ -88,7 +92,7 @@ wxString getResourceDir() inline -wxString getConfigDir() +Zstring getConfigDir() { if (isPortableVersion()) #ifdef FFS_WIN @@ -100,10 +104,14 @@ wxString getConfigDir() #endif else //use OS' standard paths { - wxString userDirectory = wxStandardPathsBase::Get().GetUserDataDir(); + Zstring userDirectory = toZ(wxStandardPathsBase::Get().GetUserDataDir()); - if (!wxDirExists(userDirectory)) - ::wxMkdir(userDirectory); //only top directory needs to be created: no recursion necessary + if (!dirExists(userDirectory)) + try + { + createDirectory(userDirectory); //only top directory needs to be created: no recursion necessary + } + catch (const FileError&) {} if (!endsWith(userDirectory, FILE_NAME_SEPARATOR)) userDirectory += FILE_NAME_SEPARATOR; @@ -114,12 +122,12 @@ wxString getConfigDir() inline -wxString getLauncher() +Zstring getLauncher() { #ifdef FFS_WIN - return impl::getInstallDir() + wxT("FreeFileSync.exe"); + return impl::getInstallDir() + Zstr("FreeFileSync.exe"); #elif defined FFS_LINUX - return impl::getBinaryDir() + wxT("FreeFileSync"); + return impl::getBinaryDir() + Zstr("FreeFileSync"); #endif } } |