2019-11-21 05:17:40 +00:00
|
|
|
|
using DynamicData;
|
|
|
|
|
using DynamicData.Binding;
|
|
|
|
|
using Microsoft.WindowsAPICodePack.Dialogs;
|
2019-11-14 05:28:27 +00:00
|
|
|
|
using ReactiveUI;
|
|
|
|
|
using ReactiveUI.Fody.Helpers;
|
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Reactive.Disposables;
|
|
|
|
|
using System.Reactive.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Media.Imaging;
|
|
|
|
|
using Wabbajack.Common;
|
|
|
|
|
using Wabbajack.Lib;
|
|
|
|
|
|
|
|
|
|
namespace Wabbajack
|
|
|
|
|
{
|
|
|
|
|
public class CompilerVM : ViewModel
|
|
|
|
|
{
|
|
|
|
|
public MainWindowVM MWVM { get; }
|
|
|
|
|
|
|
|
|
|
private readonly ObservableAsPropertyHelper<BitmapImage> _Image;
|
|
|
|
|
public BitmapImage Image => _Image.Value;
|
|
|
|
|
|
|
|
|
|
[Reactive]
|
|
|
|
|
public ModManager SelectedCompilerType { get; set; }
|
|
|
|
|
|
|
|
|
|
private readonly ObservableAsPropertyHelper<ISubCompilerVM> _Compiler;
|
|
|
|
|
public ISubCompilerVM Compiler => _Compiler.Value;
|
|
|
|
|
|
|
|
|
|
private readonly ObservableAsPropertyHelper<ModlistSettingsEditorVM> _CurrentModlistSettings;
|
|
|
|
|
public ModlistSettingsEditorVM CurrentModlistSettings => _CurrentModlistSettings.Value;
|
|
|
|
|
|
2019-11-17 07:59:00 +00:00
|
|
|
|
private readonly ObservableAsPropertyHelper<StatusUpdateTracker> _CurrentStatusTracker;
|
|
|
|
|
public StatusUpdateTracker CurrentStatusTracker => _CurrentStatusTracker.Value;
|
|
|
|
|
|
2019-11-21 05:15:47 +00:00
|
|
|
|
private readonly ObservableAsPropertyHelper<bool> _Compiling;
|
|
|
|
|
public bool Compiling => _Compiling.Value;
|
|
|
|
|
|
2019-11-14 05:28:27 +00:00
|
|
|
|
public CompilerVM(MainWindowVM mainWindowVM)
|
|
|
|
|
{
|
|
|
|
|
this.MWVM = mainWindowVM;
|
|
|
|
|
|
|
|
|
|
// Load settings
|
|
|
|
|
CompilerSettings settings = this.MWVM.Settings.Compiler;
|
|
|
|
|
this.SelectedCompilerType = settings.LastCompiledModManager;
|
|
|
|
|
this.MWVM.Settings.SaveSignal
|
|
|
|
|
.Subscribe(_ =>
|
|
|
|
|
{
|
|
|
|
|
settings.LastCompiledModManager = this.SelectedCompilerType;
|
|
|
|
|
})
|
|
|
|
|
.DisposeWith(this.CompositeDisposable);
|
|
|
|
|
|
|
|
|
|
// Swap to proper sub VM based on selected type
|
|
|
|
|
this._Compiler = this.WhenAny(x => x.SelectedCompilerType)
|
2019-11-15 04:54:34 +00:00
|
|
|
|
// Delay so the initial VM swap comes in immediately, subVM comes right after
|
|
|
|
|
.DelayInitial(TimeSpan.FromMilliseconds(50), RxApp.MainThreadScheduler)
|
2019-11-14 05:28:27 +00:00
|
|
|
|
.Select<ModManager, ISubCompilerVM>(type =>
|
|
|
|
|
{
|
|
|
|
|
switch (type)
|
|
|
|
|
{
|
|
|
|
|
case ModManager.MO2:
|
|
|
|
|
return new MO2CompilerVM(this);
|
|
|
|
|
case ModManager.Vortex:
|
2019-11-16 23:10:17 +00:00
|
|
|
|
return new VortexCompilerVM(this);
|
2019-11-14 05:28:27 +00:00
|
|
|
|
default:
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
})
|
2019-11-16 23:09:13 +00:00
|
|
|
|
// Unload old VM
|
|
|
|
|
.Pairwise()
|
|
|
|
|
.Do(pair =>
|
|
|
|
|
{
|
|
|
|
|
pair.Previous?.Unload();
|
|
|
|
|
})
|
|
|
|
|
.Select(p => p.Current)
|
2019-11-14 05:28:27 +00:00
|
|
|
|
.ToProperty(this, nameof(this.Compiler));
|
|
|
|
|
|
2019-11-17 07:59:00 +00:00
|
|
|
|
// Let sub VM determine what settings we're displaying and when
|
|
|
|
|
this._CurrentModlistSettings = this.WhenAny(x => x.Compiler.ModlistSettings)
|
2019-11-14 05:28:27 +00:00
|
|
|
|
.ToProperty(this, nameof(this.CurrentModlistSettings));
|
|
|
|
|
|
2019-11-17 07:59:00 +00:00
|
|
|
|
// Let sub VM determine what progress we're seeing
|
|
|
|
|
this._CurrentStatusTracker = this.WhenAny(x => x.Compiler.StatusTracker)
|
|
|
|
|
.ToProperty(this, nameof(this.CurrentStatusTracker));
|
|
|
|
|
|
2019-11-14 05:28:27 +00:00
|
|
|
|
this._Image = this.WhenAny(x => x.CurrentModlistSettings.ImagePath.TargetPath)
|
2019-11-15 05:31:46 +00:00
|
|
|
|
// Throttle so that it only loads image after any sets of swaps have completed
|
|
|
|
|
.Throttle(TimeSpan.FromMilliseconds(50), RxApp.MainThreadScheduler)
|
|
|
|
|
.DistinctUntilChanged()
|
2019-11-14 05:28:27 +00:00
|
|
|
|
.Select(path =>
|
|
|
|
|
{
|
2019-11-16 23:07:53 +00:00
|
|
|
|
if (string.IsNullOrWhiteSpace(path)) return UIUtils.BitmapImageFromResource("Wabbajack.Resources.Wabba_Mouth.png");
|
2019-11-14 05:28:27 +00:00
|
|
|
|
if (UIUtils.TryGetBitmapImageFromFile(path, out var image))
|
|
|
|
|
{
|
|
|
|
|
return image;
|
|
|
|
|
}
|
2019-11-15 04:59:59 +00:00
|
|
|
|
return null;
|
2019-11-14 05:28:27 +00:00
|
|
|
|
})
|
|
|
|
|
.ToProperty(this, nameof(this.Image));
|
2019-11-21 05:15:47 +00:00
|
|
|
|
|
|
|
|
|
this._Compiling = this.WhenAny(x => x.Compiler.ActiveCompilation)
|
|
|
|
|
.Select(compilation => compilation != null)
|
|
|
|
|
.ObserveOnGuiThread()
|
|
|
|
|
.ToProperty(this, nameof(this.Compiling));
|
2019-11-21 05:17:40 +00:00
|
|
|
|
|
|
|
|
|
// Compile progress updates and populate ObservableCollection
|
|
|
|
|
var subscription = this.WhenAny(x => x.Compiler.ActiveCompilation)
|
|
|
|
|
.SelectMany(c => c?.QueueStatus ?? Observable.Empty<CPUStatus>())
|
|
|
|
|
.ObserveOn(RxApp.TaskpoolScheduler)
|
|
|
|
|
.ToObservableChangeSet(x => x.ID)
|
|
|
|
|
.Batch(TimeSpan.FromMilliseconds(250), RxApp.TaskpoolScheduler)
|
|
|
|
|
.EnsureUniqueChanges()
|
|
|
|
|
.ObserveOn(RxApp.MainThreadScheduler)
|
|
|
|
|
.Sort(SortExpressionComparer<CPUStatus>.Ascending(s => s.ID), SortOptimisations.ComparesImmutableValuesOnly)
|
|
|
|
|
.Bind(this.MWVM.StatusList)
|
|
|
|
|
.Subscribe()
|
|
|
|
|
.DisposeWith(this.CompositeDisposable);
|
2019-11-14 05:28:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|