From c87eff997a912593df92fe7153e149d6aefc59d6 Mon Sep 17 00:00:00 2001 From: pizzaboxer Date: Sun, 16 Apr 2023 01:58:11 +0100 Subject: [PATCH] Add check for working deployment domain (#134) this is gonna suck to merge into 2.2.0 lmao --- Bloxstrap/App.xaml.cs | 2 +- Bloxstrap/Helpers/DeployManager.cs | 76 +++++++++++++++---- Bloxstrap/ViewModels/InstallationViewModel.cs | 2 +- 3 files changed, 63 insertions(+), 17 deletions(-) diff --git a/Bloxstrap/App.xaml.cs b/Bloxstrap/App.xaml.cs index faf6167..cf81492 100644 --- a/Bloxstrap/App.xaml.cs +++ b/Bloxstrap/App.xaml.cs @@ -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"); diff --git a/Bloxstrap/Helpers/DeployManager.cs b/Bloxstrap/Helpers/DeployManager.cs index 77f8b77..a745cd7 100644 --- a/Bloxstrap/Helpers/DeployManager.cs +++ b/Bloxstrap/Helpers/DeployManager.cs @@ -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 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 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 GetLastDeploy(bool timestamp = false) { App.Logger.WriteLine($"[DeployManager::GetLastDeploy] Getting deploy info for channel {Channel} (timestamp={timestamp})"); diff --git a/Bloxstrap/ViewModels/InstallationViewModel.cs b/Bloxstrap/ViewModels/InstallationViewModel.cs index 81e40d5..f72f01e 100644 --- a/Bloxstrap/ViewModels/InstallationViewModel.cs +++ b/Bloxstrap/ViewModels/InstallationViewModel.cs @@ -39,7 +39,7 @@ namespace Bloxstrap.ViewModels ChannelDeployInfo = null; OnPropertyChanged(nameof(ChannelDeployInfo)); - App.DeployManager.SetChannel(channel); + App.DeployManager.Channel = channel; try {