mirror of
https://github.com/GabsPuNs/Project-Zenith-Main.git
synced 2026-08-08 14:21:15 +00:00
Add RmlUi
This commit is contained in:
90
Minecraft.Client/Windows64/RmlUi_FileInterface.cpp
Normal file
90
Minecraft.Client/Windows64/RmlUi_FileInterface.cpp
Normal file
@@ -0,0 +1,90 @@
|
||||
#include "stdafx.h"
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user