diff --git a/src/platform/linux.c b/src/platform/linux.c index 8070466dfa..5bbb9a24b1 100644 --- a/src/platform/linux.c +++ b/src/platform/linux.c @@ -112,6 +112,29 @@ void platform_posix_sub_user_data_path(char *buffer, const char *homedir, const strncat(buffer, separator, MAX_PATH - strnlen(buffer, MAX_PATH) - 1); } +/** + * Default directory fallback is: + * - (command line argument) + * - /data + * - /var/lib/openrct2 + * - /usr/share/openrct2 + */ +void platform_posix_sub_resolve_openrct_data_path(utf8 *out) { + static const utf8 *searchLocations[] = { + "/var/lib/openrct2", + "/usr/share/openrct2", + }; + for (size_t i = 0; i < countof(searchLocations); i++) + { + if (platform_directory_exists(searchLocations[i])) + { + out[0] = '\0'; + safe_strncpy(out, searchLocations[i], MAX_PATH); + return; + } + } +} + utf8 *platform_open_directory_browser(utf8 *title) { STUB(); diff --git a/src/platform/osx.m b/src/platform/osx.m index 60b76132d8..1052cad4b8 100644 --- a/src/platform/osx.m +++ b/src/platform/osx.m @@ -21,6 +21,7 @@ #if defined(__APPLE__) && defined(__MACH__) @import AppKit; +@import Foundation; #include #include "platform.h" #include "../util/util.h" @@ -75,6 +76,29 @@ void platform_posix_sub_user_data_path(char *buffer, const char *homedir, const strncat(buffer, separator, MAX_PATH - strnlen(buffer, MAX_PATH) - 1); } +/** + * Default directory fallback is: + * - (command line argument) + * - /data + * - + */ +void platform_posix_sub_resolve_openrct_data_path(utf8 *out) { + @autoreleasepool + { + NSBundle *bundle = [NSBundle mainBundle]; + if (bundle) + { + const utf8 *resources = bundle.resourcePath.UTF8String; + if (platform_directory_exists(resources)) + { + out[0] = '\0'; + safe_strncpy(out, resources, MAX_PATH); + return; + } + } + } +} + void platform_show_messagebox(char *message) { @autoreleasepool diff --git a/src/platform/posix.c b/src/platform/posix.c index 82cec5a483..522c9fb1c3 100644 --- a/src/platform/posix.c +++ b/src/platform/posix.c @@ -574,9 +574,12 @@ void platform_get_openrct_data_path(utf8 *outPath) safe_strncpy(outPath, _openrctDataDirectoryPath, sizeof(_openrctDataDirectoryPath)); } +void platform_posix_sub_resolve_openrct_data_path(utf8 *out); + /** * Default directory fallback is: * - (command line argument) + * - /data * - */ void platform_resolve_openrct_data_path() @@ -599,22 +602,14 @@ void platform_resolve_openrct_data_path() strncat(buffer, separator, MAX_PATH - strnlen(buffer, MAX_PATH) - 1); strncat(buffer, "data", MAX_PATH - strnlen(buffer, MAX_PATH) - 1); - const utf8 *searchLocations[] = { - buffer, -#ifdef __linux__ - "/var/lib/openrct2", - "/usr/share/openrct2", -#endif // __linux__ - }; - for (size_t i = 0; i < countof(searchLocations); i++) + if (platform_directory_exists(buffer)) { - if (platform_directory_exists(searchLocations[i])) - { - _openrctDataDirectoryPath[0] = '\0'; - safe_strncpy(_openrctDataDirectoryPath, searchLocations[i], sizeof(_openrctDataDirectoryPath)); - return; - } + _openrctDataDirectoryPath[0] = '\0'; + safe_strncpy(_openrctDataDirectoryPath, buffer, MAX_PATH); + return; } + + platform_posix_sub_resolve_openrct_data_path(_openrctDataDirectoryPath); } void platform_get_user_directory(utf8 *outPath, const utf8 *subDirectory)