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;
using Bloxstrap.Helpers.Integrations; using Bloxstrap.Helpers.Integrations;
using Bloxstrap.Helpers.RSMM; using Bloxstrap.Helpers.RSMM;
using Bloxstrap.Models;
using System.Net; using System.Net;
namespace Bloxstrap namespace Bloxstrap
@ -131,7 +132,8 @@ namespace Bloxstrap
{ {
Dialog.Message = "Connecting to Roblox..."; 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); VersionFolder = Path.Combine(Directories.Versions, VersionGuid);
VersionPackageManifest = await PackageManifest.Get(VersionGuid); VersionPackageManifest = await PackageManifest.Get(VersionGuid);
} }

View File

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

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; }
}
}