From 8baecb0211aafc19aa5575332777afdbde09a78c Mon Sep 17 00:00:00 2001 From: Tim Ebbeke Date: Sun, 7 Jul 2024 23:20:25 +0200 Subject: [PATCH] Added more special paths. --- include/roar/filesystem/special_paths.hpp | 9 ++++ src/roar/filesystem/special_paths.cpp | 64 +++++++++++++++++++++++ 2 files changed, 73 insertions(+) diff --git a/include/roar/filesystem/special_paths.hpp b/include/roar/filesystem/special_paths.hpp index 0c0cb9ae..72213363 100644 --- a/include/roar/filesystem/special_paths.hpp +++ b/include/roar/filesystem/special_paths.hpp @@ -13,6 +13,15 @@ namespace Roar * %appdata% Linux: home. Windows: CSIDL_APPDATA * %localappdata% Linux: home. Windows: CSIDL_APPDATA_LOCAL * %temp% Linux: /tmp. Windows: ${USER}\AppData\Local\Temp + * %config_home% Linux: $XDG_CONFIG_HOME. Windows: CSIDL_APPDATA + * %config_home2% Linux: $XDG_CONFIG_HOME. Windows: CSIDL_MYDOCUMENTS + * %config_home3% Linux: $XDG_CONFIG_HOME. Windows: home + * %state_home% Linux: $XDG_CONFIG_HOME. Windows: CSIDL_APPDATA + * %state_home2% Linux: $XDG_CONFIG_HOME. Windows: CSIDL_MYDOCUMENTS + * %state_home3% Linux: $XDG_CONFIG_HOME. Windows: home + * %data_home% Linux: $XDG_DATA_HOME. Windows: CSIDL_APPDATA + * %data_home2% Linux: $XDG_DATA_HOME. Windows: CSIDL_MYDOCUMENTS + * %data_home3% Linux: $XDG_DATA_HOME. Windows: home * * * @param path diff --git a/src/roar/filesystem/special_paths.cpp b/src/roar/filesystem/special_paths.cpp index 1e8909b7..7ad77f21 100644 --- a/src/roar/filesystem/special_paths.cpp +++ b/src/roar/filesystem/special_paths.cpp @@ -31,6 +31,10 @@ namespace Roar { return getSpecialPath(CSIDL_APPDATA); } + std::filesystem::path getDocuments() + { + return getSpecialPath(CSIDL_MYDOCUMENTS); + } std::filesystem::path getLocalAppData() { return getSpecialPath(CSIDL_LOCAL_APPDATA); @@ -67,6 +71,27 @@ namespace Roar { return "/tmp"; } + std::filesystem::path getXdgConfigHome() + { + auto const* xdgConfigHome = getenv("XDG_CONFIG_HOME"); + if (xdgConfigHome != nullptr) + return {xdgConfigHome}; + return getHome() / ".config"; + } + std::filesystem::path getXdgStateHome() + { + auto const* xdgStateHome = getenv("XDG_STATE_HOME"); + if (xdgStateHome != nullptr) + return {xdgStateHome}; + return getHome() / ".local/state"; + } + std::filesystem::path getXdgDataHome() + { + auto const* xdgDataHome = getenv("XDG_DATA_HOME"); + if (xdgDataHome != nullptr) + return {xdgDataHome}; + return getHome() / ".local/share"; + } #endif } @@ -104,6 +129,45 @@ namespace Roar return path; if (tryAndMap("%temp%", getTemp)) return path; +#ifdef _WIN32 + if (tryAndMap("%config_home%", getAppData)) + return path; + if (tryAndMap("%config_home2%", getDocuments)) + return path; + if (tryAndMap("%config_home3%", getHome)) + return path; + if (tryAndMap("%state_home%", getAppData)) + return path; + if (tryAndMap("%state_home2%", getDocuments)) + return path; + if (tryAndMap("%state_home3%", getHome)) + return path; + if (tryAndMap("%data_home%", getAppData)) + return path; + if (tryAndMap("%data_home2%", getDocuments)) + return path; + if (tryAndMap("%data_home3%", getHome)) + return path; +#else + if (tryAndMap("%config_home%", getXdgConfigHome)) + return path; + if (tryAndMap("%config_home2%", getXdgConfigHome)) + return path; + if (tryAndMap("%config_home3%", getXdgConfigHome)) + return path; + if (tryAndMap("%state_home%", getXdgStateHome)) + return path; + if (tryAndMap("%state_home2%", getXdgStateHome)) + return path; + if (tryAndMap("%state_home3%", getXdgStateHome)) + return path; + if (tryAndMap("%data_home%", getXdgDataHome)) + return path; + if (tryAndMap("%data_home2%", getXdgDataHome)) + return path; + if (tryAndMap("%data_home3%", getXdgDataHome)) + return path; +#endif return path; }