From d76d7b42e4e1774a0416c933aecea871690d0335 Mon Sep 17 00:00:00 2001 From: pizzaboxer <41478239+pizzaboxer@users.noreply.github.com> Date: Thu, 16 Feb 2023 10:55:10 +0000 Subject: [PATCH] Rework DeployManager --- Bloxstrap/App.xaml.cs | 4 +- Bloxstrap/Bootstrapper.cs | 4 +- Bloxstrap/Helpers/DeployManager.cs | 37 ++++++++++++------- Bloxstrap/Helpers/RSMM/PackageManifest.cs | 2 +- Bloxstrap/ViewModels/InstallationViewModel.cs | 5 ++- 5 files changed, 31 insertions(+), 21 deletions(-) diff --git a/Bloxstrap/App.xaml.cs b/Bloxstrap/App.xaml.cs index 0a22e98..47d8a29 100644 --- a/Bloxstrap/App.xaml.cs +++ b/Bloxstrap/App.xaml.cs @@ -38,11 +38,11 @@ namespace Bloxstrap public static bool IsMenuLaunch { get; private set; } = false; public static string[] LaunchArgs { get; private set; } = null!; - public static string Version = Assembly.GetExecutingAssembly().GetName().Version!.ToString()[..^2]; // singletons public static readonly Logger Logger = new(); + public static readonly DeployManager DeployManager = new(); public static readonly JsonManager Settings = new(); public static readonly JsonManager State = new(); public static readonly HttpClient HttpClient = new(new HttpClientHandler { AutomaticDecompression = DecompressionMethods.All }); @@ -207,7 +207,7 @@ namespace Bloxstrap if (!IsFirstRun) ShouldSaveConfigs = true; - DeployManager.Channel = Settings.Prop.Channel; + DeployManager.SetChannel(Settings.Prop.Channel); // start bootstrapper and show the bootstrapper modal if we're not running silently Bootstrapper bootstrapper = new Bootstrapper(commandLine); diff --git a/Bloxstrap/Bootstrapper.cs b/Bloxstrap/Bootstrapper.cs index 8b53e25..38e1620 100644 --- a/Bloxstrap/Bootstrapper.cs +++ b/Bloxstrap/Bootstrapper.cs @@ -193,7 +193,7 @@ namespace Bloxstrap { SetStatus("Connecting to Roblox..."); - ClientVersion clientVersion = await DeployManager.GetLastDeploy(App.Settings.Prop.Channel); + ClientVersion clientVersion = await App.DeployManager.GetLastDeploy(); _versionGuid = clientVersion.VersionGuid; _versionFolder = Path.Combine(Directories.Versions, _versionGuid); _versionPackageManifest = await PackageManifest.Get(_versionGuid); @@ -780,7 +780,7 @@ namespace Bloxstrap if (_cancelFired) return; - string packageUrl = $"{DeployManager.BaseUrl}/{_versionGuid}-{package.Name}"; + string packageUrl = $"{App.DeployManager.BaseUrl}/{_versionGuid}-{package.Name}"; string packageLocation = Path.Combine(Directories.Downloads, package.Signature); string robloxPackageLocation = Path.Combine(Directories.LocalAppData, "Roblox", "Downloads", package.Signature); diff --git a/Bloxstrap/Helpers/DeployManager.cs b/Bloxstrap/Helpers/DeployManager.cs index e4b751b..40d0165 100644 --- a/Bloxstrap/Helpers/DeployManager.cs +++ b/Bloxstrap/Helpers/DeployManager.cs @@ -6,6 +6,7 @@ using System.Text.Json; using System.Threading.Tasks; using Bloxstrap.Models; +using DiscordRPC; namespace Bloxstrap.Helpers { @@ -13,13 +14,13 @@ namespace Bloxstrap.Helpers { #region Properties public const string DefaultBaseUrl = "https://setup.rbxcdn.com"; - public static string BaseUrl { get; private set; } = DefaultBaseUrl; - public const string DefaultChannel = "LIVE"; - public static string Channel { set => BaseUrl = BuildBaseUrl(value); } + + public string BaseUrl { get; private set; } = DefaultBaseUrl; + public string Channel { get; private set; } = DefaultChannel; // basically any channel that has had a deploy within the past month with a windowsplayer build - public static readonly List ChannelsAbstracted = new List() + public static readonly List ChannelsAbstracted = new() { "LIVE", "ZNext", @@ -28,7 +29,7 @@ namespace Bloxstrap.Helpers }; // why not? - public static readonly List ChannelsAll = new List() + public static readonly List ChannelsAll = new() { "LIVE", "ZAvatarTeam", @@ -50,13 +51,22 @@ namespace Bloxstrap.Helpers }; #endregion - private static string BuildBaseUrl(string channel) => channel == DefaultChannel ? DefaultBaseUrl : $"{DefaultBaseUrl}/channel/{channel.ToLower()}"; - - public static async Task GetLastDeploy(string channel, bool timestamp = false) + public void SetChannel(string channel) { - App.Logger.WriteLine($"[DeployManager::GetLastDeploy] Getting deploy info for channel {channel} (timestamp={timestamp})"); + if (Channel == channel) + return; - HttpResponseMessage deployInfoResponse = await App.HttpClient.GetAsync($"https://clientsettings.roblox.com/v2/client-version/WindowsPlayer/channel/{channel}"); + App.Logger.WriteLine($"[DeployManager::SetChannel] Set channel to {Channel}"); + + Channel = channel; + BaseUrl = channel == DefaultChannel ? DefaultBaseUrl : $"{DefaultBaseUrl}/channel/{channel.ToLower()}"; + } + + public async Task GetLastDeploy(bool timestamp = false) + { + App.Logger.WriteLine($"[DeployManager::GetLastDeploy] Getting deploy info for channel {Channel} (timestamp={timestamp})"); + + HttpResponseMessage deployInfoResponse = await App.HttpClient.GetAsync($"https://clientsettings.roblox.com/v2/client-version/WindowsPlayer/channel/{Channel}"); string rawResponse = await deployInfoResponse.Content.ReadAsStringAsync(); @@ -73,7 +83,7 @@ namespace Bloxstrap.Helpers $"\tResponse: {rawResponse}" ); - throw new Exception($"Could not get latest deploy for channel {channel}! (HTTP {deployInfoResponse.StatusCode})"); + throw new Exception($"Could not get latest deploy for channel {Channel}! (HTTP {deployInfoResponse.StatusCode})"); } App.Logger.WriteLine($"[DeployManager::GetLastDeploy] Got JSON: {rawResponse}"); @@ -85,8 +95,7 @@ namespace Bloxstrap.Helpers { App.Logger.WriteLine("[DeployManager::GetLastDeploy] Getting timestamp..."); - string channelUrl = BuildBaseUrl(channel); - string manifestUrl = $"{channelUrl}/{clientVersion.VersionGuid}-rbxPkgManifest.txt"; + string manifestUrl = $"{BaseUrl}/{clientVersion.VersionGuid}-rbxPkgManifest.txt"; // get an approximate deploy time from rbxpkgmanifest's last modified date HttpResponseMessage pkgResponse = await App.HttpClient.GetAsync(manifestUrl); @@ -95,7 +104,7 @@ namespace Bloxstrap.Helpers { string lastModified = values.First(); App.Logger.WriteLine($"[DeployManager::GetLastDeploy] {manifestUrl} - Last-Modified: {lastModified}"); - clientVersion.Timestamp = DateTime.Parse(lastModified); + clientVersion.Timestamp = DateTime.Parse(lastModified).ToLocalTime(); } } diff --git a/Bloxstrap/Helpers/RSMM/PackageManifest.cs b/Bloxstrap/Helpers/RSMM/PackageManifest.cs index bdd20d4..e4a8d2a 100644 --- a/Bloxstrap/Helpers/RSMM/PackageManifest.cs +++ b/Bloxstrap/Helpers/RSMM/PackageManifest.cs @@ -50,7 +50,7 @@ namespace Bloxstrap.Helpers.RSMM public static async Task Get(string versionGuid) { - string pkgManifestUrl = $"{DeployManager.BaseUrl}/{versionGuid}-rbxPkgManifest.txt"; + string pkgManifestUrl = $"{App.DeployManager.BaseUrl}/{versionGuid}-rbxPkgManifest.txt"; var pkgManifestData = await App.HttpClient.GetStringAsync(pkgManifestUrl); return new PackageManifest(pkgManifestData); diff --git a/Bloxstrap/ViewModels/InstallationViewModel.cs b/Bloxstrap/ViewModels/InstallationViewModel.cs index 997d4c8..9607870 100644 --- a/Bloxstrap/ViewModels/InstallationViewModel.cs +++ b/Bloxstrap/ViewModels/InstallationViewModel.cs @@ -39,13 +39,14 @@ namespace Bloxstrap.ViewModels ChannelDeployInfo = null; OnPropertyChanged(nameof(ChannelDeployInfo)); - ClientVersion info = await DeployManager.GetLastDeploy(channel, true); + App.DeployManager.SetChannel(channel); + ClientVersion info = await App.DeployManager.GetLastDeploy(true); ChannelDeployInfo = new DeployInfo { Version = info.Version, VersionGuid = info.VersionGuid, - Timestamp = info.Timestamp?.ToString("MM/dd/yyyy h:mm:ss tt", App.CultureFormat)! + Timestamp = info.Timestamp?.ToString("dddd, d MMMM yyyy 'at' h:mm:ss tt", App.CultureFormat)! }; OnPropertyChanged(nameof(ChannelDeployInfo));