From 9738752b82d6fc4dcb62bf80da625064b2b33006 Mon Sep 17 00:00:00 2001 From: Miepee Date: Sun, 24 Jul 2022 22:27:57 +0200 Subject: [PATCH] Small misc cleaning --- AM2RPortHelperCLI/Program.cs | 6 ++--- .../AM2RPortHelperGUI.Gtk/Program.cs | 2 +- .../AM2RPortHelperGUI.Mac/Program.cs | 2 +- .../AM2RPortHelperGUI.Wpf/Program.cs | 2 +- .../AM2RPortHelperGUI/MainForm.cs | 27 ++++++++++--------- 5 files changed, 20 insertions(+), 19 deletions(-) diff --git a/AM2RPortHelperCLI/Program.cs b/AM2RPortHelperCLI/Program.cs index f5254c9..14a8082 100644 --- a/AM2RPortHelperCLI/Program.cs +++ b/AM2RPortHelperCLI/Program.cs @@ -1,6 +1,5 @@ using System; using System.CommandLine; -using System.CommandLine.Builder; using System.IO; using AM2RPortHelperLib; @@ -14,8 +13,7 @@ internal static class Program private static int Main(string[] args) { Console.WriteLine("AM2RPortHelperCLI v" + PortHelper.Version); - - //TODO! + var interactiveOption = new Option(new[] { "-i", "--interactive" }, "Use an interactive mode. This will ignore all other options."); var fileOption = new Option(new[] { "-f", "--file" }, "The file path to the raw mod that should be ported. *REQUIRED*"); var linuxOption = new Option(new[] { "-l", "--linux" }, "The output file path for the Linux mod. None given equals to no Linux port."); @@ -23,7 +21,7 @@ internal static class Program var macOption = new Option(new[] { "-m", "--mac" }, "The output file path for the Mac mod. None given equals to no Mac port."); var nameOption = new Option(new[] { "-n", "--name" }, "The name used for the Mac mod. Required for the Mac option, has no effect on anything else."); - RootCommand rootCommand = new RootCommand() + RootCommand rootCommand = new RootCommand { interactiveOption, fileOption, diff --git a/AM2RPortHelperGUI/AM2RPortHelperGUI.Gtk/Program.cs b/AM2RPortHelperGUI/AM2RPortHelperGUI.Gtk/Program.cs index 8305e28..3770970 100644 --- a/AM2RPortHelperGUI/AM2RPortHelperGUI.Gtk/Program.cs +++ b/AM2RPortHelperGUI/AM2RPortHelperGUI.Gtk/Program.cs @@ -3,7 +3,7 @@ using Eto.Forms; namespace AM2RPortHelperGUI.Gtk; -class Program +static class Program { [STAThread] public static void Main(string[] args) diff --git a/AM2RPortHelperGUI/AM2RPortHelperGUI.Mac/Program.cs b/AM2RPortHelperGUI/AM2RPortHelperGUI.Mac/Program.cs index 2b347cc..4656e21 100644 --- a/AM2RPortHelperGUI/AM2RPortHelperGUI.Mac/Program.cs +++ b/AM2RPortHelperGUI/AM2RPortHelperGUI.Mac/Program.cs @@ -3,7 +3,7 @@ using Eto.Forms; namespace AM2RPortHelperGUI.Mac; -class Program +static class Program { [STAThread] public static void Main(string[] args) diff --git a/AM2RPortHelperGUI/AM2RPortHelperGUI.Wpf/Program.cs b/AM2RPortHelperGUI/AM2RPortHelperGUI.Wpf/Program.cs index 446765e..2519082 100644 --- a/AM2RPortHelperGUI/AM2RPortHelperGUI.Wpf/Program.cs +++ b/AM2RPortHelperGUI/AM2RPortHelperGUI.Wpf/Program.cs @@ -3,7 +3,7 @@ using Eto.Forms; namespace AM2RPortHelperGUI.Wpf; -class Program +static class Program { [STAThread] public static void Main(string[] args) diff --git a/AM2RPortHelperGUI/AM2RPortHelperGUI/MainForm.cs b/AM2RPortHelperGUI/AM2RPortHelperGUI/MainForm.cs index 17534d4..891670a 100644 --- a/AM2RPortHelperGUI/AM2RPortHelperGUI/MainForm.cs +++ b/AM2RPortHelperGUI/AM2RPortHelperGUI/MainForm.cs @@ -63,11 +63,13 @@ public partial class MainForm : Form filePicker.FilePathChanged += ShouldButtonPortBeEnabled; buttonPort.Click += ButtonPortOnClick; } + + // Helper functions private async void ButtonPortOnClick(object sender, EventArgs e) { DisableAllElements(); - PortHelper.OutputHandlerDelegate handler = output => Application.Instance.Invoke(() => labelProgress.Text = $"Info: {output}"); + void OutputHandlerDelegate(string output) => Application.Instance.Invoke(() => labelProgress.Text = $"Info: {output}"); string modZipPath = filePicker.FilePath; string currentDir = Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory); string linuxPath = $"{currentDir}/{Path.GetFileNameWithoutExtension(modZipPath)}_LINUX.zip"; @@ -82,13 +84,13 @@ public partial class MainForm : Form File.Delete(macPath); if (checkboxLinux.Checked.Value) - await Task.Run(() => PortHelper.PortWindowsToLinux(modZipPath,linuxPath, handler)); + await Task.Run(() => PortHelper.PortWindowsToLinux(modZipPath,linuxPath, OutputHandlerDelegate)); if (checkboxAndroid.Checked.Value) - await Task.Run(() =>PortHelper.PortWindowsToAndroid(modZipPath, androidPath, handler)); + await Task.Run(() =>PortHelper.PortWindowsToAndroid(modZipPath, androidPath, OutputHandlerDelegate)); if (checkboxMac.Checked.Value) { string modName = "foo";//MessageBox.Show() - await Task.Run(() => PortHelper.PortWindowsToMac(modZipPath, macPath, modName, handler)); + await Task.Run(() => PortHelper.PortWindowsToMac(modZipPath, macPath, modName, OutputHandlerDelegate)); } labelProgress.Text = "Done!"; @@ -97,7 +99,7 @@ public partial class MainForm : Form EnableAllElements(); } - public static void OpenFolder(string path) + private static void OpenFolder(string path) { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) Process.Start("explorer.exe", $"\"{path}\""); @@ -135,35 +137,36 @@ public partial class MainForm : Form buttonPort.Enabled = true; } - private Label labelSelectMod = new Label + // Attributes + private readonly Label labelSelectMod = new Label { Text = "Select Mod:" }; - private FilePicker filePicker = new FilePicker() + private readonly FilePicker filePicker = new FilePicker { Filters = { new FileFilter("Zip file", "*.zip") } }; - private CheckBox checkboxLinux = new CheckBox() + private readonly CheckBox checkboxLinux = new CheckBox { Text = "Linux" }; - private CheckBox checkboxAndroid = new CheckBox() + private readonly CheckBox checkboxAndroid = new CheckBox { Text = "Android" }; - private CheckBox checkboxMac = new CheckBox() + private readonly CheckBox checkboxMac = new CheckBox { Text = "Mac" }; - private Button buttonPort = new Button() + private readonly Button buttonPort = new Button { Text = "Port!", Enabled = false }; - private Label labelProgress = new Label() + private readonly Label labelProgress = new Label { Text = "Info: " };