diff --git a/Bloxstrap/App.xaml.cs b/Bloxstrap/App.xaml.cs index d2b785a..fb5ae85 100644 --- a/Bloxstrap/App.xaml.cs +++ b/Bloxstrap/App.xaml.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Globalization; using System.IO; using System.Net.Http; @@ -138,6 +137,8 @@ namespace Bloxstrap if (!IsQuiet) { IsSetupComplete = false; + // we have reshade enabled by default so we need this + FastFlags.SetRenderingMode("Direct3D 11"); new MainWindow().ShowDialog(); } } @@ -194,8 +195,8 @@ namespace Bloxstrap ShowMessageBox($"{ProjectName} is currently running, likely as a background Roblox process. Please note that not all your changes will immediately apply until you close all currently open Roblox instances.", MessageBoxImage.Information); new MainWindow().ShowDialog(); - App.FastFlags.Save(); - } + App.FastFlags.Save(); + } else if (LaunchArgs.Length > 0) { if (LaunchArgs[0].StartsWith("roblox-player:")) @@ -224,11 +225,13 @@ namespace Bloxstrap DeployManager.SetChannel(Settings.Prop.Channel); // start bootstrapper and show the bootstrapper modal if we're not running silently - Bootstrapper bootstrapper = new Bootstrapper(commandLine); + Logger.WriteLine($"[App::OnStartup] Initializing bootstrapper"); + Bootstrapper bootstrapper = new(commandLine); IBootstrapperDialog? dialog = null; if (!IsQuiet) { + Logger.WriteLine($"[App::OnStartup] Initializing bootstrapper dialog"); dialog = Settings.Prop.BootstrapperStyle.GetNew(); bootstrapper.Dialog = dialog; dialog.Bootstrapper = bootstrapper; @@ -251,11 +254,17 @@ namespace Bloxstrap } catch { - // this might be a bit problematic since this mutex will be released when the first launched instance is closed... + // create the singleton mutex before the game client does singletonMutex = new Mutex(true, "ROBLOX_singletonMutex"); } } + // there's a bug here that i have yet to fix! + // sometimes the task just terminates when the bootstrapper hasn't + // actually finished, causing the bootstrapper to hang indefinitely + // i have no idea how the fuck this happens, but it happens like VERY + // rarely so i'm not too concerned by it + // maybe one day ill find out why it happens Task bootstrapperTask = Task.Run(() => bootstrapper.Run()).ContinueWith(t => { Logger.WriteLine("[App::OnStartup] Bootstrapper task has finished"); @@ -279,23 +288,13 @@ namespace Bloxstrap if (singletonMutex is not null) { + Logger.WriteLine($"[App::OnStartup] We have singleton mutex ownership! Running in background until all Roblox processes are closed"); + // we've got ownership of the roblox singleton mutex! // if we stop running, everything will screw up once any more roblox instances launched - // also this code is blehhhh im sure theres a better way of checking if the process count changed like this - - int runningProcesses = -1; - while (runningProcesses != 0) + while (Utilities.GetProcessCount("RobloxPlayerBeta", false) != 0) { - int runningProcessesNow = Utilities.GetProcessCount("RobloxPlayerBeta", false); - - if (runningProcessesNow != runningProcesses) - { - Logger.WriteLine($"[App::OnStartup] We have singleton mutex ownership! Running in background until all Roblox processes are closed ({runningProcessesNow} remaining)..."); - runningProcesses = runningProcessesNow; - } - - // hmm... good idea to do this on main thread? - Task.Delay(5000); + Thread.Sleep(5000); } } } diff --git a/Bloxstrap/Bootstrapper.cs b/Bloxstrap/Bootstrapper.cs index dcf87ad..12ad26d 100644 --- a/Bloxstrap/Bootstrapper.cs +++ b/Bloxstrap/Bootstrapper.cs @@ -182,6 +182,13 @@ namespace Bloxstrap private async Task CheckForUpdates() { + // don't update if there's another instance running (likely running in the background) + if (Utilities.GetProcessCount(App.ProjectName) > 1) + { + App.Logger.WriteLine($"[Bootstrapper::CheckForUpdates] More than one Bloxstrap instance running, aborting update check"); + return; + } + string currentVersion = $"{App.ProjectName} v{App.Version}"; App.Logger.WriteLine($"[Bootstrapper::CheckForUpdates] Checking for {App.ProjectName} updates..."); diff --git a/Bloxstrap/Helpers/Updater.cs b/Bloxstrap/Helpers/Updater.cs index 35f6fe8..0c467c9 100644 --- a/Bloxstrap/Helpers/Updater.cs +++ b/Bloxstrap/Helpers/Updater.cs @@ -2,7 +2,11 @@ using System.Diagnostics; using System.IO; using System.Windows; -using Bloxstrap.Enums; +using System.Windows.Forms; +using System.Threading; +using System.Threading.Tasks; + +using Bloxstrap.Properties; using Bloxstrap.Views; namespace Bloxstrap.Helpers @@ -24,7 +28,6 @@ namespace Bloxstrap.Helpers if (installedVersionInfo.ProductVersion == currentVersionInfo.ProductVersion) return; - MessageBoxResult result; // silently upgrade version if the command line flag is set or if we're launching from an auto update @@ -41,31 +44,71 @@ namespace Bloxstrap.Helpers ); } - if (result != MessageBoxResult.Yes) return; - File.Delete(Directories.Application); + // yes, this is EXTREMELY hacky, but the updater process that launched the + // new version may still be open and so we have to wait for it to close + int attempts = 0; + while (attempts < 10) + { + attempts++; + + try + { + File.Delete(Directories.Application); + break; + } + catch (Exception) + { + if (attempts == 1) + App.Logger.WriteLine("[Updater::CheckInstalledVersion] Waiting for write permissions to update version"); + + Thread.Sleep(500); + } + } + + if (attempts == 10) + { + App.Logger.WriteLine("[Updater::CheckInstalledVersion] Failed to update! (Could not get write permissions after 5 seconds)"); + return; + } + File.Copy(Environment.ProcessPath, Directories.Application); Bootstrapper.Register(); - // make people using progress dialog auto switch over to fluent on upgrade - if (App.Version == "2.0.0" && App.Settings.Prop.BootstrapperStyle == BootstrapperStyle.ProgressDialog) - App.Settings.Prop.BootstrapperStyle = BootstrapperStyle.FluentDialog; + if (isAutoUpgrade) + { + NotifyIcon notification = new() + { + Icon = Resources.IconBloxstrap, + Text = "Bloxstrap", + Visible = true, + BalloonTipTitle = $"Bloxstrap has been upgraded to v{currentVersionInfo.ProductVersion}", + BalloonTipText = "Click here to see what's new in this version" + }; - if (App.IsQuiet || isAutoUpgrade) - return; - - App.ShowMessageBox( - $"{App.ProjectName} has been updated to v{currentVersionInfo.ProductVersion}", - MessageBoxImage.Information, - MessageBoxButton.OK - ); + notification.BalloonTipClicked += (_, _) => Utilities.OpenWebsite($"https://github.com/{App.ProjectRepository}/releases/tag/v{currentVersionInfo.ProductVersion}"); + notification.ShowBalloonTip(30); - //new Preferences().ShowDialog(); - new MainWindow().ShowDialog(); - App.Terminate(); + Task.Run(() => + { + Task.Delay(30000).Wait(); + notification.Dispose(); + }); + } + else if (!App.IsQuiet) + { + App.ShowMessageBox( + $"{App.ProjectName} has been updated to v{currentVersionInfo.ProductVersion}", + MessageBoxImage.Information, + MessageBoxButton.OK + ); + + new MainWindow().ShowDialog(); + App.Terminate(); + } } } } \ No newline at end of file