blob: 01a9a6958dbdc18615214007e3b7ccb23f480dbe (
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
|
// *****************************************************************************
// * 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/sys_info.h>
#include <iostream> //std::cerr
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 = []
{
try
{
const Zstring& processPath = getProcessPath(); //throw FileError
/* no need for getSymlinkResolvedPath():
=> support file systems with buggy GetFinalPathNameByHandle() implementation, e.g. Dokany-based: https://freefilesync.org/forum/viewtopic.php?t=8828
=> we're already supporting calling FFS via symlink for launcher executable, which guarantees: */
assert(getItemType( processPath) != ItemType::symlink); //throw FileError
assert(getItemType(*getParentFolderPath(processPath)) != ItemType::symlink); //throw FileError
return *getParentFolderPath(*getParentFolderPath(processPath)); //no parent folder!!? => let it crash!
}
catch (const FileError& e)
{
throw std::runtime_error(std::string(__FILE__) + '[' + numberTo<std::string>(__LINE__) + "] Failed to get process parent folder. " + utfTo<std::string>(e.toString()));
}
}();
return exeFolderParentPath;
}
}
Zstring fff::getInstallDirPath()
{
return getProcessParentFolderPath();
}
Zstring fff::getResourceDirPath()
{
return appendPath(getProcessParentFolderPath(), Zstr("Resources"));
}
Zstring fff::getConfigDirPath()
{
//note: compiler generates magic-statics code => fine, we don't expect accesses during shutdown
static const Zstring ffsConfigPath = []
{
/* Windows: %AppData%\FreeFileSync
macOS: ~/Library/Application Support/FreeFileSync
Linux (XDG layout): ~/.config/FreeFileSync */
const Zstring& configPath = []
{
try
{
return appendPath(getUserDataPath(), Zstr("FreeFileSync")); //throw FileError
}
catch (const FileError& e)
{
throw std::runtime_error(std::string(__FILE__) + '[' + numberTo<std::string>(__LINE__) + "] Failed to get config path. " + utfTo<std::string>(e.toString()));
}
}();
try
{
createDirectoryIfMissingRecursion(configPath); //throw FileError
}
catch (const FileError& e) { logExtraError(e.toString()); }
return configPath;
}();
return ffsConfigPath;
}
//this function is called by RealTimeSync!!!
Zstring fff::getFreeFileSyncLauncherPath() //throw FileError
{
return appendPath(getInstallDirPath(), Zstr("FreeFileSync"));
}
|