diff --git a/src/LibHac/IO/NxFileStream.cs b/src/LibHac/IO/NxFileStream.cs index c0e10a2c..9e6406a8 100644 --- a/src/LibHac/IO/NxFileStream.cs +++ b/src/LibHac/IO/NxFileStream.cs @@ -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) diff --git a/src/LibHac/IO/RomFs/RomFsFileSystem.cs b/src/LibHac/IO/RomFs/RomFsFileSystem.cs index 57f76a9e..4584db58 100644 --- a/src/LibHac/IO/RomFs/RomFsFileSystem.cs +++ b/src/LibHac/IO/RomFs/RomFsFileSystem.cs @@ -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; diff --git a/src/LibHac/IO/StorageFile.cs b/src/LibHac/IO/StorageFile.cs index ee11f2f3..af325a31 100644 --- a/src/LibHac/IO/StorageFile.cs +++ b/src/LibHac/IO/StorageFile.cs @@ -40,7 +40,7 @@ namespace LibHac.IO public override void SetSize(long size) { - throw new NotImplementedException(); + BaseStorage.SetSize(size); } } } diff --git a/src/LibHac/IO/StorageStream.cs b/src/LibHac/IO/StorageStream.cs index 293e1997..da0bfdd2 100644 --- a/src/LibHac/IO/StorageStream.cs +++ b/src/LibHac/IO/StorageStream.cs @@ -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)