macos: add portable.txt as flag for portable install (#16244)

This commit is contained in:
Eric Warmenhoven 2024-02-18 11:23:40 -05:00 committed by GitHub
parent c264c5a8de
commit 8071b49f9d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 49 additions and 45 deletions

View file

@ -103,48 +103,53 @@ bool fill_pathname_application_data(char *s, size_t len)
#elif defined(OSX) #elif defined(OSX)
CFBundleRef bundle = CFBundleGetMainBundle(); CFBundleRef bundle = CFBundleGetMainBundle();
bool portable = false;
if (!bundle) if (!bundle)
return false; return false;
/* get the directory containing the app */
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);
#if HAVE_STEAM #if HAVE_STEAM
portable = true; return true;
#else #else
/* if portable.txt exists next to the app then we use that directory */
char portable_buf[PATH_MAX_LENGTH] = {0};
fill_pathname_join(portable_buf, s, "portable.txt", sizeof(portable_buf));
if (path_is_valid(portable_buf))
return true;
/* if the app itself says it's portable we obey that as well */
CFStringRef key = CFStringCreateWithCString(NULL, "RAPortableInstall", kCFStringEncodingUTF8); CFStringRef key = CFStringCreateWithCString(NULL, "RAPortableInstall", kCFStringEncodingUTF8);
if (key) if (key)
{ {
CFBooleanRef val = CFBundleGetValueForInfoDictionaryKey(bundle, key); CFBooleanRef val = CFBundleGetValueForInfoDictionaryKey(bundle, key);
CFRelease(key);
if (val) if (val)
{ {
portable = CFBooleanGetValue(val); bool portable = CFBooleanGetValue(val);
CFRelease(val); CFRelease(val);
if (portable)
return true;
} }
CFRelease(key); }
/* otherwise we use ~/Library/Application Support/RetroArch */
const char *appdata = getenv("HOME");
if (appdata)
{
fill_pathname_join(s, appdata,
"Library/Application Support/RetroArch", len);
return true;
} }
#endif #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) #elif defined(RARCH_UNIX_CWD_ENV)
getcwd(s, len); getcwd(s, len);
return true; return true;

View file

@ -344,7 +344,6 @@ static void frontend_darwin_get_env(int *argc, char *argv[],
char documents_dir_buf[PATH_MAX_LENGTH] = {0}; char documents_dir_buf[PATH_MAX_LENGTH] = {0};
char application_data[PATH_MAX_LENGTH] = {0}; char application_data[PATH_MAX_LENGTH] = {0};
CFBundleRef bundle = CFBundleGetMainBundle(); CFBundleRef bundle = CFBundleGetMainBundle();
BOOL portable;
if (!bundle) if (!bundle)
return; return;
@ -354,36 +353,36 @@ static void frontend_darwin_get_env(int *argc, char *argv[],
CFStringGetCString(bundle_path, bundle_path_buf, sizeof(bundle_path_buf), kCFStringEncodingUTF8); CFStringGetCString(bundle_path, bundle_path_buf, sizeof(bundle_path_buf), kCFStringEncodingUTF8);
CFRelease(bundle_path); CFRelease(bundle_path);
CFRelease(bundle_url); CFRelease(bundle_url);
path_resolve_realpath(bundle_path_buf, sizeof(bundle_path_buf), true);
#if defined(OSX)
fill_pathname_application_data(application_data, sizeof(application_data));
BOOL portable; /* steam || RAPortableInstall || portable.txt */
#if HAVE_STEAM #if HAVE_STEAM
/* For Steam, we're going to put everything next to the .app */ /* For Steam, we're going to put everything next to the .app */
portable = YES; portable = YES;
#else #else
portable = [[[NSBundle mainBundle] objectForInfoDictionaryKey:@"RAPortableInstall"] boolValue]; portable = [[[NSBundle mainBundle] objectForInfoDictionaryKey:@"RAPortableInstall"] boolValue];
if (!portable)
{
char portable_buf[PATH_MAX_LENGTH] = {0};
fill_pathname_join(portable_buf, application_data, "portable.txt", sizeof(portable_buf));
portable = path_is_valid(portable_buf);
}
#endif #endif
if (portable) if (portable)
fill_pathname_application_data(documents_dir_buf, sizeof(documents_dir_buf)); strncpy(documents_dir_buf, application_data, sizeof(documents_dir_buf));
else else
{ {
CFSearchPathForDirectoriesInDomains(documents_dir_buf, sizeof(documents_dir_buf)); CFSearchPathForDirectoriesInDomains(documents_dir_buf, sizeof(documents_dir_buf));
#if TARGET_OS_IPHONE path_resolve_realpath(documents_dir_buf, sizeof(documents_dir_buf), true);
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)); strlcat(documents_dir_buf, "/RetroArch", sizeof(documents_dir_buf));
} }
#if defined(OSX)
fill_pathname_application_data(application_data, sizeof(application_data));
#else #else
CFSearchPathForDirectoriesInDomains(documents_dir_buf, sizeof(documents_dir_buf));
path_resolve_realpath(documents_dir_buf, sizeof(documents_dir_buf), true);
strlcat(documents_dir_buf, "/RetroArch", sizeof(documents_dir_buf));
/* iOS and tvOS are going to put everything in the documents dir */ /* iOS and tvOS are going to put everything in the documents dir */
strncpy(application_data, documents_dir_buf, sizeof(application_data)); strncpy(application_data, documents_dir_buf, sizeof(application_data));
#endif #endif