Skip to content

Commit 170c6e5

Browse files
committed
HttpClient - Use singleton and enable gzip
Rework of #45 as it kept crashing on release
1 parent a39ce6b commit 170c6e5

File tree

9 files changed

+34
-332
lines changed

9 files changed

+34
-332
lines changed

Bloxstrap/Bootstrapper.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using Bloxstrap.Helpers;
1111
using Bloxstrap.Helpers.Integrations;
1212
using Bloxstrap.Helpers.RSMM;
13+
using System.Net;
1314

1415
namespace Bloxstrap
1516
{
@@ -66,8 +67,6 @@ public partial class Bootstrapper
6667
"By default, two mod presets are provided for restoring the old death\n" +
6768
"sound and the old mouse cursor.\n";
6869

69-
private static readonly HttpClient Client = new();
70-
7170
private string? LaunchCommandLine;
7271

7372
private string VersionGuid = null!;
@@ -87,7 +86,6 @@ public Bootstrapper(string? launchCommandLine = null)
8786
{
8887
LaunchCommandLine = launchCommandLine;
8988
FreshInstall = String.IsNullOrEmpty(Program.Settings.VersionGuid);
90-
Client.Timeout = TimeSpan.FromMinutes(10);
9189
}
9290

9391
// this is called from BootstrapperStyleForm.SetupDialog()
@@ -133,7 +131,7 @@ private async Task CheckLatestVersion()
133131
{
134132
Dialog.Message = "Connecting to Roblox...";
135133

136-
VersionGuid = await Client.GetStringAsync($"{DeployManager.BaseUrl}/version");
134+
VersionGuid = await Program.HttpClient.GetStringAsync($"{DeployManager.BaseUrl}/version");
137135
VersionFolder = Path.Combine(Directories.Versions, VersionGuid);
138136
VersionPackageManifest = await PackageManifest.Get(VersionGuid);
139137
}
@@ -611,7 +609,7 @@ private async void DownloadPackage(Package package)
611609
{
612610
Debug.WriteLine($"Downloading {package.Name}...");
613611

614-
var response = await Client.GetAsync(packageUrl);
612+
var response = await Program.HttpClient.GetAsync(packageUrl);
615613

616614
if (CancelFired)
617615
return;

Bloxstrap/Dialogs/Preferences.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
<GroupBox Grid.Column="0" Header="Discord Rich Presence" Margin="10,10,5,5">
3535
<StackPanel VerticalAlignment="Center">
3636
<CheckBox x:Name="CheckBoxDRPEnabled" Content=" Show game activity" Margin="5" VerticalAlignment="Top" IsChecked="{Binding DRPEnabled, Mode=TwoWay}" />
37-
<CheckBox x:Name="CheckBoxDRPButtons" Content=" Allow others to join" Margin="5" VerticalAlignment="Top" IsEnabled="{Binding IsChecked, ElementName=CheckBoxDRPEnabled, Mode=OneWay}" IsChecked="{Binding DRPButtons, Mode=TwoWay}" />
37+
<CheckBox x:Name="CheckBoxDRPButtons" Content=" Allow people to join" Margin="5" VerticalAlignment="Top" IsEnabled="{Binding IsChecked, ElementName=CheckBoxDRPEnabled, Mode=OneWay}" IsChecked="{Binding DRPButtons, Mode=TwoWay}" />
3838
</StackPanel>
3939
</GroupBox>
4040
<GroupBox Grid.Column="1" Header="FPS Unlocking" Margin="5,10,10,5">

Bloxstrap/Helpers/DeployManager.cs

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -104,19 +104,16 @@ public static async Task<VersionDeploy> GetLastDeploy(string channel)
104104
string baseUrl = BuildBaseUrl(channel);
105105
string lastDeploy = "";
106106

107-
using (HttpClient client = new())
107+
string deployHistory = await Program.HttpClient.GetStringAsync($"{baseUrl}/DeployHistory.txt");
108+
109+
using (StringReader reader = new(deployHistory))
108110
{
109-
string deployHistory = await client.GetStringAsync($"{baseUrl}/DeployHistory.txt");
111+
string? line;
110112

111-
using (StringReader reader = new(deployHistory))
113+
while ((line = await reader.ReadLineAsync()) is not null)
112114
{
113-
string? line;
114-
115-
while ((line = await reader.ReadLineAsync()) is not null)
116-
{
117-
if (line.Contains("WindowsPlayer"))
118-
lastDeploy = line;
119-
}
115+
if (line.Contains("WindowsPlayer"))
116+
lastDeploy = line;
120117
}
121118
}
122119

@@ -132,10 +129,10 @@ public static async Task<VersionDeploy> GetLastDeploy(string channel)
132129

133130
lastDeploy = lastDeploy[18..]; // 'version-29fb7cdd06e84001 at 8/23/2022 2:07:27 PM, file version: 0, 542, 100, 5420251, git hash: b98d6b2bea36fa2161f48cca979fb620bb0c24fd ...'
134131
string versionGuid = lastDeploy[..lastDeploy.IndexOf(" at")]; // 'version-29fb7cdd06e84001'
135-
132+
136133
lastDeploy = lastDeploy[(versionGuid.Length + 4)..]; // '8/23/2022 2:07:27 PM, file version: 0, 542, 100, 5420251, git hash: b98d6b2bea36fa2161f48cca979fb620bb0c24fd ...'
137134
string strTimestamp = lastDeploy[..lastDeploy.IndexOf(", file")]; // '8/23/2022 2:07:27 PM'
138-
135+
139136
lastDeploy = lastDeploy[(strTimestamp.Length + 16)..]; // '0, 542, 100, 5420251, git hash: b98d6b2bea36fa2161f48cca979fb620bb0c24fd ...'
140137
string fileVersion = "";
141138

@@ -157,11 +154,11 @@ public static async Task<VersionDeploy> GetLastDeploy(string channel)
157154
// convert to traditional version format
158155
fileVersion = fileVersion.Replace(" ", "").Replace(',', '.');
159156

160-
return new VersionDeploy
161-
{
162-
VersionGuid = versionGuid,
163-
Timestamp = dtTimestamp,
164-
FileVersion = fileVersion
157+
return new VersionDeploy
158+
{
159+
VersionGuid = versionGuid,
160+
Timestamp = dtTimestamp,
161+
FileVersion = fileVersion
165162
};
166163
}
167164
}

Bloxstrap/Helpers/Integrations/RbxFpsUnlocker.cs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,12 @@ public static async Task CheckInstall()
9191

9292
Debug.WriteLine("Installing/Updating rbxfpsunlocker...");
9393

94-
using (HttpClient client = new())
95-
{
96-
byte[] bytes = await client.GetByteArrayAsync(downloadUrl);
94+
byte[] bytes = await Program.HttpClient.GetByteArrayAsync(downloadUrl);
9795

98-
using (MemoryStream zipStream = new(bytes))
99-
{
100-
ZipArchive zip = new(zipStream);
101-
zip.ExtractToDirectory(folderLocation, true);
102-
}
96+
using (MemoryStream zipStream = new(bytes))
97+
{
98+
ZipArchive zip = new(zipStream);
99+
zip.ExtractToDirectory(folderLocation, true);
103100
}
104101

105102
if (!File.Exists(settingsLocation))

Bloxstrap/Helpers/RSMM/PackageManifest.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,8 @@ public static async Task<PackageManifest> Get(string versionGuid)
7575
string pkgManifestUrl = $"{DeployManager.BaseUrl}/{versionGuid}-rbxPkgManifest.txt";
7676
string pkgManifestData;
7777

78-
using (HttpClient http = new())
79-
{
80-
var getData = http.GetStringAsync(pkgManifestUrl);
81-
pkgManifestData = await getData.ConfigureAwait(false);
82-
}
78+
var getData = Program.HttpClient.GetStringAsync(pkgManifestUrl);
79+
pkgManifestData = await getData.ConfigureAwait(false);
8380

8481
return new PackageManifest(pkgManifestData);
8582
}

0 commit comments

Comments
 (0)