SaveHelper.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using LibHac.Fs.Fsa;
  2. using LibHac.FsSystem;
  3. using Ryujinx.HLE.HOS;
  4. using System.IO;
  5. namespace Ryujinx.HLE.FileSystem
  6. {
  7. static class SaveHelper
  8. {
  9. public static IFileSystem OpenSystemSaveData(ServiceCtx context, ulong saveId)
  10. {
  11. SaveInfo saveInfo = new SaveInfo(0, (long)saveId, SaveDataType.SystemSaveData, SaveSpaceId.NandSystem);
  12. string savePath = context.Device.FileSystem.GetSavePath(context, saveInfo, false);
  13. if (File.Exists(savePath))
  14. {
  15. string tempDirectoryPath = $"{savePath}_temp";
  16. Directory.CreateDirectory(tempDirectoryPath);
  17. IFileSystem outputFolder = new LocalFileSystem(tempDirectoryPath);
  18. using (LocalStorage systemSaveData = new LocalStorage(savePath, FileAccess.Read, FileMode.Open))
  19. {
  20. IFileSystem saveFs = new LibHac.FsSystem.Save.SaveDataFileSystem(context.Device.System.KeySet, systemSaveData, IntegrityCheckLevel.None, false);
  21. saveFs.CopyDirectory(outputFolder, "/", "/");
  22. }
  23. File.Delete(savePath);
  24. Directory.Move(tempDirectoryPath, savePath);
  25. }
  26. else
  27. {
  28. if (!Directory.Exists(savePath))
  29. {
  30. Directory.CreateDirectory(savePath);
  31. }
  32. }
  33. return new LocalFileSystem(savePath);
  34. }
  35. }
  36. }