mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
LibCef extraction init awaits and improvements
This commit is contained in:
parent
b0bff6e121
commit
1673f8a555
@ -15,11 +15,12 @@ namespace Wabbajack.Lib.LibCefHelpers
|
||||
{
|
||||
public static class Helpers
|
||||
{
|
||||
private static readonly Task _initTask;
|
||||
|
||||
/// <summary>
|
||||
/// We bundle the cef libs inside the .exe, we need to extract them before loading any wpf code that requires them
|
||||
/// </summary>
|
||||
public static async Task ExtractLibs()
|
||||
private static async Task ExtractLibs()
|
||||
{
|
||||
if (File.Exists("cefglue.7z") && File.Exists("libcef.dll")) return;
|
||||
|
||||
@ -34,6 +35,17 @@ namespace Wabbajack.Lib.LibCefHelpers
|
||||
await FileExtractor.ExtractAll(wq, "cefglue.7z", ".");
|
||||
}
|
||||
}
|
||||
|
||||
static Helpers()
|
||||
{
|
||||
_initTask = Task.Run(ExtractLibs);
|
||||
}
|
||||
|
||||
public static Task Initialize()
|
||||
{
|
||||
return _initTask;
|
||||
}
|
||||
|
||||
public static HttpClient GetClient(IEnumerable<Cookie> cookies, string referer)
|
||||
{
|
||||
var container = ToCookieContainer(cookies);
|
||||
@ -66,7 +78,6 @@ namespace Wabbajack.Lib.LibCefHelpers
|
||||
return (await visitor.Task).Where(c => c.Domain.EndsWith(domainEnding)).ToArray();
|
||||
}
|
||||
|
||||
|
||||
private class CookieVisitor : CefCookieVisitor
|
||||
{
|
||||
TaskCompletionSource<List<Cookie>> _source = new TaskCompletionSource<List<Cookie>>();
|
||||
@ -93,8 +104,6 @@ namespace Wabbajack.Lib.LibCefHelpers
|
||||
if (disposing)
|
||||
_source.SetResult(Cookies);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public class Cookie
|
||||
|
@ -15,7 +15,7 @@ namespace Wabbajack.Test
|
||||
[TestInitialize]
|
||||
public async Task TestInitialize()
|
||||
{
|
||||
await Helpers.ExtractLibs();
|
||||
await Helpers.Initialize();
|
||||
Consts.TestMode = true;
|
||||
|
||||
utils = new TestUtils();
|
||||
|
@ -26,7 +26,7 @@ namespace Wabbajack.Test
|
||||
[TestInitialize]
|
||||
public async Task Setup()
|
||||
{
|
||||
await Helpers.ExtractLibs();
|
||||
await Helpers.Initialize();
|
||||
Utils.LogMessages.OfType<IInfo>().Subscribe(onNext: msg => TestContext.WriteLine(msg.ShortDescription));
|
||||
Utils.LogMessages.OfType<IUserIntervention>().Subscribe(msg =>
|
||||
TestContext.WriteLine("ERROR: User intervetion required: " + msg.ShortDescription));
|
||||
|
21
Wabbajack/Util/AsyncLazy.cs
Normal file
21
Wabbajack/Util/AsyncLazy.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Wabbajack
|
||||
{
|
||||
public class AsyncLazy<T> : Lazy<Task<T>>
|
||||
{
|
||||
public AsyncLazy(Func<T> valueFactory) :
|
||||
base(() => Task.Factory.StartNew(valueFactory))
|
||||
{
|
||||
}
|
||||
|
||||
public AsyncLazy(Func<Task<T>> taskFactory) :
|
||||
base(() => Task.Factory.StartNew(() => taskFactory()).Unwrap())
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
@ -36,7 +36,6 @@ namespace Wabbajack
|
||||
public readonly Lazy<InstallerVM> Installer;
|
||||
public readonly Lazy<ModListGalleryVM> Gallery;
|
||||
public readonly ModeSelectionVM ModeSelectionVM;
|
||||
public readonly WebBrowserVM WebBrowserVM;
|
||||
public readonly UserInterventionHandlers UserInterventionHandlers;
|
||||
public Dispatcher ViewDispatcher { get; set; }
|
||||
|
||||
@ -52,7 +51,6 @@ namespace Wabbajack
|
||||
Compiler = new Lazy<CompilerVM>(() => new CompilerVM(this));
|
||||
Gallery = new Lazy<ModListGalleryVM>(() => new ModListGalleryVM(this));
|
||||
ModeSelectionVM = new ModeSelectionVM(this);
|
||||
WebBrowserVM = new WebBrowserVM();
|
||||
UserInterventionHandlers = new UserInterventionHandlers(this);
|
||||
|
||||
// Set up logging
|
||||
|
@ -26,7 +26,7 @@ namespace Wabbajack
|
||||
{
|
||||
CancellationTokenSource cancel = new CancellationTokenSource();
|
||||
var oldPane = MainWindow.ActivePane;
|
||||
var vm = new WebBrowserVM();
|
||||
var vm = await WebBrowserVM.GetNew();
|
||||
MainWindow.ActivePane = vm;
|
||||
vm.BackCommand = ReactiveCommand.Create(() =>
|
||||
{
|
||||
|
@ -6,6 +6,7 @@ using System.Threading.Tasks;
|
||||
using ReactiveUI;
|
||||
using ReactiveUI.Fody.Helpers;
|
||||
using Wabbajack.Lib;
|
||||
using Wabbajack.Lib.LibCefHelpers;
|
||||
using Xilium.CefGlue.WPF;
|
||||
|
||||
namespace Wabbajack
|
||||
@ -20,10 +21,17 @@ namespace Wabbajack
|
||||
[Reactive]
|
||||
public IReactiveCommand BackCommand { get; set; }
|
||||
|
||||
public WebBrowserVM(string url = "http://www.wabbajack.org")
|
||||
private WebBrowserVM(string url = "http://www.wabbajack.org")
|
||||
{
|
||||
Browser.Address = url;
|
||||
Instructions = "Wabbajack Web Browser";
|
||||
}
|
||||
|
||||
public static async Task<WebBrowserVM> GetNew(string url = "http://www.wabbajack.org")
|
||||
{
|
||||
// Make sure libraries are extracted first
|
||||
await Helpers.Initialize();
|
||||
return new WebBrowserVM(url);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ namespace Wabbajack
|
||||
// Run some init tasks in background
|
||||
Task.Run(async () =>
|
||||
{
|
||||
await Helpers.ExtractLibs();
|
||||
await Helpers.Initialize();
|
||||
var appPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
|
||||
try
|
||||
{
|
||||
|
@ -176,6 +176,7 @@
|
||||
<Compile Include="UnderMaintenanceOverlay.xaml.cs">
|
||||
<DependentUpon>UnderMaintenanceOverlay.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Util\AsyncLazy.cs" />
|
||||
<Compile Include="View Models\CPUDisplayVM.cs" />
|
||||
<Compile Include="Views\Compilers\CompilationCompleteView.xaml.cs">
|
||||
<DependentUpon>CompilationCompleteView.xaml</DependentUpon>
|
||||
|
Loading…
Reference in New Issue
Block a user