Compilation View spruces/fixes. Basic FilePicker.Filter

This commit is contained in:
Justin Swanson
2019-10-31 18:44:17 -05:00
parent 75f61c2e18
commit 6eb75e1a9a
3 changed files with 62 additions and 124 deletions

View File

@ -5,6 +5,7 @@ using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Reactive.Disposables;
using System.Reactive.Linq; using System.Reactive.Linq;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
@ -15,15 +16,16 @@ using Wabbajack.Lib;
namespace Wabbajack namespace Wabbajack
{ {
public class CompilerVM : ViewModel, IDataErrorInfo public class CompilerVM : ViewModel
{ {
public MainWindowVM MWVM { get; } public MainWindowVM MWVM { get; }
public RunMode Mode => RunMode.Compile;
private string _Mo2Folder; private string _Mo2Folder;
public string Mo2Folder { get => _Mo2Folder; set => this.RaiseAndSetIfChanged(ref _Mo2Folder, value); } public string Mo2Folder { get => _Mo2Folder; set => this.RaiseAndSetIfChanged(ref _Mo2Folder, value); }
private string _MOProfile;
public string MOProfile { get => _MOProfile; set => this.RaiseAndSetIfChanged(ref _MOProfile, value); }
private string _ModListName; private string _ModListName;
public string ModListName { get => _ModListName; set => this.RaiseAndSetIfChanged(ref _ModListName, value); } public string ModListName { get => _ModListName; set => this.RaiseAndSetIfChanged(ref _ModListName, value); }
@ -33,9 +35,6 @@ namespace Wabbajack
private bool _UIReady = true; private bool _UIReady = true;
public bool UIReady { get => _UIReady; set => this.RaiseAndSetIfChanged(ref _UIReady, value); } public bool UIReady { get => _UIReady; set => this.RaiseAndSetIfChanged(ref _UIReady, value); }
private string _ModName;
public string ModName { get => _ModName; set => this.RaiseAndSetIfChanged(ref _ModName, value); }
private string _AuthorName; private string _AuthorName;
public string AuthorName { get => _AuthorName; set => this.RaiseAndSetIfChanged(ref _AuthorName, value); } public string AuthorName { get => _AuthorName; set => this.RaiseAndSetIfChanged(ref _AuthorName, value); }
@ -61,34 +60,16 @@ namespace Wabbajack
public string DownloadLocation { get => _DownloadLocation; set => this.RaiseAndSetIfChanged(ref _DownloadLocation, value); } public string DownloadLocation { get => _DownloadLocation; set => this.RaiseAndSetIfChanged(ref _DownloadLocation, value); }
public IReactiveCommand BeginCommand { get; } public IReactiveCommand BeginCommand { get; }
public IReactiveCommand ChangePathCommand { get; }
public IReactiveCommand ChangeDownloadPathCommand { get; }
public IReactiveCommand ChangeSplashScreenCommand { get; }
public CompilerVM(MainWindowVM mainWindowVM, string source) public CompilerVM(MainWindowVM mainWindowVM, string source)
{ {
this.MWVM = mainWindowVM; this.MWVM = mainWindowVM;
this.Location = Path.GetDirectoryName(source); this.Location = source;
this.BeginCommand = ReactiveCommand.Create( this.BeginCommand = ReactiveCommand.CreateFromTask(
execute: this.ExecuteBegin, execute: this.ExecuteBegin,
canExecute: this.WhenAny(x => x.UIReady) canExecute: this.WhenAny(x => x.UIReady)
.ObserveOnGuiThread()); .ObserveOnGuiThread());
this.ChangePathCommand = ReactiveCommand.Create(
ExecuteChangePath,
canExecute: this.WhenAny(x => x.UIReady)
.ObserveOnGuiThread());
this.ChangeDownloadPathCommand = ReactiveCommand.Create(
ExecuteChangeDownloadPath,
canExecute: this.WhenAny(x => x.UIReady)
.ObserveOnGuiThread());
this.ChangeSplashScreenCommand = ReactiveCommand.Create(
canExecute: this.WhenAny(x => x.UIReady)
.ObserveOnGuiThread(),
execute: () =>
{
this.ImagePath = UIUtils.OpenFileDialog("Banner image|*.png");
});
this._Image = this.WhenAny(x => x.ImagePath) this._Image = this.WhenAny(x => x.ImagePath)
.Select(path => .Select(path =>
@ -101,57 +82,47 @@ namespace Wabbajack
return UIUtils.BitmapImageFromResource("Wabbajack.Resources.none.png"); return UIUtils.BitmapImageFromResource("Wabbajack.Resources.none.png");
}) })
.ToProperty(this, nameof(this.Image)); .ToProperty(this, nameof(this.Image));
ConfigureForBuild(source);
} }
private void ExecuteChangePath() private void ConfigureForBuild(string location)
{ {
Location = UIUtils.ShowFolderSelectionDialog("Select Your MO2 profile directory"); var profile_folder = Path.GetDirectoryName(location);
}
private void ExecuteChangeDownloadPath()
{
var folder = UIUtils.ShowFolderSelectionDialog("Select a location for MO2 downloads");
if (folder != null)
{
DownloadLocation = folder;
}
}
private void ConfigureForBuild()
{
var profile_folder = Path.GetDirectoryName(Location);
this.Mo2Folder = Path.GetDirectoryName(Path.GetDirectoryName(profile_folder)); this.Mo2Folder = Path.GetDirectoryName(Path.GetDirectoryName(profile_folder));
if (!File.Exists(Path.Combine(this.Mo2Folder, "ModOrganizer.exe"))) if (!File.Exists(Path.Combine(this.Mo2Folder, "ModOrganizer.exe")))
{
this.Log().Error($"Error! No ModOrganizer2.exe found in {this.Mo2Folder}"); this.Log().Error($"Error! No ModOrganizer2.exe found in {this.Mo2Folder}");
var profile_name = Path.GetFileName(profile_folder);
this.ModListName = profile_name;
var tmp_compiler = new Compiler(this.Mo2Folder);
DownloadLocation = tmp_compiler.MO2DownloadsFolder;
} }
private void ExecuteBegin() this.MOProfile = Path.GetFileName(profile_folder);
this.ModListName = this.MOProfile;
var tmp_compiler = new Compiler(this.Mo2Folder);
this.DownloadLocation = tmp_compiler.MO2DownloadsFolder;
}
private async Task ExecuteBegin()
{ {
if (this.Mo2Folder != null) if (this.Mo2Folder != null)
{ {
var compiler = new Compiler(this.Mo2Folder) var compiler = new Compiler(this.Mo2Folder)
{ {
MO2Profile = this.ModListName, MO2Profile = this.MOProfile,
ModListName = this.ModName, ModListName = this.ModListName,
ModListAuthor = this.AuthorName, ModListAuthor = this.AuthorName,
ModListDescription = this.Summary, ModListDescription = this.Summary,
ModListImage = this.ImagePath, ModListImage = this.ImagePath,
ModListWebsite = this.NexusSiteURL, ModListWebsite = this.NexusSiteURL,
ModListReadme = this.ReadMeText, ModListReadme = this.ReadMeText,
}; };
var th = new Thread(() => await Task.Run(() =>
{ {
UIReady = false; UIReady = false;
try try
{ {
compiler.Compile(); compiler.Compile();
if (compiler.ModList != null && compiler.ModList.ReportHTML != null) if (compiler.ModList?.ReportHTML != null)
{ {
this.HTMLReport = compiler.ModList.ReportHTML; this.HTMLReport = compiler.ModList.ReportHTML;
} }
@ -165,11 +136,7 @@ namespace Wabbajack
{ {
UIReady = true; UIReady = true;
} }
}) });
{
Priority = ThreadPriority.BelowNormal
};
th.Start();
} }
else else
{ {
@ -177,41 +144,5 @@ namespace Wabbajack
UIReady = true; UIReady = true;
} }
} }
public string Error => "Error";
public string this[string columnName] => Validate(columnName);
private string Validate(string columnName)
{
string validationMessage = null;
switch (columnName)
{
case "Location":
if (Location == null)
{
validationMessage = null;
}
else switch (Mode)
{
case RunMode.Compile when Location != null && Directory.Exists(Location) && File.Exists(Path.Combine(Location, "modlist.txt")):
Location = Path.Combine(Location, "modlist.txt");
validationMessage = null;
ConfigureForBuild();
break;
case RunMode.Install when Location != null && Directory.Exists(Location) && !Directory.EnumerateFileSystemEntries(Location).Any():
validationMessage = null;
break;
case RunMode.Install when Location != null && Directory.Exists(Location) && Directory.EnumerateFileSystemEntries(Location).Any():
validationMessage = "You have selected a non-empty directory. Installing the modlist here might result in a broken install!";
break;
default:
validationMessage = "Invalid Mod Organizer profile directory";
break;
}
break;
}
return validationMessage;
}
} }
} }

