[DatFile, Traverse] Clean up parallel loops

This commit is contained in:
Matt Nadareski
2017-03-17 23:58:35 -07:00
parent 3f6553832b
commit d7eadf66cc
5 changed files with 27 additions and 50 deletions

View File

@@ -98,21 +98,18 @@ namespace SabreTools.Helper.Dats
Globals.Logger.User("Processing individual DATs");
// Parse all of the DATs into their own DatFiles in the array
Parallel.For(0,
inputs.Count,
Globals.ParallelOptions,
i =>
Parallel.For(0, inputs.Count, Globals.ParallelOptions, i =>
{
string input = inputs[i];
Globals.Logger.User("Adding DAT: " + input.Split('¬')[0]);
datHeaders[i] = new DatFile
{
string input = inputs[i];
Globals.Logger.User("Adding DAT: " + input.Split('¬')[0]);
datHeaders[i] = new DatFile
{
DatFormat = (DatFormat != 0 ? DatFormat : 0),
MergeRoms = MergeRoms,
};
DatFormat = (DatFormat != 0 ? DatFormat : 0),
MergeRoms = MergeRoms,
};
datHeaders[i].Parse(input.Split('¬')[0], i, 0, splitType, true, clean, descAsName);
});
datHeaders[i].Parse(input.Split('¬')[0], i, 0, splitType, true, clean, descAsName);
});
Globals.Logger.User("Processing complete in " + DateTime.Now.Subtract(start).ToString(@"hh\:mm\:ss\.fffff"));
@@ -205,7 +202,7 @@ namespace SabreTools.Helper.Dats
{
DatFile[] outDatsArray = new DatFile[inputs.Count];
Parallel.For(0, inputs.Count, j =>
Parallel.For(0, inputs.Count, Globals.ParallelOptions, j =>
{
string innerpost = " (" + Path.GetFileNameWithoutExtension(inputs[j].Split('¬')[0]) + " Only)";
DatFile diffData = new DatFile(this);
@@ -325,7 +322,7 @@ namespace SabreTools.Helper.Dats
DatFile[] outDatsArray = new DatFile[inputs.Count];
Parallel.For(0, inputs.Count, j =>
Parallel.For(0, inputs.Count, Globals.ParallelOptions, j =>
{
string innerpost = " (" + Path.GetFileNameWithoutExtension(inputs[j].Split('¬')[0]) + " Only)";
DatFile diffData;

View File

@@ -65,9 +65,7 @@ namespace SabreTools.Helper.Dats
// Process the files in the main folder
List<string> files = Directory.EnumerateFiles(basePath, "*", SearchOption.TopDirectoryOnly).ToList();
Parallel.ForEach(files,
Globals.ParallelOptions,
item =>
Parallel.ForEach(files, Globals.ParallelOptions, item =>
{
PopulateFromDirCheckFile(item, basePath, omitFromScan, bare, archivesAsFiles, enableGzip, addBlanks, addDate,
tempDir, copyFiles, headerToCheckAgainst);
@@ -75,27 +73,21 @@ namespace SabreTools.Helper.Dats
// Find all top-level subfolders
files = Directory.EnumerateDirectories(basePath, "*", SearchOption.TopDirectoryOnly).ToList();
Parallel.ForEach(files,
Globals.ParallelOptions,
item =>
Parallel.ForEach(files, Globals.ParallelOptions, item =>
{
List<string> subfiles = Directory.EnumerateFiles(item, "*", SearchOption.AllDirectories).ToList();
Parallel.ForEach(subfiles,
Globals.ParallelOptions,
subitem =>
{
PopulateFromDirCheckFile(subitem, basePath, omitFromScan, bare, archivesAsFiles, enableGzip, addBlanks, addDate,
tempDir, copyFiles, headerToCheckAgainst);
});
Parallel.ForEach(subfiles, Globals.ParallelOptions, subitem =>
{
PopulateFromDirCheckFile(subitem, basePath, omitFromScan, bare, archivesAsFiles, enableGzip, addBlanks, addDate,
tempDir, copyFiles, headerToCheckAgainst);
});
});
// Now find all folders that are empty, if we are supposed to
if (!Romba && addBlanks)
{
List<string> empties = FileTools.GetEmptyDirectories(basePath).ToList();
Parallel.ForEach(empties,
Globals.ParallelOptions,
dir =>
Parallel.ForEach(empties, Globals.ParallelOptions, dir =>
{
// Get the full path for the directory
string fulldir = Path.GetFullPath(dir);
@@ -244,9 +236,7 @@ namespace SabreTools.Helper.Dats
if (addBlanks)
{
List<string> empties = ArchiveTools.GetEmptyFoldersInArchive(newItem);
Parallel.ForEach(empties,
Globals.ParallelOptions,
empty =>
Parallel.ForEach(empties, Globals.ParallelOptions, empty =>
{
Rom emptyRom = new Rom(Path.Combine(empty, "_"), newItem, omitFromScan);
PopulateFromDirProcessFileHelper(newItem,

View File

@@ -45,16 +45,12 @@ namespace SabreTools.Helper.Dats
// First do the initial sort of all of the roms
List<string> keys = Keys.ToList();
Parallel.ForEach(keys,
Globals.ParallelOptions,
key =>
Parallel.ForEach(keys, Globals.ParallelOptions, key =>
{
List<DatItem> roms = this[key];
// Now add each of the roms to their respective games
Parallel.ForEach(roms,
Globals.ParallelOptions,
rom =>
Parallel.ForEach(roms, Globals.ParallelOptions, rom =>
{
string newkey = "";
@@ -130,9 +126,7 @@ namespace SabreTools.Helper.Dats
// Now go through and sort all of the individual lists
keys = sortable.Keys.ToList();
Parallel.ForEach(keys,
Globals.ParallelOptions,
key =>
Parallel.ForEach(keys, Globals.ParallelOptions, key =>
{
// Get the possibly unsorted list
List<DatItem> sortedlist = sortable[key];

View File

@@ -51,6 +51,7 @@ namespace SabreTools.Helper.Dats
/// <param name="descAsName">True if descriptions should be used as names, false otherwise (default)</param>
/// <param name="keepext">True if original extension should be kept, false otherwise (default)</param>
/// <param name="useTags">True if tags from the DAT should be used to merge the output, false otherwise (default)</param>
/// TODO: If replacing name with description, is it possible to update cloneof/romof/sampleof tags as well?
public void Parse(
// Standard Dat parsing
string filename,
@@ -1219,7 +1220,6 @@ namespace SabreTools.Helper.Dats
/// <param name="descAsName">True if SL XML names should be kept, false otherwise (default)</param>
/// <remrks>
/// TODO: Software Lists - sharedfeat tag (read-in, write-out)
/// TODO: If replacing name with description, is it possible to update cloneof/romof/sampleof tags as well?
/// </remrks>
private void ParseGenericXML(
// Standard Dat parsing

View File

@@ -38,9 +38,7 @@ namespace SabreTools.Helper.External
}
subdirs.Clear();
Parallel.ForEach(dirs,
Globals.ParallelOptions,
currentDir =>
Parallel.ForEach(dirs, Globals.ParallelOptions, currentDir =>
{
string[] subDirs = Directory.GetDirectories(currentDir);
@@ -56,9 +54,7 @@ namespace SabreTools.Helper.External
try
{
FileInfo[] files = dir.GetFiles("*.*", SearchOption.TopDirectoryOnly);
Parallel.ForEach(files,
Globals.ParallelOptions,
info =>
Parallel.ForEach(files, Globals.ParallelOptions, info =>
{
action(info);
});