From 587395e98b343a0f5b90eafff3f71fd013ff429a Mon Sep 17 00:00:00 2001 From: Justin Swanson Date: Wed, 20 Nov 2019 23:15:47 -0600 Subject: [PATCH] ISubCompilerVM.ActiveCompilation --- Wabbajack/View Models/Compilers/CompilerVM.cs | 8 ++++++++ .../View Models/Compilers/ISubCompilerVM.cs | 3 ++- .../View Models/Compilers/MO2CompilerVM.cs | 18 ++++++------------ .../View Models/Compilers/VortexCompilerVM.cs | 17 ++++++++--------- Wabbajack/Views/Compilers/CompilerView.xaml | 6 +++--- 5 files changed, 27 insertions(+), 25 deletions(-) diff --git a/Wabbajack/View Models/Compilers/CompilerVM.cs b/Wabbajack/View Models/Compilers/CompilerVM.cs index d7676df5..9f5e5764 100644 --- a/Wabbajack/View Models/Compilers/CompilerVM.cs +++ b/Wabbajack/View Models/Compilers/CompilerVM.cs @@ -32,6 +32,9 @@ namespace Wabbajack private readonly ObservableAsPropertyHelper _CurrentStatusTracker; public StatusUpdateTracker CurrentStatusTracker => _CurrentStatusTracker.Value; + private readonly ObservableAsPropertyHelper _Compiling; + public bool Compiling => _Compiling.Value; + public CompilerVM(MainWindowVM mainWindowVM) { this.MWVM = mainWindowVM; @@ -93,6 +96,11 @@ namespace Wabbajack return null; }) .ToProperty(this, nameof(this.Image)); + + this._Compiling = this.WhenAny(x => x.Compiler.ActiveCompilation) + .Select(compilation => compilation != null) + .ObserveOnGuiThread() + .ToProperty(this, nameof(this.Compiling)); } } } diff --git a/Wabbajack/View Models/Compilers/ISubCompilerVM.cs b/Wabbajack/View Models/Compilers/ISubCompilerVM.cs index fd44cc0d..73d12959 100644 --- a/Wabbajack/View Models/Compilers/ISubCompilerVM.cs +++ b/Wabbajack/View Models/Compilers/ISubCompilerVM.cs @@ -6,13 +6,14 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Input; using Wabbajack.Common; +using Wabbajack.Lib; namespace Wabbajack { public interface ISubCompilerVM { IReactiveCommand BeginCommand { get; } - bool Compiling { get; } + ACompiler ActiveCompilation { get; } ModlistSettingsEditorVM ModlistSettings { get; } StatusUpdateTracker StatusTracker { get;} diff --git a/Wabbajack/View Models/Compilers/MO2CompilerVM.cs b/Wabbajack/View Models/Compilers/MO2CompilerVM.cs index e04cdaa9..f4f093fa 100644 --- a/Wabbajack/View Models/Compilers/MO2CompilerVM.cs +++ b/Wabbajack/View Models/Compilers/MO2CompilerVM.cs @@ -31,8 +31,8 @@ namespace Wabbajack public IReactiveCommand BeginCommand { get; } - private readonly ObservableAsPropertyHelper _Compiling; - public bool Compiling => _Compiling.Value; + [Reactive] + public ACompiler ActiveCompilation { get; private set; } private readonly ObservableAsPropertyHelper _ModlistSettings; public ModlistSettingsEditorVM ModlistSettings => _ModlistSettings.Value; @@ -101,10 +101,9 @@ namespace Wabbajack .ObserveOnGuiThread(), execute: async () => { - MO2Compiler compiler; try { - compiler = new MO2Compiler(this.Mo2Folder) + this.ActiveCompilation = new MO2Compiler(this.Mo2Folder) { MO2Profile = this.MOProfile, ModListName = this.ModlistSettings.ModListName, @@ -114,10 +113,6 @@ namespace Wabbajack ModListWebsite = this.ModlistSettings.Website, ModListReadme = this.ModlistSettings.ReadMeText.TargetPath, }; - // TODO: USE RX HERE - compiler.TextStatus.Subscribe(Utils.Log); - // TODO: Where do we bind this? - //compiler.QueueStatus.Subscribe(_cpuStatus); } catch (Exception ex) { @@ -128,7 +123,7 @@ namespace Wabbajack try { - await compiler.Begin(); + await this.ActiveCompilation.Begin(); } catch (Exception ex) { @@ -138,12 +133,11 @@ namespace Wabbajack finally { this.StatusTracker = null; - compiler.Dispose(); + this.ActiveCompilation.Dispose(); + this.ActiveCompilation = null; } }); - this._Compiling = this.BeginCommand.IsExecuting - .ToProperty(this, nameof(this.Compiling)); // Load settings this.settings = parent.MWVM.Settings.Compiler.MO2Compilation; diff --git a/Wabbajack/View Models/Compilers/VortexCompilerVM.cs b/Wabbajack/View Models/Compilers/VortexCompilerVM.cs index 8d713e1d..88d1bc5e 100644 --- a/Wabbajack/View Models/Compilers/VortexCompilerVM.cs +++ b/Wabbajack/View Models/Compilers/VortexCompilerVM.cs @@ -18,9 +18,6 @@ namespace Wabbajack public IReactiveCommand BeginCommand { get; } - private readonly ObservableAsPropertyHelper _compiling; - public bool Compiling => _compiling.Value; - private readonly ObservableAsPropertyHelper _modListSettings; public ModlistSettingsEditorVM ModlistSettings => _modListSettings.Value; @@ -32,6 +29,9 @@ namespace Wabbajack public ObservableCollectionExtended GameOptions => _gameOptions; + [Reactive] + public ACompiler ActiveCompilation { get; private set; } + [Reactive] public GameVM SelectedGame { get; set; } @@ -82,10 +82,9 @@ namespace Wabbajack .ObserveOnGuiThread(), execute: async () => { - VortexCompiler compiler; try { - compiler = new VortexCompiler( + this.ActiveCompilation = new VortexCompiler( SelectedGame.Game, GameLocation.TargetPath, VortexCompiler.TypicalVortexFolder(), @@ -110,7 +109,7 @@ namespace Wabbajack { try { - await compiler.Begin(); + await this.ActiveCompilation.Begin(); } catch (Exception ex) { @@ -120,11 +119,11 @@ namespace Wabbajack finally { this.StatusTracker = null; + this.ActiveCompilation.Dispose(); + this.ActiveCompilation = null; } }); }); - _compiling = BeginCommand.IsExecuting - .ToProperty(this, nameof(Compiling)); // Load settings _settings = parent.MWVM.Settings.Compiler.VortexCompilation; @@ -218,4 +217,4 @@ namespace Wabbajack GameLocation.TargetPath = gogGame?.Path; } } -} \ No newline at end of file +} diff --git a/Wabbajack/Views/Compilers/CompilerView.xaml b/Wabbajack/Views/Compilers/CompilerView.xaml index 89636ccc..1d88eefa 100644 --- a/Wabbajack/Views/Compilers/CompilerView.xaml +++ b/Wabbajack/Views/Compilers/CompilerView.xaml @@ -64,7 +64,7 @@ Margin="5" Background="Transparent" HorizontalScrollBarVisibility="Disabled" - IsEnabled="{Binding Compiler.Compiling, Converter={StaticResource InverseBooleanConverter}}" + IsEnabled="{Binding Compiling, Converter={StaticResource InverseBooleanConverter}}" VerticalScrollBarVisibility="Auto"> + Visibility="{Binding Compiling, Converter={StaticResource bool2VisibilityConverter}, ConverterParameter=False}"> @@ -218,7 +218,7 @@ Grid.Column="0" Grid.ColumnSpan="5" Margin="5" - Visibility="{Binding Compiler.Compiling, Converter={StaticResource bool2VisibilityConverter}, FallbackValue=Hidden}"> + Visibility="{Binding Compiling, Converter={StaticResource bool2VisibilityConverter}, FallbackValue=Hidden}">