ryujinx-mirror/Ryujinx.HLE/FileSystem/SaveHelper.cs
Ac_K 1ff89d6482 Implement basic support of SystemSaveData and Cleanup IFileSystemProxy (#767)
* Implement basic support of SystemSaveData and Cleanup IFileSystemProxy

- Implement `OpenSystemSaveData` as a `IFileSystem` in `SaveHelper`:
  On real device, system saves data are stored encrypted, and we can't create an empty system save data for now. That's why if a user put his own dump of system save in `RyuFs\nand\system\save\`, we extract content in associated folder and open it as a `IFileSystem`. If the system save data don't exist, a folder is created.

- Cleanup `IFileSystemProxy` by adding a Helper class.

- Implement `GetSavePath` in `VirtualFileSystem` and remove `GetGameSavePath` in `SaveHelper`.

* remove the forgotten I

* Fix align
2019-09-08 23:33:40 +02:00

44 lines
No EOL
1.4 KiB
C#

using LibHac.Fs;
using Ryujinx.HLE.HOS;
using System.IO;
namespace Ryujinx.HLE.FileSystem
{
static class SaveHelper
{
public static IFileSystem OpenSystemSaveData(ServiceCtx context, ulong saveId)
{
SaveInfo saveInfo = new SaveInfo(0, (long)saveId, SaveDataType.SystemSaveData, SaveSpaceId.NandSystem);
string savePath = context.Device.FileSystem.GetSavePath(context, saveInfo, false);
if (File.Exists(savePath))
{
string tempDirectoryPath = $"{savePath}_temp";
Directory.CreateDirectory(tempDirectoryPath);
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);
saveFs.CopyFileSystem(outputFolder);
}
File.Delete(savePath);
Directory.Move(tempDirectoryPath, savePath);
}
else
{
if (!Directory.Exists(savePath))
{
Directory.CreateDirectory(savePath);
}
}
return new LocalFileSystem(savePath);
}
}
}