mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-20 06:55:02 +01:00
fix(physicslog): what no file name may have on Windows is replaced in the name of a log, on every system
A spawned vehicle is named <spawn>:<number>, and its log went to physicslog/<spawn>:<number>.dat. On NTFS that isn't even an error: it is the stream <number>.dat of the file <spawn>, which nothing lists, so the log was written and no one could find it. On Linux the file was there, under a name Windows can't open. The name of the file of a log has < > : " / \ | ? * and the control characters replaced by _, on every system, so the logs are named alike everywhere (spawn_ezt:12 is spawn_ezt_12.dat), and a _ before a name Windows keeps for a device (con, nul, com1..., with an extension too). The bytes of 1250 stay. The black box tells the log it begins by the same name. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -12,10 +12,12 @@ http://mozilla.org/MPL/2.0/.
|
||||
#include "utilities/Logs.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <exception>
|
||||
#include <fstream>
|
||||
#include <future>
|
||||
#include <memory>
|
||||
#include <string_view>
|
||||
#include <system_error>
|
||||
#include <utility>
|
||||
|
||||
@@ -36,6 +38,26 @@ void keep_last(std::string &Text, std::size_t const Most) {
|
||||
Text.erase(0, cut == std::string::npos ? Text.size() : cut + 1);
|
||||
}
|
||||
|
||||
// the name of the file of the log Name, its extension too. what no file name may have on Windows is replaced, on every
|
||||
// system, so the logs are named alike everywhere: a spawned vehicle is named <spawn>:<number>, and on NTFS "a:1.dat"
|
||||
// isn't even an error but the stream 1.dat of the file a, which nothing lists
|
||||
std::string file_name(std::string const &Name) {
|
||||
std::string name{Name};
|
||||
for (auto &character : name) {
|
||||
if (static_cast<unsigned char>(character) < 0x20 || std::string_view{R"(<>:"/\|?*)"}.find(character) != std::string_view::npos)
|
||||
character = '_';
|
||||
}
|
||||
// a device rather than a file, with any extension: con.dat is the console. told by the name before its first dot
|
||||
auto stem{name.substr(0, name.find('.'))};
|
||||
while (false == stem.empty() && stem.back() == ' ')
|
||||
stem.pop_back();
|
||||
std::ranges::transform(stem, stem.begin(), [](unsigned char const Character) { return static_cast<char>(std::toupper(Character)); });
|
||||
auto const numbered{stem.size() == 4 && (stem.starts_with("COM") || stem.starts_with("LPT")) && stem[3] >= '1' && stem[3] <= '9'};
|
||||
if (numbered || stem == "CON" || stem == "PRN" || stem == "AUX" || stem == "NUL")
|
||||
name.insert(0, 1, '_');
|
||||
return name + ".dat";
|
||||
}
|
||||
|
||||
// told in the log of the simulator, if there's the memory for it
|
||||
void tell(std::string const &Text) noexcept {
|
||||
try {
|
||||
@@ -115,7 +137,7 @@ void physicslog_writer::stop() {
|
||||
}
|
||||
|
||||
std::filesystem::path physicslog_writer::file(std::string const &Name) const {
|
||||
auto const name{Name + ".dat"};
|
||||
auto const name{file_name(Name)};
|
||||
#ifdef _WIN32
|
||||
// in the code page of the system, as the standard library would convert it, but with the bytes not of it replaced
|
||||
// instead of an exception thrown: a vehicle of a scenery written in 1250 on a Windows set to UTF-8, say
|
||||
@@ -130,7 +152,7 @@ std::filesystem::path physicslog_writer::file(std::string const &Name) const {
|
||||
}
|
||||
|
||||
std::string physicslog_writer::shown(std::string const &Name) const {
|
||||
return m_shownfolder + '/' + Name + ".dat";
|
||||
return m_shownfolder + '/' + file_name(Name);
|
||||
}
|
||||
|
||||
void physicslog_writer::start() {
|
||||
|
||||
Reference in New Issue
Block a user