mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[DatFile, FileTypes/, Utilities] GUID, but correct
This commit is contained in:
@@ -3649,9 +3649,9 @@ namespace SabreTools.Library.DatFiles
|
||||
string newBasePath = basePath;
|
||||
if (copyFiles)
|
||||
{
|
||||
newBasePath = Path.Combine(tempDir, new Guid().ToString());
|
||||
newBasePath = Path.Combine(tempDir, Guid.NewGuid().ToString());
|
||||
newItem = Path.GetFullPath(Path.Combine(newBasePath, Path.GetFullPath(item).Remove(0, basePath.Length + 1)));
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(newItem));
|
||||
Utilities.TryCreateDirectory(Path.GetDirectoryName(newItem));
|
||||
File.Copy(item, newItem, true);
|
||||
}
|
||||
|
||||
|
||||
@@ -395,7 +395,7 @@ namespace SabreTools.Library.FileTypes
|
||||
};
|
||||
|
||||
// Create the temp directory
|
||||
string tempPath = Path.Combine(outDir, new Guid().ToString());
|
||||
string tempPath = Path.Combine(outDir, Guid.NewGuid().ToString());
|
||||
if (!Directory.Exists(tempPath))
|
||||
{
|
||||
Directory.CreateDirectory(tempPath);
|
||||
@@ -608,7 +608,7 @@ namespace SabreTools.Library.FileTypes
|
||||
keys.Sort(ZipFile.TorrentZipStringCompare);
|
||||
|
||||
// Create the temp directory
|
||||
string tempPath = Path.Combine(outDir, new Guid().ToString());
|
||||
string tempPath = Path.Combine(outDir, Guid.NewGuid().ToString());
|
||||
if (!Directory.Exists(tempPath))
|
||||
{
|
||||
Directory.CreateDirectory(tempPath);
|
||||
|
||||
@@ -289,7 +289,7 @@ namespace SabreTools.Library.FileTypes
|
||||
};
|
||||
|
||||
// Create the temp directory
|
||||
string tempPath = Path.Combine(outDir, new Guid().ToString());
|
||||
string tempPath = Path.Combine(outDir, Guid.NewGuid().ToString());
|
||||
if (!Directory.Exists(tempPath))
|
||||
{
|
||||
Directory.CreateDirectory(tempPath);
|
||||
@@ -502,7 +502,7 @@ namespace SabreTools.Library.FileTypes
|
||||
keys.Sort(ZipFile.TorrentZipStringCompare);
|
||||
|
||||
// Create the temp directory
|
||||
string tempPath = Path.Combine(outDir, new Guid().ToString());
|
||||
string tempPath = Path.Combine(outDir, Guid.NewGuid().ToString());
|
||||
if (!Directory.Exists(tempPath))
|
||||
{
|
||||
Directory.CreateDirectory(tempPath);
|
||||
|
||||
@@ -1775,6 +1775,33 @@ namespace SabreTools.Library.Tools
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Try to safely delete a directory, optionally throwing the error
|
||||
/// </summary>
|
||||
/// <param name="file">Name of the directory to delete</param>
|
||||
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
|
||||
/// <returns>True if the file didn't exist or could be deleted, false otherwise</returns>
|
||||
public static bool TryCreateDirectory(string file, bool throwOnError = false)
|
||||
{
|
||||
// Now wrap creating the directory
|
||||
try
|
||||
{
|
||||
Directory.CreateDirectory(file);
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (throwOnError)
|
||||
{
|
||||
throw ex;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Try to safely delete a directory, optionally throwing the error
|
||||
/// </summary>
|
||||
@@ -1783,13 +1810,13 @@ namespace SabreTools.Library.Tools
|
||||
/// <returns>True if the file didn't exist or could be deleted, false otherwise</returns>
|
||||
public static bool TryDeleteDirectory(string file, bool throwOnError = false)
|
||||
{
|
||||
// Check if the file exists first
|
||||
// Check if the directory exists first
|
||||
if (!Directory.Exists(file))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// Now wrap deleting the file
|
||||
// Now wrap deleting the directory
|
||||
try
|
||||
{
|
||||
Directory.Delete(file, true);
|
||||
|
||||
Reference in New Issue
Block a user