Skip to content

Commit

Permalink
Merge pull request #578 from pizzaboxer/version-2.5.1
Browse files Browse the repository at this point in the history
Version 2.5.1
  • Loading branch information
pizzaboxer committed Aug 24, 2023
2 parents f7592f3 + 35caf8e commit 8f08495
Show file tree
Hide file tree
Showing 36 changed files with 593 additions and 363 deletions.
34 changes: 7 additions & 27 deletions Bloxstrap/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public partial class App : Application
)
);

private static bool _showingExceptionDialog = false;

Check warning on line 52 in Bloxstrap/App.xaml.cs

View workflow job for this annotation

GitHub Actions / build (Debug)

The field 'App._showingExceptionDialog' is assigned but its value is never used

Check warning on line 52 in Bloxstrap/App.xaml.cs

View workflow job for this annotation

GitHub Actions / build (Debug)

The field 'App._showingExceptionDialog' is assigned but its value is never used

Check warning on line 52 in Bloxstrap/App.xaml.cs

View workflow job for this annotation

GitHub Actions / build (Debug)

The field 'App._showingExceptionDialog' is assigned but its value is never used

Check warning on line 52 in Bloxstrap/App.xaml.cs

View workflow job for this annotation

GitHub Actions / build (Debug)

The field 'App._showingExceptionDialog' is assigned but its value is never used

public static void Terminate(ErrorCode exitCode = ErrorCode.ERROR_SUCCESS)
{
if (IsFirstRun)
Expand Down Expand Up @@ -85,6 +87,11 @@ public static void FinalizeExceptionHandling(Exception exception, bool log = tru
#if DEBUG
throw exception;
#else
if (_showingExceptionDialog)
return;

_showingExceptionDialog = true;

if (!IsQuiet)
Controls.ShowExceptionDialog(exception);

Expand Down Expand Up @@ -148,33 +155,6 @@ protected override void OnStartup(StartupEventArgs e)
IsUpgrade = true;
}
}

if (!IsMenuLaunch)
{
Logger.WriteLine(LOG_IDENT, "Performing connectivity check...");

try
{
HttpClient.GetAsync("https://detectportal.firefox.com").Wait();
Logger.WriteLine(LOG_IDENT, "Connectivity check finished");
}
catch (Exception ex)
{
Logger.WriteLine(LOG_IDENT, "Connectivity check failed!");
Logger.WriteException(LOG_IDENT, ex);

if (ex.GetType() == typeof(AggregateException))
ex = ex.InnerException!;

Controls.ShowConnectivityDialog(
"the internet",
$"Something may be preventing {ProjectName} from connecting to the internet, or you are currently offline. Please check and try again.",
ex
);

Terminate(ErrorCode.ERROR_CANCELLED);
}
}

using (var checker = new InstallChecker())
{
Expand Down
4 changes: 2 additions & 2 deletions Bloxstrap/Bloxstrap.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<UseWPF>true</UseWPF>
<UseWindowsForms>True</UseWindowsForms>
<ApplicationIcon>Bloxstrap.ico</ApplicationIcon>
<Version>2.5.0</Version>
<FileVersion>2.5.0.0</FileVersion>
<Version>2.5.1</Version>
<FileVersion>2.5.1.0</FileVersion>
<ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>

Expand Down
173 changes: 87 additions & 86 deletions Bloxstrap/Bootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public class Bootstrapper

private string _latestVersionGuid = null!;
private PackageManifest _versionPackageManifest = null!;
private FileManifest _versionFileManifest = null!;
private string _versionFolder = null!;

private bool _isInstalling = false;
Expand Down Expand Up @@ -114,6 +115,39 @@ public async Task Run()
return;
}

// connectivity check

App.Logger.WriteLine(LOG_IDENT, "Performing connectivity check...");

SetStatus("Connecting to Roblox...");

try
{
await RobloxDeployment.GetInfo(RobloxDeployment.DefaultChannel);
}
catch (Exception ex)
{
App.Logger.WriteLine(LOG_IDENT, "Connectivity check failed!");
App.Logger.WriteException(LOG_IDENT, ex);

string message = $"It's possible that something is preventing {App.ProjectName} from connecting to the internet. Please check and try again.";

if (ex.GetType() == typeof(HttpResponseException))
message = "Roblox may be down right now. See status.roblox.com for more information. Please try again later.";
else if (ex.GetType() == typeof(TaskCanceledException))
message = "Bloxstrap timed out when trying to connect to three different Roblox deployment mirrors, indicating a poor internet connection. Please try again later.";
else if (ex.GetType() == typeof(AggregateException))
ex = ex.InnerException!;

Controls.ShowConnectivityDialog("Roblox", message, ex);

App.Terminate(ErrorCode.ERROR_CANCELLED);
}
finally
{
App.Logger.WriteLine(LOG_IDENT, "Connectivity check finished");
}

#if !DEBUG
if (!App.IsFirstRun && App.Settings.Prop.CheckForUpdates)
await CheckForUpdates();
Expand All @@ -126,8 +160,9 @@ public async Task Run()

