Add check for working deployment domain (#134)

this is gonna suck to merge into 2.2.0 lmao
This commit is contained in:
pizzaboxer 2023-04-16 01:58:11 +01:00
parent 1f40efd10d
commit c87eff997a
No known key found for this signature in database
GPG Key ID: 59D4A1DBAD0F2BA8
3 changed files with 63 additions and 17 deletions

View File

@ -258,7 +258,7 @@ namespace Bloxstrap
if (!IsFirstRun)
ShouldSaveConfigs = true;
DeployManager.SetChannel(Settings.Prop.Channel);
DeployManager.Channel = Settings.Prop.Channel;
// start bootstrapper and show the bootstrapper modal if we're not running silently
Logger.WriteLine($"[App::OnStartup] Initializing bootstrapper");

View File

@ -13,11 +13,68 @@ namespace Bloxstrap.Helpers
public class DeployManager
{
#region Properties
public const string DefaultBaseUrl = "https://setup.rbxcdn.com";
public const string DefaultChannel = "LIVE";
public string BaseUrl { get; private set; } = DefaultBaseUrl;
public string Channel { get; private set; } = DefaultChannel;
private string _channel = DefaultChannel;
public string Channel
{
get => _channel;
set
{
if (_channel != value)
App.Logger.WriteLine($"[DeployManager::SetChannel] Changed channel to {value}");
_channel = value;
}
}
// a list of roblox delpoyment locations that we check for, in case one of them don't work
private List<string> BaseUrls = new()
{
"https://setup.rbxcdn.com",
"https://setup-ak.rbxcdn.com",
"https://s3.amazonaws.com/setup.roblox.com"
};
private string? _baseUrl = null;
public string BaseUrl
{
get
{
if (String.IsNullOrEmpty(_baseUrl))
{
// check for a working accessible deployment domain
foreach (string attemptedUrl in BaseUrls)
{
App.Logger.WriteLine($"[DeployManager::DefaultBaseUrl.Set] Testing connection to '{attemptedUrl}'...");
try
{
App.HttpClient.GetAsync($"{attemptedUrl}/version").Wait();
App.Logger.WriteLine($"[DeployManager::DefaultBaseUrl.Set] Connection successful!");
_baseUrl = attemptedUrl;
break;
}
catch (Exception ex)
{
App.Logger.WriteLine($"[DeployManager::DefaultBaseUrl.Set] Connection failed!");
App.Logger.WriteLine($"[DeployManager::DefaultBaseUrl.Set] {ex}");
continue;
}
}
if (String.IsNullOrEmpty(_baseUrl))
throw new Exception("Unable to find an accessible Roblox deploy mirror!");
}
if (Channel == DefaultChannel)
return _baseUrl;
else
return $"{_baseUrl}/channel/{Channel.ToLower()}";
}
}
// most commonly used/interesting channels
public static readonly List<string> SelectableChannels = new()
@ -32,17 +89,6 @@ namespace Bloxstrap.Helpers
};
#endregion
public void SetChannel(string channel)
{
if (Channel == channel)
return;
App.Logger.WriteLine($"[DeployManager::SetChannel] Set channel to {Channel}");
Channel = channel;
BaseUrl = channel == DefaultChannel ? DefaultBaseUrl : $"{DefaultBaseUrl}/channel/{channel.ToLower()}";
}
public async Task<ClientVersion> GetLastDeploy(bool timestamp = false)
{
App.Logger.WriteLine($"[DeployManager::GetLastDeploy] Getting deploy info for channel {Channel} (timestamp={timestamp})");

View File

@ -39,7 +39,7 @@ namespace Bloxstrap.ViewModels
ChannelDeployInfo = null;
OnPropertyChanged(nameof(ChannelDeployInfo));
App.DeployManager.SetChannel(channel);
App.DeployManager.Channel = channel;
try
{