diff options
author | B Stack <bgstack15@gmail.com> | 2020-03-18 08:59:09 -0400 |
---|---|---|
committer | B Stack <bgstack15@gmail.com> | 2020-03-18 08:59:09 -0400 |
commit | 2c4db439d235b68478d90c450289d2d0ba418547 (patch) | |
tree | 5c378aa54f4bb65c081cf9a92530d8af1f1f53dd /FreeFileSync/Source/ffs_paths.cpp | |
parent | Merge branch '10.20' into 'master' (diff) | |
download | FreeFileSync-2c4db439d235b68478d90c450289d2d0ba418547.tar.gz FreeFileSync-2c4db439d235b68478d90c450289d2d0ba418547.tar.bz2 FreeFileSync-2c4db439d235b68478d90c450289d2d0ba418547.zip |
add upstream 10.21
Diffstat (limited to 'FreeFileSync/Source/ffs_paths.cpp')
-rw-r--r-- | FreeFileSync/Source/ffs_paths.cpp | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/FreeFileSync/Source/ffs_paths.cpp b/FreeFileSync/Source/ffs_paths.cpp new file mode 100644 index 00000000..843e702e --- /dev/null +++ b/FreeFileSync/Source/ffs_paths.cpp @@ -0,0 +1,103 @@ +// ***************************************************************************** +// * This file is part of the FreeFileSync project. It is distributed under * +// * GNU General Public License: https://www.gnu.org/licenses/gpl-3.0 * +// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved * +// ***************************************************************************** + +#include "ffs_paths.h" +#include <zen/file_access.h> +#include <zen/thread.h> +#include <zen/symlink_target.h> +#include <wx/stdpaths.h> +#include <wx/app.h> + + +using namespace zen; + + +namespace +{ +Zstring getProcessParentFolderPath() +{ + //buffer getSymlinkResolvedPath()! + //note: compiler generates magic-statics code => fine, we don't expect accesses during shutdown => don't need FunStatGlobal<> + static const Zstring exeFolderParentPath = [] + { + Zstring exeFolderPath = beforeLast(utfTo<Zstring>(wxStandardPaths::Get().GetExecutablePath()), FILE_NAME_SEPARATOR, IF_MISSING_RETURN_NONE); + try + { + //get rid of relative path fragments, e.g.: C:\Data\Projects\FreeFileSync\Source\..\Build\Bin + exeFolderPath = getSymlinkResolvedPath(exeFolderPath); //throw FileError + } + catch (FileError&) { assert(false); } + + return beforeLast(exeFolderPath, FILE_NAME_SEPARATOR, IF_MISSING_RETURN_NONE); + }(); + return exeFolderParentPath; +} +} + + + + +namespace +{ +//don't make this a function-scope static (avoid code-gen for "magic static") +//getFfsVolumeId() might be called during static destruction, e.g. async update check +std::once_flag onceFlagGetFfsVolumeId; +} + +VolumeId fff::getFfsVolumeId() //throw FileError +{ + static VolumeId volumeId; //POD => no "magic static" code gen + std::call_once(onceFlagGetFfsVolumeId, [] { volumeId = getVolumeId(getProcessParentFolderPath()); }); //throw FileError + return volumeId; +} + + +bool fff::isPortableVersion() +{ + return false; //users want local installation type: https://freefilesync.org/forum/viewtopic.php?t=5750 + +} + + +Zstring fff::getResourceDirPf() +{ + return getProcessParentFolderPath() + FILE_NAME_SEPARATOR + Zstr("Resources") + FILE_NAME_SEPARATOR; +} + + +Zstring fff::getConfigDirPathPf() +{ + //note: compiler generates magic-statics code => fine, we don't expect accesses during shutdown + static const Zstring cfgFolderPathPf = [] + { + //make independent from wxWidgets global variable "appname"; support being called by RealTimeSync + auto appName = wxTheApp->GetAppName(); + wxTheApp->SetAppName(L"FreeFileSync"); + ZEN_ON_SCOPE_EXIT(wxTheApp->SetAppName(appName)); + + //OS standard path (XDG layout): ~/.config/FreeFileSync + //wxBug: wxStandardPaths::GetUserDataDir() does not honor FileLayout_XDG flag + wxStandardPaths::Get().SetFileLayout(wxStandardPaths::FileLayout_XDG); + const Zstring cfgFolderPath = appendSeparator(utfTo<Zstring>(wxStandardPaths::Get().GetUserConfigDir())) + "FreeFileSync"; + + try //create the config folder if not existing + create "Logs" subfolder while we're at it + { + createDirectoryIfMissingRecursion(appendSeparator(cfgFolderPath) + Zstr("Logs")); //throw FileError + } + catch (FileError&) { assert(false); } + + return appendSeparator(cfgFolderPath); + }(); + return cfgFolderPathPf; +} + + +//this function is called by RealTimeSync!!! +Zstring fff::getFreeFileSyncLauncherPath() +{ + return getProcessParentFolderPath() + Zstr("/FreeFileSync"); + +} |