From 38dca5c526bfd06b65b7b22e33b93b2693092061 Mon Sep 17 00:00:00 2001 From: Alex Barney Date: Tue, 28 Aug 2018 12:33:24 -0500 Subject: [PATCH] Add romfs support to CLI --- hactoolnet/Program.cs | 38 ++++++++++++++++++++++++++++++++++++++ libhac/Romfs.cs | 2 ++ 2 files changed, 40 insertions(+) diff --git a/hactoolnet/Program.cs b/hactoolnet/Program.cs index 04ce6d9b..6c192c9d 100644 --- a/hactoolnet/Program.cs +++ b/hactoolnet/Program.cs @@ -36,6 +36,7 @@ namespace hactoolnet case FileType.Pfs0: break; case FileType.Romfs: + ProcessRomFs(ctx); break; case FileType.Nax0: 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) { if (xci.SecurePartition == null) diff --git a/libhac/Romfs.cs b/libhac/Romfs.cs index 9602c772..7a2e0320 100644 --- a/libhac/Romfs.cs +++ b/libhac/Romfs.cs @@ -90,6 +90,8 @@ namespace libhac public bool FileExists(string filename) => FileDict.ContainsKey(filename); + public Stream OpenRawStream() => StreamSource.CreateStream(); + private void SetReferences() { var dirDict = Directories.ToDictionary(x => x.Offset, x => x);