diff --git a/Wabbajack.Lib/AuthorApi/Client.cs b/Wabbajack.Lib/AuthorApi/Client.cs index 8c64c826..a129ea89 100644 --- a/Wabbajack.Lib/AuthorApi/Client.cs +++ b/Wabbajack.Lib/AuthorApi/Client.cs @@ -18,20 +18,20 @@ namespace Wabbajack.Lib.AuthorApi return new Client(client); } - private Client(Common.Http.Client client) + private Client(Wabbajack.Lib.Http.Client client) { _client = client; } - public static async Task GetAuthorizedClient(string? apiKey = null) + public static async Task GetAuthorizedClient(string? apiKey = null) { - var client = new Common.Http.Client(); + var client = new Wabbajack.Lib.Http.Client(); client.Headers.Add(("X-API-KEY", await GetAPIKey(apiKey))); return client; } public static string? ApiKeyOverride = null; - private Common.Http.Client _client; + private Wabbajack.Lib.Http.Client _client; public static async ValueTask GetAPIKey(string? apiKey = null) { diff --git a/Wabbajack.Lib/ClientAPI.cs b/Wabbajack.Lib/ClientAPI.cs index 37b75759..bfa1356a 100644 --- a/Wabbajack.Lib/ClientAPI.cs +++ b/Wabbajack.Lib/ClientAPI.cs @@ -45,9 +45,9 @@ using Wabbajack.Lib.Downloaders; public class ClientAPI { - public static async Task GetClient() + public static async Task GetClient() { - var client = new Common.Http.Client(); + var client = new Wabbajack.Lib.Http.Client(); client.Headers.Add((Consts.MetricsKeyHeader, await Metrics.GetMetricsKey())); return client; } diff --git a/Wabbajack.Lib/Downloaders/AbstractNeedsLoginDownloader.cs b/Wabbajack.Lib/Downloaders/AbstractNeedsLoginDownloader.cs index 4f197f3c..256f57c3 100644 --- a/Wabbajack.Lib/Downloaders/AbstractNeedsLoginDownloader.cs +++ b/Wabbajack.Lib/Downloaders/AbstractNeedsLoginDownloader.cs @@ -26,7 +26,7 @@ namespace Wabbajack.Lib.Downloaders // ToDo // Remove null assignment. Either add nullability to type, or figure way to prepare it safely - public Common.Http.Client AuthedClient { get; private set; } = null!; + public Wabbajack.Lib.Http.Client AuthedClient { get; private set; } = null!; public ReactiveCommand TriggerLogin { get; } public ReactiveCommand ClearLogin { get; } @@ -86,7 +86,7 @@ namespace Wabbajack.Lib.Downloaders return cookies; } - public async Task GetAuthedClient() + public async Task GetAuthedClient() { Helpers.Cookie[] cookies; try diff --git a/Wabbajack.Lib/Downloaders/BethesdaNetDownloader.cs b/Wabbajack.Lib/Downloaders/BethesdaNetDownloader.cs index 60a76337..220462cd 100644 --- a/Wabbajack.Lib/Downloaders/BethesdaNetDownloader.cs +++ b/Wabbajack.Lib/Downloaders/BethesdaNetDownloader.cs @@ -216,13 +216,13 @@ namespace Wabbajack.Lib.Downloaders return true; } - private async Task<(Common.Http.Client, CDPTree, CollectedBNetInfo)> ResolveDownloadInfo() + private async Task<(Wabbajack.Lib.Http.Client, CDPTree, CollectedBNetInfo)> ResolveDownloadInfo() { var info = new CollectedBNetInfo(); var login_info = await Utils.FromEncryptedJson(DataName); - var client = new Common.Http.Client(); + var client = new Wabbajack.Lib.Http.Client(); client.Headers.Add(("User-Agent", "bnet")); foreach (var header in login_info.headers.Where(h => h.Key.ToLower().StartsWith("x-"))) diff --git a/Wabbajack.Lib/Downloaders/GoogleDriveDownloader.cs b/Wabbajack.Lib/Downloaders/GoogleDriveDownloader.cs index 76a5b2f6..1c8f0d3f 100644 --- a/Wabbajack.Lib/Downloaders/GoogleDriveDownloader.cs +++ b/Wabbajack.Lib/Downloaders/GoogleDriveDownloader.cs @@ -59,7 +59,7 @@ namespace Wabbajack.Lib.Downloaders private async Task ToHttpState() { var initialURL = $"https://drive.google.com/uc?id={Id}&export=download"; - var client = new Common.Http.Client(); + var client = new Wabbajack.Lib.Http.Client(); using var response = await client.GetAsync(initialURL); if (!response.IsSuccessStatusCode) throw new HttpException((int)response.StatusCode, response.ReasonPhrase); diff --git a/Wabbajack.Lib/Downloaders/HTTPDownloader.cs b/Wabbajack.Lib/Downloaders/HTTPDownloader.cs index 3f0df7a2..92e33807 100644 --- a/Wabbajack.Lib/Downloaders/HTTPDownloader.cs +++ b/Wabbajack.Lib/Downloaders/HTTPDownloader.cs @@ -54,7 +54,7 @@ namespace Wabbajack.Lib.Downloaders public List Headers { get; } = new List(); [JsonIgnore] - public Common.Http.Client? Client { get; set; } + public Wabbajack.Lib.Http.Client? Client { get; set; } [JsonIgnore] public override object[] PrimaryKey => new object[] { Url }; diff --git a/Wabbajack.Lib/Downloaders/MEGADownloader.cs b/Wabbajack.Lib/Downloaders/MEGADownloader.cs index 4a1fb2c0..6d9f6a78 100644 --- a/Wabbajack.Lib/Downloaders/MEGADownloader.cs +++ b/Wabbajack.Lib/Downloaders/MEGADownloader.cs @@ -115,7 +115,7 @@ namespace Wabbajack.Lib.Downloaders TriggerLogin = ReactiveCommand.Create(() => { }, IsLoggedIn.Select(b => !b).ObserveOnGuiThread()); - ClearLogin = ReactiveCommand.Create(() => Utils.CatchAndLog(() => Utils.DeleteEncryptedJson(DataName)), + ClearLogin = ReactiveCommand.CreateFromTask(() => Utils.CatchAndLog(async () => await Utils.DeleteEncryptedJson(DataName)), IsLoggedIn.ObserveOnGuiThread()); } diff --git a/Wabbajack.Lib/Downloaders/MediaFireDownloader.cs b/Wabbajack.Lib/Downloaders/MediaFireDownloader.cs index 2cbb4757..6bb1ad90 100644 --- a/Wabbajack.Lib/Downloaders/MediaFireDownloader.cs +++ b/Wabbajack.Lib/Downloaders/MediaFireDownloader.cs @@ -50,7 +50,7 @@ namespace Wabbajack.Lib.Downloaders private async Task Resolve() { - var client = new Common.Http.Client(); + var client = new Wabbajack.Lib.Http.Client(); var body = await client.GetHtmlAsync(Url); var node = body.DocumentNode.DescendantsAndSelf().First(d => d.HasClass("input") && d.HasClass("popsok") && d.GetAttributeValue("aria-label", "") == "Download file"); diff --git a/Wabbajack.Lib/Downloaders/NexusDownloader.cs b/Wabbajack.Lib/Downloaders/NexusDownloader.cs index 9235e458..9f83853f 100644 --- a/Wabbajack.Lib/Downloaders/NexusDownloader.cs +++ b/Wabbajack.Lib/Downloaders/NexusDownloader.cs @@ -46,8 +46,8 @@ namespace Wabbajack.Lib.Downloaders TriggerLogin = ReactiveCommand.CreateFromTask( execute: () => Utils.CatchAndLog(NexusApiClient.RequestAndCacheAPIKey), canExecute: IsLoggedIn.Select(b => !b).ObserveOnGuiThread()); - ClearLogin = ReactiveCommand.Create( - execute: () => Utils.CatchAndLog(() => Utils.DeleteEncryptedJson("nexusapikey")), + ClearLogin = ReactiveCommand.CreateFromTask( + execute: () => Utils.CatchAndLog(async () => await Utils.DeleteEncryptedJson("nexusapikey")), canExecute: IsLoggedIn.ObserveOnGuiThread()); } diff --git a/Wabbajack.Lib/Downloaders/UrlDownloaders/YoutubeInferencer.cs b/Wabbajack.Lib/Downloaders/UrlDownloaders/YoutubeInferencer.cs index a1c19239..fd34d2d8 100644 --- a/Wabbajack.Lib/Downloaders/UrlDownloaders/YoutubeInferencer.cs +++ b/Wabbajack.Lib/Downloaders/UrlDownloaders/YoutubeInferencer.cs @@ -16,7 +16,7 @@ namespace Wabbajack.Lib.Downloaders.UrlDownloaders var state = YouTubeDownloader.UriToState(uri) as YouTubeDownloader.State; if (state == null) return null; - var client = new YoutubeClient(Common.Http.ClientFactory.Client); + var client = new YoutubeClient(Wabbajack.Lib.Http.ClientFactory.Client); var video = await client.Videos.GetAsync(state.Key); var desc = video.Description; diff --git a/Wabbajack.Lib/Downloaders/WabbajackCDNDownloader.cs b/Wabbajack.Lib/Downloaders/WabbajackCDNDownloader.cs index 1f14b7c6..452381fe 100644 --- a/Wabbajack.Lib/Downloaders/WabbajackCDNDownloader.cs +++ b/Wabbajack.Lib/Downloaders/WabbajackCDNDownloader.cs @@ -59,7 +59,7 @@ namespace Wabbajack.Lib.Downloaders var definition = await GetDefinition(); await using var fs = await destination.Create(); using var mmfile = MemoryMappedFile.CreateFromFile(fs, null, definition.Size, MemoryMappedFileAccess.ReadWrite, HandleInheritability.None, false); - var client = new Common.Http.Client(); + var client = new Wabbajack.Lib.Http.Client(); using var queue = new WorkQueue(); await definition.Parts.PMap(queue, async part => { @@ -81,7 +81,7 @@ namespace Wabbajack.Lib.Downloaders private async Task GetDefinition() { - var client = new Common.Http.Client(); + var client = new Wabbajack.Lib.Http.Client(); using var data = await client.GetAsync(Url + "/definition.json.gz"); await using var gz = new GZipStream(await data.Content.ReadAsStreamAsync(), CompressionMode.Decompress); return gz.FromJson(); diff --git a/Wabbajack.Lib/Downloaders/YandexDownloader.cs b/Wabbajack.Lib/Downloaders/YandexDownloader.cs index 1bc5acfd..b309495f 100644 --- a/Wabbajack.Lib/Downloaders/YandexDownloader.cs +++ b/Wabbajack.Lib/Downloaders/YandexDownloader.cs @@ -61,7 +61,7 @@ namespace Wabbajack.Lib.Downloaders public override async Task Verify(Archive archive) { - var client = new Common.Http.Client(); + var client = new Wabbajack.Lib.Http.Client(); var result = await client.GetAsync(Url, errorsAsExceptions: false); return result.IsSuccessStatusCode; } diff --git a/Wabbajack.Lib/Downloaders/YouTubeDownloader.cs b/Wabbajack.Lib/Downloaders/YouTubeDownloader.cs index 0462b04b..13fae83d 100644 --- a/Wabbajack.Lib/Downloaders/YouTubeDownloader.cs +++ b/Wabbajack.Lib/Downloaders/YouTubeDownloader.cs @@ -104,7 +104,7 @@ namespace Wabbajack.Lib.Downloaders using var queue = new WorkQueue(); await using var folder = await TempFolder.Create(); folder.Dir.Combine("tracks").CreateDirectory(); - var client = new YoutubeClient(Common.Http.ClientFactory.Client); + var client = new YoutubeClient(Wabbajack.Lib.Http.ClientFactory.Client); var meta = await client.Videos.GetAsync(Key); var video = await client.Videos.Streams.GetManifestAsync(Key); var stream = video.Streams.OfType().Where(f => f.AudioCodec.StartsWith("mp4a")).OrderByDescending(a => a.Bitrate) @@ -210,7 +210,7 @@ namespace Wabbajack.Lib.Downloaders { try { - var client = new YoutubeClient(Common.Http.ClientFactory.Client); + var client = new YoutubeClient(Wabbajack.Lib.Http.ClientFactory.Client); var video = await client.Videos.GetAsync(Key); return true; } diff --git a/Wabbajack.Lib/FileUploader/AuthorAPI.cs b/Wabbajack.Lib/FileUploader/AuthorAPI.cs index 4c75364c..0a24f6ac 100644 --- a/Wabbajack.Lib/FileUploader/AuthorAPI.cs +++ b/Wabbajack.Lib/FileUploader/AuthorAPI.cs @@ -29,9 +29,9 @@ namespace Wabbajack.Lib.FileUploader return apiKey ?? (await Consts.LocalAppDataPath.Combine(Consts.AuthorAPIKeyFile).ReadAllTextAsync()).Trim(); } - public static async Task GetAuthorizedClient(string? apiKey = null) + public static async Task GetAuthorizedClient(string? apiKey = null) { - var client = new Common.Http.Client(); + var client = new Wabbajack.Lib.Http.Client(); client.Headers.Add(("X-API-KEY", await GetAPIKey(apiKey))); return client; } diff --git a/Wabbajack.Common/Http/Client.cs b/Wabbajack.Lib/Http/Client.cs similarity index 99% rename from Wabbajack.Common/Http/Client.cs rename to Wabbajack.Lib/Http/Client.cs index 05192dd4..0f8fcc55 100644 --- a/Wabbajack.Common/Http/Client.cs +++ b/Wabbajack.Lib/Http/Client.cs @@ -6,9 +6,10 @@ using System.Net; using System.Net.Http; using System.Threading.Tasks; using HtmlAgilityPack; +using Wabbajack.Common; using Wabbajack.Common.Exceptions; -namespace Wabbajack.Common.Http +namespace Wabbajack.Lib.Http { public class Client { diff --git a/Wabbajack.Common/Http/ClientFactory.cs b/Wabbajack.Lib/Http/ClientFactory.cs similarity index 96% rename from Wabbajack.Common/Http/ClientFactory.cs rename to Wabbajack.Lib/Http/ClientFactory.cs index 29cb1936..0ec211bb 100644 --- a/Wabbajack.Common/Http/ClientFactory.cs +++ b/Wabbajack.Lib/Http/ClientFactory.cs @@ -1,7 +1,8 @@ using System; using System.Net; using SysHttp = System.Net.Http; -namespace Wabbajack.Common.Http + +namespace Wabbajack.Lib.Http { public static class ClientFactory { diff --git a/Wabbajack.Lib/LibCefHelpers/Init.cs b/Wabbajack.Lib/LibCefHelpers/Init.cs index 5976b180..67695563 100644 --- a/Wabbajack.Lib/LibCefHelpers/Init.cs +++ b/Wabbajack.Lib/LibCefHelpers/Init.cs @@ -18,9 +18,9 @@ namespace Wabbajack.Lib.LibCefHelpers { public static class Helpers { - public static Common.Http.Client GetClient(IEnumerable cookies, string referer) + public static Wabbajack.Lib.Http.Client GetClient(IEnumerable cookies, string referer) { - var client = new Common.Http.Client(); + var client = new Wabbajack.Lib.Http.Client(); client.Headers.Add(("Referrer", referer)); client.Cookies.AddRange(cookies.Select(cookie => new System.Net.Cookie(cookie.Name, cookie.Value, cookie.Path, cookie.Domain))); return client; diff --git a/Wabbajack.Common/Metrics.cs b/Wabbajack.Lib/Metrics.cs similarity index 98% rename from Wabbajack.Common/Metrics.cs rename to Wabbajack.Lib/Metrics.cs index bd11580f..623e5a23 100644 --- a/Wabbajack.Common/Metrics.cs +++ b/Wabbajack.Lib/Metrics.cs @@ -7,9 +7,10 @@ using System.Security.Cryptography; using System.Text; using System.Threading.Tasks; using Microsoft.Win32; +using Wabbajack.Common; using Wabbajack.Common.Exceptions; -namespace Wabbajack.Common +namespace Wabbajack.Lib { public class Metrics { diff --git a/Wabbajack.Lib/ModListRegistry/ModListMetadata.cs b/Wabbajack.Lib/ModListRegistry/ModListMetadata.cs index d1513bc4..f8516ec4 100644 --- a/Wabbajack.Lib/ModListRegistry/ModListMetadata.cs +++ b/Wabbajack.Lib/ModListRegistry/ModListMetadata.cs @@ -62,7 +62,7 @@ namespace Wabbajack.Lib.ModListRegistry public static async Task> LoadFromGithub() { - var client = new Common.Http.Client(); + var client = new Wabbajack.Lib.Http.Client(); Utils.Log("Loading ModLists from GitHub"); var metadataResult = client.GetStringAsync(Consts.ModlistMetadataURL); var summaryResult = client.GetStringAsync(Consts.ModlistSummaryURL); diff --git a/Wabbajack.Lib/NexusApi/NexusApi.cs b/Wabbajack.Lib/NexusApi/NexusApi.cs index 349d1b57..72dd7864 100644 --- a/Wabbajack.Lib/NexusApi/NexusApi.cs +++ b/Wabbajack.Lib/NexusApi/NexusApi.cs @@ -11,7 +11,6 @@ using Wabbajack.Common; using Wabbajack.Lib.Downloaders; using System.Threading; using Wabbajack.Common.Exceptions; -using Wabbajack.Common.Http; using Wabbajack.Lib.WebAutomation; namespace Wabbajack.Lib.NexusApi @@ -20,7 +19,7 @@ namespace Wabbajack.Lib.NexusApi { private static readonly string API_KEY_CACHE_FILE = "nexus.key_cache"; - public Common.Http.Client HttpClient { get; } = new Common.Http.Client(); + public Wabbajack.Lib.Http.Client HttpClient { get; } = new Wabbajack.Lib.Http.Client(); #region Authentication @@ -255,7 +254,7 @@ namespace Wabbajack.Lib.NexusApi return new NexusApiClient(apiKey); } - public async Task Get(string url, Client? client = null) + public async Task Get(string url, Wabbajack.Lib.Http.Client? client = null) { client ??= HttpClient; int retries = 0; diff --git a/Wabbajack.Lib/NexusApi/NexusUpdatesFeeds.cs b/Wabbajack.Lib/NexusApi/NexusUpdatesFeeds.cs index f2f4c98c..becc90ee 100644 --- a/Wabbajack.Lib/NexusApi/NexusUpdatesFeeds.cs +++ b/Wabbajack.Lib/NexusApi/NexusUpdatesFeeds.cs @@ -46,7 +46,7 @@ namespace Wabbajack.Lib.NexusApi private static async Task> GetFeed(Uri uri) { - var client = new Common.Http.Client(); + var client = new Wabbajack.Lib.Http.Client(); var data = await client.GetStringAsync(uri); var reader = XmlReader.Create(new StringReader(data)); var results = SyndicationFeed.Load(reader); diff --git a/Wabbajack.Lib/StatusMessages/ManuallyDownloadFile.cs b/Wabbajack.Lib/StatusMessages/ManuallyDownloadFile.cs index ee02101d..d189e4c9 100644 --- a/Wabbajack.Lib/StatusMessages/ManuallyDownloadFile.cs +++ b/Wabbajack.Lib/StatusMessages/ManuallyDownloadFile.cs @@ -12,8 +12,8 @@ namespace Wabbajack.Lib public override string ShortDescription { get; } = string.Empty; public override string ExtendedDescription { get; } = string.Empty; - private TaskCompletionSource<(Uri, Common.Http.Client)> _tcs = new TaskCompletionSource<(Uri, Common.Http.Client)>(); - public Task<(Uri, Common.Http.Client)> Task => _tcs.Task; + private TaskCompletionSource<(Uri, Wabbajack.Lib.Http.Client)> _tcs = new TaskCompletionSource<(Uri, Wabbajack.Lib.Http.Client)>(); + public Task<(Uri, Wabbajack.Lib.Http.Client)> Task => _tcs.Task; private ManuallyDownloadFile(ManualDownloader.State state) { @@ -30,7 +30,7 @@ namespace Wabbajack.Lib _tcs.SetCanceled(); } - public void Resume(Uri s, Common.Http.Client client) + public void Resume(Uri s, Wabbajack.Lib.Http.Client client) { _tcs.SetResult((s, client)); } diff --git a/Wabbajack.Lib/Validation/ValidateModlist.cs b/Wabbajack.Lib/Validation/ValidateModlist.cs index 9dafa939..43ac949b 100644 --- a/Wabbajack.Lib/Validation/ValidateModlist.cs +++ b/Wabbajack.Lib/Validation/ValidateModlist.cs @@ -24,7 +24,7 @@ namespace Wabbajack.Lib.Validation public async Task LoadListsFromGithub() { - var client = new Common.Http.Client(); + var client = new Wabbajack.Lib.Http.Client(); Utils.Log("Loading server whitelist"); using (var response = await client.GetAsync(Consts.ServerWhitelistURL)) diff --git a/Wabbajack.Server.Test/ABuildServerSystemTest.cs b/Wabbajack.Server.Test/ABuildServerSystemTest.cs index 607d360d..55770ca4 100644 --- a/Wabbajack.Server.Test/ABuildServerSystemTest.cs +++ b/Wabbajack.Server.Test/ABuildServerSystemTest.cs @@ -7,7 +7,6 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.Extensions.Hosting; using Wabbajack.Common; -using Wabbajack.Common.Http; using Wabbajack.Common.StatusFeed; using Wabbajack.Lib; using Wabbajack.Lib.Downloaders; @@ -145,10 +144,10 @@ namespace Wabbajack.BuildServer.Test [Collection("ServerTests")] public class ABuildServerSystemTest : XunitContextBase, IClassFixture> { - protected readonly Client _client; + protected readonly Wabbajack.Lib.Http.Client _client; private readonly IDisposable _unsubMsgs; private readonly IDisposable _unsubErr; - protected Client _authedClient; + protected Wabbajack.Lib.Http.Client _authedClient; protected WorkQueue _queue; private Random _random; @@ -159,8 +158,8 @@ namespace Wabbajack.BuildServer.Test _unsubMsgs = Utils.LogMessages.OfType().Subscribe(onNext: msg => XunitContext.WriteLine(msg.ShortDescription)); _unsubErr = Utils.LogMessages.OfType().Subscribe(msg => XunitContext.WriteLine("ERROR: User intervention required: " + msg.ShortDescription)); - _client = new Client(); - _authedClient = new Client(); + _client = new Wabbajack.Lib.Http.Client(); + _authedClient = new Wabbajack.Lib.Http.Client(); Fixture = fixture.Deref(); _authedClient.Headers.Add(("x-api-key", Fixture.APIKey)); AuthorAPI.ApiKeyOverride = Fixture.APIKey; diff --git a/Wabbajack.Server.Test/MetricsTests.cs b/Wabbajack.Server.Test/MetricsTests.cs index 22df2628..9a80ee81 100644 --- a/Wabbajack.Server.Test/MetricsTests.cs +++ b/Wabbajack.Server.Test/MetricsTests.cs @@ -1,7 +1,7 @@ using System; using System.Threading.Tasks; using Dapper; -using Wabbajack.Common; +using Wabbajack.Lib; using Wabbajack.Server.DataLayer; using Wabbajack.Server.DTOs; using Xunit; diff --git a/Wabbajack.Server/Services/DiscordWebHook.cs b/Wabbajack.Server/Services/DiscordWebHook.cs index 2172b44d..1c7b794b 100644 --- a/Wabbajack.Server/Services/DiscordWebHook.cs +++ b/Wabbajack.Server/Services/DiscordWebHook.cs @@ -49,7 +49,7 @@ namespace Wabbajack.Server.Services }; if (url == null) return; - var client = new Common.Http.Client(); + var client = new Wabbajack.Lib.Http.Client(); await client.PostAsync(url, new StringContent(message.ToJson(true), Encoding.UTF8, "application/json")); } catch (Exception ex) diff --git a/Wabbajack/View Models/Settings/LoginManagerVM.cs b/Wabbajack/View Models/Settings/LoginManagerVM.cs index fa0a03ee..66af9521 100644 --- a/Wabbajack/View Models/Settings/LoginManagerVM.cs +++ b/Wabbajack/View Models/Settings/LoginManagerVM.cs @@ -84,7 +84,7 @@ namespace Wabbajack { if (Login.IconUri == null) return; - using var img = await new Common.Http.Client().GetAsync(Login.IconUri, errorsAsExceptions:false); + using var img = await new Wabbajack.Lib.Http.Client().GetAsync(Login.IconUri, errorsAsExceptions:false); if (!img.IsSuccessStatusCode) return; var icoData = new MemoryStream(await img.Content.ReadAsByteArrayAsync());