From b74acc13daf1c8591cce1ddb06d0e60b48d48166 Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Sat, 27 Oct 2018 18:51:08 +1000
Subject: Use find_directory


diff --git a/backends/platform/sdl/posix/posix.cpp b/backends/platform/sdl/posix/posix.cpp
index abae7b1..5094bb7 100644
--- a/backends/platform/sdl/posix/posix.cpp
+++ b/backends/platform/sdl/posix/posix.cpp
@@ -49,6 +49,10 @@
 #include <sys/wait.h>
 #include <unistd.h>
 
+#ifdef __HAIKU__
+#include <FindDirectory.h>
+#endif
+
 OSystem_POSIX::OSystem_POSIX(Common::String baseConfigName)
 	:
 	_baseConfigName(baseConfigName) {
@@ -93,6 +97,15 @@ Common::String OSystem_POSIX::getDefaultConfigFileName() {
 	Common::String prefix;
 #ifdef MACOSX
 	prefix = getenv("HOME");
+#elif defined(__HAIKU__)
+	static char settingsDir[PATH_MAX] = "";
+	if (find_directory(B_USER_SETTINGS_DIRECTORY, -1, false, settingsDir, sizeof(settingsDir)) == B_OK) {
+		prefix = settingsDir;
+		prefix += "/ResidualVM";
+	} else {
+		prefix = "/boot/home/config/settings/ResidualVM";
+	}
+	mkdir(prefix.c_str(), 0755);
 #elif !defined(SAMSUNGTV)
 	const char *envVar;
 	// Our old configuration file path for POSIX systems was ~/.residualvmrc.
@@ -180,6 +193,14 @@ Common::WriteStream *OSystem_POSIX::createLogFile() {
 #elif SAMSUNGTV
 	prefix = nullptr;
 	logFile = "/mtd_ram";
+#elif defined(__HAIKU__)
+	static char cacheDir[PATH_MAX] = "";
+	if (find_directory(B_USER_CACHE_DIRECTORY, -1, false, cacheDir, sizeof(cacheDir)) == B_OK) {
+		prefix = cacheDir;
+	} else {
+		prefix = "/boot/home/config/cache";
+	}
+	logFile = "ResidualVM/logs";
 #else
 	// On POSIX systems we follow the XDG Base Directory Specification for
 	// where to store files. The version we based our code upon can be found
@@ -268,6 +289,11 @@ bool OSystem_POSIX::displayLogFile() {
 bool OSystem_POSIX::openUrl(const Common::String &url) {
 	// inspired by Qt's "qdesktopservices_x11.cpp"
 
+#ifdef __HAIKU__
+	if (launchBrowser("open", url))
+		return true;
+#endif
+
 	// try "standards"
 	if (launchBrowser("xdg-open", url))
 		return true;
diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp
index 415eb36..130f02a 100644
--- a/backends/platform/sdl/sdl.cpp
+++ b/backends/platform/sdl/sdl.cpp
@@ -426,8 +426,11 @@ void OSystem_SDL::launcherInitSize(uint w, uint h) {
 	Graphics::RendererType matchingRendererType = Graphics::getBestMatchingAvailableRendererType(desiredRendererType);
 
 	bool fullscreen = ConfMan.getBool("fullscreen");
-
+#ifdef __HAIKU__
+	setupScreen(w, h, fullscreen, false);
+#else
 	setupScreen(w, h, fullscreen, matchingRendererType != Graphics::kRendererTypeTinyGL);
+#endif
 }
 // End of ResidualVM specific code
 
diff --git a/backends/saves/posix/posix-saves.cpp b/backends/saves/posix/posix-saves.cpp
index 84be67b..0d8fd58 100644
--- a/backends/saves/posix/posix-saves.cpp
+++ b/backends/saves/posix/posix-saves.cpp
@@ -44,6 +44,10 @@
 #include <errno.h>
 #include <sys/stat.h>
 
+#ifdef __HAIKU__
+#include <FindDirectory.h>
+#endif
+
 POSIXSaveFileManager::POSIXSaveFileManager() {
 	// Register default savepath.
 #if defined(SAMSUNGTV)
@@ -59,7 +63,16 @@ POSIXSaveFileManager::POSIXSaveFileManager() {
 
 		ConfMan.registerDefault("savepath", savePath);
 	}
-
+#elif defined(__HAIKU__)
+	static char settingsDir[PATH_MAX] = "";
+	if (find_directory(B_USER_SETTINGS_DIRECTORY, -1, false, settingsDir, sizeof(settingsDir)) == B_OK) {
+		savePath = settingsDir;
+		savePath += "/ResidualVM/Savegames";
+	} else {
+		savePath = "/boot/home/config/settings/ResidualVM/Savegames";
+	}
+	mkdir(savePath.c_str(), 0755);
+	ConfMan.registerDefault("savepath", savePath);
 #else
 	const char *envVar;
 
-- 
2.19.1


From d8b6419feb7fb54603d72981bced53c8ddceede5 Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Sat, 27 Oct 2018 20:55:34 +1000
Subject: Fix build for x86_gcc2


diff --git a/configure b/configure
index 7e0c930..be18bc2 100755
--- a/configure
+++ b/configure
@@ -5343,6 +5343,9 @@ $_config_h_data
 
 /* Data types */
 typedef unsigned $type_1_byte byte;
+#ifdef __HAIKU__
+#include <SupportDefs.h>
+#else
 typedef unsigned int uint;
 typedef unsigned $type_1_byte uint8;
 typedef unsigned $type_2_byte uint16;
@@ -5350,6 +5353,7 @@ typedef unsigned $type_4_byte uint32;
 typedef signed $type_1_byte int8;
 typedef signed $type_2_byte int16;
 typedef signed $type_4_byte int32;
+#endif
 EOF
 
 if test -n "$_def_64bit_type_unsigned"  ; then
-- 
2.19.1

