Some ISubInstallerVM work

This commit is contained in:
Justin Swanson
2019-12-01 23:36:47 -06:00
parent 5bb291a310
commit fb2cb28cf4
7 changed files with 153 additions and 79 deletions

View File

@ -28,9 +28,6 @@ namespace Wabbajack
private readonly ObservableAsPropertyHelper<ModlistSettingsEditorVM> _currentModlistSettings; private readonly ObservableAsPropertyHelper<ModlistSettingsEditorVM> _currentModlistSettings;
public ModlistSettingsEditorVM CurrentModlistSettings => _currentModlistSettings.Value; public ModlistSettingsEditorVM CurrentModlistSettings => _currentModlistSettings.Value;
private readonly ObservableAsPropertyHelper<StatusUpdateTracker> _currentStatusTracker;
public StatusUpdateTracker CurrentStatusTracker => _currentStatusTracker.Value;
private readonly ObservableAsPropertyHelper<bool> _compiling; private readonly ObservableAsPropertyHelper<bool> _compiling;
public bool Compiling => _compiling.Value; public bool Compiling => _compiling.Value;
@ -86,10 +83,6 @@ namespace Wabbajack
_currentModlistSettings = this.WhenAny(x => x.Compiler.ModlistSettings) _currentModlistSettings = this.WhenAny(x => x.Compiler.ModlistSettings)
.ToProperty(this, nameof(CurrentModlistSettings)); .ToProperty(this, nameof(CurrentModlistSettings));
// Let sub VM determine what progress we're seeing
_currentStatusTracker = this.WhenAny(x => x.Compiler.StatusTracker)
.ToProperty(this, nameof(CurrentStatusTracker));
_image = this.WhenAny(x => x.CurrentModlistSettings.ImagePath.TargetPath) _image = this.WhenAny(x => x.CurrentModlistSettings.ImagePath.TargetPath)
// Throttle so that it only loads image after any sets of swaps have completed // Throttle so that it only loads image after any sets of swaps have completed
.Throttle(TimeSpan.FromMilliseconds(50), RxApp.MainThreadScheduler) .Throttle(TimeSpan.FromMilliseconds(50), RxApp.MainThreadScheduler)

View File

@ -10,7 +10,6 @@ namespace Wabbajack
ACompiler ActiveCompilation { get; } ACompiler ActiveCompilation { get; }
ModlistSettingsEditorVM ModlistSettings { get; } ModlistSettingsEditorVM ModlistSettings { get; }
StatusUpdateTracker StatusTracker { get;}
void Unload(); void Unload();
} }
} }

View File

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ReactiveUI;
using Wabbajack.Common;
using Wabbajack.Lib;
namespace Wabbajack
{
public interface ISubInstallerVM
{
IReactiveCommand BeginCommand { get; }
AInstaller ActiveInstallation { get; }
void Unload();
}
}

View File

