use clientsettings to fetch version

This commit is contained in:
Matthew Brown 2022-11-24 18:22:18 +00:00
parent 947993e446
commit e77f8c1c65
5 changed files with 48 additions and 75 deletions

View File

@ -10,6 +10,7 @@ using Bloxstrap.Dialogs.BootstrapperDialogs;
using Bloxstrap.Helpers;
using Bloxstrap.Helpers.Integrations;
using Bloxstrap.Helpers.RSMM;
using Bloxstrap.Models;
using System.Net;
namespace Bloxstrap
@ -131,7 +132,8 @@ namespace Bloxstrap
{
Dialog.Message = "Connecting to Roblox...";
VersionGuid = await Program.HttpClient.GetStringAsync($"{DeployManager.BaseUrl}/version");
ClientVersion clientVersion = await DeployManager.GetLastDeploy(Program.Settings.Channel);
VersionGuid = clientVersion.VersionGuid;
VersionFolder = Path.Combine(Directories.Versions, VersionGuid);
VersionPackageManifest = await PackageManifest.Get(VersionGuid);
}

View File

@ -343,10 +343,10 @@ namespace Bloxstrap.Dialogs
{
ChannelInfo = "Getting latest version info, please wait...\n";
VersionDeploy info = await DeployManager.GetLastDeploy(channel);
string strTimestamp = info.Timestamp.ToString("MM/dd/yyyy h:mm:ss tt", Program.CultureFormat);
ClientVersion info = await DeployManager.GetLastDeploy(channel, true);
string? strTimestamp = info.Timestamp?.ToString("MM/dd/yyyy h:mm:ss tt", Program.CultureFormat);
ChannelInfo = $"Version: v{info.FileVersion} ({info.VersionGuid})\nDeployed: {strTimestamp}";
ChannelInfo = $"Version: v{info.Version} ({info.VersionGuid})\nDeployed: {strTimestamp}";
}
}
}

View File

@ -1,6 +1,5 @@
using System.IO;
using System.Net.Http;
using System.Net.Http;
using System.Text.Json;
using Bloxstrap.Models;
namespace Bloxstrap.Helpers
@ -99,67 +98,36 @@ namespace Bloxstrap.Helpers
return $"{DefaultBaseUrl}/channel/{channel.ToLower()}";
}
public static async Task<VersionDeploy> GetLastDeploy(string channel)
public static async Task<ClientVersion> GetLastDeploy(string channel, bool timestamp = false)
{
string baseUrl = BuildBaseUrl(channel);
string lastDeploy = "";
HttpResponseMessage deployInfoResponse = await Program.HttpClient.GetAsync($"https://clientsettings.roblox.com/v2/client-version/WindowsPlayer/channel/{channel}");
string deployHistory = await Program.HttpClient.GetStringAsync($"{baseUrl}/DeployHistory.txt");
using (StringReader reader = new(deployHistory))
if (!deployInfoResponse.IsSuccessStatusCode)
{
string? line;
while ((line = await reader.ReadLineAsync()) is not null)
{
if (line.Contains("WindowsPlayer"))
lastDeploy = line;
}
}
if (String.IsNullOrEmpty(lastDeploy))
// 400 = Invalid binaryType.
// 404 = Could not find version details for binaryType.
// 500 = Error while fetching version information.
// either way, we throw
throw new Exception($"Could not get latest deploy for channel {channel}");
}
// here's to hoping roblox doesn't change their deployment entry format
// (last time they did so was may 2021 so we should be fine?)
// example entry: 'New WindowsPlayer version-29fb7cdd06e84001 at 8/23/2022 2:07:27 PM, file version: 0, 542, 100, 5420251, git hash: b98d6b2bea36fa2161f48cca979fb620bb0c24fd ...'
string rawJson = await deployInfoResponse.Content.ReadAsStringAsync();
ClientVersion clientVersion = JsonSerializer.Deserialize<ClientVersion>(rawJson)!;
// there's a proper way, and then there's the lazy way
// this here is the lazy way but it should just work™
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 = "";
if (lastDeploy.Contains("git hash"))
// for preferences
if (timestamp)
{
// ~may 2021 entry: ends like 'file version: 0, 542, 100, 5420251, git hash: b98d6b2bea36fa2161f48cca979fb620bb0c24fd ...'
fileVersion = lastDeploy[..lastDeploy.IndexOf(", git")]; // '0, 542, 100, 5420251'
}
else
string channelUrl = BuildBaseUrl(channel);
HttpResponseMessage pkgMessage = await Program.HttpClient.GetAsync($"{channelUrl}/{clientVersion.VersionGuid}-rbxPkgManifest.txt");
if (pkgMessage.Content.Headers.TryGetValues("last-modified", out var values))
{
// pre-may 2021 entry: ends like 'file version: 0, 448, 0, 411122...'
fileVersion = lastDeploy[..lastDeploy.IndexOf("...")]; // '0, 448, 0, 411122'
string lastModified = values.First();
clientVersion.Timestamp = DateTime.Parse(lastModified);
}
}
// deployment timestamps are UTC-5
strTimestamp += " -05";
DateTime dtTimestamp = DateTime.ParseExact(strTimestamp, "M/d/yyyy h:mm:ss tt zz", Program.CultureFormat).ToLocalTime();
// convert to traditional version format
fileVersion = fileVersion.Replace(" ", "").Replace(',', '.');
return new VersionDeploy
{
VersionGuid = versionGuid,
Timestamp = dtTimestamp,
FileVersion = fileVersion
};
return clientVersion;
}
}
}

View File

@ -0,0 +1,18 @@
using System.Text.Json.Serialization;
namespace Bloxstrap.Models
{
public class ClientVersion
{
[JsonPropertyName("version")]
public string Version { get; set; } = null!;
[JsonPropertyName("clientVersionUpload")]
public string VersionGuid { get; set; } = null!;
[JsonPropertyName("bootstrapperVersion")]
public string BootstrapperVersion { get; set; } = null!;
public DateTime? Timestamp { get; set; }
}
}

View File

@ -1,15 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Bloxstrap.Models
{
public class VersionDeploy
{
public string VersionGuid { get; set; } = null!;
public string FileVersion { get; set; } = null!;
public DateTime Timestamp { get; set; }
}
}