mirror of
https://github.com/bloxstraplabs/bloxstrap.git
synced 2025-04-18 16:41:36 -07:00
Check channel by comparing against LIVE
also change how version comparisons work
This commit is contained in:
parent
0b8b9ea068
commit
607075c9d9
@ -542,11 +542,10 @@ namespace Bloxstrap
|
||||
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;
|
||||
|
@ -12,5 +12,7 @@
|
||||
public string BootstrapperVersion { get; set; } = null!;
|
||||
|
||||
public DateTime? Timestamp { get; set; }
|
||||
|
||||
public bool IsBehindDefaultChannel { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,8 @@
|
||||
#region Properties
|
||||
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
|
||||
private static List<string> BaseUrls = new()
|
||||
{
|
||||
@ -77,36 +79,47 @@
|
||||
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 (!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<ClientVersion>(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<ClientVersion>(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 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -79,7 +79,7 @@
|
||||
|
||||
<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" />
|
||||
<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>
|
||||
</Grid>
|
||||
<Grid Column="0">
|
||||
|
@ -27,10 +27,7 @@ namespace Bloxstrap.UI.ViewModels.Menu
|
||||
{
|
||||
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
|
||||
{
|
||||
|
@ -15,11 +15,23 @@
|
||||
|
||||
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 < version2 <br />
|
||||
/// 0: version1 == version2 <br />
|
||||
/// 1: version1 > version2
|
||||
/// </returns>
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user