Improve version cleanup (#4810)
Some checks are pending
CI (Debug) / build (push) Waiting to run
CI (Release) / build (push) Waiting to run
CI (Release) / release (push) Blocked by required conditions
CI (Release) / release-test (push) Blocked by required conditions

* more safely delete the roblox instance

* assertreadonly the whole directory
This commit is contained in:
Matt 2025-03-11 11:00:23 +00:00 committed by GitHub
parent 2acd0162fb
commit 33243bfd0a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 39 additions and 1 deletions

View File

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

View File

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