Port Main Window VM and others

This commit is contained in:
Timothy Baldridge
2021-12-27 17:53:14 -07:00
parent 4031faf6e0
commit be8a88bcae
3 changed files with 41 additions and 20 deletions

View File

@ -2,9 +2,6 @@
using ReactiveUI; using ReactiveUI;
using ReactiveUI.Fody.Helpers; using ReactiveUI.Fody.Helpers;
using System; using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reactive.Disposables; using System.Reactive.Disposables;
using System.Reactive.Linq; using System.Reactive.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -14,13 +11,9 @@ using Wabbajack.Compiler;
using Wabbajack.DTOs; using Wabbajack.DTOs;
using Wabbajack.DTOs.GitHub; using Wabbajack.DTOs.GitHub;
using Wabbajack.Lib; using Wabbajack.Lib;
using Wabbajack.Lib.AuthorApi;
using Wabbajack.Lib.Extensions; using Wabbajack.Lib.Extensions;
using Wabbajack.Lib.FileUploader;
using Wabbajack.Lib.GitHub;
using Wabbajack.Paths; using Wabbajack.Paths;
using Wabbajack.Paths.IO; using Wabbajack.Paths.IO;
using WebSocketSharp;
using Consts = Wabbajack.Lib.Consts; using Consts = Wabbajack.Lib.Consts;
namespace Wabbajack namespace Wabbajack

View File

@ -10,9 +10,11 @@ using System.Windows.Media;
using DynamicData; using DynamicData;
using DynamicData.Binding; using DynamicData.Binding;
using System.Reactive; using System.Reactive;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.WindowsAPICodePack.Dialogs; using Microsoft.WindowsAPICodePack.Dialogs;
using Microsoft.WindowsAPICodePack.Shell; using Microsoft.WindowsAPICodePack.Shell;
using Wabbajack.DTOs.JsonConverters;
using Wabbajack.Installer; using Wabbajack.Installer;
using Wabbajack.Lib.Extensions; using Wabbajack.Lib.Extensions;
using Wabbajack.Lib.Interventions; using Wabbajack.Lib.Interventions;
@ -98,7 +100,7 @@ public class InstallerVM : BackNavigatingVM, IBackNavigatingVM, ICpuStatusVM
public ReactiveCommand<Unit, Unit> GoToInstallCommand { get; } public ReactiveCommand<Unit, Unit> GoToInstallCommand { get; }
public ReactiveCommand<Unit, Unit> BeginCommand { get; } public ReactiveCommand<Unit, Unit> BeginCommand { get; }
public InstallerVM(ILogger<InstallerVM> logger, MainWindowVM mainWindowVM) : base(logger, mainWindowVM) public InstallerVM(ILogger<InstallerVM> logger, MainWindowVM mainWindowVM, ServiceProvider serviceProvider) : base(logger, mainWindowVM)
{ {
_logger = logger; _logger = logger;
var downloadsPath = KnownFolders.Downloads.Path; var downloadsPath = KnownFolders.Downloads.Path;
@ -181,6 +183,7 @@ public class InstallerVM : BackNavigatingVM, IBackNavigatingVM, ICpuStatusVM
.Replay(1) .Replay(1)
.RefCount(); .RefCount();
_modList = activePath _modList = activePath
.ObserveOn(RxApp.TaskpoolScheduler) .ObserveOn(RxApp.TaskpoolScheduler)
// Convert from active path to modlist VM // Convert from active path to modlist VM
@ -188,7 +191,7 @@ public class InstallerVM : BackNavigatingVM, IBackNavigatingVM, ICpuStatusVM
{ {
if (modListPath == default) return default; if (modListPath == default) return default;
if (!modListPath.FileExists()) return default; if (!modListPath.FileExists()) return default;
return new ModListVM(modListPath); return new ModListVM(serviceProvider.GetService<ILogger<ModListVM>>()!, modListPath, serviceProvider.GetService<DTOSerializer>());
}) })
.DisposeOld() .DisposeOld()
.ObserveOnGuiThread() .ObserveOnGuiThread()
@ -214,9 +217,12 @@ public class InstallerVM : BackNavigatingVM, IBackNavigatingVM, ICpuStatusVM
_installing = this.WhenAny(x => x.Installer.ActiveInstallation) _installing = this.WhenAny(x => x.Installer.ActiveInstallation)
.Select(i => i != null) .Select(i => i != null)
.ToGuiProperty(this, nameof(Installing)); .ToGuiProperty(this, nameof(Installing));
/*TODO
_TargetManager = this.WhenAny(x => x.ModList) _TargetManager = this.WhenAny(x => x.ModList)
.Select(modList => ModManager.Standard) .Select(modList => ModManager.Standard)
.ToGuiProperty(this, nameof(TargetManager)); .ToGuiProperty(this, nameof(TargetManager));
*/
// Add additional error check on ModList // Add additional error check on ModList
ModListLocation.AdditionalError = this.WhenAny(x => x.ModList) ModListLocation.AdditionalError = this.WhenAny(x => x.ModList)
@ -243,6 +249,7 @@ public class InstallerVM : BackNavigatingVM, IBackNavigatingVM, ICpuStatusVM
resultSelector: (i, b) => i && b) resultSelector: (i, b) => i && b)
.ObserveOnGuiThread()); .ObserveOnGuiThread());
/* TODO
_percentCompleted = this.WhenAny(x => x.Installer.ActiveInstallation) _percentCompleted = this.WhenAny(x => x.Installer.ActiveInstallation)
.StartWith(default(IInstaller)) .StartWith(default(IInstaller))
.CombineLatest( .CombineLatest(
@ -258,8 +265,10 @@ public class InstallerVM : BackNavigatingVM, IBackNavigatingVM, ICpuStatusVM
.Switch() .Switch()
.Debounce(TimeSpan.FromMilliseconds(25), RxApp.MainThreadScheduler) .Debounce(TimeSpan.FromMilliseconds(25), RxApp.MainThreadScheduler)
.ToGuiProperty(this, nameof(PercentCompleted)); .ToGuiProperty(this, nameof(PercentCompleted));
*/
Slideshow = new SlideShow(this);
Slideshow = new SlideShow( this, serviceProvider);
// Set display items to ModList if configuring or complete, // Set display items to ModList if configuring or complete,
// or to the current slideshow data if installing // or to the current slideshow data if installing
@ -308,6 +317,8 @@ public class InstallerVM : BackNavigatingVM, IBackNavigatingVM, ICpuStatusVM
this.WhenAny(x => x.Installing), this.WhenAny(x => x.Installing),
resultSelector: (modList, mod, installing) => installing ? mod : modList) resultSelector: (modList, mod, installing) => installing ? mod : modList)
.ToGuiProperty(this, nameof(Description)); .ToGuiProperty(this, nameof(Description));
/* TODO
_modListName = Observable.CombineLatest( _modListName = Observable.CombineLatest(
this.WhenAny(x => x.ModList.Error) this.WhenAny(x => x.ModList.Error)
.Select(x => x != null), .Select(x => x != null),
@ -322,6 +333,7 @@ public class InstallerVM : BackNavigatingVM, IBackNavigatingVM, ICpuStatusVM
.Where(c => c != null) .Where(c => c != null)
.SelectMany(c => c.TextStatus)) .SelectMany(c => c.TextStatus))
.ToGuiProperty(this, nameof(ModListName)); .ToGuiProperty(this, nameof(ModListName));
*/
ShowManifestCommand = ReactiveCommand.Create(() => ShowManifestCommand = ReactiveCommand.Create(() =>
{ {
@ -336,8 +348,10 @@ public class InstallerVM : BackNavigatingVM, IBackNavigatingVM, ICpuStatusVM
.Select(modList => !string.IsNullOrEmpty(modList?.Readme)) .Select(modList => !string.IsNullOrEmpty(modList?.Readme))
.ObserveOnGuiThread()); .ObserveOnGuiThread());
/*TODO
OpenLogsCommand = ReactiveCommand.Create( OpenLogsCommand = ReactiveCommand.Create(
execute: () => UIUtils.OpenFolder(Consts.LogsFolder)); execute: () => UIUtils.OpenFolder(Consts.LogsFolder));
*/
VisitModListWebsiteCommand = ReactiveCommand.Create( VisitModListWebsiteCommand = ReactiveCommand.Create(
execute: () => execute: () =>
{ {
@ -370,12 +384,13 @@ public class InstallerVM : BackNavigatingVM, IBackNavigatingVM, ICpuStatusVM
}) })
.ToGuiProperty(this, nameof(ProgressTitle)); .ToGuiProperty(this, nameof(ProgressTitle));
/*
UIUtils.BindCpuStatus( UIUtils.BindCpuStatus(
this.WhenAny(x => x.Installer.ActiveInstallation) this.WhenAny(x => x.Installer.ActiveInstallation)
.SelectMany(c => c?.QueueStatus ?? Observable.Empty<CPUStatus>()), .SelectMany(c => c?.QueueStatus ?? Observable.Empty<CPUStatus>()),
StatusList) StatusList)
.DisposeWith(CompositeDisposable); .DisposeWith(CompositeDisposable);
*/
BeginCommand = ReactiveCommand.CreateFromTask( BeginCommand = ReactiveCommand.CreateFromTask(
canExecute: this.WhenAny(x => x.Installer.CanInstall) canExecute: this.WhenAny(x => x.Installer.CanInstall)
.Select(err => err.Succeeded), .Select(err => err.Succeeded),
@ -383,7 +398,7 @@ public class InstallerVM : BackNavigatingVM, IBackNavigatingVM, ICpuStatusVM
{ {
try try
{ {
UIUtils.Log($"Starting to install {ModList.Name}"); _logger.LogInformation("Starting to install {Name}", ModList.Name);
IsBackEnabledSubject.OnNext(false); IsBackEnabledSubject.OnNext(false);
var success = await this.Installer.Install(); var success = await this.Installer.Install();
Completed = ErrorResponse.Create(success); Completed = ErrorResponse.Create(success);
@ -393,12 +408,12 @@ public class InstallerVM : BackNavigatingVM, IBackNavigatingVM, ICpuStatusVM
} }
catch (Exception ex) catch (Exception ex)
{ {
UIUtils.Error(ex); _logger.LogError(ex, "During installation");
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
Utils.Error(ex, $"Encountered error, can't continue"); _logger.LogError(ex, $"Encountered error, can't continue");
while (ex.InnerException != null) ex = ex.InnerException; while (ex.InnerException != null) ex = ex.InnerException;
Completed = ErrorResponse.Fail(ex); Completed = ErrorResponse.Fail(ex);
} }
@ -416,6 +431,7 @@ public class InstallerVM : BackNavigatingVM, IBackNavigatingVM, ICpuStatusVM
}) })
.DisposeWith(CompositeDisposable); .DisposeWith(CompositeDisposable);
/*
// Listen for user interventions, and compile a dynamic list of all unhandled ones // Listen for user interventions, and compile a dynamic list of all unhandled ones
var activeInterventions = this.WhenAny(x => x.Installer.ActiveInstallation) var activeInterventions = this.WhenAny(x => x.Installer.ActiveInstallation)
.WithLatestFrom( .WithLatestFrom(
@ -438,6 +454,7 @@ public class InstallerVM : BackNavigatingVM, IBackNavigatingVM, ICpuStatusVM
.Filter(x => x.CpuID == WorkQueue.UnassignedCpuId) .Filter(x => x.CpuID == WorkQueue.UnassignedCpuId)
.QueryWhenChanged(query => query.FirstOrDefault()) .QueryWhenChanged(query => query.FirstOrDefault())
.ToGuiProperty(this, nameof(ActiveGlobalUserIntervention)); .ToGuiProperty(this, nameof(ActiveGlobalUserIntervention));
*/
CloseWhenCompleteCommand = ReactiveCommand.CreateFromTask( CloseWhenCompleteCommand = ReactiveCommand.CreateFromTask(
canExecute: this.WhenAny(x => x.Completed) canExecute: this.WhenAny(x => x.Completed)
@ -458,8 +475,10 @@ public class InstallerVM : BackNavigatingVM, IBackNavigatingVM, ICpuStatusVM
Installer.AfterInstallNavigation(); Installer.AfterInstallNavigation();
}); });
/*
_CurrentCpuCount = this.WhenAny(x => x.Installer.ActiveInstallation.Queue.CurrentCpuCount) _CurrentCpuCount = this.WhenAny(x => x.Installer.ActiveInstallation.Queue.CurrentCpuCount)
.Switch() .Switch()
.ToGuiProperty(this, nameof(CurrentCpuCount)); .ToGuiProperty(this, nameof(CurrentCpuCount));
*/
} }
} }

View File

@ -8,8 +8,10 @@ using System.Reflection;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Windows.Input; using System.Windows.Input;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Wabbajack.Common; using Wabbajack.Common;
using Wabbajack.Downloaders.GameFile;
using Wabbajack.Lib; using Wabbajack.Lib;
using Wabbajack.Lib.Interventions; using Wabbajack.Lib.Interventions;
using Wabbajack.Networking.WabbajackClientApi; using Wabbajack.Networking.WabbajackClientApi;
@ -52,22 +54,25 @@ namespace Wabbajack
[Reactive] [Reactive]
public bool UpdateAvailable { get; private set; } public bool UpdateAvailable { get; private set; }
public MainWindowVM(ILogger<MainWindowVM> logger, MainWindow mainWindow, MainSettings settings, Client wjClient) public MainWindowVM(ILogger<MainWindowVM> logger, MainWindow mainWindow, MainSettings settings, Client wjClient,
ServiceProvider serviceProvider)
{ {
_logger = logger; _logger = logger;
_wjClient = wjClient; _wjClient = wjClient;
ConverterRegistration.Register(); ConverterRegistration.Register();
MainWindow = mainWindow; MainWindow = mainWindow;
Settings = settings; Settings = settings;
Installer = new Lazy<InstallerVM>(() => new InstallerVM(this)); Installer = new Lazy<InstallerVM>(() => new InstallerVM(serviceProvider.GetService<ILogger<InstallerVM>>(), this, serviceProvider));
Compiler = new Lazy<CompilerVM>(() => new CompilerVM(this)); Compiler = new Lazy<CompilerVM>(() => new CompilerVM(this));
SettingsPane = new Lazy<SettingsVM>(() => new SettingsVM(this)); SettingsPane = new Lazy<SettingsVM>(() => new SettingsVM(serviceProvider.GetService<ILogger<SettingsVM>>(), this, serviceProvider));
Gallery = new Lazy<ModListGalleryVM>(() => new ModListGalleryVM(this)); Gallery = new Lazy<ModListGalleryVM>(() => new ModListGalleryVM(serviceProvider.GetService<ILogger<ModListGalleryVM>>(), this,
serviceProvider.GetService<Client>(), serviceProvider.GetService<GameLocator>(), serviceProvider));
ModeSelectionVM = new ModeSelectionVM(this); ModeSelectionVM = new ModeSelectionVM(this);
ModListContentsVM = new Lazy<ModListContentsVM>(() => new ModListContentsVM(this)); ModListContentsVM = new Lazy<ModListContentsVM>(() => new ModListContentsVM(serviceProvider.GetService<ILogger<ModListContentsVM>>(), this));
UserInterventionHandlers = new UserInterventionHandlers(this); UserInterventionHandlers = new UserInterventionHandlers(serviceProvider.GetService<ILogger<UserInterventionHandlers>>(), this);
// Set up logging // Set up logging
/* TODO
Utils.LogMessages Utils.LogMessages
.ObserveOn(RxApp.TaskpoolScheduler) .ObserveOn(RxApp.TaskpoolScheduler)
.ToObservableChangeSet() .ToObservableChangeSet()
@ -107,6 +112,7 @@ namespace Wabbajack
}) })
.Subscribe() .Subscribe()
.DisposeWith(CompositeDisposable); .DisposeWith(CompositeDisposable);
*/
if (IsStartingFromModlist(out var path)) if (IsStartingFromModlist(out var path))
{ {
@ -147,6 +153,7 @@ namespace Wabbajack
private static bool IsStartingFromModlist(out AbsolutePath modlistPath) private static bool IsStartingFromModlist(out AbsolutePath modlistPath)
{ {
/* TODO
if (CLIArguments.InstallPath == null) if (CLIArguments.InstallPath == null)
{ {
modlistPath = default; modlistPath = default;
@ -155,6 +162,8 @@ namespace Wabbajack
modlistPath = (AbsolutePath)CLIArguments.InstallPath; modlistPath = (AbsolutePath)CLIArguments.InstallPath;
return true; return true;
*/
return false;
} }
public void OpenInstaller(AbsolutePath path) public void OpenInstaller(AbsolutePath path)