Merge pull request 'more-logging' (#16) from waffle.lord/SPT-AKI-Installer:more-logging into master

Reviewed-on: CWX/SPT-AKI-Installer#16
This commit is contained in:
IsWaffle 2023-05-22 23:16:36 +00:00
commit 5d8b8851a1
7 changed files with 57 additions and 10 deletions

View File

@ -25,7 +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}"); Log.Information($"Using cached file: {cacheFile.Name} - Hash: {expectedHash}");
return true; return true;
} }
@ -119,8 +119,9 @@ namespace SPTInstaller.Aki.Helper
return result.Succeeded ? cacheFile : null; return result.Succeeded ? cacheFile : null;
} }
catch catch(Exception ex)
{ {
Log.Error(ex, $"Error while getting file: {fileName}");
return null; return null;
} }
} }
@ -135,8 +136,9 @@ namespace SPTInstaller.Aki.Helper
return result.Succeeded ? cacheFile : null; return result.Succeeded ? cacheFile : null;
} }
catch catch(Exception ex)
{ {
Log.Error(ex, $"Error while getting file: {fileName}");
return null; return null;
} }
} }

View File

@ -3,6 +3,7 @@ using Serilog;
using SPTInstaller.Models; using SPTInstaller.Models;
using System; using System;
using System.IO; using System.IO;
using System.Text.RegularExpressions;
namespace SPTInstaller.Aki.Helper namespace SPTInstaller.Aki.Helper
{ {
@ -49,6 +50,19 @@ namespace SPTInstaller.Aki.Helper
} }
} }
public static string GetRedactedPath(string path)
{
var nameMatched = Regex.Match(path, @".:\\[uU]sers\\(?<NAME>[^\\]+)");
if (nameMatched.Success)
{
var name = nameMatched.Groups["NAME"].Value;
return path.Replace(name, "-REDACTED-");
}
return path;
}
public static Result CopyDirectoryWithProgress(DirectoryInfo sourceDir, DirectoryInfo targetDir, IProgress<double> progress = null) => public static Result CopyDirectoryWithProgress(DirectoryInfo sourceDir, DirectoryInfo targetDir, IProgress<double> progress = null) =>
CopyDirectoryWithProgress(sourceDir, targetDir, (msg, prog) => progress?.Report(prog)); CopyDirectoryWithProgress(sourceDir, targetDir, (msg, prog) => progress?.Report(prog));

View File

@ -1,4 +1,5 @@
using Splat; using Serilog;
using Splat;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -76,7 +77,11 @@ namespace SPTInstaller.Helpers
var service = Locator.Current.GetService(type); var service = Locator.Current.GetService(type);
if (service == null) if (service == null)
throw new InvalidOperationException($"Could not locate service of type '{type.Name}'"); {
var message = $"Could not locate service of type '{type.Name}'";
Log.Error(message);
throw new InvalidOperationException(message);
}
return service; return service;
} }
@ -92,7 +97,11 @@ namespace SPTInstaller.Helpers
var service = Locator.Current.GetService<T>(); var service = Locator.Current.GetService<T>();
if (service == null) if (service == null)
throw new InvalidOperationException($"Could not locate service of type '{nameof(T)}'"); {
var message = $"Could not locate service of type '{nameof(T)}'";
Log.Error(message);
throw new InvalidOperationException(message);
}
return service; return service;
} }
@ -108,7 +117,11 @@ namespace SPTInstaller.Helpers
var services = Locator.Current.GetServices<T>().ToArray(); var services = Locator.Current.GetServices<T>().ToArray();
if (services == null || services.Count() == 0) if (services == null || services.Count() == 0)
throw new InvalidOperationException($"Could not locate service of type '{nameof(T)}'"); {
var message = $"Could not locate service of type '{nameof(T)}'";
Log.Error(message);
throw new InvalidOperationException(message);
}
return services; return services;
} }

View File

