diff --git a/src/openrct2/core/File.cpp b/src/openrct2/core/File.cpp index bc472ebd66..7b48e66a3c 100644 --- a/src/openrct2/core/File.cpp +++ b/src/openrct2/core/File.cpp @@ -22,6 +22,7 @@ extern "C" { #include "../platform/platform.h" + #include "../util/util.h" } namespace File @@ -60,3 +61,12 @@ namespace File return result; } } + +extern "C" +{ + bool readentirefile(const utf8 * path, void * * outBuffer, size_t * outLength) + { + *outBuffer = File::ReadAllBytes(String::ToStd(path), outLength); + return (*outBuffer != nullptr); + } +} diff --git a/src/openrct2/localisation/language.cpp b/src/openrct2/localisation/language.cpp index 9a09cfcd06..f746201207 100644 --- a/src/openrct2/localisation/language.cpp +++ b/src/openrct2/localisation/language.cpp @@ -26,6 +26,7 @@ extern "C" { +#include "../platform/platform.h" #include "localisation.h" sint32 gCurrentLanguage = LANGUAGE_UNDEFINED; diff --git a/src/openrct2/object.h b/src/openrct2/object.h index 6990b18261..d7b36b94f8 100644 --- a/src/openrct2/object.h +++ b/src/openrct2/object.h @@ -19,7 +19,6 @@ #include "common.h" #include "drawing/drawing.h" -#include "platform/platform.h" // First 0xF of rct_object_entry->flags typedef enum{ @@ -108,7 +107,6 @@ extern const rct_object_entry_group object_entry_groups[]; void object_list_load(); bool object_load_entries(rct_object_entry* entries); -bool object_saved_packed(SDL_RWops* rw, const rct_object_entry * entry); bool object_entry_is_empty(const rct_object_entry *entry); bool object_entry_compare(const rct_object_entry *a, const rct_object_entry *b); diff --git a/src/openrct2/ride/track_design.c b/src/openrct2/ride/track_design.c index b17811fb0d..981d0c9ecb 100644 --- a/src/openrct2/ride/track_design.c +++ b/src/openrct2/ride/track_design.c @@ -67,29 +67,14 @@ static void track_design_preview_clear_map(); static void td6_reset_trailing_elements(rct_track_td6 * td6); static void td6_set_element_helper_pointers(rct_track_td6 * td6); -static bool td4_track_has_boosters(rct_track_td4 * td4); rct_track_td6 *track_design_open(const utf8 *path) { - SDL_RWops *file = SDL_RWFromFile(path, "rb"); - if (file != NULL) { - // Read whole file into a buffer - size_t bufferLength = (size_t)SDL_RWsize(file); - if (bufferLength < 4) { - log_error("Invalid track file: %s.", path); - SDL_RWclose(file); - return NULL; - } - - uint8 *buffer = (uint8*)malloc(bufferLength); - if (buffer == NULL) { - log_error("Unable to allocate memory for track design file."); - SDL_RWclose(file); - return NULL; - } - SDL_RWread(file, buffer, bufferLength, 1); - SDL_RWclose(file); + log_verbose("track_design_open(\"%s\")", path); + uint8 *buffer; + size_t bufferLength; + if (readentirefile(path, &buffer, &bufferLength)) { if (!sawyercoding_validate_track_checksum(buffer, bufferLength)) { log_error("Track checksum failed. %s", path); free(buffer); diff --git a/src/openrct2/util/util.c b/src/openrct2/util/util.c index 514b7d8270..4a99733acb 100644 --- a/src/openrct2/util/util.c +++ b/src/openrct2/util/util.c @@ -148,30 +148,6 @@ void path_end_with_separator(utf8 *path, size_t size) { safe_strcat(path, PATH_SEPARATOR, size); } -bool readentirefile(const utf8 *path, void **outBuffer, size_t *outLength) -{ - SDL_RWops *fp; - size_t fpLength; - void *fpBuffer; - - // Open file - fp = SDL_RWFromFile(path, "rb"); - if (fp == NULL) - return 0; - - // Get length - fpLength = (size_t)SDL_RWsize(fp); - - // Read whole file into a buffer - fpBuffer = malloc(fpLength); - SDL_RWread(fp, fpBuffer, fpLength, 1); - SDL_RWclose(fp); - - *outBuffer = fpBuffer; - *outLength = fpLength; - return 1; -} - sint32 bitscanforward(sint32 source) { #if defined(_MSC_VER) && (_MSC_VER >= 1400) // Visual Studio 2005