From ef907ee4c033da4075c9547873773e6b11c2d8d7 Mon Sep 17 00:00:00 2001 From: Timothy Baldridge Date: Sun, 27 Feb 2022 13:50:02 -0700 Subject: [PATCH] Cleanup how we handle ll downloads a bit --- Wabbajack.Lib/Downloaders/ManualDownloader.cs | 5 ++--- .../ManuallyDownloadLoversLabFile.cs | 8 +++++--- .../View Models/UserInterventionHandlers.cs | 16 ++++++++++++++-- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/Wabbajack.Lib/Downloaders/ManualDownloader.cs b/Wabbajack.Lib/Downloaders/ManualDownloader.cs index 95d647f2..635f5839 100644 --- a/Wabbajack.Lib/Downloaders/ManualDownloader.cs +++ b/Wabbajack.Lib/Downloaders/ManualDownloader.cs @@ -63,10 +63,9 @@ namespace Wabbajack.Lib.Downloaders await Utils.Log(await ManuallyDownloadMegaFile.Create(this, destination)).Task; return true; } - - if ((new Uri(Url)).Host.EndsWith("loverslab.com")) + else if ((new Uri(Url)).Host.EndsWith("loverslab.com")) { - await Utils.Log(await ManuallyDownloadLoversLabFile.Create(this, destination)).Task; + await Utils.Log(await ManuallyDownloadLoversLabFile.Create(this, destination, a)).Task; return true; } else diff --git a/Wabbajack.Lib/StatusMessages/ManuallyDownloadLoversLabFile.cs b/Wabbajack.Lib/StatusMessages/ManuallyDownloadLoversLabFile.cs index 06a5c28b..7f6e722b 100644 --- a/Wabbajack.Lib/StatusMessages/ManuallyDownloadLoversLabFile.cs +++ b/Wabbajack.Lib/StatusMessages/ManuallyDownloadLoversLabFile.cs @@ -15,16 +15,18 @@ namespace Wabbajack.Lib public AbsolutePath Destination { get; } + public Archive Archive { get; } - private ManuallyDownloadLoversLabFile(ManualDownloader.State state, AbsolutePath destination) + private ManuallyDownloadLoversLabFile(ManualDownloader.State state, AbsolutePath destination, Archive archive) { State = state; Destination = destination; + Archive = archive; } - public static async Task Create(ManualDownloader.State state, AbsolutePath destination) + public static async Task Create(ManualDownloader.State state, AbsolutePath destination, Archive archive) { - var result = new ManuallyDownloadLoversLabFile(state, destination); + var result = new ManuallyDownloadLoversLabFile(state, destination, archive); return result; } public override void Cancel() diff --git a/Wabbajack/View Models/UserInterventionHandlers.cs b/Wabbajack/View Models/UserInterventionHandlers.cs index 16f223f9..d9844b92 100644 --- a/Wabbajack/View Models/UserInterventionHandlers.cs +++ b/Wabbajack/View Models/UserInterventionHandlers.cs @@ -259,13 +259,15 @@ namespace Wabbajack p => { vm.Instructions = $"Downloading: {p}"; - })); + }, manuallyDownloadFile.Archive)); await browser.NavigateTo(new Uri(manuallyDownloadFile.State.Url)); while (!cancel.IsCancellationRequested && !tcs.Task.IsCompleted) { + await browser.EvaluateJavaScript( + "Array.from(document.getElementsByClassName('ll_adblock')).forEach(c => c.remove())"); await Task.Delay(100); } manuallyDownloadFile.Resume(); @@ -277,12 +279,14 @@ namespace Wabbajack private readonly AbsolutePath _destination; private readonly TaskCompletionSource _tcs; private readonly Action _progress; + private Archive _archive; - public BlobDownloadHandler(AbsolutePath f, TaskCompletionSource tcs, Action progress = null) + public BlobDownloadHandler(AbsolutePath f, TaskCompletionSource tcs, Action progress = null, Archive archive = null) { _progress = progress; _destination = f; _tcs = tcs; + _archive = archive; } public void OnBeforeDownload(IWebBrowser chromiumWebBrowser, IBrowser browser, DownloadItem downloadItem, IBeforeDownloadCallback callback) @@ -293,6 +297,14 @@ namespace Wabbajack public void OnDownloadUpdated(IWebBrowser chromiumWebBrowser, IBrowser browser, DownloadItem downloadItem, IDownloadItemCallback callback) { + if (_archive?.Size != 0 && downloadItem.TotalBytes != _archive?.Size) + { + _tcs.SetCanceled(); + Utils.Error( + $"Download of {_archive!.Name} (from {downloadItem.OriginalUrl}) aborted, selected file was {downloadItem.TotalBytes.ToFileSizeString()} expected size was {_archive!.Size.ToFileSizeString()}"); + return; + } + _progress?.Invoke(Percent.FactoryPutInRange(downloadItem.PercentComplete, 100)); if (downloadItem.IsComplete)