VortexCompiler VM/View work

This commit is contained in:
Justin Swanson 2019-11-16 17:10:17 -06:00
parent 2e9f222648
commit 5cfc319822
7 changed files with 310 additions and 9 deletions

View File

@ -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<Game, CompilationModlistSettings> ModlistSettings { get; } = new Dictionary<Game, CompilationModlistSettings>();
public Dictionary<Game, VortexGameSettings> ModlistSettings { get; } = new Dictionary<Game, VortexGameSettings>();
}
public class VortexGameSettings
{
public string GameLocation { get; set; }
public CompilationModlistSettings ModlistSettings { get; } = new CompilationModlistSettings();
}
}

View File

@ -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;
}

View File

@ -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<bool> _Compiling;
public bool Compiling => _Compiling.Value;
public void Unload() => throw new NotImplementedException();
private readonly ObservableAsPropertyHelper<ModlistSettingsEditorVM> _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();
}
}
}
}

View File

@ -198,6 +198,9 @@
<DataTemplate DataType="{x:Type local:MO2CompilerVM}">
<local:MO2CompilerConfigView />
</DataTemplate>
<DataTemplate DataType="{x:Type local:VortexCompilerVM}">
<local:VortexCompilerConfigView />
</DataTemplate>
</ContentPresenter.Resources>
</ContentPresenter>
<local:BeginButton

View File

@ -0,0 +1,108 @@
<UserControl
x:Class="Wabbajack.VortexCompilerConfigView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Wabbajack"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
d:DesignHeight="450"
d:DesignWidth="800"
mc:Ignorable="d">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="20" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="30" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="20" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="40" />
<RowDefinition Height="40" />
<RowDefinition Height="40" />
</Grid.RowDefinitions>
<TextBlock
Grid.Row="0"
Grid.Column="0"
HorizontalAlignment="Right"
VerticalAlignment="Center"
FontSize="14"
Text="Game"
TextAlignment="Center"
ToolTip="The game you wish to target" />
<ComboBox
Grid.Row="0"
Grid.Column="2"
Height="30"
VerticalAlignment="Center"
ToolTip="The game you wish to target" />
<TextBlock
Grid.Row="1"
Grid.Column="0"
HorizontalAlignment="Right"
VerticalAlignment="Center"
FontSize="14"
Text="Game Folder"
TextAlignment="Center"
ToolTip="The install folder for the game" />
<local:FilePicker
Grid.Row="1"
Grid.Column="2"
Height="30"
VerticalAlignment="Center"
DataContext="{Binding GameLocation}"
FontSize="14"
ToolTip="The install folder for the game" />
<TextBlock
Grid.Row="0"
Grid.Column="4"
HorizontalAlignment="Right"
VerticalAlignment="Center"
FontSize="14"
Text="Vortex Location"
TextAlignment="Center"
ToolTip="The Vortex program installation location" />
<local:FilePicker
Grid.Row="0"
Grid.Column="6"
Height="30"
VerticalAlignment="Center"
DataContext="{Binding VortexLocation}"
FontSize="14"
ToolTip="The Vortex program installation location" />
<TextBlock
Grid.Row="1"
Grid.Column="4"
HorizontalAlignment="Right"
VerticalAlignment="Center"
FontSize="14"
Text="Download Location"
TextAlignment="Center"
ToolTip="The folder to downloads your mods" />
<local:FilePicker
Grid.Row="1"
Grid.Column="6"
Height="30"
VerticalAlignment="Center"
DataContext="{Binding DownloadLocation}"
FontSize="14"
ToolTip="The folder to downloads your mods" />
<TextBlock
Grid.Row="2"
Grid.Column="4"
HorizontalAlignment="Right"
VerticalAlignment="Center"
FontSize="14"
Text="Staging Location"
TextAlignment="Center" />
<local:FilePicker
Grid.Row="2"
Grid.Column="6"
Height="30"
VerticalAlignment="Center"
DataContext="{Binding StagingLocation}"
FontSize="14" />
</Grid>
</UserControl>

View File

@ -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
{
/// <summary>
/// Interaction logic for VortexCompilerConfigView.xaml
/// </summary>
public partial class VortexCompilerConfigView : UserControl
{
public VortexCompilerConfigView()
{
InitializeComponent();
}
}
}

View File

@ -226,6 +226,9 @@
<DependentUpon>TextViewer.xaml</DependentUpon>
</Compile>
<Compile Include="Views\UserControlRx.cs" />
<Compile Include="Views\Compilers\VortexCompilerConfigView.xaml.cs">
<DependentUpon>VortexCompilerConfigView.xaml</DependentUpon>
</Compile>
<Page Include="Views\Compilers\MO2CompilerConfigView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
@ -300,6 +303,10 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Views\Compilers\VortexCompilerConfigView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs">