Files
AnyPS5/core/relinker/io/src/FileWriter.cpp
T
aplatogg b74774f713 fix(relinker): support non-ASCII input paths on Windows
The MinGW CRT delivers argv to main as ANSI code page bytes, and every narrow string became a filesystem path through the same code page, so a game in a directory with characters outside the code page failed to open (#2692). Read the command line as Unicode (wmain via -municode), keep paths as UTF-8 strings, convert at the filesystem boundaries through Io::NativePath and Io::Utf8Path, and run the --autorun output through CreateProcessW.

(cherry picked from commit 30a5181f8a)
2026-10-10 17:22:07 +00:00

29 lines
891 B
C++

#include <io/FileWriter.hpp>
#include <io/NativePath.hpp>
#include <domain/Types.hpp>
#include <fstream>
namespace Io {
void FileWriter::Write(const std::string& path, const std::vector<std::uint8_t>& data) {
std::ofstream f(NativePath(path), std::ios::binary);
if (!f)
throw Domain::RelinkerException("Cannot open output file: " + path);
f.write(reinterpret_cast<const char*>(data.data()), static_cast<std::streamsize>(data.size()));
f.close();
if (!f)
throw Domain::RelinkerException("Failed to write file: " + path);
}
void FileWriter::Write(const std::string& path, const std::string& content) {
std::ofstream f(NativePath(path));
if (!f)
throw Domain::RelinkerException("Cannot open output file: " + path);
f << content;
f.close();
if (!f)
throw Domain::RelinkerException("Failed to write file: " + path);
}
}