From 3db6be498399cecf0279d0f4b5066ff335163020 Mon Sep 17 00:00:00 2001 From: Timothy Baldridge Date: Tue, 19 Oct 2021 17:19:06 -0600 Subject: [PATCH] Add Error page (issue #1664) --- Wabbajack.App/Messages/Error.cs | 8 +++++ Wabbajack.App/Screens/CompilationViewModel.cs | 1 + Wabbajack.App/Screens/ErrorPageView.axaml | 13 +++++++ Wabbajack.App/Screens/ErrorPageView.axaml.cs | 20 +++++++++++ Wabbajack.App/Screens/ErrorPageViewModel.cs | 34 +++++++++++++++++++ .../Screens/StandardInstallationViewModel.cs | 16 ++++++--- Wabbajack.App/ServiceExtensions.cs | 2 ++ .../ViewModels/MainWindowViewModel.cs | 2 +- Wabbajack.App/Wabbajack.App.csproj | 3 ++ Wabbajack.Installer/AInstaller.cs | 8 +++-- Wabbajack.Installer/StandardInstaller.cs | 2 +- 11 files changed, 101 insertions(+), 8 deletions(-) create mode 100644 Wabbajack.App/Messages/Error.cs create mode 100644 Wabbajack.App/Screens/ErrorPageView.axaml create mode 100644 Wabbajack.App/Screens/ErrorPageView.axaml.cs create mode 100644 Wabbajack.App/Screens/ErrorPageViewModel.cs diff --git a/Wabbajack.App/Messages/Error.cs b/Wabbajack.App/Messages/Error.cs new file mode 100644 index 00000000..c2008583 --- /dev/null +++ b/Wabbajack.App/Messages/Error.cs @@ -0,0 +1,8 @@ +using System; + +namespace Wabbajack.App.Messages; + +public record Error(string Prefix, Exception Exception) +{ + +} \ No newline at end of file diff --git a/Wabbajack.App/Screens/CompilationViewModel.cs b/Wabbajack.App/Screens/CompilationViewModel.cs index 76c59dac..6ca0aaed 100644 --- a/Wabbajack.App/Screens/CompilationViewModel.cs +++ b/Wabbajack.App/Screens/CompilationViewModel.cs @@ -63,6 +63,7 @@ public class CompilationViewModel : ViewModelBase, IReceiverMarker, IReceiver + + + + + + \ No newline at end of file diff --git a/Wabbajack.App/Screens/ErrorPageView.axaml.cs b/Wabbajack.App/Screens/ErrorPageView.axaml.cs new file mode 100644 index 00000000..36441c1d --- /dev/null +++ b/Wabbajack.App/Screens/ErrorPageView.axaml.cs @@ -0,0 +1,20 @@ +using System.Reactive.Disposables; +using ReactiveUI; +using Wabbajack.App.Views; + +namespace Wabbajack.App.Screens; + +public partial class ErrorPageView : ScreenBase +{ + public ErrorPageView() + { + InitializeComponent(); + this.WhenActivated(disposables => + { + this.Bind(ViewModel, vm => vm.Prefix, view => view.Prefix.Text) + .DisposeWith(disposables); + this.Bind(ViewModel, vm => vm.ShortMessage, view => view.Message.Text) + .DisposeWith(disposables); + }); + } +} \ No newline at end of file diff --git a/Wabbajack.App/Screens/ErrorPageViewModel.cs b/Wabbajack.App/Screens/ErrorPageViewModel.cs new file mode 100644 index 00000000..373ee8cb --- /dev/null +++ b/Wabbajack.App/Screens/ErrorPageViewModel.cs @@ -0,0 +1,34 @@ +using System; +using DynamicData.Kernel; +using ReactiveUI; +using ReactiveUI.Fody.Helpers; +using Wabbajack.App.Messages; +using Wabbajack.App.ViewModels; + +namespace Wabbajack.App.Screens +{ + public class ErrorPageViewModel : ViewModelBase, IActivatableViewModel, IReceiver + { + [Reactive] + public string ShortMessage { get; set; } + + [Reactive] + public string Prefix { get; set; } + + public ErrorPageViewModel() + { + Activator = new ViewModelActivator(); + } + public void Receive(Error val) + { + Prefix = val.Prefix; + ShortMessage = val.Exception.Message; + } + + public static void Display(string prefix, Exception ex) + { + MessageBus.Instance.Send(new Error(prefix, ex)); + MessageBus.Instance.Send(new NavigateTo(typeof(ErrorPageViewModel))); + } + } +} \ No newline at end of file diff --git a/Wabbajack.App/Screens/StandardInstallationViewModel.cs b/Wabbajack.App/Screens/StandardInstallationViewModel.cs index 9ac63a44..28eda495 100644 --- a/Wabbajack.App/Screens/StandardInstallationViewModel.cs +++ b/Wabbajack.App/Screens/StandardInstallationViewModel.cs @@ -191,11 +191,19 @@ namespace Wabbajack.App.ViewModels }; _logger.LogInformation("Installer created, starting the installation process"); - var result = await _installer.Begin(CancellationToken.None); - - if (result) + try { - await SaveConfigAndContinue(_config); + var result = await _installer.Begin(CancellationToken.None); + if (!result) throw new Exception("Installation failed"); + + if (result) + { + await SaveConfigAndContinue(_config); + } + } + catch (Exception ex) + { + ErrorPageViewModel.Display("During installation", ex); } } diff --git a/Wabbajack.App/ServiceExtensions.cs b/Wabbajack.App/ServiceExtensions.cs index 688d6449..2282272d 100644 --- a/Wabbajack.App/ServiceExtensions.cs +++ b/Wabbajack.App/ServiceExtensions.cs @@ -45,6 +45,7 @@ namespace Wabbajack.App services.AddDTOSerializer(); services.AddSingleton(); services.AddTransient(); + services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); @@ -59,6 +60,7 @@ namespace Wabbajack.App services.AddSingleton(); services.AddSingleton(); + services.AddAllSingleton(); services.AddAllSingleton(); services.AddAllSingleton(); services.AddAllSingleton(); diff --git a/Wabbajack.App/ViewModels/MainWindowViewModel.cs b/Wabbajack.App/ViewModels/MainWindowViewModel.cs index 79e3939f..8f942b71 100644 --- a/Wabbajack.App/ViewModels/MainWindowViewModel.cs +++ b/Wabbajack.App/ViewModels/MainWindowViewModel.cs @@ -127,7 +127,7 @@ namespace Wabbajack.App.ViewModels if (throughput != 0) { sb.Append( - $"{limiter.Name}: [{next.Running}/{next.Pending}] {throughput.ToFileSizeString()}/sec "); + $"{limiter.Name}: [{next.Running}/{next.Pending + next.Running}] {throughput.ToFileSizeString()}/sec "); } } diff --git a/Wabbajack.App/Wabbajack.App.csproj b/Wabbajack.App/Wabbajack.App.csproj index 53cae275..139328c0 100644 --- a/Wabbajack.App/Wabbajack.App.csproj +++ b/Wabbajack.App/Wabbajack.App.csproj @@ -45,6 +45,9 @@ StandardInstallationView.axaml Code + + LogScreenView.axaml + diff --git a/Wabbajack.Installer/AInstaller.cs b/Wabbajack.Installer/AInstaller.cs index f37bfad2..f5b15bd6 100644 --- a/Wabbajack.Installer/AInstaller.cs +++ b/Wabbajack.Installer/AInstaller.cs @@ -285,9 +285,12 @@ namespace Wabbajack.Installer } _logger.LogInformation("Downloading {count} archives", missing.Count); + NextStep("Downloading files", missing.Count); - await missing.Where(a => a.State is not Manual) - .PDo(_parallelOptions, async archive => + await missing + .OrderBy(a => a.Size) + .Where(a => a.State is not Manual) + .PDoAll(async archive => { _logger.LogInformation("Downloading {archive}", archive.Name); var outputPath = _configuration.Downloads.Combine(archive.Name); @@ -303,6 +306,7 @@ namespace Wabbajack.Installer } await DownloadArchive(archive, download, token, outputPath); + UpdateProgress(1); }); } diff --git a/Wabbajack.Installer/StandardInstaller.cs b/Wabbajack.Installer/StandardInstaller.cs index 7d1e3884..b4ee3a01 100644 --- a/Wabbajack.Installer/StandardInstaller.cs +++ b/Wabbajack.Installer/StandardInstaller.cs @@ -38,7 +38,7 @@ namespace Wabbajack.Installer base(logger, config, gameLocator, extractor, jsonSerializer, vfs, fileHashCache, downloadDispatcher, parallelOptions, wjClient) { - MaxSteps = 6; + MaxSteps = 7; }