diff options
Diffstat (limited to 'Ryujinx.HLE/FileSystem')
| -rw-r--r-- | Ryujinx.HLE/FileSystem/SaveDataType.cs | 2 | ||||
| -rw-r--r-- | Ryujinx.HLE/FileSystem/SaveHelper.cs | 57 | ||||
| -rw-r--r-- | Ryujinx.HLE/FileSystem/SaveInfo.cs | 15 | ||||
| -rw-r--r-- | Ryujinx.HLE/FileSystem/VirtualFileSystem.cs | 67 |
4 files changed, 85 insertions, 56 deletions
diff --git a/Ryujinx.HLE/FileSystem/SaveDataType.cs b/Ryujinx.HLE/FileSystem/SaveDataType.cs index edfe8ab1..2207fc23 100644 --- a/Ryujinx.HLE/FileSystem/SaveDataType.cs +++ b/Ryujinx.HLE/FileSystem/SaveDataType.cs @@ -9,4 +9,4 @@ TemporaryStorage, CacheStorage } -} +}
\ No newline at end of file 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 diff --git a/Ryujinx.HLE/FileSystem/SaveInfo.cs b/Ryujinx.HLE/FileSystem/SaveInfo.cs index 8685e6ca..0fc35575 100644 --- a/Ryujinx.HLE/FileSystem/SaveInfo.cs +++ b/Ryujinx.HLE/FileSystem/SaveInfo.cs @@ -4,25 +4,24 @@ namespace Ryujinx.HLE.FileSystem { struct SaveInfo { - public ulong TitleId { get; private set; } - public long SaveId { get; private set; } - public UInt128 UserId { get; private set; } - + public ulong TitleId { get; private set; } + public long SaveId { get; private set; } public SaveDataType SaveDataType { get; private set; } public SaveSpaceId SaveSpaceId { get; private set; } + public UInt128 UserId { get; private set; } public SaveInfo( ulong titleId, long saveId, SaveDataType saveDataType, - UInt128 userId, - SaveSpaceId saveSpaceId) + SaveSpaceId saveSpaceId, + UInt128 userId = new UInt128()) { TitleId = titleId; - UserId = userId; SaveId = saveId; SaveDataType = saveDataType; SaveSpaceId = saveSpaceId; + UserId = userId; } } -} +}
\ No newline at end of file diff --git a/Ryujinx.HLE/FileSystem/VirtualFileSystem.cs b/Ryujinx.HLE/FileSystem/VirtualFileSystem.cs index e71fc27f..5511ebcc 100644 --- a/Ryujinx.HLE/FileSystem/VirtualFileSystem.cs +++ b/Ryujinx.HLE/FileSystem/VirtualFileSystem.cs @@ -54,20 +54,48 @@ namespace Ryujinx.HLE.FileSystem return fullPath; } - public string GetSdCardPath() => MakeDirAndGetFullPath(SdCardPath); + public string GetSdCardPath() => MakeFullPath(SdCardPath); - public string GetNandPath() => MakeDirAndGetFullPath(NandPath); + public string GetNandPath() => MakeFullPath(NandPath); - public string GetSystemPath() => MakeDirAndGetFullPath(SystemPath); + public string GetSystemPath() => MakeFullPath(SystemPath); - internal string GetGameSavePath(SaveInfo save, ServiceCtx context) + internal string GetSavePath(ServiceCtx context, SaveInfo saveInfo, bool isDirectory = true) { - return MakeDirAndGetFullPath(SaveHelper.GetSavePath(save, context)); + string saveUserPath = ""; + string baseSavePath = NandPath; + ulong currentTitleId = saveInfo.TitleId; + + switch (saveInfo.SaveSpaceId) + { + case SaveSpaceId.NandUser: baseSavePath = UserNandPath; break; + case SaveSpaceId.NandSystem: baseSavePath = SystemNandPath; break; + case SaveSpaceId.SdCard: baseSavePath = Path.Combine(SdCardPath, "Nintendo"); break; + } + + baseSavePath = Path.Combine(baseSavePath, "save"); + + if (saveInfo.TitleId == 0 && saveInfo.SaveDataType == SaveDataType.SaveData) + { + currentTitleId = context.Process.TitleId; + } + + if (saveInfo.SaveSpaceId == SaveSpaceId.NandUser) + { + saveUserPath = saveInfo.UserId.IsNull ? "savecommon" : saveInfo.UserId.ToString(); + } + + string savePath = Path.Combine(baseSavePath, + saveInfo.SaveId.ToString("x16"), + saveUserPath, + saveInfo.SaveDataType == SaveDataType.SaveData ? currentTitleId.ToString("x16") : string.Empty); + + return MakeFullPath(savePath, isDirectory); } public string GetFullPartitionPath(string partitionPath) { - return MakeDirAndGetFullPath(partitionPath); + return MakeFullPath(partitionPath); } public string SwitchPathToSystemPath(string switchPath) @@ -79,7 +107,7 @@ namespace Ryujinx.HLE.FileSystem return null; } - return GetFullPath(MakeDirAndGetFullPath(parts[0]), parts[1]); + return GetFullPath(MakeFullPath(parts[0]), parts[1]); } public string SystemPathToSwitchPath(string systemPath) @@ -104,37 +132,40 @@ namespace Ryujinx.HLE.FileSystem return null; } - private string MakeDirAndGetFullPath(string dir) + private string MakeFullPath(string path, bool isDirectory = true) { // Handles Common Switch Content Paths - switch (dir) + switch (path) { case ContentPath.SdCard: case "@Sdcard": - dir = SdCardPath; + path = SdCardPath; break; case ContentPath.User: - dir = UserNandPath; + path = UserNandPath; break; case ContentPath.System: - dir = SystemNandPath; + path = SystemNandPath; break; case ContentPath.SdCardContent: - dir = Path.Combine(SdCardPath, "Nintendo", "Contents"); + path = Path.Combine(SdCardPath, "Nintendo", "Contents"); break; case ContentPath.UserContent: - dir = Path.Combine(UserNandPath, "Contents"); + path = Path.Combine(UserNandPath, "Contents"); break; case ContentPath.SystemContent: - dir = Path.Combine(SystemNandPath, "Contents"); + path = Path.Combine(SystemNandPath, "Contents"); break; } - string fullPath = Path.Combine(GetBasePath(), dir); + string fullPath = Path.Combine(GetBasePath(), path); - if (!Directory.Exists(fullPath)) + if (isDirectory) { - Directory.CreateDirectory(fullPath); + if (!Directory.Exists(fullPath)) + { + Directory.CreateDirectory(fullPath); + } } return fullPath; |
