From 52408a99311fee3ba7958a81dac36df1bb7964a0 Mon Sep 17 00:00:00 2001 From: maj00r Date: Fri, 13 Nov 2026 16:08:06 +0100 Subject: [PATCH] fix: follow .fiz includes and check vehicle files whatever their case An include in a .fiz is looked up in the vehicle's folder through CaseInsensitivePaths, so its physics are read on Linux when the include names the file in other letter case. The missing-asset scan finds skins and models the same way, with extensions in any case, instead of reporting files that are there. --- StarterNG.Tests/PhysicsAndAssetsTests.cs | 40 ++++++++++++++++++ .../Vehicles/FizPhysicsRepository.cs | 7 +++- .../Vehicles/MissingAssetScanner.cs | 41 +++++++++++-------- 3 files changed, 70 insertions(+), 18 deletions(-) diff --git a/StarterNG.Tests/PhysicsAndAssetsTests.cs b/StarterNG.Tests/PhysicsAndAssetsTests.cs index 1e86f73..5c6066d 100644 --- a/StarterNG.Tests/PhysicsAndAssetsTests.cs +++ b/StarterNG.Tests/PhysicsAndAssetsTests.cs @@ -65,6 +65,19 @@ public class PhysicsAndAssetsTests Assert.Equal(125, physics.VMax); } + [Fact] + public void An_include_named_in_other_case_is_followed() + { + var installation = new TestInstallation(new InMemoryFileSystem(caseSensitive: true) + .WithFile(Fiz("pkp", "ep07", "ep07"), "include Common.FIZ 84000 end") + .WithFile(TestInstallation.At("dynamic", "pkp", "ep07", "common.fiz"), "Param: M=(1) Vmax=125")); + + var physics = installation.Physics.For("pkp/ep07/", "ep07")!; + + Assert.Equal(84000, physics.Mass); + Assert.Equal(125, physics.VMax); + } + [Fact] public void A_dot_in_the_model_name_is_part_of_the_name() { @@ -202,4 +215,31 @@ public class PhysicsAndAssetsTests Assert.Empty(installation.MissingAssets.Scan(installation.Library.Vehicles)); } + + [Fact] + public void A_livery_with_no_folder_is_looked_for_in_dynamic_itself() + { + var installation = new TestInstallation(new InMemoryFileSystem(caseSensitive: true) + .WithFile(TestInstallation.At("dynamic", "EP09.bmp"), "bitmap") + .WithFile(TestInstallation.At("dynamic", "ep09.e3d"), "model")); + var catalog = new StarterNG.Domain.Vehicles.VehicleCatalog(installation.MiniTextures); + catalog.Textures.Add(new StarterNG.Domain.Vehicles.VehicleTexture { Directory = "", Skinfile = "ep09", Model = "EP09" }); + + Assert.Empty(installation.MissingAssets.Scan(catalog)); + } + + [Fact] + public void A_skin_and_model_on_disk_in_other_case_are_not_reported() + { + var files = new InMemoryFileSystem(caseSensitive: true) + .WithFile(TestInstallation.At("dynamic", "PKP", "EP09", "textures.txt"), + "EP09-014.mat=ep09.e3d,ep09") + .WithFile(TestInstallation.At("dynamic", "PKP", "EP09", "ep09-014.BMP"), "bitmap") + .WithFile(TestInstallation.At("dynamic", "PKP", "EP09", "EP09.E3D"), "model"); + var installation = new TestInstallation(files); + installation.Vehicles.Load(installation.Library.Vehicles); + Assert.NotEmpty(installation.Library.Vehicles.Textures); + + Assert.Empty(installation.MissingAssets.Scan(installation.Library.Vehicles)); + } } diff --git a/StarterNG/Infrastructure/Vehicles/FizPhysicsRepository.cs b/StarterNG/Infrastructure/Vehicles/FizPhysicsRepository.cs index e17128a..845472d 100644 --- a/StarterNG/Infrastructure/Vehicles/FizPhysicsRepository.cs +++ b/StarterNG/Infrastructure/Vehicles/FizPhysicsRepository.cs @@ -23,6 +23,7 @@ public sealed class FizPhysicsRepository : IPhysicsRepository }; private readonly IFileSystem _files; + private readonly CaseInsensitivePaths _names; private readonly IGamePaths _paths; private readonly IDiagnosticsLog _log; @@ -38,6 +39,7 @@ public sealed class FizPhysicsRepository : IPhysicsRepository public FizPhysicsRepository(IFileSystem files, IGamePaths paths, IDiagnosticsLog log) { _files = files; + _names = new CaseInsensitivePaths(files); _paths = paths; _log = log; } @@ -165,8 +167,9 @@ public sealed class FizPhysicsRepository : IPhysicsRepository while (i < tokens.Count && !tokens[i].Equals("end", StringComparison.OrdinalIgnoreCase)) includeParameters.Add(Resolve(tokens[i++], parameters)); - Parse(physics, Path.Combine(directory, includeFile), directory, includeParameters.ToArray(), - depth + 1); + // Named in the letter case of whoever wrote the include, not always that of the file. + string included = _names.Find(directory, includeFile) ?? Path.Combine(directory, includeFile); + Parse(physics, included, directory, includeParameters.ToArray(), depth + 1); pendingKey = null; continue; } diff --git a/StarterNG/Infrastructure/Vehicles/MissingAssetScanner.cs b/StarterNG/Infrastructure/Vehicles/MissingAssetScanner.cs index d303e69..6c523d7 100644 --- a/StarterNG/Infrastructure/Vehicles/MissingAssetScanner.cs +++ b/StarterNG/Infrastructure/Vehicles/MissingAssetScanner.cs @@ -10,44 +10,53 @@ public sealed class MissingAssetScanner private static readonly string[] TextureExtensions = { ".mat", ".bmp" }; private static readonly string[] ModelExtensions = { ".t3d", ".e3d" }; - private readonly IFileSystem _files; private readonly IGamePaths _paths; + private readonly CaseInsensitivePaths _names; public MissingAssetScanner(IFileSystem files, IGamePaths paths) { - _files = files; _paths = paths; + _names = new CaseInsensitivePaths(files, keepListings: true); } public List Scan(VehicleCatalog catalog) { var lines = new List(); - - foreach (var texture in catalog.Textures) + try { - string directory = Path.Combine( - _paths.Dynamic, - texture.Directory.Replace('/', Path.DirectorySeparatorChar).TrimEnd('\\', '/')); + foreach (var texture in catalog.Textures) + { + string directory = texture.Directory.Replace('\\', '/').TrimEnd('/'); - if (!string.IsNullOrEmpty(texture.Skinfile) && - !ExistsWithAnyExtension(Path.Combine(directory, texture.Skinfile), TextureExtensions)) - lines.Add($"# no file: {texture.Directory}{texture.Skinfile}"); + if (!string.IsNullOrEmpty(texture.Skinfile) && + !ExistsWithAnyExtension(Under(directory, texture.Skinfile), TextureExtensions)) + lines.Add($"# no file: {texture.Directory}{texture.Skinfile}"); - if (!string.IsNullOrEmpty(texture.Model) && - !ExistsWithAnyExtension(Path.Combine(directory, texture.Model), ModelExtensions)) - lines.Add($"# no model: {texture.Directory}{texture.Model}"); + if (!string.IsNullOrEmpty(texture.Model) && + !ExistsWithAnyExtension(Under(directory, texture.Model), ModelExtensions)) + lines.Add($"# no model: {texture.Directory}{texture.Model}"); + } + } + finally + { + // The folders are listed once for the whole catalog, and not kept past it. + _names.Forget(); } return lines; } - private bool ExistsWithAnyExtension(string path, string[] extensions) + private static string Under(string directory, string name) => + directory.Length == 0 ? name : directory + "/" + name; + + /// Whether the file is under dynamic as named, or with one of the extensions, in any letter case. + private bool ExistsWithAnyExtension(string name, string[] extensions) { - if (_files.FileExists(path)) + if (_names.Resolve(_paths.Dynamic, name) is not null) return true; foreach (string extension in extensions) - if (_files.FileExists(Path.ChangeExtension(path, extension))) + if (_names.Resolve(_paths.Dynamic, Path.ChangeExtension(name, extension)) is not null) return true; return false;