try
{
Mutex.OpenExisting("Bloxstrap_BootstrapperMutex").Close();
App.Logger.WriteLine(LOG_IDENT, "Bloxstrap_BootstrapperMutex mutex exists, waiting...");
Mutex.OpenExisting("Bloxstrap_SingletonMutex").Close();
App.Logger.WriteLine(LOG_IDENT, "Bloxstrap_SingletonMutex mutex exists, waiting...");
SetStatus("Waiting for other instances...");
mutexExists = true;
}
catch (Exception)
Expand All @@ -136,7 +171,7 @@ public async Task Run()
}

// wait for mutex to be released if it's not yet
await using AsyncMutex mutex = new("Bloxstrap_BootstrapperMutex");
await using var mutex = new AsyncMutex(true, "Bloxstrap_SingletonMutex");
await mutex.AcquireAsync(_cancelTokenSource.Token);

// reload our configs since they've likely changed by now
Expand All @@ -148,8 +183,6 @@ public async Task Run()

await CheckLatestVersion();

CheckInstallMigration();

// install/update roblox if we're running for the first time, needs updating, or the player location doesn't exist
if (App.IsFirstRun || _latestVersionGuid != App.State.Prop.VersionGuid || !File.Exists(_playerLocation))
await InstallLatestVersion();
Expand Down Expand Up @@ -187,25 +220,22 @@ public async Task Run()

private async Task CheckLatestVersion()
{
SetStatus("Connecting to Roblox...");
const string LOG_IDENT = "Bootstrapper::CheckLatestVersion";

ClientVersion clientVersion;

try
{
clientVersion = await RobloxDeployment.GetInfo(App.Settings.Prop.Channel);
}
catch (Exception ex)
catch (HttpResponseException ex)
{
string message = "It's possible that Roblox is being blocked by a firewall. Please check and try again.";

if (ex.GetType() == typeof(HttpResponseException))
message = "Roblox may be down right now. See status.roblox.com for more information. Please try again later.";
if (ex.ResponseMessage.StatusCode != HttpStatusCode.NotFound)
throw;

Controls.ShowConnectivityDialog("Roblox", message, ex);

App.Terminate(ErrorCode.ERROR_CANCELLED);
return;
App.Logger.WriteLine(LOG_IDENT, $"Reverting enrolled channel to {RobloxDeployment.DefaultChannel} because a WindowsPlayer build does not exist for {App.Settings.Prop.Channel}");
App.Settings.Prop.Channel = RobloxDeployment.DefaultChannel;
clientVersion = await RobloxDeployment.GetInfo(App.Settings.Prop.Channel);
}

if (clientVersion.IsBehindDefaultChannel)
Expand Down Expand Up @@ -235,6 +265,7 @@ private async Task CheckLatestVersion()
_latestVersionGuid = clientVersion.VersionGuid;
_versionFolder = Path.Combine(Paths.Versions, _latestVersionGuid);
_versionPackageManifest = await PackageManifest.Get(_latestVersionGuid);
_versionFileManifest = await FileManifest.Get(_latestVersionGuid);
}

private async Task StartRoblox()
Expand Down Expand Up @@ -266,8 +297,12 @@ private async Task StartRoblox()

_launchCommandLine = _launchCommandLine.Replace("LAUNCHTIMEPLACEHOLDER", DateTimeOffset.Now.ToUnixTimeMilliseconds().ToString());

if (App.Settings.Prop.Channel.ToLowerInvariant() != RobloxDeployment.DefaultChannel.ToLowerInvariant())
_launchCommandLine += " -channel " + App.Settings.Prop.Channel.ToLowerInvariant();
_launchCommandLine += " -channel ";

if (App.Settings.Prop.Channel.ToLowerInvariant() == RobloxDeployment.DefaultChannel.ToLowerInvariant())
_launchCommandLine += "production";
else
_launchCommandLine += App.Settings.Prop.Channel.ToLowerInvariant();

// whether we should wait for roblox to exit to handle stuff in the background or clean up after roblox closes
bool shouldWait = false;
Expand Down Expand Up @@ -391,6 +426,8 @@ public void CancelInstall()
App.Logger.WriteException(LOG_IDENT, ex);
}

Dialog?.CloseBootstrapper();

App.Terminate(ErrorCode.ERROR_CANCELLED);
}
#endregion
Expand Down Expand Up @@ -444,71 +481,6 @@ public void RegisterProgramSize()
App.Logger.WriteLine(LOG_IDENT, $"Registered as {totalSize} KB");
}

