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