diff --git a/CHANGES b/CHANGES index 5408b8755..246bdec53 100644 --- a/CHANGES +++ b/CHANGES @@ -15,6 +15,7 @@ Other fixes: - ARM Debugger: Fix disassembly alignment (fixes mgba.io/i/2204) - Core: Fix memory leak in opening games from the library - Core: Fix memory searches for relative values (fixes mgba.io/i/2135) + - Core: Fix portable mode on macOS - GB Core: Fix GBC colors setting breaking default model overrides (fixes mgba.io/i/2161) - GBA: Fix out of bounds ROM accesses on patched ROMs smaller than 32 MiB - Qt: Fix infrequent deadlock when using sync to video diff --git a/CMakeLists.txt b/CMakeLists.txt index 9a5c61b0f..115fcd552 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -228,6 +228,7 @@ endif() if(APPLE) add_definitions(-D_DARWIN_C_SOURCE) + list(APPEND OS_LIB "-framework Foundation") if(CMAKE_SYSTEM_VERSION VERSION_GREATER "10.5.8") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mmacosx-version-min=10.6") endif() diff --git a/src/core/config.c b/src/core/config.c index 5a9599c4e..9f54aca26 100644 --- a/src/core/config.c +++ b/src/core/config.c @@ -19,6 +19,12 @@ #include #endif +#ifdef __APPLE__ +#include +#include +#include +#endif + #ifdef PSP2 #include #endif @@ -274,6 +280,16 @@ void mCoreConfigPortablePath(char* out, size_t outLength) { out[0] = '\0'; #else getcwd(out, outLength); +#ifdef __APPLE__ + CFBundleRef mainBundle = CFBundleGetMainBundle(); + if (strcmp(out, "/") == 0 && mainBundle) { + CFURLRef url = CFBundleCopyBundleURL(mainBundle); + CFURLRef suburl = CFURLCreateCopyDeletingLastPathComponent(kCFAllocatorDefault, url); + CFRelease(url); + CFURLGetFileSystemRepresentation(suburl, true, (UInt8*) out, outLength); + CFRelease(suburl); + } +#endif strncat(out, PATH_SEP "portable.ini", outLength - strlen(out)); #endif }