mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[DATFromDir] Add async delete
This commit is contained in:
@@ -190,18 +190,7 @@ namespace SabreTools
|
|||||||
new ParallelOptions { MaxDegreeOfParallelism = _maxDegreeOfParallelism },
|
new ParallelOptions { MaxDegreeOfParallelism = _maxDegreeOfParallelism },
|
||||||
file =>
|
file =>
|
||||||
{
|
{
|
||||||
int i = 0;
|
FileTools.DeleteFile(file);
|
||||||
while (File.Exists(file) && i < 50)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Directory.Delete(Path.GetDirectoryName(file), true);
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -320,22 +309,7 @@ namespace SabreTools
|
|||||||
// Cue to delete the file if it's a copy
|
// Cue to delete the file if it's a copy
|
||||||
if (_copyFiles)
|
if (_copyFiles)
|
||||||
{
|
{
|
||||||
int i = 0;
|
FileTools.DeleteFile(newItem);
|
||||||
while (File.Exists(newItem) && i < 50)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Directory.Delete(Path.GetDirectoryName(newItem), true);
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (File.Exists(newItem))
|
|
||||||
{
|
|
||||||
_clean.Add(newItem);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete the sub temp directory
|
// Delete the sub temp directory
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ using System.IO.Compression;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace SabreTools.Helper
|
namespace SabreTools.Helper
|
||||||
{
|
{
|
||||||
@@ -1237,6 +1238,29 @@ namespace SabreTools.Helper
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Delete a file asynchronously
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="filename">Name of the file to be deleted</param>
|
||||||
|
public async static void DeleteFile(string filename)
|
||||||
|
{
|
||||||
|
FileInfo fi = new FileInfo(filename);
|
||||||
|
await Task.Factory.StartNew(() =>
|
||||||
|
{
|
||||||
|
while (fi.Exists)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
fi.Delete();
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user