diff --git a/Bloxstrap/Bootstrapper.cs b/Bloxstrap/Bootstrapper.cs index 883f760..3c2d3a9 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"; - private static readonly HttpClient Client = new(); + public static readonly HttpClient Client = new(new HttpClientHandler { AutomaticDecompression = DecompressionMethods.All }); private string? LaunchCommandLine; diff --git a/Bloxstrap/Helpers/DeployManager.cs b/Bloxstrap/Helpers/DeployManager.cs index d794dbd..8f3d549 100644 --- a/Bloxstrap/Helpers/DeployManager.cs +++ b/Bloxstrap/Helpers/DeployManager.cs @@ -104,19 +104,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..9f260d8 100644 --- a/Bloxstrap/Helpers/Utilities.cs +++ b/Bloxstrap/Helpers/Utilities.cs @@ -15,13 +15,15 @@ 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); - } + RequestUri = new Uri(url), + Headers = { + { "User-Agent", Program.ProjectRepository } + } + }); + var json = await request.Content.ReadAsStringAsync(); + return JsonSerializer.Deserialize(json); } public static string MD5File(string filename)