mirror of
https://github.com/MaSzyna-EU07/StarterNG.git
synced 2026-11-19 15:02:15 +01:00
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:
@@ -21,6 +21,20 @@ public sealed class PhysicalFileSystemTests : IDisposable
|
|||||||
Assert.Equal(new[] { path }, Directory.GetFiles(_root));
|
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]
|
[Fact]
|
||||||
public void An_atomic_write_that_cannot_finish_leaves_what_stood_there()
|
public void An_atomic_write_that_cannot_finish_leaves_what_stood_there()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -91,8 +91,18 @@ public sealed class PhysicalFileSystem : IFileSystem
|
|||||||
public void CopyFile(string sourcePath, string destinationPath, bool overwrite) =>
|
public void CopyFile(string sourcePath, string destinationPath, bool overwrite) =>
|
||||||
File.Copy(sourcePath, destinationPath, 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 = "*") =>
|
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.
|
// A folder it may not enter costs what is in it, not the whole listing.
|
||||||
public IReadOnlyList<string> GetFilesRecursive(string path, string searchPattern) =>
|
public IReadOnlyList<string> GetFilesRecursive(string path, string searchPattern) =>
|
||||||
@@ -102,7 +112,8 @@ public sealed class PhysicalFileSystem : IFileSystem
|
|||||||
RecurseSubdirectories = true,
|
RecurseSubdirectories = true,
|
||||||
IgnoreInaccessible = true,
|
IgnoreInaccessible = true,
|
||||||
AttributesToSkip = 0,
|
AttributesToSkip = 0,
|
||||||
MatchType = MatchType.Win32
|
MatchType = MatchType.Win32,
|
||||||
|
MatchCasing = MatchCasing.CaseInsensitive
|
||||||
})
|
})
|
||||||
: Array.Empty<string>();
|
: Array.Empty<string>();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user