Allow setting length on more IStorage classes

This commit is contained in:
Alex Barney 2019-03-26 19:51:29 -05:00
parent f570c56122
commit 6e6c060e25
4 changed files with 14 additions and 10 deletions

View file

@ -7,12 +7,13 @@ namespace LibHac.IO
{
private IFile BaseFile { get; }
private bool LeaveOpen { get; }
private long _length;
public NxFileStream(IFile baseFile, bool leaveOpen)
{
BaseFile = baseFile;
LeaveOpen = leaveOpen;
Length = baseFile.GetSize();
_length = baseFile.GetSize();
}
public override int Read(byte[] buffer, int offset, int count)
@ -56,14 +57,15 @@ namespace LibHac.IO
public override void SetLength(long value)
{
throw new NotImplementedException();
BaseFile.SetSize(value);
_length = BaseFile.GetSize();
}
// todo access
public override bool CanRead => BaseFile.Mode.HasFlag(OpenMode.Read);
public override bool CanSeek => true;
public override bool CanWrite => BaseFile.Mode.HasFlag(OpenMode.Write);
public override long Length { get; }
public override long Length => _length;
public override long Position { get; set; }
protected override void Dispose(bool disposing)

View file

@ -10,7 +10,6 @@ namespace LibHac.IO.RomFs
public HierarchicalRomFileTable FileTable { get; }
private IStorage BaseStorage { get; }
// todo Don't parse entire table when opening
public RomFsFileSystem(IStorage storage)
{
BaseStorage = storage;

View file

@ -40,7 +40,7 @@ namespace LibHac.IO
public override void SetSize(long size)
{
throw new NotImplementedException();
BaseStorage.SetSize(size);
}
}
}

View file

@ -7,12 +7,13 @@ namespace LibHac.IO
{
private IStorage BaseStorage { get; }
private bool LeaveOpen { get; }
private long _length;
public StorageStream(IStorage baseStorage, FileAccess access, bool leaveOpen)
{
BaseStorage = baseStorage;
LeaveOpen = leaveOpen;
Length = baseStorage.GetSize();
_length = baseStorage.GetSize();
CanRead = access.HasFlag(FileAccess.Read);
CanWrite = access.HasFlag(FileAccess.Write);
@ -20,7 +21,7 @@ namespace LibHac.IO
public override int Read(byte[] buffer, int offset, int count)
{
int toRead = (int) Math.Min(count, Length - Position);
int toRead = (int)Math.Min(count, Length - Position);
BaseStorage.Read(buffer.AsSpan(offset, toRead), Position);
Position += toRead;
@ -58,13 +59,15 @@ namespace LibHac.IO
public override void SetLength(long value)
{
throw new NotImplementedException();
BaseStorage.SetSize(value);
_length = BaseStorage.GetSize();
}
public override bool CanRead { get; }
public override bool CanSeek => true;
public override bool CanWrite { get; }
public override long Length { get; }
public override long Length => _length;
public override long Position { get; set; }
protected override void Dispose(bool disposing)