From ff1e5ff0837f6fb8b3ee4ede235f85aec289608d Mon Sep 17 00:00:00 2001 From: emmaus Date: Tue, 6 Nov 2018 18:28:31 +0000 Subject: [PATCH] use switch style paths for contentpath --- .../FileSystem/Content/ContentManager.cs | 71 ++++++++++++------- .../FileSystem/Content/LocationHelper.cs | 12 ++-- Ryujinx.HLE/HOS/Font/SharedFontManager.cs | 8 ++- .../HOS/Services/FspSrv/IFileSystemProxy.cs | 16 ++--- .../HOS/Services/Lr/ILocationResolver.cs | 4 +- .../HOS/Services/Set/ISystemSettingsServer.cs | 8 ++- 6 files changed, 67 insertions(+), 52 deletions(-) diff --git a/Ryujinx.HLE/FileSystem/Content/ContentManager.cs b/Ryujinx.HLE/FileSystem/Content/ContentManager.cs index 93c5472de4..d112d4f392 100644 --- a/Ryujinx.HLE/FileSystem/Content/ContentManager.cs +++ b/Ryujinx.HLE/FileSystem/Content/ContentManager.cs @@ -42,20 +42,23 @@ namespace Ryujinx.HLE.FileSystem.Content foreach (StorageId StorageId in Enum.GetValues(typeof(StorageId))) { - string ContentInstallationDirectory = null; - string ContentPathString = null; + string ContentDirectory = null; + string ContentPathString = null; + string RegisteredDirectory = null; try { - ContentPathString = LocationHelper.GetContentPath(StorageId); - ContentInstallationDirectory = LocationHelper.GetRealPath(Device.FileSystem, ContentPathString); + ContentPathString = LocationHelper.GetContentRoot(StorageId); + ContentDirectory = LocationHelper.GetRealPath(Device.FileSystem, ContentPathString); + + RegisteredDirectory = Path.Combine(ContentDirectory, "registered"); } catch (NotSupportedException NEx) { continue; } - Directory.CreateDirectory(ContentInstallationDirectory); + Directory.CreateDirectory(RegisteredDirectory); LinkedList LocationList = new LinkedList(); @@ -64,7 +67,7 @@ namespace Ryujinx.HLE.FileSystem.Content LocationList.AddLast(Entry); } - foreach (string DirectoryPath in Directory.EnumerateDirectories(ContentInstallationDirectory)) + foreach (string DirectoryPath in Directory.EnumerateDirectories(RegisteredDirectory)) { if (Directory.GetFiles(DirectoryPath).Length > 0) { @@ -74,7 +77,13 @@ namespace Ryujinx.HLE.FileSystem.Content { Nca Nca = new Nca(Device.System.KeySet, NcaFile, false); - LocationEntry Entry = new LocationEntry(ContentPathString, + string SwitchPath = Path.Combine(ContentPathString + ":", + NcaFile.Name.Replace(ContentDirectory, string.Empty).TrimStart('\\')); + + // Change path format to switch's + SwitchPath = SwitchPath.Replace('\\', '/'); + + LocationEntry Entry = new LocationEntry(SwitchPath, 0, (long)Nca.Header.TitleId, Nca.Header.ContentType); @@ -93,7 +102,7 @@ namespace Ryujinx.HLE.FileSystem.Content } } - foreach (string FilePath in Directory.EnumerateFiles(ContentInstallationDirectory)) + foreach (string FilePath in Directory.EnumerateFiles(ContentDirectory)) { if (Path.GetExtension(FilePath) == ".nca") { @@ -103,7 +112,13 @@ namespace Ryujinx.HLE.FileSystem.Content { Nca Nca = new Nca(Device.System.KeySet, NcaFile, false); - LocationEntry Entry = new LocationEntry(ContentPathString, + string SwitchPath = Path.Combine(ContentPathString + ":", + FilePath.Replace(ContentDirectory, string.Empty).TrimStart('\\')); + + // Change path format to switch's + SwitchPath = SwitchPath.Replace('\\', '/'); + + LocationEntry Entry = new LocationEntry(SwitchPath, 0, (long)Nca.Header.TitleId, Nca.Header.ContentType); @@ -157,6 +172,24 @@ namespace Ryujinx.HLE.FileSystem.Content } } + public bool HasNca(string NcaId, StorageId StorageId) + { + if (ContentDictionary.ContainsValue(NcaId)) + { + var Content = ContentDictionary.FirstOrDefault(x => x.Value == NcaId); + + long TitleId = (long)Content.Key.Item1; + + ContentType ContentType = Content.Key.Item2; + + StorageId Storage = GetInstalledStorage(TitleId, ContentType, StorageId); + + return Storage == StorageId; + } + + return false; + } + public UInt128 GetInstalledNcaId(long TitleId, ContentType ContentType) { if (ContentDictionary.ContainsKey(((ulong)TitleId,ContentType))) @@ -167,22 +200,6 @@ namespace Ryujinx.HLE.FileSystem.Content return new UInt128(); } - public string GetInstalledPath(long TitleId, ContentType ContentType, StorageId StorageId) - { - LocationEntry LocationEntry = GetLocation(TitleId, ContentType, StorageId); - - string ContentPath = LocationHelper.GetRealPath(Device.FileSystem, LocationEntry.ContentPath); - - string NcaPath = Path.Combine(ContentPath, ContentDictionary[((ulong)TitleId, ContentType)]) + ".nca"; - - if (!File.Exists(NcaPath)) - { - NcaPath = Path.Combine(NcaPath, "00"); - } - - return NcaPath; - } - public StorageId GetInstalledStorage(long TitleId, ContentType ContentType, StorageId StorageId) { LocationEntry LocationEntry = GetLocation(TitleId, ContentType, StorageId); @@ -191,7 +208,7 @@ namespace Ryujinx.HLE.FileSystem.Content LocationHelper.GetStorageId(LocationEntry.ContentPath) : StorageId.None; } - public string GetInstalledContentStorage(long TitleId, StorageId StorageId, ContentType ContentType) + public string GetInstalledContentPath(long TitleId, StorageId StorageId, ContentType ContentType) { LocationEntry LocationEntry = GetLocation(TitleId, ContentType, StorageId); @@ -219,7 +236,7 @@ namespace Ryujinx.HLE.FileSystem.Content { StorageId StorageId = LocationHelper.GetStorageId(LocationEntry.ContentPath); - string InstalledPath = GetInstalledPath(LocationEntry.TitleId, ContentType, StorageId); + string InstalledPath = Device.FileSystem.SwitchPathToSystemPath(LocationEntry.ContentPath); if (!string.IsNullOrWhiteSpace(InstalledPath)) { diff --git a/Ryujinx.HLE/FileSystem/Content/LocationHelper.cs b/Ryujinx.HLE/FileSystem/Content/LocationHelper.cs index da020a848e..d011de2f96 100644 --- a/Ryujinx.HLE/FileSystem/Content/LocationHelper.cs +++ b/Ryujinx.HLE/FileSystem/Content/LocationHelper.cs @@ -14,11 +14,11 @@ namespace Ryujinx.HLE.FileSystem.Content switch (SwitchContentPath) { case ContentPath.SystemContent: - return Path.Combine(FileSystem.GetBasePath(), SystemNandPath, "Contents", "registered"); + return Path.Combine(FileSystem.GetBasePath(), SystemNandPath, "Contents"); case ContentPath.UserContent: - return Path.Combine(FileSystem.GetBasePath(), UserNandPath, "Contents", "registered"); + return Path.Combine(FileSystem.GetBasePath(), UserNandPath, "Contents"); case ContentPath.SdCardContent: - return Path.Combine(FileSystem.GetSdCardPath(), "Nintendo", "Contents", "registered"); + return Path.Combine(FileSystem.GetSdCardPath(), "Nintendo", "Contents"); case ContentPath.System: return Path.Combine(BasePath, SystemNandPath); case ContentPath.User: @@ -43,7 +43,7 @@ namespace Ryujinx.HLE.FileSystem.Content } } - public static string GetContentPath(StorageId StorageId) + public static string GetContentRoot(StorageId StorageId) { switch (StorageId) { @@ -60,7 +60,9 @@ namespace Ryujinx.HLE.FileSystem.Content public static StorageId GetStorageId(string ContentPathString) { - switch (ContentPathString) + string CleanedPath = ContentPathString.Split(':')[0]; + + switch (CleanedPath) { case ContentPath.SystemContent: case ContentPath.System: diff --git a/Ryujinx.HLE/HOS/Font/SharedFontManager.cs b/Ryujinx.HLE/HOS/Font/SharedFontManager.cs index d7267c30d5..5005fc356f 100644 --- a/Ryujinx.HLE/HOS/Font/SharedFontManager.cs +++ b/Ryujinx.HLE/HOS/Font/SharedFontManager.cs @@ -54,9 +54,11 @@ namespace Ryujinx.HLE.HOS.Font { if (ContentManager.TryGetFontTitle(Name, out long FontTitle)) { - string FontContentPath = ContentManager.GetInstalledPath(FontTitle, ContentType.Data, StorageId.NandSystem); + string ContentPath = ContentManager.GetInstalledContentPath(FontTitle, StorageId.NandSystem, ContentType.Data); - if (!string.IsNullOrWhiteSpace(FontContentPath)) + string FontPath = Device.FileSystem.SwitchPathToSystemPath(ContentPath); + + if (!string.IsNullOrWhiteSpace(FontPath)) { int FileIndex = 0; @@ -66,7 +68,7 @@ namespace Ryujinx.HLE.HOS.Font FileIndex = 1; } - FileStream NcaFileStream = new FileStream(FontContentPath, FileMode.Open, FileAccess.Read); + FileStream NcaFileStream = new FileStream(FontPath, FileMode.Open, FileAccess.Read); Nca Nca = new Nca(Device.System.KeySet, NcaFileStream, false); diff --git a/Ryujinx.HLE/HOS/Services/FspSrv/IFileSystemProxy.cs b/Ryujinx.HLE/HOS/Services/FspSrv/IFileSystemProxy.cs index 9efd214b42..d270489595 100644 --- a/Ryujinx.HLE/HOS/Services/FspSrv/IFileSystemProxy.cs +++ b/Ryujinx.HLE/HOS/Services/FspSrv/IFileSystemProxy.cs @@ -160,21 +160,13 @@ namespace Ryujinx.HLE.HOS.Services.FspSrv if (InstalledStorage != StorageId.None) { - string InstallPath = - Context.Device.System.ContentManager.GetInstalledPath(TitleId, ContentType.AocData, StorageId); + string ContentPath = Context.Device.System.ContentManager.GetInstalledContentPath(TitleId, StorageId, ContentType.AocData); - UInt128 NcaId = Context.Device.System.ContentManager.GetInstalledNcaId(TitleId, ContentType.AocData); - - if (string.IsNullOrWhiteSpace(InstallPath)) + if (string.IsNullOrWhiteSpace(ContentPath)) { - InstallPath = - Context.Device.System.ContentManager.GetInstalledPath(TitleId, ContentType.Data, StorageId); - } - - if ((NcaId.High | NcaId.Low) == 0) - { - NcaId = Context.Device.System.ContentManager.GetInstalledNcaId(TitleId, ContentType.Data); + ContentPath = Context.Device.System.ContentManager.GetInstalledContentPath(TitleId, StorageId, ContentType.AocData); } + string InstallPath = Context.Device.FileSystem.SwitchPathToSystemPath(ContentPath); if (!string.IsNullOrWhiteSpace(InstallPath)) { diff --git a/Ryujinx.HLE/HOS/Services/Lr/ILocationResolver.cs b/Ryujinx.HLE/HOS/Services/Lr/ILocationResolver.cs index 4a50fc18f8..57320288c7 100644 --- a/Ryujinx.HLE/HOS/Services/Lr/ILocationResolver.cs +++ b/Ryujinx.HLE/HOS/Services/Lr/ILocationResolver.cs @@ -221,7 +221,7 @@ namespace Ryujinx.HLE.HOS.Services.Lr { ContentManager ContentManager = Context.Device.System.ContentManager; - string ContentPath = ContentManager.GetInstalledContentStorage(TitleId, StorageId, ContentType.Program); + string ContentPath = ContentManager.GetInstalledContentPath(TitleId, StorageId, ContentType.Program); if (!string.IsNullOrWhiteSpace(ContentPath)) { @@ -244,7 +244,7 @@ namespace Ryujinx.HLE.HOS.Services.Lr { ContentManager ContentManager = Context.Device.System.ContentManager; - string ContentPath = ContentManager.GetInstalledContentStorage(TitleId, StorageId, ContentType.Manual); + string ContentPath = ContentManager.GetInstalledContentPath(TitleId, StorageId, ContentType.Manual); ContentManager.ClearEntry(TitleId, ContentType.Manual, StorageId); } diff --git a/Ryujinx.HLE/HOS/Services/Set/ISystemSettingsServer.cs b/Ryujinx.HLE/HOS/Services/Set/ISystemSettingsServer.cs index eb5adfc2af..c3c6f996fd 100644 --- a/Ryujinx.HLE/HOS/Services/Set/ISystemSettingsServer.cs +++ b/Ryujinx.HLE/HOS/Services/Set/ISystemSettingsServer.cs @@ -172,14 +172,16 @@ namespace Ryujinx.HLE.HOS.Services.Set long TitleId = 0x0100000000000809; - string Path = Device.System.ContentManager.GetInstalledPath(TitleId, ContentType.Data, StorageId.NandSystem); + string ContentPath = Device.System.ContentManager.GetInstalledContentPath(TitleId, StorageId.NandSystem, ContentType.Data); - if(string.IsNullOrWhiteSpace(Path)) + if(string.IsNullOrWhiteSpace(ContentPath)) { return null; } - FileStream FirmwareStream = File.Open(Path, FileMode.Open, FileAccess.Read); + string FirmwareTitlePath = Device.FileSystem.SwitchPathToSystemPath(ContentPath); + + FileStream FirmwareStream = File.Open(FirmwareTitlePath, FileMode.Open, FileAccess.Read); Nca FirmwareContent = new Nca(Device.System.KeySet, FirmwareStream, false);