get release info, log install path before errors

This commit is contained in:
IsWaffle 2023-10-18 20:39:38 -04:00
parent 2202a8a492
commit 75e5cd914e
2 changed files with 55 additions and 7 deletions

View File

@ -22,7 +22,7 @@
<Label Grid.Column="1" <Label Grid.Column="1"
Content="{Binding PreCheckName, RelativeSource={RelativeSource AncestorType=UserControl}}" Content="{Binding PreCheckName, RelativeSource={RelativeSource AncestorType=UserControl}}"
Classes.bold="{Binding State, RelativeSource={RelativeSource AncestorType=UserControl} Classes.bold="{Binding State, RelativeSource={RelativeSource AncestorType=UserControl},
Converter={StaticResource ResourceKey=IsStateConverter}, Converter={StaticResource ResourceKey=IsStateConverter},
ConverterParameter=Running}" ConverterParameter=Running}"
/> />

View File

@ -5,6 +5,8 @@ using System.Windows.Input;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Threading; using Avalonia.Threading;
using DialogHostAvalonia; using DialogHostAvalonia;
using Gitea.Api;
using Gitea.Client;
using ReactiveUI; using ReactiveUI;
using Serilog; using Serilog;
using SPTInstaller.Controllers; using SPTInstaller.Controllers;
@ -25,7 +27,7 @@ public class PreChecksViewModel : ViewModelBase
public ICommand DismissUpdateCommand { get; set; } public ICommand DismissUpdateCommand { get; set; }
public InstallerUpdateInfo UpdateInfo { get; set; } = new InstallerUpdateInfo(); public InstallerUpdateInfo UpdateInfo { get; set; } = new();
private string _installPath; private string _installPath;
public string InstallPath public string InstallPath
@ -33,6 +35,14 @@ public class PreChecksViewModel : ViewModelBase
get => _installPath; get => _installPath;
set => this.RaiseAndSetIfChanged(ref _installPath, value); set => this.RaiseAndSetIfChanged(ref _installPath, value);
} }
private string _installButtonText;
public string InstallButtonText
{
get => _installButtonText;
set => this.RaiseAndSetIfChanged(ref _installButtonText, value);
}
private bool _allowInstall; private bool _allowInstall;
public bool AllowInstall public bool AllowInstall
@ -61,12 +71,22 @@ public class PreChecksViewModel : ViewModelBase
get => _cacheCheckState; get => _cacheCheckState;
set => this.RaiseAndSetIfChanged(ref _cacheCheckState, value); set => this.RaiseAndSetIfChanged(ref _cacheCheckState, value);
} }
private StatusSpinner.SpinnerState _installButtonCheckState;
public StatusSpinner.SpinnerState InstallButtonCheckState
{
get => _installButtonCheckState;
set => this.RaiseAndSetIfChanged(ref _installButtonCheckState, value);
}
public PreChecksViewModel(IScreen host) : base(host) public PreChecksViewModel(IScreen host) : base(host)
{ {
var data = ServiceHelper.Get<InternalData?>(); var data = ServiceHelper.Get<InternalData?>();
var installer = ServiceHelper.Get<InstallController?>(); var installer = ServiceHelper.Get<InstallController?>();
InstallButtonText = "Please wait ...";
InstallButtonCheckState = StatusSpinner.SpinnerState.Pending;
if (data == null || installer == null) if (data == null || installer == null)
{ {
NavigateTo(new MessageViewModel(HostScreen, Result.FromError("Failed to get required service for prechecks"))); NavigateTo(new MessageViewModel(HostScreen, Result.FromError("Failed to get required service for prechecks")));
@ -74,6 +94,11 @@ public class PreChecksViewModel : ViewModelBase
} }
data.OriginalGamePath = PreCheckHelper.DetectOriginalGamePath(); data.OriginalGamePath = PreCheckHelper.DetectOriginalGamePath();
data.TargetInstallPath = Environment.CurrentDirectory;
InstallPath = data.TargetInstallPath;
Log.Information($"Install Path: {FileHelper.GetRedactedPath(InstallPath)}");
#if !TEST #if !TEST
if (data.OriginalGamePath == null) if (data.OriginalGamePath == null)
@ -83,11 +108,6 @@ public class PreChecksViewModel : ViewModelBase
} }
#endif #endif
data.TargetInstallPath = Environment.CurrentDirectory;
InstallPath = data.TargetInstallPath;
Log.Information($"Install Path: {FileHelper.GetRedactedPath(InstallPath)}");
if (data.OriginalGamePath == data.TargetInstallPath) if (data.OriginalGamePath == data.TargetInstallPath)
{ {
Log.CloseAndFlush(); Log.CloseAndFlush();
@ -156,10 +176,38 @@ public class PreChecksViewModel : ViewModelBase
Task.Run(async () => Task.Run(async () =>
{ {
// run prechecks
var result = await installer.RunPreChecks(); var result = await installer.RunPreChecks();
// check for updates
await UpdateInfo.CheckForUpdates(Assembly.GetExecutingAssembly().GetName()?.Version); await UpdateInfo.CheckForUpdates(Assembly.GetExecutingAssembly().GetName()?.Version);
// get latest spt version
InstallButtonText = "Getting latest release ...";
InstallButtonCheckState = StatusSpinner.SpinnerState.Running;
var repo = new RepositoryApi(Configuration.Default);
var akiRepoReleases = await repo.RepoListReleasesAsync("SPT-AKI", "Stable-releases");
if (akiRepoReleases == null || akiRepoReleases.Count == 0)
{
InstallButtonText = "Could not get SPT releases from repo";
InstallButtonCheckState = StatusSpinner.SpinnerState.Error;
return;
}
var latestAkiRelease = akiRepoReleases.FindAll(x => !x.Prerelease)[0];
if (latestAkiRelease == null)
{
InstallButtonText = "Could not find the latest SPT release";
InstallButtonCheckState = StatusSpinner.SpinnerState.Error;
return;
}
InstallButtonText = $"Start Install: SPT v{latestAkiRelease.TagName}";
InstallButtonCheckState = StatusSpinner.SpinnerState.OK;
AllowDetailsButton = true; AllowDetailsButton = true;
AllowInstall = result.Succeeded; AllowInstall = result.Succeeded;
}); });