Merge pull request #161 from Noggog/FilePickerVM

FilePickerVM
This commit is contained in:
Timothy Baldridge 2019-11-09 14:10:04 -07:00 committed by GitHub
commit 2e240c14ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 257 additions and 291 deletions

View File

@ -1,4 +1,5 @@
using ReactiveUI;
using Microsoft.WindowsAPICodePack.Dialogs;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;
using System;
using System.IO;
@ -25,8 +26,7 @@ namespace Wabbajack
[Reactive]
public string ModListName { get; set; }
[Reactive]
public string Location { get; set; }
public FilePickerVM Location { get; }
[Reactive]
public bool UIReady { get; set; } = true;
@ -37,8 +37,7 @@ namespace Wabbajack
[Reactive]
public string Summary { get; set; } = "Description (700 characters max)";
[Reactive]
public string ImagePath { get; set; }
public FilePickerVM ImagePath { get; }
private readonly ObservableAsPropertyHelper<BitmapImage> _Image;
public BitmapImage Image => _Image.Value;
@ -46,28 +45,50 @@ namespace Wabbajack
[Reactive]
public string Website { get; set; }
[Reactive]
public string ReadMeText { get; set; }
public FilePickerVM ReadMeText { get; }
[Reactive]
public string HTMLReport { get; set; }
[Reactive]
public string DownloadLocation { get; set; }
public FilePickerVM DownloadLocation { get; }
public IReactiveCommand BeginCommand { get; }
public CompilerVM(MainWindowVM mainWindowVM, string source)
{
this.MWVM = mainWindowVM;
this.Location = source;
this.Location = new FilePickerVM()
{
TargetPath = source,
DoExistsCheck = false,
PathType = FilePickerVM.PathTypeOptions.File,
};
this.DownloadLocation = new FilePickerVM()
{
DoExistsCheck = false,
PathType = FilePickerVM.PathTypeOptions.Folder,
};
this.ImagePath = new FilePickerVM()
{
DoExistsCheck = false,
PathType = FilePickerVM.PathTypeOptions.File,
Filters =
{
new CommonFileDialogFilter("Banner image", "*.png")
}
};
this.ReadMeText = new FilePickerVM()
{
PathType = FilePickerVM.PathTypeOptions.File,
DoExistsCheck = true,
};
this.BeginCommand = ReactiveCommand.CreateFromTask(
execute: this.ExecuteBegin,
canExecute: this.WhenAny(x => x.UIReady)
.ObserveOnGuiThread());
this._Image = this.WhenAny(x => x.ImagePath)
this._Image = this.WhenAny(x => x.ImagePath.TargetPath)
.Select(path =>
{
if (string.IsNullOrWhiteSpace(path)) return UIUtils.BitmapImageFromResource("Wabbajack.Resources.Banner_Dark.png");
@ -86,16 +107,16 @@ namespace Wabbajack
this.AuthorName = settings.Author;
this.ModListName = settings.ModListName;
this.Summary = settings.Description;
this.ReadMeText = settings.Readme;
this.ImagePath = settings.SplashScreen;
this.ReadMeText.TargetPath = settings.Readme;
this.ImagePath.TargetPath = settings.SplashScreen;
this.Website = settings.Website;
if (!string.IsNullOrWhiteSpace(settings.DownloadLocation))
{
this.DownloadLocation = settings.DownloadLocation;
this.DownloadLocation.TargetPath = settings.DownloadLocation;
}
if (!string.IsNullOrWhiteSpace(settings.Location))
{
this.Location = settings.Location;
this.Location.TargetPath = settings.Location;
}
this.MWVM.Settings.SaveSignal
.Subscribe(_ =>
@ -103,11 +124,11 @@ namespace Wabbajack
settings.Author = this.AuthorName;
settings.ModListName = this.ModListName;
settings.Description = this.Summary;
settings.Readme = this.ReadMeText;
settings.SplashScreen = this.ImagePath;
settings.Readme = this.ReadMeText.TargetPath;
settings.SplashScreen = this.ImagePath.TargetPath;
settings.Website = this.Website;
settings.Location = this.Location;
settings.DownloadLocation = this.DownloadLocation;
settings.Location = this.Location.TargetPath;
settings.DownloadLocation = this.DownloadLocation.TargetPath;
})
.DisposeWith(this.CompositeDisposable);
}
@ -125,7 +146,7 @@ namespace Wabbajack
this.ModListName = this.MOProfile;
var tmp_compiler = new Compiler(this.Mo2Folder);
this.DownloadLocation = tmp_compiler.MO2DownloadsFolder;
this.DownloadLocation.TargetPath = tmp_compiler.MO2DownloadsFolder;
}
private async Task ExecuteBegin()
@ -138,9 +159,9 @@ namespace Wabbajack
ModListName = this.ModListName,
ModListAuthor = this.AuthorName,
ModListDescription = this.Summary,
ModListImage = this.ImagePath,
ModListImage = this.ImagePath.TargetPath,
ModListWebsite = this.Website,
ModListReadme = this.ReadMeText,
ModListReadme = this.ReadMeText.TargetPath,
};
await Task.Run(() =>
{

View File

@ -0,0 +1,164 @@
using Microsoft.WindowsAPICodePack.Dialogs;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reactive.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using Wabbajack.Lib;
namespace Wabbajack
{
public class FilePickerVM : ViewModel
{
public enum PathTypeOptions
{
Off,
Either,
File,
Folder
}
public object Parent { get; }
[Reactive]
public ICommand SetTargetPathCommand { get; set; }
[Reactive]
public string TargetPath { get; set; }
[Reactive]
public string PromptTitle { get; set; }
[Reactive]
public PathTypeOptions PathType { get; set; }
[Reactive]
public bool DoExistsCheck { get; set; }
[Reactive]
public IObservable<IErrorResponse> AdditionalError { get; set; }
private readonly ObservableAsPropertyHelper<bool> _Exists;
public bool Exists => _Exists.Value;
private readonly ObservableAsPropertyHelper<bool> _InError;
public bool InError => _InError.Value;
private readonly ObservableAsPropertyHelper<string> _ErrorTooltip;
public string ErrorTooltip => _ErrorTooltip.Value;
public List<CommonFileDialogFilter> Filters { get; } = new List<CommonFileDialogFilter>();
public FilePickerVM(object parentVM = null)
{
this.Parent = parentVM;
this.SetTargetPathCommand = ConstructTypicalPickerCommand();
// Check that file exists
this._Exists = Observable.Interval(TimeSpan.FromSeconds(3))
.FilterSwitch(
Observable.CombineLatest(
this.WhenAny(x => x.PathType),
this.WhenAny(x => x.DoExistsCheck),
resultSelector: (type, doExists) => type != PathTypeOptions.Off && doExists))
.Unit()
// Also do it when fields change
.Merge(this.WhenAny(x => x.PathType).Unit())
.Merge(this.WhenAny(x => x.DoExistsCheck).Unit())
.CombineLatest(
this.WhenAny(x => x.DoExistsCheck),
this.WhenAny(x => x.PathType),
this.WhenAny(x => x.TargetPath)
.Throttle(TimeSpan.FromMilliseconds(200)),
resultSelector: (_, DoExists, Type, Path) => (DoExists, Type, Path))
// Refresh exists
.Select(t =>
{
if (!t.DoExists) return true;
switch (t.Type)
{
case PathTypeOptions.Either:
return File.Exists(t.Path) || Directory.Exists(t.Path);
case PathTypeOptions.File:
return File.Exists(t.Path);
case PathTypeOptions.Folder:
return Directory.Exists(t.Path);
default:
return true;
}
})
.DistinctUntilChanged()
.ObserveOn(RxApp.MainThreadScheduler)
.ToProperty(this, nameof(this.Exists));
this._InError = Observable.CombineLatest(
this.WhenAny(x => x.Exists),
this.WhenAny(x => x.AdditionalError)
.Select(x => x ?? Observable.Return<IErrorResponse>(ErrorResponse.Success))
.Switch()
.Select(err => !err?.Succeeded ?? false),
resultSelector: (exist, err) => !exist || err)
.ToProperty(this, nameof(this.InError));
this._ErrorTooltip = Observable.CombineLatest(
this.WhenAny(x => x.Exists)
.Select(exists => exists ? default(string) : "Path does not exist"),
this.WhenAny(x => x.AdditionalError)
.Select(x => x ?? Observable.Return<IErrorResponse>(ErrorResponse.Success))
.Switch(),
resultSelector: (exists, err) =>
{
if ((!err?.Succeeded ?? false)
&& !string.IsNullOrWhiteSpace(err.Reason))
{
return err.Reason;
}
return exists;
})
.ToProperty(this, nameof(this.ErrorTooltip));
}
public ICommand ConstructTypicalPickerCommand()
{
return ReactiveCommand.Create(
execute: () =>
{
string dirPath;
if (File.Exists(this.TargetPath))
{
dirPath = System.IO.Path.GetDirectoryName(this.TargetPath);
}
else
{
dirPath = this.TargetPath;
}
var dlg = new CommonOpenFileDialog
{
Title = this.PromptTitle,
IsFolderPicker = this.PathType == PathTypeOptions.Folder,
InitialDirectory = this.TargetPath,
AddToMostRecentlyUsedList = false,
AllowNonFileSystemItems = false,
DefaultDirectory = this.TargetPath,
EnsureFileExists = true,
EnsurePathExists = true,
EnsureReadOnly = false,
EnsureValidNames = true,
Multiselect = false,
ShowPlacesList = true,
};
foreach (var filter in this.Filters)
{
dlg.Filters.Add(filter);
}
if (dlg.ShowDialog() != CommonFileDialogResult.Ok) return;
this.TargetPath = dlg.FileName;
});
}
}
}

View File

@ -49,17 +49,9 @@ namespace Wabbajack
[Reactive]
public bool InstallingMode { get; set; }
[Reactive]
public string Location { get; set; }
public FilePickerVM Location { get; }
private readonly ObservableAsPropertyHelper<IErrorResponse> _LocationError;
public IErrorResponse LocationError => _LocationError.Value;
[Reactive]
public string DownloadLocation { get; set; }
private readonly ObservableAsPropertyHelper<IErrorResponse> _DownloadLocationError;
public IErrorResponse DownloadLocationError => _DownloadLocationError.Value;
public FilePickerVM DownloadLocation { get; }
private readonly ObservableAsPropertyHelper<float> _ProgressPercent;
public float ProgressPercent => _ProgressPercent.Value;
@ -98,15 +90,32 @@ namespace Wabbajack
this.MWVM = mainWindowVM;
this.ModListPath = source;
this.Location = new FilePickerVM()
{
DoExistsCheck = false,
PathType = FilePickerVM.PathTypeOptions.Folder,
PromptTitle = "Select Installation Directory",
};
this.Location.AdditionalError = this.WhenAny(x => x.Location.TargetPath)
.Select(x => Utils.IsDirectoryPathValid(x));
this.DownloadLocation = new FilePickerVM()
{
DoExistsCheck = false,
PathType = FilePickerVM.PathTypeOptions.Folder,
PromptTitle = "Select a location for MO2 downloads",
};
this.DownloadLocation.AdditionalError = this.WhenAny(x => x.DownloadLocation.TargetPath)
.Select(x => Utils.IsDirectoryPathValid(x));
// Load settings
InstallationSettings settings = this.MWVM.Settings.InstallationSettings.TryCreate(source);
this.Location = settings.InstallationLocation;
this.DownloadLocation = settings.DownloadLocation;
this.Location.TargetPath = settings.InstallationLocation;
this.DownloadLocation.TargetPath = settings.DownloadLocation;
this.MWVM.Settings.SaveSignal
.Subscribe(_ =>
{
settings.InstallationLocation = this.Location;
settings.DownloadLocation = this.DownloadLocation;
settings.InstallationLocation = this.Location.TargetPath;
settings.DownloadLocation = this.DownloadLocation.TargetPath;
})
.DisposeWith(this.CompositeDisposable);
@ -186,14 +195,6 @@ namespace Wabbajack
resultSelector: (modList, mod, installing) => installing ? mod : modList)
.ToProperty(this, nameof(this.Description));
this._LocationError = this.WhenAny(x => x.Location)
.Select(x => Utils.IsDirectoryPathValid(x))
.ToProperty(this, nameof(this.LocationError));
this._DownloadLocationError = this.WhenAny(x => x.DownloadLocation)
.Select(x => Utils.IsDirectoryPathValid(x))
.ToProperty(this, nameof(this.DownloadLocationError));
// Define commands
this.ShowReportCommand = ReactiveCommand.Create(ShowReport);
this.OpenReadmeCommand = ReactiveCommand.Create(
@ -205,13 +206,12 @@ namespace Wabbajack
execute: this.ExecuteBegin,
canExecute: Observable.CombineLatest(
this.WhenAny(x => x.Installing),
this.WhenAny(x => x.LocationError),
this.WhenAny(x => x.DownloadLocationError),
this.WhenAny(x => x.Location.InError),
this.WhenAny(x => x.DownloadLocation.InError),
resultSelector: (installing, loc, download) =>
{
if (installing) return false;
return (loc?.Succeeded ?? false)
&& (download?.Succeeded ?? false);
return !loc && !download;
})
.ObserveOnGuiThread());
this.VisitWebsiteCommand = ReactiveCommand.Create(
@ -221,13 +221,13 @@ namespace Wabbajack
.ObserveOnGuiThread());
// Have Installation location updates modify the downloads location if empty
this.WhenAny(x => x.Location)
this.WhenAny(x => x.Location.TargetPath)
.Skip(1) // Don't do it initially
.Subscribe(installPath =>
{
if (string.IsNullOrWhiteSpace(this.DownloadLocation))
if (string.IsNullOrWhiteSpace(this.DownloadLocation.TargetPath))
{
this.DownloadLocation = Path.Combine(installPath, "downloads");
this.DownloadLocation.TargetPath = Path.Combine(installPath, "downloads");
}
})
.DisposeWith(this.CompositeDisposable);
@ -270,9 +270,9 @@ namespace Wabbajack
{
this.Installing = true;
this.InstallingMode = true;
var installer = new Installer(this.ModListPath, this.ModList.SourceModList, Location)
var installer = new Installer(this.ModListPath, this.ModList.SourceModList, Location.TargetPath)
{
DownloadFolder = DownloadLocation
DownloadFolder = DownloadLocation.TargetPath
};
var th = new Thread(() =>
{

View File

@ -62,11 +62,8 @@
Grid.Column="1"
Width="534"
HorizontalAlignment="Left"
DoExistsCheck="False"
Filter="Banner image|*.png"
IsEnabled="{Binding UIReady}"
PathType="File"
TargetPath="{Binding ImagePath}" />
DataContext="{Binding ImagePath}"
IsEnabled="{Binding UIReady}" />
</Grid>
</Grid>
@ -114,9 +111,7 @@
Text="Readme Path"
ToolTip="Path to a readme file." />
<local:FilePicker
DoExistsCheck="False"
PathType="File"
TargetPath="{Binding ReadMeText}"
DataContext="{Binding ReadMeText}"
ToolTip="Path to a readme file." />
</StackPanel>
</ScrollViewer>
@ -167,11 +162,8 @@
<local:FilePicker
Grid.Row="0"
Grid.Column="1"
DoExistsCheck="False"
IsEnabled="{Binding UIReady}"
PathType="Folder"
SetTargetPathCommand="{Binding ChangePathCommand}"
TargetPath="{Binding Location}" />
DataContext="{Binding Location}" />
<Label
Grid.Row="2"
Grid.Column="0"
@ -179,11 +171,8 @@
<local:FilePicker
Grid.Row="2"
Grid.Column="1"
DoExistsCheck="False"
IsEnabled="{Binding UIReady}"
PathType="Folder"
SetTargetPathCommand="{Binding ChangeDownloadPathCommand}"
TargetPath="{Binding DownloadLocation}" />
DataContext="{Binding DownloadLocation}" />
</Grid>
<!-- End Location -->

View File

@ -1,4 +1,4 @@
<local:UserControlRx
<UserControl
x:Class="Wabbajack.FilePicker"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
@ -20,8 +20,8 @@
Margin="0,0,-4,0"
VerticalContentAlignment="Center"
Background="{StaticResource DarkBackgroundBrush}"
Text="{Binding TargetPath, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
Visibility="{Binding ShowTextBoxInput, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}" />
Text="{Binding TargetPath, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
Visibility="{Binding ShowTextBoxInput}" />
<icon:PackIconMaterial
Margin="0,4,4,4"
Padding="0,3"
@ -29,11 +29,11 @@
VerticalAlignment="Center"
Foreground="{StaticResource WarningBrush}"
Kind="Circle"
ToolTip="{Binding ErrorTooltip, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"
Visibility="{Binding InError, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}, Converter={StaticResource bool2VisibilityConverter}}" />
ToolTip="{Binding ErrorTooltip}"
Visibility="{Binding InError, Converter={StaticResource bool2VisibilityConverter}}" />
<Button
Grid.Column="1"
Command="{Binding SetTargetPathCommand, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"
Command="{Binding SetTargetPathCommand}"
ToolTip="Set target path">
<icon:PackIconMaterial
Width="16"
@ -42,4 +42,4 @@
Kind="DotsHorizontal" />
</Button>
</Grid>
</local:UserControlRx>
</UserControl>

View File

@ -1,216 +1,15 @@
using Microsoft.WindowsAPICodePack.Dialogs;
using ReactiveUI;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reactive.Disposables;
using System.Reactive.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;
using System.Windows.Controls;
namespace Wabbajack
{
/// <summary>
/// Interaction logic for FilePicker.xaml
/// </summary>
public partial class FilePicker : UserControlRx
public partial class FilePicker : UserControl
{
public enum PathTypeOptions
{
Off,
Either,
File,
Folder
}
public ICommand SetTargetPathCommand
{
get => (ICommand)GetValue(SetTargetPathCommandProperty);
set => SetValue(SetTargetPathCommandProperty, value);
}
public static readonly DependencyProperty SetTargetPathCommandProperty = DependencyProperty.Register(nameof(SetTargetPathCommand), typeof(ICommand), typeof(FilePicker),
new FrameworkPropertyMetadata(default(ICommand)));
public string TargetPath
{
get { return (string)GetValue(TargetPathProperty); }
set { SetValue(TargetPathProperty, value); }
}
public static readonly DependencyProperty TargetPathProperty = DependencyProperty.Register(nameof(TargetPath), typeof(string), typeof(FilePicker),
new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, WireNotifyPropertyChanged));
public bool ShowTextBoxInput
{
get => (bool)GetValue(ShowTextBoxInputProperty);
set => SetValue(ShowTextBoxInputProperty, value);
}
public static readonly DependencyProperty ShowTextBoxInputProperty = DependencyProperty.Register(nameof(ShowTextBoxInput), typeof(bool), typeof(FilePicker),
new FrameworkPropertyMetadata(true));
public PathTypeOptions PathType
{
get => (PathTypeOptions)GetValue(PathTypeProperty);
set => SetValue(PathTypeProperty, value);
}
public static readonly DependencyProperty PathTypeProperty = DependencyProperty.Register(nameof(PathType), typeof(PathTypeOptions), typeof(FilePicker),
new FrameworkPropertyMetadata(PathTypeOptions.Off, WireNotifyPropertyChanged));
public bool Exists
{
get => (bool)GetValue(ExistsProperty);
set => SetValue(ExistsProperty, value);
}
public static readonly DependencyProperty ExistsProperty = DependencyProperty.Register(nameof(Exists), typeof(bool), typeof(FilePicker),
new FrameworkPropertyMetadata(true, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, WireNotifyPropertyChanged));
public bool DoExistsCheck
{
get => (bool)GetValue(DoExistsCheckProperty);
set => SetValue(DoExistsCheckProperty, value);
}
public static readonly DependencyProperty DoExistsCheckProperty = DependencyProperty.Register(nameof(DoExistsCheck), typeof(bool), typeof(FilePicker),
new FrameworkPropertyMetadata(true, WireNotifyPropertyChanged));
public string PromptTitle
{
get => (string)GetValue(PromptTitleProperty);
set => SetValue(PromptTitleProperty, value);
}
public static readonly DependencyProperty PromptTitleProperty = DependencyProperty.Register(nameof(PromptTitle), typeof(string), typeof(FilePicker),
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 IErrorResponse AdditionalError
{
get => (IErrorResponse)GetValue(AdditionalErrorProperty);
set => SetValue(AdditionalErrorProperty, value);
}
public static readonly DependencyProperty AdditionalErrorProperty = DependencyProperty.Register(nameof(AdditionalError), typeof(IErrorResponse), typeof(FilePicker),
new FrameworkPropertyMetadata(default(IErrorResponse), WireNotifyPropertyChanged));
private readonly ObservableAsPropertyHelper<bool> _InError;
public bool InError => _InError.Value;
private readonly ObservableAsPropertyHelper<string> _ErrorTooltip;
public string ErrorTooltip => _ErrorTooltip.Value;
public FilePicker()
{
InitializeComponent();
this.SetTargetPathCommand = ReactiveCommand.Create(
execute: () =>
{
string dirPath;
if (File.Exists(this.TargetPath))
{
dirPath = System.IO.Path.GetDirectoryName(this.TargetPath);
}
else
{
dirPath = this.TargetPath;
}
var dlg = new CommonOpenFileDialog();
dlg.Title = this.PromptTitle;
dlg.IsFolderPicker = this.PathType == PathTypeOptions.Folder;
dlg.InitialDirectory = this.TargetPath;
dlg.AddToMostRecentlyUsedList = false;
dlg.AllowNonFileSystemItems = false;
dlg.DefaultDirectory = this.TargetPath;
dlg.EnsureFileExists = true;
dlg.EnsurePathExists = true;
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.Multiselect = false;
dlg.ShowPlacesList = true;
if (dlg.ShowDialog() != CommonFileDialogResult.Ok) return;
this.TargetPath = dlg.FileName;
});
// Check that file exists
Observable.Interval(TimeSpan.FromSeconds(3))
.FilterSwitch(
Observable.CombineLatest(
this.WhenAny(x => x.PathType),
this.WhenAny(x => x.DoExistsCheck),
resultSelector: (type, doExists) => type != PathTypeOptions.Off && doExists))
.Unit()
// Also do it when fields change
.Merge(this.WhenAny(x => x.PathType).Unit())
.Merge(this.WhenAny(x => x.DoExistsCheck).Unit())
.CombineLatest(
this.WhenAny(x => x.DoExistsCheck),
this.WhenAny(x => x.PathType),
this.WhenAny(x => x.TargetPath)
.Throttle(TimeSpan.FromMilliseconds(200)),
resultSelector: (_, DoExists, Type, Path) => (DoExists, Type, Path))
// Refresh exists
.Select(t =>
{
if (!t.DoExists) return true;
switch (t.Type)
{
case PathTypeOptions.Either:
return File.Exists(t.Path) || Directory.Exists(t.Path);
case PathTypeOptions.File:
return File.Exists(t.Path);
case PathTypeOptions.Folder:
return Directory.Exists(t.Path);
default:
return true;
}
})
.DistinctUntilChanged()
.ObserveOn(RxApp.MainThreadScheduler)
.Subscribe(exists => this.Exists = exists)
.DisposeWith(this.CompositeDisposable);
this._InError = Observable.CombineLatest(
this.WhenAny(x => x.Exists),
this.WhenAny(x => x.AdditionalError)
.Select(err => !err?.Succeeded ?? false),
resultSelector: (exist, err) => !exist || err)
.ToProperty(this, nameof(this.InError));
this._ErrorTooltip = Observable.CombineLatest(
this.WhenAny(x => x.Exists)
.Select(exists => exists ? default(string) : "Path does not exist"),
this.WhenAny(x => x.AdditionalError),
resultSelector: (exists, err) =>
{
if ((!err?.Succeeded ?? false)
&& !string.IsNullOrWhiteSpace(err.Reason))
{
return err.Reason;
}
return exists;
})
.ToProperty(this, nameof(this.ErrorTooltip));
}
}
}

View File

@ -646,12 +646,8 @@
Grid.Column="2"
Height="30"
VerticalAlignment="Center"
AdditionalError="{Binding LocationError}"
DoExistsCheck="False"
FontSize="14"
PathType="Folder"
PromptTitle="Select Installation directory"
TargetPath="{Binding Location}" />
DataContext="{Binding Location}"
FontSize="14" />
<TextBlock
Grid.Row="2"
Grid.Column="0"
@ -665,12 +661,8 @@
Grid.Column="2"
Height="30"
VerticalAlignment="Center"
AdditionalError="{Binding DownloadLocationError}"
DoExistsCheck="False"
FontSize="14"
PathType="Folder"
PromptTitle="Select a location for MO2 downloads"
TargetPath="{Binding DownloadLocation}" />
DataContext="{Binding DownloadLocation}"
FontSize="14" />
<Button
x:Name="BeginButton"
Grid.Row="1"

View File

@ -164,6 +164,7 @@
<Compile Include="Converters\BoolToVisibilityConverter.cs" />
<Compile Include="Extensions\EnumerableExt.cs" />
<Compile Include="Settings.cs" />
<Compile Include="View Models\FilePickerVM.cs" />
<Compile Include="View Models\ModListVM.cs" />
<Compile Include="View Models\ModVM.cs" />
<Compile Include="Views\CompilerView.xaml.cs">