From 41b9f3088ed665faf5aefc7cc62d18d076c90074 Mon Sep 17 00:00:00 2001 From: Somebody Whoisbored Date: Sun, 17 Feb 2019 18:49:00 -0700 Subject: [PATCH] Package2 opening and various tweaks (#35) * Add package2 opening to LibHac.Nand * Add utility methods for enumerating FileSystems --- src/LibHac.Nand/FatFileSystemProvider.cs | 2 +- src/LibHac.Nand/Nand.cs | 17 ++++++++++++++++- src/LibHac/IO/FileSystemExtensions.cs | 12 +++++++++++- src/LibHac/Keyset.cs | 11 ++++++++--- 4 files changed, 36 insertions(+), 6 deletions(-) diff --git a/src/LibHac.Nand/FatFileSystemProvider.cs b/src/LibHac.Nand/FatFileSystemProvider.cs index 9a1e9f9f..e7539111 100644 --- a/src/LibHac.Nand/FatFileSystemProvider.cs +++ b/src/LibHac.Nand/FatFileSystemProvider.cs @@ -45,7 +45,7 @@ namespace LibHac.Nand { path = ToDiscUtilsPath(PathTools.Normalize(path)); - if (path == @"\\") return true; + if (path == @"\") return true; return Fs.DirectoryExists(path); } diff --git a/src/LibHac.Nand/Nand.cs b/src/LibHac.Nand/Nand.cs index ae02b956..23334077 100644 --- a/src/LibHac.Nand/Nand.cs +++ b/src/LibHac.Nand/Nand.cs @@ -12,6 +12,7 @@ namespace LibHac.Nand { private GuidPartitionInfo ProdInfo { get; } private GuidPartitionInfo ProdInfoF { get; } + private GuidPartitionInfo[] Package2 { get; } private GuidPartitionInfo Safe { get; } private GuidPartitionInfo System { get; } private GuidPartitionInfo User { get; } @@ -23,6 +24,15 @@ namespace LibHac.Nand GuidPartitionInfo[] partitions = disc.Partitions.Select(x => (GuidPartitionInfo)x).ToArray(); ProdInfo = partitions.FirstOrDefault(x => x.Name == "PRODINFO"); ProdInfoF = partitions.FirstOrDefault(x => x.Name == "PRODINFOF"); + Package2 = new GuidPartitionInfo[] + { + partitions.FirstOrDefault(x => x.Name == "BCPKG2-1-Normal-Main"), + partitions.FirstOrDefault(x => x.Name == "BCPKG2-2-Normal-Sub"), + partitions.FirstOrDefault(x => x.Name == "BCPKG2-3-SafeMode-Main"), + partitions.FirstOrDefault(x => x.Name == "BCPKG2-4-SafeMode-Sub"), + partitions.FirstOrDefault(x => x.Name == "BCPKG2-5-Repair-Main"), + partitions.FirstOrDefault(x => x.Name == "BCPKG2-6-Repair-Sub") + }; Safe = partitions.FirstOrDefault(x => x.Name == "SAFE"); System = partitions.FirstOrDefault(x => x.Name == "SYSTEM"); User = partitions.FirstOrDefault(x => x.Name == "USER"); @@ -44,6 +54,11 @@ namespace LibHac.Nand return new FatFileSystemProvider(fat); } + public IStorage OpenPackage2(int index) + { + return Package2[index].Open().AsStorage().AsReadOnly(); + } + public FatFileSystemProvider OpenSafePartition() { IStorage encStorage = Safe.Open().AsStorage(); @@ -68,4 +83,4 @@ namespace LibHac.Nand return new FatFileSystemProvider(fat); } } -} +} \ No newline at end of file diff --git a/src/LibHac/IO/FileSystemExtensions.cs b/src/LibHac/IO/FileSystemExtensions.cs index 553b8667..1fab500d 100644 --- a/src/LibHac/IO/FileSystemExtensions.cs +++ b/src/LibHac/IO/FileSystemExtensions.cs @@ -61,7 +61,17 @@ namespace LibHac.IO public static IEnumerable EnumerateEntries(this IFileSystem fileSystem) { - return fileSystem.OpenDirectory("/", OpenDirectoryMode.All).EnumerateEntries("*", SearchOptions.RecurseSubdirectories); + return fileSystem.EnumerateEntries("*"); + } + + public static IEnumerable EnumerateEntries(this IFileSystem fileSystem, string searchPattern) + { + return fileSystem.EnumerateEntries(searchPattern, SearchOptions.RecurseSubdirectories); + } + + public static IEnumerable EnumerateEntries(this IFileSystem fileSystem, string searchPattern, SearchOptions searchOptions) + { + return fileSystem.OpenDirectory("/", OpenDirectoryMode.All).EnumerateEntries(searchPattern, searchOptions); } public static IEnumerable EnumerateEntries(this IDirectory directory) diff --git a/src/LibHac/Keyset.cs b/src/LibHac/Keyset.cs index fd4999a2..e8ea15ef 100644 --- a/src/LibHac/Keyset.cs +++ b/src/LibHac/Keyset.cs @@ -343,14 +343,19 @@ namespace LibHac AllKeyDict = uniqueKeys.Concat(commonKeys).ToDictionary(k => k.Name, k => k); } - public static Keyset ReadKeyFile(string filename, string titleKeysFilename = null, string consoleKeysFilename = null, IProgressReport logger = null) + public static void ReadKeyFile(Keyset keyset, string filename, string titleKeysFilename = null, string consoleKeysFilename = null, IProgressReport logger = null) { - var keyset = new Keyset(); - if (filename != null) ReadMainKeys(keyset, filename, AllKeyDict, logger); if (consoleKeysFilename != null) ReadMainKeys(keyset, consoleKeysFilename, AllKeyDict, logger); if (titleKeysFilename != null) ReadTitleKeys(keyset, titleKeysFilename, logger); keyset.DeriveKeys(logger); + } + + public static Keyset ReadKeyFile(string filename, string titleKeysFilename = null, string consoleKeysFilename = null, IProgressReport logger = null) + { + var keyset = new Keyset(); + + ReadKeyFile(keyset, filename, titleKeysFilename, consoleKeysFilename, logger); return keyset; }