From 21bc6e2e4ae6918080f2048b50e5ca2755558720 Mon Sep 17 00:00:00 2001 From: "waffle.lord" Date: Wed, 25 May 2022 08:43:12 -0400 Subject: [PATCH] all kinds of stuff --- .../EftInfo/EftClientLocation.cs | 8 +- .../Extensions/BoolExtensions.cs | 7 +- .../EftPatchHelper/Helpers/FolderCleaner.cs | 6 +- .../Interfaces/IClientSelectionTask.cs | 8 +- .../Interfaces/ISettingsTask.cs | 8 +- .../EftPatchHelper/Interfaces/ITaskable.cs | 6 +- .../EftPatchHelper/Model/Options.cs | 10 +- .../EftPatchHelper/Model/Settings.cs | 44 +++--- EftPatchHelper/EftPatchHelper/Program.cs | 134 +++--------------- .../Tasks/ClientSelectionTask.cs | 50 ++++++- .../Tasks/StartupSettingsTask.cs | 6 +- 11 files changed, 109 insertions(+), 178 deletions(-) diff --git a/EftPatchHelper/EftPatchHelper/EftInfo/EftClientLocation.cs b/EftPatchHelper/EftPatchHelper/EftInfo/EftClientLocation.cs index 6b527fa..9798ee2 100644 --- a/EftPatchHelper/EftPatchHelper/EftInfo/EftClientLocation.cs +++ b/EftPatchHelper/EftPatchHelper/EftInfo/EftClientLocation.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace EftPatchHelper.EftInfo +namespace EftPatchHelper.EftInfo { public enum EftClientLocation { diff --git a/EftPatchHelper/EftPatchHelper/Extensions/BoolExtensions.cs b/EftPatchHelper/EftPatchHelper/Extensions/BoolExtensions.cs index 8a4629e..3c0d500 100644 --- a/EftPatchHelper/EftPatchHelper/Extensions/BoolExtensions.cs +++ b/EftPatchHelper/EftPatchHelper/Extensions/BoolExtensions.cs @@ -1,9 +1,4 @@ using Spectre.Console; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace EftPatchHelper.Extensions { @@ -11,7 +6,7 @@ namespace EftPatchHelper.Extensions { public static void ValidateOrExit(this bool toValidate) { - if(!toValidate) + if (!toValidate) { AnsiConsole.Prompt(new TextPrompt("Press [blue]enter[/] to close ...").AllowEmpty()); Environment.Exit(0); diff --git a/EftPatchHelper/EftPatchHelper/Helpers/FolderCleaner.cs b/EftPatchHelper/EftPatchHelper/Helpers/FolderCleaner.cs index 321b029..dfaebb0 100644 --- a/EftPatchHelper/EftPatchHelper/Helpers/FolderCleaner.cs +++ b/EftPatchHelper/EftPatchHelper/Helpers/FolderCleaner.cs @@ -6,7 +6,7 @@ namespace EftPatchHelper.Helpers { public static string cleanPathsFile = Path.Join(Directory.GetCurrentDirectory(), "removePaths.txt"); - public static string[] AssumedPaths = + public static string[] AssumedPaths = { "BattlEye", "cache", @@ -43,11 +43,11 @@ namespace EftPatchHelper.Helpers { fsInfo.Delete(); } - + fsInfo.Refresh(); - if(!fsInfo.Exists) + if (!fsInfo.Exists) { AnsiConsole.MarkupLine($"[blue]INFO:[/] [gray]Deleting {fsInfo.Name} ...[/] [green]OK[/]"); continue; diff --git a/EftPatchHelper/EftPatchHelper/Interfaces/IClientSelectionTask.cs b/EftPatchHelper/EftPatchHelper/Interfaces/IClientSelectionTask.cs index 0a2d072..8d38a3e 100644 --- a/EftPatchHelper/EftPatchHelper/Interfaces/IClientSelectionTask.cs +++ b/EftPatchHelper/EftPatchHelper/Interfaces/IClientSelectionTask.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace EftPatchHelper.Interfaces +namespace EftPatchHelper.Interfaces { public interface IClientSelectionTask : ITaskable { diff --git a/EftPatchHelper/EftPatchHelper/Interfaces/ISettingsTask.cs b/EftPatchHelper/EftPatchHelper/Interfaces/ISettingsTask.cs index 944a7cc..4fe4122 100644 --- a/EftPatchHelper/EftPatchHelper/Interfaces/ISettingsTask.cs +++ b/EftPatchHelper/EftPatchHelper/Interfaces/ISettingsTask.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace EftPatchHelper.Interfaces +namespace EftPatchHelper.Interfaces { public interface ISettingsTask : ITaskable { diff --git a/EftPatchHelper/EftPatchHelper/Interfaces/ITaskable.cs b/EftPatchHelper/EftPatchHelper/Interfaces/ITaskable.cs index 2c3cda8..6a85970 100644 --- a/EftPatchHelper/EftPatchHelper/Interfaces/ITaskable.cs +++ b/EftPatchHelper/EftPatchHelper/Interfaces/ITaskable.cs @@ -1,6 +1,4 @@ -using EftPatchHelper.Model; - -namespace EftPatchHelper.Interfaces +namespace EftPatchHelper.Interfaces { public interface ITaskable { @@ -8,6 +6,6 @@ namespace EftPatchHelper.Interfaces /// Runs a predefined task /// /// Returns true if the task succeeded, otherwise false - public bool Run(); + public void Run(); } } diff --git a/EftPatchHelper/EftPatchHelper/Model/Options.cs b/EftPatchHelper/EftPatchHelper/Model/Options.cs index eea1037..c884005 100644 --- a/EftPatchHelper/EftPatchHelper/Model/Options.cs +++ b/EftPatchHelper/EftPatchHelper/Model/Options.cs @@ -1,13 +1,11 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using EftPatchHelper.EftInfo; namespace EftPatchHelper.Model { public class Options { - public bool PromptToOverwriteDirectories = true; + public bool IgnoreExistingDirectories = true; + public EftClient TargetClient = null; + public EftClient SourceClient = null; } } diff --git a/EftPatchHelper/EftPatchHelper/Model/Settings.cs b/EftPatchHelper/EftPatchHelper/Model/Settings.cs index 7fe8222..7d97fa5 100644 --- a/EftPatchHelper/EftPatchHelper/Model/Settings.cs +++ b/EftPatchHelper/EftPatchHelper/Model/Settings.cs @@ -1,4 +1,5 @@ -using System.Text.Json; +using Spectre.Console; +using System.Text.Json; using System.Text.Json.Serialization; namespace EftPatchHelper.Model @@ -29,35 +30,40 @@ namespace EftPatchHelper.Model [JsonPropertyName("patcherExePath")] public string PatcherEXEPath { get; set; } = ""; - public void Save() + public bool Save() { - string json = JsonSerializer.Serialize(this, typeof(Settings), new JsonSerializerOptions() { WriteIndented = true }); + try + { + string json = JsonSerializer.Serialize(this, typeof(Settings), new JsonSerializerOptions() { WriteIndented = true }); - if (string.IsNullOrWhiteSpace(json)) return; + if (string.IsNullOrWhiteSpace(json)) + { + AnsiConsole.WriteLine("[red]!! Nothing was serialized !![/]"); + return false; + } - File.WriteAllText(settingsFile, json); + File.WriteAllText(settingsFile, json); + + return true; + } + catch (Exception ex) + { + AnsiConsole.WriteException(ex); + return false; + } } - //public static Settings? Load() - //{ - // if (!File.Exists(settingsFile)) return null; - - // string json = File.ReadAllText(settingsFile); - - // return JsonSerializer.Deserialize(json); - //} - public bool Validate() { - if(string.IsNullOrWhiteSpace(TargetEftVersion)) return false; + if (string.IsNullOrWhiteSpace(TargetEftVersion)) return false; - if(string.IsNullOrWhiteSpace(PrepFolderPath)) return false; + if (string.IsNullOrWhiteSpace(PrepFolderPath)) return false; - if(string.IsNullOrWhiteSpace(BackupFolderPath)) return false; + if (string.IsNullOrWhiteSpace(BackupFolderPath)) return false; - if(string.IsNullOrWhiteSpace(LiveEftPath)) return false; + if (string.IsNullOrWhiteSpace(LiveEftPath)) return false; - if(string.IsNullOrWhiteSpace(PatcherEXEPath)) return false; + if (string.IsNullOrWhiteSpace(PatcherEXEPath)) return false; return true; } diff --git a/EftPatchHelper/EftPatchHelper/Program.cs b/EftPatchHelper/EftPatchHelper/Program.cs index 323e830..5a14347 100644 --- a/EftPatchHelper/EftPatchHelper/Program.cs +++ b/EftPatchHelper/EftPatchHelper/Program.cs @@ -1,5 +1,4 @@ // See https://aka.ms/new-console-template for more information -using EftPatchHelper.Extensions; using EftPatchHelper.Helpers; using EftPatchHelper.Interfaces; using EftPatchHelper.Model; @@ -15,29 +14,43 @@ namespace EftPatchHelper { ITaskable _settingsTasks; ITaskable _clientSelectionTasks; + ITaskable _fileProcessingTasks; + ITaskable _patchGenTasks; + ITaskable _patchTestingTasks; public static void Main(string[] args) { - // Fancy AnsiConsole.Write(new FigletText("EFT Patch Helper").Centered().Color(Color.Blue)); var host = ConfigureHost(args); host.Services.GetRequiredService().Run(); + + AnsiConsole.MarkupLine("Press [blue]Enter[/] to close ..."); + Console.ReadLine(); } public Program( ISettingsTask settingsTasks, - IClientSelectionTask clientSelectionTasks + IClientSelectionTask clientSelectionTasks, + IFileProcessingTasks fileProcessingTasks, + IPatchGenTasks patchGenTasks, + IPatchTestingTasks patchTestingTasks ) { _settingsTasks = settingsTasks; _clientSelectionTasks = clientSelectionTasks; + _fileProcessingTasks = fileProcessingTasks; + _patchGenTasks = patchGenTasks; + _patchTestingTasks = patchTestingTasks; } public void Run() { - _settingsTasks.Run().ValidateOrExit(); - _clientSelectionTasks.Run().ValidateOrExit(); + _settingsTasks.Run(); + _clientSelectionTasks.Run(); + _fileProcessingTasks.Run(); + _patchGenTasks.Run(); + _patchTestingTasks.Run(); } private static IHost ConfigureHost(string[] args) @@ -57,6 +70,9 @@ namespace EftPatchHelper services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); }) .ConfigureAppConfiguration((_, config) => @@ -66,110 +82,4 @@ namespace EftPatchHelper .Build(); } } -} - -//EftClientSelector.LoadClientList(settings); - -//EftClient targetClient = EftClientSelector.GetClient(settings.TargetEftVersion); -//EftClient sourceClient; - -//AnsiConsole.WriteLine(); -//ConfirmationPrompt confirmTarget = new ConfirmationPrompt($"Use version [purple]{_settings.TargetEftVersion}[/] as target?"); - -//if (!confirmTarget.Show(AnsiConsole.Console) || targetClient == null) -//{ -// targetClient = EftClientSelector.GetClientSelection("Select [yellow]Target[/] Version"); - -// AnsiConsole.WriteLine(); -// ConfirmationPrompt changeVersion = new ConfirmationPrompt($"Update settings target version to use [purple]{targetClient.Version}[/]?"); - -// if (changeVersion.Show(AnsiConsole.Console)) -// { -// settings.TargetEftVersion = targetClient.Version; - -// settings.Save(); -// } -//} - -//sourceClient = EftClientSelector.GetClientSelection("Select [blue]Source[/] Version"); - - -////backup data if needed -//targetClient.Backup(settings, !promptToOverwrite); -//sourceClient.Backup(settings, !promptToOverwrite); - -////copy source to prep directory -//AnsiConsole.WriteLine(); -//AnsiConsole.MarkupLine("[gray]Copying[/] [blue]source[/][gray] to prep area ...[/]"); - -//FolderCopy sourceCopy = new FolderCopy(sourceClient.FolderPath, sourceClient.PrepPath); - -//sourceCopy.Start(!promptToOverwrite); - -////copy target to prep directory -//AnsiConsole.MarkupLine("[gray]Copying[/] [blue]target[/][gray] to prep area ...[/]"); - -//FolderCopy targetCopy = new FolderCopy(targetClient.FolderPath, targetClient.PrepPath); - -//targetCopy.Start(!promptToOverwrite); - -//// clean prep source and target folders of uneeded data -//FolderCleaner.Clean(sourceClient.PrepPath); - -//FolderCleaner.Clean(targetClient.PrepPath); - -//// start patcher -//if(File.Exists(settings.PatcherEXEPath)) -//{ -// string patcherOutputName = $"Patcher_{sourceClient.Version}_to_{targetClient.Version}"; - -// AnsiConsole.Markup("Starting patcher ... "); - -// var genProc = Process.Start(new ProcessStartInfo() -// { -// FileName = settings.PatcherEXEPath, -// WorkingDirectory = new FileInfo(settings.PatcherEXEPath).Directory?.FullName ?? Directory.GetCurrentDirectory(), -// ArgumentList = -// { -// $"OutputFolderName::{patcherOutputName}", -// $"SourceFolderPath::{sourceClient.PrepPath}", -// $"TargetFolderPath::{targetClient.PrepPath}", -// $"AutoZip::{settings.AutoZip}", -// $"AutoClose::{settings.AutoClose}" -// } -// }); - -// genProc?.WaitForExit(); - -// switch((PatcherExitCode)genProc.ExitCode) -// { -// case PatcherExitCode.ProgramClosed: -// { - -// break; -// } -// case PatcherExitCode.Success: -// { - -// break; -// } -// case PatcherExitCode.MissingDir: -// { - -// break; -// } -// default: -// { -// break; -// } -// } -//} - -//AnsiConsole.MarkupLine("[green]done[/]"); - -//AnsiConsole.WriteLine(); - -//// done -//AnsiConsole.MarkupLine("Press [blue]Enter[/] to close ..."); - -//Console.ReadLine(); \ No newline at end of file +} \ No newline at end of file diff --git a/EftPatchHelper/EftPatchHelper/Tasks/ClientSelectionTask.cs b/EftPatchHelper/EftPatchHelper/Tasks/ClientSelectionTask.cs index f26429c..dc06f2d 100644 --- a/EftPatchHelper/EftPatchHelper/Tasks/ClientSelectionTask.cs +++ b/EftPatchHelper/EftPatchHelper/Tasks/ClientSelectionTask.cs @@ -1,6 +1,8 @@ -using EftPatchHelper.Helpers; +using EftPatchHelper.Extensions; +using EftPatchHelper.Helpers; using EftPatchHelper.Interfaces; using EftPatchHelper.Model; +using Spectre.Console; namespace EftPatchHelper.Tasks { @@ -17,9 +19,51 @@ namespace EftPatchHelper.Tasks _clientSelector = clientSelector; } - public bool Run() + private bool ChangeSettingsTargetVersion() { - + var targetClient = _clientSelector.GetClientSelection("Select [yellow]Target[/] Version"); + + AnsiConsole.WriteLine(); + ConfirmationPrompt changeVersion = new ConfirmationPrompt($"Update settings target version to use [purple]{targetClient.Version}[/]?"); + + if (changeVersion.Show(AnsiConsole.Console)) + { + _settings.TargetEftVersion = targetClient.Version; + + return _settings.Save(); + } + + return true; + } + + private bool ConfirmExistingTargetVersion() + { + _clientSelector.LoadClientList(); + + _options.TargetClient = _clientSelector.GetClient(_settings.TargetEftVersion); + + ConfirmationPrompt confirmTarget = new ConfirmationPrompt($"Use version [purple]{_settings.TargetEftVersion}[/] as target?"); + + // If client is null or requested change, return false to ensure change settings target is called. + return _options.TargetClient == null || !confirmTarget.Show(AnsiConsole.Console); + } + + private bool SelectSourceVersion() + { + _options.SourceClient = _clientSelector.GetClientSelection("Select [blue]Source[/] Version"); + + return _options.SourceClient != null; + } + + public void Run() + { + if (ConfirmExistingTargetVersion()) + { + ChangeSettingsTargetVersion().ValidateOrExit(); + } + + SelectSourceVersion().ValidateOrExit(); } } } + diff --git a/EftPatchHelper/EftPatchHelper/Tasks/StartupSettingsTask.cs b/EftPatchHelper/EftPatchHelper/Tasks/StartupSettingsTask.cs index 151038a..5fd57be 100644 --- a/EftPatchHelper/EftPatchHelper/Tasks/StartupSettingsTask.cs +++ b/EftPatchHelper/EftPatchHelper/Tasks/StartupSettingsTask.cs @@ -60,18 +60,16 @@ namespace EftPatchHelper.Tasks private void ConfirmOptions() { - _options.PromptToOverwriteDirectories = new ConfirmationPrompt("Prompt to overwrite directories?").Show(AnsiConsole.Console); + _options.IgnoreExistingDirectories = new ConfirmationPrompt("Skip existing directories? (you will be prompted if no)").Show(AnsiConsole.Console); } - public bool Run() + public void Run() { ValidateSettings().ValidateOrExit(); ConfirmOptions(); PrintSummary(); - - return true; } } } \ No newline at end of file