private void CheckInstallMigration()
{
const string LOG_IDENT = "Bootstrapper::CheckInstallMigration";

// check if we've changed our install location since the last time we started
// in which case, we'll have to copy over all our folders so we don't lose any mods and stuff

using RegistryKey? applicationKey = Registry.CurrentUser.OpenSubKey($@"Software\{App.ProjectName}", true);

string? oldInstallLocation = (string?)applicationKey?.GetValue("OldInstallLocation");

if (applicationKey is null || oldInstallLocation is null || oldInstallLocation == Paths.Base)
return;

SetStatus("Migrating install location...");

if (Directory.Exists(oldInstallLocation))
{
App.Logger.WriteLine(LOG_IDENT, $"Moving all files in {oldInstallLocation} to {Paths.Base}...");

foreach (string oldFileLocation in Directory.GetFiles(oldInstallLocation, "*.*", SearchOption.AllDirectories))
{
string relativeFile = oldFileLocation.Substring(oldInstallLocation.Length + 1);
string newFileLocation = Path.Combine(Paths.Base, relativeFile);
string? newDirectory = Path.GetDirectoryName(newFileLocation);

try
{
if (!String.IsNullOrEmpty(newDirectory))
Directory.CreateDirectory(newDirectory);

File.Move(oldFileLocation, newFileLocation, true);
}
catch (Exception ex)
{
App.Logger.WriteLine(LOG_IDENT, $"Failed to move {oldFileLocation} to {newFileLocation}! {ex}");
}
}

try
{
Directory.Delete(oldInstallLocation, true);
App.Logger.WriteLine(LOG_IDENT, "Deleted old install location");
}
catch (Exception ex)
{
App.Logger.WriteLine(LOG_IDENT, $"Failed to delete old install location! {ex}");
}
}

applicationKey.DeleteValue("OldInstallLocation");

// allow shortcuts to be re-registered
if (Directory.Exists(Paths.StartMenu))
Directory.Delete(Paths.StartMenu, true);

if (File.Exists(DesktopShortcutLocation))
{
File.Delete(DesktopShortcutLocation);
App.Settings.Prop.CreateDesktopIcon = true;
}

App.Logger.WriteLine(LOG_IDENT, "Finished migrating install location!");
}

public static void CheckInstall()
{
const string LOG_IDENT = "Bootstrapper::CheckInstall";
Expand Down Expand Up @@ -713,7 +685,7 @@ private void Uninstall()
// if the folder we're installed to does not end with "Bloxstrap", we're installed to a user-selected folder
// in which case, chances are they chose to install to somewhere they didn't really mean to (prior to the added warning in 2.4.0)
// if so, we're walking on eggshells and have to ensure we only clean up what we need to clean up
bool cautiousUninstall = !Paths.Base.EndsWith(App.ProjectName);
bool cautiousUninstall = !Paths.Base.ToLower().EndsWith(App.ProjectName.ToLower());

var cleanupSequence = new List<Action>
{
Expand Down Expand Up @@ -783,7 +755,7 @@ private void Uninstall()
};
}

Dialog?.ShowSuccess($"{App.ProjectName} has succesfully uninstalled", callback);
Dialog?.ShowSuccess($"{App.ProjectName} has successfully uninstalled", callback);
}
#endregion

Expand Down Expand Up @@ -906,7 +878,16 @@ private async Task InstallLatestVersion()
continue;

App.Logger.WriteLine(LOG_IDENT, $"Removing old version folder for {dir.Name}");
dir.Delete(true);

try
{
dir.Delete(true);
}
catch (Exception ex)
{
App.Logger.WriteLine(LOG_IDENT, "Failed to delete version folder!");
App.Logger.WriteException(LOG_IDENT, ex);
}
}
}
}
Expand Down Expand Up @@ -999,6 +980,12 @@ private async Task ApplyModifications()
{
const string LOG_IDENT = "Bootstrapper::ApplyModifications";

if (Process.GetProcessesByName("RobloxPlayerBeta").Where(x => x.MainModule!.FileName == _playerLocation).Any())
{
App.Logger.WriteLine(LOG_IDENT, "Roblox is running, aborting mod check");
return;
}

SetStatus("Applying Roblox modifications...");

// set executable flags for fullscreen optimizations
Expand Down Expand Up @@ -1332,6 +1319,9 @@ private async Task DownloadPackage(Package package)

for (int i = 1; i <= maxTries; i++)
{
if (_cancelFired)
return;

int totalBytesRead = 0;

try
Expand Down Expand Up @@ -1370,7 +1360,8 @@ private async Task DownloadPackage(Package package)
App.Logger.WriteLine(LOG_IDENT, $"An exception occurred after downloading {totalBytesRead} bytes. ({i}/{maxTries})");
App.Logger.WriteException(LOG_IDENT, ex);

File.Delete(packageLocation);
if (File.Exists(packageLocation))
File.Delete(packageLocation);

if (i >= maxTries)
throw;
Expand Down Expand Up @@ -1415,6 +1406,16 @@ private async Task ExtractPackage(Package package)
if (directory is not null)
Directory.CreateDirectory(directory);

if (File.Exists(extractPath))
{
var fileManifest = _versionFileManifest.FirstOrDefault(x => x.Name == Path.Combine(PackageDirectories[package.Name], entry.FullName));

if (fileManifest is not null && MD5Hash.FromFile(extractPath) == fileManifest.Signature)
continue;

File.Delete(extractPath);
}

entry.ExtractToFile(extractPath, true);
}

Expand Down
Loading

0 comments on commit 8f08495

Please sign in to comment.