Fix CriticalFailureIntervention never being handled

Can also specify if Wabbajack should exit
This commit is contained in:
Unnoen 2021-05-20 21:40:05 +10:00
parent ba41972a8c
commit a5c6b6c05c
No known key found for this signature in database
GPG Key ID: 8F8E42252BA20553
5 changed files with 34 additions and 24 deletions

View File

@ -70,21 +70,19 @@ namespace Wabbajack.Lib
var otherGame = Game.CommonlyConfusedWith.Where(g => g.MetaData().IsInstalled).Select(g => g.MetaData()).FirstOrDefault(); var otherGame = Game.CommonlyConfusedWith.Where(g => g.MetaData().IsInstalled).Select(g => g.MetaData()).FirstOrDefault();
if (otherGame != null) if (otherGame != null)
{ {
await Utils.Log(new CriticalFailureIntervention( Utils.Error(new CriticalFailureIntervention(
$"In order to do a proper install Wabbajack needs to know where your {Game.HumanFriendlyGameName} folder resides. However this game doesn't seem to be installed, we did however find a installed " + $"In order to do a proper install Wabbajack needs to know where your {Game.HumanFriendlyGameName} folder resides. However this game doesn't seem to be installed, we did however find an installed " +
$"copy of {otherGame.HumanFriendlyGameName}, did you install the wrong game?", $"copy of {otherGame.HumanFriendlyGameName}, did you install the wrong game?",
$"Could not locate {Game.HumanFriendlyGameName}")) $"Could not locate {Game.HumanFriendlyGameName}"));
.Task;
} }
else else
{ {
await Utils.Log(new CriticalFailureIntervention( Utils.Error(new CriticalFailureIntervention(
$"In order to do a proper install Wabbajack needs to know where your {Game.HumanFriendlyGameName} folder resides. However this game doesn't seem to be installed", $"In order to do a proper install Wabbajack needs to know where your {Game.HumanFriendlyGameName} folder resides. However this game doesn't seem to be installed.",
$"Could not locate {Game.HumanFriendlyGameName}")) $"Could not locate {Game.HumanFriendlyGameName}"));
.Task;
} }
Utils.Log("Exiting because we couldn't find the game folder."); Utils.Error("Exiting because we couldn't find the game folder.");
return false; return false;
} }

View File

