mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[Globals] Make parallel options easier to use
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
namespace SabreTools.Helper.Data
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SabreTools.Helper.Data
|
||||
{
|
||||
public class Globals
|
||||
{
|
||||
@@ -25,9 +27,18 @@
|
||||
}
|
||||
public static int MaxDegreeOfParallelism
|
||||
{
|
||||
get { return _maxDegreeOfParallelism; }
|
||||
set { _maxDegreeOfParallelism = value; }
|
||||
}
|
||||
public static ParallelOptions ParallelOptions
|
||||
{
|
||||
get
|
||||
{
|
||||
return new ParallelOptions()
|
||||
{
|
||||
MaxDegreeOfParallelism = _maxDegreeOfParallelism
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
@@ -40,14 +40,14 @@ namespace SabreTools.Helper.Dats
|
||||
// First do the initial sort of all of the roms
|
||||
List<string> keys = Keys.ToList();
|
||||
Parallel.ForEach(keys,
|
||||
new ParallelOptions() { MaxDegreeOfParallelism = Globals.MaxDegreeOfParallelism },
|
||||
Globals.ParallelOptions,
|
||||
key =>
|
||||
{
|
||||
List<DatItem> roms = this[key];
|
||||
|
||||
// Now add each of the roms to their respective games
|
||||
Parallel.ForEach(roms,
|
||||
new ParallelOptions() { MaxDegreeOfParallelism = Globals.MaxDegreeOfParallelism },
|
||||
Globals.ParallelOptions,
|
||||
rom =>
|
||||
{
|
||||
string newkey = "";
|
||||
@@ -125,7 +125,7 @@ namespace SabreTools.Helper.Dats
|
||||
// Now go through and sort all of the individual lists
|
||||
keys = sortable.Keys.ToList();
|
||||
Parallel.ForEach(keys,
|
||||
new ParallelOptions() { MaxDegreeOfParallelism = Globals.MaxDegreeOfParallelism },
|
||||
Globals.ParallelOptions,
|
||||
key =>
|
||||
{
|
||||
// Get the possibly unsorted list
|
||||
|
||||
@@ -103,7 +103,7 @@ namespace SabreTools.Helper.Dats
|
||||
// Parse all of the DATs into their own DatFiles in the array
|
||||
Parallel.For(0,
|
||||
inputs.Count,
|
||||
new ParallelOptions { MaxDegreeOfParallelism = Globals.MaxDegreeOfParallelism },
|
||||
Globals.ParallelOptions,
|
||||
i =>
|
||||
{
|
||||
string input = inputs[i];
|
||||
@@ -122,13 +122,13 @@ namespace SabreTools.Helper.Dats
|
||||
|
||||
Globals.Logger.User("Populating internal DAT");
|
||||
Parallel.For(0, inputs.Count,
|
||||
new ParallelOptions() { MaxDegreeOfParallelism = Globals.MaxDegreeOfParallelism },
|
||||
Globals.ParallelOptions,
|
||||
i =>
|
||||
{
|
||||
// Get the list of keys from the DAT
|
||||
List<string> keys = datHeaders[i].Keys.ToList();
|
||||
Parallel.ForEach(keys,
|
||||
new ParallelOptions() { MaxDegreeOfParallelism = Globals.MaxDegreeOfParallelism },
|
||||
Globals.ParallelOptions,
|
||||
key =>
|
||||
{
|
||||
// Add everything from the key to the internal DAT
|
||||
@@ -536,7 +536,7 @@ namespace SabreTools.Helper.Dats
|
||||
SplitType splitType, bool trim, bool single, string root)
|
||||
{
|
||||
Parallel.ForEach(inputFileNames,
|
||||
new ParallelOptions { MaxDegreeOfParallelism = Globals.MaxDegreeOfParallelism },
|
||||
Globals.ParallelOptions,
|
||||
inputFileName =>
|
||||
{
|
||||
// Clean the input string
|
||||
@@ -561,7 +561,7 @@ namespace SabreTools.Helper.Dats
|
||||
inputFileName = Path.GetFullPath(inputFileName) + Path.DirectorySeparatorChar;
|
||||
|
||||
Parallel.ForEach(Directory.EnumerateFiles(inputFileName, "*", SearchOption.AllDirectories),
|
||||
new ParallelOptions { MaxDegreeOfParallelism = Globals.MaxDegreeOfParallelism },
|
||||
Globals.ParallelOptions,
|
||||
file =>
|
||||
{
|
||||
Globals.Logger.User("Processing \"" + Path.GetFullPath(file).Remove(0, inputFileName.Length) + "\"");
|
||||
|
||||
@@ -66,7 +66,7 @@ namespace SabreTools.Helper.Dats
|
||||
// Process the files in the main folder
|
||||
List<string> files = Directory.EnumerateFiles(basePath, "*", SearchOption.TopDirectoryOnly).ToList();
|
||||
Parallel.ForEach(files,
|
||||
new ParallelOptions { MaxDegreeOfParallelism = Globals.MaxDegreeOfParallelism },
|
||||
Globals.ParallelOptions,
|
||||
item =>
|
||||
{
|
||||
PopulateFromDirCheckFile(item, basePath, omitFromScan, bare, archivesAsFiles, enableGzip, addBlanks, addDate,
|
||||
@@ -76,12 +76,12 @@ namespace SabreTools.Helper.Dats
|
||||
// Find all top-level subfolders
|
||||
files = Directory.EnumerateDirectories(basePath, "*", SearchOption.TopDirectoryOnly).ToList();
|
||||
Parallel.ForEach(files,
|
||||
new ParallelOptions { MaxDegreeOfParallelism = Globals.MaxDegreeOfParallelism },
|
||||
Globals.ParallelOptions,
|
||||
item =>
|
||||
{
|
||||
List<string> subfiles = Directory.EnumerateFiles(item, "*", SearchOption.AllDirectories).ToList();
|
||||
Parallel.ForEach(subfiles,
|
||||
new ParallelOptions { MaxDegreeOfParallelism = Globals.MaxDegreeOfParallelism },
|
||||
Globals.ParallelOptions,
|
||||
subitem =>
|
||||
{
|
||||
PopulateFromDirCheckFile(subitem, basePath, omitFromScan, bare, archivesAsFiles, enableGzip, addBlanks, addDate,
|
||||
@@ -98,7 +98,7 @@ namespace SabreTools.Helper.Dats
|
||||
.ToList();
|
||||
|
||||
Parallel.ForEach(empties,
|
||||
new ParallelOptions { MaxDegreeOfParallelism = Globals.MaxDegreeOfParallelism },
|
||||
Globals.ParallelOptions,
|
||||
dir =>
|
||||
{
|
||||
// Get the full path for the directory
|
||||
@@ -260,7 +260,7 @@ namespace SabreTools.Helper.Dats
|
||||
Globals.Logger.Verbose(Path.GetFileName(item) + " treated like an archive");
|
||||
List<string> extracted = Directory.EnumerateFiles(tempSubDir, "*", SearchOption.AllDirectories).ToList();
|
||||
Parallel.ForEach(extracted,
|
||||
new ParallelOptions { MaxDegreeOfParallelism = Globals.MaxDegreeOfParallelism },
|
||||
Globals.ParallelOptions,
|
||||
entry =>
|
||||
{
|
||||
PopulateFromDirProcessFile(entry,
|
||||
@@ -284,7 +284,7 @@ namespace SabreTools.Helper.Dats
|
||||
.ToList();
|
||||
|
||||
Parallel.ForEach(empties,
|
||||
new ParallelOptions { MaxDegreeOfParallelism = Globals.MaxDegreeOfParallelism },
|
||||
Globals.ParallelOptions,
|
||||
dir =>
|
||||
{
|
||||
// Get the full path for the directory
|
||||
|
||||
4
SabreTools.Helper/External/Traverse.cs
vendored
4
SabreTools.Helper/External/Traverse.cs
vendored
@@ -39,7 +39,7 @@ namespace SabreTools.Helper.External
|
||||
subdirs.Clear();
|
||||
|
||||
Parallel.ForEach(dirs,
|
||||
new ParallelOptions() { MaxDegreeOfParallelism = Globals.MaxDegreeOfParallelism },
|
||||
Globals.ParallelOptions,
|
||||
currentDir =>
|
||||
{
|
||||
string[] subDirs = Directory.GetDirectories(currentDir);
|
||||
@@ -57,7 +57,7 @@ namespace SabreTools.Helper.External
|
||||
{
|
||||
FileInfo[] files = dir.GetFiles("*.*", SearchOption.TopDirectoryOnly);
|
||||
Parallel.ForEach(files,
|
||||
new ParallelOptions() { MaxDegreeOfParallelism = Globals.MaxDegreeOfParallelism },
|
||||
Globals.ParallelOptions,
|
||||
info =>
|
||||
{
|
||||
action(info);
|
||||
|
||||
Reference in New Issue
Block a user