diff --git a/StarterNG.Tests/PhysicalFileSystemTests.cs b/StarterNG.Tests/PhysicalFileSystemTests.cs index 1d0e85c..811e812 100644 --- a/StarterNG.Tests/PhysicalFileSystemTests.cs +++ b/StarterNG.Tests/PhysicalFileSystemTests.cs @@ -21,6 +21,20 @@ public sealed class PhysicalFileSystemTests : IDisposable Assert.Equal(new[] { path }, Directory.GetFiles(_root)); } + [Fact] + public void A_pattern_lists_names_in_any_letter_case() + { + Directory.CreateDirectory(Path.Combine(_root, "PKP", "EP09")); + foreach (string name in new[] { "Braniewo.SCN", "kato.scn", "notes.txt", Path.Combine("PKP", "EP09", "EP09.FIZ"), + Path.Combine("PKP", "EP09", "ep09dumb.fiz") }) + File.WriteAllText(Path.Combine(_root, name), ""); + + Assert.Equal(new[] { "Braniewo.SCN", "kato.scn" }, + _files.GetFiles(_root, "*.scn").Select(Path.GetFileName).Order(StringComparer.Ordinal)); + Assert.Equal(new[] { "EP09.FIZ", "ep09dumb.fiz" }, + _files.GetFilesRecursive(_root, "*.fiz").Select(Path.GetFileName).Order(StringComparer.Ordinal)); + } + [Fact] public void An_atomic_write_that_cannot_finish_leaves_what_stood_there() { diff --git a/StarterNG/Infrastructure/Adapters/PhysicalFileSystem.cs b/StarterNG/Infrastructure/Adapters/PhysicalFileSystem.cs index 14ab1d6..dcdc457 100644 --- a/StarterNG/Infrastructure/Adapters/PhysicalFileSystem.cs +++ b/StarterNG/Infrastructure/Adapters/PhysicalFileSystem.cs @@ -91,8 +91,18 @@ public sealed class PhysicalFileSystem : IFileSystem public void CopyFile(string sourcePath, string destinationPath, bool overwrite) => File.Copy(sourcePath, destinationPath, overwrite); + // The pattern matches names in any letter case, as on Windows: the game's data, + // made there, has X.SCN as well as x.scn. public IReadOnlyList GetFiles(string path, string searchPattern = "*") => - Directory.Exists(path) ? Directory.GetFiles(path, searchPattern) : Array.Empty(); + Directory.Exists(path) + ? Directory.GetFiles(path, searchPattern, new EnumerationOptions + { + IgnoreInaccessible = false, + AttributesToSkip = 0, + MatchType = MatchType.Win32, + MatchCasing = MatchCasing.CaseInsensitive + }) + : Array.Empty(); // A folder it may not enter costs what is in it, not the whole listing. public IReadOnlyList GetFilesRecursive(string path, string searchPattern) => @@ -102,7 +112,8 @@ public sealed class PhysicalFileSystem : IFileSystem RecurseSubdirectories = true, IgnoreInaccessible = true, AttributesToSkip = 0, - MatchType = MatchType.Win32 + MatchType = MatchType.Win32, + MatchCasing = MatchCasing.CaseInsensitive }) : Array.Empty();