Package2 opening and various tweaks (#35)

* Add package2 opening to LibHac.Nand
* Add utility methods for enumerating FileSystems
This commit is contained in:
Somebody Whoisbored 2019-02-17 18:49:00 -07:00 committed by Alex Barney
parent 632d508e40
commit 41b9f3088e
4 changed files with 36 additions and 6 deletions

View file

@ -45,7 +45,7 @@ namespace LibHac.Nand
{
path = ToDiscUtilsPath(PathTools.Normalize(path));
if (path == @"\\") return true;
if (path == @"\") return true;
return Fs.DirectoryExists(path);
}

View file

@ -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);
}
}
}
}

View file

@ -61,7 +61,17 @@ namespace LibHac.IO
public static IEnumerable<DirectoryEntry> EnumerateEntries(this IFileSystem fileSystem)
{
return fileSystem.OpenDirectory("/", OpenDirectoryMode.All).EnumerateEntries("*", SearchOptions.RecurseSubdirectories);
return fileSystem.EnumerateEntries("*");
}
public static IEnumerable<DirectoryEntry> EnumerateEntries(this IFileSystem fileSystem, string searchPattern)
{
return fileSystem.EnumerateEntries(searchPattern, SearchOptions.RecurseSubdirectories);
}
public static IEnumerable<DirectoryEntry> EnumerateEntries(this IFileSystem fileSystem, string searchPattern, SearchOptions searchOptions)
{
return fileSystem.OpenDirectory("/", OpenDirectoryMode.All).EnumerateEntries(searchPattern, searchOptions);
}
public static IEnumerable<DirectoryEntry> EnumerateEntries(this IDirectory directory)

View file

@ -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;
}