Code refactoring

This commit is contained in:
Jaex 2022-10-15 01:28:50 +03:00
parent 1bfba73c26
commit cc63d784a6
4 changed files with 39 additions and 60 deletions

View file

@ -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"
}
}

View file

@ -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)
{

View file

@ -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);
}
}
}

View file

@ -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;
}
}
}