-
Notifications
You must be signed in to change notification settings - Fork 631
Support XDG Base directory specification for Linux #264
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,6 +41,12 @@ std::string home_dir() { | |
| throw agi::EnvironmentError("Could not get home directory. Make sure HOME is set."); | ||
| } | ||
|
|
||
| std::string xdg_dir(std::string_view token, agi::fs::path const& fallback) { | ||
| const char *env = getenv(token.data()); | ||
| if (env) return env; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The environment variable must be ignored if it is empty or doesn't contain an absolute path |
||
| return fallback.string(); | ||
| } | ||
|
|
||
| #ifdef APPIMAGE_BUILD | ||
| std::string exe_dir() { | ||
| char *exe, *dir; | ||
|
|
@@ -70,12 +76,32 @@ namespace agi { | |
| void Path::FillPlatformSpecificPaths() { | ||
| #ifndef __APPLE__ | ||
| agi::fs::path home = home_dir(); | ||
| SetToken("?user", home/".aegisub"); | ||
| SetToken("?local", home/".aegisub"); | ||
| agi::fs::path old_root = home/".aegisub"; | ||
|
|
||
| agi::fs::path xdg_config = xdg_dir("XDG_CONFIG_HOME", home/".config"); | ||
| agi::fs::path xdg_cache = xdg_dir("XDG_CACHE_HOME", home/".cache"); | ||
| agi::fs::path xdg_state = xdg_dir("XDG_STATE_HOME", home/".local/state"); | ||
| agi::fs::path xdg_data = xdg_dir("XDG_DATA_HOME", home/".local/share"); | ||
|
|
||
| if (agi::fs::DirectoryExists(old_root)) { | ||
| SetToken("?user", old_root); | ||
| SetToken("?local", old_root); | ||
| SetToken("?state", old_root); | ||
| } else { | ||
| SetToken("?user", xdg_config/"aegisub"); | ||
| SetToken("?local", xdg_cache/"aegisub"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Calling a cache dir |
||
| SetToken("?state", xdg_state/"aegisub"); | ||
| } | ||
|
|
||
| #ifdef APPIMAGE_BUILD | ||
| agi::fs::path data = exe_dir(); | ||
| if (data == "") data = home/".aegisub"; | ||
| if (data == "") { | ||
| if (agi::fs::DirectoryExists(old_root)) { | ||
| data = old_root; | ||
| } else { | ||
| data = xdg_data/"aegisub" | ||
| } | ||
| } | ||
| SetToken("?data", data); | ||
| SetToken("?dictionary", Decode("?data/dictionaries")); | ||
| #else | ||
|
|
@@ -87,6 +113,7 @@ void Path::FillPlatformSpecificPaths() { | |
| agi::fs::path app_support = agi::util::GetApplicationSupportDirectory(); | ||
| SetToken("?user", app_support/"Aegisub"); | ||
| SetToken("?local", app_support/"Aegisub"); | ||
| SetToken("?state", app_support/"Aegisub"); | ||
| SetToken("?data", agi::util::GetBundleSharedSupportDirectory()); | ||
| SetToken("?dictionary", Decode("?data/dictionaries")); | ||
| #endif | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tokenis not the right name for the parameter... (env_namewould be better)