mirror of
https://gitlab.com/cleanflash/installer.git
synced 2026-08-13 19:01:39 +08:00
uninstall: Less aggressive directory deletion
This commit is contained in:
@@ -21,12 +21,12 @@ namespace CleanFlashCommon {
|
||||
}
|
||||
|
||||
public static void RecursiveDelete(DirectoryInfo rootDir, DirectoryInfo baseDir, string filename) {
|
||||
if (!baseDir.Exists) {
|
||||
if (!baseDir.FullName.StartsWith(rootDir.FullName)) {
|
||||
// Sanity check.
|
||||
return;
|
||||
}
|
||||
|
||||
if (!baseDir.FullName.StartsWith(rootDir.FullName)) {
|
||||
// Sanity check.
|
||||
if (!baseDir.Exists) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -44,15 +44,6 @@ namespace CleanFlashCommon {
|
||||
DeleteFile(file);
|
||||
}
|
||||
}
|
||||
|
||||
if (!Directory.EnumerateFileSystemEntries(baseDir.FullName).Any()) {
|
||||
try {
|
||||
baseDir.Delete();
|
||||
} catch {
|
||||
HandleUtil.KillProcessesUsingFile(baseDir.FullName);
|
||||
baseDir.Delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void DeleteFile(FileInfo file) {
|
||||
@@ -77,6 +68,7 @@ namespace CleanFlashCommon {
|
||||
}
|
||||
|
||||
HandleUtil.KillProcessesUsingFile(file.FullName);
|
||||
Thread.Sleep(500);
|
||||
file.Delete();
|
||||
}
|
||||
}
|
||||
@@ -95,6 +87,31 @@ namespace CleanFlashCommon {
|
||||
RecursiveDelete(dirInfo, dirInfo, null);
|
||||
}
|
||||
|
||||
public static void WipeFolder(string baseDir) {
|
||||
DirectoryInfo dirInfo = new DirectoryInfo(baseDir);
|
||||
|
||||
if (!dirInfo.Exists) {
|
||||
return;
|
||||
}
|
||||
|
||||
RecursiveDelete(dirInfo);
|
||||
|
||||
if (!Directory.EnumerateFileSystemEntries(dirInfo.FullName).Any()) {
|
||||
try {
|
||||
dirInfo.Delete();
|
||||
} catch {
|
||||
HandleUtil.KillProcessesUsingFile(dirInfo.FullName);
|
||||
Thread.Sleep(500);
|
||||
|
||||
try {
|
||||
dirInfo.Delete();
|
||||
} catch {
|
||||
// We've tried for long enough...
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void DeleteFile(string file) {
|
||||
DeleteFile(new FileInfo(file));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user