32 #include <Knownfolders.h>
33 #include <shlobj_core.h>
34 #pragma comment(lib, "comsuppw.lib")
35 #pragma comment(lib, "kernel32.lib")
64 static std::filesystem::path home_folder;
65 static std::mutex mtx;
66 std::lock_guard<std::mutex> lock(mtx);
68 if (home_folder.empty())
71 PWSTR pszPath =
nullptr;
72 HRESULT hr = SHGetKnownFolderPath(FOLDERID_Profile, 0,
nullptr, &pszPath);
74 if (hr == S_OK && pszPath)
76 home_folder = pszPath;
82#elif HAVE_PWD_H && HAVE_UNISTD_H
84 struct passwd* p = getpwuid(getuid());
89 home_folder = p->pw_dir;
91 #error Unsupported platform
110 using namespace std::string_literals;
112 static std::filesystem::path app_data_folder;
113 static std::mutex mtx;
114 std::lock_guard<std::mutex> lock(mtx);
117 PWSTR pszPath =
nullptr;
118 HRESULT hr = SHGetKnownFolderPath(FOLDERID_RoamingAppData, 0,
nullptr, &pszPath);
120 if (hr == S_OK && pszPath)
122 app_data_folder = pszPath;
129 #if defined(__linux__)
130 app_data_folder =
get_home_dir() /
".local"s /
"share"s;
131 #elif defined(__APPLE__)
132 app_data_folder =
get_home_dir() /
"Library" /
"Application Support";
134 #error Unknown platform (please extended the code to check an appropriate macro)
138 if (!std::filesystem::exists(app_data_folder))
143 return app_data_folder;
158 using namespace std::string_literals;
160 static std::filesystem::path cache_dir;
161 static std::mutex mtx;
162 std::lock_guard<std::mutex> lock(mtx);
165 PWSTR pszPath =
nullptr;
166 HRESULT hr = SHGetKnownFolderPath(FOLDERID_LocalAppData, 0,
nullptr, &pszPath);
168 if (hr == S_OK && pszPath)
177 #if defined(__linux__)
179 #elif defined(__APPLE__)
182 #error Unknown platform (please extended the code to check an appropriate macro)
186 if (!std::filesystem::exists(cache_dir))
A Cbeam-specific runtime error that also acts like std::runtime_error.
Definition runtime_error.hpp:46
Facilitates file I/O, path normalization, and directory operations in a cross-platform manner....
Definition io.hpp:36
std::filesystem::path get_user_cache_dir()
Retrieves the path for storing user-specific cache data.
Definition system_folders.hpp:156
std::filesystem::path get_user_data_dir()
Retrieves the path for storing user-specific application data.
Definition system_folders.hpp:108
std::filesystem::path get_home_dir()
Retrieves the path to the user's home directory, based on the operating system.
Definition system_folders.hpp:62
Header file to manage inclusion of windows.h with specific settings.