ContentPath.cs 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. using LibHac.Fs;
  2. using LibHac.Ncm;
  3. using Ryujinx.Common.Configuration;
  4. using System;
  5. using static Ryujinx.HLE.FileSystem.VirtualFileSystem;
  6. using Path = System.IO.Path;
  7. namespace Ryujinx.HLE.FileSystem
  8. {
  9. internal static class ContentPath
  10. {
  11. public const string SystemContent = "@SystemContent";
  12. public const string UserContent = "@UserContent";
  13. public const string SdCardContent = "@SdCardContent";
  14. public const string SdCard = "@Sdcard";
  15. public const string CalibFile = "@CalibFile";
  16. public const string Safe = "@Safe";
  17. public const string User = "@User";
  18. public const string System = "@System";
  19. public const string Host = "@Host";
  20. public const string GamecardApp = "@GcApp";
  21. public const string GamecardContents = "@GcS00000001";
  22. public const string GamecardUpdate = "@upp";
  23. public const string RegisteredUpdate = "@RegUpdate";
  24. public const string Nintendo = "Nintendo";
  25. public const string Contents = "Contents";
  26. public static string GetRealPath(VirtualFileSystem fileSystem, string switchContentPath)
  27. {
  28. return switchContentPath switch
  29. {
  30. SystemContent => Path.Combine(AppDataManager.BaseDirPath, SystemNandPath, Contents),
  31. UserContent => Path.Combine(AppDataManager.BaseDirPath, UserNandPath, Contents),
  32. SdCardContent => Path.Combine(fileSystem.GetSdCardPath(), Nintendo, Contents),
  33. System => Path.Combine(AppDataManager.BaseDirPath, SystemNandPath),
  34. User => Path.Combine(AppDataManager.BaseDirPath, UserNandPath),
  35. _ => throw new NotSupportedException($"Content Path \"`{switchContentPath}`\" is not supported.")
  36. };
  37. }
  38. public static string GetContentPath(ContentStorageId contentStorageId)
  39. {
  40. return contentStorageId switch
  41. {
  42. ContentStorageId.System => SystemContent,
  43. ContentStorageId.User => UserContent,
  44. ContentStorageId.SdCard => SdCardContent,
  45. _ => throw new NotSupportedException($"Content Storage Id \"`{contentStorageId}`\" is not supported.")
  46. };
  47. }
  48. public static string GetContentPath(StorageId storageId)
  49. {
  50. return storageId switch
  51. {
  52. StorageId.BuiltInSystem => SystemContent,
  53. StorageId.BuiltInUser => UserContent,
  54. StorageId.SdCard => SdCardContent,
  55. _ => throw new NotSupportedException($"Storage Id \"`{storageId}`\" is not supported.")
  56. };
  57. }
  58. public static StorageId GetStorageId(string contentPathString)
  59. {
  60. return contentPathString.Split(':')[0] switch
  61. {
  62. SystemContent or
  63. System => StorageId.BuiltInSystem,
  64. UserContent or
  65. User => StorageId.BuiltInUser,
  66. SdCardContent => StorageId.SdCard,
  67. Host => StorageId.Host,
  68. GamecardApp or
  69. GamecardContents or
  70. GamecardUpdate => StorageId.GameCard,
  71. _ => StorageId.None
  72. };
  73. }
  74. }
  75. }