ISubCompilerVM.ActiveCompilation

This commit is contained in:
Justin Swanson 2019-11-20 23:15:47 -06:00
parent 2bebad5fae
commit 587395e98b
5 changed files with 27 additions and 25 deletions

View File

@ -32,6 +32,9 @@ namespace Wabbajack
private readonly ObservableAsPropertyHelper<StatusUpdateTracker> _CurrentStatusTracker; private readonly ObservableAsPropertyHelper<StatusUpdateTracker> _CurrentStatusTracker;
public StatusUpdateTracker CurrentStatusTracker => _CurrentStatusTracker.Value; public StatusUpdateTracker CurrentStatusTracker => _CurrentStatusTracker.Value;
private readonly ObservableAsPropertyHelper<bool> _Compiling;
public bool Compiling => _Compiling.Value;
public CompilerVM(MainWindowVM mainWindowVM) public CompilerVM(MainWindowVM mainWindowVM)
{ {
this.MWVM = mainWindowVM; this.MWVM = mainWindowVM;
@ -93,6 +96,11 @@ namespace Wabbajack
return null; return null;
}) })
.ToProperty(this, nameof(this.Image)); .ToProperty(this, nameof(this.Image));
this._Compiling = this.WhenAny(x => x.Compiler.ActiveCompilation)
.Select(compilation => compilation != null)
.ObserveOnGuiThread()
.ToProperty(this, nameof(this.Compiling));
} }
} }
} }

View File

