Skip to content

Commit

Permalink
Add check for working deployment domain (#134)
Browse files Browse the repository at this point in the history
this is gonna suck to merge into 2.2.0 lmao
  • Loading branch information
pizzaboxer committed Apr 16, 2023
1 parent ef9a28c commit be93879
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Bloxstrap/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ protected override void OnStartup(StartupEventArgs e)
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");
Expand Down
76 changes: 61 additions & 15 deletions Bloxstrap/Helpers/DeployManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()}";
}
}

// basically any channel that has had a deploy within the past month with a windowsplayer build
public static readonly List<string> ChannelsAbstracted = new()
Expand Down Expand Up @@ -51,17 +108,6 @@ public class DeployManager
};
#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})");
Expand Down
2 changes: 1 addition & 1 deletion Bloxstrap/ViewModels/InstallationViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ private async Task LoadChannelDeployInfo(string channel)
ChannelDeployInfo = null;
OnPropertyChanged(nameof(ChannelDeployInfo));

App.DeployManager.SetChannel(channel);
App.DeployManager.Channel = channel;
ClientVersion info = await App.DeployManager.GetLastDeploy(true);

ChannelDeployInfo = new DeployInfo
Expand Down

0 comments on commit be93879

Please sign in to comment.