Revert "Merge pull request #45 from bluepilledgreat/reuse-httpclient"

This reverts commit c6410eb407, reversing
changes made to 5b94b2741a.
This commit is contained in:
pizzaboxer 2022-11-14 17:40:00 +00:00
parent c6410eb407
commit 7295a8eec7
5 changed files with 30 additions and 24 deletions

View File

@ -1,7 +1,6 @@
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.IO.Compression; using System.IO.Compression;
using System.Net;
using System.Net.Http; using System.Net.Http;
using Microsoft.Win32; using Microsoft.Win32;
@ -67,7 +66,7 @@ namespace Bloxstrap
"By default, two mod presets are provided for restoring the old death\n" + "By default, two mod presets are provided for restoring the old death\n" +
"sound and the old mouse cursor.\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; private string? LaunchCommandLine;

View File

@ -104,7 +104,9 @@ namespace Bloxstrap.Helpers
string baseUrl = BuildBaseUrl(channel); string baseUrl = BuildBaseUrl(channel);
string lastDeploy = ""; string lastDeploy = "";
string deployHistory = await Bootstrapper.Client.GetStringAsync($"{baseUrl}/DeployHistory.txt"); using (HttpClient client = new())
{
string deployHistory = await client.GetStringAsync($"{baseUrl}/DeployHistory.txt");
using (StringReader reader = new(deployHistory)) using (StringReader reader = new(deployHistory))
{ {
@ -116,6 +118,7 @@ namespace Bloxstrap.Helpers
lastDeploy = line; lastDeploy = line;
} }
} }
}
if (String.IsNullOrEmpty(lastDeploy)) if (String.IsNullOrEmpty(lastDeploy))
throw new Exception($"Could not get latest deploy for channel {channel}"); throw new Exception($"Could not get latest deploy for channel {channel}");

View File

@ -97,13 +97,16 @@ namespace Bloxstrap.Helpers.Integrations
Debug.WriteLine("Installing/Updating rbxfpsunlocker..."); Debug.WriteLine("Installing/Updating rbxfpsunlocker...");
byte[] bytes = await Bootstrapper.Client.GetByteArrayAsync(downloadUrl); using (HttpClient client = new())
{
byte[] bytes = await client.GetByteArrayAsync(downloadUrl);
using (MemoryStream zipStream = new(bytes)) using (MemoryStream zipStream = new(bytes))
{ {
ZipArchive zip = new(zipStream); ZipArchive zip = new(zipStream);
zip.ExtractToDirectory(folderLocation, true); zip.ExtractToDirectory(folderLocation, true);
} }
}
if (!File.Exists(settingsLocation)) if (!File.Exists(settingsLocation))
{ {

View File

@ -75,8 +75,11 @@ namespace Bloxstrap.Helpers.RSMM
string pkgManifestUrl = $"{DeployManager.BaseUrl}/{versionGuid}-rbxPkgManifest.txt"; string pkgManifestUrl = $"{DeployManager.BaseUrl}/{versionGuid}-rbxPkgManifest.txt";
string pkgManifestData; string pkgManifestData;
var getData = Bootstrapper.Client.GetStringAsync(pkgManifestUrl); using (HttpClient http = new())
{
var getData = http.GetStringAsync(pkgManifestUrl);
pkgManifestData = await getData.ConfigureAwait(false); pkgManifestData = await getData.ConfigureAwait(false);
}
return new PackageManifest(pkgManifestData); return new PackageManifest(pkgManifestData);
} }

View File

@ -15,16 +15,14 @@ namespace Bloxstrap.Helpers
public static async Task<T?> GetJson<T>(string url) public static async Task<T?> GetJson<T>(string url)
{ {
var request = await Bootstrapper.Client.SendAsync(new() using (HttpClient client = new())
{ {
RequestUri = new Uri(url), client.DefaultRequestHeaders.Add("User-Agent", Program.ProjectRepository);
Headers = {
{ "User-Agent", Program.ProjectRepository } string json = await client.GetStringAsync(url);
}
});
var json = await request.Content.ReadAsStringAsync();
return JsonSerializer.Deserialize<T>(json); return JsonSerializer.Deserialize<T>(json);
} }
}
public static string MD5File(string filename) public static string MD5File(string filename)
{ {