From 7360fb4151bd6c28f202d620a30a462199033efe Mon Sep 17 00:00:00 2001 From: Damglador Date: Fri, 30 May 2025 17:42:08 +0200 Subject: [PATCH 1/6] Move data directory to .local/share/barony Technically it is not how XDG dictates it should be, but for most users that will work just fine --- src/game.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/game.cpp b/src/game.cpp index 24b442dbf..4b608320a 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -6759,11 +6759,11 @@ int main(int argc, char** argv) #ifdef USE_EOS #ifdef STEAMWORKS //Steam + EOS - snprintf(outputdir, sizeof(outputdir), "%s/.barony", basepath); + snprintf(outputdir, sizeof(outputdir), "%s/.local/share/barony", basepath); #else //Just EOS. std::string firstDotdir(basepath); - firstDotdir += "/.barony/"; + firstDotdir += "/.local/share/barony/"; if (access(firstDotdir.c_str(), F_OK) == -1) { mkdir(firstDotdir.c_str(), 0777); //Since this mkdir is not equivalent to mkdir -p, have to create each part of the path manually. @@ -6772,7 +6772,7 @@ int main(int argc, char** argv) #endif #else //USE_EOS //No EOS. Could be Steam though. Or could also not. - snprintf(outputdir, sizeof(outputdir), "%s/.barony", basepath); + snprintf(outputdir, sizeof(outputdir), "%s/.local/share/barony", basepath); #endif if (access(outputdir, F_OK) == -1) { From 3fa380c017c97c96eb7634f0543034ccf657fd68 Mon Sep 17 00:00:00 2001 From: Damglador Date: Fri, 30 May 2025 17:43:45 +0200 Subject: [PATCH 2/6] Add more fmod directories These directories are for fmodengine on Arch Linux from the AUR package https://aur.archlinux.org/packages/fmodengine --- cmake/Modules/FindFMOD.cmake | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cmake/Modules/FindFMOD.cmake b/cmake/Modules/FindFMOD.cmake index cfa9a6265..7237a5629 100644 --- a/cmake/Modules/FindFMOD.cmake +++ b/cmake/Modules/FindFMOD.cmake @@ -23,6 +23,7 @@ FIND_PATH(FMOD_INCLUDE_DIR /opt/local/include/fmodstudio/ /opt/include/ /opt/include/fmodstudio/ + /opt/fmodengine/api/core/inc/ ) FIND_LIBRARY(FMOD_LIBRARY @@ -42,6 +43,7 @@ FIND_LIBRARY(FMOD_LIBRARY /opt/lib64 /opt/lib /usr/freeware/lib64 + /usr/lib/fmodengine ) if (FMOD_LIBRARY) From 94ef0f5ccc5759431be76f9a59f9ed65feb7e067 Mon Sep 17 00:00:00 2001 From: Damglador Date: Fri, 30 May 2025 19:50:47 +0200 Subject: [PATCH 3/6] Use XDG_DATA_HOME if exists, simplify code - Use $XDG_DATA_HOME/barony if the variable is longer than 0 (exists), otherwise fallback to $HOME/.local/share/barony - Made `basepath` a sting that already includes the barony folder in it, because it was getting added to `basepath` everywhere anyway - Replaced `mkdir(outputdir, 0777)` with `std::filesystem::create_directories`, which should check if all directories before target exist and create them if they don't. --- src/game.cpp | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/game.cpp b/src/game.cpp index 4b608320a..c712d7b2e 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -65,6 +65,7 @@ #include #include #include +#include static SDL_bool SDL_MouseModeBeforeSignal = SDL_FALSE; static int SDL_MouseShowBeforeSignal = SDL_ENABLE; @@ -6755,29 +6756,32 @@ int main(int argc, char** argv) strcpy(outputdir, "./"); #else #ifndef NINTENDO - char *basepath = getenv("HOME"); + std::string basepath; + if (strlen(getenv("XDG_DATA_HOME")) > 0) + { + printlog("Picked up XDG_DATA_HOME: %s", getenv("XDG_DATA_HOME")); + basepath = getenv("XDG_DATA_HOME"); + basepath += "/barony"; + } + else + { + printlog("XDG_DATA_HOME does not exit, using HOME"); + basepath = getenv("HOME"); + basepath += "/.local/share/barony"; + } #ifdef USE_EOS #ifdef STEAMWORKS //Steam + EOS - snprintf(outputdir, sizeof(outputdir), "%s/.local/share/barony", basepath); + snprintf(outputdir, sizeof(outputdir), "%s", basepath.c_str()); #else //Just EOS. - std::string firstDotdir(basepath); - firstDotdir += "/.local/share/barony/"; - if (access(firstDotdir.c_str(), F_OK) == -1) - { - mkdir(firstDotdir.c_str(), 0777); //Since this mkdir is not equivalent to mkdir -p, have to create each part of the path manually. - } - snprintf(outputdir, sizeof(outputdir), "%s/epicgames", firstDotdir.c_str()); + snprintf(outputdir, sizeof(outputdir), "%s/epicgames", basepath.c_str()); #endif #else //USE_EOS //No EOS. Could be Steam though. Or could also not. - snprintf(outputdir, sizeof(outputdir), "%s/.local/share/barony", basepath); + snprintf(outputdir, sizeof(outputdir), "%s", basepath.c_str()); #endif - if (access(outputdir, F_OK) == -1) - { - mkdir(outputdir, 0777); - } + std::filesystem::create_directories(outputdir); // mkdir -p from C++ 17 https://en.cppreference.com/w/cpp/filesystem/create_directory.html #else // !NINTENDO strcpy(outputdir, "save:"); #endif // NINTENDO From d4438d11bf04c769fad06100fc0e3cf5abf49c68 Mon Sep 17 00:00:00 2001 From: Damglador Date: Fri, 30 May 2025 22:09:54 +0200 Subject: [PATCH 4/6] Apply the same for editor.cpp --- src/editor.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/editor.cpp b/src/editor.cpp index 7cfab087c..0a5422d60 100644 --- a/src/editor.cpp +++ b/src/editor.cpp @@ -1579,10 +1579,21 @@ int main(int argc, char** argv) #ifdef WINDOWS strcpy(outputdir, "./"); #else - char *basepath = getenv("HOME"); - snprintf(outputdir, sizeof(outputdir), "%s/.barony", basepath); - if ( access(outputdir, F_OK) == -1 ) - mkdir(outputdir, 0777); + std::string basepath; + if (strlen(getenv("XDG_DATA_HOME")) > 0) + { + printlog("Picked up XDG_DATA_HOME: %s", getenv("XDG_DATA_HOME")); + basepath = getenv("XDG_DATA_HOME"); + basepath += "/barony"; + } + else + { + printlog("XDG_DATA_HOME does not exit, using HOME"); + basepath = getenv("HOME"); + basepath += "/.local/share/barony"; + } + snprintf(outputdir, sizeof(outputdir), "%s", basepath.c_str()); + std::filesystem::create_directories(outputdir); #endif // load default language file (english) From 9fb04c66b3c211d5f03effdebd21d8e39a5dbac7 Mon Sep 17 00:00:00 2001 From: Damglador Date: Fri, 30 May 2025 23:16:01 +0200 Subject: [PATCH 5/6] Include filesystem in editor.cpp --- src/editor.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/editor.cpp b/src/editor.cpp index 0a5422d60..758f66531 100644 --- a/src/editor.cpp +++ b/src/editor.cpp @@ -20,6 +20,9 @@ #include "init.hpp" #include "mod_tools.hpp" #include +#ifdef LINUX +#include +#endif #ifndef EDITOR #define EDITOR #endif From 00aad94a4ec9f22faf3c390a598c531e310a24b9 Mon Sep 17 00:00:00 2001 From: Damglador Date: Sat, 31 May 2025 15:09:40 +0200 Subject: [PATCH 6/6] Update game.cpp --- src/game.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/game.cpp b/src/game.cpp index c712d7b2e..dad2388e0 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -6759,13 +6759,13 @@ int main(int argc, char** argv) std::string basepath; if (strlen(getenv("XDG_DATA_HOME")) > 0) { - printlog("Picked up XDG_DATA_HOME: %s", getenv("XDG_DATA_HOME")); + printlog("Picked up $XDG_DATA_HOME: %s", getenv("XDG_DATA_HOME")); basepath = getenv("XDG_DATA_HOME"); basepath += "/barony"; } else { - printlog("XDG_DATA_HOME does not exit, using HOME"); + printlog("XDG_DATA_HOME does not exit, using ~/.local/share/barony"); basepath = getenv("HOME"); basepath += "/.local/share/barony"; }