Skip to content

Commit

Permalink
Make it easy to create a "portable" osx build
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
warmenhoven committed Jan 6, 2024
1 parent 19a3688 commit 516cbda
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 33 deletions.
50 changes: 32 additions & 18 deletions file_path_special.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
37 changes: 22 additions & 15 deletions frontend/drivers/platform_darwin.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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));
Expand Down
2 changes: 2 additions & 0 deletions pkg/apple/OSX/Info_Metal.plist
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,7 @@
<string>MainMenu_Metal</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>RAPortableInstall</key>
<false/>
</dict>
</plist>

0 comments on commit 516cbda

Please sign in to comment.