Core: Fix portable mode on macOS

This commit is contained in:
Vicki Pfau 2021-06-10 00:08:14 -07:00
parent 588186531c
commit d85589b837
3 changed files with 18 additions and 0 deletions

View File

@ -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

View File

@ -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()

View File

@ -19,6 +19,12 @@
#include <strsafe.h>
#endif
#ifdef __APPLE__
#include <CoreFoundation/CFBundle.h>
#include <CoreFoundation/CFString.h>
#include <CoreFoundation/CFURL.h>
#endif
#ifdef PSP2
#include <psp2/io/stat.h>
#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
}