@ -6,13 +6,14 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Input; using System.Windows.Input;
using Wabbajack.Common; using Wabbajack.Common;
using Wabbajack.Lib;
namespace Wabbajack namespace Wabbajack
{ {
public interface ISubCompilerVM public interface ISubCompilerVM
{ {
IReactiveCommand BeginCommand { get; } IReactiveCommand BeginCommand { get; }
bool Compiling { get; } ACompiler ActiveCompilation { get; }
ModlistSettingsEditorVM ModlistSettings { get; } ModlistSettingsEditorVM ModlistSettings { get; }
StatusUpdateTracker StatusTracker { get;} StatusUpdateTracker StatusTracker { get;}

View File

@ -31,8 +31,8 @@ namespace Wabbajack
public IReactiveCommand BeginCommand { get; } public IReactiveCommand BeginCommand { get; }
private readonly ObservableAsPropertyHelper<bool> _Compiling; [Reactive]
public bool Compiling => _Compiling.Value; public ACompiler ActiveCompilation { get; private set; }
private readonly ObservableAsPropertyHelper<ModlistSettingsEditorVM> _ModlistSettings; private readonly ObservableAsPropertyHelper<ModlistSettingsEditorVM> _ModlistSettings;
public ModlistSettingsEditorVM ModlistSettings => _ModlistSettings.Value; public ModlistSettingsEditorVM ModlistSettings => _ModlistSettings.Value;
@ -101,10 +101,9 @@ namespace Wabbajack
.ObserveOnGuiThread(), .ObserveOnGuiThread(),
execute: async () => execute: async () =>
{ {
MO2Compiler compiler;
try try
{ {
compiler = new MO2Compiler(this.Mo2Folder) this.ActiveCompilation = new MO2Compiler(this.Mo2Folder)
{ {
MO2Profile = this.MOProfile, MO2Profile = this.MOProfile,
ModListName = this.ModlistSettings.ModListName, ModListName = this.ModlistSettings.ModListName,
@ -114,10 +113,6 @@ namespace Wabbajack
ModListWebsite = this.ModlistSettings.Website, ModListWebsite = this.ModlistSettings.Website,
ModListReadme = this.ModlistSettings.ReadMeText.TargetPath, 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) catch (Exception ex)
{ {
@ -128,7 +123,7 @@ namespace Wabbajack
try try
{ {
await compiler.Begin(); await this.ActiveCompilation.Begin();
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -138,12 +133,11 @@ namespace Wabbajack
finally finally
{ {
this.StatusTracker = null; this.StatusTracker = null;
compiler.Dispose(); this.ActiveCompilation.Dispose();
this.ActiveCompilation = null;
} }
}); });
this._Compiling = this.BeginCommand.IsExecuting
.ToProperty(this, nameof(this.Compiling));
// Load settings // Load settings
this.settings = parent.MWVM.Settings.Compiler.MO2Compilation; this.settings = parent.MWVM.Settings.Compiler.MO2Compilation;

View File

@ -18,9 +18,6 @@ namespace Wabbajack
public IReactiveCommand BeginCommand { get; } public IReactiveCommand BeginCommand { get; }
private readonly ObservableAsPropertyHelper<bool> _compiling;
public bool Compiling => _compiling.Value;
private readonly ObservableAsPropertyHelper<ModlistSettingsEditorVM> _modListSettings; private readonly ObservableAsPropertyHelper<ModlistSettingsEditorVM> _modListSettings;
public ModlistSettingsEditorVM ModlistSettings => _modListSettings.Value; public ModlistSettingsEditorVM ModlistSettings => _modListSettings.Value;
@ -32,6 +29,9 @@ namespace Wabbajack
public ObservableCollectionExtended<GameVM> GameOptions => _gameOptions; public ObservableCollectionExtended<GameVM> GameOptions => _gameOptions;
[Reactive]
public ACompiler ActiveCompilation { get; private set; }
[Reactive] [Reactive]
public GameVM SelectedGame { get; set; } public GameVM SelectedGame { get; set; }
@ -82,10 +82,9 @@ namespace Wabbajack
.ObserveOnGuiThread(), .ObserveOnGuiThread(),
execute: async () => execute: async () =>
{ {
VortexCompiler compiler;
try try
{ {
compiler = new VortexCompiler( this.ActiveCompilation = new VortexCompiler(
SelectedGame.Game, SelectedGame.Game,
GameLocation.TargetPath, GameLocation.TargetPath,
VortexCompiler.TypicalVortexFolder(), VortexCompiler.TypicalVortexFolder(),
@ -110,7 +109,7 @@ namespace Wabbajack
{ {
try try
{ {
await compiler.Begin(); await this.ActiveCompilation.Begin();
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -120,11 +119,11 @@ namespace Wabbajack
finally finally
{ {
this.StatusTracker = null; this.StatusTracker = null;
this.ActiveCompilation.Dispose();
this.ActiveCompilation = null;
} }
}); });
}); });
_compiling = BeginCommand.IsExecuting
.ToProperty(this, nameof(Compiling));
// Load settings // Load settings
_settings = parent.MWVM.Settings.Compiler.VortexCompilation; _settings = parent.MWVM.Settings.Compiler.VortexCompilation;

View File

@ -64,7 +64,7 @@
Margin="5" Margin="5"
Background="Transparent" Background="Transparent"
HorizontalScrollBarVisibility="Disabled" HorizontalScrollBarVisibility="Disabled"
IsEnabled="{Binding Compiler.Compiling, Converter={StaticResource InverseBooleanConverter}}" IsEnabled="{Binding Compiling, Converter={StaticResource InverseBooleanConverter}}"
VerticalScrollBarVisibility="Auto"> VerticalScrollBarVisibility="Auto">
<StackPanel <StackPanel
Margin="0,5,0,0" Margin="0,5,0,0"
@ -152,7 +152,7 @@
Margin="35,0,35,0" Margin="35,0,35,0"
VerticalAlignment="Center" VerticalAlignment="Center"
ClipToBounds="False" ClipToBounds="False"
Visibility="{Binding Compiler.Compiling, Converter={StaticResource bool2VisibilityConverter}, ConverterParameter=False}"> Visibility="{Binding Compiling, Converter={StaticResource bool2VisibilityConverter}, ConverterParameter=False}">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="*" /> <RowDefinition Height="*" />
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
@ -218,7 +218,7 @@
Grid.Column="0" Grid.Column="0"
Grid.ColumnSpan="5" Grid.ColumnSpan="5"
Margin="5" Margin="5"
Visibility="{Binding Compiler.Compiling, Converter={StaticResource bool2VisibilityConverter}, FallbackValue=Hidden}"> Visibility="{Binding Compiling, Converter={StaticResource bool2VisibilityConverter}, FallbackValue=Hidden}">
<local:LogCpuView DataContext="{Binding MWVM}" /> <local:LogCpuView DataContext="{Binding MWVM}" />
</Grid> </Grid>
</Grid> </Grid>