diff options
Diffstat (limited to 'Ryujinx.HLE/FileSystem')
-rw-r--r-- | Ryujinx.HLE/FileSystem/Content/ContentPath.cs | 19 | ||||
-rw-r--r-- | Ryujinx.HLE/FileSystem/Content/LocationHelper.cs | 91 | ||||
-rw-r--r-- | Ryujinx.HLE/FileSystem/Content/StorageId.cs | 9 | ||||
-rw-r--r-- | Ryujinx.HLE/FileSystem/Content/TitleType.cs | 15 | ||||
-rw-r--r-- | Ryujinx.HLE/FileSystem/ContentManager.cs (renamed from Ryujinx.HLE/FileSystem/Content/ContentManager.cs) | 19 | ||||
-rw-r--r-- | Ryujinx.HLE/FileSystem/ContentPath.cs | 82 | ||||
-rw-r--r-- | Ryujinx.HLE/FileSystem/EncryptedFileSystemCreator.cs | 5 | ||||
-rw-r--r-- | Ryujinx.HLE/FileSystem/LocationEntry.cs (renamed from Ryujinx.HLE/FileSystem/Content/LocationEntry.cs) | 2 | ||||
-rw-r--r-- | Ryujinx.HLE/FileSystem/SaveDataType.cs | 12 | ||||
-rw-r--r-- | Ryujinx.HLE/FileSystem/SaveInfo.cs | 27 | ||||
-rw-r--r-- | Ryujinx.HLE/FileSystem/SaveSpaceId.cs | 10 | ||||
-rw-r--r-- | Ryujinx.HLE/FileSystem/StorageId.cs | 12 | ||||
-rw-r--r-- | Ryujinx.HLE/FileSystem/SystemVersion.cs (renamed from Ryujinx.HLE/FileSystem/Content/SystemVersion.cs) | 3 | ||||
-rw-r--r-- | Ryujinx.HLE/FileSystem/VirtualFileSystem.cs | 88 |
14 files changed, 126 insertions, 268 deletions
diff --git a/Ryujinx.HLE/FileSystem/Content/ContentPath.cs b/Ryujinx.HLE/FileSystem/Content/ContentPath.cs deleted file mode 100644 index 1e2c8ab3..00000000 --- a/Ryujinx.HLE/FileSystem/Content/ContentPath.cs +++ /dev/null @@ -1,19 +0,0 @@ -namespace Ryujinx.HLE.FileSystem.Content -{ - static class ContentPath - { - public const string SystemContent = "@SystemContent"; - public const string UserContent = "@UserContent"; - public const string SdCardContent = "@SdCardContent"; - public const string SdCard = "@SdCard"; - public const string CalibFile = "@CalibFile"; - public const string Safe = "@Safe"; - public const string User = "@User"; - public const string System = "@System"; - public const string Host = "@Host"; - public const string GamecardApp = "@GcApp"; - public const string GamecardContents = "@GcS00000001"; - public const string GamecardUpdate = "@upp"; - public const string RegisteredUpdate = "@RegUpdate"; - } -}
\ No newline at end of file diff --git a/Ryujinx.HLE/FileSystem/Content/LocationHelper.cs b/Ryujinx.HLE/FileSystem/Content/LocationHelper.cs deleted file mode 100644 index c522b053..00000000 --- a/Ryujinx.HLE/FileSystem/Content/LocationHelper.cs +++ /dev/null @@ -1,91 +0,0 @@ -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; - } - } - } -} diff --git a/Ryujinx.HLE/FileSystem/Content/StorageId.cs b/Ryujinx.HLE/FileSystem/Content/StorageId.cs deleted file mode 100644 index 4ff3dd65..00000000 --- a/Ryujinx.HLE/FileSystem/Content/StorageId.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Ryujinx.HLE.FileSystem.Content -{ - public enum ContentStorageId - { - NandSystem, - NandUser, - SdCard - } -} diff --git a/Ryujinx.HLE/FileSystem/Content/TitleType.cs b/Ryujinx.HLE/FileSystem/Content/TitleType.cs deleted file mode 100644 index 6ad26c9c..00000000 --- a/Ryujinx.HLE/FileSystem/Content/TitleType.cs +++ /dev/null @@ -1,15 +0,0 @@ -namespace Ryujinx.HLE.FileSystem.Content -{ - enum TitleType - { - SystemPrograms = 0x01, - SystemDataArchive = 0x02, - SystemUpdate = 0x03, - FirmwarePackageA = 0x04, - FirmwarePackageB = 0x05, - RegularApplication = 0x80, - Update = 0x81, - AddOnContent = 0x82, - DeltaTitle = 0x83 - } -} diff --git a/Ryujinx.HLE/FileSystem/Content/ContentManager.cs b/Ryujinx.HLE/FileSystem/ContentManager.cs index 8ac31a4c..2544cdda 100644 --- a/Ryujinx.HLE/FileSystem/Content/ContentManager.cs +++ b/Ryujinx.HLE/FileSystem/ContentManager.cs @@ -20,7 +20,7 @@ using System.IO.Compression; using System.Linq; using Path = System.IO.Path; -namespace Ryujinx.HLE.FileSystem.Content +namespace Ryujinx.HLE.FileSystem { public class ContentManager { @@ -110,8 +110,8 @@ namespace Ryujinx.HLE.FileSystem.Content try { - contentPathString = LocationHelper.GetContentRoot(storageId); - contentDirectory = LocationHelper.GetRealPath(_virtualFileSystem, contentPathString); + contentPathString = ContentPath.GetContentPath(storageId); + contentDirectory = ContentPath.GetRealPath(_virtualFileSystem, contentPathString); registeredDirectory = Path.Combine(contentDirectory, "registered"); } catch (NotSupportedException) @@ -367,8 +367,7 @@ namespace Ryujinx.HLE.FileSystem.Content { LocationEntry locationEntry = GetLocation(titleId, contentType, storageId); - return locationEntry.ContentPath != null ? - LocationHelper.GetStorageId(locationEntry.ContentPath) : StorageId.None; + return locationEntry.ContentPath != null ? ContentPath.GetStorageId(locationEntry.ContentPath) : StorageId.None; } } @@ -493,8 +492,8 @@ namespace Ryujinx.HLE.FileSystem.Content public void InstallFirmware(string firmwareSource) { - string contentPathString = LocationHelper.GetContentRoot(StorageId.NandSystem); - string contentDirectory = LocationHelper.GetRealPath(_virtualFileSystem, contentPathString); + string contentPathString = ContentPath.GetContentPath(StorageId.BuiltInSystem); + string contentDirectory = ContentPath.GetRealPath(_virtualFileSystem, contentPathString); string registeredDirectory = Path.Combine(contentDirectory, "registered"); string temporaryDirectory = Path.Combine(contentDirectory, "temp"); @@ -998,9 +997,9 @@ namespace Ryujinx.HLE.FileSystem.Content foreach (var entry in updateNcas) { - foreach (var nca in entry.Value) + foreach (var (type, path) in entry.Value) { - extraNcas += nca.path + Environment.NewLine; + extraNcas += path + Environment.NewLine; } } @@ -1019,7 +1018,7 @@ namespace Ryujinx.HLE.FileSystem.Content lock (_lock) { - var locationEnties = _locationEntries[StorageId.NandSystem]; + var locationEnties = _locationEntries[StorageId.BuiltInSystem]; foreach (var entry in locationEnties) { diff --git a/Ryujinx.HLE/FileSystem/ContentPath.cs b/Ryujinx.HLE/FileSystem/ContentPath.cs new file mode 100644 index 00000000..c8663081 --- /dev/null +++ b/Ryujinx.HLE/FileSystem/ContentPath.cs @@ -0,0 +1,82 @@ +using LibHac.Fs; +using LibHac.Ncm; +using Ryujinx.Common.Configuration; +using System; + +using static Ryujinx.HLE.FileSystem.VirtualFileSystem; +using Path = System.IO.Path; + +namespace Ryujinx.HLE.FileSystem +{ + internal static class ContentPath + { + public const string SystemContent = "@SystemContent"; + public const string UserContent = "@UserContent"; + public const string SdCardContent = "@SdCardContent"; + public const string SdCard = "@Sdcard"; + public const string CalibFile = "@CalibFile"; + public const string Safe = "@Safe"; + public const string User = "@User"; + public const string System = "@System"; + public const string Host = "@Host"; + public const string GamecardApp = "@GcApp"; + public const string GamecardContents = "@GcS00000001"; + public const string GamecardUpdate = "@upp"; + public const string RegisteredUpdate = "@RegUpdate"; + + public const string Nintendo = "Nintendo"; + public const string Contents = "Contents"; + + public static string GetRealPath(VirtualFileSystem fileSystem, string switchContentPath) + { + return switchContentPath switch + { + SystemContent => Path.Combine(AppDataManager.BaseDirPath, SystemNandPath, Contents), + UserContent => Path.Combine(AppDataManager.BaseDirPath, UserNandPath, Contents), + SdCardContent => Path.Combine(fileSystem.GetSdCardPath(), Nintendo, Contents), + System => Path.Combine(AppDataManager.BaseDirPath, SystemNandPath), + User => Path.Combine(AppDataManager.BaseDirPath, UserNandPath), + _ => throw new NotSupportedException($"Content Path \"`{switchContentPath}`\" is not supported.") + }; + } + + public static string GetContentPath(ContentStorageId contentStorageId) + { + return contentStorageId switch + { + ContentStorageId.System => SystemContent, + ContentStorageId.User => UserContent, + ContentStorageId.SdCard => SdCardContent, + _ => throw new NotSupportedException($"Content Storage Id \"`{contentStorageId}`\" is not supported.") + }; + } + + public static string GetContentPath(StorageId storageId) + { + return storageId switch + { + StorageId.BuiltInSystem => SystemContent, + StorageId.BuiltInUser => UserContent, + StorageId.SdCard => SdCardContent, + _ => throw new NotSupportedException($"Storage Id \"`{storageId}`\" is not supported.") + }; + } + + public static StorageId GetStorageId(string contentPathString) + { + return contentPathString.Split(':')[0] switch + { + SystemContent or + System => StorageId.BuiltInSystem, + UserContent or + User => StorageId.BuiltInUser, + SdCardContent => StorageId.SdCard, + Host => StorageId.Host, + GamecardApp or + GamecardContents or + GamecardUpdate => StorageId.GameCard, + _ => StorageId.None + }; + } + } +}
\ No newline at end of file diff --git a/Ryujinx.HLE/FileSystem/EncryptedFileSystemCreator.cs b/Ryujinx.HLE/FileSystem/EncryptedFileSystemCreator.cs index 60c3cfdb..f32dc2d7 100644 --- a/Ryujinx.HLE/FileSystem/EncryptedFileSystemCreator.cs +++ b/Ryujinx.HLE/FileSystem/EncryptedFileSystemCreator.cs @@ -8,7 +8,6 @@ namespace Ryujinx.HLE.FileSystem { public class EncryptedFileSystemCreator : IEncryptedFileSystemCreator { - public Result Create(ref SharedRef<IFileSystem> outEncryptedFileSystem, ref SharedRef<IFileSystem> baseFileSystem, IEncryptedFileSystemCreator.KeyId idIndex, in EncryptionSeed encryptionSeed) @@ -18,10 +17,10 @@ namespace Ryujinx.HLE.FileSystem return ResultFs.InvalidArgument.Log(); } - // Todo: Reenable when AesXtsFileSystem is fixed + // TODO: Reenable when AesXtsFileSystem is fixed. outEncryptedFileSystem = SharedRef<IFileSystem>.CreateMove(ref baseFileSystem); return Result.Success; } } -} +}
\ No newline at end of file diff --git a/Ryujinx.HLE/FileSystem/Content/LocationEntry.cs b/Ryujinx.HLE/FileSystem/LocationEntry.cs index bf938746..45cbc8cd 100644 --- a/Ryujinx.HLE/FileSystem/Content/LocationEntry.cs +++ b/Ryujinx.HLE/FileSystem/LocationEntry.cs @@ -1,6 +1,6 @@ using LibHac.FsSystem; -namespace Ryujinx.HLE.FileSystem.Content +namespace Ryujinx.HLE.FileSystem { public struct LocationEntry { diff --git a/Ryujinx.HLE/FileSystem/SaveDataType.cs b/Ryujinx.HLE/FileSystem/SaveDataType.cs deleted file mode 100644 index 2207fc23..00000000 --- a/Ryujinx.HLE/FileSystem/SaveDataType.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace Ryujinx.HLE.FileSystem -{ - enum SaveDataType : byte - { - SystemSaveData, - SaveData, - BcatDeliveryCacheStorage, - DeviceSaveData, - TemporaryStorage, - CacheStorage - } -}
\ No newline at end of file diff --git a/Ryujinx.HLE/FileSystem/SaveInfo.cs b/Ryujinx.HLE/FileSystem/SaveInfo.cs deleted file mode 100644 index 96f2f020..00000000 --- a/Ryujinx.HLE/FileSystem/SaveInfo.cs +++ /dev/null @@ -1,27 +0,0 @@ -using Ryujinx.HLE.HOS.Services.Account.Acc; - -namespace Ryujinx.HLE.FileSystem -{ - struct SaveInfo - { - public ulong TitleId { get; private set; } - public long SaveId { get; private set; } - public SaveDataType SaveDataType { get; private set; } - public SaveSpaceId SaveSpaceId { get; private set; } - public UserId UserId { get; private set; } - - public SaveInfo( - ulong titleId, - long saveId, - SaveDataType saveDataType, - SaveSpaceId saveSpaceId, - UserId userId = new UserId()) - { - TitleId = titleId; - SaveId = saveId; - SaveDataType = saveDataType; - SaveSpaceId = saveSpaceId; - UserId = userId; - } - } -}
\ No newline at end of file diff --git a/Ryujinx.HLE/FileSystem/SaveSpaceId.cs b/Ryujinx.HLE/FileSystem/SaveSpaceId.cs deleted file mode 100644 index d51922df..00000000 --- a/Ryujinx.HLE/FileSystem/SaveSpaceId.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace Ryujinx.HLE.FileSystem -{ - enum SaveSpaceId - { - NandSystem, - NandUser, - SdCard, - TemporaryStorage - } -} diff --git a/Ryujinx.HLE/FileSystem/StorageId.cs b/Ryujinx.HLE/FileSystem/StorageId.cs deleted file mode 100644 index d4043e2c..00000000 --- a/Ryujinx.HLE/FileSystem/StorageId.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace Ryujinx.HLE.FileSystem -{ - public enum StorageId - { - None, - Host, - GameCard, - NandSystem, - NandUser, - SdCard - } -} diff --git a/Ryujinx.HLE/FileSystem/Content/SystemVersion.cs b/Ryujinx.HLE/FileSystem/SystemVersion.cs index 3f19e135..a7926d5d 100644 --- a/Ryujinx.HLE/FileSystem/Content/SystemVersion.cs +++ b/Ryujinx.HLE/FileSystem/SystemVersion.cs @@ -1,8 +1,7 @@ using Ryujinx.HLE.Utilities; using System.IO; -using System.Text; -namespace Ryujinx.HLE.FileSystem.Content +namespace Ryujinx.HLE.FileSystem { public class SystemVersion { diff --git a/Ryujinx.HLE/FileSystem/VirtualFileSystem.cs b/Ryujinx.HLE/FileSystem/VirtualFileSystem.cs index 9359b03c..001a1f5f 100644 --- a/Ryujinx.HLE/FileSystem/VirtualFileSystem.cs +++ b/Ryujinx.HLE/FileSystem/VirtualFileSystem.cs @@ -13,7 +13,6 @@ using LibHac.Tools.Fs; using LibHac.Tools.FsSystem; using Ryujinx.Common.Configuration; using Ryujinx.Common.Logging; -using Ryujinx.HLE.FileSystem.Content; using Ryujinx.HLE.HOS; using System; using System.Buffers.Text; @@ -28,20 +27,29 @@ namespace Ryujinx.HLE.FileSystem { public class VirtualFileSystem : IDisposable { - public const string NandPath = AppDataManager.DefaultNandDir; - public const string SdCardPath = AppDataManager.DefaultSdcardDir; + public static string SafeNandPath = Path.Combine(AppDataManager.DefaultNandDir, "safe"); + public static string SystemNandPath = Path.Combine(AppDataManager.DefaultNandDir, "system"); + public static string UserNandPath = Path.Combine(AppDataManager.DefaultNandDir, "user"); - public static string SafeNandPath = Path.Combine(NandPath, "safe"); - public static string SystemNandPath = Path.Combine(NandPath, "system"); - public static string UserNandPath = Path.Combine(NandPath, "user"); + public KeySet KeySet { get; private set; } + public EmulatedGameCard GameCard { get; private set; } + public EmulatedSdCard SdCard { get; private set; } + public ModLoader ModLoader { get; private set; } + public Stream RomFs { get; private set; } private static bool _isInitialized = false; - public KeySet KeySet { get; private set; } - public EmulatedGameCard GameCard { get; private set; } - public EmulatedSdCard SdCard { get; private set; } + public static VirtualFileSystem CreateInstance() + { + if (_isInitialized) + { + throw new InvalidOperationException("VirtualFileSystem can only be instantiated once!"); + } - public ModLoader ModLoader { get; private set; } + _isInitialized = true; + + return new VirtualFileSystem(); + } private VirtualFileSystem() { @@ -49,8 +57,6 @@ namespace Ryujinx.HLE.FileSystem ModLoader = new ModLoader(); // Should only be created once } - public Stream RomFs { get; private set; } - public void LoadRomFs(string fileName) { RomFs = new FileStream(fileName, FileMode.Open, FileAccess.Read); @@ -79,7 +85,7 @@ namespace Ryujinx.HLE.FileSystem string fullPath = Path.GetFullPath(Path.Combine(basePath, fileName)); - if (!fullPath.StartsWith(GetBasePath())) + if (!fullPath.StartsWith(AppDataManager.BaseDirPath)) { return null; } @@ -87,14 +93,8 @@ namespace Ryujinx.HLE.FileSystem return fullPath; } - internal string GetBasePath() => AppDataManager.BaseDirPath; - internal string GetSdCardPath() => MakeFullPath(SdCardPath); - public string GetNandPath() => MakeFullPath(NandPath); - - public string GetFullPartitionPath(string partitionPath) - { - return MakeFullPath(partitionPath); - } + internal string GetSdCardPath() => MakeFullPath(AppDataManager.DefaultSdcardDir); + public string GetNandPath() => MakeFullPath(AppDataManager.DefaultNandDir); public string SwitchPathToSystemPath(string switchPath) { @@ -110,7 +110,7 @@ namespace Ryujinx.HLE.FileSystem public string SystemPathToSwitchPath(string systemPath) { - string baseSystemPath = GetBasePath() + Path.DirectorySeparatorChar; + string baseSystemPath = AppDataManager.BaseDirPath + Path.DirectorySeparatorChar; if (systemPath.StartsWith(baseSystemPath)) { @@ -136,8 +136,7 @@ namespace Ryujinx.HLE.FileSystem switch (path) { case ContentPath.SdCard: - case "@Sdcard": - path = SdCardPath; + path = AppDataManager.DefaultSdcardDir; break; case ContentPath.User: path = UserNandPath; @@ -146,7 +145,7 @@ namespace Ryujinx.HLE.FileSystem path = SystemNandPath; break; case ContentPath.SdCardContent: - path = Path.Combine(SdCardPath, "Nintendo", "Contents"); + path = Path.Combine(AppDataManager.DefaultSdcardDir, "Nintendo", "Contents"); break; case ContentPath.UserContent: path = Path.Combine(UserNandPath, "Contents"); @@ -156,27 +155,19 @@ namespace Ryujinx.HLE.FileSystem break; } - string fullPath = Path.Combine(GetBasePath(), path); + string fullPath = Path.Combine(AppDataManager.BaseDirPath, path); - if (isDirectory) + if (isDirectory && !Directory.Exists(fullPath)) { - if (!Directory.Exists(fullPath)) - { - Directory.CreateDirectory(fullPath); - } + Directory.CreateDirectory(fullPath); } return fullPath; } - public DriveInfo GetDrive() - { - return new DriveInfo(Path.GetPathRoot(GetBasePath())); - } - public void InitializeFsServer(LibHac.Horizon horizon, out HorizonClient fsServerClient) { - LocalFileSystem serverBaseFs = new LocalFileSystem(GetBasePath()); + LocalFileSystem serverBaseFs = new LocalFileSystem(AppDataManager.BaseDirPath); fsServerClient = horizon.CreatePrivilegedHorizonClient(); var fsServer = new FileSystemServer(fsServerClient); @@ -505,7 +496,7 @@ namespace Ryujinx.HLE.FileSystem bool canFixBySaveDataId = extraData.Attribute.StaticSaveDataId == 0 && info.StaticSaveDataId != 0; - bool hasEmptyOwnerId = extraData.OwnerId == 0 && info.Type != LibHac.Fs.SaveDataType.System; + bool hasEmptyOwnerId = extraData.OwnerId == 0 && info.Type != SaveDataType.System; if (!canFixByProgramId && !canFixBySaveDataId && !hasEmptyOwnerId) { @@ -523,7 +514,7 @@ namespace Ryujinx.HLE.FileSystem // The rest of the extra data can't be created from the save data info. // On user saves the owner ID will almost certainly be the same as the program ID. - if (info.Type != LibHac.Fs.SaveDataType.System) + if (info.Type != SaveDataType.System) { extraData.OwnerId = info.ProgramId.Value; } @@ -580,11 +571,6 @@ namespace Ryujinx.HLE.FileSystem } }; - public void Unload() - { - RomFs?.Dispose(); - } - public void Dispose() { Dispose(true); @@ -594,20 +580,8 @@ namespace Ryujinx.HLE.FileSystem { if (disposing) { - Unload(); + RomFs?.Dispose(); } } - - public static VirtualFileSystem CreateInstance() - { - if (_isInitialized) - { - throw new InvalidOperationException("VirtualFileSystem can only be instantiated once!"); - } - - _isInitialized = true; - - return new VirtualFileSystem(); - } } }
\ No newline at end of file |