From 7295a8eec7c4ac81ae8cca96b58ca84ded3441eb Mon Sep 17 00:00:00 2001 From: pizzaboxer <41478239+pizzaboxer@users.noreply.github.com> Date: Mon, 14 Nov 2022 17:40:00 +0000 Subject: [PATCH] Revert "Merge pull request #45 from bluepilledgreat/reuse-httpclient" This reverts commit c6410eb4074d0ffc77a9cc46cc5c2e8bdbf74e54, reversing changes made to 5b94b2741a6fe9ca3257ec807789db3ad960c802. --- Bloxstrap/Bootstrapper.cs | 3 +-- Bloxstrap/Helpers/DeployManager.cs | 17 ++++++++++------- .../Helpers/Integrations/RbxFpsUnlocker.cs | 13 ++++++++----- Bloxstrap/Helpers/RSMM/PackageManifest.cs | 7 +++++-- Bloxstrap/Helpers/Utilities.cs | 14 ++++++-------- 5 files changed, 30 insertions(+), 24 deletions(-) diff --git a/Bloxstrap/Bootstrapper.cs b/Bloxstrap/Bootstrapper.cs index 3c2d3a9..883f760 100644 --- a/Bloxstrap/Bootstrapper.cs +++ b/Bloxstrap/Bootstrapper.cs @@ -1,7 +1,6 @@ using System.Diagnostics; using System.IO; using System.IO.Compression; -using System.Net; using System.Net.Http; using Microsoft.Win32; @@ -67,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"; - public static readonly HttpClient Client = new(new HttpClientHandler { AutomaticDecompression = DecompressionMethods.All }); + private static readonly HttpClient Client = new(); private string? LaunchCommandLine; diff --git a/Bloxstrap/Helpers/DeployManager.cs b/Bloxstrap/Helpers/DeployManager.cs index 8f3d549..d794dbd 100644 --- a/Bloxstrap/Helpers/DeployManager.cs +++ b/Bloxstrap/Helpers/DeployManager.cs @@ -104,16 +104,19 @@ namespace Bloxstrap.Helpers string baseUrl = BuildBaseUrl(channel); string lastDeploy = ""; - string deployHistory = await Bootstrapper.Client.GetStringAsync($"{baseUrl}/DeployHistory.txt"); - - using (StringReader reader = new(deployHistory)) + using (HttpClient client = new()) { - string? line; + string deployHistory = await client.GetStringAsync($"{baseUrl}/DeployHistory.txt"); - while ((line = await reader.ReadLineAsync()) is not null) + using (StringReader reader = new(deployHistory)) { - if (line.Contains("WindowsPlayer")) - lastDeploy = line; + string? line; + + while ((line = await reader.ReadLineAsync()) is not null) + { + if (line.Contains("WindowsPlayer")) + lastDeploy = line; + } } } diff --git a/Bloxstrap/Helpers/Integrations/RbxFpsUnlocker.cs b/Bloxstrap/Helpers/Integrations/RbxFpsUnlocker.cs index 66b362d..2139872 100644 --- a/Bloxstrap/Helpers/Integrations/RbxFpsUnlocker.cs +++ b/Bloxstrap/Helpers/Integrations/RbxFpsUnlocker.cs @@ -97,12 +97,15 @@ namespace Bloxstrap.Helpers.Integrations Debug.WriteLine("Installing/Updating rbxfpsunlocker..."); - byte[] bytes = await Bootstrapper.Client.GetByteArrayAsync(downloadUrl); - - using (MemoryStream zipStream = new(bytes)) + using (HttpClient client = new()) { - ZipArchive zip = new(zipStream); - zip.ExtractToDirectory(folderLocation, true); + byte[] bytes = await client.GetByteArrayAsync(downloadUrl); + + 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 51c6a40..bacfabd 100644 --- a/Bloxstrap/Helpers/RSMM/PackageManifest.cs +++ b/Bloxstrap/Helpers/RSMM/PackageManifest.cs @@ -75,8 +75,11 @@ namespace Bloxstrap.Helpers.RSMM string pkgManifestUrl = $"{DeployManager.BaseUrl}/{versionGuid}-rbxPkgManifest.txt"; string pkgManifestData; - var getData = Bootstrapper.Client.GetStringAsync(pkgManifestUrl); - pkgManifestData = await getData.ConfigureAwait(false); + using (HttpClient http = new()) + { + var getData = http.GetStringAsync(pkgManifestUrl); + pkgManifestData = await getData.ConfigureAwait(false); + } return new PackageManifest(pkgManifestData); } diff --git a/Bloxstrap/Helpers/Utilities.cs b/Bloxstrap/Helpers/Utilities.cs index 9f260d8..22a60d4 100644 --- a/Bloxstrap/Helpers/Utilities.cs +++ b/Bloxstrap/Helpers/Utilities.cs @@ -15,15 +15,13 @@ namespace Bloxstrap.Helpers public static async Task GetJson(string url) { - var request = await Bootstrapper.Client.SendAsync(new() + using (HttpClient client = new()) { - RequestUri = new Uri(url), - Headers = { - { "User-Agent", Program.ProjectRepository } - } - }); - var json = await request.Content.ReadAsStringAsync(); - return JsonSerializer.Deserialize(json); + client.DefaultRequestHeaders.Add("User-Agent", Program.ProjectRepository); + + string json = await client.GetStringAsync(url); + return JsonSerializer.Deserialize(json); + } } public static string MD5File(string filename)