Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nall: Account for macOS app bundles in program path. #1373

Merged
merged 2 commits into from Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion desktop-ui/desktop-ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ auto locate(const string& name) -> string {

// On macOS, also check the AppBundle Resource path
#if defined(PLATFORM_MACOS)
location = {Path::program(), "../Resources/", name};
location = {Path::resources(), name};
if(inode::exists(location)) return location;
#endif

Expand Down
8 changes: 4 additions & 4 deletions desktop-ui/settings/paths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,14 @@ auto PathSettings::construct() -> void {
auto PathSettings::refresh() -> void {
//simplifies pathnames by abbreviating the home folder and trailing slash
auto pathname = [](string name) -> string {
if(name.beginsWith(Path::user())) {
name.trimLeft(Path::user(), 1L);
name.prepend("~/");
}
if(name.beginsWith(Path::program())) {
name.trimLeft(Path::program(), 1L);
name.prepend("./");
}
if(name.beginsWith(Path::user())) {
name.trimLeft(Path::user(), 1L);
name.prepend("~/");
}
if(name != "/") name.trimRight("/", 1L);
return name;
};
Expand Down
2 changes: 1 addition & 1 deletion mia/mia.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ auto locate(const string& name) -> string {

// On macOS, also check the AppBundle Resource path
#if defined(PLATFORM_MACOS)
location = {Path::program(), "../Resources/", name};
location = {Path::resources(), name};
if(inode::exists(location)) return location;
#endif

Expand Down
24 changes: 24 additions & 0 deletions nall/path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#if defined(PLATFORM_WINDOWS)
#include <shlobj.h>
#elif defined(PLATFORM_MACOS)
#include <CoreFoundation/CFBundle.h>
#endif

namespace nall::Path {
Expand All @@ -14,12 +16,34 @@ NALL_HEADER_INLINE auto program() -> string {
result.transform("\\", "/");
return Path::real(result);
#else
#if defined(PLATFORM_MACOS)
if (CFBundleRef bundle = CFBundleGetMainBundle()) {
char path[PATH_MAX] = "";
CFURLRef url = CFBundleCopyBundleURL(bundle);
CFURLGetFileSystemRepresentation(url, true, reinterpret_cast<UInt8*>(path), sizeof(path));
CFRelease(url);
return Path::real(path);
}
#endif
Dl_info info;
dladdr((void*)&program, &info);
return Path::real(info.dli_fname);
#endif
}

NALL_HEADER_INLINE auto resources() -> string {
#if defined(PLATFORM_MACOS)
if (CFBundleRef bundle = CFBundleGetMainBundle()) {
char path[PATH_MAX] = "";
CFURLRef url = CFBundleCopyBundleURL(bundle);
CFURLGetFileSystemRepresentation(url, true, reinterpret_cast<UInt8*>(path), sizeof(path));
CFRelease(url);
return string(path).append("/Contents/Resources/");
}
#endif
return program();
}

NALL_HEADER_INLINE auto root() -> string {
#if defined(PLATFORM_WINDOWS)
wchar_t path[PATH_MAX] = L"";
Expand Down
4 changes: 4 additions & 0 deletions nall/path.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ inline auto real(string_view name) -> string {

auto program() -> string;

// program()
// ./ares.app/Contents/Resources/
auto resources() -> string;

// /
// c:/
auto root() -> string;
Expand Down
Loading