pkNX/pkNX.Containers/VFS/FileSystems/ReadOnlyFileSystem.cs
duckdoom4 e74bfbc365 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..
2023-09-08 22:58:26 +02:00

75 lines
2.3 KiB
C#

using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.CompilerServices;
namespace pkNX.Containers.VFS;
public class ReadOnlyFileSystem : IFileSystem
{
public bool IsReadOnly => true;
public IFileSystem FileSystem { get; }
public ReadOnlyFileSystem(IFileSystem fileSystem)
{
FileSystem = fileSystem;
}
public void Dispose()
{
FileSystem.Dispose();
GC.SuppressFinalize(this);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public IEnumerable<FileSystemPath> GetEntityPaths(FileSystemPath path, Func<FileSystemPath, bool>? filter = null)
{
return FileSystem.GetEntityPaths(path, filter);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public IEnumerable<FileSystemPath> GetDirectoryPaths(FileSystemPath path, Func<FileSystemPath, bool>? filter = null)
{
return FileSystem.GetDirectoryPaths(path, filter);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public IEnumerable<FileSystemPath> GetFilePaths(FileSystemPath path, Func<FileSystemPath, bool>? filter = null)
{
return FileSystem.GetFilePaths(path, filter);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Exists(FileSystemPath path)
{
return FileSystem.Exists(path);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Stream OpenFile(FileSystemPath path, FileMode mode = FileMode.Open, FileAccess access = FileAccess.Read)
{
if (access != FileAccess.Read)
throw new UnauthorizedAccessException("This is a read-only filesystem.");
return FileSystem.OpenFile(path, mode, access);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Stream CreateFile(FileSystemPath path)
{
throw new UnauthorizedAccessException("This is a read-only filesystem.");
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void CreateDirectory(FileSystemPath path)
{
throw new UnauthorizedAccessException("This is a read-only filesystem.");
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Delete(FileSystemPath path)
{
throw new UnauthorizedAccessException("This is a read-only filesystem.");
}
}