From 1876e3b67117cfabdbe78d3b5c1ced09ebe54ee3 Mon Sep 17 00:00:00 2001 From: Alex Barney Date: Fri, 24 May 2019 15:03:07 -0500 Subject: [PATCH] Add ReadOnlyFileSystem --- src/LibHac/Fs/ReadOnlyDirectory.cs | 22 +++++++++ src/LibHac/Fs/ReadOnlyFile.cs | 28 +++++++++++ src/LibHac/Fs/ReadOnlyFileSystem.cs | 75 +++++++++++++++++++++++++++++ 3 files changed, 125 insertions(+) create mode 100644 src/LibHac/Fs/ReadOnlyDirectory.cs create mode 100644 src/LibHac/Fs/ReadOnlyFile.cs create mode 100644 src/LibHac/Fs/ReadOnlyFileSystem.cs diff --git a/src/LibHac/Fs/ReadOnlyDirectory.cs b/src/LibHac/Fs/ReadOnlyDirectory.cs new file mode 100644 index 00000000..5d8a3c27 --- /dev/null +++ b/src/LibHac/Fs/ReadOnlyDirectory.cs @@ -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 Read() => BaseDir.Read(); + public int GetEntryCount() => BaseDir.GetEntryCount(); + } +} diff --git a/src/LibHac/Fs/ReadOnlyFile.cs b/src/LibHac/Fs/ReadOnlyFile.cs new file mode 100644 index 00000000..39fa0f5c --- /dev/null +++ b/src/LibHac/Fs/ReadOnlyFile.cs @@ -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 destination, long offset) + { + return BaseFile.Read(destination, offset); + } + + public override long GetSize() + { + return BaseFile.GetSize(); + } + + public override void Flush() { } + public override void Write(ReadOnlySpan source, long offset) => throw new NotSupportedException(); + public override void SetSize(long size) => throw new NotSupportedException(); + } +} diff --git a/src/LibHac/Fs/ReadOnlyFileSystem.cs b/src/LibHac/Fs/ReadOnlyFileSystem.cs new file mode 100644 index 00000000..1a57194c --- /dev/null +++ b/src/LibHac/Fs/ReadOnlyFileSystem.cs @@ -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 outBuffer, ReadOnlySpan 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(); + } +}