[fix] 修复BashUtil.RemoveDir的bug

main
walon 2023-11-02 10:47:55 +08:00
parent 84ed2e6b9d
commit 94a329a522
1 changed files with 13 additions and 6 deletions

View File

@ -64,20 +64,27 @@ namespace HybridCLR.Editor.Installer
{ {
UnityEngine.Debug.Log($"[BashUtil] RemoveDir dir:{dir}"); UnityEngine.Debug.Log($"[BashUtil] RemoveDir dir:{dir}");
} }
if (!Directory.Exists(dir))
{
return;
}
int maxTryCount = 5; int maxTryCount = 5;
for (int i = 0; i < maxTryCount; ++i) for (int i = 0; i < maxTryCount; ++i)
{ {
try try
{ {
if (Directory.Exists(dir)) if (!Directory.Exists(dir))
{ {
Directory.Delete(dir, true); return;
} }
foreach (var file in Directory.GetFiles(dir))
{
File.SetAttributes(file, FileAttributes.Normal);
File.Delete(file);
}
foreach (var subDir in Directory.GetDirectories(dir))
{
RemoveDir(subDir);
}
Directory.Delete(dir);
break;
} }
catch (Exception e) catch (Exception e)
{ {