diff --git a/src/openrct2/Context.cpp b/src/openrct2/Context.cpp index 524727a1fc..ac71323c15 100644 --- a/src/openrct2/Context.cpp +++ b/src/openrct2/Context.cpp @@ -772,7 +772,7 @@ namespace OpenRCT2 if (String::IsNullOrEmpty(gCustomRCT2DataPath)) { // Check install directory - if (gConfigGeneral.rct2_path.empty() || !platform_original_game_data_exists(gConfigGeneral.rct2_path.c_str())) + if (gConfigGeneral.rct2_path.empty() || !Platform::OriginalGameDataExists(gConfigGeneral.rct2_path)) { log_verbose( "install directory does not exist or invalid directory selected, %s", gConfigGeneral.rct2_path.c_str()); diff --git a/src/openrct2/config/Config.cpp b/src/openrct2/config/Config.cpp index 1390aee5b8..e228409149 100644 --- a/src/openrct2/config/Config.cpp +++ b/src/openrct2/config/Config.cpp @@ -695,7 +695,7 @@ namespace Config for (const utf8* location : searchLocations) { - if (platform_original_game_data_exists(location)) + if (Platform::OriginalGameDataExists(location)) { return location; } @@ -705,20 +705,20 @@ namespace Config if (platform_get_steam_path(steamPath, sizeof(steamPath))) { std::string location = Path::Combine(steamPath, platform_get_rct2_steam_dir()); - if (platform_original_game_data_exists(location.c_str())) + if (Platform::OriginalGameDataExists(location)) { return location; } } auto discordPath = Platform::GetFolderPath(SPECIAL_FOLDER::RCT2_DISCORD); - if (!discordPath.empty() && platform_original_game_data_exists(discordPath.c_str())) + if (!discordPath.empty() && Platform::OriginalGameDataExists(discordPath)) { return discordPath; } auto exePath = Path::GetDirectory(Platform::GetCurrentExecutablePath()); - if (platform_original_game_data_exists(exePath.c_str())) + if (Platform::OriginalGameDataExists(exePath)) { return exePath; } @@ -922,7 +922,7 @@ bool config_find_or_browse_install_directory() } gConfigGeneral.rct2_path = installPath; - if (platform_original_game_data_exists(installPath.c_str())) + if (Platform::OriginalGameDataExists(installPath)) { return true; } diff --git a/src/openrct2/platform/Platform2.h b/src/openrct2/platform/Platform2.h index 98d886d282..936b0c8675 100644 --- a/src/openrct2/platform/Platform2.h +++ b/src/openrct2/platform/Platform2.h @@ -46,6 +46,8 @@ namespace Platform bool FindApp(const std::string& app, std::string* output); int32_t Execute(const std::string& command, std::string* output = nullptr); + bool OriginalGameDataExists(std::string_view path); + #if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__FreeBSD__) std::string GetEnvironmentPath(const char* name); std::string GetHomePath(); diff --git a/src/openrct2/platform/Posix.cpp b/src/openrct2/platform/Posix.cpp index af42078dcf..720fa8c38c 100644 --- a/src/openrct2/platform/Posix.cpp +++ b/src/openrct2/platform/Posix.cpp @@ -77,15 +77,6 @@ bool platform_directory_exists(const utf8* path) return result == 0 && S_ISDIR(dirinfo.st_mode); } -bool platform_original_game_data_exists(const utf8* path) -{ - char checkPath[MAX_PATH]; - safe_strcpy(checkPath, path, MAX_PATH); - safe_strcat_path(checkPath, "Data", MAX_PATH); - safe_strcat_path(checkPath, "g1.dat", MAX_PATH); - return Platform::FileExists(checkPath); -} - // Implement our own version of getumask(), as it is documented being // "a vaporware GNU extension". static mode_t openrct2_getumask() diff --git a/src/openrct2/platform/Shared.cpp b/src/openrct2/platform/Shared.cpp index 4a2ab65df6..dff4ae2ca9 100644 --- a/src/openrct2/platform/Shared.cpp +++ b/src/openrct2/platform/Shared.cpp @@ -20,6 +20,7 @@ #include "../OpenRCT2.h" #include "../config/Config.h" #include "../core/FileSystem.hpp" +#include "../core/Path.hpp" #include "../drawing/Drawing.h" #include "../drawing/LightFX.h" #include "../localisation/Currency.h" @@ -99,6 +100,12 @@ namespace Platform log_verbose("Checking if file exists: %s", path.c_str()); return fs::exists(file); } + + bool OriginalGameDataExists(std::string_view path) + { + std::string combinedPath = Path::ResolveCasing(Path::Combine(path, "Data", "g1.dat")); + return Platform::FileExists(combinedPath); + } } // namespace Platform using update_palette_func = void (*)(const uint8_t*, int32_t, int32_t); diff --git a/src/openrct2/platform/Windows.cpp b/src/openrct2/platform/Windows.cpp index 04c70360e1..41cc19b896 100644 --- a/src/openrct2/platform/Windows.cpp +++ b/src/openrct2/platform/Windows.cpp @@ -66,15 +66,6 @@ bool platform_directory_exists(const utf8* path) return dwAttrib != INVALID_FILE_ATTRIBUTES && (dwAttrib & FILE_ATTRIBUTE_DIRECTORY); } -bool platform_original_game_data_exists(const utf8* path) -{ - utf8 checkPath[MAX_PATH]; - safe_strcpy(checkPath, path, MAX_PATH); - safe_strcat_path(checkPath, "Data", MAX_PATH); - safe_strcat_path(checkPath, "g1.dat", MAX_PATH); - return Platform::FileExists(checkPath); -} - bool platform_ensure_directory_exists(const utf8* path) { if (platform_directory_exists(path)) diff --git a/src/openrct2/platform/platform.h b/src/openrct2/platform/platform.h index af85318121..d7d357c686 100644 --- a/src/openrct2/platform/platform.h +++ b/src/openrct2/platform/platform.h @@ -90,7 +90,6 @@ void platform_get_time_utc(rct2_time* out_time); // Platform specific definitions bool platform_directory_exists(const utf8* path); -bool platform_original_game_data_exists(const utf8* path); time_t platform_file_get_modified_time(const utf8* path); bool platform_ensure_directory_exists(const utf8* path); bool platform_directory_delete(const utf8* path);