Improve how updating Roblox is handled

fixes the problem of the versions folder not being properly cleaned out

also instead of skipping the roblox update process if multiple instances are running, continue with the update process but don't delete any older versions when finished
This commit is contained in:
pizzaboxer 2023-06-12 16:49:14 +01:00
parent 3926f30866
commit 09ad916236
No known key found for this signature in database
GPG Key ID: 59D4A1DBAD0F2BA8
3 changed files with 25 additions and 15 deletions

View File

@ -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!;

View File

@ -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"))
{
@ -818,11 +807,26 @@ namespace Bloxstrap
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();

View File

@ -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);