From d854a6c8297f82f491a378e54abd442530db5ca0 Mon Sep 17 00:00:00 2001 From: Lucas Eriksson Date: Tue, 9 Feb 2021 14:46:39 +0100 Subject: [PATCH] settings: Read xemu.ini from binary path first --- ui/xemu-settings.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/ui/xemu-settings.c b/ui/xemu-settings.c index 41cbe4448f..f3fc225513 100644 --- a/ui/xemu-settings.c +++ b/ui/xemu-settings.c @@ -21,7 +21,9 @@ #include #include #include +#include #include +#include #include "xemu-settings.h" #include "inih/ini.c" // FIXME @@ -189,6 +191,20 @@ int xemu_settings_get_enum(enum xemu_settings_keys key, int *val) return 0; } +bool xemu_settings_detect_portable_mode(void) +{ + bool val = false; + char *portable_path = g_strdup_printf("%s%s", SDL_GetBasePath(), filename); + FILE *tmpfile; + if ((tmpfile = fopen(portable_path, "r"))) { + fclose(tmpfile); + val = true; + } + + free(portable_path); + return val; +} + const char *xemu_settings_get_path(void) { if (settings_path != NULL) { @@ -197,6 +213,13 @@ const char *xemu_settings_get_path(void) char *base = SDL_GetPrefPath("xemu", "xemu"); assert(base != NULL); + + // Check for xemu.ini in xemu binary directory, "portable mode" + if (xemu_settings_detect_portable_mode()) { + base = SDL_GetBasePath(); + assert(base != NULL); + } + size_t base_len = strlen(base); size_t filename_len = strlen(filename); @@ -230,6 +253,13 @@ const char *xemu_settings_get_default_eeprom_path(void) char *base = SDL_GetPrefPath("xemu", "xemu"); assert(base != NULL); + + // Check for xemu.ini in xemu binary directory, "portable mode" + if (xemu_settings_detect_portable_mode()) { + base = SDL_GetBasePath(); + assert(base != NULL); + } + size_t base_len = strlen(base); const char *name = "eeprom.bin";