Skip to content

Commit

Permalink
Simplify XDG Base Directory support code
Browse files Browse the repository at this point in the history
Capitalize app name in the paths.
  • Loading branch information
WhiredPlanck committed Mar 6, 2022
1 parent 851201f commit 8e1fdd1
Showing 1 changed file with 9 additions and 25 deletions.
34 changes: 9 additions & 25 deletions libaegisub/unix/path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,12 @@ std::string home_dir() {
throw agi::EnvironmentError("Could not get home directory. Make sure HOME is set.");
}

std::string xdg_config_home_dir() {
const char *env = getenv("XDG_CONFIG_HOME");
std::string xdg_dir(const std::string &environment_variable,
const std::string &fallback_directory)
{
const char *env = getenv(environment_variable.c_str());
if (env && *env) return env;

agi::fs::path home = home_dir();
return (home/".config").string();
}

std::string xdg_cache_home_dir() {
const char *env = getenv("XDG_CACHE_HOME");
if (env && *env) return env;

agi::fs::path home = home_dir();
return (home/".cache").string();
}

std::string xdg_data_home_dir() {
const char *env = getenv("XDG_DATA_HOME");
if (env && *env) return env;

agi::fs::path home = home_dir();
return (home/".local/share").string();
return fallback_directory;
}
#endif
}
Expand All @@ -69,10 +53,10 @@ void Path::FillPlatformSpecificPaths() {
agi::fs::path prev_dir = home/".aegisub";
if (!boost::filesystem::exists(prev_dir))
{
agi::fs::path xdg_config_home = xdg_config_home_dir();
agi::fs::path xdg_cache_home = xdg_cache_home_dir();
SetToken("?user", xdg_config_home/"aegisub");
SetToken("?local", xdg_cache_home/"aegisub");
agi::fs::path xdg_config_home = xdg_dir("XDG_CONFIG_HOME", (home/".config").string());
agi::fs::path xdg_cache_home = xdg_dir("XDG_CACHE_HOME", (home/".cache").string());
SetToken("?user", xdg_config_home/"Aegisub");
SetToken("?local", xdg_cache_home/"Aegisub");
} else {
SetToken("?user", prev_dir);
SetToken("?local", prev_dir);
Expand Down

0 comments on commit 8e1fdd1

Please sign in to comment.