Add ReadOnlyFileSystem

This commit is contained in:
Alex Barney 2019-05-24 15:03:07 -05:00
parent 279e180466
commit 1876e3b671
3 changed files with 125 additions and 0 deletions

View file

@ -0,0 +1,22 @@
using System.Collections.Generic;
namespace LibHac.Fs
{
public class ReadOnlyDirectory : IDirectory
{
private IDirectory BaseDir { get; }
public IFileSystem ParentFileSystem { get; }
public string FullPath => BaseDir.FullPath;
public OpenDirectoryMode Mode => BaseDir.Mode;
public ReadOnlyDirectory(IFileSystem parentFileSystem, IDirectory baseDirectory)
{
ParentFileSystem = parentFileSystem;
BaseDir = baseDirectory;
}
public IEnumerable<DirectoryEntry> Read() => BaseDir.Read();
public int GetEntryCount() => BaseDir.GetEntryCount();
}
}

View file

@ -0,0 +1,28 @@
using System;
namespace LibHac.Fs
{
public class ReadOnlyFile : FileBase
{
private IFile BaseFile { get; }
public ReadOnlyFile(IFile baseFile)
{
BaseFile = baseFile;
}
public override int Read(Span<byte> destination, long offset)
{
return BaseFile.Read(destination, offset);
}
public override long GetSize()
{
return BaseFile.GetSize();
}
public override void Flush() { }
public override void Write(ReadOnlySpan<byte> source, long offset) => throw new NotSupportedException();
public override void SetSize(long size) => throw new NotSupportedException();
}
}

View file

@ -0,0 +1,75 @@
using System;
namespace LibHac.Fs
{
public class ReadOnlyFileSystem : IFileSystem
{
private IFileSystem BaseFs { get; }
public ReadOnlyFileSystem(IFileSystem baseFileSystem)
{
BaseFs = baseFileSystem;
}
public IDirectory OpenDirectory(string path, OpenDirectoryMode mode)
{
IDirectory baseDir = BaseFs.OpenDirectory(path, mode);
return new ReadOnlyDirectory(this, baseDir);
}
public IFile OpenFile(string path, OpenMode mode)
{
IFile baseFile = BaseFs.OpenFile(path, mode);
return new ReadOnlyFile(baseFile);
}
public bool DirectoryExists(string path)
{
return BaseFs.DirectoryExists(path);
}
public bool FileExists(string path)
{
return BaseFs.FileExists(path);
}
public DirectoryEntryType GetEntryType(string path)
{
return BaseFs.GetEntryType(path);
}
public long GetFreeSpaceSize(string path)
{
return 0;
}
public long GetTotalSpaceSize(string path)
{
return BaseFs.GetTotalSpaceSize(path);
}
public FileTimeStampRaw GetFileTimeStampRaw(string path)
{
return BaseFs.GetFileTimeStampRaw(path);
}
public void Commit()
{
}
public void QueryEntry(Span<byte> outBuffer, ReadOnlySpan<byte> inBuffer, string path, QueryId queryId)
{
BaseFs.QueryEntry(outBuffer, inBuffer, path, queryId);
}
public void CreateDirectory(string path) => throw new NotSupportedException();
public void CreateFile(string path, long size, CreateFileOptions options) => throw new NotSupportedException();
public void DeleteDirectory(string path) => throw new NotSupportedException();
public void DeleteDirectoryRecursively(string path) => throw new NotSupportedException();
public void CleanDirectoryRecursively(string path) => throw new NotSupportedException();
public void DeleteFile(string path) => throw new NotSupportedException();
public void RenameDirectory(string srcPath, string dstPath) => throw new NotSupportedException();
public void RenameFile(string srcPath, string dstPath) => throw new NotSupportedException();
}
}