mirror of
https://github.com/Thealexbarney/LibHac.git
synced 2024-11-14 10:49:41 +01:00
Make FileBase abstract methods protected
This commit is contained in:
parent
8f4c310b7e
commit
8390e10ae0
13 changed files with 67 additions and 68 deletions
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace LibHac.Fs.Accessors
|
||||
{
|
||||
public class FileAccessor : IFile
|
||||
public class FileAccessor : FileBase
|
||||
{
|
||||
private IFile File { get; set; }
|
||||
|
||||
|
@ -17,14 +17,14 @@ namespace LibHac.Fs.Accessors
|
|||
OpenMode = mode;
|
||||
}
|
||||
|
||||
public Result Read(out long bytesRead, long offset, Span<byte> destination, ReadOption options)
|
||||
protected override Result ReadImpl(out long bytesRead, long offset, Span<byte> destination, ReadOption options)
|
||||
{
|
||||
CheckIfDisposed();
|
||||
|
||||
return File.Read(out bytesRead, offset, destination, options);
|
||||
}
|
||||
|
||||
public Result Write(long offset, ReadOnlySpan<byte> source, WriteOption options)
|
||||
protected override Result WriteImpl(long offset, ReadOnlySpan<byte> source, WriteOption options)
|
||||
{
|
||||
CheckIfDisposed();
|
||||
|
||||
|
@ -35,7 +35,6 @@ namespace LibHac.Fs.Accessors
|
|||
return Result.Success;
|
||||
}
|
||||
|
||||
//
|
||||
Result rc = File.Write(offset, source, options);
|
||||
|
||||
if (rc.IsSuccess())
|
||||
|
@ -46,7 +45,7 @@ namespace LibHac.Fs.Accessors
|
|||
return rc;
|
||||
}
|
||||
|
||||
public Result Flush()
|
||||
protected override Result FlushImpl()
|
||||
{
|
||||
CheckIfDisposed();
|
||||
|
||||
|
@ -60,21 +59,21 @@ namespace LibHac.Fs.Accessors
|
|||
return rc;
|
||||
}
|
||||
|
||||
public Result GetSize(out long size)
|
||||
protected override Result GetSizeImpl(out long size)
|
||||
{
|
||||
CheckIfDisposed();
|
||||
|
||||
return File.GetSize(out size);
|
||||
}
|
||||
|
||||
public Result SetSize(long size)
|
||||
protected override Result SetSizeImpl(long size)
|
||||
{
|
||||
CheckIfDisposed();
|
||||
|
||||
return File.SetSize(size);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (File == null) return;
|
||||
|
||||
|
|
|
@ -9,11 +9,11 @@ namespace LibHac.Fs
|
|||
private int _disposedState;
|
||||
private bool IsDisposed => _disposedState != 0;
|
||||
|
||||
public abstract Result ReadImpl(out long bytesRead, long offset, Span<byte> destination, ReadOption options);
|
||||
public abstract Result WriteImpl(long offset, ReadOnlySpan<byte> source, WriteOption options);
|
||||
public abstract Result FlushImpl();
|
||||
public abstract Result GetSizeImpl(out long size);
|
||||
public abstract Result SetSizeImpl(long size);
|
||||
protected abstract Result ReadImpl(out long bytesRead, long offset, Span<byte> destination, ReadOption options);
|
||||
protected abstract Result WriteImpl(long offset, ReadOnlySpan<byte> source, WriteOption options);
|
||||
protected abstract Result FlushImpl();
|
||||
protected abstract Result GetSizeImpl(out long size);
|
||||
protected abstract Result SetSizeImpl(long size);
|
||||
|
||||
public Result Read(out long bytesRead, long offset, Span<byte> destination, ReadOption options)
|
||||
{
|
||||
|
|
|
@ -53,7 +53,7 @@ namespace LibHac.FsSystem
|
|||
return key;
|
||||
}
|
||||
|
||||
public override Result ReadImpl(out long bytesRead, long offset, Span<byte> destination, ReadOption options)
|
||||
protected override Result ReadImpl(out long bytesRead, long offset, Span<byte> destination, ReadOption options)
|
||||
{
|
||||
bytesRead = default;
|
||||
|
||||
|
@ -67,7 +67,7 @@ namespace LibHac.FsSystem
|
|||
return Result.Success;
|
||||
}
|
||||
|
||||
public override Result WriteImpl(long offset, ReadOnlySpan<byte> source, WriteOption options)
|
||||
protected override Result WriteImpl(long offset, ReadOnlySpan<byte> source, WriteOption options)
|
||||
{
|
||||
Result rc = ValidateWriteParams(offset, source.Length, Mode, out bool isResizeNeeded);
|
||||
if (rc.IsFailure()) return rc;
|
||||
|
@ -89,18 +89,18 @@ namespace LibHac.FsSystem
|
|||
return Result.Success;
|
||||
}
|
||||
|
||||
public override Result FlushImpl()
|
||||
protected override Result FlushImpl()
|
||||
{
|
||||
return BaseStorage.Flush();
|
||||
}
|
||||
|
||||
public override Result GetSizeImpl(out long size)
|
||||
protected override Result GetSizeImpl(out long size)
|
||||
{
|
||||
size = Header.Size;
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
public override Result SetSizeImpl(long size)
|
||||
protected override Result SetSizeImpl(long size)
|
||||
{
|
||||
Header.SetSize(size, VerificationKey);
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ namespace LibHac.FsSystem
|
|||
}
|
||||
}
|
||||
|
||||
public override Result ReadImpl(out long bytesRead, long offset, Span<byte> destination, ReadOption options)
|
||||
protected override Result ReadImpl(out long bytesRead, long offset, Span<byte> destination, ReadOption options)
|
||||
{
|
||||
bytesRead = default;
|
||||
|
||||
|
@ -69,7 +69,7 @@ namespace LibHac.FsSystem
|
|||
return Result.Success;
|
||||
}
|
||||
|
||||
public override Result WriteImpl(long offset, ReadOnlySpan<byte> source, WriteOption options)
|
||||
protected override Result WriteImpl(long offset, ReadOnlySpan<byte> source, WriteOption options)
|
||||
{
|
||||
Result rc = ValidateWriteParams(offset, source.Length, Mode, out _);
|
||||
if (rc.IsFailure()) return rc;
|
||||
|
@ -105,7 +105,7 @@ namespace LibHac.FsSystem
|
|||
return Result.Success;
|
||||
}
|
||||
|
||||
public override Result FlushImpl()
|
||||
protected override Result FlushImpl()
|
||||
{
|
||||
foreach (IFile file in Sources)
|
||||
{
|
||||
|
@ -116,7 +116,7 @@ namespace LibHac.FsSystem
|
|||
return Result.Success;
|
||||
}
|
||||
|
||||
public override Result GetSizeImpl(out long size)
|
||||
protected override Result GetSizeImpl(out long size)
|
||||
{
|
||||
size = default;
|
||||
|
||||
|
@ -131,7 +131,7 @@ namespace LibHac.FsSystem
|
|||
return Result.Success;
|
||||
}
|
||||
|
||||
public override Result SetSizeImpl(long size)
|
||||
protected override Result SetSizeImpl(long size)
|
||||
{
|
||||
Result rc = GetSize(out long currentSize);
|
||||
if (rc.IsFailure()) return rc;
|
||||
|
|
|
@ -16,27 +16,27 @@ namespace LibHac.FsSystem
|
|||
Mode = mode;
|
||||
}
|
||||
|
||||
public override Result ReadImpl(out long bytesRead, long offset, Span<byte> destination, ReadOption options)
|
||||
protected override Result ReadImpl(out long bytesRead, long offset, Span<byte> destination, ReadOption options)
|
||||
{
|
||||
return BaseFile.Read(out bytesRead, offset, destination, options);
|
||||
}
|
||||
|
||||
public override Result WriteImpl(long offset, ReadOnlySpan<byte> source, WriteOption options)
|
||||
protected override Result WriteImpl(long offset, ReadOnlySpan<byte> source, WriteOption options)
|
||||
{
|
||||
return BaseFile.Write(offset, source, options);
|
||||
}
|
||||
|
||||
public override Result FlushImpl()
|
||||
protected override Result FlushImpl()
|
||||
{
|
||||
return BaseFile.Flush();
|
||||
}
|
||||
|
||||
public override Result GetSizeImpl(out long size)
|
||||
protected override Result GetSizeImpl(out long size)
|
||||
{
|
||||
return BaseFile.GetSize(out size);
|
||||
}
|
||||
|
||||
public override Result SetSizeImpl(long size)
|
||||
protected override Result SetSizeImpl(long size)
|
||||
{
|
||||
return BaseFile.SetSize(size);
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ namespace LibHac.FsSystem
|
|||
File = new StreamFile(Stream, mode);
|
||||
}
|
||||
|
||||
public override Result ReadImpl(out long bytesRead, long offset, Span<byte> destination, ReadOption options)
|
||||
protected override Result ReadImpl(out long bytesRead, long offset, Span<byte> destination, ReadOption options)
|
||||
{
|
||||
bytesRead = 0;
|
||||
|
||||
|
@ -37,7 +37,7 @@ namespace LibHac.FsSystem
|
|||
return File.Read(out bytesRead, offset, destination.Slice(0, (int)toRead), options);
|
||||
}
|
||||
|
||||
public override Result WriteImpl(long offset, ReadOnlySpan<byte> source, WriteOption options)
|
||||
protected override Result WriteImpl(long offset, ReadOnlySpan<byte> source, WriteOption options)
|
||||
{
|
||||
Result rc = ValidateWriteParams(offset, source.Length, Mode, out _);
|
||||
if (rc.IsFailure()) return rc;
|
||||
|
@ -45,7 +45,7 @@ namespace LibHac.FsSystem
|
|||
return File.Write(offset, source, options);
|
||||
}
|
||||
|
||||
public override Result FlushImpl()
|
||||
protected override Result FlushImpl()
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -57,7 +57,7 @@ namespace LibHac.FsSystem
|
|||
}
|
||||
}
|
||||
|
||||
public override Result GetSizeImpl(out long size)
|
||||
protected override Result GetSizeImpl(out long size)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -70,7 +70,7 @@ namespace LibHac.FsSystem
|
|||
}
|
||||
}
|
||||
|
||||
public override Result SetSizeImpl(long size)
|
||||
protected override Result SetSizeImpl(long size)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
|
@ -16,7 +16,7 @@ namespace LibHac.FsSystem
|
|||
|
||||
private long Length { get; }
|
||||
|
||||
public override Result ReadImpl(out long bytesRead, long offset, Span<byte> destination, ReadOption options)
|
||||
protected override Result ReadImpl(out long bytesRead, long offset, Span<byte> destination, ReadOption options)
|
||||
{
|
||||
bytesRead = 0;
|
||||
|
||||
|
@ -29,23 +29,23 @@ namespace LibHac.FsSystem
|
|||
return Result.Success;
|
||||
}
|
||||
|
||||
public override Result WriteImpl(long offset, ReadOnlySpan<byte> source, WriteOption options)
|
||||
protected override Result WriteImpl(long offset, ReadOnlySpan<byte> source, WriteOption options)
|
||||
{
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
public override Result FlushImpl()
|
||||
protected override Result FlushImpl()
|
||||
{
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
public override Result GetSizeImpl(out long size)
|
||||
protected override Result GetSizeImpl(out long size)
|
||||
{
|
||||
size = Length;
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
public override Result SetSizeImpl(long size)
|
||||
protected override Result SetSizeImpl(long size)
|
||||
{
|
||||
return ResultFs.UnsupportedOperation.Log();
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ namespace LibHac.FsSystem
|
|||
Size = size;
|
||||
}
|
||||
|
||||
public override Result ReadImpl(out long bytesRead, long offset, Span<byte> destination, ReadOption options)
|
||||
protected override Result ReadImpl(out long bytesRead, long offset, Span<byte> destination, ReadOption options)
|
||||
{
|
||||
bytesRead = 0;
|
||||
|
||||
|
@ -32,7 +32,7 @@ namespace LibHac.FsSystem
|
|||
return Result.Success;
|
||||
}
|
||||
|
||||
public override Result WriteImpl(long offset, ReadOnlySpan<byte> source, WriteOption options)
|
||||
protected override Result WriteImpl(long offset, ReadOnlySpan<byte> source, WriteOption options)
|
||||
{
|
||||
Result rc = ValidateWriteParams(offset, source.Length, Mode, out bool isResizeNeeded);
|
||||
if (rc.IsFailure()) return rc;
|
||||
|
@ -53,7 +53,7 @@ namespace LibHac.FsSystem
|
|||
return Result.Success;
|
||||
}
|
||||
|
||||
public override Result FlushImpl()
|
||||
protected override Result FlushImpl()
|
||||
{
|
||||
if (!Mode.HasFlag(OpenMode.Write))
|
||||
{
|
||||
|
@ -63,13 +63,13 @@ namespace LibHac.FsSystem
|
|||
return Result.Success;
|
||||
}
|
||||
|
||||
public override Result GetSizeImpl(out long size)
|
||||
protected override Result GetSizeImpl(out long size)
|
||||
{
|
||||
size = Size;
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
public override Result SetSizeImpl(long size)
|
||||
protected override Result SetSizeImpl(long size)
|
||||
{
|
||||
if (!Mode.HasFlag(OpenMode.Write))
|
||||
{
|
||||
|
|
|
@ -12,27 +12,27 @@ namespace LibHac.FsSystem
|
|||
BaseFile = baseFile;
|
||||
}
|
||||
|
||||
public override Result ReadImpl(out long bytesRead, long offset, Span<byte> destination, ReadOption options)
|
||||
protected override Result ReadImpl(out long bytesRead, long offset, Span<byte> destination, ReadOption options)
|
||||
{
|
||||
return BaseFile.Read(out bytesRead, offset, destination, options);
|
||||
}
|
||||
|
||||
public override Result GetSizeImpl(out long size)
|
||||
protected override Result GetSizeImpl(out long size)
|
||||
{
|
||||
return BaseFile.GetSize(out size);
|
||||
}
|
||||
|
||||
public override Result FlushImpl()
|
||||
protected override Result FlushImpl()
|
||||
{
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
public override Result WriteImpl(long offset, ReadOnlySpan<byte> source, WriteOption options)
|
||||
protected override Result WriteImpl(long offset, ReadOnlySpan<byte> source, WriteOption options)
|
||||
{
|
||||
return ResultFs.InvalidOpenModeForWrite.Log();
|
||||
}
|
||||
|
||||
public override Result SetSizeImpl(long size)
|
||||
protected override Result SetSizeImpl(long size)
|
||||
{
|
||||
return ResultFs.InvalidOpenModeForWrite.Log();
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ namespace LibHac.FsSystem.RomFs
|
|||
Size = size;
|
||||
}
|
||||
|
||||
public override Result ReadImpl(out long bytesRead, long offset, Span<byte> destination, ReadOption options)
|
||||
protected override Result ReadImpl(out long bytesRead, long offset, Span<byte> destination, ReadOption options)
|
||||
{
|
||||
bytesRead = default;
|
||||
|
||||
|
@ -33,23 +33,23 @@ namespace LibHac.FsSystem.RomFs
|
|||
return Result.Success;
|
||||
}
|
||||
|
||||
public override Result WriteImpl(long offset, ReadOnlySpan<byte> source, WriteOption options)
|
||||
protected override Result WriteImpl(long offset, ReadOnlySpan<byte> source, WriteOption options)
|
||||
{
|
||||
return ResultFs.UnsupportedOperationModifyRomFsFile.Log();
|
||||
}
|
||||
|
||||
public override Result FlushImpl()
|
||||
protected override Result FlushImpl()
|
||||
{
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
public override Result GetSizeImpl(out long size)
|
||||
protected override Result GetSizeImpl(out long size)
|
||||
{
|
||||
size = Size;
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
public override Result SetSizeImpl(long size)
|
||||
protected override Result SetSizeImpl(long size)
|
||||
{
|
||||
return ResultFs.UnsupportedOperationModifyRomFsFile.Log();
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ namespace LibHac.FsSystem.Save
|
|||
Size = size;
|
||||
}
|
||||
|
||||
public override Result ReadImpl(out long bytesRead, long offset, Span<byte> destination, ReadOption options)
|
||||
protected override Result ReadImpl(out long bytesRead, long offset, Span<byte> destination, ReadOption options)
|
||||
{
|
||||
bytesRead = default;
|
||||
|
||||
|
@ -41,7 +41,7 @@ namespace LibHac.FsSystem.Save
|
|||
return Result.Success;
|
||||
}
|
||||
|
||||
public override Result WriteImpl(long offset, ReadOnlySpan<byte> source, WriteOption options)
|
||||
protected override Result WriteImpl(long offset, ReadOnlySpan<byte> source, WriteOption options)
|
||||
{
|
||||
Result rc = ValidateWriteParams(offset, source.Length, Mode, out bool isResizeNeeded);
|
||||
if (rc.IsFailure()) return rc;
|
||||
|
@ -62,18 +62,18 @@ namespace LibHac.FsSystem.Save
|
|||
return Result.Success;
|
||||
}
|
||||
|
||||
public override Result FlushImpl()
|
||||
protected override Result FlushImpl()
|
||||
{
|
||||
return BaseStorage.Flush();
|
||||
}
|
||||
|
||||
public override Result GetSizeImpl(out long size)
|
||||
protected override Result GetSizeImpl(out long size)
|
||||
{
|
||||
size = Size;
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
public override Result SetSizeImpl(long size)
|
||||
protected override Result SetSizeImpl(long size)
|
||||
{
|
||||
if (size < 0) throw new ArgumentOutOfRangeException(nameof(size));
|
||||
if (Size == size) return Result.Success;
|
||||
|
|
|
@ -14,7 +14,7 @@ namespace LibHac.FsSystem
|
|||
Mode = mode;
|
||||
}
|
||||
|
||||
public override Result ReadImpl(out long bytesRead, long offset, Span<byte> destination, ReadOption options)
|
||||
protected override Result ReadImpl(out long bytesRead, long offset, Span<byte> destination, ReadOption options)
|
||||
{
|
||||
bytesRead = default;
|
||||
|
||||
|
@ -34,7 +34,7 @@ namespace LibHac.FsSystem
|
|||
return Result.Success;
|
||||
}
|
||||
|
||||
public override Result WriteImpl(long offset, ReadOnlySpan<byte> source, WriteOption options)
|
||||
protected override Result WriteImpl(long offset, ReadOnlySpan<byte> source, WriteOption options)
|
||||
{
|
||||
Result rc = ValidateWriteParams(offset, source.Length, Mode, out bool isResizeNeeded);
|
||||
if (rc.IsFailure()) return rc;
|
||||
|
@ -56,7 +56,7 @@ namespace LibHac.FsSystem
|
|||
return Result.Success;
|
||||
}
|
||||
|
||||
public override Result FlushImpl()
|
||||
protected override Result FlushImpl()
|
||||
{
|
||||
if (!Mode.HasFlag(OpenMode.Write))
|
||||
return Result.Success;
|
||||
|
@ -64,12 +64,12 @@ namespace LibHac.FsSystem
|
|||
return BaseStorage.Flush();
|
||||
}
|
||||
|
||||
public override Result GetSizeImpl(out long size)
|
||||
protected override Result GetSizeImpl(out long size)
|
||||
{
|
||||
return BaseStorage.GetSize(out size);
|
||||
}
|
||||
|
||||
public override Result SetSizeImpl(long size)
|
||||
protected override Result SetSizeImpl(long size)
|
||||
{
|
||||
if (!Mode.HasFlag(OpenMode.Write))
|
||||
return ResultFs.InvalidOpenModeForWrite.Log();
|
||||
|
|
|
@ -25,7 +25,7 @@ namespace LibHac.FsSystem
|
|||
Mode = mode;
|
||||
}
|
||||
|
||||
public override Result ReadImpl(out long bytesRead, long offset, Span<byte> destination, ReadOption options)
|
||||
protected override Result ReadImpl(out long bytesRead, long offset, Span<byte> destination, ReadOption options)
|
||||
{
|
||||
bytesRead = default;
|
||||
|
||||
|
@ -65,7 +65,7 @@ namespace LibHac.FsSystem
|
|||
#endif
|
||||
}
|
||||
|
||||
public override Result WriteImpl(long offset, ReadOnlySpan<byte> source, WriteOption options)
|
||||
protected override Result WriteImpl(long offset, ReadOnlySpan<byte> source, WriteOption options)
|
||||
{
|
||||
Result rc = ValidateWriteParams(offset, source.Length, Mode, out _);
|
||||
if (rc.IsFailure()) return rc;
|
||||
|
@ -99,7 +99,7 @@ namespace LibHac.FsSystem
|
|||
return Result.Success;
|
||||
}
|
||||
|
||||
public override Result FlushImpl()
|
||||
protected override Result FlushImpl()
|
||||
{
|
||||
lock (Locker)
|
||||
{
|
||||
|
@ -108,7 +108,7 @@ namespace LibHac.FsSystem
|
|||
}
|
||||
}
|
||||
|
||||
public override Result GetSizeImpl(out long size)
|
||||
protected override Result GetSizeImpl(out long size)
|
||||
{
|
||||
lock (Locker)
|
||||
{
|
||||
|
@ -117,7 +117,7 @@ namespace LibHac.FsSystem
|
|||
}
|
||||
}
|
||||
|
||||
public override Result SetSizeImpl(long size)
|
||||
protected override Result SetSizeImpl(long size)
|
||||
{
|
||||
lock (Locker)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue