LibHac/hactoolnet/ProcessRomfs.cs
Alex Barney 3d50085e22
Use Storage throughout the library instead of Stream (#18)
*Create an IStorage interface and Storage abstract class to use instead of Stream

* Improve AES-XTS performance by ~16x

* Double AES-CTR performance: 800 MB/s -> 1600 MB/s on a 6700K

* Add AES-XTS tests

* Add AES benchmark and AES-CTR writing

* Add support for a hashed FAT in save files

* Add option to export decrypted NCA

* Allow opening decrypted package1 and package2

* Make sure romfs disposal can cascade all the way down

* Validate NCA, NPDM and package2 signatures
2018-11-18 23:20:34 -05:00

43 lines
1.2 KiB
C#

using System.IO;
using LibHac;
using LibHac.IO;
namespace hactoolnet
{
internal static class ProcessRomfs
{
public static void Process(Context ctx)
{
using (var file = new FileStream(ctx.Options.InFile, FileMode.Open, FileAccess.Read))
{
var romfs = new Romfs(file.AsStorage());
Process(ctx, romfs);
}
}
public static void Process(Context ctx, Romfs romfs)
{
if (ctx.Options.ListRomFs)
{
foreach (RomfsFile romfsFile in romfs.Files)
{
ctx.Logger.LogMessage(romfsFile.FullPath);
}
}
if (ctx.Options.RomfsOut != null)
{
using (var outFile = new FileStream(ctx.Options.RomfsOut, FileMode.Create, FileAccess.ReadWrite))
{
IStorage romfsStorage = romfs.OpenRawStream();
romfsStorage.CopyToStream(outFile, romfsStorage.Length, ctx.Logger);
}
}
if (ctx.Options.RomfsOutDir != null)
{
romfs.Extract(ctx.Options.RomfsOutDir, ctx.Logger);
}
}
}
}