summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI.Toolkit/Utilities/FileUtilities.cs
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2019-09-13 17:22:45 -0400
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2019-09-13 17:22:45 -0400
commit125bcbee56bf40cf82abc7fdb502f8cbc18546cf (patch)
tree788997dd4683867b6e32e307c17c855bd7209d98 /src/StardewModdingAPI.Toolkit/Utilities/FileUtilities.cs
parent56726073ba65a018312bcd9db7072381073de315 (diff)
downloadSMAPI-125bcbee56bf40cf82abc7fdb502f8cbc18546cf.tar.gz
SMAPI-125bcbee56bf40cf82abc7fdb502f8cbc18546cf.tar.bz2
SMAPI-125bcbee56bf40cf82abc7fdb502f8cbc18546cf.zip
migrate to new project file format
Diffstat (limited to 'src/StardewModdingAPI.Toolkit/Utilities/FileUtilities.cs')
-rw-r--r--src/StardewModdingAPI.Toolkit/Utilities/FileUtilities.cs46
1 files changed, 0 insertions, 46 deletions
diff --git a/src/StardewModdingAPI.Toolkit/Utilities/FileUtilities.cs b/src/StardewModdingAPI.Toolkit/Utilities/FileUtilities.cs
deleted file mode 100644
index 7856fdb1..00000000
--- a/src/StardewModdingAPI.Toolkit/Utilities/FileUtilities.cs
+++ /dev/null
@@ -1,46 +0,0 @@
-using System.IO;
-using System.Threading;
-
-namespace StardewModdingAPI.Toolkit.Utilities
-{
- /// <summary>Provides utilities for dealing with files.</summary>
- public static class FileUtilities
- {
- /*********
- ** Public methods
- *********/
- /// <summary>Delete a file or folder regardless of file permissions, and block until deletion completes.</summary>
- /// <param name="entry">The file or folder to reset.</param>
- public static void ForceDelete(FileSystemInfo entry)
- {
- // ignore if already deleted
- entry.Refresh();
- if (!entry.Exists)
- return;
-
- // delete children
- if (entry is DirectoryInfo folder)
- {
- foreach (FileSystemInfo child in folder.GetFileSystemInfos())
- FileUtilities.ForceDelete(child);
- }
-
- // reset permissions & delete
- entry.Attributes = FileAttributes.Normal;
- entry.Delete();
-
- // wait for deletion to finish
- for (int i = 0; i < 10; i++)
- {
- entry.Refresh();
- if (entry.Exists)
- Thread.Sleep(500);
- }
-
- // throw exception if deletion didn't happen before timeout
- entry.Refresh();
- if (entry.Exists)
- throw new IOException($"Timed out trying to delete {entry.FullName}");
- }
- }
-}