by toxicbits » Thu Mar 22, 2018 6:05 am
GZDoom should use the path defined in the environment variable XDG_CONFIG_HOME and if it's not defined, fall back to ~/.config. Cf. the XDG Base Directory Specification:
https://standards.freedesktop.org/based ... atest.html
This makes it easier to package. I've tried to fix this myself, but somehow configPath still contains ~/.config in the
block even if it should contain the value of the environment variable.
Examples of XDG_CONFIG_HOME usage:
https://github.com/chocolate-doom/choco ... 445e6365d5
https://github.com/Novum/vkQuake/pull/116/files
My patch:
Spoiler:
Code: Select all
From f3c4d5a2cb8a210b076caf78d4d36202fc6fe898 Mon Sep 17 00:00:00 2001
From: toxicbits
Date: Thu, 8 Mar 2018 21:43:54 +0100
Subject: [PATCH] Use XDG_CONFIG_HOME if it's defined
---
src/posix/unix/i_specialpaths.cpp | 27 ++++++++++++++++++++++-----
1 file changed, 23 insertions(+), 5 deletions(-)
diff --git a/src/posix/unix/i_specialpaths.cpp b/src/posix/unix/i_specialpaths.cpp
index 60cc12fcf..61ff54a3c 100644
--- a/src/posix/unix/i_specialpaths.cpp
+++ b/src/posix/unix/i_specialpaths.cpp
@@ -40,6 +40,7 @@
#include "version.h" // for GAMENAME
+#include <iostream>
FString GetUserFile (const char *file)
{
@@ -53,12 +54,22 @@ FString GetUserFile (const char *file)
struct stat extrainfo;
// Sanity check for $HOME/.config
- FString configPath = NicePath("$HOME/.config/");
+ FString pathString = "$XDG_CONFIG_HOME";
+ std::cout << "NicePath(pathString).GetChars(): " << NicePath(pathString).GetChars() << std::endl;
+ if (NicePath("$XDG_CONFIG_HOME").IsEmpty())
+ {
+ std::cout << "$XDG_CONFIG_HOME was empty" << std::endl; pathString = "$HOME/.config/";
+ }
+ std::cout << "NicePath(pathString).GetChars():" << NicePath(pathString).GetChars() << std::endl;
+ FString configPath = NicePath(pathString);
+ std::cout << "configPath.GetChars(): " << configPath.GetChars() << std::endl;
if (stat (configPath, &extrainfo) == -1)
{
if (mkdir (configPath, S_IRUSR | S_IWUSR | S_IXUSR) == -1)
{
- I_FatalError ("Failed to create $HOME/.config directory:\n%s", strerror(errno));
+ std::cout << configPath.GetChars() << std::endl;
+ I_FatalError ("Failed to create %s directory:\n%s <- pathString", pathString.GetChars(), strerror(errno));
+ I_FatalError ("Failed to create %s directory:\n%s <- configPath", configPath.GetChars(), strerror(errno));
}
}
else if (!S_ISDIR(extrainfo.st_mode))
@@ -80,7 +90,6 @@ FString GetUserFile (const char *file)
else
moved = true;
}
-
if (!moved && mkdir (path, S_IRUSR | S_IWUSR | S_IXUSR) == -1)
{
I_FatalError ("Failed to create %s directory:\n%s",
@@ -110,7 +119,11 @@ FString M_GetAppDataPath(bool create)
{
// Don't use GAME_DIR and such so that ZDoom and its child ports can
// share the node cache.
- FString path = NicePath("$HOME/.config/" GAMENAMELOWERCASE);
+ FString path = NicePath("$XDG_CONFIG_HOME/" GAMENAMELOWERCASE);
+ if (NicePath("$XDG_CONFIG_HOME/").IsEmpty())
+ {
+ path = NicePath("$HOME/.config/" GAMENAMELOWERCASE);
+ }
if (create)
{
CreatePath(path);
@@ -130,7 +143,11 @@ FString M_GetCachePath(bool create)
{
// Don't use GAME_DIR and such so that ZDoom and its child ports can
// share the node cache.
- FString path = NicePath("$HOME/.config/zdoom/cache");
+ FString path = NicePath("$XDG_CONFIG_HOME/zdoom/cache");
+ if (NicePath("$XDG_CONFIG_HOME/").IsEmpty())
+ {
+ path = NicePath("$HOME/.config/zdoom/cache");
+ }
if (create)
{
CreatePath(path);
--
2.14.3
GZDoom should use the path defined in the environment variable XDG_CONFIG_HOME and if it's not defined, fall back to ~/.config. Cf. the XDG Base Directory Specification: https://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
This makes it easier to package. I've tried to fix this myself, but somehow configPath still contains ~/.config in the [code]if (mkdir[/code] block even if it should contain the value of the environment variable.
Examples of XDG_CONFIG_HOME usage:
https://github.com/chocolate-doom/chocolate-doom/commit/d1d65f2567d4943e2103414e793b0e445e6365d5
https://github.com/Novum/vkQuake/pull/116/files
My patch:
[spoiler][code]From f3c4d5a2cb8a210b076caf78d4d36202fc6fe898 Mon Sep 17 00:00:00 2001
From: toxicbits
Date: Thu, 8 Mar 2018 21:43:54 +0100
Subject: [PATCH] Use XDG_CONFIG_HOME if it's defined
---
src/posix/unix/i_specialpaths.cpp | 27 ++++++++++++++++++++++-----
1 file changed, 23 insertions(+), 5 deletions(-)
diff --git a/src/posix/unix/i_specialpaths.cpp b/src/posix/unix/i_specialpaths.cpp
index 60cc12fcf..61ff54a3c 100644
--- a/src/posix/unix/i_specialpaths.cpp
+++ b/src/posix/unix/i_specialpaths.cpp
@@ -40,6 +40,7 @@
#include "version.h" // for GAMENAME
+#include <iostream>
FString GetUserFile (const char *file)
{
@@ -53,12 +54,22 @@ FString GetUserFile (const char *file)
struct stat extrainfo;
// Sanity check for $HOME/.config
- FString configPath = NicePath("$HOME/.config/");
+ FString pathString = "$XDG_CONFIG_HOME";
+ std::cout << "NicePath(pathString).GetChars(): " << NicePath(pathString).GetChars() << std::endl;
+ if (NicePath("$XDG_CONFIG_HOME").IsEmpty())
+ {
+ std::cout << "$XDG_CONFIG_HOME was empty" << std::endl; pathString = "$HOME/.config/";
+ }
+ std::cout << "NicePath(pathString).GetChars():" << NicePath(pathString).GetChars() << std::endl;
+ FString configPath = NicePath(pathString);
+ std::cout << "configPath.GetChars(): " << configPath.GetChars() << std::endl;
if (stat (configPath, &extrainfo) == -1)
{
if (mkdir (configPath, S_IRUSR | S_IWUSR | S_IXUSR) == -1)
{
- I_FatalError ("Failed to create $HOME/.config directory:\n%s", strerror(errno));
+ std::cout << configPath.GetChars() << std::endl;
+ I_FatalError ("Failed to create %s directory:\n%s <- pathString", pathString.GetChars(), strerror(errno));
+ I_FatalError ("Failed to create %s directory:\n%s <- configPath", configPath.GetChars(), strerror(errno));
}
}
else if (!S_ISDIR(extrainfo.st_mode))
@@ -80,7 +90,6 @@ FString GetUserFile (const char *file)
else
moved = true;
}
-
if (!moved && mkdir (path, S_IRUSR | S_IWUSR | S_IXUSR) == -1)
{
I_FatalError ("Failed to create %s directory:\n%s",
@@ -110,7 +119,11 @@ FString M_GetAppDataPath(bool create)
{
// Don't use GAME_DIR and such so that ZDoom and its child ports can
// share the node cache.
- FString path = NicePath("$HOME/.config/" GAMENAMELOWERCASE);
+ FString path = NicePath("$XDG_CONFIG_HOME/" GAMENAMELOWERCASE);
+ if (NicePath("$XDG_CONFIG_HOME/").IsEmpty())
+ {
+ path = NicePath("$HOME/.config/" GAMENAMELOWERCASE);
+ }
if (create)
{
CreatePath(path);
@@ -130,7 +143,11 @@ FString M_GetCachePath(bool create)
{
// Don't use GAME_DIR and such so that ZDoom and its child ports can
// share the node cache.
- FString path = NicePath("$HOME/.config/zdoom/cache");
+ FString path = NicePath("$XDG_CONFIG_HOME/zdoom/cache");
+ if (NicePath("$XDG_CONFIG_HOME/").IsEmpty())
+ {
+ path = NicePath("$HOME/.config/zdoom/cache");
+ }
if (create)
{
CreatePath(path);
--
2.14.3
[/code][/spoiler]