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.
This commit is contained in:
Eric Warmenhoven 2024-01-07 10:58:06 -05:00 committed by GitHub
parent ed73141856
commit 272b66a5db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 56 additions and 33 deletions

View File

@ -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)
{
fill_pathname_join(s, appdata,
"Library/Application Support/RetroArch", len);
return true;
}
CFStringRef key = CFStringCreateWithCString(NULL, "RAPortableInstall", kCFStringEncodingUTF8);
CFBooleanRef val = CFBundleGetValueForInfoDictionaryKey(bundle, key);
if (val)
portable = CFBooleanGetValue(val);
CFRelease(val);
CFRelease(key);
#endif
if (portable)
{
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;
}
}
#elif defined(RARCH_UNIX_CWD_ENV)
getcwd(s, len);
return true;

View File

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

View File

@ -51,5 +51,7 @@
<string>MainMenu_Metal</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>RAPortableInstall</key>
<false/>
</dict>
</plist>