diff --git a/desktop-ui/desktop-ui.cpp b/desktop-ui/desktop-ui.cpp index 1c00138ed..5742a80bf 100644 --- a/desktop-ui/desktop-ui.cpp +++ b/desktop-ui/desktop-ui.cpp @@ -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 diff --git a/desktop-ui/settings/paths.cpp b/desktop-ui/settings/paths.cpp index c2e594e99..39de6496e 100644 --- a/desktop-ui/settings/paths.cpp +++ b/desktop-ui/settings/paths.cpp @@ -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; }; diff --git a/mia/mia.cpp b/mia/mia.cpp index a5b24530a..11dd8cbe8 100644 --- a/mia/mia.cpp +++ b/mia/mia.cpp @@ -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 diff --git a/nall/path.cpp b/nall/path.cpp index 02a12b9f3..265cf9fe3 100644 --- a/nall/path.cpp +++ b/nall/path.cpp @@ -2,6 +2,8 @@ #if defined(PLATFORM_WINDOWS) #include +#elif defined(PLATFORM_MACOS) + #include #endif namespace nall::Path { @@ -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(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(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""; diff --git a/nall/path.hpp b/nall/path.hpp index b9b602a68..621811005 100644 --- a/nall/path.hpp +++ b/nall/path.hpp @@ -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;