From 18a217a97413837baf53f32905c8c3672c315b7f Mon Sep 17 00:00:00 2001 From: "waffle.lord" Date: Thu, 18 May 2023 20:04:00 -0400 Subject: [PATCH] bug fixes, ui tweaks, additional logging --- SPTInstaller/Helpers/DownloadCacheHelper.cs | 2 ++ .../Installer Tasks/CopyClientTask.cs | 2 +- SPTInstaller/Installer Tasks/DownloadTask.cs | 6 ++-- .../Installer Tasks/IntializationTask.cs | 7 ++-- .../Installer Tasks/ReleaseCheckTask.cs | 2 +- .../Installer Tasks/SetupClientTask.cs | 2 +- SPTInstaller/Models/InstallerTaskBase.cs | 16 ++++----- SPTInstaller/ViewModels/InstallViewModel.cs | 2 +- SPTInstaller/ViewModels/MessageViewModel.cs | 22 +++++++++++-- SPTInstaller/ViewModels/PreChecksViewModel.cs | 4 +-- SPTInstaller/Views/MessageView.axaml | 33 +++++++++++++------ 11 files changed, 65 insertions(+), 33 deletions(-) diff --git a/SPTInstaller/Helpers/DownloadCacheHelper.cs b/SPTInstaller/Helpers/DownloadCacheHelper.cs index 0ab712c..59e0ae7 100644 --- a/SPTInstaller/Helpers/DownloadCacheHelper.cs +++ b/SPTInstaller/Helpers/DownloadCacheHelper.cs @@ -1,4 +1,5 @@ using HttpClientProgress; +using Serilog; using SPTInstaller.Models; using System; using System.IO; @@ -24,6 +25,7 @@ namespace SPTInstaller.Aki.Helper { if (expectedHash != null && FileHashHelper.CheckHash(cacheFile, expectedHash)) { + Log.Information($"Using cached file: {cacheFile.Name}"); return true; } diff --git a/SPTInstaller/Installer Tasks/CopyClientTask.cs b/SPTInstaller/Installer Tasks/CopyClientTask.cs index 400ce71..1783959 100644 --- a/SPTInstaller/Installer Tasks/CopyClientTask.cs +++ b/SPTInstaller/Installer Tasks/CopyClientTask.cs @@ -24,7 +24,7 @@ namespace SPTInstaller.Installer_Tasks var originalGameDirInfo = new DirectoryInfo(_data.OriginalGamePath); var targetInstallDirInfo = new DirectoryInfo(_data.TargetInstallPath); - return FileHelper.CopyDirectoryWithProgress(originalGameDirInfo, targetInstallDirInfo, (message, progress) => { SetStatus($"Copying Client Files", message, progress, null, true); }); + return FileHelper.CopyDirectoryWithProgress(originalGameDirInfo, targetInstallDirInfo, (message, progress) => { SetStatus(null, message, progress, null, true); }); } } } diff --git a/SPTInstaller/Installer Tasks/DownloadTask.cs b/SPTInstaller/Installer Tasks/DownloadTask.cs index 3bddbaa..8a91e2e 100644 --- a/SPTInstaller/Installer Tasks/DownloadTask.cs +++ b/SPTInstaller/Installer Tasks/DownloadTask.cs @@ -90,7 +90,7 @@ namespace SPTInstaller.Installer_Tasks public override async Task TaskOperation() { - var progress = new Progress((d) => { SetStatus("", "", (int)Math.Floor(d)); }); + var progress = new Progress((d) => { SetStatus(null, null, (int)Math.Floor(d)); }); if (_data.PatchNeeded) { @@ -101,7 +101,7 @@ namespace SPTInstaller.Installer_Tasks return buildResult; } - SetStatus("", "", 0); + SetStatus(null, null, 0); var patcherDownloadRresult = await DownloadPatcherFromMirrors(progress); @@ -111,7 +111,7 @@ namespace SPTInstaller.Installer_Tasks } } - SetStatus("Downloading SPT-AKI", "", 0); + SetStatus("Downloading SPT-AKI", _data.AkiReleaseDownloadLink, 0); _data.AkiZipInfo = await DownloadCacheHelper.GetOrDownloadFileAsync("sptaki.zip", _data.AkiReleaseDownloadLink, progress, _data.AkiReleaseHash); diff --git a/SPTInstaller/Installer Tasks/IntializationTask.cs b/SPTInstaller/Installer Tasks/IntializationTask.cs index b91f68b..ed1635f 100644 --- a/SPTInstaller/Installer Tasks/IntializationTask.cs +++ b/SPTInstaller/Installer Tasks/IntializationTask.cs @@ -17,6 +17,8 @@ namespace SPTInstaller.Installer_Tasks public override async Task TaskOperation() { + SetStatus("Initializing", ""); + _data.OriginalGamePath = PreCheckHelper.DetectOriginalGamePath(); if (_data.OriginalGamePath == null) @@ -35,7 +37,7 @@ namespace SPTInstaller.Installer_Tasks if (_data.OriginalGamePath == null) { - return Result.FromError("Unable to find EFT OG directory, please make sure EFT is installed. Please also run EFT once"); + return Result.FromError("Unable to find original EFT directory, please make sure EFT is installed. Please also run EFT once"); } if (_data.OriginalGamePath == _data.TargetInstallPath) @@ -45,10 +47,9 @@ namespace SPTInstaller.Installer_Tasks if (File.Exists(Path.Join(_data.TargetInstallPath, "EscapeFromTarkov.exe"))) { - return Result.FromError("Installer is located in a Folder that has existing Game Files. Please make sure the installer is in a fresh folder as per the guide"); + return Result.FromError("Installer is located in a folder that has existing game files. Please make sure the installer is in a fresh folder as per the guide"); } - return Result.FromSuccess($"Current Game Version: {_data.OriginalGameVersion}"); } } diff --git a/SPTInstaller/Installer Tasks/ReleaseCheckTask.cs b/SPTInstaller/Installer Tasks/ReleaseCheckTask.cs index 9fc5f89..edddeda 100644 --- a/SPTInstaller/Installer Tasks/ReleaseCheckTask.cs +++ b/SPTInstaller/Installer Tasks/ReleaseCheckTask.cs @@ -75,7 +75,7 @@ namespace SPTInstaller.Installer_Tasks status += " - Patch Available"; } - SetStatus("", status); + SetStatus(null, status); return Result.FromSuccess(status); } diff --git a/SPTInstaller/Installer Tasks/SetupClientTask.cs b/SPTInstaller/Installer Tasks/SetupClientTask.cs index 41d284e..e577659 100644 --- a/SPTInstaller/Installer Tasks/SetupClientTask.cs +++ b/SPTInstaller/Installer Tasks/SetupClientTask.cs @@ -25,7 +25,7 @@ namespace SPTInstaller.Installer_Tasks var patcherEXE = new FileInfo(Path.Join(_data.TargetInstallPath, "patcher.exe")); - var progress = new Progress((d) => { SetStatus("", "", (int)Math.Floor(d)); }); + var progress = new Progress((d) => { SetStatus(null, null, (int)Math.Floor(d)); }); if (_data.PatchNeeded) diff --git a/SPTInstaller/Models/InstallerTaskBase.cs b/SPTInstaller/Models/InstallerTaskBase.cs index 56d7bb9..eb939cb 100644 --- a/SPTInstaller/Models/InstallerTaskBase.cs +++ b/SPTInstaller/Models/InstallerTaskBase.cs @@ -91,15 +91,15 @@ namespace SPTInstaller.Models /// /// Update the status details of the task /// - /// The main message to display. Not updated if empty - /// The details of the task. Not updated if empty - /// Progress of the task. Not empty if null. Overrides progressStyle if a non-null value is supplied + /// The main message to display. Not updated if null + /// The details of the task. Not updated if null + /// Progress of the task. Overrides progressStyle if a non-null value is supplied /// The style of the progress bar - public void SetStatus(string message, string details, int? progress = null, ProgressStyle? progressStyle = null, bool noLog = false) + public void SetStatus(string? message, string? details, int? progress = null, ProgressStyle? progressStyle = null, bool noLog = false) { - if(!string.IsNullOrWhiteSpace(message) && message != StatusMessage) + if(message != null && message != StatusMessage) { - if (!noLog) + if (!noLog && !string.IsNullOrWhiteSpace(message)) { Log.Information($" <===> {message} <===>"); } @@ -107,9 +107,9 @@ namespace SPTInstaller.Models StatusMessage = message; } - if(!string.IsNullOrWhiteSpace(details) && details != StatusDetails) + if(details != null && details != StatusDetails) { - if (!noLog) + if (!noLog && !string.IsNullOrWhiteSpace(details)) { Log.Information(details); } diff --git a/SPTInstaller/ViewModels/InstallViewModel.cs b/SPTInstaller/ViewModels/InstallViewModel.cs index d4fc310..80d0870 100644 --- a/SPTInstaller/ViewModels/InstallViewModel.cs +++ b/SPTInstaller/ViewModels/InstallViewModel.cs @@ -31,7 +31,7 @@ namespace SPTInstaller.ViewModels { var result = await installer.RunTasks(); - NavigateTo(new MessageViewModel(HostScreen, result.Message)); + NavigateTo(new MessageViewModel(HostScreen, result)); }); } } diff --git a/SPTInstaller/ViewModels/MessageViewModel.cs b/SPTInstaller/ViewModels/MessageViewModel.cs index d2a6041..7591382 100644 --- a/SPTInstaller/ViewModels/MessageViewModel.cs +++ b/SPTInstaller/ViewModels/MessageViewModel.cs @@ -1,12 +1,20 @@ using Avalonia; using ReactiveUI; using Serilog; +using SPTInstaller.Interfaces; using System.Windows.Input; namespace SPTInstaller.ViewModels { public class MessageViewModel : ViewModelBase { + private bool _HasErrors; + public bool HasErrors + { + get => _HasErrors; + set => this.RaiseAndSetIfChanged(ref _HasErrors, value); + } + private string _Message; public string Message { @@ -22,10 +30,18 @@ namespace SPTInstaller.ViewModels } }); - public MessageViewModel(IScreen Host, string message) : base(Host) + public MessageViewModel(IScreen Host, IResult result) : base(Host) { - Message = message; - Log.Information(message); + Message = result.Message; + + if(result.Succeeded) + { + Log.Information(Message); + return; + } + + HasErrors = true; + Log.Error(Message); } } } diff --git a/SPTInstaller/ViewModels/PreChecksViewModel.cs b/SPTInstaller/ViewModels/PreChecksViewModel.cs index c0ac9b0..4e8dbbf 100644 --- a/SPTInstaller/ViewModels/PreChecksViewModel.cs +++ b/SPTInstaller/ViewModels/PreChecksViewModel.cs @@ -30,7 +30,7 @@ namespace SPTInstaller.ViewModels if(data == null || installer == null) { - NavigateTo(new MessageViewModel(HostScreen, "Failed to get required service for prechecks")); + NavigateTo(new MessageViewModel(HostScreen, Result.FromError("Failed to get required service for prechecks"))); return; } @@ -51,7 +51,7 @@ namespace SPTInstaller.ViewModels if(!result.Succeeded) { //if a required precheck fails, abort to message view - NavigateTo(new MessageViewModel(HostScreen ,result.Message)); + NavigateTo(new MessageViewModel(HostScreen ,result)); } }); } diff --git a/SPTInstaller/Views/MessageView.axaml b/SPTInstaller/Views/MessageView.axaml index 79e7ac7..a4f8d76 100644 --- a/SPTInstaller/Views/MessageView.axaml +++ b/SPTInstaller/Views/MessageView.axaml @@ -3,24 +3,37 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" - x:Class="SPTInstaller.Views.MessageView"> - + x:Class="SPTInstaller.Views.MessageView" + > + + + - + -