mirror of
https://github.com/Thealexbarney/LibHac.git
synced 2024-11-14 10:49:41 +01:00
Fix issues with empty files in SaveDataFileSystemCore
This commit is contained in:
parent
6f7de478eb
commit
25a66cf4df
2 changed files with 14 additions and 1 deletions
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in a new issue