diff --git a/SabreTools.Helper/Objects/DATFromDirParallel.cs b/SabreTools.Helper/Objects/DATFromDirParallel.cs index 68bd5ca7..f55b3ebc 100644 --- a/SabreTools.Helper/Objects/DATFromDirParallel.cs +++ b/SabreTools.Helper/Objects/DATFromDirParallel.cs @@ -26,7 +26,7 @@ namespace SabreTools private bool _archivesAsFiles; private bool _enableGzip; private bool _addblanks; - private int _maxParallelism; + private int _maxDegreeOfParallelism; // Other required variables private Logger _logger; @@ -48,14 +48,14 @@ namespace SabreTools /// True if archives should be treated as files, false otherwise /// True if GZIP archives should be treated as files, false otherwise /// Name of the directory to create a temp folder in (blank is current directory) - /// Integer representing the maximum amount of parallelization to be used + /// Integer representing the maximum amount of parallelization to be used /// Logger object for console and file output public DATFromDirParallel(string basePath, Dat datdata, bool noMD5, bool noSHA1, bool bare, - bool archivesAsFiles, bool enableGzip, string tempDir, int maxParallelism, Logger logger) + bool archivesAsFiles, bool enableGzip, string tempDir, int maxDegreeOfParallelism, Logger logger) { _basePath = Path.GetFullPath(basePath); _datdata = datdata; - _datdata.Files.Add("null", new List(10)); + _datdata.Files.Add("null", new List()); _noMD5 = noMD5; _noSHA1 = noSHA1; _bare = bare; @@ -63,11 +63,11 @@ namespace SabreTools _enableGzip = enableGzip; _addblanks = true; _tempDir = tempDir; - _maxParallelism = maxParallelism; + _maxDegreeOfParallelism = maxDegreeOfParallelism; _logger = logger; } - /// + /// /// Process the file, folder, or list of some combination into a DAT file /// /// True if the DAT could be created, false otherwise @@ -97,7 +97,7 @@ namespace SabreTools // Process the files in all subfolders Parallel.ForEach(Directory.EnumerateFiles(_basePath, "*", SearchOption.AllDirectories), - new ParallelOptions { MaxDegreeOfParallelism = _maxParallelism }, + new ParallelOptions { MaxDegreeOfParallelism = _maxDegreeOfParallelism }, item => { ProcessPossibleArchive(item); @@ -107,7 +107,7 @@ namespace SabreTools if (!_datdata.Romba && _addblanks) { Parallel.ForEach(Directory.EnumerateDirectories(_basePath, "*", SearchOption.AllDirectories), - new ParallelOptions { MaxDegreeOfParallelism = _maxParallelism }, + new ParallelOptions { MaxDegreeOfParallelism = _maxDegreeOfParallelism }, dir => { if (Directory.EnumerateFiles(dir, "*", SearchOption.TopDirectoryOnly).Count() == 0) @@ -174,8 +174,15 @@ namespace SabreTools }); } - // Wait for 5 seconds, just to be sure that no handles are open still - Thread.Sleep(5000); + // Now that we're done, delete the temp folder + try + { + Directory.Delete(_tempDir, true); + } + catch + { + // Just absorb the error for now + } return true; } @@ -247,7 +254,7 @@ namespace SabreTools { _logger.Log(Path.GetFileName(item) + " treated like an archive"); Parallel.ForEach(Directory.EnumerateFiles(tempSubDir, "*", SearchOption.AllDirectories), - new ParallelOptions { MaxDegreeOfParallelism = _maxParallelism }, + new ParallelOptions { MaxDegreeOfParallelism = _maxDegreeOfParallelism }, entry => { ProcessFile(entry, tempSubDir, Path.GetFileNameWithoutExtension(item), _datdata); diff --git a/SabreTools/Partials/SabreTools_Inits.cs b/SabreTools/Partials/SabreTools_Inits.cs index abbc7b70..99d9ec3b 100644 --- a/SabreTools/Partials/SabreTools_Inits.cs +++ b/SabreTools/Partials/SabreTools_Inits.cs @@ -441,7 +441,7 @@ namespace SabreTools /// True if archives should be treated as files, false otherwise /// True if GZIP archives should be treated as files, false otherwise /// Name of the directory to create a temp folder in (blank is current directory - /// Integer representing the maximum amount of parallelization to be used + /// Integer representing the maximum amount of parallelization to be used private static void InitDatFromDirParallel(List inputs, string filename, string name, @@ -459,7 +459,7 @@ namespace SabreTools bool archivesAsFiles, bool enableGzip, string tempDir, - int maxParallelism) + int maxDegreeOfParallelism) { // Create a new DATFromDir object and process the inputs Dat datdata = new Dat @@ -484,14 +484,17 @@ namespace SabreTools if (Directory.Exists(path)) { string basePath = Path.GetFullPath(path); - DATFromDirParallel dfd = new DATFromDirParallel(basePath, datdata, noMD5, noSHA1, bare, archivesAsFiles, enableGzip, tempDir, maxParallelism, _logger); + DATFromDirParallel dfd = new DATFromDirParallel(basePath, datdata, noMD5, noSHA1, bare, archivesAsFiles, enableGzip, tempDir, maxDegreeOfParallelism, _logger); bool success = dfd.Start(); - // For DFDParallel only - DatTools.WriteDatfile(dfd.DatData, "", _logger); + // If it was a success, write the DAT out + if (success) + { + DatTools.WriteDatfile(dfd.DatData, "", _logger); + } - // If we failed, show the help - if (!success) + // Otherwise, show the help + else { Console.WriteLine(); Build.Help(); @@ -524,7 +527,7 @@ namespace SabreTools { foreach (string file in Directory.EnumerateFiles(input, "*", SearchOption.AllDirectories)) { - DatTools.SplitByExt(input, outdir, (input.EndsWith(Path.DirectorySeparatorChar.ToString()) ? input : input + Path.DirectorySeparatorChar), extaList, extbList, _logger); + DatTools.SplitByExt(file, outdir, (input.EndsWith(Path.DirectorySeparatorChar.ToString()) ? input : input + Path.DirectorySeparatorChar), extaList, extbList, _logger); } } else @@ -555,7 +558,7 @@ namespace SabreTools { foreach (string file in Directory.EnumerateFiles(input, "*", SearchOption.AllDirectories)) { - DatTools.SplitByHash(input, outdir, (input.EndsWith(Path.DirectorySeparatorChar.ToString()) ? input : input + Path.DirectorySeparatorChar), _logger); + DatTools.SplitByHash(file, outdir, (input.EndsWith(Path.DirectorySeparatorChar.ToString()) ? input : input + Path.DirectorySeparatorChar), _logger); } } else @@ -586,7 +589,7 @@ namespace SabreTools { foreach (string file in Directory.EnumerateFiles(input, "*", SearchOption.AllDirectories)) { - DatTools.SplitByType(input, outdir, (input.EndsWith(Path.DirectorySeparatorChar.ToString()) ? input : input + Path.DirectorySeparatorChar), _logger); + DatTools.SplitByType(file, outdir, (input.EndsWith(Path.DirectorySeparatorChar.ToString()) ? input : input + Path.DirectorySeparatorChar), _logger); } } else