mirror of
https://github.com/RetroPortingToolKit/psxrecomp
synced 2026-10-26 02:11:36 -04:00
Preserve spaces in remembered regional disc paths
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <toml.hpp>
|
||||
#include <cstdio>
|
||||
#include <fstream>
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
#include <stdexcept>
|
||||
@@ -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<<toml::format(state);out.flush();if(!out)throw std::runtime_error("Cannot save regional selection");}
|
||||
/* TOML continuation lines trim leading whitespace. Width-wrapping a
|
||||
* filename at a space would silently change the remembered disc path. */
|
||||
{std::ofstream out(temp,std::ios::binary);out<<toml::format(state,(std::numeric_limits<std::size_t>::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");
|
||||
|
||||
@@ -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 <windows.h>
|
||||
#endif
|
||||
#include "regional_launch.h"
|
||||
#include <cstdio>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
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<std::string> 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<std::string>(state,"disc")!=path ||
|
||||
toml::find<std::string>(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;
|
||||
}
|
||||
Reference in New Issue
Block a user