mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
More work on manual downloader
This commit is contained in:
parent
5948af4c0d
commit
934cdd18ce
@ -52,6 +52,7 @@ namespace Wabbajack
|
|||||||
|
|
||||||
services.AddTransient<MainWindow>();
|
services.AddTransient<MainWindow>();
|
||||||
services.AddTransient<MainWindowVM>();
|
services.AddTransient<MainWindowVM>();
|
||||||
|
services.AddTransient<BrowserWindow>();
|
||||||
services.AddSingleton<SystemParametersConstructor>();
|
services.AddSingleton<SystemParametersConstructor>();
|
||||||
services.AddSingleton<LauncherUpdater>();
|
services.AddSingleton<LauncherUpdater>();
|
||||||
services.AddSingleton<ResourceMonitor>();
|
services.AddSingleton<ResourceMonitor>();
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Reactive.Disposables;
|
||||||
|
using System.Windows.Threading;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using ReactiveUI;
|
using ReactiveUI;
|
||||||
using Wabbajack.DTOs.Interventions;
|
using Wabbajack.DTOs.Interventions;
|
||||||
|
using Wabbajack.Messages;
|
||||||
using Wabbajack.UserIntervention;
|
using Wabbajack.UserIntervention;
|
||||||
|
|
||||||
namespace Wabbajack.Interventions;
|
namespace Wabbajack.Interventions;
|
||||||
@ -23,18 +26,24 @@ public class UserInteventionHandler : IUserInterventionHandler
|
|||||||
{
|
{
|
||||||
// Recast these or they won't be properly handled by the message bus
|
// Recast these or they won't be properly handled by the message bus
|
||||||
case ManualDownload md:
|
case ManualDownload md:
|
||||||
var view = new BrowserWindow();
|
{
|
||||||
var provider = _serviceProvider.GetRequiredService<ManualDownloadHandler>();
|
var provider = _serviceProvider.GetRequiredService<ManualDownloadHandler>();
|
||||||
view.DataContext = provider;
|
|
||||||
provider.Intervention = md;
|
provider.Intervention = md;
|
||||||
view.Show();
|
MessageBus.Current.SendMessage(new SpawnBrowserWindow(provider));
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case ManualBlobDownload bd:
|
case ManualBlobDownload bd:
|
||||||
MessageBus.Current.SendMessage(bd);
|
{
|
||||||
|
var provider = _serviceProvider.GetRequiredService<ManualBlobDownloadHandler>();
|
||||||
|
provider.Intervention = bd;
|
||||||
|
MessageBus.Current.SendMessage(new SpawnBrowserWindow(provider));
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
_logger.LogError("No handler for user intervention: {Type}", intervention);
|
_logger.LogError("No handler for user intervention: {Type}", intervention);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
5
Wabbajack.App.Wpf/Messages/SpawnBrowserWindow.cs
Normal file
5
Wabbajack.App.Wpf/Messages/SpawnBrowserWindow.cs
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
namespace Wabbajack.Messages;
|
||||||
|
|
||||||
|
public record SpawnBrowserWindow (BrowserWindowViewModel Vm)
|
||||||
|
{
|
||||||
|
}
|
@ -14,7 +14,7 @@ public class ManualDownloadHandler : BrowserWindowViewModel
|
|||||||
|
|
||||||
protected override async Task Run(CancellationToken token)
|
protected override async Task Run(CancellationToken token)
|
||||||
{
|
{
|
||||||
await WaitForReady();
|
//await WaitForReady();
|
||||||
var archive = Intervention.Archive;
|
var archive = Intervention.Archive;
|
||||||
var md = Intervention.Archive.State as Manual;
|
var md = Intervention.Archive.State as Manual;
|
||||||
|
|
||||||
|
@ -56,7 +56,14 @@ public abstract class BrowserWindowViewModel : ViewModel
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
tcs.TrySetException(new Exception($"Navigation error to {uri}"));
|
if (a.WebErrorStatus == CoreWebView2WebErrorStatus.ConnectionAborted)
|
||||||
|
{
|
||||||
|
tcs.TrySetResult();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tcs.TrySetException(new Exception($"Navigation error to {uri} - {a.WebErrorStatus}"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,13 +102,9 @@ namespace Wabbajack
|
|||||||
.Subscribe(HandleNavigateBack)
|
.Subscribe(HandleNavigateBack)
|
||||||
.DisposeWith(CompositeDisposable);
|
.DisposeWith(CompositeDisposable);
|
||||||
|
|
||||||
MessageBus.Current.Listen<ManualDownload>()
|
MessageBus.Current.Listen<SpawnBrowserWindow>()
|
||||||
.Subscribe(HandleManualDownload)
|
.ObserveOnGuiThread()
|
||||||
.DisposeWith(CompositeDisposable);
|
.Subscribe(HandleSpawnBrowserWindow)
|
||||||
|
|
||||||
|
|
||||||
MessageBus.Current.Listen<ManualBlobDownload>()
|
|
||||||
.Subscribe(HandleManualBlobDownload)
|
|
||||||
.DisposeWith(CompositeDisposable);
|
.DisposeWith(CompositeDisposable);
|
||||||
|
|
||||||
_resourceMonitor.Updates
|
_resourceMonitor.Updates
|
||||||
@ -180,6 +176,13 @@ namespace Wabbajack
|
|||||||
//MessageBus.Current.SendMessage(new OpenBrowserTab(handler));
|
//MessageBus.Current.SendMessage(new OpenBrowserTab(handler));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void HandleSpawnBrowserWindow(SpawnBrowserWindow msg)
|
||||||
|
{
|
||||||
|
var window = _serviceProvider.GetRequiredService<BrowserWindow>();
|
||||||
|
window.DataContext = msg.Vm;
|
||||||
|
window.Show();
|
||||||
|
}
|
||||||
|
|
||||||
private void HandleNavigateTo(NavigateToGlobal.ScreenType s)
|
private void HandleNavigateTo(NavigateToGlobal.ScreenType s)
|
||||||
{
|
{
|
||||||
if (s is NavigateToGlobal.ScreenType.Settings)
|
if (s is NavigateToGlobal.ScreenType.Settings)
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
TitleBarHeight="25"
|
TitleBarHeight="25"
|
||||||
UseLayoutRounding="True"
|
UseLayoutRounding="True"
|
||||||
WindowTitleBrush="{StaticResource MahApps.Brushes.Accent}"
|
WindowTitleBrush="{StaticResource MahApps.Brushes.Accent}"
|
||||||
Activated="BrowserWindow_OnActivated"
|
ContentRendered="BrowserWindow_OnActivated"
|
||||||
mc:Ignorable="d">
|
mc:Ignorable="d">
|
||||||
<Grid Background="#121212" MouseDown="UIElement_OnMouseDown">
|
<Grid Background="#121212" MouseDown="UIElement_OnMouseDown">
|
||||||
<Grid.RowDefinitions>
|
<Grid.RowDefinitions>
|
||||||
@ -43,7 +43,7 @@
|
|||||||
</Button>
|
</Button>
|
||||||
<TextBox Grid.Row="1" Grid.Column="3" VerticalContentAlignment="Center"></TextBox>
|
<TextBox Grid.Row="1" Grid.Column="3" VerticalContentAlignment="Center"></TextBox>
|
||||||
|
|
||||||
<wpf:WebView2 Grid.Row="2" Grid.ColumnSpan="3" Name="Browser" Source="https://www.wabbajack.org"></wpf:WebView2>
|
<wpf:WebView2 Grid.Row="2" Grid.ColumnSpan="3" Name="Browser"></wpf:WebView2>
|
||||||
|
|
||||||
</Grid>
|
</Grid>
|
||||||
</mahapps:MetroWindow>
|
</mahapps:MetroWindow>
|
||||||
|
@ -117,7 +117,6 @@ public class NexusDownloader : ADownloader<Nexus>, IUrlDownloader
|
|||||||
{
|
{
|
||||||
if (IsManualDebugMode || await _api.IsPremium(token))
|
if (IsManualDebugMode || await _api.IsPremium(token))
|
||||||
{
|
{
|
||||||
using var _ = await _interventionLimiter.Begin("Downloading file manually", 1, token);
|
|
||||||
return await DownloadManually(archive, state, destination, job, token);
|
return await DownloadManually(archive, state, destination, job, token);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -156,8 +155,14 @@ public class NexusDownloader : ADownloader<Nexus>, IUrlDownloader
|
|||||||
Url = new Uri($"https://www.nexusmods.com/{state.Game.MetaData().NexusName}/mods/{state.ModID}?tab=files&file_id={state.FileID}")
|
Url = new Uri($"https://www.nexusmods.com/{state.Game.MetaData().NexusName}/mods/{state.ModID}?tab=files&file_id={state.FileID}")
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
_userInterventionHandler.Raise(md);
|
|
||||||
var browserState = await md.Task;
|
ManualDownload.BrowserDownloadState browserState;
|
||||||
|
using (var _ = await _interventionLimiter.Begin("Downloading file manually", 1, token))
|
||||||
|
{
|
||||||
|
_userInterventionHandler.Raise(md);
|
||||||
|
browserState = await md.Task;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
var msg = browserState.ToHttpRequestMessage();
|
var msg = browserState.ToHttpRequestMessage();
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ public static class ServiceExtensions
|
|||||||
new Resource<IInstaller>("Installer", GetSettings(s, "Installer")));
|
new Resource<IInstaller>("Installer", GetSettings(s, "Installer")));
|
||||||
|
|
||||||
service.AddAllSingleton<IResource, IResource<IUserInterventionHandler>>(s =>
|
service.AddAllSingleton<IResource, IResource<IUserInterventionHandler>>(s =>
|
||||||
new Resource<IUserInterventionHandler>("User Intervention", 3));
|
new Resource<IUserInterventionHandler>("User Intervention", 1));
|
||||||
|
|
||||||
service.AddSingleton<LoggingRateLimiterReporter>();
|
service.AddSingleton<LoggingRateLimiterReporter>();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user