From 2e9f2226487d5118441e382076a68a9cde6de27c Mon Sep 17 00:00:00 2001 From: Justin Swanson Date: Sat, 16 Nov 2019 17:09:13 -0600 Subject: [PATCH] ISubCompilerVM.Unload() To save settings when swapping off a compiler VM --- Wabbajack/Settings.cs | 3 +-- Wabbajack/View Models/Compilers/CompilerVM.cs | 7 +++++++ .../View Models/Compilers/ISubCompilerVM.cs | 1 + .../View Models/Compilers/MO2CompilerVM.cs | 18 ++++++++++-------- .../View Models/Compilers/VortexCompilerVM.cs | 2 ++ 5 files changed, 21 insertions(+), 10 deletions(-) diff --git a/Wabbajack/Settings.cs b/Wabbajack/Settings.cs index 37eca284..84d63649 100644 --- a/Wabbajack/Settings.cs +++ b/Wabbajack/Settings.cs @@ -1,4 +1,4 @@ -using Newtonsoft.Json; +using Newtonsoft.Json; using ReactiveUI.Fody.Helpers; using System; using System.Collections.Generic; @@ -58,7 +58,6 @@ namespace Wabbajack public class ModlistInstallationSettings { public string InstallationLocation { get; set; } - public string StagingLocation { get; set; } public string DownloadLocation { get; set; } } diff --git a/Wabbajack/View Models/Compilers/CompilerVM.cs b/Wabbajack/View Models/Compilers/CompilerVM.cs index d378567c..5176a7b1 100644 --- a/Wabbajack/View Models/Compilers/CompilerVM.cs +++ b/Wabbajack/View Models/Compilers/CompilerVM.cs @@ -59,6 +59,13 @@ namespace Wabbajack return null; } }) + // Unload old VM + .Pairwise() + .Do(pair => + { + pair.Previous?.Unload(); + }) + .Select(p => p.Current) .ToProperty(this, nameof(this.Compiler)); // Let sub VM determine what settings we're displaying and when diff --git a/Wabbajack/View Models/Compilers/ISubCompilerVM.cs b/Wabbajack/View Models/Compilers/ISubCompilerVM.cs index 1319e61a..16ceec29 100644 --- a/Wabbajack/View Models/Compilers/ISubCompilerVM.cs +++ b/Wabbajack/View Models/Compilers/ISubCompilerVM.cs @@ -13,5 +13,6 @@ namespace Wabbajack IReactiveCommand BeginCommand { get; } bool Compiling { get; } ModlistSettingsEditorVM ModlistSettings { get; } + void Unload(); } } diff --git a/Wabbajack/View Models/Compilers/MO2CompilerVM.cs b/Wabbajack/View Models/Compilers/MO2CompilerVM.cs index e0517322..6555d608 100644 --- a/Wabbajack/View Models/Compilers/MO2CompilerVM.cs +++ b/Wabbajack/View Models/Compilers/MO2CompilerVM.cs @@ -16,6 +16,8 @@ namespace Wabbajack { public class MO2CompilerVM : ViewModel, ISubCompilerVM { + private readonly MO2CompilationSettings settings; + private readonly ObservableAsPropertyHelper _Mo2Folder; public string Mo2Folder => _Mo2Folder.Value; @@ -132,19 +134,14 @@ namespace Wabbajack .ToProperty(this, nameof(this.Compiling)); // Load settings - var settings = parent.MWVM.Settings.Compiler.MO2Compilation; + this.settings = parent.MWVM.Settings.Compiler.MO2Compilation; this.ModlistLocation.TargetPath = settings.LastCompiledProfileLocation; if (!string.IsNullOrWhiteSpace(settings.DownloadLocation)) { this.DownloadLocation.TargetPath = settings.DownloadLocation; } parent.MWVM.Settings.SaveSignal - .Subscribe(_ => - { - settings.DownloadLocation = this.DownloadLocation.TargetPath; - settings.LastCompiledProfileLocation = this.ModlistLocation.TargetPath; - this.ModlistSettings?.Save(); - }) + .Subscribe(_ => Unload()) .DisposeWith(this.CompositeDisposable); // Load custom modlist settings per MO2 profile @@ -195,8 +192,13 @@ namespace Wabbajack } }) .DisposeWith(this.CompositeDisposable); + } - + public void Unload() + { + settings.DownloadLocation = this.DownloadLocation.TargetPath; + settings.LastCompiledProfileLocation = this.ModlistLocation.TargetPath; + this.ModlistSettings?.Save(); } } } diff --git a/Wabbajack/View Models/Compilers/VortexCompilerVM.cs b/Wabbajack/View Models/Compilers/VortexCompilerVM.cs index c6d78cd1..02216cb7 100644 --- a/Wabbajack/View Models/Compilers/VortexCompilerVM.cs +++ b/Wabbajack/View Models/Compilers/VortexCompilerVM.cs @@ -15,5 +15,7 @@ namespace Wabbajack public bool Compiling => throw new NotImplementedException(); public ModlistSettingsEditorVM ModlistSettings => throw new NotImplementedException(); + + public void Unload() => throw new NotImplementedException(); } }