18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-01 09:27:10 +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
+10 -4
View File
@@ -491,9 +491,8 @@ std::vector<marked_file> marked_files(std::filesystem::path const &Folder, std::
// the templates (*.inc) are a part of the layer including them, their own lines are the descriptions (//$e)
if (scenery_text::lowered(file.name).ends_with(".inc"))
continue;
std::ifstream input{Folder / file.name, std::ios::binary};
std::string const text{std::istreambuf_iterator<char>(input), std::istreambuf_iterator<char>()};
auto lines{marked_lines(text)};
auto const text{scenery_text::file_text(Folder / file.name)};
auto lines{marked_lines(text.value_or(std::string{}))};
if (lines.empty())
continue;
result.push_back({file.name, file.context, std::move(lines)});
@@ -505,13 +504,20 @@ opened open_project(std::filesystem::path const &Folder, std::string const &Map,
{
opened result;
auto const path{path_of(Folder / Map)};
if (std::filesystem::exists(path))
if (std::error_code error; std::filesystem::exists(path, error))
{
result.project = load(path);
return result;
}
auto made{migrate(marked_files(Folder, Map), Areas)};
result.notes = std::move(made.notes);
// no //$ lines: no file is written next to the map, which would be one more stray file in a working copy of the data. The project,
// empty, is written as the editor saves the scenery once it has something
if (made.project.network.lines().empty() && made.project.network.nodes().empty())
{
result.project.project = std::move(made.project);
return result;
}
std::string error;
if (false == save(made.project, path, error))
{