18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-01 18:47:06 +01:00

fix(editor): file names outside the code page don't crash the project, includes are found in any case, a project file cut short isn't put in place

- The scenario index made a string of the name of every file in the folder, which throws on Windows for a name the ANSI code
  page can't hold (the class of GE#560). It looks at the extension first and leaves out a .scn the game couldn't open by its
  name either; the messages of the project file show paths as UTF-8.
- The includes are read with the FileCased() fallback of the game (scenery_text::file_text), so on Linux an include written in
  another case no longer drops the scenario from the index, skips the migration of its file or marks its tracks as changed by
  hand.
- save() closes the file before looking at it: a failed last flush no longer renames a truncated .new over the project.
- "next node 0" is refused instead of wrapping to 0xffffffff.
- open_project() writes no .eu07proj when there were no //$ lines to migrate, and asks exists() without throwing.
This commit is contained in:
maj00r
2026-11-24 18:54:33 +01:00
parent 2b36fbe9af
commit b15f7dcdec
8 changed files with 106 additions and 27 deletions
+17 -7
View File
@@ -9,6 +9,7 @@ http://mozilla.org/MPL/2.0/.
#include "stdafx.h"
#include "editor/project/sceneryText.hpp"
#include "utilities/utilities.h"
#include <algorithm>
#include <array>
@@ -93,13 +94,6 @@ std::string normalized(std::string_view const Name)
return result;
}
std::optional<std::string> file_text(std::filesystem::path const &Path)
{
std::ifstream file{Path, std::ios::binary};
if (false == file.is_open())
return std::nullopt;
return std::string{std::istreambuf_iterator<char>(file), std::istreambuf_iterator<char>()};
}
// (p1), (p2)... put in place by the parameters of the include, a missing one as none (cParser::substituteParameters())
void substitute(std::string &Text, std::vector<std::string> const &Parameters)
@@ -442,6 +436,22 @@ std::optional<std::string> node_text(std::string_view const Text, std::string_vi
return std::nullopt;
}
std::optional<std::string> file_text(std::filesystem::path const &Path)
{
std::ifstream file{Path, std::ios::binary};
if (false == file.is_open())
{
// named in another case, as the game finds it on Linux
auto const cased{FileCased(Path)};
if (cased.empty())
return std::nullopt;
file.open(cased, std::ios::binary);
if (false == file.is_open())
return std::nullopt;
}
return std::string{std::istreambuf_iterator<char>(file), std::istreambuf_iterator<char>()};
}
bool same_file(std::string_view const A, std::string_view const B)
{
return normalized(A) == normalized(B);