diff --git a/LEGO1/lego/sources/misc/legostorage.cpp b/LEGO1/lego/sources/misc/legostorage.cpp index 7da93569..af4ecb8e 100644 --- a/LEGO1/lego/sources/misc/legostorage.cpp +++ b/LEGO1/lego/sources/misc/legostorage.cpp @@ -42,7 +42,7 @@ LegoFile::LegoFile() LegoFile::~LegoFile() { if (m_file) { - fclose(m_file); + SDL_CloseIO(m_file); } } @@ -52,7 +52,7 @@ LegoResult LegoFile::Read(void* p_buffer, LegoU32 p_size) if (!m_file) { return FAILURE; } - if (fread(p_buffer, 1, p_size, m_file) != p_size) { + if (SDL_ReadIO(m_file, p_buffer, p_size) != p_size) { return FAILURE; } return SUCCESS; @@ -64,7 +64,7 @@ LegoResult LegoFile::Write(const void* p_buffer, LegoU32 p_size) if (!m_file) { return FAILURE; } - if (fwrite(p_buffer, 1, p_size, m_file) != p_size) { + if (SDL_WriteIO(m_file, p_buffer, p_size) != p_size) { return FAILURE; } return SUCCESS; @@ -76,7 +76,7 @@ LegoResult LegoFile::GetPosition(LegoU32& p_position) if (!m_file) { return FAILURE; } - LegoU32 position = ftell(m_file); + Sint64 position = SDL_TellIO(m_file); if (position == -1) { return FAILURE; } @@ -90,7 +90,7 @@ LegoResult LegoFile::SetPosition(LegoU32 p_position) if (!m_file) { return FAILURE; } - if (fseek(m_file, p_position, SEEK_SET) != 0) { + if (SDL_SeekIO(m_file, p_position, SDL_IO_SEEK_SET) != p_position) { return FAILURE; } return SUCCESS; @@ -100,7 +100,7 @@ LegoResult LegoFile::SetPosition(LegoU32 p_position) LegoResult LegoFile::Open(const char* p_name, LegoU32 p_mode) { if (m_file) { - fclose(m_file); + SDL_CloseIO(m_file); } char mode[4]; mode[0] = '\0'; @@ -115,13 +115,15 @@ LegoResult LegoFile::Open(const char* p_name, LegoU32 p_mode) strcat(mode, "w"); } if ((p_mode & c_text) != 0) { - strcat(mode, "t"); } else { strcat(mode, "b"); } - if (!(m_file = fopen(p_name, mode))) { + MxString path(p_name); + path.NormalizePath(); + + if (!(m_file = SDL_IOFromFile(path.GetData(), mode))) { return FAILURE; } return SUCCESS; diff --git a/LEGO1/lego/sources/misc/legostorage.h b/LEGO1/lego/sources/misc/legostorage.h index 5de72303..16cc976c 100644 --- a/LEGO1/lego/sources/misc/legostorage.h +++ b/LEGO1/lego/sources/misc/legostorage.h @@ -5,7 +5,7 @@ #include "mxgeometry/mxgeometry3d.h" #include "mxstring.h" -#include +#include // VTABLE: LEGO1 0x100d7d80 // SIZE 0x08 @@ -149,7 +149,7 @@ class LegoFile : public LegoStorage { // LegoFile::`scalar deleting destructor' protected: - FILE* m_file; // 0x08 + SDL_IOStream* m_file; // 0x08 }; #endif // __LEGOSTORAGE_H diff --git a/LEGO1/omni/include/mxstring.h b/LEGO1/omni/include/mxstring.h index 79bab68c..ccaafbed 100644 --- a/LEGO1/omni/include/mxstring.h +++ b/LEGO1/omni/include/mxstring.h @@ -17,6 +17,7 @@ class MxString : public MxCore { void Reverse(); void ToUpperCase(); void ToLowerCase(); + void NormalizePath() { NormalizePath(m_data); } MxString& operator=(const MxString& p_str); const MxString& operator=(const char* p_str); diff --git a/LEGO1/omni/src/common/mxutilities.cpp b/LEGO1/omni/src/common/mxutilities.cpp index 9be9150c..7f3b3205 100644 --- a/LEGO1/omni/src/common/mxutilities.cpp +++ b/LEGO1/omni/src/common/mxutilities.cpp @@ -77,9 +77,6 @@ void MakeSourceName(char* p_output, const char* p_input) if (extLoc) { *extLoc = 0; } - - // [library:filesystem] Normalize this name since it will be part of a path. - MxString::NormalizePath(p_output); } // FUNCTION: LEGO1 0x100b7050 diff --git a/LEGO1/omni/src/stream/mxio.cpp b/LEGO1/omni/src/stream/mxio.cpp index 60d927c2..dbc9a78d 100644 --- a/LEGO1/omni/src/stream/mxio.cpp +++ b/LEGO1/omni/src/stream/mxio.cpp @@ -1,6 +1,7 @@ #include "mxio.h" #include "decomp.h" +#include "mxstring.h" #include #include @@ -40,9 +41,9 @@ MxU16 MXIOINFO::Open(const char* p_filename, MxULong p_flags) m_info.lDiskOffset = m_info.lBufOffset = 0; - // DECOMP: Cast of p_flags to u16 forces the `movzx` instruction - // original: m_info.hmmio = OpenFile(p_filename, &unused, (MxU16) p_flags); - ASSIGN_M_FILE(SDL_IOFromFile(p_filename, "rb")); + MxString path(p_filename); + path.NormalizePath(); + ASSIGN_M_FILE(SDL_IOFromFile(path.GetData(), "rb")); if (M_FILE != NULL) { m_info.dwFlags = p_flags;