mirror of
https://github.com/isledecomp/isle-portable.git
synced 2026-02-03 12:31:15 +00:00
Use SDL IOStream for LegoStorage
This commit is contained in:
parent
e32e37ef26
commit
8986f3ddce
@ -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;
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
#include "mxgeometry/mxgeometry3d.h"
|
||||
#include "mxstring.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <SDL3/SDL_iostream.h>
|
||||
|
||||
// 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
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
#include "mxio.h"
|
||||
|
||||
#include "decomp.h"
|
||||
#include "mxstring.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <limits.h>
|
||||
@ -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;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user