From 8f4c310b7e5e063b70e56459fd9f508bda6fecc0 Mon Sep 17 00:00:00 2001 From: Alex Barney Date: Fri, 11 Oct 2019 19:11:36 -0500 Subject: [PATCH] Add FileSystemBase --- src/LibHac/Fs/FileBase.cs | 7 +- src/LibHac/Fs/FileSystemBase.cs | 196 ++++++++++++++++++ src/LibHac/FsSystem/AesXtsFileSystem.cs | 34 +-- .../FsSystem/ConcatenationFileSystem.cs | 34 +-- .../FsSystem/DirectorySaveDataFileSystem.cs | 52 ++--- src/LibHac/FsSystem/LayeredFileSystem.cs | 42 ++-- src/LibHac/FsSystem/PartitionFileSystem.cs | 46 ++-- src/LibHac/FsSystem/ReadOnlyFileSystem.cs | 40 ++-- src/LibHac/FsSystem/RomFs/RomFsFileSystem.cs | 44 ++-- .../FsSystem/Save/SaveDataFileSystem.cs | 42 ++-- .../FsSystem/Save/SaveDataFileSystemCore.cs | 44 ++-- src/LibHac/FsSystem/SubdirectoryFileSystem.cs | 34 +-- 12 files changed, 359 insertions(+), 256 deletions(-) create mode 100644 src/LibHac/Fs/FileSystemBase.cs diff --git a/src/LibHac/Fs/FileBase.cs b/src/LibHac/Fs/FileBase.cs index 887dfa98..6aec6529 100644 --- a/src/LibHac/Fs/FileBase.cs +++ b/src/LibHac/Fs/FileBase.cs @@ -55,8 +55,11 @@ namespace LibHac.Fs public Result GetSize(out long size) { - size = default; - if (IsDisposed) return ResultFs.PreconditionViolation.Log(); + if (IsDisposed) + { + size = default; + return ResultFs.PreconditionViolation.Log(); + } return GetSizeImpl(out size); } diff --git a/src/LibHac/Fs/FileSystemBase.cs b/src/LibHac/Fs/FileSystemBase.cs new file mode 100644 index 00000000..3f6ec78f --- /dev/null +++ b/src/LibHac/Fs/FileSystemBase.cs @@ -0,0 +1,196 @@ +using System; +using System.Threading; + +namespace LibHac.Fs +{ + public abstract class FileSystemBase : IFileSystem + { + // 0 = not disposed; 1 = disposed + private int _disposedState; + private bool IsDisposed => _disposedState != 0; + + protected abstract Result CreateDirectoryImpl(string path); + protected abstract Result CreateFileImpl(string path, long size, CreateFileOptions options); + protected abstract Result DeleteDirectoryImpl(string path); + protected abstract Result DeleteDirectoryRecursivelyImpl(string path); + protected abstract Result CleanDirectoryRecursivelyImpl(string path); + protected abstract Result DeleteFileImpl(string path); + protected abstract Result OpenDirectoryImpl(out IDirectory directory, string path, OpenDirectoryMode mode); + protected abstract Result OpenFileImpl(out IFile file, string path, OpenMode mode); + protected abstract Result RenameDirectoryImpl(string oldPath, string newPath); + protected abstract Result RenameFileImpl(string oldPath, string newPath); + protected abstract Result GetEntryTypeImpl(out DirectoryEntryType entryType, string path); + protected abstract Result CommitImpl(); + + public Result CreateDirectory(string path) + { + if (IsDisposed) return ResultFs.PreconditionViolation.Log(); + + return CreateDirectoryImpl(path); + } + + public Result CreateFile(string path, long size, CreateFileOptions options) + { + if (IsDisposed) return ResultFs.PreconditionViolation.Log(); + + return CreateFileImpl(path, size, options); + } + + public Result DeleteDirectory(string path) + { + if (IsDisposed) return ResultFs.PreconditionViolation.Log(); + + return DeleteDirectoryImpl(path); + } + + public Result DeleteDirectoryRecursively(string path) + { + if (IsDisposed) return ResultFs.PreconditionViolation.Log(); + + return DeleteDirectoryRecursivelyImpl(path); + } + + public Result CleanDirectoryRecursively(string path) + { + if (IsDisposed) return ResultFs.PreconditionViolation.Log(); + + return CleanDirectoryRecursivelyImpl(path); + } + + public Result DeleteFile(string path) + { + if (IsDisposed) return ResultFs.PreconditionViolation.Log(); + + return DeleteFileImpl(path); + } + + public Result OpenDirectory(out IDirectory directory, string path, OpenDirectoryMode mode) + { + if (IsDisposed) + { + directory = default; + return ResultFs.PreconditionViolation.Log(); + } + + return OpenDirectoryImpl(out directory, path, mode); + } + + public Result OpenFile(out IFile file, string path, OpenMode mode) + { + if (IsDisposed) + { + file = default; + return ResultFs.PreconditionViolation.Log(); + } + + return OpenFileImpl(out file, path, mode); + } + + public Result RenameDirectory(string oldPath, string newPath) + { + if (IsDisposed) return ResultFs.PreconditionViolation.Log(); + + return RenameDirectoryImpl(oldPath, newPath); + } + + public Result RenameFile(string oldPath, string newPath) + { + if (IsDisposed) return ResultFs.PreconditionViolation.Log(); + + return RenameFileImpl(oldPath, newPath); + } + + public Result GetEntryType(out DirectoryEntryType entryType, string path) + { + if (IsDisposed) + { + entryType = default; + return ResultFs.PreconditionViolation.Log(); + } + + return GetEntryTypeImpl(out entryType, path); + } + + public Result GetFreeSpaceSize(out long freeSpace, string path) + { + if (IsDisposed) + { + freeSpace = default; + return ResultFs.PreconditionViolation.Log(); + } + + return GetFreeSpaceSizeImpl(out freeSpace, path); + } + + public Result GetTotalSpaceSize(out long totalSpace, string path) + { + if (IsDisposed) + { + totalSpace = default; + return ResultFs.PreconditionViolation.Log(); + } + + return GetTotalSpaceSizeImpl(out totalSpace, path); + } + + public Result GetFileTimeStampRaw(out FileTimeStampRaw timeStamp, string path) + { + if (IsDisposed) + { + timeStamp = default; + return ResultFs.PreconditionViolation.Log(); + } + + return GetFileTimeStampRawImpl(out timeStamp, path); + } + + public Result Commit() + { + if (IsDisposed) return ResultFs.PreconditionViolation.Log(); + + return CommitImpl(); + } + + public Result QueryEntry(Span outBuffer, ReadOnlySpan inBuffer, QueryId queryId, string path) + { + if (IsDisposed) return ResultFs.PreconditionViolation.Log(); + + return QueryEntryImpl(outBuffer, inBuffer, queryId, path); + } + + public void Dispose() + { + // Make sure Dispose is only called once + if (Interlocked.CompareExchange(ref _disposedState, 1, 0) == 0) + { + Dispose(true); + GC.SuppressFinalize(this); + } + } + + protected virtual void Dispose(bool disposing) { } + + protected virtual Result GetFreeSpaceSizeImpl(out long freeSpace, string path) + { + freeSpace = default; + return ResultFs.NotImplemented.Log(); + } + + protected virtual Result GetTotalSpaceSizeImpl(out long totalSpace, string path) + { + totalSpace = default; + return ResultFs.NotImplemented.Log(); + } + + protected virtual Result GetFileTimeStampRawImpl(out FileTimeStampRaw timeStamp, string path) + { + timeStamp = default; + return ResultFs.NotImplemented.Log(); + } + + protected virtual Result QueryEntryImpl(Span outBuffer, ReadOnlySpan inBuffer, QueryId queryId, string path) + { + return ResultFs.NotImplemented.Log(); + } + } +} diff --git a/src/LibHac/FsSystem/AesXtsFileSystem.cs b/src/LibHac/FsSystem/AesXtsFileSystem.cs index 118200bb..45c04399 100644 --- a/src/LibHac/FsSystem/AesXtsFileSystem.cs +++ b/src/LibHac/FsSystem/AesXtsFileSystem.cs @@ -4,7 +4,7 @@ using LibHac.Fs; namespace LibHac.FsSystem { - public class AesXtsFileSystem : IFileSystem + public class AesXtsFileSystem : FileSystemBase { public int BlockSize { get; } @@ -28,12 +28,12 @@ namespace LibHac.FsSystem BlockSize = blockSize; } - public Result CreateDirectory(string path) + protected override Result CreateDirectoryImpl(string path) { return BaseFileSystem.CreateDirectory(path); } - public Result CreateFile(string path, long size, CreateFileOptions options) + protected override Result CreateFileImpl(string path, long size, CreateFileOptions options) { return CreateFile(path, size, options, new byte[0x20]); } @@ -67,27 +67,27 @@ namespace LibHac.FsSystem return Result.Success; } - public Result DeleteDirectory(string path) + protected override Result DeleteDirectoryImpl(string path) { return BaseFileSystem.DeleteDirectory(path); } - public Result DeleteDirectoryRecursively(string path) + protected override Result DeleteDirectoryRecursivelyImpl(string path) { return BaseFileSystem.DeleteDirectoryRecursively(path); } - public Result CleanDirectoryRecursively(string path) + protected override Result CleanDirectoryRecursivelyImpl(string path) { return BaseFileSystem.CleanDirectoryRecursively(path); } - public Result DeleteFile(string path) + protected override Result DeleteFileImpl(string path) { return BaseFileSystem.DeleteFile(path); } - public Result OpenDirectory(out IDirectory directory, string path, OpenDirectoryMode mode) + protected override Result OpenDirectoryImpl(out IDirectory directory, string path, OpenDirectoryMode mode) { directory = default; path = PathTools.Normalize(path); @@ -99,7 +99,7 @@ namespace LibHac.FsSystem return Result.Success; } - public Result OpenFile(out IFile file, string path, OpenMode mode) + protected override Result OpenFileImpl(out IFile file, string path, OpenMode mode) { file = default; path = PathTools.Normalize(path); @@ -113,7 +113,7 @@ namespace LibHac.FsSystem return Result.Success; } - public Result RenameDirectory(string oldPath, string newPath) + protected override Result RenameDirectoryImpl(string oldPath, string newPath) { oldPath = PathTools.Normalize(oldPath); newPath = PathTools.Normalize(newPath); @@ -176,7 +176,7 @@ namespace LibHac.FsSystem } } - public Result RenameFile(string oldPath, string newPath) + protected override Result RenameFileImpl(string oldPath, string newPath) { oldPath = PathTools.Normalize(oldPath); newPath = PathTools.Normalize(newPath); @@ -202,32 +202,32 @@ namespace LibHac.FsSystem return Result.Success; } - public Result GetEntryType(out DirectoryEntryType entryType, string path) + protected override Result GetEntryTypeImpl(out DirectoryEntryType entryType, string path) { return BaseFileSystem.GetEntryType(out entryType, path); } - public Result GetFileTimeStampRaw(out FileTimeStampRaw timeStamp, string path) + protected override Result GetFileTimeStampRawImpl(out FileTimeStampRaw timeStamp, string path) { return BaseFileSystem.GetFileTimeStampRaw(out timeStamp, path); } - public Result GetFreeSpaceSize(out long freeSpace, string path) + protected override Result GetFreeSpaceSizeImpl(out long freeSpace, string path) { return BaseFileSystem.GetFreeSpaceSize(out freeSpace, path); } - public Result GetTotalSpaceSize(out long totalSpace, string path) + protected override Result GetTotalSpaceSizeImpl(out long totalSpace, string path) { return BaseFileSystem.GetTotalSpaceSize(out totalSpace, path); } - public Result Commit() + protected override Result CommitImpl() { return BaseFileSystem.Commit(); } - public Result QueryEntry(Span outBuffer, ReadOnlySpan inBuffer, QueryId queryId, string path) + protected override Result QueryEntryImpl(Span outBuffer, ReadOnlySpan inBuffer, QueryId queryId, string path) { return BaseFileSystem.QueryEntry(outBuffer, inBuffer, queryId, path); } diff --git a/src/LibHac/FsSystem/ConcatenationFileSystem.cs b/src/LibHac/FsSystem/ConcatenationFileSystem.cs index 5c60d594..f90045ac 100644 --- a/src/LibHac/FsSystem/ConcatenationFileSystem.cs +++ b/src/LibHac/FsSystem/ConcatenationFileSystem.cs @@ -21,7 +21,7 @@ namespace LibHac.FsSystem /// Each sub-file except the final one must have the size that was specified /// at the creation of the . /// - public class ConcatenationFileSystem : IFileSystem + public class ConcatenationFileSystem : FileSystemBase { private const long DefaultSubFileSize = 0xFFFF0000; // Hard-coded value used by FS private IAttributeFileSystem BaseFileSystem { get; } @@ -104,7 +104,7 @@ namespace LibHac.FsSystem return BaseFileSystem.SetFileAttributes(path, NxFileAttributes.Archive); } - public Result CreateDirectory(string path) + protected override Result CreateDirectoryImpl(string path) { path = PathTools.Normalize(path); string parent = PathTools.GetParentDirectory(path); @@ -118,7 +118,7 @@ namespace LibHac.FsSystem return BaseFileSystem.CreateDirectory(path); } - public Result CreateFile(string path, long size, CreateFileOptions options) + protected override Result CreateFileImpl(string path, long size, CreateFileOptions options) { path = PathTools.Normalize(path); @@ -162,7 +162,7 @@ namespace LibHac.FsSystem return Result.Success; } - public Result DeleteDirectory(string path) + protected override Result DeleteDirectoryImpl(string path) { path = PathTools.Normalize(path); @@ -174,7 +174,7 @@ namespace LibHac.FsSystem return BaseFileSystem.DeleteDirectory(path); } - public Result DeleteDirectoryRecursively(string path) + protected override Result DeleteDirectoryRecursivelyImpl(string path) { path = PathTools.Normalize(path); @@ -183,7 +183,7 @@ namespace LibHac.FsSystem return BaseFileSystem.DeleteDirectoryRecursively(path); } - public Result CleanDirectoryRecursively(string path) + protected override Result CleanDirectoryRecursivelyImpl(string path) { path = PathTools.Normalize(path); @@ -192,7 +192,7 @@ namespace LibHac.FsSystem return BaseFileSystem.CleanDirectoryRecursively(path); } - public Result DeleteFile(string path) + protected override Result DeleteFileImpl(string path) { path = PathTools.Normalize(path); @@ -212,7 +212,7 @@ namespace LibHac.FsSystem return BaseFileSystem.DeleteDirectory(path); } - public Result OpenDirectory(out IDirectory directory, string path, OpenDirectoryMode mode) + protected override Result OpenDirectoryImpl(out IDirectory directory, string path, OpenDirectoryMode mode) { directory = default; path = PathTools.Normalize(path); @@ -229,7 +229,7 @@ namespace LibHac.FsSystem return Result.Success; } - public Result OpenFile(out IFile file, string path, OpenMode mode) + protected override Result OpenFileImpl(out IFile file, string path, OpenMode mode) { file = default; path = PathTools.Normalize(path); @@ -257,7 +257,7 @@ namespace LibHac.FsSystem return Result.Success; } - public Result RenameDirectory(string oldPath, string newPath) + protected override Result RenameDirectoryImpl(string oldPath, string newPath) { oldPath = PathTools.Normalize(oldPath); newPath = PathTools.Normalize(newPath); @@ -270,7 +270,7 @@ namespace LibHac.FsSystem return BaseFileSystem.RenameDirectory(oldPath, newPath); } - public Result RenameFile(string oldPath, string newPath) + protected override Result RenameFileImpl(string oldPath, string newPath) { oldPath = PathTools.Normalize(oldPath); newPath = PathTools.Normalize(newPath); @@ -285,7 +285,7 @@ namespace LibHac.FsSystem } } - public Result GetEntryType(out DirectoryEntryType entryType, string path) + protected override Result GetEntryTypeImpl(out DirectoryEntryType entryType, string path) { path = PathTools.Normalize(path); @@ -298,27 +298,27 @@ namespace LibHac.FsSystem return BaseFileSystem.GetEntryType(out entryType, path); } - public Result GetFreeSpaceSize(out long freeSpace, string path) + protected override Result GetFreeSpaceSizeImpl(out long freeSpace, string path) { return BaseFileSystem.GetFreeSpaceSize(out freeSpace, path); } - public Result GetTotalSpaceSize(out long totalSpace, string path) + protected override Result GetTotalSpaceSizeImpl(out long totalSpace, string path) { return BaseFileSystem.GetTotalSpaceSize(out totalSpace, path); } - public Result GetFileTimeStampRaw(out FileTimeStampRaw timeStamp, string path) + protected override Result GetFileTimeStampRawImpl(out FileTimeStampRaw timeStamp, string path) { return BaseFileSystem.GetFileTimeStampRaw(out timeStamp, path); } - public Result Commit() + protected override Result CommitImpl() { return BaseFileSystem.Commit(); } - public Result QueryEntry(Span outBuffer, ReadOnlySpan inBuffer, QueryId queryId, string path) + protected override Result QueryEntryImpl(Span outBuffer, ReadOnlySpan inBuffer, QueryId queryId, string path) { if (queryId != QueryId.MakeConcatFile) return ResultFs.UnsupportedOperationInConcatFsQueryEntry.Log(); diff --git a/src/LibHac/FsSystem/DirectorySaveDataFileSystem.cs b/src/LibHac/FsSystem/DirectorySaveDataFileSystem.cs index 4a5838fa..93e03091 100644 --- a/src/LibHac/FsSystem/DirectorySaveDataFileSystem.cs +++ b/src/LibHac/FsSystem/DirectorySaveDataFileSystem.cs @@ -1,9 +1,8 @@ -using System; -using LibHac.Fs; +using LibHac.Fs; namespace LibHac.FsSystem { - public class DirectorySaveDataFileSystem : IFileSystem + public class DirectorySaveDataFileSystem : FileSystemBase { private const string CommittedDir = "/0/"; private const string WorkingDir = "/1/"; @@ -34,7 +33,7 @@ namespace LibHac.FsSystem } } - public Result CreateDirectory(string path) + protected override Result CreateDirectoryImpl(string path) { string fullPath = GetFullPath(PathTools.Normalize(path)); @@ -44,7 +43,7 @@ namespace LibHac.FsSystem } } - public Result CreateFile(string path, long size, CreateFileOptions options) + protected override Result CreateFileImpl(string path, long size, CreateFileOptions options) { string fullPath = GetFullPath(PathTools.Normalize(path)); @@ -54,7 +53,7 @@ namespace LibHac.FsSystem } } - public Result DeleteDirectory(string path) + protected override Result DeleteDirectoryImpl(string path) { string fullPath = GetFullPath(PathTools.Normalize(path)); @@ -64,7 +63,7 @@ namespace LibHac.FsSystem } } - public Result DeleteDirectoryRecursively(string path) + protected override Result DeleteDirectoryRecursivelyImpl(string path) { string fullPath = GetFullPath(PathTools.Normalize(path)); @@ -74,7 +73,7 @@ namespace LibHac.FsSystem } } - public Result CleanDirectoryRecursively(string path) + protected override Result CleanDirectoryRecursivelyImpl(string path) { string fullPath = GetFullPath(PathTools.Normalize(path)); @@ -84,7 +83,7 @@ namespace LibHac.FsSystem } } - public Result DeleteFile(string path) + protected override Result DeleteFileImpl(string path) { string fullPath = GetFullPath(PathTools.Normalize(path)); @@ -94,7 +93,7 @@ namespace LibHac.FsSystem } } - public Result OpenDirectory(out IDirectory directory, string path, OpenDirectoryMode mode) + protected override Result OpenDirectoryImpl(out IDirectory directory, string path, OpenDirectoryMode mode) { string fullPath = GetFullPath(PathTools.Normalize(path)); @@ -104,7 +103,7 @@ namespace LibHac.FsSystem } } - public Result OpenFile(out IFile file, string path, OpenMode mode) + protected override Result OpenFileImpl(out IFile file, string path, OpenMode mode) { file = default; string fullPath = GetFullPath(PathTools.Normalize(path)); @@ -125,7 +124,7 @@ namespace LibHac.FsSystem } } - public Result RenameDirectory(string oldPath, string newPath) + protected override Result RenameDirectoryImpl(string oldPath, string newPath) { string fullOldPath = GetFullPath(PathTools.Normalize(oldPath)); string fullNewPath = GetFullPath(PathTools.Normalize(newPath)); @@ -136,7 +135,7 @@ namespace LibHac.FsSystem } } - public Result RenameFile(string oldPath, string newPath) + protected override Result RenameFileImpl(string oldPath, string newPath) { string fullOldPath = GetFullPath(PathTools.Normalize(oldPath)); string fullNewPath = GetFullPath(PathTools.Normalize(newPath)); @@ -147,7 +146,7 @@ namespace LibHac.FsSystem } } - public Result GetEntryType(out DirectoryEntryType entryType, string path) + protected override Result GetEntryTypeImpl(out DirectoryEntryType entryType, string path) { string fullPath = GetFullPath(PathTools.Normalize(path)); @@ -157,25 +156,7 @@ namespace LibHac.FsSystem } } - public Result GetFreeSpaceSize(out long freeSpace, string path) - { - freeSpace = default; - return ResultFs.NotImplemented.Log(); - } - - public Result GetTotalSpaceSize(out long totalSpace, string path) - { - totalSpace = default; - return ResultFs.NotImplemented.Log(); - } - - public Result GetFileTimeStampRaw(out FileTimeStampRaw timeStamp, string path) - { - timeStamp = default; - return ResultFs.NotImplemented.Log(); - } - - public Result Commit() + protected override Result CommitImpl() { lock (Locker) { @@ -195,11 +176,6 @@ namespace LibHac.FsSystem } } - public Result QueryEntry(Span outBuffer, ReadOnlySpan inBuffer, QueryId queryId, string path) - { - return ResultFs.NotImplemented.Log(); - } - private string GetFullPath(string path) { return PathTools.Normalize(PathTools.Combine(WorkingDir, path)); diff --git a/src/LibHac/FsSystem/LayeredFileSystem.cs b/src/LibHac/FsSystem/LayeredFileSystem.cs index fe29a3fb..c48a33cb 100644 --- a/src/LibHac/FsSystem/LayeredFileSystem.cs +++ b/src/LibHac/FsSystem/LayeredFileSystem.cs @@ -4,7 +4,7 @@ using LibHac.Fs; namespace LibHac.FsSystem { - public class LayeredFileSystem : IFileSystem + public class LayeredFileSystem : FileSystemBase { private List Sources { get; } = new List(); @@ -13,7 +13,7 @@ namespace LibHac.FsSystem Sources.AddRange(sourceFileSystems); } - public Result OpenDirectory(out IDirectory directory, string path, OpenDirectoryMode mode) + protected override Result OpenDirectoryImpl(out IDirectory directory, string path, OpenDirectoryMode mode) { directory = default; path = PathTools.Normalize(path); @@ -43,7 +43,7 @@ namespace LibHac.FsSystem return Result.Success; } - public Result OpenFile(out IFile file, string path, OpenMode mode) + protected override Result OpenFileImpl(out IFile file, string path, OpenMode mode) { file = default; path = PathTools.Normalize(path); @@ -67,7 +67,7 @@ namespace LibHac.FsSystem return ResultFs.PathNotFound.Log(); } - public Result GetEntryType(out DirectoryEntryType entryType, string path) + protected override Result GetEntryTypeImpl(out DirectoryEntryType entryType, string path) { path = PathTools.Normalize(path); @@ -86,7 +86,7 @@ namespace LibHac.FsSystem return ResultFs.PathNotFound.Log(); } - public Result GetFileTimeStampRaw(out FileTimeStampRaw timeStamp, string path) + protected override Result GetFileTimeStampRawImpl(out FileTimeStampRaw timeStamp, string path) { path = PathTools.Normalize(path); @@ -104,7 +104,7 @@ namespace LibHac.FsSystem return ResultFs.PathNotFound.Log(); } - public Result QueryEntry(Span outBuffer, ReadOnlySpan inBuffer, QueryId queryId, string path) + protected override Result QueryEntryImpl(Span outBuffer, ReadOnlySpan inBuffer, QueryId queryId, string path) { path = PathTools.Normalize(path); @@ -121,30 +121,18 @@ namespace LibHac.FsSystem return ResultFs.PathNotFound.Log(); } - public Result Commit() + protected override Result CommitImpl() { return Result.Success; } - public Result CreateDirectory(string path) => ResultFs.UnsupportedOperation.Log(); - public Result CreateFile(string path, long size, CreateFileOptions options) => ResultFs.UnsupportedOperation.Log(); - public Result DeleteDirectory(string path) => ResultFs.UnsupportedOperation.Log(); - public Result DeleteDirectoryRecursively(string path) => ResultFs.UnsupportedOperation.Log(); - public Result CleanDirectoryRecursively(string path) => ResultFs.UnsupportedOperation.Log(); - public Result DeleteFile(string path) => ResultFs.UnsupportedOperation.Log(); - public Result RenameDirectory(string oldPath, string newPath) => ResultFs.UnsupportedOperation.Log(); - public Result RenameFile(string oldPath, string newPath) => ResultFs.UnsupportedOperation.Log(); - - public Result GetFreeSpaceSize(out long freeSpace, string path) - { - freeSpace = default; - return ResultFs.UnsupportedOperation.Log(); - } - - public Result GetTotalSpaceSize(out long totalSpace, string path) - { - totalSpace = default; - return ResultFs.UnsupportedOperation.Log(); - } + protected override Result CreateDirectoryImpl(string path) => ResultFs.UnsupportedOperation.Log(); + protected override Result CreateFileImpl(string path, long size, CreateFileOptions options) => ResultFs.UnsupportedOperation.Log(); + protected override Result DeleteDirectoryImpl(string path) => ResultFs.UnsupportedOperation.Log(); + protected override Result DeleteDirectoryRecursivelyImpl(string path) => ResultFs.UnsupportedOperation.Log(); + protected override Result CleanDirectoryRecursivelyImpl(string path) => ResultFs.UnsupportedOperation.Log(); + protected override Result DeleteFileImpl(string path) => ResultFs.UnsupportedOperation.Log(); + protected override Result RenameDirectoryImpl(string oldPath, string newPath) => ResultFs.UnsupportedOperation.Log(); + protected override Result RenameFileImpl(string oldPath, string newPath) => ResultFs.UnsupportedOperation.Log(); } } diff --git a/src/LibHac/FsSystem/PartitionFileSystem.cs b/src/LibHac/FsSystem/PartitionFileSystem.cs index ece8b637..a3b8e8d1 100644 --- a/src/LibHac/FsSystem/PartitionFileSystem.cs +++ b/src/LibHac/FsSystem/PartitionFileSystem.cs @@ -7,7 +7,7 @@ using LibHac.Fs; namespace LibHac.FsSystem { - public class PartitionFileSystem : IFileSystem + public class PartitionFileSystem : FileSystemBase { // todo Re-add way of checking a file hash public PartitionFileSystemHeader Header { get; } @@ -30,13 +30,13 @@ namespace LibHac.FsSystem BaseStorage = storage; } - public Result OpenDirectory(out IDirectory directory, string path, OpenDirectoryMode mode) + protected override Result OpenDirectoryImpl(out IDirectory directory, string path, OpenDirectoryMode mode) { directory = new PartitionDirectory(this, path, mode); return Result.Success; } - public Result OpenFile(out IFile file, string path, OpenMode mode) + protected override Result OpenFileImpl(out IFile file, string path, OpenMode mode) { path = PathTools.Normalize(path).TrimStart('/'); @@ -54,7 +54,7 @@ namespace LibHac.FsSystem return new PartitionFile(BaseStorage, HeaderSize + entry.Offset, entry.Size, mode); } - public Result GetEntryType(out DirectoryEntryType entryType, string path) + protected override Result GetEntryTypeImpl(out DirectoryEntryType entryType, string path) { entryType = DirectoryEntryType.NotFound; path = PathTools.Normalize(path); @@ -74,39 +74,19 @@ namespace LibHac.FsSystem return ResultFs.PathNotFound.Log(); } - public Result CreateDirectory(string path) => ResultFs.UnsupportedOperationModifyPartitionFileSystem.Log(); - public Result CreateFile(string path, long size, CreateFileOptions options) => ResultFs.UnsupportedOperationModifyPartitionFileSystem.Log(); - public Result DeleteDirectory(string path) => ResultFs.UnsupportedOperationModifyPartitionFileSystem.Log(); - public Result DeleteDirectoryRecursively(string path) => ResultFs.UnsupportedOperationModifyPartitionFileSystem.Log(); - public Result CleanDirectoryRecursively(string path) => ResultFs.UnsupportedOperationModifyPartitionFileSystem.Log(); - public Result DeleteFile(string path) => ResultFs.UnsupportedOperationModifyPartitionFileSystem.Log(); - public Result RenameDirectory(string oldPath, string newPath) => ResultFs.UnsupportedOperationModifyPartitionFileSystem.Log(); - public Result RenameFile(string oldPath, string newPath) => ResultFs.UnsupportedOperationModifyPartitionFileSystem.Log(); + protected override Result CreateDirectoryImpl(string path) => ResultFs.UnsupportedOperationModifyPartitionFileSystem.Log(); + protected override Result CreateFileImpl(string path, long size, CreateFileOptions options) => ResultFs.UnsupportedOperationModifyPartitionFileSystem.Log(); + protected override Result DeleteDirectoryImpl(string path) => ResultFs.UnsupportedOperationModifyPartitionFileSystem.Log(); + protected override Result DeleteDirectoryRecursivelyImpl(string path) => ResultFs.UnsupportedOperationModifyPartitionFileSystem.Log(); + protected override Result CleanDirectoryRecursivelyImpl(string path) => ResultFs.UnsupportedOperationModifyPartitionFileSystem.Log(); + protected override Result DeleteFileImpl(string path) => ResultFs.UnsupportedOperationModifyPartitionFileSystem.Log(); + protected override Result RenameDirectoryImpl(string oldPath, string newPath) => ResultFs.UnsupportedOperationModifyPartitionFileSystem.Log(); + protected override Result RenameFileImpl(string oldPath, string newPath) => ResultFs.UnsupportedOperationModifyPartitionFileSystem.Log(); - public Result GetFreeSpaceSize(out long freeSpace, string path) - { - freeSpace = default; - return ResultFs.NotImplemented.Log(); - } - - public Result GetTotalSpaceSize(out long totalSpace, string path) - { - totalSpace = default; - return ResultFs.NotImplemented.Log(); - } - - public Result GetFileTimeStampRaw(out FileTimeStampRaw timeStamp, string path) - { - timeStamp = default; - return ResultFs.NotImplemented.Log(); - } - - public Result Commit() + protected override Result CommitImpl() { return Result.Success; } - - public Result QueryEntry(Span outBuffer, ReadOnlySpan inBuffer, QueryId queryId, string path) => ResultFs.NotImplemented.Log(); } public enum PartitionFileSystemType diff --git a/src/LibHac/FsSystem/ReadOnlyFileSystem.cs b/src/LibHac/FsSystem/ReadOnlyFileSystem.cs index 66fc9e18..a3c4860c 100644 --- a/src/LibHac/FsSystem/ReadOnlyFileSystem.cs +++ b/src/LibHac/FsSystem/ReadOnlyFileSystem.cs @@ -1,9 +1,8 @@ -using System; -using LibHac.Fs; +using LibHac.Fs; namespace LibHac.FsSystem { - public class ReadOnlyFileSystem : IFileSystem + public class ReadOnlyFileSystem : FileSystemBase { private IFileSystem BaseFs { get; } @@ -12,12 +11,12 @@ namespace LibHac.FsSystem BaseFs = baseFileSystem; } - public Result OpenDirectory(out IDirectory directory, string path, OpenDirectoryMode mode) + protected override Result OpenDirectoryImpl(out IDirectory directory, string path, OpenDirectoryMode mode) { return BaseFs.OpenDirectory(out directory, path, mode); } - public Result OpenFile(out IFile file, string path, OpenMode mode) + protected override Result OpenFileImpl(out IFile file, string path, OpenMode mode) { file = default; @@ -28,12 +27,12 @@ namespace LibHac.FsSystem return Result.Success; } - public Result GetEntryType(out DirectoryEntryType entryType, string path) + protected override Result GetEntryTypeImpl(out DirectoryEntryType entryType, string path) { return BaseFs.GetEntryType(out entryType, path); } - public Result GetFreeSpaceSize(out long freeSpace, string path) + protected override Result GetFreeSpaceSizeImpl(out long freeSpace, string path) { freeSpace = 0; return Result.Success; @@ -42,7 +41,7 @@ namespace LibHac.FsSystem // return ResultFs.UnsupportedOperationReadOnlyFileSystemGetSpace.Log(); } - public Result GetTotalSpaceSize(out long totalSpace, string path) + protected override Result GetTotalSpaceSizeImpl(out long totalSpace, string path) { return BaseFs.GetTotalSpaceSize(out totalSpace, path); @@ -50,7 +49,7 @@ namespace LibHac.FsSystem // return ResultFs.UnsupportedOperationReadOnlyFileSystemGetSpace.Log(); } - public Result GetFileTimeStampRaw(out FileTimeStampRaw timeStamp, string path) + protected override Result GetFileTimeStampRawImpl(out FileTimeStampRaw timeStamp, string path) { return BaseFs.GetFileTimeStampRaw(out timeStamp, path); @@ -58,30 +57,25 @@ namespace LibHac.FsSystem // return ResultFs.NotImplemented.Log(); } - public Result Commit() + protected override Result CommitImpl() { return Result.Success; } - public Result QueryEntry(Span outBuffer, ReadOnlySpan inBuffer, QueryId queryId, string path) - { - return ResultFs.NotImplemented.Log(); - } + protected override Result CreateDirectoryImpl(string path) => ResultFs.UnsupportedOperationModifyReadOnlyFileSystem.Log(); - public Result CreateDirectory(string path) => ResultFs.UnsupportedOperationModifyReadOnlyFileSystem.Log(); + protected override Result CreateFileImpl(string path, long size, CreateFileOptions options) => ResultFs.UnsupportedOperationModifyReadOnlyFileSystem.Log(); - public Result CreateFile(string path, long size, CreateFileOptions options) => ResultFs.UnsupportedOperationModifyReadOnlyFileSystem.Log(); + protected override Result DeleteDirectoryImpl(string path) => ResultFs.UnsupportedOperationModifyReadOnlyFileSystem.Log(); - public Result DeleteDirectory(string path) => ResultFs.UnsupportedOperationModifyReadOnlyFileSystem.Log(); + protected override Result DeleteDirectoryRecursivelyImpl(string path) => ResultFs.UnsupportedOperationModifyReadOnlyFileSystem.Log(); - public Result DeleteDirectoryRecursively(string path) => ResultFs.UnsupportedOperationModifyReadOnlyFileSystem.Log(); + protected override Result CleanDirectoryRecursivelyImpl(string path) => ResultFs.UnsupportedOperationModifyReadOnlyFileSystem.Log(); - public Result CleanDirectoryRecursively(string path) => ResultFs.UnsupportedOperationModifyReadOnlyFileSystem.Log(); + protected override Result DeleteFileImpl(string path) => ResultFs.UnsupportedOperationModifyReadOnlyFileSystem.Log(); - public Result DeleteFile(string path) => ResultFs.UnsupportedOperationModifyReadOnlyFileSystem.Log(); + protected override Result RenameDirectoryImpl(string oldPath, string newPath) => ResultFs.UnsupportedOperationModifyReadOnlyFileSystem.Log(); - public Result RenameDirectory(string oldPath, string newPath) => ResultFs.UnsupportedOperationModifyReadOnlyFileSystem.Log(); - - public Result RenameFile(string oldPath, string newPath) => ResultFs.UnsupportedOperationModifyReadOnlyFileSystem.Log(); + protected override Result RenameFileImpl(string oldPath, string newPath) => ResultFs.UnsupportedOperationModifyReadOnlyFileSystem.Log(); } } diff --git a/src/LibHac/FsSystem/RomFs/RomFsFileSystem.cs b/src/LibHac/FsSystem/RomFs/RomFsFileSystem.cs index cdd8507d..56dafb95 100644 --- a/src/LibHac/FsSystem/RomFs/RomFsFileSystem.cs +++ b/src/LibHac/FsSystem/RomFs/RomFsFileSystem.cs @@ -1,9 +1,8 @@ -using System; -using LibHac.Fs; +using LibHac.Fs; namespace LibHac.FsSystem.RomFs { - public class RomFsFileSystem : IFileSystem + public class RomFsFileSystem : FileSystemBase { public RomfsHeader Header { get; } @@ -23,7 +22,7 @@ namespace LibHac.FsSystem.RomFs FileTable = new HierarchicalRomFileTable(dirHashTable, dirEntryTable, fileHashTable, fileEntryTable); } - public Result GetEntryType(out DirectoryEntryType entryType, string path) + protected override Result GetEntryTypeImpl(out DirectoryEntryType entryType, string path) { entryType = DirectoryEntryType.NotFound; path = PathTools.Normalize(path); @@ -43,12 +42,12 @@ namespace LibHac.FsSystem.RomFs return ResultFs.PathNotFound.Log(); } - public Result Commit() + protected override Result CommitImpl() { return Result.Success; } - public Result OpenDirectory(out IDirectory directory, string path, OpenDirectoryMode mode) + protected override Result OpenDirectoryImpl(out IDirectory directory, string path, OpenDirectoryMode mode) { directory = default; path = PathTools.Normalize(path); @@ -62,7 +61,7 @@ namespace LibHac.FsSystem.RomFs return Result.Success; } - public Result OpenFile(out IFile file, string path, OpenMode mode) + protected override Result OpenFileImpl(out IFile file, string path, OpenMode mode) { file = default; path = PathTools.Normalize(path); @@ -87,37 +86,26 @@ namespace LibHac.FsSystem.RomFs return BaseStorage; } - public Result CreateDirectory(string path) => ResultFs.UnsupportedOperationModifyRomFsFileSystem.Log(); - public Result CreateFile(string path, long size, CreateFileOptions options) => ResultFs.UnsupportedOperationModifyRomFsFileSystem.Log(); - public Result DeleteDirectory(string path) => ResultFs.UnsupportedOperationModifyRomFsFileSystem.Log(); - public Result DeleteDirectoryRecursively(string path) => ResultFs.UnsupportedOperationModifyRomFsFileSystem.Log(); - public Result CleanDirectoryRecursively(string path) => ResultFs.UnsupportedOperationModifyRomFsFileSystem.Log(); - public Result DeleteFile(string path) => ResultFs.UnsupportedOperationModifyRomFsFileSystem.Log(); - public Result RenameDirectory(string oldPath, string newPath) => ResultFs.UnsupportedOperationModifyRomFsFileSystem.Log(); - public Result RenameFile(string oldPath, string newPath) => ResultFs.UnsupportedOperationModifyRomFsFileSystem.Log(); + protected override Result CreateDirectoryImpl(string path) => ResultFs.UnsupportedOperationModifyRomFsFileSystem.Log(); + protected override Result CreateFileImpl(string path, long size, CreateFileOptions options) => ResultFs.UnsupportedOperationModifyRomFsFileSystem.Log(); + protected override Result DeleteDirectoryImpl(string path) => ResultFs.UnsupportedOperationModifyRomFsFileSystem.Log(); + protected override Result DeleteDirectoryRecursivelyImpl(string path) => ResultFs.UnsupportedOperationModifyRomFsFileSystem.Log(); + protected override Result CleanDirectoryRecursivelyImpl(string path) => ResultFs.UnsupportedOperationModifyRomFsFileSystem.Log(); + protected override Result DeleteFileImpl(string path) => ResultFs.UnsupportedOperationModifyRomFsFileSystem.Log(); + protected override Result RenameDirectoryImpl(string oldPath, string newPath) => ResultFs.UnsupportedOperationModifyRomFsFileSystem.Log(); + protected override Result RenameFileImpl(string oldPath, string newPath) => ResultFs.UnsupportedOperationModifyRomFsFileSystem.Log(); - public Result GetFreeSpaceSize(out long freeSpace, string path) + protected override Result GetFreeSpaceSizeImpl(out long freeSpace, string path) { freeSpace = default; return ResultFs.UnsupportedOperationRomFsFileSystemGetSpace.Log(); } - public Result GetTotalSpaceSize(out long totalSpace, string path) + protected override Result GetTotalSpaceSizeImpl(out long totalSpace, string path) { totalSpace = default; return ResultFs.UnsupportedOperationRomFsFileSystemGetSpace.Log(); } - - public Result GetFileTimeStampRaw(out FileTimeStampRaw timeStamp, string path) - { - timeStamp = default; - return ResultFs.NotImplemented.Log(); - } - - public Result QueryEntry(Span outBuffer, ReadOnlySpan inBuffer, QueryId queryId, string path) - { - return ResultFs.NotImplemented.Log(); - } } public class RomfsHeader diff --git a/src/LibHac/FsSystem/Save/SaveDataFileSystem.cs b/src/LibHac/FsSystem/Save/SaveDataFileSystem.cs index 1e62ed3b..e0a01582 100644 --- a/src/LibHac/FsSystem/Save/SaveDataFileSystem.cs +++ b/src/LibHac/FsSystem/Save/SaveDataFileSystem.cs @@ -1,11 +1,10 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.IO; using LibHac.Fs; namespace LibHac.FsSystem.Save { - public class SaveDataFileSystem : IFileSystem + public class SaveDataFileSystem : FileSystemBase { internal const byte TrimFillValue = 0; @@ -143,113 +142,104 @@ namespace LibHac.FsSystem.Save IntegrityStorageType.Save, integrityCheckLevel, LeaveOpen); } - public Result CreateDirectory(string path) + protected override Result CreateDirectoryImpl(string path) { Result result = SaveDataFileSystemCore.CreateDirectory(path); return SaveResults.ConvertToExternalResult(result); } - public Result CreateFile(string path, long size, CreateFileOptions options) + protected override Result CreateFileImpl(string path, long size, CreateFileOptions options) { Result result = SaveDataFileSystemCore.CreateFile(path, size, options); return SaveResults.ConvertToExternalResult(result); } - public Result DeleteDirectory(string path) + protected override Result DeleteDirectoryImpl(string path) { Result result = SaveDataFileSystemCore.DeleteDirectory(path); return SaveResults.ConvertToExternalResult(result); } - public Result DeleteDirectoryRecursively(string path) + protected override Result DeleteDirectoryRecursivelyImpl(string path) { Result result = SaveDataFileSystemCore.DeleteDirectoryRecursively(path); return SaveResults.ConvertToExternalResult(result); } - public Result CleanDirectoryRecursively(string path) + protected override Result CleanDirectoryRecursivelyImpl(string path) { Result result = SaveDataFileSystemCore.CleanDirectoryRecursively(path); return SaveResults.ConvertToExternalResult(result); } - public Result DeleteFile(string path) + protected override Result DeleteFileImpl(string path) { Result result = SaveDataFileSystemCore.DeleteFile(path); return SaveResults.ConvertToExternalResult(result); } - public Result OpenDirectory(out IDirectory directory, string path, OpenDirectoryMode mode) + protected override Result OpenDirectoryImpl(out IDirectory directory, string path, OpenDirectoryMode mode) { Result result = SaveDataFileSystemCore.OpenDirectory(out directory, path, mode); return SaveResults.ConvertToExternalResult(result); } - public Result OpenFile(out IFile file, string path, OpenMode mode) + protected override Result OpenFileImpl(out IFile file, string path, OpenMode mode) { Result result = SaveDataFileSystemCore.OpenFile(out file, path, mode); return SaveResults.ConvertToExternalResult(result); } - public Result RenameDirectory(string oldPath, string newPath) + protected override Result RenameDirectoryImpl(string oldPath, string newPath) { Result result = SaveDataFileSystemCore.RenameDirectory(oldPath, newPath); return SaveResults.ConvertToExternalResult(result); } - public Result RenameFile(string oldPath, string newPath) + protected override Result RenameFileImpl(string oldPath, string newPath) { Result result = SaveDataFileSystemCore.RenameFile(oldPath, newPath); return SaveResults.ConvertToExternalResult(result); } - public Result GetEntryType(out DirectoryEntryType entryType, string path) + protected override Result GetEntryTypeImpl(out DirectoryEntryType entryType, string path) { Result result = SaveDataFileSystemCore.GetEntryType(out entryType, path); return SaveResults.ConvertToExternalResult(result); } - public Result GetFreeSpaceSize(out long freeSpace, string path) + protected override Result GetFreeSpaceSizeImpl(out long freeSpace, string path) { Result result = SaveDataFileSystemCore.GetFreeSpaceSize(out freeSpace, path); return SaveResults.ConvertToExternalResult(result); } - public Result GetTotalSpaceSize(out long totalSpace, string path) + protected override Result GetTotalSpaceSizeImpl(out long totalSpace, string path) { Result result = SaveDataFileSystemCore.GetTotalSpaceSize(out totalSpace, path); return SaveResults.ConvertToExternalResult(result); } - public Result Commit() + protected override Result CommitImpl() { Result result = Commit(Keyset); return SaveResults.ConvertToExternalResult(result); } - public Result GetFileTimeStampRaw(out FileTimeStampRaw timeStamp, string path) - { - timeStamp = default; - return ResultFs.NotImplemented.Log(); - } - - public Result QueryEntry(Span outBuffer, ReadOnlySpan inBuffer, QueryId queryId, string path) => - ResultFs.NotImplemented.Log(); - public Result Commit(Keyset keyset) { CoreDataIvfcStorage.Flush(); diff --git a/src/LibHac/FsSystem/Save/SaveDataFileSystemCore.cs b/src/LibHac/FsSystem/Save/SaveDataFileSystemCore.cs index 731676ab..5b8fd880 100644 --- a/src/LibHac/FsSystem/Save/SaveDataFileSystemCore.cs +++ b/src/LibHac/FsSystem/Save/SaveDataFileSystemCore.cs @@ -1,10 +1,9 @@ -using System; -using System.IO; +using System.IO; using LibHac.Fs; namespace LibHac.FsSystem.Save { - public class SaveDataFileSystemCore : IFileSystem + public class SaveDataFileSystemCore : FileSystemBase { private IStorage BaseStorage { get; } private IStorage HeaderStorage { get; } @@ -28,7 +27,7 @@ namespace LibHac.FsSystem.Save FileTable = new HierarchicalSaveFileTable(dirTableStorage, fileTableStorage); } - public Result CreateDirectory(string path) + protected override Result CreateDirectoryImpl(string path) { path = PathTools.Normalize(path); @@ -37,7 +36,7 @@ namespace LibHac.FsSystem.Save return Result.Success; } - public Result CreateFile(string path, long size, CreateFileOptions options) + protected override Result CreateFileImpl(string path, long size, CreateFileOptions options) { path = PathTools.Normalize(path); @@ -64,7 +63,7 @@ namespace LibHac.FsSystem.Save return Result.Success; } - public Result DeleteDirectory(string path) + protected override Result DeleteDirectoryImpl(string path) { path = PathTools.Normalize(path); @@ -73,7 +72,7 @@ namespace LibHac.FsSystem.Save return Result.Success; } - public Result DeleteDirectoryRecursively(string path) + protected override Result DeleteDirectoryRecursivelyImpl(string path) { path = PathTools.Normalize(path); @@ -85,7 +84,7 @@ namespace LibHac.FsSystem.Save return Result.Success; } - public Result CleanDirectoryRecursively(string path) + protected override Result CleanDirectoryRecursivelyImpl(string path) { path = PathTools.Normalize(path); @@ -94,7 +93,7 @@ namespace LibHac.FsSystem.Save return Result.Success; } - public Result DeleteFile(string path) + protected override Result DeleteFileImpl(string path) { path = PathTools.Normalize(path); @@ -113,7 +112,7 @@ namespace LibHac.FsSystem.Save return Result.Success; } - public Result OpenDirectory(out IDirectory directory, string path, OpenDirectoryMode mode) + protected override Result OpenDirectoryImpl(out IDirectory directory, string path, OpenDirectoryMode mode) { directory = default; path = PathTools.Normalize(path); @@ -128,7 +127,7 @@ namespace LibHac.FsSystem.Save return Result.Success; } - public Result OpenFile(out IFile file, string path, OpenMode mode) + protected override Result OpenFileImpl(out IFile file, string path, OpenMode mode) { file = default; path = PathTools.Normalize(path); @@ -145,7 +144,7 @@ namespace LibHac.FsSystem.Save return Result.Success; } - public Result RenameDirectory(string oldPath, string newPath) + protected override Result RenameDirectoryImpl(string oldPath, string newPath) { oldPath = PathTools.Normalize(oldPath); newPath = PathTools.Normalize(newPath); @@ -153,7 +152,7 @@ namespace LibHac.FsSystem.Save return FileTable.RenameDirectory(oldPath, newPath); } - public Result RenameFile(string oldPath, string newPath) + protected override Result RenameFileImpl(string oldPath, string newPath) { oldPath = PathTools.Normalize(oldPath); newPath = PathTools.Normalize(newPath); @@ -163,7 +162,7 @@ namespace LibHac.FsSystem.Save return Result.Success; } - public Result GetEntryType(out DirectoryEntryType entryType, string path) + protected override Result GetEntryTypeImpl(out DirectoryEntryType entryType, string path) { path = PathTools.Normalize(path); @@ -183,7 +182,7 @@ namespace LibHac.FsSystem.Save return ResultFs.PathNotFound.Log(); } - public Result GetFreeSpaceSize(out long freeSpace, string path) + protected override Result GetFreeSpaceSizeImpl(out long freeSpace, string path) { int freeBlockCount = AllocationTable.GetFreeListLength(); freeSpace = Header.BlockSize * freeBlockCount; @@ -191,29 +190,18 @@ namespace LibHac.FsSystem.Save return Result.Success; } - public Result GetTotalSpaceSize(out long totalSpace, string path) + protected override Result GetTotalSpaceSizeImpl(out long totalSpace, string path) { totalSpace = Header.BlockSize * Header.BlockCount; return Result.Success; } - public Result Commit() + protected override Result CommitImpl() { return Result.Success; } - public Result GetFileTimeStampRaw(out FileTimeStampRaw timeStamp, string path) - { - timeStamp = default; - return ResultFs.NotImplemented.Log(); - } - - public Result QueryEntry(Span outBuffer, ReadOnlySpan inBuffer, QueryId queryId, string path) - { - return ResultFs.NotImplemented.Log(); - } - public IStorage GetBaseStorage() => BaseStorage.AsReadOnly(); public IStorage GetHeaderStorage() => HeaderStorage.AsReadOnly(); diff --git a/src/LibHac/FsSystem/SubdirectoryFileSystem.cs b/src/LibHac/FsSystem/SubdirectoryFileSystem.cs index e9bb51f8..8b00bd71 100644 --- a/src/LibHac/FsSystem/SubdirectoryFileSystem.cs +++ b/src/LibHac/FsSystem/SubdirectoryFileSystem.cs @@ -3,7 +3,7 @@ using LibHac.Fs; namespace LibHac.FsSystem { - public class SubdirectoryFileSystem : IFileSystem + public class SubdirectoryFileSystem : FileSystemBase { private string RootPath { get; } private IFileSystem ParentFileSystem { get; } @@ -19,63 +19,63 @@ namespace LibHac.FsSystem RootPath = PathTools.Normalize(rootPath); } - public Result CreateDirectory(string path) + protected override Result CreateDirectoryImpl(string path) { string fullPath = ResolveFullPath(PathTools.Normalize(path)); return ParentFileSystem.CreateDirectory(fullPath); } - public Result CreateFile(string path, long size, CreateFileOptions options) + protected override Result CreateFileImpl(string path, long size, CreateFileOptions options) { string fullPath = ResolveFullPath(PathTools.Normalize(path)); return ParentFileSystem.CreateFile(fullPath, size, options); } - public Result DeleteDirectory(string path) + protected override Result DeleteDirectoryImpl(string path) { string fullPath = ResolveFullPath(PathTools.Normalize(path)); return ParentFileSystem.DeleteDirectory(fullPath); } - public Result DeleteDirectoryRecursively(string path) + protected override Result DeleteDirectoryRecursivelyImpl(string path) { string fullPath = ResolveFullPath(PathTools.Normalize(path)); return ParentFileSystem.DeleteDirectoryRecursively(fullPath); } - public Result CleanDirectoryRecursively(string path) + protected override Result CleanDirectoryRecursivelyImpl(string path) { string fullPath = ResolveFullPath(PathTools.Normalize(path)); return ParentFileSystem.CleanDirectoryRecursively(fullPath); } - public Result DeleteFile(string path) + protected override Result DeleteFileImpl(string path) { string fullPath = ResolveFullPath(PathTools.Normalize(path)); return ParentFileSystem.DeleteFile(fullPath); } - public Result OpenDirectory(out IDirectory directory, string path, OpenDirectoryMode mode) + protected override Result OpenDirectoryImpl(out IDirectory directory, string path, OpenDirectoryMode mode) { string fullPath = ResolveFullPath(PathTools.Normalize(path)); return ParentFileSystem.OpenDirectory(out directory, fullPath, mode); } - public Result OpenFile(out IFile file, string path, OpenMode mode) + protected override Result OpenFileImpl(out IFile file, string path, OpenMode mode) { string fullPath = ResolveFullPath(PathTools.Normalize(path)); return ParentFileSystem.OpenFile(out file, fullPath, mode); } - public Result RenameDirectory(string oldPath, string newPath) + protected override Result RenameDirectoryImpl(string oldPath, string newPath) { string fullOldPath = ResolveFullPath(PathTools.Normalize(oldPath)); string fullNewPath = ResolveFullPath(PathTools.Normalize(newPath)); @@ -83,7 +83,7 @@ namespace LibHac.FsSystem return ParentFileSystem.RenameDirectory(fullOldPath, fullNewPath); } - public Result RenameFile(string oldPath, string newPath) + protected override Result RenameFileImpl(string oldPath, string newPath) { string fullOldPath = ResolveFullPath(PathTools.Normalize(oldPath)); string fullNewPath = ResolveFullPath(PathTools.Normalize(newPath)); @@ -91,40 +91,40 @@ namespace LibHac.FsSystem return ParentFileSystem.RenameFile(fullOldPath, fullNewPath); } - public Result GetEntryType(out DirectoryEntryType entryType, string path) + protected override Result GetEntryTypeImpl(out DirectoryEntryType entryType, string path) { string fullPath = ResolveFullPath(PathTools.Normalize(path)); return ParentFileSystem.GetEntryType(out entryType, fullPath); } - public Result Commit() + protected override Result CommitImpl() { return ParentFileSystem.Commit(); } - public Result GetFreeSpaceSize(out long freeSpace, string path) + protected override Result GetFreeSpaceSizeImpl(out long freeSpace, string path) { string fullPath = ResolveFullPath(PathTools.Normalize(path)); return ParentFileSystem.GetFreeSpaceSize(out freeSpace, fullPath); } - public Result GetTotalSpaceSize(out long totalSpace, string path) + protected override Result GetTotalSpaceSizeImpl(out long totalSpace, string path) { string fullPath = ResolveFullPath(PathTools.Normalize(path)); return ParentFileSystem.GetTotalSpaceSize(out totalSpace, fullPath); } - public Result GetFileTimeStampRaw(out FileTimeStampRaw timeStamp, string path) + protected override Result GetFileTimeStampRawImpl(out FileTimeStampRaw timeStamp, string path) { string fullPath = ResolveFullPath(PathTools.Normalize(path)); return ParentFileSystem.GetFileTimeStampRaw(out timeStamp, fullPath); } - public Result QueryEntry(Span outBuffer, ReadOnlySpan inBuffer, QueryId queryId, string path) + protected override Result QueryEntryImpl(Span outBuffer, ReadOnlySpan inBuffer, QueryId queryId, string path) { string fullPath = ResolveFullPath(PathTools.Normalize(path));