Skip to content

Commit 3a6892a

Browse files
committed
MacOS: Better handle directories of non-bundle applications
1 parent d2bbe83 commit 3a6892a

3 files changed

Lines changed: 23 additions & 7 deletions

File tree

common/CocoaTools.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ namespace CocoaTools
3131
bool DelayedLaunch(std::string_view file);
3232
/// Open a Finder window to the given URL
3333
bool ShowInFinder(std::string_view file);
34+
/// Get the path to the resources directory of the current application
35+
std::optional<std::string> GetResourcePath();
3436

3537
/// Create a window
3638
void* CreateWindow(std::string_view title, uint32_t width, uint32_t height);

common/CocoaTools.mm

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,22 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N
224224
bool CocoaTools::ShowInFinder(std::string_view file)
225225
{
226226
return [[NSWorkspace sharedWorkspace] selectFile:NSStringFromStringView(file)
227-
inFileViewerRootedAtPath:nil];
227+
inFileViewerRootedAtPath:@""];
228228
}
229229

230+
std::optional<std::string> CocoaTools::GetResourcePath()
231+
{ @autoreleasepool {
232+
if (NSBundle* bundle = [NSBundle mainBundle])
233+
{
234+
NSString* rsrc = [bundle resourcePath];
235+
NSString* root = [bundle bundlePath];
236+
if ([rsrc isEqualToString:root])
237+
rsrc = [rsrc stringByAppendingString:@"/resources"];
238+
return [rsrc UTF8String];
239+
}
240+
return std::nullopt;
241+
}}
242+
230243
// MARK: - GSRunner
231244

232245
void* CocoaTools::CreateWindow(std::string_view title, u32 width, u32 height)

pcsx2/Pcsx2Config.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2083,17 +2083,16 @@ void Pcsx2Config::ClearInvalidPerGameConfiguration(SettingsInterface* si)
20832083
void EmuFolders::SetAppRoot()
20842084
{
20852085
std::string program_path = FileSystem::GetProgramPath();
2086+
Console.WriteLnFmt("Program Path: {}", program_path);
2087+
AppRoot = Path::Canonicalize(Path::GetDirectory(program_path));
20862088
#ifdef __APPLE__
20872089
const auto bundle_path = CocoaTools::GetNonTranslocatedBundlePath();
20882090
if (bundle_path.has_value())
20892091
{
20902092
// On macOS, override with the bundle path if launched from a bundle.
2091-
program_path = bundle_path.value();
2093+
AppRoot = StringUtil::EndsWithNoCase(*bundle_path, ".app") ? Path::GetDirectory(*bundle_path) : *bundle_path;
20922094
}
20932095
#endif
2094-
Console.WriteLnFmt("Program Path: {}", program_path);
2095-
2096-
AppRoot = Path::Canonicalize(Path::GetDirectory(program_path));
20972096

20982097
// logging of directories in case something goes wrong super early
20992098
Console.WriteLnFmt("AppRoot Directory: {}", AppRoot);
@@ -2110,8 +2109,10 @@ bool EmuFolders::SetResourcesDirectory()
21102109
#endif
21112110
#else
21122111
// On macOS, this is in the bundle resources directory.
2113-
const std::string program_path = FileSystem::GetProgramPath();
2114-
Resources = Path::Canonicalize(Path::Combine(Path::GetDirectory(program_path), "../Resources"));
2112+
if (auto resources = CocoaTools::GetResourcePath())
2113+
Resources = *resources;
2114+
else
2115+
Resources = Path::Combine(AppRoot, "resources");
21152116
#endif
21162117

21172118
Console.WriteLnFmt("Resources Directory: {}", Resources);

0 commit comments

Comments
 (0)