From 872d6fe7b86faa48cc01f0b4cf8d1dbaaf23ed4c Mon Sep 17 00:00:00 2001
From: David Carlier <devnexen@gmail.com>
Date: Sat, 2 Apr 2022 15:05:14 +0100
Subject: [PATCH] data directory more abstract for BSD/Haiku...

---
 Sources/Gui/Main.cpp | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/Sources/Gui/Main.cpp b/Sources/Gui/Main.cpp
index 0a9d6868..a299b357 100644
--- a/Sources/Gui/Main.cpp
+++ b/Sources/Gui/Main.cpp
@@ -387,8 +387,8 @@ int main(int argc, char **argv) {
 			}
 		}
 
-		spades::g_userResourceDirectory =
-		  home + "/Library/Application Support/OpenSpades/Resources";
+		spades::g_userResourceDirectory = SDL_GetPrefPath(nullptr, "OpenSpades");
+		spades::g_userResourceDirectory += "Resources";
 
 		spades::FileManager::AddFileSystem(
 		  new spades::DirectoryFileSystem(spades::g_userResourceDirectory, true));
@@ -400,18 +400,19 @@ int main(int argc, char **argv) {
 		spades::FileManager::AddFileSystem(new spades::DirectoryFileSystem(
 		  CMAKE_INSTALL_PREFIX "/" OPENSPADES_INSTALL_RESOURCES, false));
 
-		std::string xdg_data_home = home + "/.local/share";
+		std::string xdg_data_home = SDL_GetPrefPath(nullptr, "openspades");
 
 		if (getenv("XDG_DATA_HOME") == NULL) {
 			SPLog("XDG_DATA_HOME not defined. Assuming that XDG_DATA_HOME is ~/.local/share");
 		} else {
-			std::string xdg_data_home = getenv("XDG_DATA_HOME");
+			xdg_data_home = getenv("XDG_DATA_HOME");
+		        xdg_data_home += "/openspades";
 			SPLog("XDG_DATA_HOME is %s", xdg_data_home.c_str());
 		}
 
 		struct stat info;
 
-		if (stat((xdg_data_home + "/openspades").c_str(), &info) != 0) {
+		if (stat((xdg_data_home).c_str(), &info) != 0) {
 			if (stat((home + "/.openspades").c_str(), &info) != 0) {
 			} else if (info.st_mode & S_IFDIR) {
 				SPLog("Openspades directory in XDG_DATA_HOME not found, though old directory "
@@ -437,7 +438,7 @@ int main(int argc, char **argv) {
 			}
 		}
 
-		spades::g_userResourceDirectory = xdg_data_home + "/openspades/Resources";
+		spades::g_userResourceDirectory = xdg_data_home + "Resources";
 
 		spades::FileManager::AddFileSystem(
 		  new spades::DirectoryFileSystem(spades::g_userResourceDirectory, true));