Merge pull request #58 from tr4wzified/properfoldervalidation

Improved location validation
This commit is contained in:
Timothy Baldridge
2019-09-26 14:57:46 -06:00
committed by GitHub
3 changed files with 80 additions and 53 deletions

View File

@ -16,7 +16,7 @@ using Wabbajack.Properties;
namespace Wabbajack namespace Wabbajack
{ {
internal class AppState : INotifyPropertyChanged internal class AppState : INotifyPropertyChanged, IDataErrorInfo
{ {
private ICommand _begin; private ICommand _begin;
@ -158,6 +158,7 @@ namespace Wabbajack
} }
} }
public string DownloadLocation public string DownloadLocation
{ {
get => _downloadLocation; get => _downloadLocation;
@ -315,7 +316,46 @@ namespace Wabbajack
public void OnPropertyChanged(string name) public void OnPropertyChanged(string name)
{ {
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name)); if(PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(name));
}
}
public string Error
{
get { return "Error"; }
}
public string this[string columnName]
{
get
{
return Validate(columnName);
}
}
private string Validate(string columnName)
{
string validationMessage = null;
switch (columnName)
{
case "Location":
if (Location == null)
{
validationMessage = null;
}
else if (Location != null && Directory.Exists(Location) && File.Exists(Path.Combine(Location, "modlist.txt")))
{
Location = Path.Combine(Location, "modlist.txt");
validationMessage = null;
ConfigureForBuild();
}
else
{
validationMessage = "Invalid Mod Organizer profile directory";
}
break;
}
return validationMessage;
} }
private void UpdateLoop() private void UpdateLoop()
@ -421,20 +461,7 @@ namespace Wabbajack
else else
{ {
var folder = UIUtils.ShowFolderSelectionDialog("Select Your MO2 profile directory"); var folder = UIUtils.ShowFolderSelectionDialog("Select Your MO2 profile directory");
Location = folder;
if (folder != null)
{
var file = Path.Combine(folder, "modlist.txt");
if(File.Exists(file))
{
Location = file;
ConfigureForBuild();
}
else
{
Utils.Log($"No modlist.txt found at {file}");
}
}
} }
} }
@ -500,9 +527,7 @@ namespace Wabbajack
th.Priority = ThreadPriority.BelowNormal; th.Priority = ThreadPriority.BelowNormal;
th.Start(); th.Start();
} }
else else if (_mo2Folder != null)
{
if (_mo2Folder != null)
{ {
var compiler = new Compiler(_mo2Folder, msg => LogMsg(msg)); var compiler = new Compiler(_mo2Folder, msg => LogMsg(msg));
compiler.IgnoreMissingFiles = IgnoreMissingFiles; compiler.IgnoreMissingFiles = IgnoreMissingFiles;
@ -547,5 +572,4 @@ namespace Wabbajack
public string Msg { get; internal set; } public string Msg { get; internal set; }
public int ID { get; internal set; } public int ID { get; internal set; }
} }
}
} }

View File

@ -64,8 +64,8 @@
<RowDefinition MinHeight="10" /> <RowDefinition MinHeight="10" />
<RowDefinition /> <RowDefinition />
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Label Grid.Row="0" Content="MO2 Location:" Grid.Column="0" /> <Label Grid.Row="0" Content="MO2 Profile:" Grid.Column="0" />
<TextBox Grid.Row="0" Grid.Column="1" Text="{Binding Location}" IsEnabled="{Binding UIReady}"/> <TextBox Grid.Row="0" Grid.Column="1" Text="{Binding Location, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, NotifyOnValidationError=True}" IsEnabled="{Binding UIReady}"/>
<Button Grid.Row="0" Content="Select" MinWidth="80" Grid.Column="2" Command="{Binding ChangePath}" IsEnabled="{Binding UIReady}"/> <Button Grid.Row="0" Content="Select" MinWidth="80" Grid.Column="2" Command="{Binding ChangePath}" IsEnabled="{Binding UIReady}"/>
<Label Grid.Row="2" Content="Download Location:" Grid.Column="0" /> <Label Grid.Row="2" Content="Download Location:" Grid.Column="0" />
<TextBox Grid.Row="2" Grid.Column="1" Text="{Binding DownloadLocation}" IsEnabled="{Binding UIReady}"/> <TextBox Grid.Row="2" Grid.Column="1" Text="{Binding DownloadLocation}" IsEnabled="{Binding UIReady}"/>

View File

@ -838,6 +838,9 @@
</Setter.Value> </Setter.Value>
</Setter> </Setter>
<Style.Triggers> <Style.Triggers>
<DataTrigger Binding="{Binding Path=(Validation.HasError), RelativeSource={RelativeSource self}}" Value="True">
<Setter Property="ToolTip" Value="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=(Validation.Errors)[0].ErrorContent}"/>
</DataTrigger>
<!--<MultiTrigger> <!--<MultiTrigger>
<MultiTrigger.Conditions> <MultiTrigger.Conditions>
<Condition Property="IsInactiveSelectionHighlightEnabled" Value="true"/> <Condition Property="IsInactiveSelectionHighlightEnabled" Value="true"/>