2020-02-14 01:21:24 +01:00
|
|
|
|
using LibHac.Common;
|
|
|
|
|
using LibHac.Fs;
|
2021-02-21 08:00:59 +01:00
|
|
|
|
using LibHac.Fs.Fsa;
|
2020-02-14 01:21:24 +01:00
|
|
|
|
using LibHac.Fs.Shim;
|
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
|
|
namespace LibHac.Tests.Fs.FileSystemClientTests.ShimTests
|
|
|
|
|
{
|
|
|
|
|
public class SaveData
|
|
|
|
|
{
|
|
|
|
|
[Fact]
|
|
|
|
|
public void MountCacheStorage_CanMountCreatedCacheStorage()
|
|
|
|
|
{
|
2020-07-10 06:22:04 +02:00
|
|
|
|
var applicationId = new Ncm.ApplicationId(1);
|
2020-02-14 01:21:24 +01:00
|
|
|
|
FileSystemClient fs = FileSystemServerFactory.CreateClient(true);
|
|
|
|
|
|
2020-07-10 06:22:04 +02:00
|
|
|
|
fs.CreateCacheStorage(applicationId, SaveDataSpaceId.User, applicationId.Value, 0, 0, SaveDataFlags.None);
|
2020-02-14 01:21:24 +01:00
|
|
|
|
|
2020-03-09 08:06:39 +01:00
|
|
|
|
Assert.Success(fs.MountCacheStorage("cache".ToU8Span(), applicationId));
|
2020-02-14 01:21:24 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void MountCacheStorage_WrittenDataPersists()
|
|
|
|
|
{
|
2020-07-10 06:22:04 +02:00
|
|
|
|
var applicationId = new Ncm.ApplicationId(1);
|
2020-02-14 01:21:24 +01:00
|
|
|
|
FileSystemClient fs = FileSystemServerFactory.CreateClient(true);
|
|
|
|
|
|
2020-07-10 06:22:04 +02:00
|
|
|
|
fs.CreateCacheStorage(applicationId, SaveDataSpaceId.SdCache, applicationId.Value, 0, 0, SaveDataFlags.None);
|
2020-03-09 08:06:39 +01:00
|
|
|
|
fs.MountCacheStorage("cache".ToU8Span(), applicationId);
|
2020-02-14 01:21:24 +01:00
|
|
|
|
|
2020-03-09 08:06:39 +01:00
|
|
|
|
fs.CreateFile("cache:/file".ToU8Span(), 0);
|
|
|
|
|
fs.Commit("cache".ToU8Span());
|
|
|
|
|
fs.Unmount("cache".ToU8Span());
|
2020-02-14 01:21:24 +01:00
|
|
|
|
|
2020-03-09 08:06:39 +01:00
|
|
|
|
Assert.Success(fs.MountCacheStorage("cache".ToU8Span(), applicationId));
|
|
|
|
|
Assert.Success(fs.GetEntryType(out DirectoryEntryType type, "cache:/file".ToU8Span()));
|
2020-02-14 01:21:24 +01:00
|
|
|
|
Assert.Equal(DirectoryEntryType.File, type);
|
|
|
|
|
}
|
2020-04-04 23:19:36 +02:00
|
|
|
|
|
2020-02-14 01:21:24 +01:00
|
|
|
|
[Fact]
|
|
|
|
|
public void MountCacheStorage_SdCardIsPreferredOverBis()
|
|
|
|
|
{
|
2020-07-10 06:22:04 +02:00
|
|
|
|
var applicationId = new Ncm.ApplicationId(1);
|
2020-02-14 01:21:24 +01:00
|
|
|
|
FileSystemClient fs = FileSystemServerFactory.CreateClient(true);
|
|
|
|
|
|
2021-08-05 20:59:05 +02:00
|
|
|
|
Assert.Success(fs.CreateCacheStorage(applicationId, SaveDataSpaceId.SdCache, applicationId.Value, 0, 0, SaveDataFlags.None));
|
|
|
|
|
Assert.Success(fs.MountCacheStorage("cache".ToU8Span(), applicationId));
|
2020-03-09 08:06:39 +01:00
|
|
|
|
fs.CreateFile("cache:/sd".ToU8Span(), 0);
|
|
|
|
|
fs.Commit("cache".ToU8Span());
|
|
|
|
|
fs.Unmount("cache".ToU8Span());
|
2020-02-14 01:21:24 +01:00
|
|
|
|
|
|
|
|
|
// Turn off the SD card so the User save is mounted
|
|
|
|
|
fs.SetSdCardAccessibility(false);
|
|
|
|
|
|
2020-07-10 06:22:04 +02:00
|
|
|
|
fs.CreateCacheStorage(applicationId, SaveDataSpaceId.User, applicationId.Value, 0, 0, SaveDataFlags.None);
|
2020-03-09 08:06:39 +01:00
|
|
|
|
fs.MountCacheStorage("cache".ToU8Span(), applicationId);
|
|
|
|
|
fs.CreateFile("cache:/bis".ToU8Span(), 0);
|
|
|
|
|
fs.Commit("cache".ToU8Span());
|
|
|
|
|
fs.Unmount("cache".ToU8Span());
|
2020-02-14 01:21:24 +01:00
|
|
|
|
|
|
|
|
|
fs.SetSdCardAccessibility(true);
|
|
|
|
|
|
|
|
|
|
Assert.Success(fs.MountCacheStorage("cache".ToU8String(), applicationId));
|
2020-03-09 08:06:39 +01:00
|
|
|
|
Assert.Success(fs.GetEntryType(out _, "cache:/sd".ToU8Span()));
|
|
|
|
|
Assert.Failure(fs.GetEntryType(out _, "cache:/bis".ToU8Span()));
|
2020-02-14 01:21:24 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|