From 5fdb3419185c42f71a4b24c5608dfb8824c3f914 Mon Sep 17 00:00:00 2001 From: Matthew Brown <97983689+bluepilledgreat@users.noreply.github.com> Date: Sat, 12 Nov 2022 22:50:27 +0000 Subject: [PATCH 1/3] reuse httpclient --- Bloxstrap/Bootstrapper.cs | 2 +- Bloxstrap/Helpers/DeployManager.cs | 17 +++++++---------- .../Helpers/Integrations/RbxFpsUnlocker.cs | 13 +++++-------- Bloxstrap/Helpers/RSMM/PackageManifest.cs | 7 ++----- Bloxstrap/Helpers/Utilities.cs | 13 +++++++------ 5 files changed, 22 insertions(+), 30 deletions(-) diff --git a/Bloxstrap/Bootstrapper.cs b/Bloxstrap/Bootstrapper.cs index 15ee22e..1f75481 100644 --- a/Bloxstrap/Bootstrapper.cs +++ b/Bloxstrap/Bootstrapper.cs @@ -66,7 +66,7 @@ namespace Bloxstrap "By default, two mod presets are provided for restoring the old death\n" + "sound and the old mouse cursor.\n"; - private static readonly HttpClient Client = new(); + public static readonly HttpClient Client = new(); private string? LaunchCommandLine; diff --git a/Bloxstrap/Helpers/DeployManager.cs b/Bloxstrap/Helpers/DeployManager.cs index b537bec..6d2c971 100644 --- a/Bloxstrap/Helpers/DeployManager.cs +++ b/Bloxstrap/Helpers/DeployManager.cs @@ -102,19 +102,16 @@ namespace Bloxstrap.Helpers string baseUrl = BuildBaseUrl(channel); string lastDeploy = ""; - using (HttpClient client = new()) + string deployHistory = await Bootstrapper.Client.GetStringAsync($"{baseUrl}/DeployHistory.txt"); + + using (StringReader reader = new(deployHistory)) { - string deployHistory = await client.GetStringAsync($"{baseUrl}/DeployHistory.txt"); + string? line; - using (StringReader reader = new(deployHistory)) + while ((line = await reader.ReadLineAsync()) is not null) { - string? line; - - while ((line = await reader.ReadLineAsync()) is not null) - { - if (line.Contains("WindowsPlayer")) - lastDeploy = line; - } + if (line.Contains("WindowsPlayer")) + lastDeploy = line; } } diff --git a/Bloxstrap/Helpers/Integrations/RbxFpsUnlocker.cs b/Bloxstrap/Helpers/Integrations/RbxFpsUnlocker.cs index 2139872..66b362d 100644 --- a/Bloxstrap/Helpers/Integrations/RbxFpsUnlocker.cs +++ b/Bloxstrap/Helpers/Integrations/RbxFpsUnlocker.cs @@ -97,15 +97,12 @@ namespace Bloxstrap.Helpers.Integrations Debug.WriteLine("Installing/Updating rbxfpsunlocker..."); - using (HttpClient client = new()) - { - byte[] bytes = await client.GetByteArrayAsync(downloadUrl); + byte[] bytes = await Bootstrapper.Client.GetByteArrayAsync(downloadUrl); - using (MemoryStream zipStream = new(bytes)) - { - ZipArchive zip = new(zipStream); - zip.ExtractToDirectory(folderLocation, true); - } + using (MemoryStream zipStream = new(bytes)) + { + ZipArchive zip = new(zipStream); + zip.ExtractToDirectory(folderLocation, true); } if (!File.Exists(settingsLocation)) diff --git a/Bloxstrap/Helpers/RSMM/PackageManifest.cs b/Bloxstrap/Helpers/RSMM/PackageManifest.cs index bacfabd..51c6a40 100644 --- a/Bloxstrap/Helpers/RSMM/PackageManifest.cs +++ b/Bloxstrap/Helpers/RSMM/PackageManifest.cs @@ -75,11 +75,8 @@ namespace Bloxstrap.Helpers.RSMM string pkgManifestUrl = $"{DeployManager.BaseUrl}/{versionGuid}-rbxPkgManifest.txt"; string pkgManifestData; - using (HttpClient http = new()) - { - var getData = http.GetStringAsync(pkgManifestUrl); - pkgManifestData = await getData.ConfigureAwait(false); - } + var getData = Bootstrapper.Client.GetStringAsync(pkgManifestUrl); + pkgManifestData = await getData.ConfigureAwait(false); return new PackageManifest(pkgManifestData); } diff --git a/Bloxstrap/Helpers/Utilities.cs b/Bloxstrap/Helpers/Utilities.cs index 22a60d4..86d1b37 100644 --- a/Bloxstrap/Helpers/Utilities.cs +++ b/Bloxstrap/Helpers/Utilities.cs @@ -15,13 +15,14 @@ namespace Bloxstrap.Helpers public static async Task GetJson(string url) { - using (HttpClient client = new()) + var request = await Bootstrapper.Client.SendAsync(new() { - client.DefaultRequestHeaders.Add("User-Agent", Program.ProjectRepository); - - string json = await client.GetStringAsync(url); - return JsonSerializer.Deserialize(json); - } + Headers = { + { "User-Agent", Program.ProjectRepository } + } + }); + var json = await request.Content.ReadAsStringAsync(); + return JsonSerializer.Deserialize(json); } public static string MD5File(string filename) From bdcd58f4cbed2a74c09555d4e8c400366a4ca91b Mon Sep 17 00:00:00 2001 From: Matthew Brown <97983689+bluepilledgreat@users.noreply.github.com> Date: Sat, 12 Nov 2022 22:58:13 +0000 Subject: [PATCH 2/3] enable httpclient decompression --- Bloxstrap/Bootstrapper.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Bloxstrap/Bootstrapper.cs b/Bloxstrap/Bootstrapper.cs index 1f75481..b660fcf 100644 --- a/Bloxstrap/Bootstrapper.cs +++ b/Bloxstrap/Bootstrapper.cs @@ -1,6 +1,7 @@ using System.Diagnostics; using System.IO; using System.IO.Compression; +using System.Net; using System.Net.Http; using Microsoft.Win32; @@ -66,7 +67,7 @@ namespace Bloxstrap "By default, two mod presets are provided for restoring the old death\n" + "sound and the old mouse cursor.\n"; - public static readonly HttpClient Client = new(); + public static readonly HttpClient Client = new(new HttpClientHandler { AutomaticDecompression = DecompressionMethods.All }); private string? LaunchCommandLine; From 5d4fc39475482494c9368f6ec179d9ef1cb31cde Mon Sep 17 00:00:00 2001 From: Matthew Brown <97983689+bluepilledgreat@users.noreply.github.com> Date: Sun, 13 Nov 2022 09:47:02 +0000 Subject: [PATCH 3/3] forgot uri --- Bloxstrap/Helpers/Utilities.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Bloxstrap/Helpers/Utilities.cs b/Bloxstrap/Helpers/Utilities.cs index 86d1b37..9f260d8 100644 --- a/Bloxstrap/Helpers/Utilities.cs +++ b/Bloxstrap/Helpers/Utilities.cs @@ -17,6 +17,7 @@ namespace Bloxstrap.Helpers { var request = await Bootstrapper.Client.SendAsync(new() { + RequestUri = new Uri(url), Headers = { { "User-Agent", Program.ProjectRepository } }