Cleanup how we handle ll downloads a bit

This commit is contained in:
Timothy Baldridge 2022-02-27 13:50:02 -07:00
parent 57fdc42ea4
commit ef907ee4c0
3 changed files with 21 additions and 8 deletions

View File

@ -63,10 +63,9 @@ namespace Wabbajack.Lib.Downloaders
await Utils.Log(await ManuallyDownloadMegaFile.Create(this, destination)).Task; await Utils.Log(await ManuallyDownloadMegaFile.Create(this, destination)).Task;
return true; return true;
} }
else if ((new Uri(Url)).Host.EndsWith("loverslab.com"))
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; return true;
} }
else else

View File

@ -15,16 +15,18 @@ namespace Wabbajack.Lib
public AbsolutePath Destination { get; } 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; State = state;
Destination = destination; Destination = destination;
Archive = archive;
} }
public static async Task<ManuallyDownloadLoversLabFile> Create(ManualDownloader.State state, AbsolutePath destination) public static async Task<ManuallyDownloadLoversLabFile> Create(ManualDownloader.State state, AbsolutePath destination, Archive archive)
{ {
var result = new ManuallyDownloadLoversLabFile(state, destination); var result = new ManuallyDownloadLoversLabFile(state, destination, archive);
return result; return result;
} }
public override void Cancel() public override void Cancel()

View File

@ -259,13 +259,15 @@ namespace Wabbajack
p => p =>
{ {
vm.Instructions = $"Downloading: {p}"; vm.Instructions = $"Downloading: {p}";
})); }, manuallyDownloadFile.Archive));
await browser.NavigateTo(new Uri(manuallyDownloadFile.State.Url)); await browser.NavigateTo(new Uri(manuallyDownloadFile.State.Url));
while (!cancel.IsCancellationRequested && !tcs.Task.IsCompleted) while (!cancel.IsCancellationRequested && !tcs.Task.IsCompleted)
{ {
await browser.EvaluateJavaScript(
"Array.from(document.getElementsByClassName('ll_adblock')).forEach(c => c.remove())");
await Task.Delay(100); await Task.Delay(100);
} }
manuallyDownloadFile.Resume(); manuallyDownloadFile.Resume();
@ -277,12 +279,14 @@ namespace Wabbajack
private readonly AbsolutePath _destination; private readonly AbsolutePath _destination;
private readonly TaskCompletionSource _tcs; private readonly TaskCompletionSource _tcs;
private readonly Action<Percent> _progress; private readonly Action<Percent> _progress;
private Archive _archive;
public BlobDownloadHandler(AbsolutePath f, TaskCompletionSource tcs, Action<Percent> progress = null) public BlobDownloadHandler(AbsolutePath f, TaskCompletionSource tcs, Action<Percent> progress = null, Archive archive = null)
{ {
_progress = progress; _progress = progress;
_destination = f; _destination = f;
_tcs = tcs; _tcs = tcs;
_archive = archive;
} }
public void OnBeforeDownload(IWebBrowser chromiumWebBrowser, IBrowser browser, DownloadItem downloadItem, public void OnBeforeDownload(IWebBrowser chromiumWebBrowser, IBrowser browser, DownloadItem downloadItem,
IBeforeDownloadCallback callback) IBeforeDownloadCallback callback)
@ -293,6 +297,14 @@ namespace Wabbajack
public void OnDownloadUpdated(IWebBrowser chromiumWebBrowser, IBrowser browser, DownloadItem downloadItem, public void OnDownloadUpdated(IWebBrowser chromiumWebBrowser, IBrowser browser, DownloadItem downloadItem,
IDownloadItemCallback callback) 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)); _progress?.Invoke(Percent.FactoryPutInRange(downloadItem.PercentComplete, 100));
if (downloadItem.IsComplete) if (downloadItem.IsComplete)