save state

This commit is contained in:
2026-01-16 16:34:32 +01:00
parent fbb6917812
commit a35c222570
15 changed files with 1052 additions and 266 deletions

View File

@@ -0,0 +1,66 @@
// D:\Dev\Mosis\MosisService\designer\src\desktop_file_interface.cpp
#include "desktop_file_interface.h"
#include <cstdio>
#include <filesystem>
namespace fs = std::filesystem;
namespace mosis {
void DesktopFileInterface::SetAssetsPath(const std::string& path) {
m_assets_path = path;
// Ensure trailing separator
if (!m_assets_path.empty() && m_assets_path.back() != '/' && m_assets_path.back() != '\\') {
m_assets_path += '/';
}
}
std::string DesktopFileInterface::ResolvePath(const std::string& path) const {
// If path is absolute, use it directly
if (fs::path(path).is_absolute()) {
return path;
}
// Otherwise, prepend assets path
return m_assets_path + path;
}
Rml::FileHandle DesktopFileInterface::Open(const Rml::String& path) {
std::string resolved = ResolvePath(path);
FILE* file = fopen(resolved.c_str(), "rb");
return reinterpret_cast<Rml::FileHandle>(file);
}
void DesktopFileInterface::Close(Rml::FileHandle file) {
if (file) {
fclose(reinterpret_cast<FILE*>(file));
}
}
size_t DesktopFileInterface::Read(void* buffer, size_t size, Rml::FileHandle file) {
if (!file) return 0;
return fread(buffer, 1, size, reinterpret_cast<FILE*>(file));
}
bool DesktopFileInterface::Seek(Rml::FileHandle file, long offset, int origin) {
if (!file) return false;
return fseek(reinterpret_cast<FILE*>(file), offset, origin) == 0;
}
size_t DesktopFileInterface::Tell(Rml::FileHandle file) {
if (!file) return 0;
return static_cast<size_t>(ftell(reinterpret_cast<FILE*>(file)));
}
size_t DesktopFileInterface::Length(Rml::FileHandle file) {
if (!file) return 0;
FILE* f = reinterpret_cast<FILE*>(file);
long current = ftell(f);
fseek(f, 0, SEEK_END);
long length = ftell(f);
fseek(f, current, SEEK_SET);
return static_cast<size_t>(length);
}
} // namespace mosis