From 5cfc319822cad06ac5dc7230d483e25319538264 Mon Sep 17 00:00:00 2001 From: Justin Swanson Date: Sat, 16 Nov 2019 17:10:17 -0600 Subject: [PATCH] VortexCompiler VM/View work --- Wabbajack/Settings.cs | 11 +- Wabbajack/View Models/Compilers/CompilerVM.cs | 4 +- .../View Models/Compilers/VortexCompilerVM.cs | 158 +++++++++++++++++- Wabbajack/Views/Compilers/CompilerView.xaml | 3 + .../Compilers/VortexCompilerConfigView.xaml | 108 ++++++++++++ .../VortexCompilerConfigView.xaml.cs | 28 ++++ Wabbajack/Wabbajack.csproj | 7 + 7 files changed, 310 insertions(+), 9 deletions(-) create mode 100644 Wabbajack/Views/Compilers/VortexCompilerConfigView.xaml create mode 100644 Wabbajack/Views/Compilers/VortexCompilerConfigView.xaml.cs diff --git a/Wabbajack/Settings.cs b/Wabbajack/Settings.cs index 84d63649..b68caa47 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; @@ -87,8 +87,15 @@ namespace Wabbajack public class VortexCompilationSettings { + public string DownloadLocation { get; set; } public string StagingLocation { get; set; } public Game LastCompiledGame { get; set; } - public Dictionary ModlistSettings { get; } = new Dictionary(); + public Dictionary ModlistSettings { get; } = new Dictionary(); + } + + public class VortexGameSettings + { + public string GameLocation { get; set; } + public CompilationModlistSettings ModlistSettings { get; } = new CompilationModlistSettings(); } } diff --git a/Wabbajack/View Models/Compilers/CompilerVM.cs b/Wabbajack/View Models/Compilers/CompilerVM.cs index 5176a7b1..63ae0b50 100644 --- a/Wabbajack/View Models/Compilers/CompilerVM.cs +++ b/Wabbajack/View Models/Compilers/CompilerVM.cs @@ -1,4 +1,4 @@ -using Microsoft.WindowsAPICodePack.Dialogs; +using Microsoft.WindowsAPICodePack.Dialogs; using ReactiveUI; using ReactiveUI.Fody.Helpers; using System; @@ -54,7 +54,7 @@ namespace Wabbajack case ModManager.MO2: return new MO2CompilerVM(this); case ModManager.Vortex: - return new VortexCompilerVM(); + return new VortexCompilerVM(this); default: return null; } diff --git a/Wabbajack/View Models/Compilers/VortexCompilerVM.cs b/Wabbajack/View Models/Compilers/VortexCompilerVM.cs index 02216cb7..0860d9d5 100644 --- a/Wabbajack/View Models/Compilers/VortexCompilerVM.cs +++ b/Wabbajack/View Models/Compilers/VortexCompilerVM.cs @@ -1,21 +1,169 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Reactive.Disposables; +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 VortexCompilerVM : ViewModel, ISubCompilerVM { - public IReactiveCommand BeginCommand => throw new NotImplementedException(); + private readonly VortexCompilationSettings settings; - public bool Compiling => throw new NotImplementedException(); + public IReactiveCommand BeginCommand { get; } - public ModlistSettingsEditorVM ModlistSettings => throw new NotImplementedException(); + private readonly ObservableAsPropertyHelper _Compiling; + public bool Compiling => _Compiling.Value; - public void Unload() => throw new NotImplementedException(); + private readonly ObservableAsPropertyHelper _ModlistSettings; + public ModlistSettingsEditorVM ModlistSettings => _ModlistSettings.Value; + + [Reactive] + public Game SelectedGame { get; set; } + + [Reactive] + public FilePickerVM GameLocation { get; set; } + + [Reactive] + public FilePickerVM VortexLocation { get; set; } + + [Reactive] + public FilePickerVM DownloadsLocation { get; set; } + + [Reactive] + public FilePickerVM StagingLocation { get; set; } + + public VortexCompilerVM(CompilerVM parent) + { + this.GameLocation = new FilePickerVM() + { + DoExistsCheck = true, + PathType = FilePickerVM.PathTypeOptions.Folder, + PromptTitle = "Select Game Folder Location" + }; + this.VortexLocation = new FilePickerVM() + { + DoExistsCheck = true, + PathType = FilePickerVM.PathTypeOptions.Folder, + PromptTitle = "Select Vortex Install Folder" + }; + this.DownloadsLocation = new FilePickerVM() + { + DoExistsCheck = false, + PathType = FilePickerVM.PathTypeOptions.Folder, + PromptTitle = "Select Downloads Folder" + }; + this.StagingLocation = new FilePickerVM() + { + DoExistsCheck = false, + PathType = FilePickerVM.PathTypeOptions.Folder, + PromptTitle = "Select Staging Folder" + }; + + // Wire start command + this.BeginCommand = ReactiveCommand.CreateFromTask( + canExecute: Observable.CombineLatest( + this.WhenAny(x => x.GameLocation.InError), + this.WhenAny(x => x.VortexLocation.InError), + this.WhenAny(x => x.DownloadsLocation.InError), + this.WhenAny(x => x.StagingLocation.InError), + resultSelector: (g, v, d, s) => !g && !v && !d && !s) + .ObserveOnGuiThread(), + execute: async () => + { + VortexCompiler compiler; + try + { + compiler = new VortexCompiler( + game: this.SelectedGame, + gamePath: this.GameLocation.TargetPath, + vortexFolder: this.VortexLocation.TargetPath, + downloadsFolder: this.DownloadsLocation.TargetPath, + stagingFolder: this.StagingLocation.TargetPath); + } + catch (Exception ex) + { + while (ex.InnerException != null) ex = ex.InnerException; + Utils.Log($"Compiler error: {ex.ExceptionToString()}"); + return; + } + await Task.Run(() => + { + try + { + compiler.Compile(); + } + catch (Exception ex) + { + while (ex.InnerException != null) ex = ex.InnerException; + Utils.Log($"Compiler error: {ex.ExceptionToString()}"); + } + }); + }); + this._Compiling = this.BeginCommand.IsExecuting + .ToProperty(this, nameof(this.Compiling)); + + // Load settings + this.settings = parent.MWVM.Settings.Compiler.VortexCompilation; + this.SelectedGame = settings.LastCompiledGame; + if (!string.IsNullOrWhiteSpace(settings.DownloadLocation)) + { + this.DownloadsLocation.TargetPath = settings.DownloadLocation; + } + if (!string.IsNullOrWhiteSpace(settings.StagingLocation)) + { + this.StagingLocation.TargetPath = settings.StagingLocation; + } + parent.MWVM.Settings.SaveSignal + .Subscribe(_ => Unload()) + .DisposeWith(this.CompositeDisposable); + + // Load custom game settings when game type changes + this.WhenAny(x => x.SelectedGame) + .Select(game => settings.ModlistSettings.TryCreate(game)) + .Pairwise() + .Subscribe(pair => + { + if (pair.Previous != null) + { + pair.Previous.GameLocation = this.GameLocation.TargetPath; + } + this.GameLocation.TargetPath = pair.Current?.GameLocation ?? null; + }) + .DisposeWith(this.CompositeDisposable); + + // Load custom modlist settings when game type changes + this._ModlistSettings = this.WhenAny(x => x.SelectedGame) + .Select(game => + { + var gameSettings = settings.ModlistSettings.TryCreate(game); + return new ModlistSettingsEditorVM(gameSettings.ModlistSettings); + }) + // Interject and save old while loading new + .Pairwise() + .Do(pair => + { + pair.Previous?.Save(); + pair.Current?.Init(); + }) + .Select(x => x.Current) + // Save to property + .ObserveOnGuiThread() + .ToProperty(this, nameof(this.ModlistSettings)); + } + + public void Unload() + { + settings.DownloadLocation = this.DownloadsLocation.TargetPath; + settings.StagingLocation = this.StagingLocation.TargetPath; + settings.LastCompiledGame = this.SelectedGame; + this.ModlistSettings?.Save(); + } } -} +} \ No newline at end of file diff --git a/Wabbajack/Views/Compilers/CompilerView.xaml b/Wabbajack/Views/Compilers/CompilerView.xaml index 20e983ca..6916376e 100644 --- a/Wabbajack/Views/Compilers/CompilerView.xaml +++ b/Wabbajack/Views/Compilers/CompilerView.xaml @@ -198,6 +198,9 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Wabbajack/Views/Compilers/VortexCompilerConfigView.xaml.cs b/Wabbajack/Views/Compilers/VortexCompilerConfigView.xaml.cs new file mode 100644 index 00000000..324daa75 --- /dev/null +++ b/Wabbajack/Views/Compilers/VortexCompilerConfigView.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace Wabbajack +{ + /// + /// Interaction logic for VortexCompilerConfigView.xaml + /// + public partial class VortexCompilerConfigView : UserControl + { + public VortexCompilerConfigView() + { + InitializeComponent(); + } + } +} diff --git a/Wabbajack/Wabbajack.csproj b/Wabbajack/Wabbajack.csproj index b0819839..0bc1fa9a 100644 --- a/Wabbajack/Wabbajack.csproj +++ b/Wabbajack/Wabbajack.csproj @@ -226,6 +226,9 @@ TextViewer.xaml + + VortexCompilerConfigView.xaml + Designer MSBuild:Compile @@ -300,6 +303,10 @@ MSBuild:Compile Designer + + Designer + MSBuild:Compile +