Compiler begin button wired up and fixed a bit

This commit is contained in:
Justin Swanson 2019-11-09 19:19:18 -06:00
parent 5b4cb1fa89
commit 197d2317f9
7 changed files with 77 additions and 32 deletions

View File

@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;
namespace Wabbajack
{
[ValueConversion(typeof(Visibility), typeof(bool))]
public class BoolToVisibilityHiddenConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (targetType != typeof(Visibility))
throw new InvalidOperationException($"The target must be of type {nameof(Visibility)}");
bool compareTo = true;
if (parameter is bool p)
{
compareTo = p;
}
else if (parameter is string str && str.ToUpper().Equals("FALSE"))
{
compareTo = false;
}
return ((bool)value) == compareTo ? Visibility.Visible : Visibility.Hidden;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}

View File

@ -9,6 +9,7 @@
<!--Converters-->
<local:BoolToVisibilityConverter x:Key="bool2VisibilityConverter" />
<local:BoolToVisibilityHiddenConverter x:Key="bool2VisibilityHiddenConverter" />
<local:IsNotNullVisibilityConverter x:Key="IsNotNullVisibilityConverter"/>
<!--Colors-->

View File

@ -87,8 +87,11 @@ namespace Wabbajack
this.BeginCommand = ReactiveCommand.CreateFromTask(
execute: this.ExecuteBegin,
canExecute: this.WhenAny(x => x.Compiling)
.Select(compiling => !compiling)
canExecute: Observable.CombineLatest(
this.WhenAny(x => x.Compiling),
this.WhenAny(x => x.ModlistLocation.InError),
this.WhenAny(x => x.DownloadLocation.InError),
resultSelector: (c, ml, down) => !c && !ml && !down)
.ObserveOnGuiThread());
this._Image = this.WhenAny(x => x.ImagePath.TargetPath)
@ -154,7 +157,7 @@ namespace Wabbajack
.Select<string, IErrorResponse>(moFolder =>
{
if (Directory.Exists(moFolder)) return ErrorResponse.Success;
return ErrorResponse.Fail("MO2 Folder could not be located from the given modlist location. Make sure your modlist is inside a valid MO2 distribution.");
return ErrorResponse.Fail($"MO2 Folder could not be located from the given modlist location.{Environment.NewLine}Make sure your modlist is inside a valid MO2 distribution.");
});
// Load settings
@ -193,9 +196,10 @@ namespace Wabbajack
private async Task ExecuteBegin()
{
if (this.Mo2Folder != null)
Compiler compiler;
try
{
var compiler = new Compiler(this.Mo2Folder)
compiler = new Compiler(this.Mo2Folder)
{
MO2Profile = this.MOProfile,
ModListName = this.ModListName,
@ -205,33 +209,34 @@ namespace Wabbajack
ModListWebsite = this.Website,
ModListReadme = this.ReadMeText.TargetPath,
};
await Task.Run(() =>
{
Compiling = true;
try
{
compiler.Compile();
if (compiler.ModList?.ReportHTML != null)
{
this.HTMLReport = compiler.ModList.ReportHTML;
}
}
catch (Exception ex)
{
while (ex.InnerException != null) ex = ex.InnerException;
Utils.Log($"Can't continue: {ex.ExceptionToString()}");
}
finally
{
Compiling = false;
}
});
}
else
catch (Exception ex)
{
Utils.Log("Cannot compile modlist: no valid Mod Organizer profile directory selected.");
Compiling = false;
while (ex.InnerException != null) ex = ex.InnerException;
Utils.Log($"Compiler error: {ex.ExceptionToString()}");
return;
}
await Task.Run(() =>
{
Compiling = true;
try
{
compiler.Compile();
if (compiler.ModList?.ReportHTML != null)
{
this.HTMLReport = compiler.ModList.ReportHTML;
}
}
catch (Exception ex)
{
while (ex.InnerException != null) ex = ex.InnerException;
Utils.Log($"Compiler error: {ex.ExceptionToString()}");
}
finally
{
Compiling = false;
}
});
}
}
}

View File

@ -16,7 +16,7 @@
VerticalAlignment="Center"
Background="{StaticResource PrimaryVariantBrush}"
CornerRadius="43"
Visibility="{Binding IsEnabled, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}, Converter={StaticResource bool2VisibilityConverter}}">
Visibility="{Binding IsEnabled, ElementName=button, Converter={StaticResource bool2VisibilityHiddenConverter}}">
<Border.Effect>
<BlurEffect Radius="10" />
</Border.Effect>
@ -32,6 +32,7 @@
</Border.Style>
</Border>
<Button
x:Name="button"
Width="54"
Height="54"
HorizontalAlignment="Center"

View File

@ -26,7 +26,7 @@ namespace Wabbajack
set => SetValue(CommandProperty, value);
}
public static readonly DependencyProperty CommandProperty = DependencyProperty.Register(nameof(Command), typeof(ICommand), typeof(BeginButton),
new FrameworkPropertyMetadata(default(ICommand), FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));
new FrameworkPropertyMetadata(default(ICommand)));
public BeginButton()
{

View File

@ -165,7 +165,8 @@
<local:BeginButton
Grid.Row="0"
Grid.RowSpan="2"
Grid.Column="4" />
Grid.Column="4"
Command="{Binding BeginCommand}" />
</Grid>
</Grid>
<Grid

View File

@ -161,6 +161,7 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="Converters\BoolToVisibilityHiddenConverter.cs" />
<Compile Include="Views\BeginButton.xaml.cs">
<DependentUpon>BeginButton.xaml</DependentUpon>
</Compile>