From 4ea74ad52686eff7f5e0fbeb570e8ffb4ae42496 Mon Sep 17 00:00:00 2001 From: Ted John Date: Thu, 9 Feb 2017 21:48:44 +0000 Subject: [PATCH] Remove RWops from check_file_paths --- src/openrct2/OpenRCT2.cpp | 33 ++++++++++++++++++++++++++++++++ src/openrct2/core/File.cpp | 5 +++++ src/openrct2/core/File.h | 1 + src/openrct2/rct2.c | 39 -------------------------------------- src/openrct2/rct2.h | 2 +- 5 files changed, 40 insertions(+), 40 deletions(-) diff --git a/src/openrct2/OpenRCT2.cpp b/src/openrct2/OpenRCT2.cpp index 3be08f2754..72fbb8d749 100644 --- a/src/openrct2/OpenRCT2.cpp +++ b/src/openrct2/OpenRCT2.cpp @@ -17,6 +17,8 @@ #include #include "core/Console.hpp" #include "core/Guard.hpp" +#include "core/File.h" +#include "core/FileStream.hpp" #include "core/String.hpp" #include "FileClassifier.h" #include "network/network.h" @@ -44,6 +46,7 @@ extern "C" #include "object_list.h" #include "platform/platform.h" #include "rct1.h" + #include "rct2.h" #include "rct2/interop.h" } @@ -320,6 +323,36 @@ extern "C" { OpenRCT2::_finished = true; } + + bool check_file_path(sint32 pathId) + { + const utf8 * path = get_file_path(pathId); + switch (pathId) { + case PATH_ID_G1: + if (!File::Exists(path)) + { + Console::Error::WriteLine("Unable to find '%s'", path); + return false; + } + break; + case PATH_ID_CUSTOM1: + case PATH_ID_CUSTOM2: + if (File::Exists(path)) + { + try + { + auto fs = FileStream(path, FILE_MODE_OPEN); + sint32 index = 36 + (pathId - PATH_ID_CUSTOM1); + gRideMusicInfoList[index]->length = fs.GetLength(); + } + catch (const Exception &) + { + } + } + break; + } + return true; + } } namespace OpenRCT2 diff --git a/src/openrct2/core/File.cpp b/src/openrct2/core/File.cpp index f3dd67396d..db6b6457d0 100644 --- a/src/openrct2/core/File.cpp +++ b/src/openrct2/core/File.cpp @@ -27,6 +27,11 @@ extern "C" namespace File { + bool Exists(const std::string &path) + { + return platform_file_exists(path.c_str()); + } + bool Copy(const std::string &srcPath, const std::string &dstPath, bool overwrite) { return platform_file_copy(srcPath.c_str(), dstPath.c_str(), overwrite); diff --git a/src/openrct2/core/File.h b/src/openrct2/core/File.h index 0110bc50da..991a4addf7 100644 --- a/src/openrct2/core/File.h +++ b/src/openrct2/core/File.h @@ -21,6 +21,7 @@ namespace File { + bool Exists(const std::string &path); bool Copy(const std::string &srcPath, const std::string &dstPath, bool overwrite); bool Delete(const std::string &path); bool Move(const std::string &srcPath, const std::string &dstPath); diff --git a/src/openrct2/rct2.c b/src/openrct2/rct2.c index e1b916a392..0d060e2f1f 100644 --- a/src/openrct2/rct2.c +++ b/src/openrct2/rct2.c @@ -377,45 +377,6 @@ sint32 check_file_paths() return 1; } -/** - * - * rct2: 0x00674CA5 - */ -sint32 check_file_path(sint32 pathId) -{ - const utf8* path = get_file_path(pathId); - SDL_RWops *file = SDL_RWFromFile(path, "rb"); - - switch (pathId) { - case PATH_ID_G1: - if (file == NULL) { - log_fatal("Could not find file %s", path); - return 0; - } - break; - - case PATH_ID_CUSTOM1: - if (file != NULL) { - // Store file size in music_custom1_size @ 0x009AF164 - gRideMusicInfoList[36]->length = (uint32)SDL_RWsize(file); - } - break; - - case PATH_ID_CUSTOM2: - if (file != NULL) { - // Store file size in music_custom2_size @ 0x009AF16E - gRideMusicInfoList[37]->length = (uint32)SDL_RWsize(file); - } - break; - } - - if (file != NULL) { - SDL_RWclose(file); - } - - return 1; -} - void rct2_update() { sint32 tickCount = SDL_GetTicks(); diff --git a/src/openrct2/rct2.h b/src/openrct2/rct2.h index 05d3865b9d..829fa00771 100644 --- a/src/openrct2/rct2.h +++ b/src/openrct2/rct2.h @@ -180,7 +180,7 @@ void rct2_update(); void substitute_path(char *dest, size_t size, const char *path, const char *filename); sint32 check_mutex(); sint32 check_file_paths(); -sint32 check_file_path(sint32 pathId); +bool check_file_path(sint32 pathId); sint32 check_files_integrity(); const char *get_file_path(sint32 pathId); void rct2_quit();