Made VFS fully functional

Still need to start using it, but want to do it a bit slow to test it out. Also should really build some unit tests for this one..
This commit is contained in:
duckdoom4
2023-09-08 22:53:30 +02:00
parent 39308b2509
commit e74bfbc365
11 changed files with 310 additions and 157 deletions

View File

@@ -30,12 +30,15 @@ public MountPoint(FileSystemPath mountPath, IFileSystem fileSystem)
public class VirtualFileSystem : IFileSystem
{
public static VirtualFileSystem Current { get; private set; } = null!;
public SortedSet<MountPoint> Mounts { get; }
public bool IsReadOnly => Mounts.All(x => x.FileSystem.IsReadOnly);
public VirtualFileSystem(IEnumerable<MountPoint> mounts)
{
Mounts = new SortedSet<MountPoint>(mounts);
Current = this;
}
public VirtualFileSystem(params MountPoint[] mounts) :
@@ -84,18 +87,17 @@ public bool Exists(FileSystemPath path)
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Stream CreateFile(FileSystemPath path)
public Stream OpenFile(FileSystemPath path, FileMode mode = FileMode.Open, FileAccess access = FileAccess.Read)
{
var mount = GetMountPoint(path);
return mount.FileSystem.CreateFile(path);
return mount.FileSystem.OpenFile(path, mode, access);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Stream OpenFile(FileSystemPath path, FileAccess access)
{
var mount = GetMountPoint(path);
return mount.FileSystem.OpenFile(path, access);
}
public Stream OpenWrite(FileSystemPath path) => OpenFile(path, FileMode.OpenOrCreate, FileAccess.Write);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Stream CreateFile(FileSystemPath path) => OpenFile(path, FileMode.Create, FileAccess.Write);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void CreateDirectory(FileSystemPath path)