mirror of
https://github.com/MaSzyna-EU07/StarterNG.git
synced 2026-11-19 06:55:59 +01:00
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:
@@ -30,9 +30,12 @@ public static class LegacyText
|
||||
/// most files are 1250, and that was an exception per file on every load.
|
||||
/// A byte order mark is dropped, or it would stick to the first token.
|
||||
/// </summary>
|
||||
public static string Decode(byte[] bytes)
|
||||
public static string Decode(byte[] bytes) => Decode(bytes, out _);
|
||||
|
||||
/// <param name="encoding">What the file is written in, for what is made of it to go back in the same.</param>
|
||||
public static string Decode(byte[] bytes, out Encoding encoding)
|
||||
{
|
||||
var (encoding, bom) = Detect(bytes);
|
||||
(encoding, var bom) = Detect(bytes);
|
||||
return encoding.GetString(bytes, bom.Length, bytes.Length - bom.Length);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using StarterNG.Application.Abstractions;
|
||||
@@ -73,6 +74,7 @@ public sealed class SceneryRepository : ISceneryRepository
|
||||
|
||||
// Looked at ahead of the reading: changed meanwhile, it counts as changed.
|
||||
var sources = new Dictionary<string, FileStamp?> { [path] = FileStamp.Of(_files, path) };
|
||||
var encodings = new Dictionary<string, Encoding>(StringComparer.Ordinal);
|
||||
|
||||
// With its own .sbt the scenery's terrain comes from it, and the simulator
|
||||
// passes its terrain includes over without opening them.
|
||||
@@ -87,13 +89,21 @@ public sealed class SceneryRepository : ISceneryRepository
|
||||
string? file = ResolveInclude(name);
|
||||
string full = Path.Combine(_paths.Scenery, file ?? name.Replace('\\', '/'));
|
||||
sources[full] = FileStamp.Of(_files, full);
|
||||
return file is null ? null : (file, LegacyText.Decode(_files.ReadAllBytes(full)));
|
||||
if (file is null)
|
||||
return null;
|
||||
|
||||
string included = LegacyText.Decode(_files.ReadAllBytes(full), out var encoding);
|
||||
encodings[file] = encoding;
|
||||
return (file, included);
|
||||
}
|
||||
|
||||
string text = SceneryIncludes.Inline(LegacyText.Decode(_files.ReadAllBytes(path)), ReadInclude);
|
||||
string own = LegacyText.Decode(_files.ReadAllBytes(path), out var ownEncoding);
|
||||
string text = SceneryIncludes.Inline(own, ReadInclude);
|
||||
var scenery = _parser.Parse(path, text, FindInclude);
|
||||
scenery.HasCompanionTimetable = binaryTerrain;
|
||||
scenery.Sources = sources;
|
||||
scenery.TextEncoding = ownEncoding;
|
||||
scenery.IncludeEncodings = encodings;
|
||||
return scenery;
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
Reference in New Issue
Block a user