fix: list files whatever the case of their extensions on Linux

PhysicalFileSystem matches a search pattern case-insensitively, as on
Windows, so X.SCN, .BMP minis and .FIZ files of data made on Windows are
listed on Linux as well.
This commit is contained in:
maj00r
2026-11-13 16:11:58 +01:00
parent 52408a9931
commit 34f2ce99e8
2 changed files with 27 additions and 2 deletions

View File

@@ -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()
{

View File

@@ -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<string> GetFiles(string path, string searchPattern = "*") =>
Directory.Exists(path) ? Directory.GetFiles(path, searchPattern) : Array.Empty<string>();
Directory.Exists(path)
? Directory.GetFiles(path, searchPattern, new EnumerationOptions
{
IgnoreInaccessible = false,
AttributesToSkip = 0,
MatchType = MatchType.Win32,
MatchCasing = MatchCasing.CaseInsensitive
})
: Array.Empty<string>();
// A folder it may not enter costs what is in it, not the whole listing.
public IReadOnlyList<string> 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<string>();