From 575ae4572aadf24af1bfb8a238c83c514b09b4c9 Mon Sep 17 00:00:00 2001 From: "Admiral H. Curtiss" Date: Sun, 2 Nov 2014 06:09:21 +0100 Subject: [PATCH] Delete output if patching fails. --- Program.cs | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/Program.cs b/Program.cs index 0ceaca7..93f9a63 100644 --- a/Program.cs +++ b/Program.cs @@ -6,20 +6,20 @@ using System.Text; namespace WfcPatcher { class Program { static void Main( string[] args ) { - foreach ( string s in args ) { -#if DEBUG -#else + foreach ( string filename in args ) { + string newFilename = System.IO.Path.Combine( System.IO.Path.GetDirectoryName( filename ), System.IO.Path.GetFileNameWithoutExtension( filename ) ) + " (AltWfc)" + System.IO.Path.GetExtension( filename ); +#if !DEBUG try { #endif - string newFilename = PatchFile( s ); + PatchFile( filename, newFilename ); Console.WriteLine( "Patched to " + newFilename + "!" ); Console.WriteLine(); -#if DEBUG -#else +#if !DEBUG } catch ( Exception ex ) { - Console.WriteLine( "Failed patching " + s ); + Console.WriteLine( "Failed patching " + filename ); Console.WriteLine( ex.ToString() ); Console.WriteLine(); + System.IO.File.Delete( newFilename ); } #endif } @@ -33,10 +33,9 @@ namespace WfcPatcher { return gamecode; } - static string PatchFile( string filename ) { + static void PatchFile( string filename, string newFilename ) { Console.WriteLine( "Reading and copying " + filename + "..." ); var ndsSrc = new System.IO.FileStream( filename, System.IO.FileMode.Open ); - string newFilename = System.IO.Path.Combine( System.IO.Path.GetDirectoryName( filename ), System.IO.Path.GetFileNameWithoutExtension( filename ) ) + " (AltWfc)" + System.IO.Path.GetExtension( filename ); var nds = new System.IO.FileStream( newFilename, System.IO.FileMode.Create ); Util.CopyStream( ndsSrc, nds, (int)ndsSrc.Length ); ndsSrc.Close(); @@ -70,8 +69,6 @@ namespace WfcPatcher { PatchOverlay( nds, arm7overlayoff, arm7overlaylen ); nds.Close(); - - return newFilename; } static void PatchArm9( System.IO.FileStream nds, uint pos, uint len ) {