aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.HLE/FileSystem/SaveHelper.cs
blob: b74d853c79935625a2aa00eb81510012ebfc3108 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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)
        {
            string BaseSavePath   = NandPath;
            long   CurrentTitleId = SaveMetaData.TitleId;

            switch (SaveMetaData.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 (SaveMetaData.TitleId == 0 && SaveMetaData.SaveDataType == SaveDataType.SaveData)
            {
                if (Context.Process.MetaData != null)
                {
                    CurrentTitleId = Context.Process.MetaData.ACI0.TitleId;
                }
            }

            string SaveAccount = SaveMetaData.UserId.IsZero() ? "savecommon" : SaveMetaData.UserId.ToString();

            string SavePath = Path.Combine(BaseSavePath,
                SaveMetaData.SaveId.ToString("x16"),
                SaveAccount,
                SaveMetaData.SaveDataType == SaveDataType.SaveData ? CurrentTitleId.ToString("x16") : string.Empty);

            return SavePath;
        }
    }
}