0.2.0-dev Download ZIP
51 lines ·1.7 KB Raw
| 1 | using System.Diagnostics.CodeAnalysis; |
| 2 | |
| 3 | namespace EvilEngine.Mounts; |
| 4 | |
| 5 | public sealed class SubtreeSource(IFileSource parent, VirtualPath root) : IFileSource |
| 6 | { |
| 7 | public string Location { get; } = root.IsRoot ? parent.Location : $"{parent.Location}/{root}"; |
| 8 | |
| 9 | public CaseRule CaseRule => parent.CaseRule; |
| 10 | |
| 11 | public bool Exists(VirtualPath path) |
| 12 | { |
| 13 | return parent.Exists(root.Join(path)); |
| 14 | } |
| 15 | |
| 16 | public bool TryOpen(VirtualPath path, [NotNullWhen(true)] out Stream? stream) |
| 17 | { |
| 18 | return parent.TryOpen(root.Join(path), out stream); |
| 19 | } |
| 20 | |
| 21 | public bool TryOpenAccess(VirtualPath path, [NotNullWhen(true)] out IRandomAccess? access) |
| 22 | { |
| 23 | return parent.TryOpenAccess(root.Join(path), out access); |
| 24 | } |
| 25 | |
| 26 | public IEnumerable<FileEntry> Enumerate(VirtualPath directory, bool recursive) |
| 27 | { |
| 28 | foreach (var entry in parent.Enumerate(root.Join(directory), recursive)) |
| 29 | if (entry.Path.TryRelativeTo(root, CaseRule, out var relative)) |
| 30 | yield return entry with { Path = relative }; |
| 31 | } |
| 32 | |
| 33 | public bool DirectoryExists(VirtualPath directory) |
| 34 | { |
| 35 | return parent.DirectoryExists(root.Join(directory)); |
| 36 | } |
| 37 | |
| 38 | public IEnumerable<VirtualPath> EnumerateDirectories(VirtualPath directory) |
| 39 | { |
| 40 | foreach (var folder in parent.EnumerateDirectories(root.Join(directory))) |
| 41 | if (folder.TryRelativeTo(root, CaseRule, out var relative)) |
| 42 | yield return relative; |
| 43 | } |
| 44 | |
| 45 | public IEnumerable<VirtualPath> EnumerateRemoved() |
| 46 | { |
| 47 | foreach (var path in parent.EnumerateRemoved()) |
| 48 | if (path.TryRelativeTo(root, CaseRule, out var relative)) |
| 49 | yield return relative; |
| 50 | } |
| 51 | } |