reuse httpclient

This commit is contained in:
Matthew Brown 2022-11-12 22:50:27 +00:00
parent 01a9cff6e1
commit 5fdb341918
5 changed files with 22 additions and 30 deletions

View File

@ -66,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";
private static readonly HttpClient Client = new(); public static readonly HttpClient Client = new();
private string? LaunchCommandLine; private string? LaunchCommandLine;

View File

@ -102,19 +102,16 @@ namespace Bloxstrap.Helpers
string baseUrl = BuildBaseUrl(channel); string baseUrl = BuildBaseUrl(channel);
string lastDeploy = ""; 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; if (line.Contains("WindowsPlayer"))
lastDeploy = line;
while ((line = await reader.ReadLineAsync()) is not null)
{
if (line.Contains("WindowsPlayer"))
lastDeploy = line;
}
} }
} }

View File

@ -97,15 +97,12 @@ namespace Bloxstrap.Helpers.Integrations
Debug.WriteLine("Installing/Updating rbxfpsunlocker..."); Debug.WriteLine("Installing/Updating rbxfpsunlocker...");
using (HttpClient client = new()) byte[] bytes = await Bootstrapper.Client.GetByteArrayAsync(downloadUrl);
{
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,11 +75,8 @@ namespace Bloxstrap.Helpers.RSMM
string pkgManifestUrl = $"{DeployManager.BaseUrl}/{versionGuid}-rbxPkgManifest.txt"; string pkgManifestUrl = $"{DeployManager.BaseUrl}/{versionGuid}-rbxPkgManifest.txt";
string pkgManifestData; string pkgManifestData;
using (HttpClient http = new()) var getData = Bootstrapper.Client.GetStringAsync(pkgManifestUrl);
{ pkgManifestData = await getData.ConfigureAwait(false);
var getData = http.GetStringAsync(pkgManifestUrl);
pkgManifestData = await getData.ConfigureAwait(false);
}
return new PackageManifest(pkgManifestData); return new PackageManifest(pkgManifestData);
} }

View File

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