Skip to content

Commit 4fa9aa3

Browse files
committed
Fix crash when trying to delete a file/folder that's open
1 parent 80689ee commit 4fa9aa3

1 file changed

Lines changed: 13 additions & 9 deletions

File tree

src/Common.cs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -316,20 +316,24 @@ public static void SyncManager(bool setCheckState = false)
316316
// Deletes a file as well as any directories made empty by its deletion
317317
public static void DeleteFileAndDirectories(string file)
318318
{
319-
if (File.Exists(file)) File.Delete(file);
319+
try
320+
{
321+
if (File.Exists(file)) File.Delete(file);
320322

321-
string folder = Path.GetDirectoryName(file);
323+
string folder = Path.GetDirectoryName(file);
322324

323-
while (folder != SourcePath)
324-
{
325-
if (Directory.Exists(folder) && !Directory.EnumerateFileSystemEntries(folder).Any())
325+
while (folder != SourcePath)
326326
{
327-
Directory.Delete(folder, false);
328-
}
329-
else break;
327+
if (Directory.Exists(folder) && !Directory.EnumerateFileSystemEntries(folder).Any())
328+
{
329+
Directory.Delete(folder, false);
330+
}
331+
else break;
330332

331-
folder = Directory.GetParent(folder).ToString();
333+
folder = Directory.GetParent(folder).ToString();
334+
}
332335
}
336+
catch { }
333337
}
334338

335339
// Checks if specified Flashpoint destination path is valid, and optionally updates its respective textbox

0 commit comments

Comments
 (0)