diff --git a/Patcher/PatchGenerator/App.xaml b/Patcher/PatchGenerator/App.xaml index 601179f..3341652 100644 --- a/Patcher/PatchGenerator/App.xaml +++ b/Patcher/PatchGenerator/App.xaml @@ -2,7 +2,8 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:PatchGenerator" - StartupUri="MainWindow.xaml"> + StartupUri="MainWindow.xaml" + Startup="Application_Startup"> diff --git a/Patcher/PatchGenerator/App.xaml.cs b/Patcher/PatchGenerator/App.xaml.cs index eb4c3a1..b842762 100644 --- a/Patcher/PatchGenerator/App.xaml.cs +++ b/Patcher/PatchGenerator/App.xaml.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Configuration; -using System.Data; -using System.Linq; -using System.Threading.Tasks; -using System.Windows; +using System.Windows; namespace PatchGenerator { @@ -13,5 +7,34 @@ namespace PatchGenerator /// public partial class App : Application { + private void Application_Startup(object sender, StartupEventArgs e) + { + GenStartupArgs startupArgs = null; + + if (e.Args != null && e.Args.Length > 0) + { + if(e.Args[0].ToLower() == "help") + { + System.Text.StringBuilder sb = new System.Text.StringBuilder() + .AppendLine("Help - Shows this message box if in position 1") + .AppendLine("") + .AppendLine("Parameters below can be used like this: \"Name::Value\"") + .AppendLine("OutputFolderName - The output file for the patch") + .AppendLine("TargetFolderPath - The target folder path") + .AppendLine("CompareFolderPath - The compare folder path") + .AppendLine("AutoZip - Set if the output folder should be zipped up after patch generation. Defaults to true"); + + MessageBox.Show(sb.ToString(), "Parameter Help Info", MessageBoxButton.OK, MessageBoxImage.Information); + + Application.Current.Shutdown(0); + } + + startupArgs = GenStartupArgs.Parse(e.Args); + } + + MainWindow mw = new MainWindow(startupArgs); + + mw.ShowDialog(); + } } } diff --git a/Patcher/PatchGenerator/GenStartupArgs.cs b/Patcher/PatchGenerator/GenStartupArgs.cs new file mode 100644 index 0000000..f126dee --- /dev/null +++ b/Patcher/PatchGenerator/GenStartupArgs.cs @@ -0,0 +1,67 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PatchGenerator +{ + public class GenStartupArgs + { + public bool ReadyToRun => OutputFolderName != "" && CompareFolderPath != "" && TargetFolderPath != ""; + public string OutputFolderName { get; private set; } = ""; + public string CompareFolderPath { get; private set; } = ""; + public string TargetFolderPath { get; private set; } = ""; + public bool AutoZip { get; private set; } = true; + protected GenStartupArgs(string OutputFolderName, string CompareFolderPath, string TargetFolderPath, bool AutoZip) + { + this.OutputFolderName = OutputFolderName; + this.CompareFolderPath = CompareFolderPath; + this.TargetFolderPath = TargetFolderPath; + this.AutoZip = AutoZip; + } + + public static GenStartupArgs Parse(string[] Args) + { + if (Args == null || Args.Length == 0) return null; + + string ofn = ""; + string cfp = ""; + string tfp = ""; + bool az = true; + + foreach(string arg in Args) + { + if (arg.Split("::").Length != 2) return null; + + var argSplit = arg.Split("::"); + + switch(argSplit[0]) + { + case "OutputFolderName": + { + ofn = argSplit[1]; + break; + } + case "CompareFolderPath": + { + cfp = argSplit[1]; + break; + } + case "TargetFolderPath": + { + tfp = argSplit[1]; + break; + } + case "AutoZip": + { + az = bool.Parse(argSplit[1]); + break; + } + } + } + + return new GenStartupArgs(ofn, cfp, tfp, az); + } + } +} diff --git a/Patcher/PatchGenerator/MainWindow.xaml.cs b/Patcher/PatchGenerator/MainWindow.xaml.cs index 0431190..47eb5dc 100644 --- a/Patcher/PatchGenerator/MainWindow.xaml.cs +++ b/Patcher/PatchGenerator/MainWindow.xaml.cs @@ -27,6 +27,35 @@ namespace PatchGenerator InitializeComponent(); } + public MainWindow(GenStartupArgs startupArgs = null) + { + InitializeComponent(); + + if (startupArgs == null) return; + + FileNameBox.Text = startupArgs.OutputFolderName; + if (startupArgs.CompareFolderPath != "") + { + compareFolder = startupArgs.CompareFolderPath; + CompareLabel.Content = $"Compare Folder:\n{compareFolder}"; + CompareLabel.BorderBrush = Brushes.DarkCyan; + } + + if (startupArgs.TargetFolderPath != "") + { + targetFolder = startupArgs.TargetFolderPath; + TargetLabel.Content = $"Target Folder:\n{targetFolder}"; + TargetLabel.BorderBrush = Brushes.DarkCyan; + } + + AutoZip = startupArgs.AutoZip; + + if (startupArgs.ReadyToRun) + { + GenButton_Click(null, null); + } + } + private string GetStopWatchTime() { return $"Hours: {stopwatch.Elapsed.Hours} - Mins: {stopwatch.Elapsed.Minutes} - Secs: {stopwatch.Elapsed.Seconds} - MilliSecs: {stopwatch.Elapsed.Milliseconds}";