Skip to content

Commit

Permalink
Basically support XDG Base Directory specification
Browse files Browse the repository at this point in the history
  • Loading branch information
WhiredPlanck committed Dec 21, 2021
1 parent f8dca9f commit 851201f
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions libaegisub/unix/path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,48 @@ 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");
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();
}
#endif
}

namespace agi {
void Path::FillPlatformSpecificPaths() {
#ifndef __APPLE__
agi::fs::path home = home_dir();
SetToken("?user", home/".aegisub");
SetToken("?local", home/".aegisub");
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");
} else {
SetToken("?user", prev_dir);
SetToken("?local", prev_dir);
}
SetToken("?data", P_DATA);
SetToken("?dictionary", "/usr/share/hunspell");
#else
Expand Down

0 comments on commit 851201f

Please sign in to comment.