mirror of https://github.com/OpenRCT2/OpenRCT2.git
Fix GetBundlePath, add install paths to match cmake install
This commit is contained in:
parent
fb316a746a
commit
7bea24708e
|
@ -49,10 +49,17 @@ namespace Platform
|
|||
NSBundle* bundle = [NSBundle mainBundle];
|
||||
if (bundle)
|
||||
{
|
||||
auto resources = bundle.resourcePath.UTF8String;
|
||||
if (Path::DirectoryExists(resources))
|
||||
// This method may return a valid bundle object even for unbundled apps.
|
||||
// See https://developer.apple.com/documentation/foundation/nsbundle/1410786-mainbundle?language=objc
|
||||
// Therefore, double check this is a valid bundle (has an ID string)
|
||||
auto bundleId = bundle.bundleIdentifier.UTF8String;
|
||||
if (bundleId)
|
||||
{
|
||||
return resources;
|
||||
auto resources = bundle.resourcePath.UTF8String;
|
||||
if (Path::DirectoryExists(resources))
|
||||
{
|
||||
return resources;
|
||||
}
|
||||
}
|
||||
}
|
||||
return std::string();
|
||||
|
@ -70,23 +77,36 @@ namespace Platform
|
|||
if (!path.empty())
|
||||
{
|
||||
path = Path::GetAbsolute(path);
|
||||
return path;
|
||||
}
|
||||
else
|
||||
{
|
||||
auto exePath = GetCurrentExecutablePath();
|
||||
auto exeDirectory = Path::GetDirectory(exePath);
|
||||
path = Path::Combine(exeDirectory, "data");
|
||||
NSString* nsPath = [NSString stringWithUTF8String:path.c_str()];
|
||||
if (![[NSFileManager defaultManager] fileExistsAtPath:nsPath])
|
||||
// check if this is an app bundle
|
||||
path = GetBundlePath();
|
||||
if (!path.empty())
|
||||
{
|
||||
path = GetBundlePath();
|
||||
if (path.empty())
|
||||
{
|
||||
path = "/";
|
||||
return path;
|
||||
}
|
||||
else
|
||||
{
|
||||
// this is not in an app bundle
|
||||
auto exePath = GetCurrentExecutablePath();
|
||||
auto exeDirectory = Path::GetDirectory(exePath);
|
||||
|
||||
// check build and install paths
|
||||
NSArray *dataSearchLocations = @[@"data", @"../share/openrct2"];
|
||||
|
||||
for (NSString *searchLocation in dataSearchLocations) {
|
||||
path = Path::Combine(exeDirectory, [searchLocation UTF8String]);
|
||||
NSString* nsPath = [NSString stringWithUTF8String:path.c_str()];
|
||||
if ([[NSFileManager defaultManager] fileExistsAtPath:nsPath])
|
||||
{
|
||||
return path;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return path;
|
||||
return "/";
|
||||
}
|
||||
|
||||
std::string GetCurrentExecutablePath()
|
||||
|
|
Loading…
Reference in New Issue