Skip to content

Commit

Permalink
HttpClient - Use singleton and enable gzip
Browse files Browse the repository at this point in the history
Rework of #45 as it kept crashing on release
  • Loading branch information
pizzaboxer committed Nov 14, 2022
1 parent a39ce6b commit 170c6e5
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 332 deletions.
8 changes: 3 additions & 5 deletions Bloxstrap/Bootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Bloxstrap.Helpers;
using Bloxstrap.Helpers.Integrations;
using Bloxstrap.Helpers.RSMM;
using System.Net;

namespace Bloxstrap
{
Expand Down Expand Up @@ -66,8 +67,6 @@ public partial class Bootstrapper
"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();

private string? LaunchCommandLine;

private string VersionGuid = null!;
Expand All @@ -87,7 +86,6 @@ public Bootstrapper(string? launchCommandLine = null)
{
LaunchCommandLine = launchCommandLine;
FreshInstall = String.IsNullOrEmpty(Program.Settings.VersionGuid);
Client.Timeout = TimeSpan.FromMinutes(10);
}

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

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

var response = await Client.GetAsync(packageUrl);
var response = await Program.HttpClient.GetAsync(packageUrl);

if (CancelFired)
return;
Expand Down
2 changes: 1 addition & 1 deletion Bloxstrap/Dialogs/Preferences.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<GroupBox Grid.Column="0" Header="Discord Rich Presence" Margin="10,10,5,5">
<StackPanel VerticalAlignment="Center">
<CheckBox x:Name="CheckBoxDRPEnabled" Content=" Show game activity" Margin="5" VerticalAlignment="Top" IsChecked="{Binding DRPEnabled, Mode=TwoWay}" />
<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}" />
<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}" />
</StackPanel>
</GroupBox>
<GroupBox Grid.Column="1" Header="FPS Unlocking" Margin="5,10,10,5">
Expand Down
31 changes: 14 additions & 17 deletions Bloxstrap/Helpers/DeployManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,19 +104,16 @@ public static async Task<VersionDeploy> GetLastDeploy(string channel)
string baseUrl = BuildBaseUrl(channel);
string lastDeploy = "";

using (HttpClient client = new())
string deployHistory = await Program.HttpClient.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;
}
}

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

lastDeploy = lastDeploy[18..]; // 'version-29fb7cdd06e84001 at 8/23/2022 2:07:27 PM, file version: 0, 542, 100, 5420251, git hash: b98d6b2bea36fa2161f48cca979fb620bb0c24fd ...'
string versionGuid = lastDeploy[..lastDeploy.IndexOf(" at")]; // 'version-29fb7cdd06e84001'

lastDeploy = lastDeploy[(versionGuid.Length + 4)..]; // '8/23/2022 2:07:27 PM, file version: 0, 542, 100, 5420251, git hash: b98d6b2bea36fa2161f48cca979fb620bb0c24fd ...'
string strTimestamp = lastDeploy[..lastDeploy.IndexOf(", file")]; // '8/23/2022 2:07:27 PM'

lastDeploy = lastDeploy[(strTimestamp.Length + 16)..]; // '0, 542, 100, 5420251, git hash: b98d6b2bea36fa2161f48cca979fb620bb0c24fd ...'
string fileVersion = "";

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

return new VersionDeploy
{
VersionGuid = versionGuid,
Timestamp = dtTimestamp,
FileVersion = fileVersion
return new VersionDeploy
{
VersionGuid = versionGuid,
Timestamp = dtTimestamp,
FileVersion = fileVersion
};
}
}
Expand Down
13 changes: 5 additions & 8 deletions Bloxstrap/Helpers/Integrations/RbxFpsUnlocker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,12 @@ public static async Task CheckInstall()

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

using (HttpClient client = new())
{
byte[] bytes = await client.GetByteArrayAsync(downloadUrl);
byte[] bytes = await Program.HttpClient.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))
Expand Down
7 changes: 2 additions & 5 deletions Bloxstrap/Helpers/RSMM/PackageManifest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,8 @@ public static async Task<PackageManifest> Get(string versionGuid)
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 = Program.HttpClient.GetStringAsync(pkgManifestUrl);
pkgManifestData = await getData.ConfigureAwait(false);

return new PackageManifest(pkgManifestData);
}
Expand Down
Loading

0 comments on commit 170c6e5

Please sign in to comment.