Skip to content

Commit

Permalink
Added more special paths.
Browse files Browse the repository at this point in the history
  • Loading branch information
5cript committed Jul 7, 2024
1 parent f2f0378 commit 8baecb0
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
9 changes: 9 additions & 0 deletions include/roar/filesystem/special_paths.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
64 changes: 64 additions & 0 deletions src/roar/filesystem/special_paths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 8baecb0

Please sign in to comment.