@ -17,7 +17,7 @@ namespace SPTInstaller.Installer_Tasks
public override async Task<IResult> TaskOperation() public override async Task<IResult> TaskOperation()
{ {
SetStatus("Initializing", ""); SetStatus("Initializing", $"Target Install Path: {FileHelper.GetRedactedPath(_data.TargetInstallPath)}");
_data.OriginalGamePath = PreCheckHelper.DetectOriginalGamePath(); _data.OriginalGamePath = PreCheckHelper.DetectOriginalGamePath();
@ -26,6 +26,8 @@ namespace SPTInstaller.Installer_Tasks
return Result.FromError("EFT IS NOT INSTALLED!"); return Result.FromError("EFT IS NOT INSTALLED!");
} }
SetStatus(null, $"Installed EFT Game Path: {FileHelper.GetRedactedPath(_data.OriginalGamePath)}");
var result = PreCheckHelper.DetectOriginalGameVersion(_data.OriginalGamePath); var result = PreCheckHelper.DetectOriginalGameVersion(_data.OriginalGamePath);
if (!result.Succeeded) if (!result.Succeeded)
@ -35,6 +37,8 @@ namespace SPTInstaller.Installer_Tasks
_data.OriginalGameVersion = result.Message; _data.OriginalGameVersion = result.Message;
SetStatus(null, $"Installed EFT Game Version: {_data.OriginalGameVersion}");
if (_data.OriginalGamePath == null) if (_data.OriginalGamePath == null)
{ {
return Result.FromError("Unable to find original EFT 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");

View File

@ -9,6 +9,8 @@
<PackageIcon>icon.ico</PackageIcon> <PackageIcon>icon.ico</PackageIcon>
<ApplicationIcon>Assets\icon.ico</ApplicationIcon> <ApplicationIcon>Assets\icon.ico</ApplicationIcon>
<Configurations>Debug;Release;TEST</Configurations> <Configurations>Debug;Release;TEST</Configurations>
<AssemblyVersion>2.2</AssemblyVersion>
<FileVersion>2.2</FileVersion>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View File

@ -2,6 +2,7 @@
using ReactiveUI; using ReactiveUI;
using Serilog; using Serilog;
using System; using System;
using System.Reflection;
namespace SPTInstaller.ViewModels namespace SPTInstaller.ViewModels
{ {
@ -10,9 +11,20 @@ namespace SPTInstaller.ViewModels
public RoutingState Router { get; } = new RoutingState(); public RoutingState Router { get; } = new RoutingState();
public ViewModelActivator Activator { get; } = new ViewModelActivator(); public ViewModelActivator Activator { get; } = new ViewModelActivator();
private string _title;
public string Title
{
get => _title;
set => this.RaiseAndSetIfChanged(ref _title, value);
}
public MainWindowViewModel() public MainWindowViewModel()
{ {
Log.Information("========= LAUNCHER STARTED ========="); string? version = Assembly.GetExecutingAssembly().GetName()?.Version?.ToString();
Title = $"SPT Installer {"v" + version ?? "--unknown version--"}";
Log.Information($"========= {Title} Started =========");
Log.Information(Environment.OSVersion.VersionString); Log.Information(Environment.OSVersion.VersionString);
Router.Navigate.Execute(new PreChecksViewModel(this)); Router.Navigate.Execute(new PreChecksViewModel(this));

View File

@ -27,7 +27,7 @@
</Design.DataContext> </Design.DataContext>
<Grid RowDefinitions="AUTO,*"> <Grid RowDefinitions="AUTO,*">
<cc:TitleBar Title="SPT Installer" <cc:TitleBar Title="{Binding Title}"
XButtonCommand="{Binding CloseCommand}" XButtonCommand="{Binding CloseCommand}"
MinButtonCommand="{Binding MinimizeCommand}" MinButtonCommand="{Binding MinimizeCommand}"
/> />