diff --git a/LibHac/Save/AllocationTableStream.cs b/LibHac/Save/AllocationTableStream.cs index 49785789..9adb6884 100644 --- a/LibHac/Save/AllocationTableStream.cs +++ b/LibHac/Save/AllocationTableStream.cs @@ -76,12 +76,29 @@ namespace LibHac.Save public override void Write(byte[] buffer, int offset, int count) { - throw new NotImplementedException(); + int remaining = count; + int outOffset = offset; + + while (remaining > 0) + { + int remainingInSegment = Iterator.CurrentSegmentSize * BlockSize - SegmentPos; + int bytesToWrite = Math.Min(remaining, remainingInSegment); + Data.Write(buffer, outOffset, bytesToWrite); + + outOffset += bytesToWrite; + remaining -= bytesToWrite; + + if (SegmentPos >= Iterator.CurrentSegmentSize * BlockSize) + { + if (!Iterator.MoveNext()) return; + Data.Position = Iterator.PhysicalBlock * BlockSize; + } + } } public override bool CanRead => true; public override bool CanSeek => true; - public override bool CanWrite => false; + public override bool CanWrite => true; public override long Length { get; } public override long Position diff --git a/LibHac/Save/Savefile.cs b/LibHac/Save/Savefile.cs index 4135fb11..ba3394f0 100644 --- a/LibHac/Save/Savefile.cs +++ b/LibHac/Save/Savefile.cs @@ -10,7 +10,6 @@ namespace LibHac.Save public Header Header { get; } public SharedStreamSource SavefileSource { get; } - private JournalStream JournalStream { get; } public SharedStreamSource JournalStreamSource { get; } private HierarchicalIntegrityVerificationStream IvfcStream { get; } public SharedStreamSource IvfcStreamSource { get; } @@ -47,8 +46,8 @@ namespace LibHac.Save Stream journalData = DataRemapStorage.OpenStream(layout.JournalDataOffset, layout.JournalDataSizeB + layout.SizeReservedArea); - JournalStream = new JournalStream(journalData, journalMap, (int)Header.Journal.BlockSize); - JournalStreamSource = new SharedStreamSource(JournalStream); + var journalStream = new JournalStream(journalData, journalMap, (int)Header.Journal.BlockSize); + JournalStreamSource = new SharedStreamSource(journalStream); IvfcStream = InitIvfcStream(integrityCheckLevel); @@ -106,7 +105,7 @@ namespace LibHac.Save IvfcLevelHeader level = ivfc.LevelHeaders[i - 1]; Stream data = i == ivfcLevels - 1 - ? JournalStream + ? JournalStreamSource.CreateStream() : MetaRemapStorage.OpenStream(level.LogicalOffset, level.HashDataSize); initInfo[i] = new IntegrityVerificationInfo