Add romfs support to CLI

This commit is contained in:
Alex Barney 2018-08-28 12:33:24 -05:00
parent 9276a213bc
commit 38dca5c526
2 changed files with 40 additions and 0 deletions

View file

@ -36,6 +36,7 @@ namespace hactoolnet
case FileType.Pfs0: case FileType.Pfs0:
break; break;
case FileType.Romfs: case FileType.Romfs:
ProcessRomFs(ctx);
break; break;
case FileType.Nax0: case FileType.Nax0:
break; break;
@ -367,6 +368,43 @@ namespace hactoolnet
} }
} }
private static void ProcessRomFs(Context ctx)
{
using (var file = new FileStream(ctx.Options.InFile, FileMode.Open, FileAccess.Read))
{
var romfs = new Romfs(file);
ProcessRomFs(ctx, romfs);
}
}
private static void ProcessRomFs(Context ctx, Romfs romfs)
{
using (var file = new FileStream(ctx.Options.InFile, FileMode.Open, FileAccess.Read))
{
if (ctx.Options.ListRomFs)
{
foreach (var 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))
{
var romfsStream = romfs.OpenRawStream();
romfsStream.CopyStream(outFile, romfsStream.Length, ctx.Logger);
}
}
if (ctx.Options.RomfsOutDir != null)
{
romfs.Extract(ctx.Options.RomfsOutDir, ctx.Logger);
}
}
}
private static Nca GetXciMainNca(Xci xci, Context ctx) private static Nca GetXciMainNca(Xci xci, Context ctx)
{ {
if (xci.SecurePartition == null) if (xci.SecurePartition == null)

View file

@ -90,6 +90,8 @@ namespace libhac
public bool FileExists(string filename) => FileDict.ContainsKey(filename); public bool FileExists(string filename) => FileDict.ContainsKey(filename);
public Stream OpenRawStream() => StreamSource.CreateStream();
private void SetReferences() private void SetReferences()
{ {
var dirDict = Directories.ToDictionary(x => x.Offset, x => x); var dirDict = Directories.ToDictionary(x => x.Offset, x => x);