From 607075c9d9b3ec9d6634d4183fd948d1e9acb8f4 Mon Sep 17 00:00:00 2001 From: pizzaboxer Date: Mon, 17 Jul 2023 10:10:53 +0100 Subject: [PATCH] Check channel by comparing against LIVE also change how version comparisons work --- Bloxstrap/Bootstrapper.cs | 5 +- Bloxstrap/Models/ClientVersion.cs | 2 + Bloxstrap/RobloxDeployment.cs | 66 +++++++++++++------ .../UI/Elements/Menu/Pages/BehaviourPage.xaml | 2 +- .../UI/ViewModels/Menu/BehaviourViewModel.cs | 5 +- Bloxstrap/Utilities.cs | 20 ++++-- 6 files changed, 67 insertions(+), 33 deletions(-) diff --git a/Bloxstrap/Bootstrapper.cs b/Bloxstrap/Bootstrapper.cs index 95a51f60..dceebbec 100644 --- a/Bloxstrap/Bootstrapper.cs +++ b/Bloxstrap/Bootstrapper.cs @@ -542,11 +542,10 @@ private async Task CheckForUpdates() return; } - int numCurrentVersion = Utilities.VersionToNumber(App.Version); - int numLatestVersion = Utilities.VersionToNumber(releaseInfo.TagName); + int versionComparison = Utilities.CompareVersions(App.Version, releaseInfo.TagName); // check if we aren't using a deployed build, so we can update to one if a new version comes out - if (numCurrentVersion == numLatestVersion && App.BuildMetadata.CommitRef.StartsWith("tag") || numCurrentVersion > numLatestVersion) + if (versionComparison == 0 && App.BuildMetadata.CommitRef.StartsWith("tag") || versionComparison == -1) { App.Logger.WriteLine($"[Bootstrapper::CheckForUpdates] No updates found"); return; diff --git a/Bloxstrap/Models/ClientVersion.cs b/Bloxstrap/Models/ClientVersion.cs index e951e4e0..b90df0a3 100644 --- a/Bloxstrap/Models/ClientVersion.cs +++ b/Bloxstrap/Models/ClientVersion.cs @@ -12,5 +12,7 @@ public class ClientVersion public string BootstrapperVersion { get; set; } = null!; public DateTime? Timestamp { get; set; } + + public bool IsBehindDefaultChannel { get; set; } } } diff --git a/Bloxstrap/RobloxDeployment.cs b/Bloxstrap/RobloxDeployment.cs index 6667ca8e..067e7325 100644 --- a/Bloxstrap/RobloxDeployment.cs +++ b/Bloxstrap/RobloxDeployment.cs @@ -5,6 +5,8 @@ public static class RobloxDeployment #region Properties public const string DefaultChannel = "LIVE"; + private static Dictionary ClientVersionCache = new(); + // a list of roblox delpoyment locations that we check for, in case one of them don't work private static List BaseUrls = new() { @@ -77,36 +79,47 @@ public static string GetLocation(string resource, string? channel = null) return location; } - public static async Task GetInfo(string channel, bool timestamp = false) + public static async Task GetInfo(string channel, bool extraInformation = false) { - App.Logger.WriteLine($"[RobloxDeployment::GetInfo] Getting deploy info for channel {channel} (timestamp={timestamp})"); - - HttpResponseMessage deployInfoResponse = await App.HttpClient.GetAsync($"https://clientsettingscdn.roblox.com/v2/client-version/WindowsPlayer/channel/{channel}"); + App.Logger.WriteLine($"[RobloxDeployment::GetInfo] Getting deploy info for channel {channel} (extraInformation={extraInformation})"); - string rawResponse = await deployInfoResponse.Content.ReadAsStringAsync(); + ClientVersion clientVersion; - if (!deployInfoResponse.IsSuccessStatusCode) + if (ClientVersionCache.ContainsKey(channel)) { - // 400 = Invalid binaryType. - // 404 = Could not find version details for binaryType. - // 500 = Error while fetching version information. - // either way, we throw - - App.Logger.WriteLine( - "[RobloxDeployment::GetInfo] Failed to fetch deploy info!\r\n" + - $"\tStatus code: {deployInfoResponse.StatusCode}\r\n" + - $"\tResponse: {rawResponse}" - ); - - throw new Exception($"Could not get latest deploy for channel {channel}! (HTTP {deployInfoResponse.StatusCode})"); + App.Logger.WriteLine($"[RobloxDeployment::GetInfo] Deploy information is cached"); + clientVersion = ClientVersionCache[channel]; } + else + { + HttpResponseMessage deployInfoResponse = await App.HttpClient.GetAsync($"https://clientsettingscdn.roblox.com/v2/client-version/WindowsPlayer/channel/{channel}"); - ClientVersion clientVersion = JsonSerializer.Deserialize(rawResponse)!; + string rawResponse = await deployInfoResponse.Content.ReadAsStringAsync(); + + if (!deployInfoResponse.IsSuccessStatusCode) + { + // 400 = Invalid binaryType. + // 404 = Could not find version details for binaryType. + // 500 = Error while fetching version information. + // either way, we throw + + App.Logger.WriteLine( + "[RobloxDeployment::GetInfo] Failed to fetch deploy info!\r\n" + + $"\tStatus code: {deployInfoResponse.StatusCode}\r\n" + + $"\tResponse: {rawResponse}" + ); + + throw new Exception($"Could not get latest deploy for channel {channel}! (HTTP {deployInfoResponse.StatusCode})"); + } + + clientVersion = JsonSerializer.Deserialize(rawResponse)!; + } + // for preferences - if (timestamp) + if (extraInformation && clientVersion.Timestamp is null) { - App.Logger.WriteLine("[RobloxDeployment::GetInfo] Getting timestamp..."); + App.Logger.WriteLine("[RobloxDeployment::GetInfo] Getting extra information..."); string manifestUrl = GetLocation($"/{clientVersion.VersionGuid}-rbxPkgManifest.txt", channel); @@ -119,8 +132,19 @@ public static async Task GetInfo(string channel, bool timestamp = App.Logger.WriteLine($"[RobloxDeployment::GetInfo] {manifestUrl} - Last-Modified: {lastModified}"); clientVersion.Timestamp = DateTime.Parse(lastModified).ToLocalTime(); } + + // check if channel is behind LIVE + if (channel != DefaultChannel) + { + var defaultClientVersion = await GetInfo(DefaultChannel); + + if (Utilities.CompareVersions(clientVersion.Version, defaultClientVersion.Version) == -1) + clientVersion.IsBehindDefaultChannel = true; + } } + ClientVersionCache[channel] = clientVersion; + return clientVersion; } } diff --git a/Bloxstrap/UI/Elements/Menu/Pages/BehaviourPage.xaml b/Bloxstrap/UI/Elements/Menu/Pages/BehaviourPage.xaml index 50c85ca7..f137e8f3 100644 --- a/Bloxstrap/UI/Elements/Menu/Pages/BehaviourPage.xaml +++ b/Bloxstrap/UI/Elements/Menu/Pages/BehaviourPage.xaml @@ -79,7 +79,7 @@ - + diff --git a/Bloxstrap/UI/ViewModels/Menu/BehaviourViewModel.cs b/Bloxstrap/UI/ViewModels/Menu/BehaviourViewModel.cs index 38b1a192..8b7e4f7d 100644 --- a/Bloxstrap/UI/ViewModels/Menu/BehaviourViewModel.cs +++ b/Bloxstrap/UI/ViewModels/Menu/BehaviourViewModel.cs @@ -27,10 +27,7 @@ private async Task LoadChannelDeployInfo(string channel) { ClientVersion info = await RobloxDeployment.GetInfo(channel, true); - if (info.Timestamp?.AddMonths(1) < DateTime.Now) - ChannelWarningVisibility = Visibility.Visible; - else - ChannelWarningVisibility = Visibility.Collapsed; + ChannelWarningVisibility = info.IsBehindDefaultChannel ? Visibility.Visible : Visibility.Collapsed; ChannelDeployInfo = new DeployInfo { diff --git a/Bloxstrap/Utilities.cs b/Bloxstrap/Utilities.cs index c362a710..ae604cbb 100644 --- a/Bloxstrap/Utilities.cs +++ b/Bloxstrap/Utilities.cs @@ -15,11 +15,23 @@ public static long GetFreeDiskSpace(string path) public static void ShellExecute(string website) => Process.Start(new ProcessStartInfo { FileName = website, UseShellExecute = true }); - public static int VersionToNumber(string version) + /// + /// + /// + /// + /// + /// + /// Result of System.Version.CompareTo
+ /// -1: version1 < version2
+ /// 0: version1 == version2
+ /// 1: version1 > version2 + ///
+ public static int CompareVersions(string versionStr1, string versionStr2) { - // yes this is kinda stupid lol - version = version.Replace("v", "").Replace(".", ""); - return Int32.Parse(version); + var version1 = new Version(versionStr1.Replace("v", "")); + var version2 = new Version(versionStr2.Replace("v", "")); + + return version1.CompareTo(version2); } } }