From 043667164648485b774667c00ce9d87cb37f4019 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Mon, 28 Mar 2016 18:23:49 -0700 Subject: [PATCH] Enable saving of the extracted header --- Deheader/Deheader.cs | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/Deheader/Deheader.cs b/Deheader/Deheader.cs index 06f3a7f9..4a9ba24b 100644 --- a/Deheader/Deheader.cs +++ b/Deheader/Deheader.cs @@ -9,7 +9,8 @@ namespace WoD class Deheader { private static Dictionary types; - private static string help = @"Deheader.exe filename|dirname"; + private static bool save; + private static string help = @"Deheader.exe [-s] filename|dirname"; static void Main(string[] args) { @@ -21,14 +22,25 @@ namespace WoD types.Add("nes", 16); types.Add("snes", 512); - if (args.Length != 1) + if (args.Length == 0 || args.Length > 2) { Console.WriteLine(help); return; } // Get the filename (or foldername) - string file = args[0]; + string file = ""; + if (args.Length == 1) + { + file = args[0]; + save = false; + } + else + { + file = args[1]; + save = true; + } + // If it's a single file, just check it if (File.Exists(file)) @@ -92,6 +104,18 @@ namespace WoD Console.WriteLine("Deteched header type: " + type); int hs = types[type]; + // Write out the header if we're saving it + if (save) + { + Console.WriteLine("Writing header to file: " + file + ".header"); + BinaryWriter bwh = new BinaryWriter(File.OpenWrite(file + ".header")); + for (int i = 0; i < hs; i++) + { + bwh.Write(hbin[i]); + } + bwh.Close(); + } + // Get the bytes that aren't from the header from the extracted bit so they can be written before the rest of the file hbin = hbin.Skip(hs).ToArray();