Upgrade platform_original_game_data_exists()

This commit is contained in:
Gymnasiast 2022-01-05 14:17:19 +01:00
parent ff909cc286
commit 77e5defeca
No known key found for this signature in database
GPG Key ID: DBFFF47AB2CA3EDD
7 changed files with 15 additions and 25 deletions

View File

@ -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());

View File

@ -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;
}

View File

@ -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();

View File

@ -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()

View File

@ -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);

View File

@ -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))

View File

@ -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);