bug fixes, ui tweaks, additional logging

This commit is contained in:
IsWaffle 2023-05-18 20:04:00 -04:00
parent 229ffad552
commit 18a217a974
11 changed files with 65 additions and 33 deletions

View File

@ -1,4 +1,5 @@
using HttpClientProgress; using HttpClientProgress;
using Serilog;
using SPTInstaller.Models; using SPTInstaller.Models;
using System; using System;
using System.IO; using System.IO;
@ -24,6 +25,7 @@ namespace SPTInstaller.Aki.Helper
{ {
if (expectedHash != null && FileHashHelper.CheckHash(cacheFile, expectedHash)) if (expectedHash != null && FileHashHelper.CheckHash(cacheFile, expectedHash))
{ {
Log.Information($"Using cached file: {cacheFile.Name}");
return true; return true;
} }

View File

@ -24,7 +24,7 @@ namespace SPTInstaller.Installer_Tasks
var originalGameDirInfo = new DirectoryInfo(_data.OriginalGamePath); var originalGameDirInfo = new DirectoryInfo(_data.OriginalGamePath);
var targetInstallDirInfo = new DirectoryInfo(_data.TargetInstallPath); 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); });
} }
} }
} }

View File

@ -90,7 +90,7 @@ namespace SPTInstaller.Installer_Tasks
public override async Task<IResult> TaskOperation() public override async Task<IResult> TaskOperation()
{ {
var progress = new Progress<double>((d) => { SetStatus("", "", (int)Math.Floor(d)); }); var progress = new Progress<double>((d) => { SetStatus(null, null, (int)Math.Floor(d)); });
if (_data.PatchNeeded) if (_data.PatchNeeded)
{ {
@ -101,7 +101,7 @@ namespace SPTInstaller.Installer_Tasks
return buildResult; return buildResult;
} }
SetStatus("", "", 0); SetStatus(null, null, 0);
var patcherDownloadRresult = await DownloadPatcherFromMirrors(progress); 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); _data.AkiZipInfo = await DownloadCacheHelper.GetOrDownloadFileAsync("sptaki.zip", _data.AkiReleaseDownloadLink, progress, _data.AkiReleaseHash);

View File

@ -17,6 +17,8 @@ namespace SPTInstaller.Installer_Tasks
public override async Task<IResult> TaskOperation() public override async Task<IResult> TaskOperation()
{ {
SetStatus("Initializing", "");
_data.OriginalGamePath = PreCheckHelper.DetectOriginalGamePath(); _data.OriginalGamePath = PreCheckHelper.DetectOriginalGamePath();
if (_data.OriginalGamePath == null) if (_data.OriginalGamePath == null)
@ -35,7 +37,7 @@ namespace SPTInstaller.Installer_Tasks
if (_data.OriginalGamePath == null) 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) if (_data.OriginalGamePath == _data.TargetInstallPath)
@ -45,10 +47,9 @@ namespace SPTInstaller.Installer_Tasks
if (File.Exists(Path.Join(_data.TargetInstallPath, "EscapeFromTarkov.exe"))) 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}"); return Result.FromSuccess($"Current Game Version: {_data.OriginalGameVersion}");
} }
} }

View File

@ -75,7 +75,7 @@ namespace SPTInstaller.Installer_Tasks
status += " - Patch Available"; status += " - Patch Available";
} }
SetStatus("", status); SetStatus(null, status);
return Result.FromSuccess(status); return Result.FromSuccess(status);
} }

View File

@ -25,7 +25,7 @@ namespace SPTInstaller.Installer_Tasks
var patcherEXE = new FileInfo(Path.Join(_data.TargetInstallPath, "patcher.exe")); var patcherEXE = new FileInfo(Path.Join(_data.TargetInstallPath, "patcher.exe"));
var progress = new Progress<double>((d) => { SetStatus("", "", (int)Math.Floor(d)); }); var progress = new Progress<double>((d) => { SetStatus(null, null, (int)Math.Floor(d)); });
if (_data.PatchNeeded) if (_data.PatchNeeded)

View File

