aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.HLE/FileSystem/Content/LocationHelper.cs
blob: c522b053ba6714f2eeb2cc8bd797371650236ec4 (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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
using System;
using System.IO;

using static Ryujinx.HLE.FileSystem.VirtualFileSystem;

namespace Ryujinx.HLE.FileSystem.Content
{
    internal static class LocationHelper
    {
        public static string GetRealPath(VirtualFileSystem fileSystem, string switchContentPath)
        {
            string basePath = fileSystem.GetBasePath();

            switch (switchContentPath)
            {
                case ContentPath.SystemContent:
                    return Path.Combine(basePath, SystemNandPath, "Contents");
                case ContentPath.UserContent:
                    return Path.Combine(basePath, UserNandPath, "Contents");
                case ContentPath.SdCardContent:
                    return Path.Combine(fileSystem.GetSdCardPath(), "Nintendo", "Contents");
                case ContentPath.System:
                    return Path.Combine(basePath, SystemNandPath);
                case ContentPath.User:
                    return Path.Combine(basePath, UserNandPath);
                default:
                    throw new NotSupportedException($"Content Path `{switchContentPath}` is not supported.");
            }
        }

        public static string GetContentPath(ContentStorageId contentStorageId)
        {
            switch (contentStorageId)
            {
                case ContentStorageId.NandSystem:
                    return ContentPath.SystemContent;
                case ContentStorageId.NandUser:
                    return ContentPath.UserContent;
                case ContentStorageId.SdCard:
                    return ContentPath.SdCardContent;
                default:
                    throw new NotSupportedException($"Content Storage `{contentStorageId}` is not supported.");
            }
        }

        public static string GetContentRoot(StorageId storageId)
        {
            switch (storageId)
            {
                case StorageId.NandSystem:
                    return ContentPath.SystemContent;
                case StorageId.NandUser:
                    return ContentPath.UserContent;
                case StorageId.SdCard:
                    return ContentPath.SdCardContent;
                default:
                    throw new NotSupportedException($"Storage Id `{storageId}` is not supported.");
            }
        }

        public static StorageId GetStorageId(string contentPathString)
        {
            string cleanedPath = contentPathString.Split(':')[0];

            switch (cleanedPath)
            {
                case ContentPath.SystemContent:
                case ContentPath.System:
                    return StorageId.NandSystem;

                case ContentPath.UserContent:
                case ContentPath.User:
                    return StorageId.NandUser;

                case ContentPath.SdCardContent:
                    return StorageId.SdCard;

                case ContentPath.Host:
                    return StorageId.Host;

                case ContentPath.GamecardApp:
                case ContentPath.GamecardContents:
                case ContentPath.GamecardUpdate:
                    return StorageId.GameCard;

                default:
                    return StorageId.None;
            }
        }
    }
}