diff --git a/Bloxstrap/App.xaml.cs b/Bloxstrap/App.xaml.cs index a16478d..d49ad31 100644 --- a/Bloxstrap/App.xaml.cs +++ b/Bloxstrap/App.xaml.cs @@ -30,6 +30,7 @@ namespace Bloxstrap public const string ProjectName = "Bloxstrap"; public const string ProjectRepository = "pizzaboxer/bloxstrap"; + public const string RobloxAppName = "RobloxPlayerBeta"; // used only for communicating between app and menu - use Directories.Base for anything else public static string BaseDirectory = null!; diff --git a/Bloxstrap/Bootstrapper.cs b/Bloxstrap/Bootstrapper.cs index 3da54e1..7cf2a02 100644 --- a/Bloxstrap/Bootstrapper.cs +++ b/Bloxstrap/Bootstrapper.cs @@ -168,15 +168,10 @@ namespace Bloxstrap CheckInstallMigration(); - // only update roblox if we're running for the first time, or if - // roblox isn't running and our version guid is out of date, or the player exe doesn't exist - if (App.IsFirstRun || !Utilities.CheckIfRobloxRunning() && (_latestVersionGuid != App.State.Prop.VersionGuid || !File.Exists(_playerLocation))) + // 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(); - // last time the version folder was set, it was set to the latest version guid - // but if we skipped updating because roblox is already running, we want it to be set to our current version - _versionFolder = Path.Combine(Directories.Versions, App.State.Prop.VersionGuid); - if (App.IsFirstRun) App.ShouldSaveConfigs = true; @@ -792,19 +787,13 @@ namespace Bloxstrap { if (!_versionPackageManifest.Exists(package => filename.Contains(package.Signature))) { - App.Logger.WriteLine($"Deleting unused package {filename}"); + App.Logger.WriteLine($"[Bootstrapper::InstallLatestVersion] Deleting unused package {filename}"); File.Delete(filename); } } string oldVersionFolder = Path.Combine(Directories.Versions, App.State.Prop.VersionGuid); - if (_latestVersionGuid != App.State.Prop.VersionGuid && Directory.Exists(oldVersionFolder)) - { - // and also to delete our old version folder - Directory.Delete(oldVersionFolder, true); - } - // move old compatibility flags for the old location using (RegistryKey appFlagsKey = Registry.CurrentUser.CreateSubKey($"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\AppCompatFlags\\Layers")) { @@ -817,12 +806,27 @@ namespace Bloxstrap appFlagsKey.SetValue(_playerLocation, appFlags); appFlagsKey.DeleteValue(oldGameClientLocation); } + } + + // delete any old version folders + // we only do this if roblox isnt running just in case an update happened + // while they were launching a second instance or something idk + if (!Process.GetProcessesByName(App.RobloxAppName).Any()) + { + foreach (DirectoryInfo dir in new DirectoryInfo(Directories.Versions).GetDirectories()) + { + if (dir.Name == _latestVersionGuid || !dir.Name.StartsWith("version-")) + continue; + + App.Logger.WriteLine($"[Bootstrapper::InstallLatestVersion] Removing old version folder for {dir.Name}"); + dir.Delete(true); + } } } App.State.Prop.VersionGuid = _latestVersionGuid; - // don't register program size until the program is registered + // don't register program size until the program is registered, which will be done after this if (!App.IsFirstRun && !FreshInstall) RegisterProgramSize(); diff --git a/Bloxstrap/Singletons/Logger.cs b/Bloxstrap/Singletons/Logger.cs index 97a5350..190f8b5 100644 --- a/Bloxstrap/Singletons/Logger.cs +++ b/Bloxstrap/Singletons/Logger.cs @@ -8,6 +8,11 @@ using System.Threading; namespace Bloxstrap.Singletons { // https://stackoverflow.com/a/53873141/11852173 + // TODO - this kind of sucks + // the main problem is just that this doesn't finish writing log entries before exiting the program + // this can be solved by making writetolog completely synchronous, but while it doesn't affect performance, its's not ideal + // also, writing and flushing for every single line that's written may not be great + public class Logger { private readonly SemaphoreSlim _semaphore = new(1, 1);