35 namespace cloe::utility {
70 std::filesystem::path xdg_temp_dir();
73 std::filesystem::path xdg_getenv_path(
const std::string& env);
74 std::filesystem::path xdg_path(
const std::string& env,
const std::filesystem::path& default_path);
75 std::vector<std::filesystem::path> xdg_paths(
const std::string& env,
76 const std::string& default_paths);
81 std::filesystem::path xdg_find(
const std::filesystem::path& file,
82 const std::vector<std::filesystem::path>& dirs);
84 std::vector<std::filesystem::path> xdg_findall(
const std::filesystem::path& file,
85 const std::vector<std::filesystem::path>& dirs);
87 void xdg_merge(
const std::filesystem::path& file,
const std::vector<std::filesystem::path>& dirs,
88 bool reverse,
const std::function<
bool(
const std::filesystem::path&)>& mergefn);
93 return xdg_path(
"XDG_CONFIG_HOME",
"~/.config");
95 return xdg_path(
"XDG_CONFIG_HOME", xdg_getenv_path(
"LOCALAPPDATA"));
102 return xdg_path(
"XDG_DATA_HOME",
"~/.local/share");
104 return xdg_path(
"XDG_DATA_HOME", xdg_getenv_path(
"LOCALAPPDATA"));
111 return xdg_path(
"XDG_CACHE_HOME",
"~/.cache");
113 return xdg_path(
"XDG_CACHE_HOME", xdg_getenv_path(
"TEMP"));
120 return xdg_path(
"XDG_RUNTIME_DIR", xdg_temp_dir());
122 return xdg_path(
"XDG_CACHE_HOME", xdg_getenv_path(
"TEMP"));
129 return xdg_paths(
"XDG_CONFIG_DIRS",
"/etc/xdg");
131 return xdg_paths(
"XDG_CONFIG_DIRS", xdg_getenv_path(
"APPDATA").
string());
138 return xdg_paths(
"XDG_DATA_DIRS",
"/usr/local/share:/usr/share");
140 return xdg_paths(
"XDG_DATA_DIRS", xdg_getenv_path(
"APPDATA").
string());
163 inline std::filesystem::path user_config(
const std::filesystem::path& file) {
164 return config_home() / file;
166 inline std::filesystem::path user_data(
const std::filesystem::path& file) {
167 return data_home() / file;
169 inline std::filesystem::path user_cache(
const std::filesystem::path& file) {
172 inline std::filesystem::path user_runtime(
const std::filesystem::path& file) {
182 inline std::filesystem::path find_config(
const std::filesystem::path& file) {
185 inline std::filesystem::path find_data(
const std::filesystem::path& file) {
188 inline std::filesystem::path find_cache(
const std::filesystem::path& file) {
189 return xdg_find(file, std::vector<std::filesystem::path>{
cache_home()});
191 inline std::filesystem::path find_runtime(
const std::filesystem::path& file) {
192 return xdg_find(file, std::vector<std::filesystem::path>{
runtime_dir()});
201 inline std::vector<std::filesystem::path> find_all_config(
const std::filesystem::path& file) {
204 inline std::vector<std::filesystem::path> find_all_data(
const std::filesystem::path& file) {
216 inline void merge_config(
const std::filesystem::path& file,
217 const std::function<
bool(
const std::filesystem::path&)>& mergefn,
218 bool reverse =
false) {
222 inline void merge_data(
const std::filesystem::path& file,
223 const std::function<
bool(
const std::filesystem::path&)>& mergefn,
224 bool reverse =
false) {
std::vector< std::filesystem::path > config_dirs()
Global configuration directories, e.g., /etc/xdg.
Definition: xdg.hpp:127
std::filesystem::path cache_home()
User cache files base directory, e.g., ~/.cache.
Definition: xdg.hpp:109
std::filesystem::path runtime_dir()
User runtime files base directory, e.g., /run/user/1000
Definition: xdg.hpp:118
std::filesystem::path data_home()
User data files base directory, e.g., ~/.local/share.
Definition: xdg.hpp:100
std::vector< std::filesystem::path > data_dirs()
Global data files directories, e.g., /usr/local/share.
Definition: xdg.hpp:136
std::filesystem::path config_home()
User configuration base directory, e.g., ~./config.
Definition: xdg.hpp:91
XdgError
Definition: xdg.hpp:40
std::vector< std::filesystem::path > all_data_dirs()
User and global data directories.
Definition: xdg.hpp:152
std::vector< std::filesystem::path > all_config_dirs()
User and global configuration directories.
Definition: xdg.hpp:145