Fix issues with empty files in SaveDataFileSystemCore

This commit is contained in:
Alex Barney 2019-05-10 14:58:26 -05:00
parent 6f7de478eb
commit 25a66cf4df
2 changed files with 14 additions and 1 deletions

View file

@ -1,4 +1,5 @@
using System;
using System.IO;
namespace LibHac.IO.Save
{
@ -92,6 +93,8 @@ namespace LibHac.IO.Save
if (oldBlockCount == 0)
{
InitialBlock = Fat.Allocate(newBlockCount);
if (InitialBlock == -1) throw new IOException("Not enough space to resize file.");
_length = newBlockCount * BlockSize;
return;
@ -101,7 +104,7 @@ namespace LibHac.IO.Save
{
Fat.Free(InitialBlock);
InitialBlock = -1;
InitialBlock = int.MinValue;
_length = 0;
return;
@ -110,6 +113,8 @@ namespace LibHac.IO.Save
if (newBlockCount > oldBlockCount)
{
int newBlocks = Fat.Allocate(newBlockCount - oldBlockCount);
if (InitialBlock == -1) throw new IOException("Not enough space to resize file.");
Fat.Join(InitialBlock, newBlocks);
}
else

View file

@ -38,6 +38,14 @@ namespace LibHac.IO.Save
{
path = PathTools.Normalize(path);
if (size == 0)
{
var emptyFileEntry = new SaveFileInfo { StartBlock = int.MinValue, Length = size };
FileTable.AddFile(path, ref emptyFileEntry);
return;
}
int blockCount = (int)Util.DivideByRoundUp(size, AllocationTable.Header.BlockSize);
int startBlock = AllocationTable.Allocate(blockCount);