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
commit e65b84b25a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 80 additions and 53 deletions

View File

@ -16,7 +16,7 @@ using Wabbajack.Properties;
namespace Wabbajack
{
internal class AppState : INotifyPropertyChanged
internal class AppState : INotifyPropertyChanged, IDataErrorInfo
{
private ICommand _begin;
@ -157,6 +157,7 @@ namespace Wabbajack
OnPropertyChanged("Location");
}
}
public string DownloadLocation
{
@ -315,7 +316,46 @@ namespace Wabbajack
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()
@ -421,20 +461,7 @@ namespace Wabbajack
else
{
var folder = UIUtils.ShowFolderSelectionDialog("Select Your MO2 profile directory");
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}");
}
}
Location = folder;
}
}
@ -500,42 +527,40 @@ namespace Wabbajack
th.Priority = ThreadPriority.BelowNormal;
th.Start();
}
else if (_mo2Folder != null)
{
var compiler = new Compiler(_mo2Folder, msg => LogMsg(msg));
compiler.IgnoreMissingFiles = IgnoreMissingFiles;
compiler.MO2Profile = ModListName;
var th = new Thread(() =>
{
UIReady = false;
try
{
compiler.Compile();
if (compiler.ModList != null && compiler.ModList.ReportHTML != null)
HTMLReport = compiler.ModList.ReportHTML;
}
catch (Exception ex)
{
while (ex.InnerException != null) ex = ex.InnerException;
LogMsg(ex.StackTrace);
LogMsg(ex.ToString());
LogMsg($"{ex.Message} - Can't continue");
}
finally
{
UIReady = true;
}
});
th.Priority = ThreadPriority.BelowNormal;
th.Start();
}
else
{
if (_mo2Folder != null)
{
var compiler = new Compiler(_mo2Folder, msg => LogMsg(msg));
compiler.IgnoreMissingFiles = IgnoreMissingFiles;
compiler.MO2Profile = ModListName;
var th = new Thread(() =>
{
UIReady = false;
try
{
compiler.Compile();
if (compiler.ModList != null && compiler.ModList.ReportHTML != null)
HTMLReport = compiler.ModList.ReportHTML;
}
catch (Exception ex)
{
while (ex.InnerException != null) ex = ex.InnerException;
LogMsg(ex.StackTrace);
LogMsg(ex.ToString());
LogMsg($"{ex.Message} - Can't continue");
}
finally
{
UIReady = true;
}
});
th.Priority = ThreadPriority.BelowNormal;
th.Start();
}
else
{
Utils.Log("Cannot compile modlist: no valid Mod Organizer profile directory selected.");
UIReady = true;
}
Utils.Log("Cannot compile modlist: no valid Mod Organizer profile directory selected.");
UIReady = true;
}
}
}
@ -547,5 +572,4 @@ namespace Wabbajack
public string Msg { get; internal set; }
public int ID { get; internal set; }
}
}
}

View File

@ -64,8 +64,8 @@
<RowDefinition MinHeight="10" />
<RowDefinition />
</Grid.RowDefinitions>
<Label Grid.Row="0" Content="MO2 Location:" Grid.Column="0" />
<TextBox Grid.Row="0" Grid.Column="1" Text="{Binding Location}" IsEnabled="{Binding UIReady}"/>
<Label Grid.Row="0" Content="MO2 Profile:" Grid.Column="0" />
<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}"/>
<Label Grid.Row="2" Content="Download Location:" Grid.Column="0" />
<TextBox Grid.Row="2" Grid.Column="1" Text="{Binding DownloadLocation}" IsEnabled="{Binding UIReady}"/>

View File

@ -838,6 +838,9 @@
</Setter.Value>
</Setter>
<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.Conditions>
<Condition Property="IsInactiveSelectionHighlightEnabled" Value="true"/>