Optimize GetLatestVersionInfo

This optimizes the GetLatestVersionInfo function for better readability
This commit is contained in:
Santana 2024-12-15 20:41:14 -06:00
parent 84822e29c6
commit 9fc5ab8228

View File

@ -260,68 +260,60 @@ namespace Bloxstrap
{ {
const string LOG_IDENT = "Bootstrapper::GetLatestVersionInfo"; const string LOG_IDENT = "Bootstrapper::GetLatestVersionInfo";
// before we do anything, we need to query our channel using (var key = Registry.CurrentUser.CreateSubKey($"SOFTWARE\\ROBLOX Corporation\\Environments\\{AppData.RegistryName}\\Channel"))
// if it's set in the launch uri, we need to use it and set the registry key for it {
// else, check if the registry key for it exists, and use it // Check for channel in launch arguments
using var key = Registry.CurrentUser.CreateSubKey($"SOFTWARE\\ROBLOX Corporation\\Environments\\{AppData.RegistryName}\\Channel");
var match = Regex.Match( var match = Regex.Match(
App.LaunchSettings.RobloxLaunchArgs, App.LaunchSettings.RobloxLaunchArgs,
"channel:([a-zA-Z0-9-_]+)", @"channel:([a-zA-Z0-9-_]+)",
RegexOptions.IgnoreCase | RegexOptions.CultureInvariant RegexOptions.IgnoreCase | RegexOptions.CultureInvariant
); );
if (match.Groups.Count == 2) if (match.Success)
{ {
Deployment.Channel = match.Groups[1].Value.ToLowerInvariant(); Deployment.Channel = match.Groups[1].Value.ToLowerInvariant();
} }
else if (key.GetValue("www.roblox.com") is string value && !String.IsNullOrEmpty(value)) else if (key.GetValue("www.roblox.com") is string value && !string.IsNullOrEmpty(value))
{ {
Deployment.Channel = value.ToLowerInvariant(); Deployment.Channel = value.ToLowerInvariant();
} }
if (String.IsNullOrEmpty(Deployment.Channel)) // Fallback to default if no channel is set
if (string.IsNullOrEmpty(Deployment.Channel))
{
Deployment.Channel = Deployment.DefaultChannel; Deployment.Channel = Deployment.DefaultChannel;
}
App.Logger.WriteLine(LOG_IDENT, $"Got channel as {Deployment.DefaultChannel}"); // Save the updated channel to the registry
key.SetValueSafe("www.roblox.com", Deployment.IsDefaultChannel ? "" : Deployment.Channel);
}
if (!Deployment.IsDefaultChannel) App.Logger.WriteLine(LOG_IDENT, $"Using channel: {Deployment.Channel}");
App.SendStat("robloxChannel", Deployment.Channel);
// Fetch client version information
ClientVersion clientVersion; ClientVersion clientVersion;
try try
{ {
clientVersion = await Deployment.GetInfo(); clientVersion = await Deployment.GetInfo();
} }
catch (InvalidChannelException ex) catch (InvalidChannelException ex)
{ {
App.Logger.WriteLine(LOG_IDENT, $"Resetting channel from {Deployment.Channel} because {ex.StatusCode}"); App.Logger.WriteLine(LOG_IDENT, $"Error fetching version info for channel {Deployment.Channel}: {ex.StatusCode}");
throw; // Propagate the exception since channel correction is not required
Deployment.Channel = Deployment.DefaultChannel;
clientVersion = await Deployment.GetInfo();
} }
if (clientVersion.IsBehindDefaultChannel) // Update version information
{
App.Logger.WriteLine(LOG_IDENT, $"Resetting channel from {Deployment.Channel} because it's behind production");
Deployment.Channel = Deployment.DefaultChannel;
clientVersion = await Deployment.GetInfo();
}
key.SetValueSafe("www.roblox.com", Deployment.IsDefaultChannel ? "" : Deployment.Channel);
_latestVersionGuid = clientVersion.VersionGuid; _latestVersionGuid = clientVersion.VersionGuid;
_latestVersionDirectory = Path.Combine(Paths.Versions, _latestVersionGuid); _latestVersionDirectory = Path.Combine(Paths.Versions, _latestVersionGuid);
// Fetch the package manifest
string pkgManifestUrl = Deployment.GetLocation($"/{_latestVersionGuid}-rbxPkgManifest.txt"); string pkgManifestUrl = Deployment.GetLocation($"/{_latestVersionGuid}-rbxPkgManifest.txt");
var pkgManifestData = await App.HttpClient.GetStringAsync(pkgManifestUrl); var pkgManifestData = await App.HttpClient.GetStringAsync(pkgManifestUrl);
_versionPackageManifest = new(pkgManifestData); _versionPackageManifest = new(pkgManifestData);
} }
private void StartRoblox() private void StartRoblox()
{ {
const string LOG_IDENT = "Bootstrapper::StartRoblox"; const string LOG_IDENT = "Bootstrapper::StartRoblox";