aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.HLE/FileSystem/SaveHelper.cs
diff options
context:
space:
mode:
authorAc_K <Acoustik666@gmail.com>2019-09-08 23:33:40 +0200
committerThomas Guillemard <me@thog.eu>2019-09-08 23:33:40 +0200
commit1ff89d6482a6ec907bb983c1d2bc473bea546367 (patch)
tree9ca3bcb30007abd249419cdd63f8e475bc6059a8 /Ryujinx.HLE/FileSystem/SaveHelper.cs
parent9afb8ad485b364e3ecf738b1175c32cce95507bd (diff)
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
Diffstat (limited to 'Ryujinx.HLE/FileSystem/SaveHelper.cs')
-rw-r--r--Ryujinx.HLE/FileSystem/SaveHelper.cs57
1 files changed, 28 insertions, 29 deletions
diff --git a/Ryujinx.HLE/FileSystem/SaveHelper.cs b/Ryujinx.HLE/FileSystem/SaveHelper.cs
index 51400458..a1072498 100644
--- a/Ryujinx.HLE/FileSystem/SaveHelper.cs
+++ b/Ryujinx.HLE/FileSystem/SaveHelper.cs
@@ -1,45 +1,44 @@
-using Ryujinx.HLE.HOS;
+using LibHac.Fs;
+using Ryujinx.HLE.HOS;
using System.IO;
-using static Ryujinx.HLE.FileSystem.VirtualFileSystem;
-
namespace Ryujinx.HLE.FileSystem
{
static class SaveHelper
{
- public static string GetSavePath(SaveInfo saveMetaData, ServiceCtx context)
+ public static IFileSystem OpenSystemSaveData(ServiceCtx context, ulong saveId)
{
- string baseSavePath = NandPath;
- ulong currentTitleId = saveMetaData.TitleId;
+ SaveInfo saveInfo = new SaveInfo(0, (long)saveId, SaveDataType.SystemSaveData, SaveSpaceId.NandSystem);
+ string savePath = context.Device.FileSystem.GetSavePath(context, saveInfo, false);
- switch (saveMetaData.SaveSpaceId)
+ if (File.Exists(savePath))
{
- case SaveSpaceId.NandUser:
- baseSavePath = UserNandPath;
- break;
- case SaveSpaceId.NandSystem:
- baseSavePath = SystemNandPath;
- break;
- case SaveSpaceId.SdCard:
- baseSavePath = Path.Combine(SdCardPath, "Nintendo");
- break;
- }
+ string tempDirectoryPath = $"{savePath}_temp";
- baseSavePath = Path.Combine(baseSavePath, "save");
+ Directory.CreateDirectory(tempDirectoryPath);
- if (saveMetaData.TitleId == 0 && saveMetaData.SaveDataType == SaveDataType.SaveData)
- {
- currentTitleId = context.Process.TitleId;
- }
+ 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);
- string saveAccount = saveMetaData.UserId.IsNull ? "savecommon" : saveMetaData.UserId.ToString();
+ saveFs.CopyFileSystem(outputFolder);
+ }
- string savePath = Path.Combine(baseSavePath,
- saveMetaData.SaveId.ToString("x16"),
- saveAccount,
- saveMetaData.SaveDataType == SaveDataType.SaveData ? currentTitleId.ToString("x16") : string.Empty);
+ File.Delete(savePath);
+
+ Directory.Move(tempDirectoryPath, savePath);
+ }
+ else
+ {
+ if (!Directory.Exists(savePath))
+ {
+ Directory.CreateDirectory(savePath);
+ }
+ }
- return savePath;
+ return new LocalFileSystem(savePath);
}
}
-}
+} \ No newline at end of file