diff --git a/Library/DiscUtils.Wim/WimFileSystem.cs b/Library/DiscUtils.Wim/WimFileSystem.cs index f47f6049f..4540f8cd9 100644 --- a/Library/DiscUtils.Wim/WimFileSystem.cs +++ b/Library/DiscUtils.Wim/WimFileSystem.cs @@ -711,7 +711,7 @@ private DirectoryEntry GetEntry(string path) path = Path.DirectorySeparatorChar + path; } - return GetEntry(GetDirectory(0), path.AsMemory().Split(Utilities.PathSeparators).ToArray()); + return GetEntry(GetDirectory(0), path.AsMemory().Split('/', '\\').ToArray()); } private DirectoryEntry GetEntry(List dir, ReadOnlyMemory[] path) diff --git a/Tests/LibraryTests/Wim/WimFileSystemTest.cs b/Tests/LibraryTests/Wim/WimFileSystemTest.cs index c55bd6cb4..06424fb12 100644 --- a/Tests/LibraryTests/Wim/WimFileSystemTest.cs +++ b/Tests/LibraryTests/Wim/WimFileSystemTest.cs @@ -6,16 +6,57 @@ namespace LibraryTests.Wim; public class WinFileSystemTest - { + private static string testDataPath = Path.Combine("..", "..", "LibraryTests", "Wim", "Data", "TestData.wim"); + [Fact] - public void ReadRootDirectory() + public void ReadRootDirectoryFiles() { - using var fileStream = File.OpenRead(Path.Combine("..", "..", "LibraryTests", "Wim", "Data", "TestData.wim")); + using var fileStream = File.OpenRead(testDataPath); var wimFile = new WimFile(fileStream); var image = wimFile.GetImage(0); var files = image.GetFiles(image.Root.FullName, "*.*", SearchOption.AllDirectories).ToList(); + Assert.Equal(3, files.Count); } + + [Fact] + public void ReadSubDirectoryFiles() + { + using var fileStream = File.OpenRead(testDataPath); + var wimFile = new WimFile(fileStream); + var image = wimFile.GetImage(0); + + var files = image.GetFiles("\\TestData", "*.*", SearchOption.AllDirectories).ToList(); + + Assert.Equal(3, files.Count); + } + + [Fact] + public void ReadFilteredDirectory() + { + const string ExpectedDirectoryPath = "\\TestData\\Foo"; + + using var fileStream = File.OpenRead(testDataPath); + var wimFile = new WimFile(fileStream); + var image = wimFile.GetImage(0); + + var directories = image.GetDirectories(image.Root.FullName, "Foo.*", SearchOption.AllDirectories).ToList(); + + Assert.Single(directories); + Assert.Equal(ExpectedDirectoryPath, directories[0]); + } + + [Fact] + public void ReadFilteredFile() + { + using var fileStream = File.OpenRead(testDataPath); + var wimFile = new WimFile(fileStream); + var image = wimFile.GetImage(0); + + var files = image.GetFiles("\\TestData\\Foo", "Lorem.*", SearchOption.AllDirectories).ToList(); + + Assert.Equal(2, files.Count); + } }