Giter Club home page Giter Club logo

Comments (1)

witchymary avatar witchymary commented on July 17, 2024

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

from aegisub.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.