From b9bc2fd4c803e7a61d44f55ecec393d42927a3df Mon Sep 17 00:00:00 2001 From: Eric Warmenhoven Date: Sun, 7 Jan 2024 10:58:06 -0500 Subject: [PATCH] Make it easy to create a "portable" osx build (#16081) Default to false, except steam builds where it's forced true; a portable build has the behavior of putting all files next to the application. --- file_path_special.c | 50 +++++++++++++++++++----------- frontend/drivers/platform_darwin.m | 37 +++++++++++++--------- pkg/apple/OSX/Info_Metal.plist | 2 ++ 3 files changed, 56 insertions(+), 33 deletions(-) diff --git a/file_path_special.c b/file_path_special.c index e51d8a95ae9..05b3bbda62c 100644 --- a/file_path_special.c +++ b/file_path_special.c @@ -102,30 +102,44 @@ bool fill_pathname_application_data(char *s, size_t len) #endif #elif defined(OSX) -#if HAVE_STEAM - CFStringRef parent_path; - CFURLRef bundle_url, parent_url; CFBundleRef bundle = CFBundleGetMainBundle(); + bool portable = false; if (!bundle) return false; - bundle_url = CFBundleCopyBundleURL(bundle); - parent_url = CFURLCreateCopyDeletingLastPathComponent(NULL, bundle_url); - parent_path = CFURLCopyFileSystemPath(parent_url, kCFURLPOSIXPathStyle); - CFStringGetCString(parent_path, s, len, kCFStringEncodingUTF8); - CFRelease(parent_path); - CFRelease(parent_url); - CFRelease(bundle_url); - return true; +#if HAVE_STEAM + portable = true; #else - const char *appdata = getenv("HOME"); - - if (appdata) + CFStringRef key = CFStringCreateWithCString(NULL, "RAPortableInstall", kCFStringEncodingUTF8); + CFBooleanRef val = CFBundleGetValueForInfoDictionaryKey(bundle, key); + if (val) + portable = CFBooleanGetValue(val); + CFRelease(val); + CFRelease(key); +#endif + if (portable) { - fill_pathname_join(s, appdata, - "Library/Application Support/RetroArch", len); - return true; + CFStringRef parent_path; + CFURLRef bundle_url, parent_url; + bundle_url = CFBundleCopyBundleURL(bundle); + parent_url = CFURLCreateCopyDeletingLastPathComponent(NULL, bundle_url); + parent_path = CFURLCopyFileSystemPath(parent_url, kCFURLPOSIXPathStyle); + CFStringGetCString(parent_path, s, len, kCFStringEncodingUTF8); + CFRelease(parent_path); + CFRelease(parent_url); + CFRelease(bundle_url); + return true; + } + else + { + const char *appdata = getenv("HOME"); + + if (appdata) + { + fill_pathname_join(s, appdata, + "Library/Application Support/RetroArch", len); + return true; + } } -#endif #elif defined(RARCH_UNIX_CWD_ENV) getcwd(s, len); return true; diff --git a/frontend/drivers/platform_darwin.m b/frontend/drivers/platform_darwin.m index 795e21a4238..b49ea56843a 100644 --- a/frontend/drivers/platform_darwin.m +++ b/frontend/drivers/platform_darwin.m @@ -344,6 +344,7 @@ static void frontend_darwin_get_env(int *argc, char *argv[], char documents_dir_buf[PATH_MAX_LENGTH] = {0}; char application_data[PATH_MAX_LENGTH] = {0}; CFBundleRef bundle = CFBundleGetMainBundle(); + BOOL portable; if (!bundle) return; @@ -356,23 +357,29 @@ static void frontend_darwin_get_env(int *argc, char *argv[], #if HAVE_STEAM /* For Steam, we're going to put everything next to the .app */ - fill_pathname_application_data(documents_dir_buf, sizeof(documents_dir_buf)); + portable = YES; #else - CFSearchPathForDirectoriesInDomains(documents_dir_buf, sizeof(documents_dir_buf)); -#if TARGET_OS_IPHONE - char resolved_documents_dir_buf[PATH_MAX_LENGTH] = {0}; - char resolved_bundle_dir_buf[PATH_MAX_LENGTH] = {0}; - if (realpath(documents_dir_buf, resolved_documents_dir_buf)) - strlcpy(documents_dir_buf, - resolved_documents_dir_buf, - sizeof(documents_dir_buf)); - if (realpath(bundle_path_buf, resolved_bundle_dir_buf)) - strlcpy(bundle_path_buf, - resolved_bundle_dir_buf, - sizeof(bundle_path_buf)); -#endif - strlcat(documents_dir_buf, "/RetroArch", sizeof(documents_dir_buf)); + portable = [[[NSBundle mainBundle] objectForInfoDictionaryKey:@"RAPortableInstall"] boolValue]; #endif + if (portable) + fill_pathname_application_data(documents_dir_buf, sizeof(documents_dir_buf)); + else + { + CFSearchPathForDirectoriesInDomains(documents_dir_buf, sizeof(documents_dir_buf)); +#if TARGET_OS_IPHONE + char resolved_documents_dir_buf[PATH_MAX_LENGTH] = {0}; + char resolved_bundle_dir_buf[PATH_MAX_LENGTH] = {0}; + if (realpath(documents_dir_buf, resolved_documents_dir_buf)) + strlcpy(documents_dir_buf, + resolved_documents_dir_buf, + sizeof(documents_dir_buf)); + if (realpath(bundle_path_buf, resolved_bundle_dir_buf)) + strlcpy(bundle_path_buf, + resolved_bundle_dir_buf, + sizeof(bundle_path_buf)); +#endif + strlcat(documents_dir_buf, "/RetroArch", sizeof(documents_dir_buf)); + } #if defined(OSX) fill_pathname_application_data(application_data, sizeof(application_data)); diff --git a/pkg/apple/OSX/Info_Metal.plist b/pkg/apple/OSX/Info_Metal.plist index ebd73fd076a..3dabdb556a7 100644 --- a/pkg/apple/OSX/Info_Metal.plist +++ b/pkg/apple/OSX/Info_Metal.plist @@ -51,5 +51,7 @@ MainMenu_Metal NSPrincipalClass NSApplication + RAPortableInstall +