mirror of
https://github.com/bloxstraplabs/bloxstrap.git
synced 2025-04-10 15:25:42 -07:00
Improve version cleanup (#4810)
* more safely delete the roblox instance * assertreadonly the whole directory
This commit is contained in:
parent
2acd0162fb
commit
33243bfd0a
@ -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);
|
||||
|
@ -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}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user