LocationHelper.cs 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. using System;
  2. using System.IO;
  3. using static Ryujinx.HLE.FileSystem.VirtualFileSystem;
  4. namespace Ryujinx.HLE.FileSystem.Content
  5. {
  6. internal static class LocationHelper
  7. {
  8. public static string GetRealPath(VirtualFileSystem fileSystem, string switchContentPath)
  9. {
  10. string basePath = fileSystem.GetBasePath();
  11. switch (switchContentPath)
  12. {
  13. case ContentPath.SystemContent:
  14. return Path.Combine(basePath, SystemNandPath, "Contents");
  15. case ContentPath.UserContent:
  16. return Path.Combine(basePath, UserNandPath, "Contents");
  17. case ContentPath.SdCardContent:
  18. return Path.Combine(fileSystem.GetSdCardPath(), "Nintendo", "Contents");
  19. case ContentPath.System:
  20. return Path.Combine(basePath, SystemNandPath);
  21. case ContentPath.User:
  22. return Path.Combine(basePath, UserNandPath);
  23. default:
  24. throw new NotSupportedException($"Content Path `{switchContentPath}` is not supported.");
  25. }
  26. }
  27. public static string GetContentPath(ContentStorageId contentStorageId)
  28. {
  29. switch (contentStorageId)
  30. {
  31. case ContentStorageId.NandSystem:
  32. return ContentPath.SystemContent;
  33. case ContentStorageId.NandUser:
  34. return ContentPath.UserContent;
  35. case ContentStorageId.SdCard:
  36. return ContentPath.SdCardContent;
  37. default:
  38. throw new NotSupportedException($"Content Storage `{contentStorageId}` is not supported.");
  39. }
  40. }
  41. public static string GetContentRoot(StorageId storageId)
  42. {
  43. switch (storageId)
  44. {
  45. case StorageId.NandSystem:
  46. return ContentPath.SystemContent;
  47. case StorageId.NandUser:
  48. return ContentPath.UserContent;
  49. case StorageId.SdCard:
  50. return ContentPath.SdCardContent;
  51. default:
  52. throw new NotSupportedException($"Storage Id `{storageId}` is not supported.");
  53. }
  54. }
  55. public static StorageId GetStorageId(string contentPathString)
  56. {
  57. string cleanedPath = contentPathString.Split(':')[0];
  58. switch (cleanedPath)
  59. {
  60. case ContentPath.SystemContent:
  61. case ContentPath.System:
  62. return StorageId.NandSystem;
  63. case ContentPath.UserContent:
  64. case ContentPath.User:
  65. return StorageId.NandUser;
  66. case ContentPath.SdCardContent:
  67. return StorageId.SdCard;
  68. case ContentPath.Host:
  69. return StorageId.Host;
  70. case ContentPath.GamecardApp:
  71. case ContentPath.GamecardContents:
  72. case ContentPath.GamecardUpdate:
  73. return StorageId.GameCard;
  74. default:
  75. return StorageId.None;
  76. }
  77. }
  78. }
  79. }