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;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
namespace LibHac.IO.Save
|
namespace LibHac.IO.Save
|
||||||
{
|
{
|
||||||
|
@ -92,6 +93,8 @@ namespace LibHac.IO.Save
|
||||||
if (oldBlockCount == 0)
|
if (oldBlockCount == 0)
|
||||||
{
|
{
|
||||||
InitialBlock = Fat.Allocate(newBlockCount);
|
InitialBlock = Fat.Allocate(newBlockCount);
|
||||||
|
if (InitialBlock == -1) throw new IOException("Not enough space to resize file.");
|
||||||
|
|
||||||
_length = newBlockCount * BlockSize;
|
_length = newBlockCount * BlockSize;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
@ -101,7 +104,7 @@ namespace LibHac.IO.Save
|
||||||
{
|
{
|
||||||
Fat.Free(InitialBlock);
|
Fat.Free(InitialBlock);
|
||||||
|
|
||||||
InitialBlock = -1;
|
InitialBlock = int.MinValue;
|
||||||
_length = 0;
|
_length = 0;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
@ -110,6 +113,8 @@ namespace LibHac.IO.Save
|
||||||
if (newBlockCount > oldBlockCount)
|
if (newBlockCount > oldBlockCount)
|
||||||
{
|
{
|
||||||
int newBlocks = Fat.Allocate(newBlockCount - oldBlockCount);
|
int newBlocks = Fat.Allocate(newBlockCount - oldBlockCount);
|
||||||
|
if (InitialBlock == -1) throw new IOException("Not enough space to resize file.");
|
||||||
|
|
||||||
Fat.Join(InitialBlock, newBlocks);
|
Fat.Join(InitialBlock, newBlocks);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -38,6 +38,14 @@ namespace LibHac.IO.Save
|
||||||
{
|
{
|
||||||
path = PathTools.Normalize(path);
|
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 blockCount = (int)Util.DivideByRoundUp(size, AllocationTable.Header.BlockSize);
|
||||||
int startBlock = AllocationTable.Allocate(blockCount);
|
int startBlock = AllocationTable.Allocate(blockCount);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue