diff --git a/Wabbajack.App.Wpf/View Models/Compilers/MO2CompilerVM.cs b/Wabbajack.App.Wpf/View Models/Compilers/MO2CompilerVM.cs index 4c53206e..0f06add0 100644 --- a/Wabbajack.App.Wpf/View Models/Compilers/MO2CompilerVM.cs +++ b/Wabbajack.App.Wpf/View Models/Compilers/MO2CompilerVM.cs @@ -2,9 +2,6 @@ using ReactiveUI; using ReactiveUI.Fody.Helpers; using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; using System.Reactive.Disposables; using System.Reactive.Linq; using System.Threading.Tasks; @@ -14,13 +11,9 @@ using Wabbajack.Compiler; using Wabbajack.DTOs; using Wabbajack.DTOs.GitHub; using Wabbajack.Lib; -using Wabbajack.Lib.AuthorApi; using Wabbajack.Lib.Extensions; -using Wabbajack.Lib.FileUploader; -using Wabbajack.Lib.GitHub; using Wabbajack.Paths; using Wabbajack.Paths.IO; -using WebSocketSharp; using Consts = Wabbajack.Lib.Consts; namespace Wabbajack diff --git a/Wabbajack.App.Wpf/View Models/Installers/InstallerVM.cs b/Wabbajack.App.Wpf/View Models/Installers/InstallerVM.cs index ec916419..0ef9089a 100644 --- a/Wabbajack.App.Wpf/View Models/Installers/InstallerVM.cs +++ b/Wabbajack.App.Wpf/View Models/Installers/InstallerVM.cs @@ -10,9 +10,11 @@ using System.Windows.Media; using DynamicData; using DynamicData.Binding; using System.Reactive; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.WindowsAPICodePack.Dialogs; using Microsoft.WindowsAPICodePack.Shell; +using Wabbajack.DTOs.JsonConverters; using Wabbajack.Installer; using Wabbajack.Lib.Extensions; using Wabbajack.Lib.Interventions; @@ -98,7 +100,7 @@ public class InstallerVM : BackNavigatingVM, IBackNavigatingVM, ICpuStatusVM public ReactiveCommand GoToInstallCommand { get; } public ReactiveCommand BeginCommand { get; } - public InstallerVM(ILogger logger, MainWindowVM mainWindowVM) : base(logger, mainWindowVM) + public InstallerVM(ILogger logger, MainWindowVM mainWindowVM, ServiceProvider serviceProvider) : base(logger, mainWindowVM) { _logger = logger; var downloadsPath = KnownFolders.Downloads.Path; @@ -181,6 +183,7 @@ public class InstallerVM : BackNavigatingVM, IBackNavigatingVM, ICpuStatusVM .Replay(1) .RefCount(); + _modList = activePath .ObserveOn(RxApp.TaskpoolScheduler) // Convert from active path to modlist VM @@ -188,7 +191,7 @@ public class InstallerVM : BackNavigatingVM, IBackNavigatingVM, ICpuStatusVM { if (modListPath == default) return default; if (!modListPath.FileExists()) return default; - return new ModListVM(modListPath); + return new ModListVM(serviceProvider.GetService>()!, modListPath, serviceProvider.GetService()); }) .DisposeOld() .ObserveOnGuiThread() @@ -214,9 +217,12 @@ public class InstallerVM : BackNavigatingVM, IBackNavigatingVM, ICpuStatusVM _installing = this.WhenAny(x => x.Installer.ActiveInstallation) .Select(i => i != null) .ToGuiProperty(this, nameof(Installing)); + + /*TODO _TargetManager = this.WhenAny(x => x.ModList) .Select(modList => ModManager.Standard) .ToGuiProperty(this, nameof(TargetManager)); + */ // Add additional error check on ModList ModListLocation.AdditionalError = this.WhenAny(x => x.ModList) @@ -243,6 +249,7 @@ public class InstallerVM : BackNavigatingVM, IBackNavigatingVM, ICpuStatusVM resultSelector: (i, b) => i && b) .ObserveOnGuiThread()); + /* TODO _percentCompleted = this.WhenAny(x => x.Installer.ActiveInstallation) .StartWith(default(IInstaller)) .CombineLatest( @@ -258,8 +265,10 @@ public class InstallerVM : BackNavigatingVM, IBackNavigatingVM, ICpuStatusVM .Switch() .Debounce(TimeSpan.FromMilliseconds(25), RxApp.MainThreadScheduler) .ToGuiProperty(this, nameof(PercentCompleted)); + */ - Slideshow = new SlideShow(this); + + Slideshow = new SlideShow( this, serviceProvider); // Set display items to ModList if configuring or complete, // or to the current slideshow data if installing @@ -308,6 +317,8 @@ public class InstallerVM : BackNavigatingVM, IBackNavigatingVM, ICpuStatusVM this.WhenAny(x => x.Installing), resultSelector: (modList, mod, installing) => installing ? mod : modList) .ToGuiProperty(this, nameof(Description)); + + /* TODO _modListName = Observable.CombineLatest( this.WhenAny(x => x.ModList.Error) .Select(x => x != null), @@ -322,6 +333,7 @@ public class InstallerVM : BackNavigatingVM, IBackNavigatingVM, ICpuStatusVM .Where(c => c != null) .SelectMany(c => c.TextStatus)) .ToGuiProperty(this, nameof(ModListName)); + */ ShowManifestCommand = ReactiveCommand.Create(() => { @@ -336,8 +348,10 @@ public class InstallerVM : BackNavigatingVM, IBackNavigatingVM, ICpuStatusVM .Select(modList => !string.IsNullOrEmpty(modList?.Readme)) .ObserveOnGuiThread()); + /*TODO OpenLogsCommand = ReactiveCommand.Create( execute: () => UIUtils.OpenFolder(Consts.LogsFolder)); + */ VisitModListWebsiteCommand = ReactiveCommand.Create( execute: () => { @@ -370,12 +384,13 @@ public class InstallerVM : BackNavigatingVM, IBackNavigatingVM, ICpuStatusVM }) .ToGuiProperty(this, nameof(ProgressTitle)); + /* UIUtils.BindCpuStatus( this.WhenAny(x => x.Installer.ActiveInstallation) .SelectMany(c => c?.QueueStatus ?? Observable.Empty()), StatusList) .DisposeWith(CompositeDisposable); - +*/ BeginCommand = ReactiveCommand.CreateFromTask( canExecute: this.WhenAny(x => x.Installer.CanInstall) .Select(err => err.Succeeded), @@ -383,7 +398,7 @@ public class InstallerVM : BackNavigatingVM, IBackNavigatingVM, ICpuStatusVM { try { - UIUtils.Log($"Starting to install {ModList.Name}"); + _logger.LogInformation("Starting to install {Name}", ModList.Name); IsBackEnabledSubject.OnNext(false); var success = await this.Installer.Install(); Completed = ErrorResponse.Create(success); @@ -393,12 +408,12 @@ public class InstallerVM : BackNavigatingVM, IBackNavigatingVM, ICpuStatusVM } catch (Exception ex) { - UIUtils.Error(ex); + _logger.LogError(ex, "During installation"); } } 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; Completed = ErrorResponse.Fail(ex); } @@ -416,6 +431,7 @@ public class InstallerVM : BackNavigatingVM, IBackNavigatingVM, ICpuStatusVM }) .DisposeWith(CompositeDisposable); + /* // Listen for user interventions, and compile a dynamic list of all unhandled ones var activeInterventions = this.WhenAny(x => x.Installer.ActiveInstallation) .WithLatestFrom( @@ -438,6 +454,7 @@ public class InstallerVM : BackNavigatingVM, IBackNavigatingVM, ICpuStatusVM .Filter(x => x.CpuID == WorkQueue.UnassignedCpuId) .QueryWhenChanged(query => query.FirstOrDefault()) .ToGuiProperty(this, nameof(ActiveGlobalUserIntervention)); + */ CloseWhenCompleteCommand = ReactiveCommand.CreateFromTask( canExecute: this.WhenAny(x => x.Completed) @@ -458,8 +475,10 @@ public class InstallerVM : BackNavigatingVM, IBackNavigatingVM, ICpuStatusVM Installer.AfterInstallNavigation(); }); + /* _CurrentCpuCount = this.WhenAny(x => x.Installer.ActiveInstallation.Queue.CurrentCpuCount) .Switch() .ToGuiProperty(this, nameof(CurrentCpuCount)); + */ } } \ No newline at end of file diff --git a/Wabbajack.App.Wpf/View Models/MainWindowVM.cs b/Wabbajack.App.Wpf/View Models/MainWindowVM.cs index aea08c35..094e26f2 100644 --- a/Wabbajack.App.Wpf/View Models/MainWindowVM.cs +++ b/Wabbajack.App.Wpf/View Models/MainWindowVM.cs @@ -8,8 +8,10 @@ using System.Reflection; using System.Threading.Tasks; using System.Windows; using System.Windows.Input; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Wabbajack.Common; +using Wabbajack.Downloaders.GameFile; using Wabbajack.Lib; using Wabbajack.Lib.Interventions; using Wabbajack.Networking.WabbajackClientApi; @@ -52,22 +54,25 @@ namespace Wabbajack [Reactive] public bool UpdateAvailable { get; private set; } - public MainWindowVM(ILogger logger, MainWindow mainWindow, MainSettings settings, Client wjClient) + public MainWindowVM(ILogger logger, MainWindow mainWindow, MainSettings settings, Client wjClient, + ServiceProvider serviceProvider) { _logger = logger; _wjClient = wjClient; ConverterRegistration.Register(); MainWindow = mainWindow; Settings = settings; - Installer = new Lazy(() => new InstallerVM(this)); + Installer = new Lazy(() => new InstallerVM(serviceProvider.GetService>(), this, serviceProvider)); Compiler = new Lazy(() => new CompilerVM(this)); - SettingsPane = new Lazy(() => new SettingsVM(this)); - Gallery = new Lazy(() => new ModListGalleryVM(this)); + SettingsPane = new Lazy(() => new SettingsVM(serviceProvider.GetService>(), this, serviceProvider)); + Gallery = new Lazy(() => new ModListGalleryVM(serviceProvider.GetService>(), this, + serviceProvider.GetService(), serviceProvider.GetService(), serviceProvider)); ModeSelectionVM = new ModeSelectionVM(this); - ModListContentsVM = new Lazy(() => new ModListContentsVM(this)); - UserInterventionHandlers = new UserInterventionHandlers(this); + ModListContentsVM = new Lazy(() => new ModListContentsVM(serviceProvider.GetService>(), this)); + UserInterventionHandlers = new UserInterventionHandlers(serviceProvider.GetService>(), this); // Set up logging + /* TODO Utils.LogMessages .ObserveOn(RxApp.TaskpoolScheduler) .ToObservableChangeSet() @@ -107,6 +112,7 @@ namespace Wabbajack }) .Subscribe() .DisposeWith(CompositeDisposable); + */ if (IsStartingFromModlist(out var path)) { @@ -147,6 +153,7 @@ namespace Wabbajack private static bool IsStartingFromModlist(out AbsolutePath modlistPath) { + /* TODO if (CLIArguments.InstallPath == null) { modlistPath = default; @@ -155,6 +162,8 @@ namespace Wabbajack modlistPath = (AbsolutePath)CLIArguments.InstallPath; return true; + */ + return false; } public void OpenInstaller(AbsolutePath path)