Check channel by comparing against LIVE

also change how version comparisons work
This commit is contained in:
pizzaboxer 2023-07-17 10:10:53 +01:00
parent 0b8b9ea068
commit 607075c9d9
No known key found for this signature in database
GPG Key ID: 59D4A1DBAD0F2BA8
6 changed files with 67 additions and 33 deletions

View File

@ -542,11 +542,10 @@ namespace Bloxstrap
return; return;
} }
int numCurrentVersion = Utilities.VersionToNumber(App.Version); int versionComparison = Utilities.CompareVersions(App.Version, releaseInfo.TagName);
int numLatestVersion = Utilities.VersionToNumber(releaseInfo.TagName);
// check if we aren't using a deployed build, so we can update to one if a new version comes out // 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"); App.Logger.WriteLine($"[Bootstrapper::CheckForUpdates] No updates found");
return; return;

View File

@ -12,5 +12,7 @@
public string BootstrapperVersion { get; set; } = null!; public string BootstrapperVersion { get; set; } = null!;
public DateTime? Timestamp { get; set; } public DateTime? Timestamp { get; set; }
public bool IsBehindDefaultChannel { get; set; }
} }
} }

View File

@ -5,6 +5,8 @@
#region Properties #region Properties
public const string DefaultChannel = "LIVE"; public const string DefaultChannel = "LIVE";
private static Dictionary<string, ClientVersion> ClientVersionCache = new();
// a list of roblox delpoyment locations that we check for, in case one of them don't work // a list of roblox delpoyment locations that we check for, in case one of them don't work
private static List<string> BaseUrls = new() private static List<string> BaseUrls = new()
{ {
@ -77,36 +79,47 @@
return location; return location;
} }
public static async Task<ClientVersion> GetInfo(string channel, bool timestamp = false) public static async Task<ClientVersion> GetInfo(string channel, bool extraInformation = false)
{ {
App.Logger.WriteLine($"[RobloxDeployment::GetInfo] Getting deploy info for channel {channel} (timestamp={timestamp})"); App.Logger.WriteLine($"[RobloxDeployment::GetInfo] Getting deploy info for channel {channel} (extraInformation={extraInformation})");
HttpResponseMessage deployInfoResponse = await App.HttpClient.GetAsync($"https://clientsettingscdn.roblox.com/v2/client-version/WindowsPlayer/channel/{channel}"); ClientVersion clientVersion;
string rawResponse = await deployInfoResponse.Content.ReadAsStringAsync(); if (ClientVersionCache.ContainsKey(channel))
if (!deployInfoResponse.IsSuccessStatusCode)
{ {
// 400 = Invalid binaryType. App.Logger.WriteLine($"[RobloxDeployment::GetInfo] Deploy information is cached");
// 404 = Could not find version details for binaryType. clientVersion = ClientVersionCache[channel];
// 500 = Error while fetching version information. }
// either way, we throw else
{
HttpResponseMessage deployInfoResponse = await App.HttpClient.GetAsync($"https://clientsettingscdn.roblox.com/v2/client-version/WindowsPlayer/channel/{channel}");
App.Logger.WriteLine( string rawResponse = await deployInfoResponse.Content.ReadAsStringAsync();
"[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})"); 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<ClientVersion>(rawResponse)!;
} }
ClientVersion clientVersion = JsonSerializer.Deserialize<ClientVersion>(rawResponse)!;
// for preferences // 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); string manifestUrl = GetLocation($"/{clientVersion.VersionGuid}-rbxPkgManifest.txt", channel);
@ -119,8 +132,19 @@
App.Logger.WriteLine($"[RobloxDeployment::GetInfo] {manifestUrl} - Last-Modified: {lastModified}"); App.Logger.WriteLine($"[RobloxDeployment::GetInfo] {manifestUrl} - Last-Modified: {lastModified}");
clientVersion.Timestamp = DateTime.Parse(lastModified).ToLocalTime(); 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; return clientVersion;
} }
} }

View File

@ -79,7 +79,7 @@
<StackPanel Grid.Row="3" Grid.ColumnSpan="2" Margin="0,16,0,0" Orientation="Horizontal" Visibility="{Binding ChannelWarningVisibility, Mode=OneWay}"> <StackPanel Grid.Row="3" Grid.ColumnSpan="2" Margin="0,16,0,0" Orientation="Horizontal" Visibility="{Binding ChannelWarningVisibility, Mode=OneWay}">
<Image Grid.Column="0" Width="24" Height="24" RenderOptions.BitmapScalingMode="HighQuality" Source="pack://application:,,,/Resources/MessageBox/Warning.png" /> <Image Grid.Column="0" Width="24" Height="24" RenderOptions.BitmapScalingMode="HighQuality" Source="pack://application:,,,/Resources/MessageBox/Warning.png" />
<TextBlock Margin="8,0,0,0" VerticalAlignment="Center" Text="This channel may be out of date, as it was last deployed to over a month ago." /> <TextBlock Margin="8,0,0,0" VerticalAlignment="Center" Text="This channel is out of date, and is likely no longer being updated. Please use another channel." />
</StackPanel> </StackPanel>
</Grid> </Grid>
<Grid Column="0"> <Grid Column="0">

View File

@ -27,10 +27,7 @@ namespace Bloxstrap.UI.ViewModels.Menu
{ {
ClientVersion info = await RobloxDeployment.GetInfo(channel, true); ClientVersion info = await RobloxDeployment.GetInfo(channel, true);
if (info.Timestamp?.AddMonths(1) < DateTime.Now) ChannelWarningVisibility = info.IsBehindDefaultChannel ? Visibility.Visible : Visibility.Collapsed;
ChannelWarningVisibility = Visibility.Visible;
else
ChannelWarningVisibility = Visibility.Collapsed;
ChannelDeployInfo = new DeployInfo ChannelDeployInfo = new DeployInfo
{ {

View File

@ -15,11 +15,23 @@
public static void ShellExecute(string website) => Process.Start(new ProcessStartInfo { FileName = website, UseShellExecute = true }); public static void ShellExecute(string website) => Process.Start(new ProcessStartInfo { FileName = website, UseShellExecute = true });
public static int VersionToNumber(string version) /// <summary>
///
/// </summary>
/// <param name="versionStr1"></param>
/// <param name="versionStr2"></param>
/// <returns>
/// Result of System.Version.CompareTo <br />
/// -1: version1 &lt; version2 <br />
/// 0: version1 == version2 <br />
/// 1: version1 &gt; version2
/// </returns>
public static int CompareVersions(string versionStr1, string versionStr2)
{ {
// yes this is kinda stupid lol var version1 = new Version(versionStr1.Replace("v", ""));
version = version.Replace("v", "").Replace(".", ""); var version2 = new Version(versionStr2.Replace("v", ""));
return Int32.Parse(version);
return version1.CompareTo(version2);
} }
} }
} }