From c340e12e7367c5b43daf06dd208885251215a8eb Mon Sep 17 00:00:00 2001 From: Matthew Stanley <1379tech@gmail.com> Date: Thu, 22 Oct 2026 14:18:15 -0700 Subject: [PATCH] Preserve spaces in remembered regional disc paths --- runtime/CMakeLists.txt | 7 ++++ runtime/include/regional_launch.h | 5 ++- runtime/tests/test_regional_selection.cpp | 39 +++++++++++++++++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 runtime/tests/test_regional_selection.cpp diff --git a/runtime/CMakeLists.txt b/runtime/CMakeLists.txt index c125b850..12167dc4 100644 --- a/runtime/CMakeLists.txt +++ b/runtime/CMakeLists.txt @@ -936,6 +936,13 @@ if(BUILD_TESTING) target_link_libraries(disc_path_resolve_test PRIVATE chdr-static) add_test(NAME disc_path_resolve_test COMMAND disc_path_resolve_test) + add_executable(regional_selection_test tests/test_regional_selection.cpp) + target_compile_features(regional_selection_test PRIVATE cxx_std_17) + target_include_directories(regional_selection_test PRIVATE include + ${PSXRECOMP_ROOT}/recompiler/lib/toml11) + add_test(NAME regional_selection_test COMMAND regional_selection_test + ${CMAKE_CURRENT_BINARY_DIR}/regional-selection-fixture) + # Both BIOS filename conventions (bare vs region-qualified) resolve, in # both directions, so a config and a dump folder may disagree. add_executable(bios_rom_alias_test tests/test_bios_rom_alias.cpp) diff --git a/runtime/include/regional_launch.h b/runtime/include/regional_launch.h index b3efa969..415095d6 100644 --- a/runtime/include/regional_launch.h +++ b/runtime/include/regional_launch.h @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -79,7 +80,9 @@ inline void remember(const Profile& profile,const std::string& disc) { 0 #endif )+".tmp"); - {std::ofstream out(temp,std::ios::binary);out<::max)());out.flush();if(!out)throw std::runtime_error("Cannot save regional selection");} #if defined(_WIN32) if(!MoveFileExW(temp.c_str(),(root/"europe-selection.toml").c_str(),MOVEFILE_REPLACE_EXISTING|MOVEFILE_WRITE_THROUGH)) throw std::runtime_error("Cannot commit regional selection"); diff --git a/runtime/tests/test_regional_selection.cpp b/runtime/tests/test_regional_selection.cpp new file mode 100644 index 00000000..2c374007 --- /dev/null +++ b/runtime/tests/test_regional_selection.cpp @@ -0,0 +1,39 @@ +// Exercise the production atomic writer and parser across formatting boundaries. +#if defined(_WIN32) +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN +#endif +#ifndef NOMINMAX +#define NOMINMAX +#endif +#include +#endif +#include "regional_launch.h" +#include +#include +#include + +int main(int argc, char** argv) { + if(argc!=2) return 2; + using namespace PSXRecompV4::regional; + root=fs::path(argv[1]);fs::create_directories(root); + const Profile profile{"SCES-01330","",0,{}}; + std::vector paths; + for(unsigned n=0;n<160;++n) { + paths.push_back("G:\\owned\\"+std::string(n,'d')+ + "\\Tombi! (Europe) (En,Fr,De,It,Nl) (Rev 1).cue"); + } + paths.push_back("G:\\"+std::string(80,'x')+"\\Tombi! (Europe) Espa\xc3\xb1ol.cue"); + paths.push_back("G:\\"+std::string(80,'x')+"\\Tombi! #game [Rev 1].cue"); + for(const auto& path:paths) { + remember(profile,path); + const auto state=toml::parse((root/"europe-selection.toml").string()); + if(toml::find(state,"disc")!=path || + toml::find(state,"profile")!=profile.id) { + std::fprintf(stderr,"FAIL: remembered path changed (%zu bytes)\n",path.size()); + return 1; + } + } + std::printf("PASS: %zu production selection roundtrips preserve spaces, escapes and UTF-8\n",paths.size()); + return 0; +}