|
7 | 7 | #include <algorithm> |
8 | 8 |
|
9 | 9 | #if defined(OS_WINDOWS) |
10 | | - #include <windows.h> |
11 | | - #include <shlobj.h> |
| 10 | +#include <windows.h> |
| 11 | +#include <shlobj.h> |
12 | 12 | #elif defined(OS_LINUX) || defined(OS_WEB) |
13 | | - #include <xdg.hpp> |
14 | | -# endif |
| 13 | +#include <xdg.hpp> |
| 14 | +#endif |
15 | 15 |
|
16 | | -namespace hex::paths { |
| 16 | +namespace hex::paths |
| 17 | +{ |
17 | 18 | const char* ApplicationName = "fluxengine"; |
18 | 19 |
|
19 | | - std::vector<std::fs::path> getDataPaths(bool includeSystemFolders) { |
| 20 | + std::vector<std::fs::path> getDataPaths(bool includeSystemFolders) |
| 21 | + { |
20 | 22 | std::vector<std::fs::path> paths; |
21 | 23 |
|
22 | | - #if defined(OS_WINDOWS) |
| 24 | +#if defined(OS_WINDOWS) |
23 | 25 |
|
24 | | - // In the portable Windows version, we just use the executable directory |
25 | | - // Prevent the use of the AppData folder here |
26 | | - if (!ImHexApi::System::isPortableVersion()) { |
27 | | - PWSTR wAppDataPath = nullptr; |
28 | | - if (SUCCEEDED(SHGetKnownFolderPath(FOLDERID_LocalAppData, KF_FLAG_CREATE, nullptr, &wAppDataPath))) { |
29 | | - paths.emplace_back(wAppDataPath); |
30 | | - CoTaskMemFree(wAppDataPath); |
31 | | - } |
| 26 | + // In the portable Windows version, we just use the executable directory |
| 27 | + // Prevent the use of the AppData folder here |
| 28 | + if (!ImHexApi::System::isPortableVersion()) |
| 29 | + { |
| 30 | + PWSTR wAppDataPath = nullptr; |
| 31 | + if (SUCCEEDED(SHGetKnownFolderPath(FOLDERID_LocalAppData, |
| 32 | + KF_FLAG_CREATE, |
| 33 | + nullptr, |
| 34 | + &wAppDataPath))) |
| 35 | + { |
| 36 | + paths.emplace_back(wAppDataPath); |
| 37 | + CoTaskMemFree(wAppDataPath); |
32 | 38 | } |
| 39 | + } |
33 | 40 |
|
34 | | - #elif defined(OS_MACOS) |
35 | | - |
36 | | - paths.push_back(wolv::io::fs::getApplicationSupportDirectoryPath() / ApplicationName); |
| 41 | +#elif defined(OS_MACOS) |
37 | 42 |
|
38 | | - #elif defined(OS_LINUX) || defined(OS_WEB) |
| 43 | + paths.push_back(wolv::io::fs::getApplicationSupportDirectoryPath() / |
| 44 | + ApplicationName); |
39 | 45 |
|
40 | | - paths.push_back(xdg::DataHomeDir()); |
| 46 | +#elif defined(OS_LINUX) || defined(OS_WEB) |
41 | 47 |
|
42 | | - auto dataDirs = xdg::DataDirs(); |
43 | | - std::copy(dataDirs.begin(), dataDirs.end(), std::back_inserter(paths)); |
| 48 | + paths.push_back(xdg::DataHomeDir()); |
44 | 49 |
|
45 | | - #endif |
| 50 | +#endif |
46 | 51 |
|
47 | | - #if defined(OS_MACOS) |
| 52 | +#if defined(OS_MACOS) |
48 | 53 |
|
49 | | - if (includeSystemFolders) { |
50 | | - if (auto executablePath = wolv::io::fs::getExecutablePath(); executablePath.has_value()) { |
51 | | - paths.push_back(executablePath->parent_path()); |
52 | | - } |
| 54 | + if (includeSystemFolders) |
| 55 | + { |
| 56 | + if (auto executablePath = wolv::io::fs::getExecutablePath(); |
| 57 | + executablePath.has_value()) |
| 58 | + { |
| 59 | + paths.push_back(executablePath->parent_path()); |
53 | 60 | } |
| 61 | + } |
54 | 62 |
|
55 | | - #else |
| 63 | +#else |
56 | 64 |
|
57 | | - for (auto &path : paths) |
58 | | - path = path / ApplicationName; |
| 65 | + for (auto& path : paths) |
| 66 | + path = path / ApplicationName; |
59 | 67 |
|
60 | | - if (ImHexApi::System::isPortableVersion() || includeSystemFolders) { |
61 | | - if (auto executablePath = wolv::io::fs::getExecutablePath(); executablePath.has_value()) |
62 | | - paths.push_back(executablePath->parent_path()); |
63 | | - } |
64 | | - |
65 | | - #endif |
| 68 | + if (ImHexApi::System::isPortableVersion() || includeSystemFolders) |
| 69 | + { |
| 70 | + if (auto executablePath = wolv::io::fs::getExecutablePath(); |
| 71 | + executablePath.has_value()) |
| 72 | + paths.push_back(executablePath->parent_path()); |
| 73 | + } |
66 | 74 |
|
| 75 | +#endif |
67 | 76 |
|
68 | 77 | // Add additional data directories to the path |
69 | 78 | auto additionalDirs = ImHexApi::System::getAdditionalFolderPaths(); |
70 | 79 | std::ranges::copy(additionalDirs, std::back_inserter(paths)); |
71 | 80 |
|
72 | 81 | // Add the project file directory to the path, if one is loaded |
73 | | - if (ProjectFile::hasPath()) { |
| 82 | + if (ProjectFile::hasPath()) |
| 83 | + { |
74 | 84 | paths.push_back(ProjectFile::getPath().parent_path()); |
75 | 85 | } |
76 | 86 |
|
77 | 87 | return paths; |
78 | 88 | } |
79 | 89 |
|
80 | | - std::vector<std::fs::path> getConfigPaths(bool includeSystemFolders) { |
81 | | - #if defined(OS_WINDOWS) |
82 | | - return getDataPaths(includeSystemFolders); |
83 | | - #elif defined(OS_MACOS) |
84 | | - return getDataPaths(includeSystemFolders); |
85 | | - #elif defined(OS_LINUX) || defined(OS_WEB) |
86 | | - std::ignore = includeSystemFolders; |
87 | | - return {xdg::ConfigHomeDir() / ApplicationName}; |
88 | | - #endif |
| 90 | + std::vector<std::fs::path> getConfigPaths(bool includeSystemFolders) |
| 91 | + { |
| 92 | +#if defined(OS_WINDOWS) |
| 93 | + return getDataPaths(includeSystemFolders); |
| 94 | +#elif defined(OS_MACOS) |
| 95 | + return getDataPaths(includeSystemFolders); |
| 96 | +#elif defined(OS_LINUX) || defined(OS_WEB) |
| 97 | + std::ignore = includeSystemFolders; |
| 98 | + return {xdg::ConfigHomeDir() / ApplicationName}; |
| 99 | +#endif |
89 | 100 | } |
90 | 101 |
|
91 | | - static std::vector<std::fs::path> appendPath(std::vector<std::fs::path> paths, std::fs::path folder) { |
| 102 | + static std::vector<std::fs::path> appendPath( |
| 103 | + std::vector<std::fs::path> paths, std::fs::path folder) |
| 104 | + { |
92 | 105 | folder.make_preferred(); |
93 | | - |
94 | | - for (auto &path : paths) |
| 106 | + |
| 107 | + for (auto& path : paths) |
95 | 108 | path = path / folder; |
96 | 109 |
|
97 | 110 | return paths; |
98 | 111 | } |
99 | 112 |
|
100 | | - static std::vector<std::fs::path> getPluginPaths() { |
| 113 | + static std::vector<std::fs::path> getPluginPaths() |
| 114 | + { |
101 | 115 | std::vector<std::fs::path> paths = getDataPaths(true); |
102 | 116 |
|
103 | | - // Add the system plugin directory to the path if one was provided at compile time |
104 | | - #if defined(OS_LINUX) && defined(SYSTEM_PLUGINS_LOCATION) |
105 | | - paths.push_back(SYSTEM_PLUGINS_LOCATION); |
106 | | - #endif |
| 117 | +// Add the system plugin directory to the path if one was provided at compile |
| 118 | +// time |
| 119 | +#if defined(OS_LINUX) && defined(SYSTEM_PLUGINS_LOCATION) |
| 120 | + paths.push_back(SYSTEM_PLUGINS_LOCATION); |
| 121 | +#endif |
107 | 122 |
|
108 | 123 | return paths; |
109 | 124 | } |
110 | 125 |
|
111 | | - namespace impl { |
| 126 | + namespace impl |
| 127 | + { |
112 | 128 |
|
113 | | - std::vector<std::fs::path> DefaultPath::read() const { |
| 129 | + std::vector<std::fs::path> DefaultPath::read() const |
| 130 | + { |
114 | 131 | auto result = this->all(); |
115 | 132 |
|
116 | | - std::erase_if(result, [](const auto &entryPath) { |
117 | | - return !wolv::io::fs::isDirectory(entryPath); |
118 | | - }); |
| 133 | + std::erase_if(result, |
| 134 | + [](const auto& entryPath) |
| 135 | + { |
| 136 | + return !wolv::io::fs::isDirectory(entryPath); |
| 137 | + }); |
119 | 138 |
|
120 | 139 | return result; |
121 | 140 | } |
122 | 141 |
|
123 | | - std::vector<std::fs::path> DefaultPath::write() const { |
| 142 | + std::vector<std::fs::path> DefaultPath::write() const |
| 143 | + { |
124 | 144 | auto result = this->read(); |
125 | 145 |
|
126 | | - std::erase_if(result, [](const auto &entryPath) { |
127 | | - return !hex::fs::isPathWritable(entryPath); |
128 | | - }); |
| 146 | + std::erase_if(result, |
| 147 | + [](const auto& entryPath) |
| 148 | + { |
| 149 | + return !hex::fs::isPathWritable(entryPath); |
| 150 | + }); |
129 | 151 |
|
130 | 152 | return result; |
131 | 153 | } |
132 | 154 |
|
133 | | - std::vector<std::fs::path> ConfigPath::all() const { |
| 155 | + std::vector<std::fs::path> ConfigPath::all() const |
| 156 | + { |
134 | 157 | return appendPath(getConfigPaths(false), m_postfix); |
135 | 158 | } |
136 | 159 |
|
137 | | - std::vector<std::fs::path> DataPath::all() const { |
| 160 | + std::vector<std::fs::path> DataPath::all() const |
| 161 | + { |
138 | 162 | return appendPath(getDataPaths(true), m_postfix); |
139 | 163 | } |
140 | 164 |
|
141 | | - std::vector<std::fs::path> DataPath::write() const { |
| 165 | + std::vector<std::fs::path> DataPath::write() const |
| 166 | + { |
142 | 167 | auto result = appendPath(getDataPaths(false), m_postfix); |
143 | 168 |
|
144 | | - std::erase_if(result, [](const auto &entryPath) { |
145 | | - return !hex::fs::isPathWritable(entryPath); |
146 | | - }); |
| 169 | + std::erase_if(result, |
| 170 | + [](const auto& entryPath) |
| 171 | + { |
| 172 | + return !hex::fs::isPathWritable(entryPath); |
| 173 | + }); |
147 | 174 |
|
148 | 175 | return result; |
149 | 176 | } |
150 | 177 |
|
151 | | - std::vector<std::fs::path> PluginPath::all() const { |
| 178 | + std::vector<std::fs::path> PluginPath::all() const |
| 179 | + { |
152 | 180 | return appendPath(getPluginPaths(), m_postfix); |
153 | 181 | } |
154 | 182 |
|
|
0 commit comments