CocoaTools: Return nullopt if not running from bundle

pull/3794/head
Stenzek 2 weeks ago
parent 1f065b5eae
commit d9071e49b9
No known key found for this signature in database

@ -83,7 +83,16 @@ std::optional<std::string> CocoaTools::GetBundlePath()
std::optional<std::string> ret;
@autoreleasepool
{
NSURL* url = [NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]];
NSBundle* bundle = [NSBundle mainBundle];
if (!bundle)
return std::nullopt;
// A real macOS application bundle should have CFBundlePackageType = APPL.
NSString* packageType = [bundle objectForInfoDictionaryKey:@"CFBundlePackageType"];
if (![packageType isEqualToString:@"APPL"])
return std::nullopt;
NSURL* url = [bundle bundleURL];
if (url)
ret = std::string([url fileSystemRepresentation]);
}

Loading…
Cancel
Save