2019-09-08 23:33:40 +02:00
|
|
|
|
using LibHac.Fs;
|
|
|
|
|
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))
|
|
|
|
|
{
|
|
|
|
|
IFileSystem saveFs = new LibHac.Fs.Save.SaveDataFileSystem(context.Device.System.KeySet, systemSaveData, IntegrityCheckLevel.None, false);
|
2018-09-09 00:04:26 +02:00
|
|
|
|
|
2019-09-08 23:33:40 +02:00
|
|
|
|
saveFs.CopyFileSystem(outputFolder);
|
|
|
|
|
}
|
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
|
|
|
|
}
|