mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
CompilerVM: Modlist file picker shows errors if not in MO2 directory
This commit is contained in:
parent
0ef91d9da8
commit
5b4cb1fa89
@ -77,6 +77,12 @@ namespace Wabbajack
|
||||
return new ErrorResponse(successful, reason);
|
||||
}
|
||||
#endregion
|
||||
|
||||
public static ErrorResponse Convert(IErrorResponse err, bool nullIsSuccess = true)
|
||||
{
|
||||
if (err == null) return ErrorResponse.Create(nullIsSuccess);
|
||||
return new ErrorResponse(err.Succeeded, err.Reason, err.Exception);
|
||||
}
|
||||
}
|
||||
|
||||
public interface IErrorResponse
|
||||
|
@ -52,12 +52,6 @@ namespace Wabbajack
|
||||
|
||||
public FilePickerVM DownloadLocation { get; }
|
||||
|
||||
[Reactive]
|
||||
public bool ModlistLocationInError { get; set; }
|
||||
|
||||
[Reactive]
|
||||
public bool DownloadLocationInError { get; set; }
|
||||
|
||||
public IReactiveCommand BeginCommand { get; }
|
||||
|
||||
public CompilerVM(MainWindowVM mainWindowVM, string source)
|
||||
@ -155,6 +149,14 @@ namespace Wabbajack
|
||||
})
|
||||
.DisposeWith(this.CompositeDisposable);
|
||||
|
||||
// Wire missing Mo2Folder to signal error state for Modlist Location
|
||||
this.ModlistLocation.AdditionalError = this.WhenAny(x => x.Mo2Folder)
|
||||
.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.");
|
||||
});
|
||||
|
||||
// Load settings
|
||||
CompilationSettings settings = this.MWVM.Settings.CompilationSettings.TryCreate(source);
|
||||
this.AuthorText = settings.Author;
|
||||
@ -189,15 +191,6 @@ namespace Wabbajack
|
||||
.DisposeWith(this.CompositeDisposable);
|
||||
}
|
||||
|
||||
private void ConfigureForBuild(string location)
|
||||
{
|
||||
var profile_folder = Path.GetDirectoryName(location);
|
||||
if (!File.Exists(Path.Combine(this.Mo2Folder, "ModOrganizer.exe")))
|
||||
{
|
||||
Utils.Log($"Error! No ModOrganizer2.exe found in {this.Mo2Folder}");
|
||||
}
|
||||
}
|
||||
|
||||
private async Task ExecuteBegin()
|
||||
{
|
||||
if (this.Mo2Folder != null)
|
||||
|
@ -46,6 +46,9 @@ namespace Wabbajack
|
||||
private readonly ObservableAsPropertyHelper<bool> _Exists;
|
||||
public bool Exists => _Exists.Value;
|
||||
|
||||
private readonly ObservableAsPropertyHelper<ErrorResponse> _ErrorState;
|
||||
public ErrorResponse ErrorState => _ErrorState.Value;
|
||||
|
||||
private readonly ObservableAsPropertyHelper<bool> _InError;
|
||||
public bool InError => _InError.Value;
|
||||
|
||||
@ -96,15 +99,25 @@ namespace Wabbajack
|
||||
.ObserveOn(RxApp.MainThreadScheduler)
|
||||
.ToProperty(this, nameof(this.Exists));
|
||||
|
||||
this._InError = Observable.CombineLatest(
|
||||
this.WhenAny(x => x.Exists),
|
||||
this._ErrorState = Observable.CombineLatest(
|
||||
this.WhenAny(x => x.Exists)
|
||||
.Select(exists => ErrorResponse.Create(successful: exists, exists ? default(string) : "Path does not exist")),
|
||||
this.WhenAny(x => x.AdditionalError)
|
||||
.Select(x => x ?? Observable.Return<IErrorResponse>(ErrorResponse.Success))
|
||||
.Switch()
|
||||
.Select(err => !err?.Succeeded ?? false),
|
||||
resultSelector: (exist, err) => !exist || err)
|
||||
.Switch(),
|
||||
resultSelector: (exist, err) =>
|
||||
{
|
||||
if (exist.Failed) return exist;
|
||||
return ErrorResponse.Convert(err);
|
||||
})
|
||||
.ToProperty(this, nameof(this.ErrorState));
|
||||
|
||||
this._InError = this.WhenAny(x => x.ErrorState)
|
||||
.Select(x => !x.Succeeded)
|
||||
.ToProperty(this, nameof(this.InError));
|
||||
|
||||
// Doesn't derive from ErrorState, as we want to bubble non-empty tooltips,
|
||||
// which is slightly different logic
|
||||
this._ErrorTooltip = Observable.CombineLatest(
|
||||
this.WhenAny(x => x.Exists)
|
||||
.Select(exists => exists ? default(string) : "Path does not exist"),
|
||||
@ -113,12 +126,8 @@ namespace Wabbajack
|
||||
.Switch(),
|
||||
resultSelector: (exists, err) =>
|
||||
{
|
||||
if ((!err?.Succeeded ?? false)
|
||||
&& !string.IsNullOrWhiteSpace(err.Reason))
|
||||
{
|
||||
return err.Reason;
|
||||
}
|
||||
return exists;
|
||||
if (!string.IsNullOrWhiteSpace(exists)) return exists;
|
||||
return err?.Reason;
|
||||
})
|
||||
.ToProperty(this, nameof(this.ErrorTooltip));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user