From f0cf89e80e6714a00093cb026d90ba1db5e5a736 Mon Sep 17 00:00:00 2001
From: Ra-V2 <rav.bernacki@gmail.com>
Date: Tue, 10 Dec 2019 19:17:42 +0000
Subject: change localization of save files


diff --git a/main.c b/main.c
index 392d09e..6ee8017 100644
--- a/main.c
+++ b/main.c
@@ -7,6 +7,16 @@
 #include <SDL_thread.h>
 // #include <pthread.h>
 
+#ifdef __HAIKU__
+#include <unistd.h>
+#include <libgen.h>
+#include <FindDirectory.h>
+#include <fs_info.h>
+#include <sys/stat.h>
+#include <bsd/string.h>
+#include <Errors.h>
+#endif
+
 #ifndef WINDOWS
 #include <unistd.h>
 #include <pwd.h>
@@ -1559,6 +1569,7 @@ int WINAPI WinMain (HINSTANCE hInstance,
 #ifdef MAEMO
 	putenv("SDL_VIDEO_X11_WMCLASS=lines");
 #endif
+	chdir(dirname(argv[0]));
 	game_mutex = SDL_CreateMutex();
 	if (gfx_init())
 		return 1;
@@ -1630,12 +1641,23 @@ char *get_path(int n)
 	static char path[255];
 
 #ifndef WINDOWS
+#ifdef __HAIKU__
+	dev_t volume = dev_for_path("/boot");
+	char buffer[B_PATH_NAME_LENGTH+B_FILE_NAME_LENGTH];
+	if(find_directory(B_USER_SETTINGS_DIRECTORY, volume, true, buffer, sizeof(buffer)) == B_OK)
+	{
+	strlcat(buffer, "/color_lines", sizeof(buffer));
+	mkdir(buffer, 0700);
+	strlcpy(path, buffer, sizeof(path));
+	}
+#else
 	struct passwd *pw;
 	pw = getpwuid(getuid());
 	if (!pw) {
 		strcpy(path, "/tmp");
 	} else 
 		snprintf(path, sizeof(path) - 32, "%s", pw->pw_dir);
+#endif
 #else
 	static char appdir[MAX_PATH];
 
@@ -1654,7 +1676,7 @@ char *get_path(int n)
 		strcpy( path, appdir );
                     }
 #endif
-
+#ifndef __HAIKU__
 	switch (n) {
 	case 0:
 		strcat(path,"/.lines-save");
@@ -1667,5 +1689,19 @@ char *get_path(int n)
 		break;	
 	}
 	return path;
+#else
+	switch (n) {
+	case 0:
+		strcat(path,"/lines-save");
+		break;
+	case 1:
+		strcat(path,"/lines-scores");
+		break;	
+	case 2:
+		strcat(path,"/lines");
+		break;	
+	}
+	return path;
+#endif
 }
 #endif
-- 
2.23.0

