Skip to content
This repository has been archived by the owner on Aug 7, 2022. It is now read-only.

Commit

Permalink
Added ClearTempDir functions
Browse files Browse the repository at this point in the history
  • Loading branch information
erri120 committed Nov 28, 2019
1 parent a372b01 commit 915269e
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions OMODExtraction/Framework.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,36 @@ public class OMODFrameworkException : ApplicationException
{
public OMODFrameworkException(string s) : base(s) { }
}

/// <summary>
/// Convenience function that will clean the entire temp folder for you
/// </summary>
/// <param name="deleteRoot">Whether to delete the folder itself</param>
public static void CleanTempDir(bool deleteRoot = false)
{
if(!Directory.Exists(TempDir))
return;

var dInfo = new DirectoryInfo(TempDir);
dInfo.GetFiles().Do(f =>
{
if (!f.Exists || f.IsReadOnly)
return;

try
{
f.Delete();
}
catch
{
// ignored
}

});
dInfo.GetDirectories().Do(d => {if(d.Exists && !d.Attributes.HasFlag(FileAttributes.ReadOnly)) d.Delete(true);});

if(deleteRoot)
Directory.Delete(TempDir);
}
}
}

0 comments on commit 915269e

Please sign in to comment.