Finish Classic 0.2 portability and release preparation (by Codex)

This commit is contained in:
Codex committed 2026-10-18 20:51:39 +02:00
1 parent 74ca973111
commit 6e5fa72ed5
13 files changed
+186 -25

No files matched your search

+5 -1
View File
@@ -33,7 +33,11 @@ Documents read_archive(const fs::path &file) {
if (fs::is_symlink(fs::symlink_status(file)) || !fs::is_regular_file(file) ||
fs::file_size(file) > 128ull * 1024 * 1024)
fail("invalid native archive");
const auto input = read_file(file);
// The archive itself remains a real file when its path is a mounted asset root.
std::ifstream stream(file, std::ios::binary);
std::string input(size_t(fs::file_size(file)), '\0');
if (!stream.read(input.data(), std::streamsize(input.size())))
fail("cannot read native archive");
mz_zip_archive zip{};
if (!mz_zip_reader_init_mem(&zip, input.data(), input.size(), 0))
fail("invalid ZIP archive");
+5
View File
@@ -34,8 +34,13 @@ include(../launch/rmlui.cmake)
target_sources(bmh_launcher PRIVATE ../launch/launcher_rmlui.cpp)
target_link_libraries(bmh_launcher PRIVATE bmh_rmlui nfd)
add_executable(launcher_document_tests ../../tests/launcher_document_tests.cpp)
target_include_directories(launcher_document_tests PRIVATE ..)
target_link_libraries(launcher_document_tests PRIVATE RmlUi::Core)
add_test(NAME launcher_document_tests COMMAND launcher_document_tests "${launcher_assets}")
add_test(NAME launcher_unicode_document_tests COMMAND launcher_document_tests "${launcher_assets}" unicode)
if(MSVC)
target_compile_options(launcher_document_tests PRIVATE /utf-8)
endif()
add_executable(native_content_tests ../../tests/native_content_tests.cpp)
target_link_libraries(native_content_tests PRIVATE bmh_launcher)
add_test(NAME native_content_tests COMMAND native_content_tests)
+6 -2
View File
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: GPL-3.0-only
#include "launch/launcher_ui.hpp"
#include "launch/rml_path.hpp"
#include "launch/archive.hpp"
#include "launch/process.hpp"
#include "version.hpp"
@@ -117,6 +118,7 @@ struct Video {
};
class RmlLauncher final : public LauncherUI, public Rml::EventListener {
Video video_;
rml::AssetFiles files_;
SystemInterface_SDL system_{video_.window};
RenderInterface_GL3 renderer_;
TextInputMethodEditor_SDL ime_;
@@ -215,6 +217,7 @@ class RmlLauncher final : public LauncherUI, public Rml::EventListener {
answered_ = accepted_ = false;
display("overlay", true);
modal_visible_ = true;
context_->Update();
if (auto *input = document_->GetElementById("mod-name"))
input->Focus(true);
else
@@ -391,6 +394,7 @@ class RmlLauncher final : public LauncherUI, public Rml::EventListener {
throw std::runtime_error("RmlUI could not create the OpenGL renderer");
try {
Rml::SetSystemInterface(&system_);
Rml::SetFileInterface(&files_);
Rml::SetRenderInterface(&renderer_);
Rml::SetTextInputHandler(&ime_);
initialized_ = Rml::Initialise();
@@ -398,12 +402,12 @@ class RmlLauncher final : public LauncherUI, public Rml::EventListener {
throw std::runtime_error("RmlUI initialization failed");
const auto assets = executable_path({}).parent_path() / "assets" / "launcher";
for (const char *weight : {"Regular", "Bold"})
if (!Rml::LoadFontFace(path_to_utf8(assets / (std::string("LatoLatin-") + weight + ".ttf"))))
if (!Rml::LoadFontFace(rml::asset_path(assets / (std::string("LatoLatin-") + weight + ".ttf"))))
throw std::runtime_error("Launcher font missing; extract the complete OpenBMH package");
context_ = Rml::CreateContext("launcher", {1100, 688});
if (!context_)
throw std::runtime_error("RmlUI launcher context failed");
document_ = context_->LoadDocument(path_to_utf8(assets / "launcher.rml"));
document_ = context_->LoadDocument(rml::asset_path(assets / "launcher.rml"));
if (!document_)
throw std::runtime_error("Launcher layout missing; extract the complete OpenBMH package");
document_->AddEventListener("click", this);
+35
View File
@@ -0,0 +1,35 @@
// SPDX-License-Identifier: GPL-3.0-only
#pragma once
#include <filesystem>
#include <string>
#include <cstdio>
#include <RmlUi/Core/FileInterface.h>
namespace bmh::rml {
// RmlUI parses document locations as URLs. Native Windows backslashes make
// URL::GetPath() empty, so relative image sources lose their asset directory.
inline std::string asset_path(const std::filesystem::path &path) {
const auto utf8 = path.generic_u8string();
return {utf8.begin(), utf8.end()};
}
// RmlUI paths are UTF-8. The Windows narrow fopen API uses the system code page.
class AssetFiles : public Rml::FileInterface {
public:
Rml::FileHandle Open(const Rml::String &path) override {
#ifdef _WIN32
const std::u8string utf8(path.begin(), path.end());
return reinterpret_cast<Rml::FileHandle>(_wfopen(std::filesystem::path(utf8).c_str(), L"rb"));
#else
return reinterpret_cast<Rml::FileHandle>(std::fopen(path.c_str(), "rb"));
#endif
}
void Close(Rml::FileHandle file) override { std::fclose(reinterpret_cast<FILE *>(file)); }
size_t Read(void *buffer, size_t size, Rml::FileHandle file) override {
return std::fread(buffer, 1, size, reinterpret_cast<FILE *>(file));
}
bool Seek(Rml::FileHandle file, long offset, int origin) override {
return std::fseek(reinterpret_cast<FILE *>(file), offset, origin) == 0;
}
size_t Tell(Rml::FileHandle file) override { return size_t(std::ftell(reinterpret_cast<FILE *>(file))); }
};
} // namespace bmh::rml