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");
|
Globals.Logger.User("Processing individual DATs");
|
||||||
|
|
||||||
// Parse all of the DATs into their own DatFiles in the array
|
// Parse all of the DATs into their own DatFiles in the array
|
||||||
Parallel.For(0,
|
Parallel.For(0, inputs.Count, Globals.ParallelOptions, i =>
|
||||||
inputs.Count,
|
|
||||||
Globals.ParallelOptions,
|
|
||||||
i =>
|
|
||||||
{
|
{
|
||||||
string input = inputs[i];
|
string input = inputs[i];
|
||||||
Globals.Logger.User("Adding DAT: " + input.Split('¬')[0]);
|
Globals.Logger.User("Adding DAT: " + input.Split('¬')[0]);
|
||||||
@@ -205,7 +202,7 @@ namespace SabreTools.Helper.Dats
|
|||||||
{
|
{
|
||||||
DatFile[] outDatsArray = new DatFile[inputs.Count];
|
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)";
|
string innerpost = " (" + Path.GetFileNameWithoutExtension(inputs[j].Split('¬')[0]) + " Only)";
|
||||||
DatFile diffData = new DatFile(this);
|
DatFile diffData = new DatFile(this);
|
||||||
@@ -325,7 +322,7 @@ namespace SabreTools.Helper.Dats
|
|||||||
|
|
||||||
DatFile[] outDatsArray = new DatFile[inputs.Count];
|
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)";
|
string innerpost = " (" + Path.GetFileNameWithoutExtension(inputs[j].Split('¬')[0]) + " Only)";
|
||||||
DatFile diffData;
|
DatFile diffData;
|
||||||
|
|||||||
@@ -65,9 +65,7 @@ namespace SabreTools.Helper.Dats
|
|||||||
|
|
||||||
// Process the files in the main folder
|
// Process the files in the main folder
|
||||||
List<string> files = Directory.EnumerateFiles(basePath, "*", SearchOption.TopDirectoryOnly).ToList();
|
List<string> files = Directory.EnumerateFiles(basePath, "*", SearchOption.TopDirectoryOnly).ToList();
|
||||||
Parallel.ForEach(files,
|
Parallel.ForEach(files, Globals.ParallelOptions, item =>
|
||||||
Globals.ParallelOptions,
|
|
||||||
item =>
|
|
||||||
{
|
{
|
||||||
PopulateFromDirCheckFile(item, basePath, omitFromScan, bare, archivesAsFiles, enableGzip, addBlanks, addDate,
|
PopulateFromDirCheckFile(item, basePath, omitFromScan, bare, archivesAsFiles, enableGzip, addBlanks, addDate,
|
||||||
tempDir, copyFiles, headerToCheckAgainst);
|
tempDir, copyFiles, headerToCheckAgainst);
|
||||||
@@ -75,14 +73,10 @@ namespace SabreTools.Helper.Dats
|
|||||||
|
|
||||||
// Find all top-level subfolders
|
// Find all top-level subfolders
|
||||||
files = Directory.EnumerateDirectories(basePath, "*", SearchOption.TopDirectoryOnly).ToList();
|
files = Directory.EnumerateDirectories(basePath, "*", SearchOption.TopDirectoryOnly).ToList();
|
||||||
Parallel.ForEach(files,
|
Parallel.ForEach(files, Globals.ParallelOptions, item =>
|
||||||
Globals.ParallelOptions,
|
|
||||||
item =>
|
|
||||||
{
|
{
|
||||||
List<string> subfiles = Directory.EnumerateFiles(item, "*", SearchOption.AllDirectories).ToList();
|
List<string> subfiles = Directory.EnumerateFiles(item, "*", SearchOption.AllDirectories).ToList();
|
||||||
Parallel.ForEach(subfiles,
|
Parallel.ForEach(subfiles, Globals.ParallelOptions, subitem =>
|
||||||
Globals.ParallelOptions,
|
|
||||||
subitem =>
|
|
||||||
{
|
{
|
||||||
PopulateFromDirCheckFile(subitem, basePath, omitFromScan, bare, archivesAsFiles, enableGzip, addBlanks, addDate,
|
PopulateFromDirCheckFile(subitem, basePath, omitFromScan, bare, archivesAsFiles, enableGzip, addBlanks, addDate,
|
||||||
tempDir, copyFiles, headerToCheckAgainst);
|
tempDir, copyFiles, headerToCheckAgainst);
|
||||||
@@ -93,9 +87,7 @@ namespace SabreTools.Helper.Dats
|
|||||||
if (!Romba && addBlanks)
|
if (!Romba && addBlanks)
|
||||||
{
|
{
|
||||||
List<string> empties = FileTools.GetEmptyDirectories(basePath).ToList();
|
List<string> empties = FileTools.GetEmptyDirectories(basePath).ToList();
|
||||||
Parallel.ForEach(empties,
|
Parallel.ForEach(empties, Globals.ParallelOptions, dir =>
|
||||||
Globals.ParallelOptions,
|
|
||||||
dir =>
|
|
||||||
{
|
{
|
||||||
// Get the full path for the directory
|
// Get the full path for the directory
|
||||||
string fulldir = Path.GetFullPath(dir);
|
string fulldir = Path.GetFullPath(dir);
|
||||||
@@ -244,9 +236,7 @@ namespace SabreTools.Helper.Dats
|
|||||||
if (addBlanks)
|
if (addBlanks)
|
||||||
{
|
{
|
||||||
List<string> empties = ArchiveTools.GetEmptyFoldersInArchive(newItem);
|
List<string> empties = ArchiveTools.GetEmptyFoldersInArchive(newItem);
|
||||||
Parallel.ForEach(empties,
|
Parallel.ForEach(empties, Globals.ParallelOptions, empty =>
|
||||||
Globals.ParallelOptions,
|
|
||||||
empty =>
|
|
||||||
{
|
{
|
||||||
Rom emptyRom = new Rom(Path.Combine(empty, "_"), newItem, omitFromScan);
|
Rom emptyRom = new Rom(Path.Combine(empty, "_"), newItem, omitFromScan);
|
||||||
PopulateFromDirProcessFileHelper(newItem,
|
PopulateFromDirProcessFileHelper(newItem,
|
||||||
|
|||||||
@@ -45,16 +45,12 @@ namespace SabreTools.Helper.Dats
|
|||||||
|
|
||||||
// First do the initial sort of all of the roms
|
// First do the initial sort of all of the roms
|
||||||
List<string> keys = Keys.ToList();
|
List<string> keys = Keys.ToList();
|
||||||
Parallel.ForEach(keys,
|
Parallel.ForEach(keys, Globals.ParallelOptions, key =>
|
||||||
Globals.ParallelOptions,
|
|
||||||
key =>
|
|
||||||
{
|
{
|
||||||
List<DatItem> roms = this[key];
|
List<DatItem> roms = this[key];
|
||||||
|
|
||||||
// Now add each of the roms to their respective games
|
// Now add each of the roms to their respective games
|
||||||
Parallel.ForEach(roms,
|
Parallel.ForEach(roms, Globals.ParallelOptions, rom =>
|
||||||
Globals.ParallelOptions,
|
|
||||||
rom =>
|
|
||||||
{
|
{
|
||||||
string newkey = "";
|
string newkey = "";
|
||||||
|
|
||||||
@@ -130,9 +126,7 @@ namespace SabreTools.Helper.Dats
|
|||||||
|
|
||||||
// Now go through and sort all of the individual lists
|
// Now go through and sort all of the individual lists
|
||||||
keys = sortable.Keys.ToList();
|
keys = sortable.Keys.ToList();
|
||||||
Parallel.ForEach(keys,
|
Parallel.ForEach(keys, Globals.ParallelOptions, key =>
|
||||||
Globals.ParallelOptions,
|
|
||||||
key =>
|
|
||||||
{
|
{
|
||||||
// Get the possibly unsorted list
|
// Get the possibly unsorted list
|
||||||
List<DatItem> sortedlist = sortable[key];
|
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="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="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>
|
/// <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(
|
public void Parse(
|
||||||
// Standard Dat parsing
|
// Standard Dat parsing
|
||||||
string filename,
|
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>
|
/// <param name="descAsName">True if SL XML names should be kept, false otherwise (default)</param>
|
||||||
/// <remrks>
|
/// <remrks>
|
||||||
/// TODO: Software Lists - sharedfeat tag (read-in, write-out)
|
/// 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>
|
/// </remrks>
|
||||||
private void ParseGenericXML(
|
private void ParseGenericXML(
|
||||||
// Standard Dat parsing
|
// 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();
|
subdirs.Clear();
|
||||||
|
|
||||||
Parallel.ForEach(dirs,
|
Parallel.ForEach(dirs, Globals.ParallelOptions, currentDir =>
|
||||||
Globals.ParallelOptions,
|
|
||||||
currentDir =>
|
|
||||||
{
|
{
|
||||||
string[] subDirs = Directory.GetDirectories(currentDir);
|
string[] subDirs = Directory.GetDirectories(currentDir);
|
||||||
|
|
||||||
@@ -56,9 +54,7 @@ namespace SabreTools.Helper.External
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
FileInfo[] files = dir.GetFiles("*.*", SearchOption.TopDirectoryOnly);
|
FileInfo[] files = dir.GetFiles("*.*", SearchOption.TopDirectoryOnly);
|
||||||
Parallel.ForEach(files,
|
Parallel.ForEach(files, Globals.ParallelOptions, info =>
|
||||||
Globals.ParallelOptions,
|
|
||||||
info =>
|
|
||||||
{
|
{
|
||||||
action(info);
|
action(info);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user