From 33243bfd0a942de4ad151343f468e9d77e5fc1d3 Mon Sep 17 00:00:00 2001 From: Matt <97983689+bluepilledgreat@users.noreply.github.com> Date: Tue, 11 Mar 2025 11:00:23 +0000 Subject: [PATCH] Improve version cleanup (#4810) * more safely delete the roblox instance * assertreadonly the whole directory --- Bloxstrap/Bootstrapper.cs | 30 +++++++++++++++++++++++++++++- Bloxstrap/Utility/Filesystem.cs | 10 ++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/Bloxstrap/Bootstrapper.cs b/Bloxstrap/Bootstrapper.cs index bc6e36d..3bf0cff 100644 --- a/Bloxstrap/Bootstrapper.cs +++ b/Bloxstrap/Bootstrapper.cs @@ -662,7 +662,28 @@ namespace Bloxstrap #endregion #region Roblox Install - private void CleanupVersionsFolder() + private static bool TryDeleteRobloxInDirectory(string dir) + { + string clientPath = Path.Combine(dir, "RobloxPlayerBeta.exe"); + if (!File.Exists(dir)) + { + clientPath = Path.Combine(dir, "RobloxStudioBeta.exe"); + if (!File.Exists(dir)) + return true; // ok??? + } + + try + { + File.Delete(clientPath); + return true; + } + catch (Exception) + { + return false; + } + } + + public static void CleanupVersionsFolder() { const string LOG_IDENT = "Bootstrapper::CleanupVersionsFolder"; @@ -672,6 +693,13 @@ namespace Bloxstrap if (dirName != App.State.Prop.Player.VersionGuid && dirName != App.State.Prop.Studio.VersionGuid) { + Filesystem.AssertReadOnlyDirectory(dir); + + // check if it's still being used first + // we dont want to accidentally delete the files of a running roblox instance + if (!TryDeleteRobloxInDirectory(dir)) + continue; + try { Directory.Delete(dir, true); diff --git a/Bloxstrap/Utility/Filesystem.cs b/Bloxstrap/Utility/Filesystem.cs index 77bd284..13a9d7f 100644 --- a/Bloxstrap/Utility/Filesystem.cs +++ b/Bloxstrap/Utility/Filesystem.cs @@ -31,5 +31,15 @@ namespace Bloxstrap.Utility fileInfo.IsReadOnly = false; App.Logger.WriteLine("Filesystem::AssertReadOnly", $"The following file was set as read-only: {filePath}"); } + + internal static void AssertReadOnlyDirectory(string directoryPath) + { + var directory = new DirectoryInfo(directoryPath) { Attributes = FileAttributes.Normal }; + + foreach (var info in directory.GetFileSystemInfos("*", SearchOption.AllDirectories)) + info.Attributes = FileAttributes.Normal; + + App.Logger.WriteLine("Filesystem::AssertReadOnlyDirectory", $"The following directory was set as read-only: {directoryPath}"); + } } }