@ -12,13 +12,17 @@ namespace Wabbajack.Lib
private TaskCompletionSource<ConfirmationIntervention.Choice> _source = new TaskCompletionSource<ConfirmationIntervention.Choice>(); private TaskCompletionSource<ConfirmationIntervention.Choice> _source = new TaskCompletionSource<ConfirmationIntervention.Choice>();
public Task<ConfirmationIntervention.Choice> Task => _source.Task; public Task<ConfirmationIntervention.Choice> Task => _source.Task;
public CriticalFailureIntervention(string description, string title) public CriticalFailureIntervention(string description, string title, bool exit = false)
{ {
ExtendedDescription = description; ExtendedDescription = description;
ShortDescription = title; ShortDescription = title;
ExitApplication = exit;
} }
public override string ShortDescription { get; } public override string ShortDescription { get; }
public override string ExtendedDescription { get; } public override string ExtendedDescription { get; }
public bool ExitApplication { get; }
public void Cancel() public void Cancel()
{ {
_source.SetResult(ConfirmationIntervention.Choice.Abort); _source.SetResult(ConfirmationIntervention.Choice.Abort);

View File

@ -97,13 +97,19 @@ namespace Wabbajack
public InstallerVM(MainWindowVM mainWindowVM) : base(mainWindowVM) public InstallerVM(MainWindowVM mainWindowVM) : base(mainWindowVM)
{ {
if (AbsolutePath.EntryPoint.IsChildOf(new AbsolutePath(KnownFolders.Downloads.Path)))
if (Path.GetDirectoryName(Assembly.GetEntryAssembly().Location.ToLower()) == KnownFolders.Downloads.Path.ToLower())
{ {
Utils.Error(new CriticalFailureIntervention( Utils.Error(new CriticalFailureIntervention(
"Wabbajack is running inside your Downloads folder. This folder is often highly monitored by antivirus software and these can often " + "Wabbajack is running inside your Downloads folder. This folder is often highly monitored by antivirus software and these can often " +
"conflict with the operations Wabbajack needs to perform. Please move this executable outside of your Downloads folder and then restart the app.", "conflict with the operations Wabbajack needs to perform. Please move Wabbajack outside of your Downloads folder and then restart the app.",
"Cannot run inside Downloads")); "Cannot run inside Downloads", true));
}
else if (AbsolutePath.EntryPoint.IsChildOf(new AbsolutePath(KnownFolders.SkyDrive.Path)))
{
Utils.Error(new CriticalFailureIntervention(
$"Wabbajack is running inside a OneDrive folder \"{new AbsolutePath(KnownFolders.SkyDrive.Path)}\". This folder is known to cause issues with Wabbajack. " +
"Please move Wabbajack outside of your OneDrive folder and then restart the app.",
"Cannot run inside OneDrive", true));
} }
MWVM = mainWindowVM; MWVM = mainWindowVM;

View File

@ -77,9 +77,9 @@ namespace Wabbajack
.Bind(Log) .Bind(Log)
.Subscribe() .Subscribe()
.DisposeWith(CompositeDisposable); .DisposeWith(CompositeDisposable);
Utils.LogMessages Utils.LogMessages
.OfType<IUserIntervention>() .Where(a => a is IUserIntervention or CriticalFailureIntervention)
.ObserveOnGuiThread() .ObserveOnGuiThread()
.SelectTask(async msg => .SelectTask(async msg =>
{ {
@ -93,9 +93,9 @@ namespace Wabbajack
Utils.Error(ex, $"Error while handling user intervention of type {msg?.GetType()}"); Utils.Error(ex, $"Error while handling user intervention of type {msg?.GetType()}");
try try
{ {
if (!msg.Handled) if (msg is IUserIntervention {Handled: false} intervention)
{ {
msg.Cancel(); intervention.Cancel();
} }
} }
catch (Exception cancelEx) catch (Exception cancelEx)

View File

@ -10,6 +10,7 @@ using System.Windows.Threading;
using CefSharp; using CefSharp;
using ReactiveUI; using ReactiveUI;
using Wabbajack.Common; using Wabbajack.Common;
using Wabbajack.Common.StatusFeed;
using Wabbajack.Lib; using Wabbajack.Lib;
using Wabbajack.Lib.Downloaders; using Wabbajack.Lib.Downloaders;
using Wabbajack.Lib.LibCefHelpers; using Wabbajack.Lib.LibCefHelpers;
@ -57,12 +58,12 @@ namespace Wabbajack
MainWindow.NavigateTo(oldPane); MainWindow.NavigateTo(oldPane);
} }
public async Task Handle(IUserIntervention msg) public async Task Handle(IStatusMessage msg)
{ {
switch (msg) switch (msg)
{ {
case RequestNexusAuthorization c: case RequestNexusAuthorization c:
await WrapBrowserJob(msg, async (vm, cancel) => await WrapBrowserJob(c, async (vm, cancel) =>
{ {
await vm.Driver.WaitForInitialized(); await vm.Driver.WaitForInitialized();
var key = await NexusApiClient.SetupNexusLogin(new CefSharpWrapper(vm.Browser), m => vm.Instructions = m, cancel.Token); var key = await NexusApiClient.SetupNexusLogin(new CefSharpWrapper(vm.Browser), m => vm.Instructions = m, cancel.Token);
@ -70,13 +71,13 @@ namespace Wabbajack
}); });
break; break;
case ManuallyDownloadNexusFile c: case ManuallyDownloadNexusFile c:
await WrapBrowserJob(msg, (vm, cancel) => HandleManualNexusDownload(vm, cancel, c)); await WrapBrowserJob(c, (vm, cancel) => HandleManualNexusDownload(vm, cancel, c));
break; break;
case ManuallyDownloadFile c: case ManuallyDownloadFile c:
await WrapBrowserJob(msg, (vm, cancel) => HandleManualDownload(vm, cancel, c)); await WrapBrowserJob(c, (vm, cancel) => HandleManualDownload(vm, cancel, c));
break; break;
case AbstractNeedsLoginDownloader.RequestSiteLogin c: case AbstractNeedsLoginDownloader.RequestSiteLogin c:
await WrapBrowserJob(msg, async (vm, cancel) => await WrapBrowserJob(c, async (vm, cancel) =>
{ {
await vm.Driver.WaitForInitialized(); await vm.Driver.WaitForInitialized();
var data = await c.Downloader.GetAndCacheCookies(new CefSharpWrapper(vm.Browser), m => vm.Instructions = m, cancel.Token); var data = await c.Downloader.GetAndCacheCookies(new CefSharpWrapper(vm.Browser), m => vm.Instructions = m, cancel.Token);
@ -87,6 +88,7 @@ namespace Wabbajack
MessageBox.Show(c.ExtendedDescription, c.ShortDescription, MessageBoxButton.OK, MessageBox.Show(c.ExtendedDescription, c.ShortDescription, MessageBoxButton.OK,
MessageBoxImage.Error); MessageBoxImage.Error);
c.Cancel(); c.Cancel();
if (c.ExitApplication) await MainWindow.ShutdownApplication();
break; break;
case ConfirmationIntervention c: case ConfirmationIntervention c:
break; break;