Keep each file's encoding in the copy written for a start

The copy carries the scenario includes put in place of their include lines,
read as UTF-8 where they are, and it was written all in code page 1250. A name
with a Polish letter in a UTF-8 include then no longer matched the same name in
the files the simulator reads apart, and what 1250 lacks became '?'. Each part
now goes out in the encoding of the file it came from, the scenery's own file
too, as a save of a trainset already did.
This commit is contained in:
maj00r
2026-11-03 21:51:52 +01:00
parent 32d7417c22
commit a8f8cb0b74
6 changed files with 79 additions and 8 deletions

View File

@@ -98,4 +98,25 @@ public class SceneryRepositoryTests
Assert.Null(new SceneryImageLocator(files).Resolve(scenery));
}
[Fact]
public void The_copy_written_for_a_start_keeps_each_file_in_its_own_encoding()
{
const string cars =
"trainset none droga 0 0\r\n" +
"node -1 0 żuk dynamic road\\zuk zuk zuk 0 headdriver 0 0 enddynamic\r\n" +
"endtrainset\r\n";
var files = new InMemoryFileSystem()
.WithLegacyFile(Path.Combine("game", "scenery", "kato.scn"),
"//$n Łódź\r\nFirstInit\r\ninclude auta.scm end\r\n")
.WithFile(Path.Combine("game", "scenery", "auta.scm"), cars);
var scenery = Assert.Single(Build(files, out _).LoadAll());
byte[] exported = scenery.BuildExportBytes(skipDecorTrainsets: false, new StubRandom());
static bool Has(byte[] text, byte[] part) => text.AsSpan().IndexOf(part) >= 0;
Assert.True(Has(exported, LegacyText.CodePage1250.GetBytes("//$n Łódź\r\n")));
Assert.True(Has(exported, Encoding.UTF8.GetBytes("żuk dynamic")));
Assert.False(Has(exported, Encoding.UTF8.GetBytes("Łódź")));
}
}