From ef111342f92b21cfe36f690cf3827c300a89a4f3 Mon Sep 17 00:00:00 2001 From: Codex Date: Thu, 22 Oct 2026 21:51:34 +0200 Subject: [PATCH] Handle Unicode Windows profile paths in editor settings (by Codex) --- docs/qa/editor-poc/README.md | 1 + src/editor/options.cpp | 13 ++++++++++--- tests/editor_core_tests.cpp | 20 ++++++++++++++++++++ 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/docs/qa/editor-poc/README.md b/docs/qa/editor-poc/README.md index 993058c..32e604e 100644 --- a/docs/qa/editor-poc/README.md +++ b/docs/qa/editor-poc/README.md @@ -24,6 +24,7 @@ Validation performed: references, dates/scales, roster moves/swaps/order, shared undo/redo/save checkpoint, atomic OBW overwrite, exact image originals, arbitrary SVG/raster transforms, unknown-extension preservation and authenticated MCP HTTP. + Windows additionally checks a profile directory containing non-ASCII letters. - `tests/editor_gui_smoke.py`: real mouse/keyboard inspector edit; untouched JSON colour field retained; native search focus; shared MCP/native undo/redo; save to OBW. This check caught and fixed RmlUI textarea entity handling and diff --git a/src/editor/options.cpp b/src/editor/options.cpp index 76d93a3..10e42a4 100644 --- a/src/editor/options.cpp +++ b/src/editor/options.cpp @@ -3,7 +3,10 @@ #include #include #include -#ifndef _WIN32 +#ifdef _WIN32 +#define NOMINMAX +#include +#else #include #endif namespace bmh::editor { @@ -11,8 +14,12 @@ Options Options::load(fs::path override_path) { Options result; if (override_path.empty()) { #ifdef _WIN32 - auto base = std::getenv("APPDATA"); - override_path = (base ? path(base) : fs::temp_directory_path()) / "OpenBMH" / "editor.json"; + // The narrow CRT environment is encoded in the active Windows code + // page, not UTF-8. Use the native path for names such as Müller. + wchar_t base[32768]{}; + const auto count = GetEnvironmentVariableW(L"APPDATA", base, 32768); + override_path = + (count > 0 && count < 32768 ? fs::path(base) : fs::temp_directory_path()) / "OpenBMH" / "editor.json"; #elif defined(__APPLE__) auto base = std::getenv("HOME"); override_path = diff --git a/tests/editor_core_tests.cpp b/tests/editor_core_tests.cpp index 2e8d154..1ab921c 100644 --- a/tests/editor_core_tests.cpp +++ b/tests/editor_core_tests.cpp @@ -5,6 +5,10 @@ #include #include #include +#ifdef _WIN32 +#define NOMINMAX +#include +#endif using namespace bmh::editor; namespace { @@ -175,6 +179,22 @@ int main() { options.apply({{"language", "en"}, {"theme", "silver"}, {"mcp_port", 0}}); options.save(); check(Options::load(root / "settings.json").language == "en", "persistent language"); +#ifdef _WIN32 + { + wchar_t old_value[32768]{}; + const auto length = GetEnvironmentVariableW(L"APPDATA", old_value, 32768); + struct Restore { + std::wstring value; + bool present; + ~Restore() { SetEnvironmentVariableW(L"APPDATA", present ? value.c_str() : nullptr); } + } restore{old_value, length > 0}; + const auto profile = root / L"Profil-ÄÖÜ"; + SetEnvironmentVariableW(L"APPDATA", profile.c_str()); + const auto native_options = Options::load(); + check(native_options.settings_file == profile / "OpenBMH/editor.json", "Unicode Windows profile path"); + check(fs::is_regular_file(native_options.settings_file), "Unicode Windows settings saved"); + } +#endif check(tr("de", "clubs") != tr("en", "clubs"), "bilingual labels"); McpServer mcp(s); mcp.start(options);