Open justbispo opened 3 months ago
I have a patch that works on arch1's fork, if you're interested:
From ee22306713bfa5ecdac072dbab6f648421b295d0 Mon Sep 17 00:00:00 2001
From: witchymary
Date: Sun, 8 Oct 2023 14:39:05 -0300
Subject: [PATCH] XDG Support
---
libaegisub/unix/path.cpp | 21 +++++++++++++++++++--
1 file changed, 19 insertions(+), 2 deletions(-)
diff --git a/libaegisub/unix/path.cpp b/libaegisub/unix/path.cpp
index 7a2c9a465..e40961a01 100644
--- a/libaegisub/unix/path.cpp
+++ b/libaegisub/unix/path.cpp
@@ -42,6 +42,14 @@ std::string home_dir() {
throw agi::EnvironmentError("Could not get home directory. Make sure HOME is set.");
}
+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;
+ return fallback_directory;
+}
+
#ifdef APPIMAGE_BUILD
std::string exe_dir() {
char *exe, *dir;
@@ -71,8 +79,17 @@ 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_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);
+ }
#ifdef APPIMAGE_BUILD
agi::fs::path exe = exe_dir();
--
2.42.0
Implement the necessary changes to support the XDG Base Directory specification.
This issue was first brought up here with a bit more info, and a solution was presented in a pull request on wangqr's fork here.
I've tried to implement it myself on this fork, hoping I was lucky enough that it was just copy-paste with no issues, but it threw some errors and I don't know how to fix them since I don't have any knowledge of C++.