mirror of https://github.com/OpenRCT2/OpenRCT2.git
Remove use of RWops from track design
This commit is contained in:
parent
3a1331190b
commit
4d16e3e1bd
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
|
||||
extern "C" {
|
||||
|
||||
#include "../platform/platform.h"
|
||||
#include "localisation.h"
|
||||
|
||||
sint32 gCurrentLanguage = LANGUAGE_UNDEFINED;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue