mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[DatFile, Traverse] Clean up parallel loops
This commit is contained in:
@@ -98,10 +98,7 @@ 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]);
|
||||
@@ -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;
|
||||
|
||||
@@ -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,14 +73,10 @@ 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 =>
|
||||
Parallel.ForEach(subfiles, Globals.ParallelOptions, subitem =>
|
||||
{
|
||||
PopulateFromDirCheckFile(subitem, basePath, omitFromScan, bare, archivesAsFiles, enableGzip, addBlanks, addDate,
|
||||
tempDir, copyFiles, headerToCheckAgainst);
|
||||
@@ -93,9 +87,7 @@ namespace SabreTools.Helper.Dats
|
||||
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,
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -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
|
||||
|
||||
8
SabreTools.Helper/External/Traverse.cs
vendored
8
SabreTools.Helper/External/Traverse.cs
vendored
@@ -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);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user