From cc63d784a6d791d6b54feb1f3463c3f6ac6bb6c2 Mon Sep 17 00:00:00 2001 From: Jaex Date: Sat, 15 Oct 2022 01:28:50 +0300 Subject: [PATCH] Code refactoring --- AppVeyor/after_build.ps1 | 6 ++-- ShareX.HelpersLib/CLI/CLIManager.cs | 7 ++++- ShareX.Setup/Program.cs | 49 ++++++++++++++++++----------- ShareX.Setup/SetupHelpers.cs | 37 ---------------------- 4 files changed, 39 insertions(+), 60 deletions(-) diff --git a/AppVeyor/after_build.ps1 b/AppVeyor/after_build.ps1 index f2e7b2fe2..e3896727e 100644 --- a/AppVeyor/after_build.ps1 +++ b/AppVeyor/after_build.ps1 @@ -2,14 +2,14 @@ if ($env:APPVEYOR_PULL_REQUEST_NUMBER -eq $null) { if ($env:CONFIGURATION -eq "Release") { - & "ShareX.Setup\bin\Release\ShareX.Setup.exe" -AppVeyorRelease + & "ShareX.Setup\bin\Release\ShareX.Setup.exe" -AppVeyor "$env:CONFIGURATION" } elseif ($env:CONFIGURATION -eq "Steam") { - & "ShareX.Setup\bin\Steam\ShareX.Setup.exe" -AppVeyorSteam + & "ShareX.Setup\bin\Steam\ShareX.Setup.exe" -AppVeyor "$env:CONFIGURATION" } elseif ($env:CONFIGURATION -eq "MicrosoftStore") { - & "ShareX.Setup\bin\MicrosoftStore\ShareX.Setup.exe" -AppVeyorMicrosoftStore + & "ShareX.Setup\bin\MicrosoftStore\ShareX.Setup.exe" -AppVeyor "$env:CONFIGURATION" } } \ No newline at end of file diff --git a/ShareX.HelpersLib/CLI/CLIManager.cs b/ShareX.HelpersLib/CLI/CLIManager.cs index 669634b0d..c22010597 100644 --- a/ShareX.HelpersLib/CLI/CLIManager.cs +++ b/ShareX.HelpersLib/CLI/CLIManager.cs @@ -150,9 +150,14 @@ public bool IsCommandExist(params string[] commands) return false; } + public CLICommand GetCommand(string command) + { + return Commands.Find(x => x.CheckCommand(command)); + } + public string GetParameter(string command) { - CLICommand cliCommand = Commands.Find(x => x.CheckCommand(command)); + CLICommand cliCommand = GetCommand(command); if (cliCommand != null) { diff --git a/ShareX.Setup/Program.cs b/ShareX.Setup/Program.cs index 043bd4375..b74d19a3b 100644 --- a/ShareX.Setup/Program.cs +++ b/ShareX.Setup/Program.cs @@ -51,11 +51,7 @@ private enum SetupJobs Portable = CreatePortable | OpenOutputDirectory, Steam = CreateSteamFolder | OpenOutputDirectory, MicrosoftStore = CreateMicrosoftStoreFolder | CompileAppx | OpenOutputDirectory, - MicrosoftStoreDebug = CreateMicrosoftStoreDebugFolder, - - AppVeyorRelease = CreateSetup | CreatePortable | CreateChecksumFile | DownloadFFmpeg, - AppVeyorSteam = CreateSteamFolder | DownloadFFmpeg, - AppVeyorMicrosoftStore = CreateMicrosoftStoreFolder | CompileAppx | DownloadFFmpeg + MicrosoftStoreDebug = CreateMicrosoftStoreDebugFolder } private static SetupJobs Job = SetupJobs.Stable; @@ -122,7 +118,7 @@ private static void Main(string[] args) { Console.WriteLine("ShareX setup started."); - CheckAppVeyor(args); + CheckArgs(args); Console.WriteLine("Setup job: " + Job); @@ -208,22 +204,37 @@ private static void Main(string[] args) Console.WriteLine("ShareX setup successfully completed."); } - private static void CheckAppVeyor(string[] args) + private static void CheckArgs(string[] args) { - if (SetupHelpers.CheckArguments(args, "-AppVeyorRelease")) + CLIManager cli = new CLIManager(args); + cli.ParseCommands(); + + CLICommand command = cli.GetCommand("AppVeyor"); + + if (command != null) { AppVeyor = true; - Job = SetupJobs.AppVeyorRelease; - } - else if (SetupHelpers.CheckArguments(args, "-AppVeyorSteam")) - { - AppVeyor = true; - Job = SetupJobs.AppVeyorSteam; - } - else if (SetupHelpers.CheckArguments(args, "-AppVeyorMicrosoftStore")) - { - AppVeyor = true; - Job = SetupJobs.AppVeyorMicrosoftStore; + + string configuration = command.Parameter; + + Console.WriteLine("AppVeyor: " + configuration); + + if (configuration.Equals("Release", StringComparison.OrdinalIgnoreCase)) + { + Job = SetupJobs.CreateSetup | SetupJobs.CreatePortable | SetupJobs.CreateChecksumFile | SetupJobs.DownloadFFmpeg; + } + else if (configuration.Equals("Steam", StringComparison.OrdinalIgnoreCase)) + { + Job = SetupJobs.CreateSteamFolder | SetupJobs.DownloadFFmpeg; + } + else if (configuration.Equals("MicrosoftStore", StringComparison.OrdinalIgnoreCase)) + { + Job = SetupJobs.CreateMicrosoftStoreFolder | SetupJobs.CompileAppx | SetupJobs.DownloadFFmpeg; + } + else + { + Environment.Exit(0); + } } } diff --git a/ShareX.Setup/SetupHelpers.cs b/ShareX.Setup/SetupHelpers.cs index 9e3b5be56..950076d3d 100644 --- a/ShareX.Setup/SetupHelpers.cs +++ b/ShareX.Setup/SetupHelpers.cs @@ -26,7 +26,6 @@ using ShareX.HelpersLib; using System; using System.Collections.Generic; -using System.Diagnostics; using System.IO; using System.Linq; @@ -89,41 +88,5 @@ public static void CopyFiles(string directory, string searchPattern, string toFo CopyFiles(files, toFolder); } - - private static void ProcessStart(string filePath, string arguments) - { - Console.WriteLine($"Process starting: {filePath} {arguments}"); - - using (Process process = new Process()) - { - ProcessStartInfo psi = new ProcessStartInfo() - { - FileName = filePath, - Arguments = arguments, - UseShellExecute = false, - CreateNoWindow = true - }; - - process.StartInfo = psi; - process.Start(); - process.WaitForExit(); - } - } - - public static bool CheckArguments(string[] args, string check) - { - if (!string.IsNullOrEmpty(check)) - { - foreach (string arg in args) - { - if (!string.IsNullOrEmpty(arg) && arg.Equals(check, StringComparison.InvariantCultureIgnoreCase)) - { - return true; - } - } - } - - return false; - } } } \ No newline at end of file