all kinds of stuff

This commit is contained in:
IsWaffle 2022-05-25 08:43:12 -04:00
parent b243a150f5
commit 21bc6e2e4a
11 changed files with 109 additions and 178 deletions

View File

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

View File

@ -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<string>("Press [blue]enter[/] to close ...").AllowEmpty());
Environment.Exit(0);

View File

@ -47,7 +47,7 @@ namespace EftPatchHelper.Helpers
fsInfo.Refresh();
if(!fsInfo.Exists)
if (!fsInfo.Exists)
{
AnsiConsole.MarkupLine($"[blue]INFO:[/] [gray]Deleting {fsInfo.Name} ...[/] [green]OK[/]");
continue;

View File

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

View File

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

View File

@ -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
/// </summary>
/// <returns>Returns true if the task succeeded, otherwise false</returns>
public bool Run();
public void Run();
}
}

View File

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

View File

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

View File

@ -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<Program>().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<ISettingsTask, StartupSettingsTask>();
services.AddTransient<IClientSelectionTask, ClientSelectionTask>();
services.AddTransient<IFileProcessingTasks, FileProcessingTasks>();
services.AddTransient<IPatchGenTasks, PatchGenTasks>();
services.AddTransient<IPatchTestingTasks, PatchTestingTasks>();
services.AddTransient<Program>();
})
.ConfigureAppConfiguration((_, config) =>
@ -67,109 +83,3 @@ namespace EftPatchHelper
}
}
}
//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();

View File

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

View File

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