SaveHelper.cs 1.4 KB

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