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