View File

@ -31,9 +31,9 @@
<TextBlock <TextBlock
FontSize="16" FontSize="16"
FontWeight="Bold" FontWeight="Bold"
Text="{Binding Mode}" /> Text="Compiling" />
<TextBlock FontSize="16" Text=" : " /> <TextBlock FontSize="16" Text=" : " />
<TextBlock FontSize="16" Text="{Binding ModListName}" /> <TextBlock FontSize="16" Text="{Binding MOProfile}" />
</StackPanel> </StackPanel>
<Grid Grid.Row="1" Grid.Column="0" <Grid Grid.Row="1" Grid.Column="0"
@ -50,24 +50,21 @@
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" /> <ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" /> <ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Label <Label
Grid.Column="0" Grid.Column="0"
Content="Splash Screen Path:" /> Content="Splash Screen Path:" />
<TextBox <local:FilePicker Grid.Column="1"
Grid.Column="1" PathType="File"
IsEnabled="{Binding UIReady}" DoExistsCheck="False"
Text="{Binding ImagePath}" /> TargetPath="{Binding ImagePath}"
<Button Filter="Banner image|*.png"
Grid.Column="2" IsEnabled="{Binding UIReady}" HorizontalAlignment="Left" Width="534" />
MinWidth="80"
Command="{Binding ChangeSplashScreenCommand}"
Content="Select" />
</Grid> </Grid>
</Grid> </Grid>
<ScrollViewer Grid.Row="1" Grid.Column="2" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto" <ScrollViewer Grid.Row="1" Grid.Column="2" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto"
IsEnabled="{Binding UIReady}"
Background="Transparent"> Background="Transparent">
<StackPanel Orientation="Vertical" Background="Transparent" > <StackPanel Orientation="Vertical" Background="Transparent" >
<StackPanel.Resources> <StackPanel.Resources>
@ -80,7 +77,7 @@
</Style> </Style>
</StackPanel.Resources> </StackPanel.Resources>
<TextBlock Text="ModList Name" Margin="{StaticResource TitleMargin}" /> <TextBlock Text="ModList Name" Margin="{StaticResource TitleMargin}" />
<TextBox Text="{Binding ModName}" Style="{StaticResource ValueStyle}" /> <TextBox Text="{Binding ModListName}" Style="{StaticResource ValueStyle}" />
<TextBlock Text="Author" Margin="{StaticResource TitleMargin}" /> <TextBlock Text="Author" Margin="{StaticResource TitleMargin}" />
<TextBox Text="{Binding AuthorName}" Style="{StaticResource ValueStyle}" /> <TextBox Text="{Binding AuthorName}" Style="{StaticResource ValueStyle}" />
<TextBlock Text="Description" Margin="{StaticResource TitleMargin}" /> <TextBlock Text="Description" Margin="{StaticResource TitleMargin}" />
@ -88,7 +85,10 @@
<TextBlock Text="Website" Margin="{StaticResource TitleMargin}" /> <TextBlock Text="Website" Margin="{StaticResource TitleMargin}" />
<TextBox Text="{Binding NexusSiteURL}" Style="{StaticResource ValueStyle}" /> <TextBox Text="{Binding NexusSiteURL}" Style="{StaticResource ValueStyle}" />
<TextBlock Text="Readme Path" Margin="{StaticResource TitleMargin}" ToolTip="Path to a readme file." /> <TextBlock Text="Readme Path" Margin="{StaticResource TitleMargin}" ToolTip="Path to a readme file." />
<TextBox Text="{Binding NexusSiteURL}" Style="{StaticResource ValueStyle}" ToolTip="Path to a readme file." /> <local:FilePicker TargetPath="{Binding ReadMeText}"
PathType="File"
DoExistsCheck="False"
ToolTip="Path to a readme file." />
</StackPanel> </StackPanel>
</ScrollViewer> </ScrollViewer>
@ -125,7 +125,6 @@
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" /> <ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" /> <ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition /> <RowDefinition />
@ -136,33 +135,25 @@
Grid.Row="0" Grid.Row="0"
Grid.Column="0" Grid.Column="0"
Content="Installation Location:" /> Content="Installation Location:" />
<TextBox <local:FilePicker
Grid.Row="0" Grid.Row="0"
Grid.Column="1" Grid.Column="1"
IsEnabled="{Binding UIReady}" PathType="Folder"
Text="{Binding Location, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, NotifyOnValidationError=True}" /> DoExistsCheck="False"
<Button TargetPath="{Binding Location}"
Grid.Row="0" SetTargetPathCommand="{Binding ChangePathCommand}"
Grid.Column="2"
MinWidth="80"
Command="{Binding ChangePathCommand}"
Content="Select"
IsEnabled="{Binding UIReady}" /> IsEnabled="{Binding UIReady}" />
<Label <Label
Grid.Row="2" Grid.Row="2"
Grid.Column="0" Grid.Column="0"
Content="Download Location:" /> Content="Download Location:" />
<TextBox <local:FilePicker
Grid.Row="2" Grid.Row="2"
Grid.Column="1" Grid.Column="1"
IsEnabled="{Binding UIReady}" PathType="Folder"
Text="{Binding DownloadLocation}" /> DoExistsCheck="False"
<Button TargetPath="{Binding DownloadLocation}"
Grid.Row="2" SetTargetPathCommand="{Binding ChangeDownloadPathCommand}"
Grid.Column="2"
MinWidth="80"
Command="{Binding ChangeDownloadPathCommand}"
Content="Select"
IsEnabled="{Binding UIReady}" /> IsEnabled="{Binding UIReady}" />
</Grid> </Grid>
<!-- End Location --> <!-- End Location -->

