mirror of
https://github.com/Thealexbarney/LibHac.git
synced 2024-11-14 10:49:41 +01:00
Allow setting length on more IStorage classes
This commit is contained in:
parent
f570c56122
commit
6e6c060e25
4 changed files with 14 additions and 10 deletions
|
@ -7,12 +7,13 @@ namespace LibHac.IO
|
||||||
{
|
{
|
||||||
private IFile BaseFile { get; }
|
private IFile BaseFile { get; }
|
||||||
private bool LeaveOpen { get; }
|
private bool LeaveOpen { get; }
|
||||||
|
private long _length;
|
||||||
|
|
||||||
public NxFileStream(IFile baseFile, bool leaveOpen)
|
public NxFileStream(IFile baseFile, bool leaveOpen)
|
||||||
{
|
{
|
||||||
BaseFile = baseFile;
|
BaseFile = baseFile;
|
||||||
LeaveOpen = leaveOpen;
|
LeaveOpen = leaveOpen;
|
||||||
Length = baseFile.GetSize();
|
_length = baseFile.GetSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override int Read(byte[] buffer, int offset, int count)
|
public override int Read(byte[] buffer, int offset, int count)
|
||||||
|
@ -56,14 +57,15 @@ namespace LibHac.IO
|
||||||
|
|
||||||
public override void SetLength(long value)
|
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 CanRead => BaseFile.Mode.HasFlag(OpenMode.Read);
|
||||||
public override bool CanSeek => true;
|
public override bool CanSeek => true;
|
||||||
public override bool CanWrite => BaseFile.Mode.HasFlag(OpenMode.Write);
|
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; }
|
public override long Position { get; set; }
|
||||||
|
|
||||||
protected override void Dispose(bool disposing)
|
protected override void Dispose(bool disposing)
|
||||||
|
|
|
@ -10,7 +10,6 @@ namespace LibHac.IO.RomFs
|
||||||
public HierarchicalRomFileTable FileTable { get; }
|
public HierarchicalRomFileTable FileTable { get; }
|
||||||
private IStorage BaseStorage { get; }
|
private IStorage BaseStorage { get; }
|
||||||
|
|
||||||
// todo Don't parse entire table when opening
|
|
||||||
public RomFsFileSystem(IStorage storage)
|
public RomFsFileSystem(IStorage storage)
|
||||||
{
|
{
|
||||||
BaseStorage = storage;
|
BaseStorage = storage;
|
||||||
|
|
|
@ -40,7 +40,7 @@ namespace LibHac.IO
|
||||||
|
|
||||||
public override void SetSize(long size)
|
public override void SetSize(long size)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
BaseStorage.SetSize(size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,12 +7,13 @@ namespace LibHac.IO
|
||||||
{
|
{
|
||||||
private IStorage BaseStorage { get; }
|
private IStorage BaseStorage { get; }
|
||||||
private bool LeaveOpen { get; }
|
private bool LeaveOpen { get; }
|
||||||
|
private long _length;
|
||||||
|
|
||||||
public StorageStream(IStorage baseStorage, FileAccess access, bool leaveOpen)
|
public StorageStream(IStorage baseStorage, FileAccess access, bool leaveOpen)
|
||||||
{
|
{
|
||||||
BaseStorage = baseStorage;
|
BaseStorage = baseStorage;
|
||||||
LeaveOpen = leaveOpen;
|
LeaveOpen = leaveOpen;
|
||||||
Length = baseStorage.GetSize();
|
_length = baseStorage.GetSize();
|
||||||
|
|
||||||
CanRead = access.HasFlag(FileAccess.Read);
|
CanRead = access.HasFlag(FileAccess.Read);
|
||||||
CanWrite = access.HasFlag(FileAccess.Write);
|
CanWrite = access.HasFlag(FileAccess.Write);
|
||||||
|
@ -20,7 +21,7 @@ namespace LibHac.IO
|
||||||
|
|
||||||
public override int Read(byte[] buffer, int offset, int count)
|
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);
|
BaseStorage.Read(buffer.AsSpan(offset, toRead), Position);
|
||||||
|
|
||||||
Position += toRead;
|
Position += toRead;
|
||||||
|
@ -58,13 +59,15 @@ namespace LibHac.IO
|
||||||
|
|
||||||
public override void SetLength(long value)
|
public override void SetLength(long value)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
BaseStorage.SetSize(value);
|
||||||
|
|
||||||
|
_length = BaseStorage.GetSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool CanRead { get; }
|
public override bool CanRead { get; }
|
||||||
public override bool CanSeek => true;
|
public override bool CanSeek => true;
|
||||||
public override bool CanWrite { get; }
|
public override bool CanWrite { get; }
|
||||||
public override long Length { get; }
|
public override long Length => _length;
|
||||||
public override long Position { get; set; }
|
public override long Position { get; set; }
|
||||||
|
|
||||||
protected override void Dispose(bool disposing)
|
protected override void Dispose(bool disposing)
|
||||||
|
|
Loading…
Reference in a new issue