mirror of
https://github.com/Thealexbarney/LibHac.git
synced 2024-11-14 10:49:41 +01:00
Fix EnsureApplicationSaveData failing if the temp save already exists
This commit is contained in:
parent
4e23465982
commit
0a96e8d623
3 changed files with 122 additions and 41 deletions
|
@ -677,6 +677,7 @@ public static class ApplicationSaveDataManagement
|
||||||
if (ResultFs.PathAlreadyExists.Includes(rc))
|
if (ResultFs.PathAlreadyExists.Includes(rc))
|
||||||
{
|
{
|
||||||
// Nothing to do if the save already exists.
|
// Nothing to do if the save already exists.
|
||||||
|
rc.Catch().Handle();
|
||||||
}
|
}
|
||||||
else if (ResultFs.UsableSpaceNotEnough.Includes(rc))
|
else if (ResultFs.UsableSpaceNotEnough.Includes(rc))
|
||||||
{
|
{
|
||||||
|
@ -686,6 +687,7 @@ public static class ApplicationSaveDataManagement
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
fs.Impl.AbortIfNeeded(rc);
|
||||||
return rc.Miss();
|
return rc.Miss();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -706,6 +708,7 @@ public static class ApplicationSaveDataManagement
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
fs.Impl.AbortIfNeeded(rc);
|
||||||
return rc.Miss();
|
return rc.Miss();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -742,8 +745,14 @@ public static class ApplicationSaveDataManagement
|
||||||
|
|
||||||
requiredSize += temporaryStorageSize;
|
requiredSize += temporaryStorageSize;
|
||||||
}
|
}
|
||||||
|
else if (ResultFs.PathAlreadyExists.Includes(rc))
|
||||||
|
{
|
||||||
|
// Nothing to do if the save already exists.
|
||||||
|
rc.Catch().Handle();
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
fs.Impl.AbortIfNeeded(rc);
|
||||||
return rc.Miss();
|
return rc.Miss();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -776,6 +785,7 @@ public static class ApplicationSaveDataManagement
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
fs.Impl.AbortIfNeeded(rc);
|
||||||
return rc.Miss();
|
return rc.Miss();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -789,7 +799,10 @@ public static class ApplicationSaveDataManagement
|
||||||
}
|
}
|
||||||
|
|
||||||
outRequiredSize = requiredSize;
|
outRequiredSize = requiredSize;
|
||||||
return ResultFs.UsableSpaceNotEnough.Log();
|
|
||||||
|
rc = ResultFs.UsableSpaceNotEnough.Log();
|
||||||
|
fs.Impl.AbortIfNeeded(rc);
|
||||||
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Result ExtendApplicationSaveData(this FileSystemClient fs, out long outRequiredSize,
|
public static Result ExtendApplicationSaveData(this FileSystemClient fs, out long outRequiredSize,
|
||||||
|
|
|
@ -26,17 +26,25 @@ public class ApplicationSaveDataManagementTests
|
||||||
};
|
};
|
||||||
|
|
||||||
Assert.Success(fs.EnsureApplicationSaveData(out _, applicationId, in controlProperty, in userId));
|
Assert.Success(fs.EnsureApplicationSaveData(out _, applicationId, in controlProperty, in userId));
|
||||||
|
AssertSaveExists();
|
||||||
|
|
||||||
using var iterator = new UniqueRef<SaveDataIterator>();
|
// EnsureApplicationSaveData should do nothing the second time it is called
|
||||||
fs.OpenSaveDataIterator(ref iterator.Ref(), SaveDataSpaceId.User);
|
Assert.Success(fs.EnsureApplicationSaveData(out _, applicationId, in controlProperty, in userId));
|
||||||
|
AssertSaveExists();
|
||||||
|
|
||||||
var info = new SaveDataInfo[2];
|
void AssertSaveExists()
|
||||||
Assert.Success(iterator.Get.ReadSaveDataInfo(out long entriesRead, info));
|
{
|
||||||
|
using var iterator = new UniqueRef<SaveDataIterator>();
|
||||||
|
fs.OpenSaveDataIterator(ref iterator.Ref(), SaveDataSpaceId.User);
|
||||||
|
|
||||||
Assert.Equal(1, entriesRead);
|
var info = new SaveDataInfo[2];
|
||||||
Assert.Equal(applicationId, info[0].ProgramId);
|
Assert.Success(iterator.Get.ReadSaveDataInfo(out long entriesRead, info));
|
||||||
Assert.Equal(Utility.ConvertAccountUidToFsUserId(userId), info[0].UserId);
|
|
||||||
Assert.Equal(SaveDataType.Account, info[0].Type);
|
Assert.Equal(1, entriesRead);
|
||||||
|
Assert.Equal(applicationId, info[0].ProgramId);
|
||||||
|
Assert.Equal(Utility.ConvertAccountUidToFsUserId(userId), info[0].UserId);
|
||||||
|
Assert.Equal(SaveDataType.Account, info[0].Type);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
@ -54,17 +62,24 @@ public class ApplicationSaveDataManagementTests
|
||||||
};
|
};
|
||||||
|
|
||||||
Assert.Success(fs.EnsureApplicationSaveData(out _, applicationId, in controlProperty, in userId));
|
Assert.Success(fs.EnsureApplicationSaveData(out _, applicationId, in controlProperty, in userId));
|
||||||
|
AssertSaveExists();
|
||||||
|
|
||||||
using var iterator = new UniqueRef<SaveDataIterator>();
|
Assert.Success(fs.EnsureApplicationSaveData(out _, applicationId, in controlProperty, in userId));
|
||||||
fs.OpenSaveDataIterator(ref iterator.Ref(), SaveDataSpaceId.User);
|
AssertSaveExists();
|
||||||
|
|
||||||
var info = new SaveDataInfo[2];
|
void AssertSaveExists()
|
||||||
Assert.Success(iterator.Get.ReadSaveDataInfo(out long entriesRead, info));
|
{
|
||||||
|
using var iterator = new UniqueRef<SaveDataIterator>();
|
||||||
|
fs.OpenSaveDataIterator(ref iterator.Ref(), SaveDataSpaceId.User);
|
||||||
|
|
||||||
Assert.Equal(1, entriesRead);
|
var info = new SaveDataInfo[2];
|
||||||
Assert.Equal(applicationId, info[0].ProgramId);
|
Assert.Success(iterator.Get.ReadSaveDataInfo(out long entriesRead, info));
|
||||||
Assert.Equal(InvalidUserId, info[0].UserId);
|
|
||||||
Assert.Equal(SaveDataType.Device, info[0].Type);
|
Assert.Equal(1, entriesRead);
|
||||||
|
Assert.Equal(applicationId, info[0].ProgramId);
|
||||||
|
Assert.Equal(InvalidUserId, info[0].UserId);
|
||||||
|
Assert.Equal(SaveDataType.Device, info[0].Type);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
@ -81,17 +96,24 @@ public class ApplicationSaveDataManagementTests
|
||||||
};
|
};
|
||||||
|
|
||||||
Assert.Success(fs.EnsureApplicationSaveData(out _, applicationId, in controlProperty, in userId));
|
Assert.Success(fs.EnsureApplicationSaveData(out _, applicationId, in controlProperty, in userId));
|
||||||
|
AssertSaveExists();
|
||||||
|
|
||||||
using var iterator = new UniqueRef<SaveDataIterator>();
|
Assert.Success(fs.EnsureApplicationSaveData(out _, applicationId, in controlProperty, in userId));
|
||||||
fs.OpenSaveDataIterator(ref iterator.Ref(), SaveDataSpaceId.User);
|
AssertSaveExists();
|
||||||
|
|
||||||
var info = new SaveDataInfo[2];
|
void AssertSaveExists()
|
||||||
Assert.Success(iterator.Get.ReadSaveDataInfo(out long entriesRead, info));
|
{
|
||||||
|
using var iterator = new UniqueRef<SaveDataIterator>();
|
||||||
|
fs.OpenSaveDataIterator(ref iterator.Ref(), SaveDataSpaceId.User);
|
||||||
|
|
||||||
Assert.Equal(1, entriesRead);
|
var info = new SaveDataInfo[2];
|
||||||
Assert.Equal(applicationId, info[0].ProgramId);
|
Assert.Success(iterator.Get.ReadSaveDataInfo(out long entriesRead, info));
|
||||||
Assert.Equal(InvalidUserId, info[0].UserId);
|
|
||||||
Assert.Equal(SaveDataType.Bcat, info[0].Type);
|
Assert.Equal(1, entriesRead);
|
||||||
|
Assert.Equal(applicationId, info[0].ProgramId);
|
||||||
|
Assert.Equal(InvalidUserId, info[0].UserId);
|
||||||
|
Assert.Equal(SaveDataType.Bcat, info[0].Type);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
@ -108,18 +130,26 @@ public class ApplicationSaveDataManagementTests
|
||||||
};
|
};
|
||||||
|
|
||||||
Assert.Success(fs.EnsureApplicationSaveData(out _, applicationId, in controlProperty, in userId));
|
Assert.Success(fs.EnsureApplicationSaveData(out _, applicationId, in controlProperty, in userId));
|
||||||
|
AssertSaveExists();
|
||||||
|
|
||||||
using var iterator = new UniqueRef<SaveDataIterator>();
|
Assert.Success(fs.EnsureApplicationSaveData(out _, applicationId, in controlProperty, in userId));
|
||||||
fs.OpenSaveDataIterator(ref iterator.Ref(), SaveDataSpaceId.Temporary);
|
AssertSaveExists();
|
||||||
|
|
||||||
var info = new SaveDataInfo[2];
|
void AssertSaveExists()
|
||||||
Assert.Success(iterator.Get.ReadSaveDataInfo(out long entriesRead, info));
|
{
|
||||||
|
using var iterator = new UniqueRef<SaveDataIterator>();
|
||||||
|
fs.OpenSaveDataIterator(ref iterator.Ref(), SaveDataSpaceId.Temporary);
|
||||||
|
|
||||||
Assert.Equal(1, entriesRead);
|
var info = new SaveDataInfo[2];
|
||||||
Assert.Equal(applicationId, info[0].ProgramId);
|
Assert.Success(iterator.Get.ReadSaveDataInfo(out long entriesRead, info));
|
||||||
Assert.Equal(InvalidUserId, info[0].UserId);
|
|
||||||
Assert.Equal(SaveDataType.Temporary, info[0].Type);
|
Assert.Equal(1, entriesRead);
|
||||||
|
Assert.Equal(applicationId, info[0].ProgramId);
|
||||||
|
Assert.Equal(InvalidUserId, info[0].UserId);
|
||||||
|
Assert.Equal(SaveDataType.Temporary, info[0].Type);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public static void EnsureApplicationSaveData_NeedsExtension_IsExtended()
|
public static void EnsureApplicationSaveData_NeedsExtension_IsExtended()
|
||||||
{
|
{
|
||||||
|
@ -180,18 +210,25 @@ public class ApplicationSaveDataManagementTests
|
||||||
|
|
||||||
Assert.Success(fs.EnsureApplicationCacheStorage(out _, out CacheStorageTargetMedia target, applicationId,
|
Assert.Success(fs.EnsureApplicationCacheStorage(out _, out CacheStorageTargetMedia target, applicationId,
|
||||||
in controlProperty));
|
in controlProperty));
|
||||||
|
AssertSaveExists();
|
||||||
|
|
||||||
Assert.Equal(CacheStorageTargetMedia.SdCard, target);
|
Assert.Success(fs.EnsureApplicationCacheStorage(out _, out target, applicationId, in controlProperty));
|
||||||
|
AssertSaveExists();
|
||||||
|
|
||||||
using var iterator = new UniqueRef<SaveDataIterator>();
|
void AssertSaveExists()
|
||||||
fs.OpenSaveDataIterator(ref iterator.Ref(), SaveDataSpaceId.SdUser);
|
{
|
||||||
|
Assert.Equal(CacheStorageTargetMedia.SdCard, target);
|
||||||
|
|
||||||
var info = new SaveDataInfo[2];
|
using var iterator = new UniqueRef<SaveDataIterator>();
|
||||||
Assert.Success(iterator.Get.ReadSaveDataInfo(out long entriesRead, info));
|
fs.OpenSaveDataIterator(ref iterator.Ref(), SaveDataSpaceId.SdUser);
|
||||||
|
|
||||||
Assert.Equal(1, entriesRead);
|
var info = new SaveDataInfo[2];
|
||||||
Assert.Equal(applicationId, info[0].ProgramId);
|
Assert.Success(iterator.Get.ReadSaveDataInfo(out long entriesRead, info));
|
||||||
Assert.Equal(SaveDataType.Cache, info[0].Type);
|
|
||||||
|
Assert.Equal(1, entriesRead);
|
||||||
|
Assert.Equal(applicationId, info[0].ProgramId);
|
||||||
|
Assert.Equal(SaveDataType.Cache, info[0].Type);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
|
@ -339,6 +339,37 @@ public class SaveDataManagement
|
||||||
Assert.Equal(mainProgramId, info[0].ProgramId);
|
Assert.Equal(mainProgramId, info[0].ProgramId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void CreateTemporaryStorage_DoesNotExist_SaveIsCreated()
|
||||||
|
{
|
||||||
|
long availableSize = 0x220000;
|
||||||
|
|
||||||
|
var applicationId = new Ncm.ApplicationId(1);
|
||||||
|
FileSystemClient fs = FileSystemServerFactory.CreateClient(true);
|
||||||
|
|
||||||
|
Assert.Success(fs.CreateTemporaryStorage(applicationId, 0, availableSize, SaveDataFlags.None));
|
||||||
|
|
||||||
|
using var iterator = new UniqueRef<SaveDataIterator>();
|
||||||
|
fs.OpenSaveDataIterator(ref iterator.Ref(), SaveDataSpaceId.Temporary);
|
||||||
|
|
||||||
|
var info = new SaveDataInfo[2];
|
||||||
|
iterator.Get.ReadSaveDataInfo(out long entriesRead, info);
|
||||||
|
|
||||||
|
Assert.Equal(1, entriesRead);
|
||||||
|
Assert.Equal(applicationId, info[0].ProgramId);
|
||||||
|
Assert.Equal(SaveDataType.Temporary, info[0].Type);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void CreateTemporaryStorage_AlreadyExists_ReturnsPathAlreadyExists()
|
||||||
|
{
|
||||||
|
var applicationId = new Ncm.ApplicationId(1);
|
||||||
|
FileSystemClient fs = FileSystemServerFactory.CreateClient(true);
|
||||||
|
|
||||||
|
Assert.Success(fs.CreateTemporaryStorage(applicationId, 0, 0x400000, SaveDataFlags.None));
|
||||||
|
Assert.Result(ResultFs.PathAlreadyExists, fs.CreateTemporaryStorage(applicationId, 0, 0x400000, SaveDataFlags.None));
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void DeleteSaveData_DoesNotExist_ReturnsTargetNotFound()
|
public void DeleteSaveData_DoesNotExist_ReturnsTargetNotFound()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue