[All] Change threading to be global

This commit is contained in:
Matt Nadareski
2017-07-13 17:03:38 -07:00
parent b7b6247ef0
commit 181716fb41
12 changed files with 50 additions and 48 deletions

View File

@@ -112,7 +112,7 @@ namespace SabreTools.Library.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, i =>
{
string input = inputs[i];
Globals.Logger.User("Adding DAT: " + input.Split('¬')[0]);
@@ -128,11 +128,11 @@ namespace SabreTools.Library.Dats
Globals.Logger.User("Processing complete in " + DateTime.Now.Subtract(start).ToString(@"hh\:mm\:ss\.fffff"));
Globals.Logger.User("Populating internal DAT");
Parallel.For(0, inputs.Count, Globals.ParallelOptions, i =>
Parallel.For(0, inputs.Count, i =>
{
// Get the list of keys from the DAT
List<string> keys = datHeaders[i].Keys.ToList();
Parallel.ForEach(keys, Globals.ParallelOptions, key =>
Parallel.ForEach(keys, key =>
{
// Add everything from the key to the internal DAT
AddRange(key, datHeaders[i][key]);
@@ -179,9 +179,7 @@ namespace SabreTools.Library.Dats
Globals.Logger.User("Populating base DAT for comparison...");
List<string> baseFileNames = FileTools.GetOnlyFilesFromInputs(basePaths);
Parallel.ForEach(baseFileNames,
Globals.ParallelOptions,
path =>
Parallel.ForEach(baseFileNames, path =>
{
Parse(path, 0, 0, keep: true, clean: clean, remUnicode: remUnicode, descAsName: descAsName);
});
@@ -193,9 +191,7 @@ namespace SabreTools.Library.Dats
// Now we want to compare each input DAT against the base
List<string> inputFileNames = FileTools.GetOnlyFilesFromInputs(inputPaths, appendparent: true);
Parallel.ForEach(inputFileNames,
Globals.ParallelOptions,
path =>
Parallel.ForEach(inputFileNames, path =>
{
// Get the two halves of the path
string[] splitpath = path.Split('¬');
@@ -211,9 +207,7 @@ namespace SabreTools.Library.Dats
// Then we do a hashwise comparison against the base DAT
List<string> keys = intDat.Keys.ToList();
Parallel.ForEach(keys,
Globals.ParallelOptions,
key =>
Parallel.ForEach(keys, key =>
{
List<DatItem> datItems = intDat[key];
List<DatItem> keepDatItems = new List<DatItem>();
@@ -277,7 +271,7 @@ namespace SabreTools.Library.Dats
DatFile[] outDatsArray = new DatFile[inputs.Count];
Parallel.For(0, inputs.Count, Globals.ParallelOptions, j =>
Parallel.For(0, inputs.Count, j =>
{
string innerpost = " (" + Path.GetFileNameWithoutExtension(inputs[j].Split('¬')[0]) + " Only)";
DatFile diffData;
@@ -307,7 +301,7 @@ namespace SabreTools.Library.Dats
Globals.Logger.User("Populating all output DATs");
List<string> keys = Keys.ToList();
Parallel.ForEach(keys, Globals.ParallelOptions, key =>
Parallel.ForEach(keys, key =>
{
List<DatItem> items = DatItem.Merge(this[key]);
@@ -419,7 +413,7 @@ namespace SabreTools.Library.Dats
{
DatFile[] outDatsArray = new DatFile[inputs.Count];
Parallel.For(0, inputs.Count, Globals.ParallelOptions, j =>
Parallel.For(0, inputs.Count, j =>
{
string innerpost = " (" + Path.GetFileNameWithoutExtension(inputs[j].Split('¬')[0]) + " Only)";
DatFile diffData = new DatFile(this);
@@ -439,7 +433,7 @@ namespace SabreTools.Library.Dats
Globals.Logger.User("Populating all output DATs");
List<string> keys = Keys.ToList();
Parallel.ForEach(keys, Globals.ParallelOptions, key =>
Parallel.ForEach(keys, key =>
{
List<DatItem> items = DatItem.Merge(this[key]);
@@ -537,7 +531,7 @@ namespace SabreTools.Library.Dats
if (Type == "SuperDAT")
{
List<string> keys = Keys.ToList();
Parallel.ForEach(keys, Globals.ParallelOptions, key =>
Parallel.ForEach(keys, key =>
{
List<DatItem> items = this[key].ToList();
List<DatItem> newItems = new List<DatItem>();
@@ -586,7 +580,7 @@ namespace SabreTools.Library.Dats
public void Update(List<string> inputFileNames, string outDir, bool inplace, bool clean, bool remUnicode, bool descAsName,
Filter filter, SplitType splitType, bool trim, bool single, string root)
{
Parallel.ForEach(inputFileNames, Globals.ParallelOptions, inputFileName =>
Parallel.ForEach(inputFileNames, inputFileName =>
{
// Clean the input string
if (inputFileName != "")
@@ -624,7 +618,7 @@ namespace SabreTools.Library.Dats
}
List<string> subFiles = Directory.EnumerateFiles(inputFileName, "*", SearchOption.AllDirectories).ToList();
Parallel.ForEach(subFiles, Globals.ParallelOptions, file =>
Parallel.ForEach(subFiles, file =>
{
Globals.Logger.User("Processing \"" + Path.GetFullPath(file).Remove(0, inputFileName.Length) + "\"");
DatFile innerDatdata = new DatFile(this);

View File

@@ -66,7 +66,7 @@ namespace SabreTools.Library.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, item =>
{
PopulateFromDirCheckFile(item, basePath, omitFromScan, bare, archivesAsFiles, enableGzip, skipFileType,
addBlanks, addDate, tempDir, copyFiles, headerToCheckAgainst);
@@ -74,10 +74,10 @@ namespace SabreTools.Library.Dats
// Find all top-level subfolders
files = Directory.EnumerateDirectories(basePath, "*", SearchOption.TopDirectoryOnly).ToList();
Parallel.ForEach(files, Globals.ParallelOptions, item =>
Parallel.ForEach(files, item =>
{
List<string> subfiles = Directory.EnumerateFiles(item, "*", SearchOption.AllDirectories).ToList();
Parallel.ForEach(subfiles, Globals.ParallelOptions, subitem =>
Parallel.ForEach(subfiles, subitem =>
{
PopulateFromDirCheckFile(subitem, basePath, omitFromScan, bare, archivesAsFiles, enableGzip, skipFileType,
addBlanks, addDate, tempDir, copyFiles, headerToCheckAgainst);
@@ -88,7 +88,7 @@ namespace SabreTools.Library.Dats
if (!Romba && addBlanks)
{
List<string> empties = FileTools.GetEmptyDirectories(basePath).ToList();
Parallel.ForEach(empties, Globals.ParallelOptions, dir =>
Parallel.ForEach(empties, dir =>
{
// Get the full path for the directory
string fulldir = Path.GetFullPath(dir);
@@ -243,7 +243,7 @@ namespace SabreTools.Library.Dats
else
{
// First take care of the found items
Parallel.ForEach(extracted, Globals.ParallelOptions, rom =>
Parallel.ForEach(extracted, rom =>
{
PopulateFromDirProcessFileHelper(newItem,
rom,
@@ -255,7 +255,7 @@ namespace SabreTools.Library.Dats
if (addBlanks)
{
List<string> empties = ArchiveTools.GetEmptyFoldersInArchive(newItem);
Parallel.ForEach(empties, Globals.ParallelOptions, empty =>
Parallel.ForEach(empties, empty =>
{
Rom emptyRom = new Rom(Path.Combine(empty, "_"), newItem, omitFromScan);
PopulateFromDirProcessFileHelper(newItem,

View File

@@ -52,7 +52,7 @@ namespace SabreTools.Library.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, key =>
{
List<DatItem> roms = this[key];
@@ -143,7 +143,7 @@ namespace SabreTools.Library.Dats
// Now go through and sort all of the individual lists
keys = sortable.Keys.ToList();
Parallel.ForEach(keys, Globals.ParallelOptions, key =>
Parallel.ForEach(keys, key =>
{
// Get the possibly unsorted list
List<DatItem> sortedlist = sortable[key];
@@ -183,7 +183,7 @@ namespace SabreTools.Library.Dats
{
// Loop over every key in the dictionary
List<string> keys = Keys.ToList();
Parallel.ForEach(keys, Globals.ParallelOptions, key =>
Parallel.ForEach(keys, key =>
{
// For every item in the current key
List<DatItem> items = this[key];
@@ -235,7 +235,7 @@ namespace SabreTools.Library.Dats
// First we want to get a mapping for all games to description
ConcurrentDictionary<string, string> mapping = new ConcurrentDictionary<string, string>();
List<string> keys = Keys.ToList();
Parallel.ForEach(keys, Globals.ParallelOptions, key =>
Parallel.ForEach(keys, key =>
{
List<DatItem> items = this[key];
foreach (DatItem item in items)
@@ -250,7 +250,7 @@ namespace SabreTools.Library.Dats
// Now we loop through every item and update accordingly
keys = Keys.ToList();
Parallel.ForEach(keys, Globals.ParallelOptions, key =>
Parallel.ForEach(keys, key =>
{
List<DatItem> items = this[key];
List<DatItem> newItems = new List<DatItem>();
@@ -305,7 +305,7 @@ namespace SabreTools.Library.Dats
// Now process all of the roms
List<string> keys = Keys.ToList();
Parallel.ForEach(keys, Globals.ParallelOptions, key =>
Parallel.ForEach(keys, key =>
{
List<DatItem> items = this[key];
for (int j = 0; j < items.Count; j++)

View File

@@ -128,7 +128,7 @@ namespace SabreTools.Library.Dats
// Now loop through and get only directories from the input paths
List<string> directories = new List<string>();
Parallel.ForEach(inputs, Globals.ParallelOptions, input =>
Parallel.ForEach(inputs, input =>
{
// Add to the list if the input is a directory
if (Directory.Exists(input))

View File

@@ -85,7 +85,7 @@ namespace SabreTools.Library.Dats
// Now separate the roms accordingly
List<string> keys = Keys.ToList();
Parallel.ForEach(keys, Globals.ParallelOptions, key =>
Parallel.ForEach(keys, key =>
{
List<DatItem> items = this[key];
foreach (DatItem item in items)
@@ -307,7 +307,7 @@ namespace SabreTools.Library.Dats
// Now populate each of the DAT objects in turn
List<string> keys = Keys.ToList();
Parallel.ForEach(keys, Globals.ParallelOptions, key =>
Parallel.ForEach(keys, key =>
{
List<DatItem> items = this[key];
foreach (DatItem item in items)
@@ -418,7 +418,7 @@ namespace SabreTools.Library.Dats
keys.Sort(SplitByLevelSort);
// Then, we loop over the games
Parallel.ForEach(keys, Globals.ParallelOptions, key =>
Parallel.ForEach(keys, key =>
{
// Here, the key is the name of the game to be used for comparison
if (tempDat.Name != null && tempDat.Name != Style.GetDirectoryName(key))
@@ -584,7 +584,7 @@ namespace SabreTools.Library.Dats
// Now populate each of the DAT objects in turn
List<string> keys = Keys.ToList();
Parallel.ForEach(keys, Globals.ParallelOptions, key =>
Parallel.ForEach(keys, key =>
{
List<DatItem> items = this[key];
foreach(DatItem item in items)

View File

@@ -177,7 +177,7 @@ namespace SabreTools.Library.Dats
// Loop through and add
List<string> keys = Keys.ToList();
Parallel.ForEach(keys, Globals.ParallelOptions, key =>
Parallel.ForEach(keys, key =>
{
List<DatItem> items = this[key];
foreach(DatItem item in items)
@@ -387,7 +387,7 @@ namespace SabreTools.Library.Dats
// Make sure we have all files
List<Tuple<string, string>> newinputs = new List<Tuple<string, string>>(); // item, basepath
Parallel.ForEach(inputs, Globals.ParallelOptions, input =>
Parallel.ForEach(inputs, input =>
{
if (File.Exists(input))
{

View File

@@ -136,7 +136,7 @@ namespace SabreTools.Library.Dats
keys.Sort(new NaturalComparer());
// Write out all required formats
Parallel.ForEach(outfiles.Keys, Globals.ParallelOptions, datFormat =>
Parallel.ForEach(outfiles.Keys, datFormat =>
{
string outfile = outfiles[datFormat];