Make SaveFs writable

This commit is contained in:
Alex Barney 2018-10-15 21:17:53 -05:00
parent 4a43c330b6
commit 0eaefba071
2 changed files with 22 additions and 6 deletions

View file

@ -76,12 +76,29 @@ namespace LibHac.Save
public override void Write(byte[] buffer, int offset, int count) 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 CanRead => true;
public override bool CanSeek => true; public override bool CanSeek => true;
public override bool CanWrite => false; public override bool CanWrite => true;
public override long Length { get; } public override long Length { get; }
public override long Position public override long Position

View file

@ -10,7 +10,6 @@ namespace LibHac.Save
public Header Header { get; } public Header Header { get; }
public SharedStreamSource SavefileSource { get; } public SharedStreamSource SavefileSource { get; }
private JournalStream JournalStream { get; }
public SharedStreamSource JournalStreamSource { get; } public SharedStreamSource JournalStreamSource { get; }
private HierarchicalIntegrityVerificationStream IvfcStream { get; } private HierarchicalIntegrityVerificationStream IvfcStream { get; }
public SharedStreamSource IvfcStreamSource { get; } public SharedStreamSource IvfcStreamSource { get; }
@ -47,8 +46,8 @@ namespace LibHac.Save
Stream journalData = DataRemapStorage.OpenStream(layout.JournalDataOffset, Stream journalData = DataRemapStorage.OpenStream(layout.JournalDataOffset,
layout.JournalDataSizeB + layout.SizeReservedArea); layout.JournalDataSizeB + layout.SizeReservedArea);
JournalStream = new JournalStream(journalData, journalMap, (int)Header.Journal.BlockSize); var journalStream = new JournalStream(journalData, journalMap, (int)Header.Journal.BlockSize);
JournalStreamSource = new SharedStreamSource(JournalStream); JournalStreamSource = new SharedStreamSource(journalStream);
IvfcStream = InitIvfcStream(integrityCheckLevel); IvfcStream = InitIvfcStream(integrityCheckLevel);
@ -106,7 +105,7 @@ namespace LibHac.Save
IvfcLevelHeader level = ivfc.LevelHeaders[i - 1]; IvfcLevelHeader level = ivfc.LevelHeaders[i - 1];
Stream data = i == ivfcLevels - 1 Stream data = i == ivfcLevels - 1
? JournalStream ? JournalStreamSource.CreateStream()
: MetaRemapStorage.OpenStream(level.LogicalOffset, level.HashDataSize); : MetaRemapStorage.OpenStream(level.LogicalOffset, level.HashDataSize);
initInfo[i] = new IntegrityVerificationInfo initInfo[i] = new IntegrityVerificationInfo