Files
GabsPuNs-Project_Zenith_Main/Minecraft.Client/Windows64/RmlUi_FileInterface.cpp
GabsPuNs 3ee643962d Fix compilation for MSVC, also moved some folders.
1. Added again the libraries for MSVC. If you need MinGW libraries version tell me
2. Removed "#include stdafx.h". Is not needed.
3. Renamed "RmlUIAssets" to "UI" and "Menus" to "Iggy"
2026-06-10 21:22:41 -04:00

90 lines
1.9 KiB
C++

#include "RmlUi_FileInterface.h"
FileInterface_Game::FileInterface_Game()
{
memset(m_files, 0, sizeof(m_files));
}
FileInterface_Game::~FileInterface_Game()
{
for (size_t i = 0; i < MAX_OPEN_FILES; i++)
{
if (m_files[i])
fclose(m_files[i]);
}
}
Rml::FileHandle FileInterface_Game::Open(const Rml::String& path)
{
// Try the path as-is first (for absolute paths)
FILE* fp;
if (fopen_s(&fp, path.c_str(), "rb") == 0 && fp)
{
for (size_t i = 0; i < MAX_OPEN_FILES; i++)
{
if (!m_files[i])
{
m_files[i] = fp;
return static_cast<Rml::FileHandle>(i + 1);
}
}
fclose(fp);
return 0;
}
// If asset path is set and path is relative, try prepending it
if (!m_asset_path.empty())
{
Rml::String full_path = m_asset_path + "/" + path;
if (fopen_s(&fp, full_path.c_str(), "rb") == 0 && fp)
{
for (size_t i = 0; i < MAX_OPEN_FILES; i++)
{
if (!m_files[i])
{
m_files[i] = fp;
return static_cast<Rml::FileHandle>(i + 1);
}
}
fclose(fp);
return 0;
}
}
return 0;
}
void FileInterface_Game::Close(Rml::FileHandle file)
{
size_t index = static_cast<size_t>(file) - 1;
if (index < MAX_OPEN_FILES && m_files[index])
{
fclose(m_files[index]);
m_files[index] = nullptr;
}
}
size_t FileInterface_Game::Read(void* buffer, size_t size, Rml::FileHandle file)
{
size_t index = static_cast<size_t>(file) - 1;
if (index < MAX_OPEN_FILES && m_files[index])
return fread(buffer, 1, size, m_files[index]);
return 0;
}
bool FileInterface_Game::Seek(Rml::FileHandle file, long offset, int origin)
{
size_t index = static_cast<size_t>(file) - 1;
if (index < MAX_OPEN_FILES && m_files[index])
return _fseeki64(m_files[index], offset, origin) == 0;
return false;
}
size_t FileInterface_Game::Tell(Rml::FileHandle file)
{
size_t index = static_cast<size_t>(file) - 1;
if (index < MAX_OPEN_FILES && m_files[index])
return _ftelli64(m_files[index]);
return 0;
}