mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Cef->WebView2
This commit is contained in:
parent
8f2f3b6eab
commit
2cdc61debd
@ -1,123 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using Alphaleonis.Win32.Filesystem;
|
||||
using CefSharp;
|
||||
using CefSharp.OffScreen;
|
||||
using Wabbajack.Common;
|
||||
using Wabbajack.DTOs.JsonConverters;
|
||||
using Cookie = CefSharp.Cookie;
|
||||
|
||||
namespace Wabbajack.LibCefHelpers
|
||||
{
|
||||
public static class Helpers
|
||||
{
|
||||
public static HttpRequestMessage MakeMessage(HttpMethod method, Uri uri, IEnumerable<Cookie> cookies, string referer)
|
||||
{
|
||||
var msg = new HttpRequestMessage(method, uri);
|
||||
msg.Headers.Add("Referrer", referer);
|
||||
var cs = string.Join(",", cookies.Select(c => $"{c.Name}={c.Value}"));
|
||||
msg.Headers.Add("Cookie", cs);
|
||||
return msg;
|
||||
}
|
||||
|
||||
private static CookieContainer ToCookieContainer(IEnumerable<Cookie> cookies)
|
||||
{
|
||||
var container = new CookieContainer();
|
||||
cookies
|
||||
.Do(cookie =>
|
||||
{
|
||||
container.Add(new System.Net.Cookie(cookie.Name, cookie.Value, cookie.Path, cookie.Domain));
|
||||
});
|
||||
|
||||
return container;
|
||||
}
|
||||
|
||||
public static async Task<DTOs.Logins.Cookie[]> GetCookies(string domainEnding = "")
|
||||
{
|
||||
var manager = Cef.GetGlobalCookieManager();
|
||||
var visitor = new CookieVisitor();
|
||||
if (!manager.VisitAllCookies(visitor))
|
||||
return Array.Empty<DTOs.Logins.Cookie>();
|
||||
var cc = await visitor.Task;
|
||||
|
||||
return (await visitor.Task).Where(c => c.Domain.EndsWith(domainEnding)).ToArray();
|
||||
}
|
||||
|
||||
private class CookieVisitor : ICookieVisitor
|
||||
{
|
||||
TaskCompletionSource<List<DTOs.Logins.Cookie>> _source = new();
|
||||
public Task<List<DTOs.Logins.Cookie>> Task => _source.Task;
|
||||
|
||||
public List<DTOs.Logins.Cookie> Cookies { get; } = new ();
|
||||
public void Dispose()
|
||||
{
|
||||
_source.SetResult(Cookies);
|
||||
}
|
||||
|
||||
public bool Visit(CefSharp.Cookie cookie, int count, int total, ref bool deleteCookie)
|
||||
{
|
||||
Cookies.Add(new DTOs.Logins.Cookie
|
||||
{
|
||||
Name = cookie.Name,
|
||||
Value = cookie.Value,
|
||||
Domain = cookie.Domain,
|
||||
Path = cookie.Path
|
||||
});
|
||||
if (count == total)
|
||||
_source.SetResult(Cookies);
|
||||
deleteCookie = false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
public static void ClearCookies()
|
||||
{
|
||||
var manager = Cef.GetGlobalCookieManager();
|
||||
var visitor = new CookieDeleter();
|
||||
manager.VisitAllCookies(visitor);
|
||||
}
|
||||
|
||||
public static async Task DeleteCookiesWhere(Func<DTOs.Logins.Cookie,bool> filter)
|
||||
{
|
||||
var manager = Cef.GetGlobalCookieManager();
|
||||
var visitor = new CookieDeleter(filter);
|
||||
manager.VisitAllCookies(visitor);
|
||||
}
|
||||
}
|
||||
|
||||
class CookieDeleter : ICookieVisitor
|
||||
{
|
||||
private Func<DTOs.Logins.Cookie, bool>? _filter;
|
||||
|
||||
public CookieDeleter(Func<DTOs.Logins.Cookie, bool>? filter = null)
|
||||
{
|
||||
_filter = filter;
|
||||
}
|
||||
public void Dispose()
|
||||
{
|
||||
}
|
||||
|
||||
public bool Visit(Cookie cookie, int count, int total, ref bool deleteCookie)
|
||||
{
|
||||
if (_filter == null)
|
||||
{
|
||||
deleteCookie = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
var conv = new DTOs.Logins.Cookie
|
||||
{
|
||||
Name = cookie.Name, Domain = cookie.Domain, Value = cookie.Value, Path = cookie.Path
|
||||
};
|
||||
if (_filter(conv))
|
||||
deleteCookie = true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
@ -2,13 +2,10 @@ using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using ReactiveUI;
|
||||
using Wabbajack.DTOs.Logins;
|
||||
using Wabbajack.LibCefHelpers;
|
||||
using Wabbajack.Messages;
|
||||
using Wabbajack.Models;
|
||||
using Wabbajack.Networking.Http.Interfaces;
|
||||
using Wabbajack.Services.OSIntegrated.TokenProviders;
|
||||
|
||||
namespace Wabbajack.UserIntervention;
|
||||
|
||||
|
@ -59,11 +59,6 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="cef.redist.x64" Version="91.1.23" />
|
||||
<PackageReference Include="CefSharp.Common" Version="91.1.230" />
|
||||
<PackageReference Include="CefSharp.Wpf" Version="91.1.230">
|
||||
<NoWarn>NU1701</NoWarn>
|
||||
</PackageReference>
|
||||
<PackageReference Include="DynamicData" Version="7.3.1" />
|
||||
<PackageReference Include="Extended.Wpf.Toolkit" Version="4.1.0">
|
||||
<NoWarn>NU1701</NoWarn>
|
||||
@ -81,6 +76,7 @@
|
||||
<PackageReference Include="MahApps.Metro.IconPacks" Version="4.8.0" />
|
||||
<PackageReference Include="Microsoft-WindowsAPICodePack-Shell" Version="1.1.4" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.0" />
|
||||
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.1189-prerelease" />
|
||||
<PackageReference Include="PInvoke.User32" Version="0.7.104" />
|
||||
<PackageReference Include="ReactiveUI" Version="16.2.6" />
|
||||
<PackageReference Include="ReactiveUI.Fody" Version="16.2.6" />
|
||||
@ -88,10 +84,6 @@
|
||||
<PackageReference Include="Silk.NET.DXGI" Version="2.6.0" />
|
||||
<PackageReference Include="System.Reactive" Version="5.0.0" />
|
||||
<PackageReference Include="WPFThemes.DarkBlend" Version="1.0.8" />
|
||||
<PackageReference Include="CefSharp.OffScreen">
|
||||
<Version>91.1.230</Version>
|
||||
<NoWarn>NU1701</NoWarn>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
Loading…
Reference in New Issue
Block a user