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