diff --git a/src/openrct2-ui/windows/InstallTrack.cpp b/src/openrct2-ui/windows/InstallTrack.cpp index 1acca806f3..10b6949f2a 100644 --- a/src/openrct2-ui/windows/InstallTrack.cpp +++ b/src/openrct2-ui/windows/InstallTrack.cpp @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include #include #include @@ -428,7 +428,7 @@ static void window_install_track_design(rct_window* w) safe_strcat_path(destPath, _trackName.c_str(), sizeof(destPath)); path_append_extension(destPath, ".td6", sizeof(destPath)); - if (platform_file_exists(destPath)) + if (Platform::FileExists(destPath)) { log_info("%s already exists, prompting user for a different track design name", destPath); context_show_error(STR_UNABLE_TO_INSTALL_THIS_TRACK_DESIGN, STR_NONE); diff --git a/src/openrct2-ui/windows/Options.cpp b/src/openrct2-ui/windows/Options.cpp index 83a3822072..9c40675c00 100644 --- a/src/openrct2-ui/windows/Options.cpp +++ b/src/openrct2-ui/windows/Options.cpp @@ -33,7 +33,6 @@ #include #include #include -#include #include #include #include @@ -1493,7 +1492,7 @@ static void window_options_dropdown(rct_window* w, rct_widgetindex widgetIndex, break; case WIDX_TITLE_MUSIC_DROPDOWN: if ((dropdownIndex == 1 || dropdownIndex == 3) - && !platform_file_exists(context_get_path_legacy(PATH_ID_CSS50))) + && !Platform::FileExists(context_get_path_legacy(PATH_ID_CSS50))) { context_show_error(STR_OPTIONS_MUSIC_ERR_CSS50_NOT_FOUND, STR_OPTIONS_MUSIC_ERR_CSS50_NOT_FOUND_HINT); } diff --git a/src/openrct2/Game.cpp b/src/openrct2/Game.cpp index 873e50a434..8b98453b9d 100644 --- a/src/openrct2/Game.cpp +++ b/src/openrct2/Game.cpp @@ -39,7 +39,6 @@ #include "peep/Peep.h" #include "peep/Staff.h" #include "platform/Platform2.h" -#include "platform/platform.h" #include "rct1/RCT1.h" #include "ride/Ride.h" #include "ride/RideRatings.h" @@ -789,7 +788,7 @@ void game_autosave() safe_strcat(backupPath, fileExtension, sizeof(backupPath)); safe_strcat(backupPath, ".bak", sizeof(backupPath)); - if (platform_file_exists(path)) + if (Platform::FileExists(path)) { platform_file_copy(path, backupPath, true); } diff --git a/src/openrct2/cmdline/BenchSpriteSort.cpp b/src/openrct2/cmdline/BenchSpriteSort.cpp index 3ace2f7cfc..de851929c4 100644 --- a/src/openrct2/cmdline/BenchSpriteSort.cpp +++ b/src/openrct2/cmdline/BenchSpriteSort.cpp @@ -22,7 +22,7 @@ # include "../interface/Viewport.h" # include "../localisation/Localisation.h" # include "../paint/Paint.h" -# include "../platform/platform.h" +# include "../platform/Platform2.h" # include "../util/Util.h" # include "../world/Climate.h" # include "../world/Map.h" @@ -180,7 +180,7 @@ static int cmdline_for_bench_sprite_sort(int argc, const char** argv) // Extract file names from argument list. If there is no such file, consider it benchmark option. for (int i = 0; i < argc; i++) { - if (platform_file_exists(argv[i])) + if (Platform::FileExists(argv[i])) { // Register benchmark for sv6 if valid std::vector sessions = extract_paint_session(argv[i]); diff --git a/src/openrct2/cmdline/RootCommands.cpp b/src/openrct2/cmdline/RootCommands.cpp index e9fc2f311d..77f7671fa7 100644 --- a/src/openrct2/cmdline/RootCommands.cpp +++ b/src/openrct2/cmdline/RootCommands.cpp @@ -22,7 +22,6 @@ #include "../object/ObjectRepository.h" #include "../platform/Crash.h" #include "../platform/Platform2.h" -#include "../platform/platform.h" #include "CommandLine.hpp" #include @@ -368,7 +367,7 @@ static exitcode_t HandleCommandSetRCT2(CommandLineArgEnumerator* enumerator) String::Set(pathG1Check, sizeof(pathG1Check), path); Path::Append(pathG1Check, sizeof(pathG1Check), "Data"); Path::Append(pathG1Check, sizeof(pathG1Check), "g1.dat"); - if (!platform_file_exists(pathG1Check)) + if (Platform::FileExists(pathG1Check)) { Console::Error::WriteLine("RCT2 path not valid."); Console::Error::WriteLine("Unable to find %s.", pathG1Check); diff --git a/src/openrct2/core/File.cpp b/src/openrct2/core/File.cpp index 21ff19c8e0..8bfb4a47e5 100644 --- a/src/openrct2/core/File.cpp +++ b/src/openrct2/core/File.cpp @@ -14,7 +14,7 @@ # include #endif -#include "../platform/platform.h" +#include "../platform/Platform2.h" #include "../util/Util.h" #include "File.h" #include "FileStream.hpp" @@ -26,7 +26,7 @@ namespace File { bool Exists(const std::string& path) { - return platform_file_exists(path.c_str()); + return Platform::FileExists(path); } bool Copy(const std::string& srcPath, const std::string& dstPath, bool overwrite) diff --git a/src/openrct2/interface/Screenshot.cpp b/src/openrct2/interface/Screenshot.cpp index b6e0775ede..5fc29e9a69 100644 --- a/src/openrct2/interface/Screenshot.cpp +++ b/src/openrct2/interface/Screenshot.cpp @@ -21,7 +21,6 @@ #include "../drawing/X8DrawingEngine.h" #include "../localisation/Localisation.h" #include "../platform/Platform2.h" -#include "../platform/platform.h" #include "../util/Util.h" #include "../world/Climate.h" #include "../world/Map.h" @@ -146,7 +145,7 @@ static std::optional screenshot_get_next_path() for (int tries = 0; tries < 100; tries++) { auto path = pathComposer(tries); - if (!platform_file_exists(path.c_str())) + if (!Platform::FileExists(path)) { return path; } diff --git a/src/openrct2/network/Network.cpp b/src/openrct2/network/Network.cpp index fcb2aad157..2aaf8586a1 100644 --- a/src/openrct2/network/Network.cpp +++ b/src/openrct2/network/Network.cpp @@ -18,7 +18,7 @@ #include "../actions/NetworkModifyGroupAction.hpp" #include "../actions/PeepPickupAction.hpp" #include "../core/Guard.hpp" -#include "../platform/platform.h" +#include "../platform/Platform2.h" #include "../scripting/ScriptEngine.h" #include "../ui/UiContext.h" #include "../ui/WindowManager.h" @@ -503,7 +503,7 @@ bool Network::BeginClient(const std::string& host, uint16_t port) utf8 keyPath[MAX_PATH]; network_get_private_key_path(keyPath, sizeof(keyPath), gConfigNetwork.player_name); - if (!platform_file_exists(keyPath)) + if (!Platform::FileExists(keyPath)) { Console::WriteLine("Generating key... This may take a while"); Console::WriteLine("Need to collect enough entropy from the system"); @@ -1242,7 +1242,7 @@ void Network::LoadGroups() safe_strcat_path(path, "groups.json", sizeof(path)); json_t* json = nullptr; - if (platform_file_exists(path)) + if (Platform::FileExists(path)) { try { @@ -2356,7 +2356,7 @@ void Network::Client_Handle_TOKEN(NetworkConnection& connection, NetworkPacket& { utf8 keyPath[MAX_PATH]; network_get_private_key_path(keyPath, sizeof(keyPath), gConfigNetwork.player_name); - if (!platform_file_exists(keyPath)) + if (!Platform::FileExists(keyPath)) { log_error("Key file (%s) was not found. Restart client to re-generate it.", keyPath); return; @@ -4031,7 +4031,7 @@ void network_send_password(const std::string& password) { utf8 keyPath[MAX_PATH]; network_get_private_key_path(keyPath, sizeof(keyPath), gConfigNetwork.player_name); - if (!platform_file_exists(keyPath)) + if (!Platform::FileExists(keyPath)) { log_error("Private key %s missing! Restart the game to generate it.", keyPath); return; diff --git a/src/openrct2/network/NetworkUser.cpp b/src/openrct2/network/NetworkUser.cpp index 9e0cb664f6..9d27043fce 100644 --- a/src/openrct2/network/NetworkUser.cpp +++ b/src/openrct2/network/NetworkUser.cpp @@ -15,7 +15,7 @@ # include "../core/Json.hpp" # include "../core/Path.hpp" # include "../core/String.hpp" -# include "../platform/platform.h" +# include "../platform/Platform2.h" # include @@ -86,7 +86,7 @@ void NetworkUserManager::Load() utf8 path[MAX_PATH]; GetStorePath(path, sizeof(path)); - if (platform_file_exists(path)) + if (Platform::FileExists(path)) { DisposeUsers(); @@ -120,7 +120,7 @@ void NetworkUserManager::Save() json_t* jsonUsers = nullptr; try { - if (platform_file_exists(path)) + if (Platform::FileExists(path)) { jsonUsers = Json::ReadFromFile(path); } diff --git a/src/openrct2/network/ServerList.cpp b/src/openrct2/network/ServerList.cpp index bc7c400554..4d472c050e 100644 --- a/src/openrct2/network/ServerList.cpp +++ b/src/openrct2/network/ServerList.cpp @@ -20,7 +20,7 @@ # include "../core/Memory.hpp" # include "../core/Path.hpp" # include "../core/String.hpp" -# include "../platform/platform.h" +# include "../platform/Platform2.h" # include "Socket.h" # include "network.h" @@ -156,7 +156,7 @@ std::vector ServerList::ReadFavourites() const { auto env = GetContext()->GetPlatformEnvironment(); auto path = env->GetFilePath(PATHID::NETWORK_SERVERS); - if (platform_file_exists(path.c_str())) + if (Platform::FileExists(path)) { auto fs = FileStream(path, FILE_MODE_OPEN); auto numEntries = fs.ReadValue(); diff --git a/src/openrct2/platform/Platform2.h b/src/openrct2/platform/Platform2.h index 67f81d5723..fb5f565f5e 100644 --- a/src/openrct2/platform/Platform2.h +++ b/src/openrct2/platform/Platform2.h @@ -33,6 +33,7 @@ namespace Platform std::string GetInstallPath(); std::string GetDocsPath(); std::string GetCurrentExecutablePath(); + bool FileExists(const std::string path); rct2_time GetTimeLocal(); rct2_date GetDateLocal(); diff --git a/src/openrct2/platform/Posix.cpp b/src/openrct2/platform/Posix.cpp index 65f16cfe3d..20e47ce732 100644 --- a/src/openrct2/platform/Posix.cpp +++ b/src/openrct2/platform/Posix.cpp @@ -25,7 +25,7 @@ # include "../localisation/Date.h" # include "../localisation/Language.h" # include "../util/Util.h" -# include "platform.h" +# include "Platform2.h" # include # include @@ -71,13 +71,6 @@ void platform_get_time_utc(rct2_time* out_time) out_time->hour = timeinfo->tm_hour; } -bool platform_file_exists(const utf8* path) -{ - bool exists = access(path, F_OK) != -1; - log_verbose("file '%s' exists = %i", path, exists); - return exists; -} - bool platform_directory_exists(const utf8* path) { struct stat dirinfo; @@ -92,7 +85,7 @@ bool platform_original_game_data_exists(const utf8* path) safe_strcpy(checkPath, path, MAX_PATH); safe_strcat_path(checkPath, "Data", MAX_PATH); safe_strcat_path(checkPath, "g1.dat", MAX_PATH); - return platform_file_exists(checkPath); + return Platform::FileExists(checkPath); } // Implement our own version of getumask(), as it is documented being diff --git a/src/openrct2/platform/Shared.cpp b/src/openrct2/platform/Shared.cpp index aa289c1e48..358709a283 100644 --- a/src/openrct2/platform/Shared.cpp +++ b/src/openrct2/platform/Shared.cpp @@ -20,6 +20,7 @@ #include "../Game.h" #include "../OpenRCT2.h" #include "../config/Config.h" +#include "../core/FileSystem.hpp" #include "../drawing/Drawing.h" #include "../drawing/LightFX.h" #include "../localisation/Currency.h" @@ -90,6 +91,12 @@ namespace Platform outTime.second = localTime->tm_sec; return outTime; } + + bool FileExists(const std::string path) + { + fs::path file = path; + return fs::exists(file); + } } // 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 9aeede6826..bba464bf0e 100644 --- a/src/openrct2/platform/Windows.cpp +++ b/src/openrct2/platform/Windows.cpp @@ -55,14 +55,6 @@ # define swprintf_s(a, b, c, d, ...) swprintf(a, b, c, ##__VA_ARGS__) # endif -bool platform_file_exists(const utf8* path) -{ - auto wPath = String::ToWideChar(path); - DWORD result = GetFileAttributesW(wPath.c_str()); - DWORD error = GetLastError(); - return !(result == INVALID_FILE_ATTRIBUTES && (error == ERROR_FILE_NOT_FOUND || error == ERROR_PATH_NOT_FOUND)); -} - bool platform_directory_exists(const utf8* path) { auto wPath = String::ToWideChar(path); @@ -76,7 +68,7 @@ bool platform_original_game_data_exists(const utf8* path) safe_strcpy(checkPath, path, MAX_PATH); safe_strcat_path(checkPath, "Data", MAX_PATH); safe_strcat_path(checkPath, "g1.dat", MAX_PATH); - return platform_file_exists(checkPath); + return Platform::FileExists(checkPath); } bool platform_ensure_directory_exists(const utf8* path) diff --git a/src/openrct2/platform/platform.h b/src/openrct2/platform/platform.h index 80e951095a..acdab3d3ec 100644 --- a/src/openrct2/platform/platform.h +++ b/src/openrct2/platform/platform.h @@ -90,7 +90,6 @@ void platform_get_date_utc(rct2_date* out_date); void platform_get_time_utc(rct2_time* out_time); // Platform specific definitions -bool platform_file_exists(const utf8* path); 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); diff --git a/src/openrct2/scenario/ScenarioRepository.cpp b/src/openrct2/scenario/ScenarioRepository.cpp index addc41c9bf..b9f295df65 100644 --- a/src/openrct2/scenario/ScenarioRepository.cpp +++ b/src/openrct2/scenario/ScenarioRepository.cpp @@ -23,7 +23,7 @@ #include "../localisation/Language.h" #include "../localisation/Localisation.h" #include "../localisation/LocalisationService.h" -#include "../platform/platform.h" +#include "../platform/Platform2.h" #include "../rct12/SawyerChunkReader.h" #include "Scenario.h" #include "ScenarioSources.h" @@ -579,7 +579,7 @@ private: void LoadScores() { std::string path = _env->GetFilePath(PATHID::SCORES); - if (!platform_file_exists(path.c_str())) + if (!Platform::FileExists(path)) { return; } @@ -626,7 +626,7 @@ private: void LoadLegacyScores(const std::string& path) { - if (!platform_file_exists(path.c_str())) + if (!Platform::FileExists(path)) { return; }