Add more utility functions to VFS

This commit is contained in:
duckdoom4
2023-09-06 00:08:53 +02:00
parent ddc35df319
commit 01ed02e507
10 changed files with 136 additions and 63 deletions

View File

@@ -7,9 +7,9 @@ namespace pkNX.Containers.VFS;
public interface IFileSystem : IDisposable
{
IEnumerable<FileSystemPath> GetEntityPaths(FileSystemPath path);
IEnumerable<FileSystemPath> GetDirectoryPaths(FileSystemPath path);
IEnumerable<FileSystemPath> GetFilePaths(FileSystemPath path);
IEnumerable<FileSystemPath> GetEntityPaths(FileSystemPath path, Func<FileSystemPath, bool>? filter = null);
IEnumerable<FileSystemPath> GetDirectoryPaths(FileSystemPath path, Func<FileSystemPath, bool>? filter = null);
IEnumerable<FileSystemPath> GetFilePaths(FileSystemPath path, Func<FileSystemPath, bool>? filter = null);
bool Exists(FileSystemPath path);
Stream CreateFile(FileSystemPath path);
@@ -51,18 +51,18 @@ public static RelativeFileSystem AsRelativeFileSystem(this IFileSystem self, Pat
return new(self, toAbsolutePath, toRelativePath);
}
public static IEnumerable<IFileSystemEntity> GetEntities(this IFileSystem self, FileSystemPath path)
public static IEnumerable<IFileSystemEntity> GetEntities(this IFileSystem self, FileSystemPath path, Func<FileSystemPath, bool>? filter = null)
{
return self.GetEntityPaths(path).Select(p => IFileSystemEntity.Create(self, p));
return self.GetEntityPaths(path, filter).Select(p => IFileSystemEntity.Create(self, p));
}
public static IEnumerable<VirtualDirectory> GetDirectories(this IFileSystem self, FileSystemPath path)
public static IEnumerable<VirtualDirectory> GetDirectories(this IFileSystem self, FileSystemPath path, Func<FileSystemPath, bool>? filter = null)
{
return self.GetDirectoryPaths(path).Select(p => VirtualDirectory.Create(self, p));
return self.GetDirectoryPaths(path, filter).Select(p => VirtualDirectory.Create(self, p));
}
public static IEnumerable<VirtualFile> GetFiles(this IFileSystem self, FileSystemPath path)
public static IEnumerable<VirtualFile> GetFiles(this IFileSystem self, FileSystemPath path, Func<FileSystemPath, bool>? filter = null)
{
return self.GetFilePaths(path).Select(p => VirtualFile.Create(self, p));
return self.GetFilePaths(path, filter).Select(p => VirtualFile.Create(self, p));
}
}