View File

@ -89,6 +89,14 @@ namespace Wabbajack
public static readonly DependencyProperty PromptTitleProperty = DependencyProperty.Register(nameof(PromptTitle), typeof(string), typeof(FilePicker), public static readonly DependencyProperty PromptTitleProperty = DependencyProperty.Register(nameof(PromptTitle), typeof(string), typeof(FilePicker),
new FrameworkPropertyMetadata(default(string), FrameworkPropertyMetadataOptions.BindsTwoWayByDefault)); new FrameworkPropertyMetadata(default(string), FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));
public string Filter
{
get => (string)GetValue(FilterProperty);
set => SetValue(FilterProperty, value);
}
public static readonly DependencyProperty FilterProperty = DependencyProperty.Register(nameof(Filter), typeof(string), typeof(FilePicker),
new FrameworkPropertyMetadata(default(string)));
public FilePicker() public FilePicker()
{ {
InitializeComponent(); InitializeComponent();
@ -115,6 +123,14 @@ namespace Wabbajack
dlg.EnsureFileExists = true; dlg.EnsureFileExists = true;
dlg.EnsurePathExists = true; dlg.EnsurePathExists = true;
dlg.EnsureReadOnly = false; dlg.EnsureReadOnly = false;
if (!string.IsNullOrWhiteSpace(this.Filter))
{
var split = this.Filter.Split('|');
if (split.Length == 2)
{
dlg.Filters.Add(new CommonFileDialogFilter(split[0], split[1]));
}
}
dlg.EnsureValidNames = true; dlg.EnsureValidNames = true;
dlg.Multiselect = false; dlg.Multiselect = false;
dlg.ShowPlacesList = true; dlg.ShowPlacesList = true;