#include "core/resources/resource_helper.hpp" #include #include #include namespace Resource::Helper { namespace { std::string g_data_root; } // namespace void setDataRoot(const std::string& absolute_path) { g_data_root = absolute_path; if (!g_data_root.empty() && g_data_root.back() != '/') { g_data_root += '/'; } } auto resolve(const std::string& filepath) -> std::string { if (filepath.empty() || filepath.front() == '/') { return filepath; } if (g_data_root.empty()) { return filepath; } return g_data_root + filepath; } auto loadFile(const std::string& filepath) -> std::vector { const auto FULL = resolve(filepath); std::ifstream file(FULL, std::ios::binary | std::ios::ate); if (!file) { std::cerr << "Resource::Helper: cannot open " << FULL << '\n'; return {}; } std::streamsize size = file.tellg(); file.seekg(0, std::ios::beg); std::vector data(static_cast(size)); if (!file.read(reinterpret_cast(data.data()), size)) { std::cerr << "Resource::Helper: failed to read " << FULL << '\n'; return {}; } return data; } } // namespace Resource::Helper