Implement pre-flight checks

This commit is contained in:
Timothy Baldridge 2022-07-13 15:22:05 -06:00
parent 6671fcb533
commit 905eca4ea7
3 changed files with 35 additions and 6 deletions

View File

@ -21,6 +21,7 @@ using Wabbajack.Compiler;
using Wabbajack.DTOs;
using Wabbajack.DTOs.JsonConverters;
using Wabbajack.Models;
using Wabbajack.Networking.WabbajackClientApi;
using Wabbajack.Paths;
using Wabbajack.Paths.IO;
using Wabbajack.Services.OSIntegrated;
@ -45,6 +46,7 @@ namespace Wabbajack
private readonly ILogger<CompilerVM> _logger;
private readonly ResourceMonitor _resourceMonitor;
private readonly CompilerSettingsInferencer _inferencer;
private readonly Client _wjClient;
[Reactive]
public CompilerState State { get; set; }
@ -95,7 +97,7 @@ namespace Wabbajack
public CompilerVM(ILogger<CompilerVM> logger, DTOSerializer dtos, SettingsManager settingsManager,
IServiceProvider serviceProvider, LogStream loggerProvider, ResourceMonitor resourceMonitor,
CompilerSettingsInferencer inferencer) : base(logger)
CompilerSettingsInferencer inferencer, Client wjClient) : base(logger)
{
_logger = logger;
_dtos = dtos;
@ -104,6 +106,7 @@ namespace Wabbajack
LoggerProvider = loggerProvider;
_resourceMonitor = resourceMonitor;
_inferencer = inferencer;
_wjClient = wjClient;
BackCommand =
ReactiveCommand.CreateFromTask(async () =>
@ -207,6 +210,7 @@ namespace Wabbajack
{
try
{
var token = CancellationToken.None;
State = CompilerState.Compiling;
var mo2Settings = new CompilerSettings
@ -225,9 +229,15 @@ namespace Wabbajack
UseGamePaths = true
};
if (PublishUpdate && !await RunPreflightChecks(token))
{
State = CompilerState.Errored;
return;
}
var compiler = MO2Compiler.Create(_serviceProvider, mo2Settings);
await compiler.Begin(CancellationToken.None);
await compiler.Begin(token);
State = CompilerState.Completed;
}
@ -240,7 +250,18 @@ namespace Wabbajack
await tsk;
}
private async Task<bool> RunPreflightChecks(CancellationToken token)
{
var lists = await _wjClient.GetMyModlists(token);
if (!lists.Any(x => x.Equals(MachineUrl, StringComparison.InvariantCultureIgnoreCase)))
{
_logger.LogError("Preflight Check failed, list {MachineUrl} not found in any repository", MachineUrl);
return false;
}
return true;
}
private async Task SaveSettingsFile()
{
if (Source == default) return;

View File

@ -34,8 +34,8 @@ namespace Wabbajack
.DisposeWith(disposables);
ViewModel.WhenAny(vm => vm.State)
.Select(x => x == CompilerState.Errored)
.Select(failed => $"Installation {(failed ? "Failed" : "Complete")}")
.Select(x => x is CompilerState.Errored or CompilerState.Completed)
.Select(failed => $"Compilation {(failed ? "Failed" : "Complete")}")
.BindToStrict(this, x => x.CompilationComplete.TitleText.Text)
.DisposeWith(disposables);
@ -78,7 +78,7 @@ namespace Wabbajack
.DisposeWith(disposables);
ViewModel.WhenAnyValue(vm => vm.State)
.Select(v => v == CompilerState.Completed ? Visibility.Visible : Visibility.Collapsed)
.Select(v => v is CompilerState.Completed or CompilerState.Errored ? Visibility.Visible : Visibility.Collapsed)
.BindToStrict(this, view => view.CompilationComplete.Visibility)
.DisposeWith(disposables);

View File

@ -456,4 +456,12 @@ public class Client
HttpException.ThrowOnFailure(response);
return await _dtos.DeserializeAsync<IndexedVirtualFile>(await response.Content.ReadAsStreamAsync(token), token);
}
public async Task<IReadOnlyList<string>> GetMyModlists(CancellationToken token)
{
var msg = await MakeMessage(HttpMethod.Get, new Uri($"{_configuration.BuildServerUrl}author_controls/lists"));
using var response = await _client.SendAsync(msg, token);
HttpException.ThrowOnFailure(response);
return (await _dtos.DeserializeAsync<string[]>(await response.Content.ReadAsStreamAsync(token), token))!;
}
}