2020-09-01 21:08:59 +01:00
|
|
|
|
using LibHac.Fs.Fsa;
|
2019-10-17 07:17:44 +01:00
|
|
|
|
using LibHac.FsSystem;
|
2019-09-08 22:33:40 +01:00
|
|
|
|
using Ryujinx.HLE.HOS;
|
2018-09-08 23:04:26 +01:00
|
|
|
|
using System.IO;
|
|
|
|
|
|
|
|
|
|
namespace Ryujinx.HLE.FileSystem
|
|
|
|
|
{
|
|
|
|
|
static class SaveHelper
|
|
|
|
|
{
|
2019-09-08 22:33:40 +01:00
|
|
|
|
public static IFileSystem OpenSystemSaveData(ServiceCtx context, ulong saveId)
|
2018-09-08 23:04:26 +01:00
|
|
|
|
{
|
2019-09-08 22:33:40 +01:00
|
|
|
|
SaveInfo saveInfo = new SaveInfo(0, (long)saveId, SaveDataType.SystemSaveData, SaveSpaceId.NandSystem);
|
|
|
|
|
string savePath = context.Device.FileSystem.GetSavePath(context, saveInfo, false);
|
2018-09-08 23:04:26 +01:00
|
|
|
|
|
2019-09-08 22:33:40 +01:00
|
|
|
|
if (File.Exists(savePath))
|
2018-09-08 23:04:26 +01:00
|
|
|
|
{
|
2019-09-08 22:33:40 +01:00
|
|
|
|
string tempDirectoryPath = $"{savePath}_temp";
|
2018-09-08 23:04:26 +01:00
|
|
|
|
|
2019-09-08 22:33:40 +01:00
|
|
|
|
Directory.CreateDirectory(tempDirectoryPath);
|
2018-09-08 23:04:26 +01:00
|
|
|
|
|
2019-09-08 22:33:40 +01:00
|
|
|
|
IFileSystem outputFolder = new LocalFileSystem(tempDirectoryPath);
|
|
|
|
|
|
|
|
|
|
using (LocalStorage systemSaveData = new LocalStorage(savePath, FileAccess.Read, FileMode.Open))
|
|
|
|
|
{
|
2019-10-17 07:17:44 +01:00
|
|
|
|
IFileSystem saveFs = new LibHac.FsSystem.Save.SaveDataFileSystem(context.Device.System.KeySet, systemSaveData, IntegrityCheckLevel.None, false);
|
2018-09-08 23:04:26 +01:00
|
|
|
|
|
2019-10-17 07:17:44 +01:00
|
|
|
|
saveFs.CopyDirectory(outputFolder, "/", "/");
|
2019-09-08 22:33:40 +01:00
|
|
|
|
}
|
2018-10-07 14:13:46 +01:00
|
|
|
|
|
2019-09-08 22:33:40 +01:00
|
|
|
|
File.Delete(savePath);
|
|
|
|
|
|
|
|
|
|
Directory.Move(tempDirectoryPath, savePath);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (!Directory.Exists(savePath))
|
|
|
|
|
{
|
|
|
|
|
Directory.CreateDirectory(savePath);
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-09-08 23:04:26 +01:00
|
|
|
|
|
2019-09-08 22:33:40 +01:00
|
|
|
|
return new LocalFileSystem(savePath);
|
2018-09-08 23:04:26 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-09-08 22:33:40 +01:00
|
|
|
|
}
|