From b243a150f50db6a1887c009bbf5e0aae11e3325a Mon Sep 17 00:00:00 2001 From: "waffle.lord" Date: Tue, 17 May 2022 21:51:02 -0400 Subject: [PATCH] reworked program startup and settings. client seletions is WIP --- .../EftPatchHelper/EftInfo/EftClient.cs | 1 + .../EftPatchHelper/EftPatchHelper.csproj | 11 +- .../Extensions/BoolExtensions.cs | 21 ++ .../Helpers/EftClientSelector.cs | 41 +-- .../Interfaces/IClientSelectionTask.cs | 12 + .../Interfaces/ISettingsTask.cs | 12 + .../EftPatchHelper/Interfaces/ITaskable.cs | 13 + .../EftPatchHelper/Model/Options.cs | 13 + .../EftPatchHelper/Model/PatcherExitCode.cs | 12 + .../EftPatchHelper/{ => Model}/Settings.cs | 29 ++- EftPatchHelper/EftPatchHelper/Program.cs | 238 +++++++++++------- .../Tasks/ClientSelectionTask.cs | 25 ++ .../Tasks/StartupSettingsTask.cs | 77 ++++++ EftPatchHelper/EftPatchHelper/settings.json | 9 + 14 files changed, 393 insertions(+), 121 deletions(-) create mode 100644 EftPatchHelper/EftPatchHelper/Extensions/BoolExtensions.cs create mode 100644 EftPatchHelper/EftPatchHelper/Interfaces/IClientSelectionTask.cs create mode 100644 EftPatchHelper/EftPatchHelper/Interfaces/ISettingsTask.cs create mode 100644 EftPatchHelper/EftPatchHelper/Interfaces/ITaskable.cs create mode 100644 EftPatchHelper/EftPatchHelper/Model/Options.cs create mode 100644 EftPatchHelper/EftPatchHelper/Model/PatcherExitCode.cs rename EftPatchHelper/EftPatchHelper/{ => Model}/Settings.cs (67%) create mode 100644 EftPatchHelper/EftPatchHelper/Tasks/ClientSelectionTask.cs create mode 100644 EftPatchHelper/EftPatchHelper/Tasks/StartupSettingsTask.cs create mode 100644 EftPatchHelper/EftPatchHelper/settings.json diff --git a/EftPatchHelper/EftPatchHelper/EftInfo/EftClient.cs b/EftPatchHelper/EftPatchHelper/EftInfo/EftClient.cs index 0b40774..5c52e9c 100644 --- a/EftPatchHelper/EftPatchHelper/EftInfo/EftClient.cs +++ b/EftPatchHelper/EftPatchHelper/EftInfo/EftClient.cs @@ -1,4 +1,5 @@ using EftPatchHelper.Helpers; +using EftPatchHelper.Model; using Spectre.Console; namespace EftPatchHelper.EftInfo diff --git a/EftPatchHelper/EftPatchHelper/EftPatchHelper.csproj b/EftPatchHelper/EftPatchHelper/EftPatchHelper.csproj index 95b62d7..f150611 100644 --- a/EftPatchHelper/EftPatchHelper/EftPatchHelper.csproj +++ b/EftPatchHelper/EftPatchHelper/EftPatchHelper.csproj @@ -8,7 +8,16 @@ - + + + + + + + + + Always + diff --git a/EftPatchHelper/EftPatchHelper/Extensions/BoolExtensions.cs b/EftPatchHelper/EftPatchHelper/Extensions/BoolExtensions.cs new file mode 100644 index 0000000..8a4629e --- /dev/null +++ b/EftPatchHelper/EftPatchHelper/Extensions/BoolExtensions.cs @@ -0,0 +1,21 @@ +using Spectre.Console; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EftPatchHelper.Extensions +{ + public static class BoolExtensions + { + public static void ValidateOrExit(this bool toValidate) + { + if(!toValidate) + { + AnsiConsole.Prompt(new TextPrompt("Press [blue]enter[/] to close ...").AllowEmpty()); + Environment.Exit(0); + } + } + } +} diff --git a/EftPatchHelper/EftPatchHelper/Helpers/EftClientSelector.cs b/EftPatchHelper/EftPatchHelper/Helpers/EftClientSelector.cs index 8aa65be..c71bcf7 100644 --- a/EftPatchHelper/EftPatchHelper/Helpers/EftClientSelector.cs +++ b/EftPatchHelper/EftPatchHelper/Helpers/EftClientSelector.cs @@ -1,17 +1,24 @@ using EftPatchHelper.EftInfo; +using EftPatchHelper.Model; using Spectre.Console; using System.Diagnostics; namespace EftPatchHelper.Helpers { - public static class EftClientSelector + public class EftClientSelector { - private static List clientList = new List(); + private List _clientList = new List(); + private Settings _settings; - public static string? GetLiveVersion(Settings settings) + public EftClientSelector(Settings settings) + { + _settings = settings; + } + + public string? GetLiveVersion() { // Get eft live version - string eftVersion = FileVersionInfo.GetVersionInfo(Path.Join(settings.LiveEftPath, "EscapeFromTarkov.exe")).ProductVersion?.Replace('-', '.'); + string eftVersion = FileVersionInfo.GetVersionInfo(Path.Join(_settings.LiveEftPath, "EscapeFromTarkov.exe")).ProductVersion?.Replace('-', '.'); //remove leading 0 from version number if (eftVersion != null && eftVersion.StartsWith("0.")) @@ -24,32 +31,32 @@ namespace EftPatchHelper.Helpers return string.Join('.', fixedVersion); } - public static EftClient GetClient(string Version) + public EftClient GetClient(string Version) { - return clientList.Where(x => x.Version == Version).FirstOrDefault(); + return _clientList.Where(x => x.Version == Version).FirstOrDefault(); } - public static void LoadClientList(Settings settings) + public void LoadClientList() { - clientList.Clear(); + _clientList.Clear(); - string? eftVersion = GetLiveVersion(settings); + string? eftVersion = GetLiveVersion(); if (eftVersion != null) { // add eft live version to version options - clientList.Add(new EftClient() + _clientList.Add(new EftClient() { - FolderPath = settings.LiveEftPath, + FolderPath = _settings.LiveEftPath, Version = eftVersion, - PrepPath = Path.Join(settings.PrepFolderPath, eftVersion), + PrepPath = Path.Join(_settings.PrepFolderPath, eftVersion), Location = EftClientLocation.Live }); } // add backup folders to version options - foreach (string backup in Directory.GetDirectories(settings.BackupFolderPath)) + foreach (string backup in Directory.GetDirectories(_settings.BackupFolderPath)) { DirectoryInfo backupDir = new DirectoryInfo(backup); @@ -58,17 +65,17 @@ namespace EftPatchHelper.Helpers continue; } - clientList.Add(new EftClient() + _clientList.Add(new EftClient() { FolderPath = backupDir.FullName, Version = backupDir.Name, - PrepPath = Path.Join(settings.PrepFolderPath, backupDir.Name), + PrepPath = Path.Join(_settings.PrepFolderPath, backupDir.Name), Location = EftClientLocation.Backup }); } } - public static EftClient GetClientSelection(string Prompt) + public EftClient GetClientSelection(string Prompt) { SelectionPrompt clientPrompt = new SelectionPrompt() { @@ -78,7 +85,7 @@ namespace EftPatchHelper.Helpers Converter = (x) => x.DisplayName }; - clientPrompt.AddChoices(clientList); + clientPrompt.AddChoices(_clientList); return clientPrompt.Show(AnsiConsole.Console); } diff --git a/EftPatchHelper/EftPatchHelper/Interfaces/IClientSelectionTask.cs b/EftPatchHelper/EftPatchHelper/Interfaces/IClientSelectionTask.cs new file mode 100644 index 0000000..0a2d072 --- /dev/null +++ b/EftPatchHelper/EftPatchHelper/Interfaces/IClientSelectionTask.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EftPatchHelper.Interfaces +{ + public interface IClientSelectionTask : ITaskable + { + } +} diff --git a/EftPatchHelper/EftPatchHelper/Interfaces/ISettingsTask.cs b/EftPatchHelper/EftPatchHelper/Interfaces/ISettingsTask.cs new file mode 100644 index 0000000..944a7cc --- /dev/null +++ b/EftPatchHelper/EftPatchHelper/Interfaces/ISettingsTask.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EftPatchHelper.Interfaces +{ + public interface ISettingsTask : ITaskable + { + } +} diff --git a/EftPatchHelper/EftPatchHelper/Interfaces/ITaskable.cs b/EftPatchHelper/EftPatchHelper/Interfaces/ITaskable.cs new file mode 100644 index 0000000..2c3cda8 --- /dev/null +++ b/EftPatchHelper/EftPatchHelper/Interfaces/ITaskable.cs @@ -0,0 +1,13 @@ +using EftPatchHelper.Model; + +namespace EftPatchHelper.Interfaces +{ + public interface ITaskable + { + /// + /// Runs a predefined task + /// + /// Returns true if the task succeeded, otherwise false + public bool Run(); + } +} diff --git a/EftPatchHelper/EftPatchHelper/Model/Options.cs b/EftPatchHelper/EftPatchHelper/Model/Options.cs new file mode 100644 index 0000000..eea1037 --- /dev/null +++ b/EftPatchHelper/EftPatchHelper/Model/Options.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EftPatchHelper.Model +{ + public class Options + { + public bool PromptToOverwriteDirectories = true; + } +} diff --git a/EftPatchHelper/EftPatchHelper/Model/PatcherExitCode.cs b/EftPatchHelper/EftPatchHelper/Model/PatcherExitCode.cs new file mode 100644 index 0000000..8c9c02b --- /dev/null +++ b/EftPatchHelper/EftPatchHelper/Model/PatcherExitCode.cs @@ -0,0 +1,12 @@ +namespace EftPatchHelper.Model +{ + public enum PatcherExitCode + { + ProgramClosed = 0, + Success = 10, + EftExeNotFound = 11, + NoPatchFolder = 12, + MissingFile = 13, + MissingDir = 14 + } +} diff --git a/EftPatchHelper/EftPatchHelper/Settings.cs b/EftPatchHelper/EftPatchHelper/Model/Settings.cs similarity index 67% rename from EftPatchHelper/EftPatchHelper/Settings.cs rename to EftPatchHelper/EftPatchHelper/Model/Settings.cs index 6feb2ed..7fe8222 100644 --- a/EftPatchHelper/EftPatchHelper/Settings.cs +++ b/EftPatchHelper/EftPatchHelper/Model/Settings.cs @@ -1,29 +1,32 @@ using System.Text.Json; using System.Text.Json.Serialization; -namespace EftPatchHelper +namespace EftPatchHelper.Model { public class Settings { [JsonIgnore] public static string settingsFile = Path.Join(Directory.GetCurrentDirectory(), "settings.json"); - [JsonPropertyName("target_eft_version")] + [JsonPropertyName("targetEftVersion")] public string TargetEftVersion { get; set; } = ""; - [JsonPropertyName("prep_folder_path")] + [JsonPropertyName("prepFolderPath")] public string PrepFolderPath { get; set; } = ""; - [JsonPropertyName("backup_folder_path")] + [JsonPropertyName("backupFolderPath")] public string BackupFolderPath { get; set; } = ""; - [JsonPropertyName("live_eft_path")] + [JsonPropertyName("liveEftPath")] public string LiveEftPath { get; set; } = ""; - [JsonPropertyName("auto_zip")] + [JsonPropertyName("autoZip")] public bool AutoZip { get; set; } = true; - [JsonPropertyName("patcher_exe_path")] + [JsonPropertyName("autoClose")] + public bool AutoClose { get; set; } = false; + + [JsonPropertyName("patcherExePath")] public string PatcherEXEPath { get; set; } = ""; public void Save() @@ -35,14 +38,14 @@ namespace EftPatchHelper File.WriteAllText(settingsFile, json); } - public static Settings? Load() - { - if (!File.Exists(settingsFile)) return null; + //public static Settings? Load() + //{ + // if (!File.Exists(settingsFile)) return null; - string json = File.ReadAllText(settingsFile); + // string json = File.ReadAllText(settingsFile); - return JsonSerializer.Deserialize(json); - } + // return JsonSerializer.Deserialize(json); + //} public bool Validate() { diff --git a/EftPatchHelper/EftPatchHelper/Program.cs b/EftPatchHelper/EftPatchHelper/Program.cs index c13fc64..323e830 100644 --- a/EftPatchHelper/EftPatchHelper/Program.cs +++ b/EftPatchHelper/EftPatchHelper/Program.cs @@ -1,117 +1,175 @@ // See https://aka.ms/new-console-template for more information -using EftPatchHelper; -using EftPatchHelper.EftInfo; +using EftPatchHelper.Extensions; using EftPatchHelper.Helpers; +using EftPatchHelper.Interfaces; +using EftPatchHelper.Model; +using EftPatchHelper.Tasks; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; using Spectre.Console; -using System.Diagnostics; -Settings? settings = Settings.Load(); - - -// check settings file exists -if(settings == null) +namespace EftPatchHelper { - settings = new Settings(); - settings.Save(); - - AnsiConsole.MarkupLine($"Settings file was create here: \n[blue]{Settings.settingsFile}[/]\n\nPlease update it and try again."); - AnsiConsole.MarkupLine("Press [blue]Enter[/] to close ..."); - Console.ReadLine(); - return; -} - -// validate settings -if(!settings.Validate()) -{ - AnsiConsole.MarkupLine($"[red]Settings file seems to be missing some information, please fix it[/]\n\nPath to file:\n[blue]{Settings.settingsFile}[/]\n\n"); - AnsiConsole.MarkupLine("Press [blue]Enter[/] to close ..."); - Console.ReadLine(); - return; -} - -/// Fancy -AnsiConsole.Write(new FigletText("EFT Patch Helper").Centered().Color(Color.Blue)); - -// show some settings information -AnsiConsole.WriteLine(); -AnsiConsole.MarkupLine($"Current target version is [purple]{settings.TargetEftVersion}[/]"); -AnsiConsole.MarkupLine($"Prep folder path is [purple]{settings.PrepFolderPath}[/]"); -AnsiConsole.MarkupLine($"Backup folder path is [purple]{settings.BackupFolderPath}[/]"); -AnsiConsole.WriteLine(); - -EftClientSelector.LoadClientList(settings); - -EftClient targetClient = EftClientSelector.GetClient(settings.TargetEftVersion); -EftClient sourceClient; - -AnsiConsole.WriteLine(); -bool promptToOverwrite = new ConfirmationPrompt("Prompt to overwrite directories?").Show(AnsiConsole.Console); - -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)) + public class Program { - settings.TargetEftVersion = targetClient.Version; + ITaskable _settingsTasks; + ITaskable _clientSelectionTasks; - settings.Save(); + 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(); + } + + public Program( + ISettingsTask settingsTasks, + IClientSelectionTask clientSelectionTasks + ) + { + _settingsTasks = settingsTasks; + _clientSelectionTasks = clientSelectionTasks; + } + + public void Run() + { + _settingsTasks.Run().ValidateOrExit(); + _clientSelectionTasks.Run().ValidateOrExit(); + } + + private static IHost ConfigureHost(string[] args) + { + return Host.CreateDefaultBuilder(args).ConfigureServices((_, services) => + { + services.AddSingleton(); + services.AddSingleton(serviceProvider => + { + var configuration = serviceProvider.GetRequiredService(); + var settings = configuration.Get(); + if (settings == null) throw new Exception("Failed to retrieve settings"); + return settings; + }); + + services.AddScoped(); + + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + }) + .ConfigureAppConfiguration((_, config) => + { + config.AddJsonFile(Settings.settingsFile, optional: true, reloadOnChange: true); + }) + .Build(); + } } } -sourceClient = EftClientSelector.GetClientSelection("Select [blue]Source[/] Version"); +//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); +////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 ...[/]"); +////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); +//FolderCopy sourceCopy = new FolderCopy(sourceClient.FolderPath, sourceClient.PrepPath); -sourceCopy.Start(!promptToOverwrite); +//sourceCopy.Start(!promptToOverwrite); -//copy target to prep directory -AnsiConsole.MarkupLine("[gray]Copying[/] [blue]target[/][gray] to prep area ...[/]"); +////copy target to prep directory +//AnsiConsole.MarkupLine("[gray]Copying[/] [blue]target[/][gray] to prep area ...[/]"); -FolderCopy targetCopy = new FolderCopy(targetClient.FolderPath, targetClient.PrepPath); +//FolderCopy targetCopy = new FolderCopy(targetClient.FolderPath, targetClient.PrepPath); -targetCopy.Start(!promptToOverwrite); +//targetCopy.Start(!promptToOverwrite); -// clean prep source and target folders of uneeded data -FolderCleaner.Clean(sourceClient.PrepPath); +//// clean prep source and target folders of uneeded data +//FolderCleaner.Clean(sourceClient.PrepPath); -FolderCleaner.Clean(targetClient.PrepPath); +//FolderCleaner.Clean(targetClient.PrepPath); -// start patcher -if(File.Exists(settings.PatcherEXEPath)) -{ - string patcherOutputName = $"Patcher_{sourceClient.Version}_to_{targetClient.Version}"; +//// start patcher +//if(File.Exists(settings.PatcherEXEPath)) +//{ +// string patcherOutputName = $"Patcher_{sourceClient.Version}_to_{targetClient.Version}"; - AnsiConsole.Markup("Starting patcher ... "); +// AnsiConsole.Markup("Starting patcher ... "); - 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}"} - }); -} +// 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}" +// } +// }); -AnsiConsole.MarkupLine("[green]done[/]"); +// genProc?.WaitForExit(); -AnsiConsole.WriteLine(); +// switch((PatcherExitCode)genProc.ExitCode) +// { +// case PatcherExitCode.ProgramClosed: +// { -// done -AnsiConsole.MarkupLine("Press [blue]Enter[/] to close ..."); +// break; +// } +// case PatcherExitCode.Success: +// { -Console.ReadLine(); \ No newline at end of file +// 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 diff --git a/EftPatchHelper/EftPatchHelper/Tasks/ClientSelectionTask.cs b/EftPatchHelper/EftPatchHelper/Tasks/ClientSelectionTask.cs new file mode 100644 index 0000000..f26429c --- /dev/null +++ b/EftPatchHelper/EftPatchHelper/Tasks/ClientSelectionTask.cs @@ -0,0 +1,25 @@ +using EftPatchHelper.Helpers; +using EftPatchHelper.Interfaces; +using EftPatchHelper.Model; + +namespace EftPatchHelper.Tasks +{ + public class ClientSelectionTask : IClientSelectionTask + { + private Settings _settings; + private Options _options; + private EftClientSelector _clientSelector; + + public ClientSelectionTask(Settings settings, Options options, EftClientSelector clientSelector) + { + _settings = settings; + _options = options; + _clientSelector = clientSelector; + } + + public bool Run() + { + + } + } +} diff --git a/EftPatchHelper/EftPatchHelper/Tasks/StartupSettingsTask.cs b/EftPatchHelper/EftPatchHelper/Tasks/StartupSettingsTask.cs new file mode 100644 index 0000000..151038a --- /dev/null +++ b/EftPatchHelper/EftPatchHelper/Tasks/StartupSettingsTask.cs @@ -0,0 +1,77 @@ +using EftPatchHelper.Extensions; +using EftPatchHelper.Interfaces; +using EftPatchHelper.Model; +using Spectre.Console; + +namespace EftPatchHelper.Tasks +{ + public class StartupSettingsTask : ISettingsTask + { + private Settings? _settings { get; set; } + private Options _options { get; set; } + public StartupSettingsTask(Settings? settings, Options options) + { + _settings = settings; + _options = options; + } + + public void PrintSummary() + { + AnsiConsole.WriteLine(); + + // show some settings information + Table settingsTable = new Table() + .Alignment(Justify.Center) + .HorizontalBorder() + .HideHeaders() + .BorderStyle(Style.Parse("blue")) + .AddColumn("Data") + .AddColumn("Value") + .AddRow("Current target version", $"[purple]{_settings?.TargetEftVersion}[/]") + .AddRow("Prep folder path", $"[purple]{_settings?.PrepFolderPath}[/]") + .AddRow("Backup folder path", $"[purple]{_settings?.BackupFolderPath}[/]"); + + AnsiConsole.Write(settingsTable); + + AnsiConsole.WriteLine(); + } + + private bool ValidateSettings() + { + // check settings file exists + if (_settings == null) + { + _settings = new Settings(); + _settings.Save(); + + AnsiConsole.MarkupLine($"Settings file was create here: \n[blue]{Settings.settingsFile}[/]\n\nPlease update it and try again."); + return false; + } + + // validate settings + if (!_settings.Validate()) + { + AnsiConsole.MarkupLine($"[red]Settings file seems to be missing some information, please fix it[/]\n\nPath to file:\n[blue]{Settings.settingsFile}[/]\n\n"); + return false; + } + + return true; + } + + private void ConfirmOptions() + { + _options.PromptToOverwriteDirectories = new ConfirmationPrompt("Prompt to overwrite directories?").Show(AnsiConsole.Console); + } + + public bool Run() + { + ValidateSettings().ValidateOrExit(); + + ConfirmOptions(); + + PrintSummary(); + + return true; + } + } +} \ No newline at end of file diff --git a/EftPatchHelper/EftPatchHelper/settings.json b/EftPatchHelper/EftPatchHelper/settings.json new file mode 100644 index 0000000..2fe6fa8 --- /dev/null +++ b/EftPatchHelper/EftPatchHelper/settings.json @@ -0,0 +1,9 @@ +{ + "targetEftVersion": "C:\\users\\johno\\desktop\\tmp", + "prepFolderPath": "C:\\users\\johno\\desktop\\tmp", + "backupFolderPath": "C:\\users\\johno\\desktop\\tmp", + "liveEftPath": "C:\\users\\johno\\desktop\\tmp", + "patcherExePath": "C:\\users\\johno\\desktop\\tmp", + "autoZip": true, + "autoClose": false +} \ No newline at end of file