From 306e90f6ef1a03bb16c1e7363c3517592c3e1b77 Mon Sep 17 00:00:00 2001 From: Timothy Baldridge Date: Thu, 18 Aug 2022 17:02:19 -0600 Subject: [PATCH] Bunch of fixes for Masterstroke --- .../UserIntervention/ManualDownloadHandler.cs | 6 ++++- .../View Models/BrowserWindowViewModel.cs | 23 +++++++++++++++++-- .../View Models/Compilers/CompilerVM.cs | 2 +- .../View Models/Installers/InstallerVM.cs | 1 + Wabbajack.App.Wpf/Views/MainWindow.xaml.cs | 5 ++++ .../CompilerSettingsInferencer.cs | 3 +++ .../NexusDownloader.cs | 20 ++++++++++++++++ 7 files changed, 56 insertions(+), 4 deletions(-) diff --git a/Wabbajack.App.Wpf/UserIntervention/ManualDownloadHandler.cs b/Wabbajack.App.Wpf/UserIntervention/ManualDownloadHandler.cs index 8ed9e354..6bf219c1 100644 --- a/Wabbajack.App.Wpf/UserIntervention/ManualDownloadHandler.cs +++ b/Wabbajack.App.Wpf/UserIntervention/ManualDownloadHandler.cs @@ -23,7 +23,11 @@ public class ManualDownloadHandler : BrowserWindowViewModel Instructions = string.IsNullOrWhiteSpace(md.Prompt) ? $"Please download {archive.Name}" : md.Prompt; await NavigateTo(md.Url); - var uri = await WaitForDownloadUri(token); + + var uri = await WaitForDownloadUri(token, async () => + { + await RunJavaScript("Array.from(document.getElementsByTagName(\"iframe\")).forEach(f => f.remove())"); + }); Intervention.Finish(uri); } diff --git a/Wabbajack.App.Wpf/View Models/BrowserWindowViewModel.cs b/Wabbajack.App.Wpf/View Models/BrowserWindowViewModel.cs index 6dfb8911..310d8f31 100644 --- a/Wabbajack.App.Wpf/View Models/BrowserWindowViewModel.cs +++ b/Wabbajack.App.Wpf/View Models/BrowserWindowViewModel.cs @@ -76,6 +76,11 @@ public abstract class BrowserWindowViewModel : ViewModel _browser.NavigationCompleted -= Completed; } + public async Task RunJavaScript(string script) + { + await _browser.ExecuteScriptAsync(script); + } + public async Task GetCookies(string domainEnding, CancellationToken token) { var cookies = (await _browser.CoreWebView2.CookieManager.GetCookiesAsync("")) @@ -103,7 +108,7 @@ public abstract class BrowserWindowViewModel : ViewModel return doc; } - public async Task WaitForDownloadUri(CancellationToken token) + public async Task WaitForDownloadUri(CancellationToken token, Func? whileWaiting) { var source = new TaskCompletionSource(); var referer = _browser.Source; @@ -122,8 +127,22 @@ public abstract class BrowserWindowViewModel : ViewModel args.Cancel = true; args.Handled = true; }; + Uri uri; + + while (true) + { + try + { + uri = await source.Task.WaitAsync(TimeSpan.FromMilliseconds(250), token); + break; + } + catch (TimeoutException) + { + if (whileWaiting != null) + await whileWaiting(); + } + } - var uri = await source.Task.WaitAsync(token); var cookies = await GetCookies(uri.Host, token); return new ManualDownload.BrowserDownloadState(uri, cookies, new[] { diff --git a/Wabbajack.App.Wpf/View Models/Compilers/CompilerVM.cs b/Wabbajack.App.Wpf/View Models/Compilers/CompilerVM.cs index ce6dc008..58882695 100644 --- a/Wabbajack.App.Wpf/View Models/Compilers/CompilerVM.cs +++ b/Wabbajack.App.Wpf/View Models/Compilers/CompilerVM.cs @@ -256,7 +256,7 @@ namespace Wabbajack .ObserveOnGuiThread() .Subscribe(update => { - StatusText = update.EventArgs.StatusText; + StatusText = $"{update.EventArgs.StatusText} - {update.EventArgs.StepProgress}"; StatusProgress = update.EventArgs.StepsProgress; }); diff --git a/Wabbajack.App.Wpf/View Models/Installers/InstallerVM.cs b/Wabbajack.App.Wpf/View Models/Installers/InstallerVM.cs index be30ebd7..40417966 100644 --- a/Wabbajack.App.Wpf/View Models/Installers/InstallerVM.cs +++ b/Wabbajack.App.Wpf/View Models/Installers/InstallerVM.cs @@ -352,6 +352,7 @@ public class InstallerVM : BackNavigatingVM, IBackNavigatingVM, ICpuStatusVM DownloadLoadction = Installer.DownloadLocation.TargetPath, Metadata = ModlistMetadata }); + await _settingsManager.Save(LastLoadedModlist, ModListLocation.TargetPath); try { diff --git a/Wabbajack.App.Wpf/Views/MainWindow.xaml.cs b/Wabbajack.App.Wpf/Views/MainWindow.xaml.cs index 38f16507..954a9b57 100644 --- a/Wabbajack.App.Wpf/Views/MainWindow.xaml.cs +++ b/Wabbajack.App.Wpf/Views/MainWindow.xaml.cs @@ -53,6 +53,11 @@ namespace Wabbajack Environment.Exit(-1); }; + Closed += (s, e) => + { + Environment.Exit(0); + }; + MessageBus.Current.Listen() .ObserveOnGuiThread() .Subscribe(u => diff --git a/Wabbajack.Compiler/CompilerSettingsInferencer.cs b/Wabbajack.Compiler/CompilerSettingsInferencer.cs index 56ed795b..008f3060 100644 --- a/Wabbajack.Compiler/CompilerSettingsInferencer.cs +++ b/Wabbajack.Compiler/CompilerSettingsInferencer.cs @@ -72,6 +72,9 @@ public class CompilerSettingsInferencer if (file.FileName.WithoutExtension().ToString() == Consts.WABBAJACK_INCLUDE) cs.Include = cs.Include.Add(file.Parent.RelativeTo(mo2Folder)); + + if (file.FileName.WithoutExtension().ToString() == Consts.WABBAJACK_NOMATCH_INCLUDE) + cs.NoMatchInclude = cs.NoMatchInclude.Add(file.Parent.RelativeTo(mo2Folder)); } _logger.LogInformation("Finding Always Enabled mods"); diff --git a/Wabbajack.Downloaders.Nexus/NexusDownloader.cs b/Wabbajack.Downloaders.Nexus/NexusDownloader.cs index 3a010c4d..77ef642c 100644 --- a/Wabbajack.Downloaders.Nexus/NexusDownloader.cs +++ b/Wabbajack.Downloaders.Nexus/NexusDownloader.cs @@ -180,6 +180,16 @@ public class NexusDownloader : ADownloader, IUrlDownloader try { var fileInfo = await _api.FileInfo(state.Game.MetaData().NexusName!, state.ModID, state.FileID, token); + var (modInfo, _) = await _api.ModInfo(state.Game.MetaData().NexusName!, state.ModID, token); + + state.Description = FixupSummary(modInfo.Summary); + state.Version = modInfo.Version; + state.Author = modInfo.Author; + state.ImageURL = new Uri(modInfo.PictureUrl); + state.Name = modInfo.Name; + state.IsNSFW = modInfo.ContainsAdultContent; + + return fileInfo.info.FileId == state.FileID; } catch (HttpException) @@ -187,6 +197,16 @@ public class NexusDownloader : ADownloader, IUrlDownloader return false; } } + + public static string FixupSummary(string? argSummary) + { + if (argSummary == null) + return ""; + return argSummary.Replace("'", "'") + .Replace("
", "\n\n") + .Replace("
", "\n\n") + .Replace("!", "!"); + } public override IEnumerable MetaIni(Archive a, Nexus state) {