@ -91,15 +91,15 @@ namespace SPTInstaller.Models
/// <summary> /// <summary>
/// Update the status details of the task /// Update the status details of the task
/// </summary> /// </summary>
/// <param name="message">The main message to display. Not updated if empty</param> /// <param name="message">The main message to display. Not updated if null</param>
/// <param name="details">The details of the task. Not updated if empty</param> /// <param name="details">The details of the task. Not updated if null</param>
/// <param name="progress">Progress of the task. Not empty if null. Overrides progressStyle if a non-null value is supplied</param> /// <param name="progress">Progress of the task. Overrides progressStyle if a non-null value is supplied</param>
/// <param name="progressStyle">The style of the progress bar</param> /// <param name="progressStyle">The style of the progress bar</param>
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} <===>"); Log.Information($" <===> {message} <===>");
} }
@ -107,9 +107,9 @@ namespace SPTInstaller.Models
StatusMessage = message; StatusMessage = message;
} }
if(!string.IsNullOrWhiteSpace(details) && details != StatusDetails) if(details != null && details != StatusDetails)
{ {
if (!noLog) if (!noLog && !string.IsNullOrWhiteSpace(details))
{ {
Log.Information(details); Log.Information(details);
} }

View File

@ -31,7 +31,7 @@ namespace SPTInstaller.ViewModels
{ {
var result = await installer.RunTasks(); var result = await installer.RunTasks();
NavigateTo(new MessageViewModel(HostScreen, result.Message)); NavigateTo(new MessageViewModel(HostScreen, result));
}); });
} }
} }

View File

@ -1,12 +1,20 @@
using Avalonia; using Avalonia;
using ReactiveUI; using ReactiveUI;
using Serilog; using Serilog;
using SPTInstaller.Interfaces;
using System.Windows.Input; using System.Windows.Input;
namespace SPTInstaller.ViewModels namespace SPTInstaller.ViewModels
{ {
public class MessageViewModel : ViewModelBase public class MessageViewModel : ViewModelBase
{ {
private bool _HasErrors;
public bool HasErrors
{
get => _HasErrors;
set => this.RaiseAndSetIfChanged(ref _HasErrors, value);
}
private string _Message; private string _Message;
public 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; Message = result.Message;
Log.Information(message);
if(result.Succeeded)
{
Log.Information(Message);
return;
}
HasErrors = true;
Log.Error(Message);
} }
} }
} }

View File

@ -30,7 +30,7 @@ namespace SPTInstaller.ViewModels
if(data == null || installer == null) 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; return;
} }
@ -51,7 +51,7 @@ namespace SPTInstaller.ViewModels
if(!result.Succeeded) if(!result.Succeeded)
{ {
//if a required precheck fails, abort to message view //if a required precheck fails, abort to message view
NavigateTo(new MessageViewModel(HostScreen ,result.Message)); NavigateTo(new MessageViewModel(HostScreen ,result));
} }
}); });
} }

View File

@ -3,24 +3,37 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="SPTInstaller.Views.MessageView"> x:Class="SPTInstaller.Views.MessageView"
<Grid ColumnDefinitions="*,AUTO,*" RowDefinitions="*,AUTO,*"> >
<UserControl.Styles>
<Style Selector="Grid.error">
<Setter Property="Background" Value="#330000"/>
</Style>
<Style Selector="Label.error">
<Setter Property="Foreground" Value="Crimson"/>
</Style>
<StackPanel Grid.Row="1" Grid.Column="1" Spacing="20"> </UserControl.Styles>
<Label Content="{Binding Message}" FontSize="18" <Grid ColumnDefinitions="*,AUTO,*" RowDefinitions="*,AUTO,20,AUTO,*"
HorizontalAlignment="Center" Classes.error="{Binding HasErrors}">
<Label Grid.Column="1" Grid.Row="1"
Classes.error="{Binding HasErrors}">
<TextBlock Text="{Binding Message}" FontSize="18"
TextWrapping="Wrap"
MaxWidth="500"
HorizontalAlignment="Center"
/> />
</Label>
<Button Content="Close" Command="{Binding CloseCommand}" <Button Grid.Column="1" Grid.Row="3"
Content="Close" Command="{Binding CloseCommand}"
FontSize="15" FontWeight="SemiBold" FontSize="15" FontWeight="SemiBold"
Classes="yellow" Classes.yellow="{Binding !HasErrors}"
HorizontalAlignment="Center" HorizontalAlignment="Center"
VerticalContentAlignment="Center" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" HorizontalContentAlignment="Center"
Padding="20 10" Padding="20 10"
/> />
</StackPanel>
</Grid> </Grid>
</UserControl> </UserControl>