diff options
Diffstat (limited to 'Ryujinx.HLE/FileSystem/SaveHelper.cs')
-rw-r--r-- | Ryujinx.HLE/FileSystem/SaveHelper.cs | 57 |
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 |