@ -17,6 +17,7 @@ using ReactiveUI.Fody.Helpers;
using System.Windows.Media; using System.Windows.Media;
using DynamicData; using DynamicData;
using DynamicData.Binding; using DynamicData.Binding;
using System.Reactive;
namespace Wabbajack namespace Wabbajack
{ {
@ -33,15 +34,12 @@ namespace Wabbajack
public FilePickerVM ModListPath { get; } public FilePickerVM ModListPath { get; }
[Reactive] private readonly ObservableAsPropertyHelper<ISubInstallerVM> _installer;
public bool UIReady { get; set; } public ISubInstallerVM Installer => _installer.Value;
private readonly ObservableAsPropertyHelper<string> _htmlReport; private readonly ObservableAsPropertyHelper<string> _htmlReport;
public string HTMLReport => _htmlReport.Value; public string HTMLReport => _htmlReport.Value;
[Reactive]
public AInstaller ActiveInstallation { get; private set; }
private readonly ObservableAsPropertyHelper<bool> _installing; private readonly ObservableAsPropertyHelper<bool> _installing;
public bool Installing => _installing.Value; public bool Installing => _installing.Value;
@ -82,8 +80,10 @@ namespace Wabbajack
private readonly ObservableAsPropertyHelper<ModlistInstallationSettings> _CurrentSettings; private readonly ObservableAsPropertyHelper<ModlistInstallationSettings> _CurrentSettings;
public ModlistInstallationSettings CurrentSettings => _CurrentSettings.Value; public ModlistInstallationSettings CurrentSettings => _CurrentSettings.Value;
private readonly ObservableAsPropertyHelper<ModManager?> _TargetManager;
public ModManager? TargetManager => _TargetManager.Value;
// Command properties // Command properties
public IReactiveCommand BeginCommand { get; }
public IReactiveCommand ShowReportCommand { get; } public IReactiveCommand ShowReportCommand { get; }
public IReactiveCommand OpenReadmeCommand { get; } public IReactiveCommand OpenReadmeCommand { get; }
public IReactiveCommand VisitWebsiteCommand { get; } public IReactiveCommand VisitWebsiteCommand { get; }
@ -127,6 +127,31 @@ namespace Wabbajack
PromptTitle = "Select a modlist to install" PromptTitle = "Select a modlist to install"
}; };
// Swap to proper sub VM based on selected type
_installer = this.WhenAny(x => x.TargetManager)
// Delay so the initial VM swap comes in immediately, subVM comes right after
.DelayInitial(TimeSpan.FromMilliseconds(50), RxApp.MainThreadScheduler)
.Select<ModManager?, ISubInstallerVM>(type =>
{
switch (type)
{
case ModManager.MO2:
return new MO2InstallerVM(this);
case ModManager.Vortex:
throw new NotImplementedException();
default:
return null;
}
})
// Unload old VM
.Pairwise()
.Do(pair =>
{
pair.Previous?.Unload();
})
.Select(p => p.Current)
.ToProperty(this, nameof(Installer));
// Load settings // Load settings
_CurrentSettings = this.WhenAny(x => x.ModListPath.TargetPath) _CurrentSettings = this.WhenAny(x => x.ModListPath.TargetPath)
.Select(path => path == null ? null : MWVM.Settings.Installer.ModlistSettings.TryCreate(path)) .Select(path => path == null ? null : MWVM.Settings.Installer.ModlistSettings.TryCreate(path))
@ -161,17 +186,20 @@ namespace Wabbajack
_htmlReport = this.WhenAny(x => x.ModList) _htmlReport = this.WhenAny(x => x.ModList)
.Select(modList => modList?.ReportHTML) .Select(modList => modList?.ReportHTML)
.ToProperty(this, nameof(HTMLReport)); .ToProperty(this, nameof(HTMLReport));
_installing = this.WhenAny(x => x.ActiveInstallation) _installing = this.WhenAny(x => x.Installer.ActiveInstallation)
.Select(compilation => compilation != null) .Select(compilation => compilation != null)
.ObserveOnGuiThread() .ObserveOnGuiThread()
.ToProperty(this, nameof(Installing)); .ToProperty(this, nameof(Installing));
_TargetManager = this.WhenAny(x => x.ModList)
.Select(modList => modList?.ModManager)
.ToProperty(this, nameof(TargetManager));
BackCommand = ReactiveCommand.Create( BackCommand = ReactiveCommand.Create(
execute: () => mainWindowVM.ActivePane = mainWindowVM.ModeSelectionVM, execute: () => mainWindowVM.ActivePane = mainWindowVM.ModeSelectionVM,
canExecute: this.WhenAny(x => x.Installing) canExecute: this.WhenAny(x => x.Installing)
.Select(x => !x)); .Select(x => !x));
_percentCompleted = this.WhenAny(x => x.ActiveInstallation) _percentCompleted = this.WhenAny(x => x.Installer.ActiveInstallation)
.StartWith(default(AInstaller)) .StartWith(default(AInstaller))
.Pairwise() .Pairwise()
.Select(c => .Select(c =>
@ -233,18 +261,6 @@ namespace Wabbajack
canExecute: this.WhenAny(x => x.ModList) canExecute: this.WhenAny(x => x.ModList)
.Select(modList => !string.IsNullOrEmpty(modList?.Readme)) .Select(modList => !string.IsNullOrEmpty(modList?.Readme))
.ObserveOnGuiThread()); .ObserveOnGuiThread());
BeginCommand = ReactiveCommand.CreateFromTask(
execute: ExecuteBegin,
canExecute: Observable.CombineLatest(
this.WhenAny(x => x.Installing),
this.WhenAny(x => x.Location.InError),
this.WhenAny(x => x.DownloadLocation.InError),
resultSelector: (installing, loc, download) =>
{
if (installing) return false;
return !loc && !download;
})
.ObserveOnGuiThread());
VisitWebsiteCommand = ReactiveCommand.Create( VisitWebsiteCommand = ReactiveCommand.Create(
execute: () => Process.Start(ModList.Website), execute: () => Process.Start(ModList.Website),
canExecute: this.WhenAny(x => x.ModList.Website) canExecute: this.WhenAny(x => x.ModList.Website)
@ -274,7 +290,7 @@ namespace Wabbajack
.ToProperty(this, nameof(ProgressTitle)); .ToProperty(this, nameof(ProgressTitle));
// Compile progress updates and populate ObservableCollection // Compile progress updates and populate ObservableCollection
this.WhenAny(x => x.ActiveInstallation) this.WhenAny(x => x.Installer.ActiveInstallation)
.SelectMany(c => c?.QueueStatus ?? Observable.Empty<CPUStatus>()) .SelectMany(c => c?.QueueStatus ?? Observable.Empty<CPUStatus>())
.ObserveOn(RxApp.TaskpoolScheduler) .ObserveOn(RxApp.TaskpoolScheduler)
.ToObservableChangeSet(x => x.ID) .ToObservableChangeSet(x => x.ID)
@ -286,6 +302,16 @@ namespace Wabbajack
.Bind(StatusList) .Bind(StatusList)
.Subscribe() .Subscribe()
.DisposeWith(CompositeDisposable); .DisposeWith(CompositeDisposable);
// When sub installer begins an install, mark state variable
this.WhenAny(x => x.Installer.BeginCommand)
.Select(x => x?.StartingExecution() ?? Observable.Empty<Unit>())
.Switch()
.Subscribe(_ =>
{
InstallingMode = true;
})
.DisposeWith(CompositeDisposable);
} }
private void ShowReport() private void ShowReport()
@ -321,54 +347,6 @@ namespace Wabbajack
} }
} }
private async Task ExecuteBegin()
{
InstallingMode = true;
AInstaller installer;
try
{
installer = new MO2Installer(
archive: ModListPath.TargetPath,
modList: ModList.SourceModList,
outputFolder: Location.TargetPath,
downloadFolder: DownloadLocation.TargetPath);
}
catch (Exception ex)
{
while (ex.InnerException != null) ex = ex.InnerException;
Utils.Log(ex.StackTrace);
Utils.Log(ex.ToString());
Utils.Log($"{ex.Message} - Can't continue");
ActiveInstallation = null;
return;
}
await Task.Run(async () =>
{
IDisposable subscription = null;
try
{
var workTask = installer.Begin();
ActiveInstallation = installer;
await workTask;
}
catch (Exception ex)
{
while (ex.InnerException != null) ex = ex.InnerException;
Utils.Log(ex.StackTrace);
Utils.Log(ex.ToString());
Utils.Log($"{ex.Message} - Can't continue");
}
finally
{
// Dispose of CPU tracking systems
subscription?.Dispose();
ActiveInstallation = null;
}
});
}
private void SaveSettings(ModlistInstallationSettings settings) private void SaveSettings(ModlistInstallationSettings settings)
{ {
MWVM.Settings.Installer.LastInstalledListLocation = ModListPath.TargetPath; MWVM.Settings.Installer.LastInstalledListLocation = ModListPath.TargetPath;

View File

@ -0,0 +1,84 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive.Linq;
using System.Text;
using System.Threading.Tasks;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;
using Wabbajack.Common;
using Wabbajack.Lib;
namespace Wabbajack
{
public class MO2InstallerVM : ViewModel, ISubInstallerVM
{
public IReactiveCommand BeginCommand { get; }
[Reactive]
public AInstaller ActiveInstallation { get; private set; }
public MO2InstallerVM(InstallerVM installerVM)
{
BeginCommand = ReactiveCommand.CreateFromTask(
canExecute: Observable.CombineLatest(
installerVM.WhenAny(x => x.Location.InError),
installerVM.WhenAny(x => x.DownloadLocation.InError),
resultSelector: (loc, download) =>
{
return !loc && !download;
})
.ObserveOnGuiThread(),
execute: async () =>
{
AInstaller installer;
try
{
installer = new MO2Installer(
archive: installerVM.ModListPath.TargetPath,
modList: installerVM.ModList.SourceModList,
outputFolder: installerVM.Location.TargetPath,
downloadFolder: installerVM.DownloadLocation.TargetPath);
}
catch (Exception ex)
{
while (ex.InnerException != null) ex = ex.InnerException;
Utils.Log(ex.StackTrace);
Utils.Log(ex.ToString());
Utils.Log($"{ex.Message} - Can't continue");
ActiveInstallation = null;
return;
}
await Task.Run(async () =>
{
IDisposable subscription = null;
try
{
var workTask = installer.Begin();
ActiveInstallation = installer;
await workTask;
}
catch (Exception ex)
{
while (ex.InnerException != null) ex = ex.InnerException;
Utils.Log(ex.StackTrace);
Utils.Log(ex.ToString());
Utils.Log($"{ex.Message} - Can't continue");
}
finally
{
// Dispose of CPU tracking systems
subscription?.Dispose();
ActiveInstallation = null;
}
});
});
}
public void Unload()
{
}
}
}

View File

@ -347,7 +347,7 @@
Grid.Column="4" Grid.Column="4"
Margin="0,0,25,0" Margin="0,0,25,0"
HorizontalAlignment="Right" HorizontalAlignment="Right"
Command="{Binding BeginCommand, Mode=OneWay}" /> Command="{Binding Installer.BeginCommand, Mode=OneWay}" />
</Grid> </Grid>
</ScrollViewer> </ScrollViewer>
</Grid> </Grid>

View File

@ -169,6 +169,8 @@
<SubType>Designer</SubType> <SubType>Designer</SubType>
</ApplicationDefinition> </ApplicationDefinition>
<Compile Include="Converters\EqualsToBoolConverter.cs" /> <Compile Include="Converters\EqualsToBoolConverter.cs" />
<Compile Include="View Models\Installers\ISubInstallerVM.cs" />
<Compile Include="View Models\Installers\MO2InstallerVM.cs" />
<Compile Include="View Models\ModListGalleryVM.cs" /> <Compile Include="View Models\ModListGalleryVM.cs" />
<Compile Include="View Models\ModListMetadataVM.cs" /> <Compile Include="View Models\ModListMetadataVM.cs" />
<Compile Include="Views\Common\HeatedBackgroundView.xaml.cs"> <Compile Include="Views\Common\HeatedBackgroundView.xaml.cs">
@ -301,7 +303,7 @@
<DependentUpon>App.xaml</DependentUpon> <DependentUpon>App.xaml</DependentUpon>
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="View Models\InstallerVM.cs" /> <Compile Include="View Models\Installers\InstallerVM.cs" />
<Compile Include="Util\AutoScrollBehavior.cs" /> <Compile Include="Util\AutoScrollBehavior.cs" />
<Compile Include="Views\MainWindow.xaml.cs"> <Compile Include="Views\MainWindow.xaml.cs">
<DependentUpon>MainWindow.xaml</DependentUpon> <DependentUpon>MainWindow.xaml</DependentUpon>