mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[DatFile] Parallel hunting
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
using System;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Generic;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
using SabreTools.Helper.Data;
|
using SabreTools.Helper.Data;
|
||||||
|
|
||||||
@@ -460,10 +460,10 @@ namespace SabreTools.Helper.Dats
|
|||||||
lock (_files)
|
lock (_files)
|
||||||
{
|
{
|
||||||
int count = 0;
|
int count = 0;
|
||||||
foreach (string key in _files.Keys)
|
Parallel.ForEach(_files.Keys, Globals.ParallelOptions, key =>
|
||||||
{
|
{
|
||||||
count += _files[key].Count;
|
count += _files[key].Count;
|
||||||
}
|
});
|
||||||
|
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -221,30 +221,36 @@ namespace SabreTools.Helper.Dats
|
|||||||
// Now, loop through the dictionary and populate the correct DATs
|
// Now, loop through the dictionary and populate the correct DATs
|
||||||
start = DateTime.Now;
|
start = DateTime.Now;
|
||||||
Globals.Logger.User("Populating all output DATs");
|
Globals.Logger.User("Populating all output DATs");
|
||||||
List<string> keys = Keys.ToList();
|
|
||||||
foreach (string key in keys)
|
|
||||||
{
|
|
||||||
List<DatItem> roms = DatItem.Merge(this[key]);
|
|
||||||
|
|
||||||
if (roms != null && roms.Count > 0)
|
List<string> keys = Keys.ToList();
|
||||||
|
Parallel.ForEach(keys, Globals.ParallelOptions, key =>
|
||||||
{
|
{
|
||||||
foreach (DatItem rom in roms)
|
List<DatItem> items = DatItem.Merge(this[key]);
|
||||||
|
|
||||||
|
// If the rom list is empty or null, just skip it
|
||||||
|
if (items == null || items.Count == 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Loop through and add the items correctly
|
||||||
|
Parallel.ForEach(items, Globals.ParallelOptions, item =>
|
||||||
{
|
{
|
||||||
// No duplicates
|
// No duplicates
|
||||||
if ((diff & DiffMode.NoDupes) != 0 || (diff & DiffMode.Individuals) != 0)
|
if ((diff & DiffMode.NoDupes) != 0 || (diff & DiffMode.Individuals) != 0)
|
||||||
{
|
{
|
||||||
if ((rom.Dupe & DupeType.Internal) != 0)
|
if ((item.Dupe & DupeType.Internal) != 0)
|
||||||
{
|
{
|
||||||
// Individual DATs that are output
|
// Individual DATs that are output
|
||||||
if ((diff & DiffMode.Individuals) != 0)
|
if ((diff & DiffMode.Individuals) != 0)
|
||||||
{
|
{
|
||||||
outDats[rom.SystemID].Add(key, rom);
|
outDats[item.SystemID].Add(key, item);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Merged no-duplicates DAT
|
// Merged no-duplicates DAT
|
||||||
if ((diff & DiffMode.NoDupes) != 0)
|
if ((diff & DiffMode.NoDupes) != 0)
|
||||||
{
|
{
|
||||||
DatItem newrom = rom;
|
DatItem newrom = item;
|
||||||
newrom.Machine.Name += " (" + Path.GetFileNameWithoutExtension(inputs[newrom.SystemID].Split('¬')[0]) + ")";
|
newrom.Machine.Name += " (" + Path.GetFileNameWithoutExtension(inputs[newrom.SystemID].Split('¬')[0]) + ")";
|
||||||
|
|
||||||
outerDiffData.Add(key, newrom);
|
outerDiffData.Add(key, newrom);
|
||||||
@@ -255,17 +261,17 @@ namespace SabreTools.Helper.Dats
|
|||||||
// Duplicates only
|
// Duplicates only
|
||||||
if ((diff & DiffMode.Dupes) != 0)
|
if ((diff & DiffMode.Dupes) != 0)
|
||||||
{
|
{
|
||||||
if ((rom.Dupe & DupeType.External) != 0)
|
if ((item.Dupe & DupeType.External) != 0)
|
||||||
{
|
{
|
||||||
DatItem newrom = rom;
|
DatItem newrom = item;
|
||||||
newrom.Machine.Name += " (" + Path.GetFileNameWithoutExtension(inputs[newrom.SystemID].Split('¬')[0]) + ")";
|
newrom.Machine.Name += " (" + Path.GetFileNameWithoutExtension(inputs[newrom.SystemID].Split('¬')[0]) + ")";
|
||||||
|
|
||||||
dupeData.Add(key, newrom);
|
dupeData.Add(key, newrom);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
}
|
});
|
||||||
}
|
|
||||||
Globals.Logger.User("Populating complete in " + DateTime.Now.Subtract(start).ToString(@"hh\:mm\:ss\.fffff"));
|
Globals.Logger.User("Populating complete in " + DateTime.Now.Subtract(start).ToString(@"hh\:mm\:ss\.fffff"));
|
||||||
|
|
||||||
// Finally, loop through and output each of the DATs
|
// Finally, loop through and output each of the DATs
|
||||||
@@ -287,7 +293,7 @@ namespace SabreTools.Helper.Dats
|
|||||||
// Output the individual (a-b) DATs
|
// Output the individual (a-b) DATs
|
||||||
if ((diff & DiffMode.Individuals) != 0)
|
if ((diff & DiffMode.Individuals) != 0)
|
||||||
{
|
{
|
||||||
for (int j = 0; j < inputs.Count; j++)
|
Parallel.For(0, inputs.Count, j =>
|
||||||
{
|
{
|
||||||
// If we have an output directory set, replace the path
|
// If we have an output directory set, replace the path
|
||||||
string[] split = inputs[j].Split('¬');
|
string[] split = inputs[j].Split('¬');
|
||||||
@@ -297,7 +303,7 @@ namespace SabreTools.Helper.Dats
|
|||||||
|
|
||||||
// Try to output the file
|
// Try to output the file
|
||||||
outDats[j].WriteToFile(path);
|
outDats[j].WriteToFile(path);
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
Globals.Logger.User("Outputting complete in " + DateTime.Now.Subtract(start).ToString(@"hh\:mm\:ss\.fffff"));
|
Globals.Logger.User("Outputting complete in " + DateTime.Now.Subtract(start).ToString(@"hh\:mm\:ss\.fffff"));
|
||||||
}
|
}
|
||||||
@@ -353,31 +359,36 @@ namespace SabreTools.Helper.Dats
|
|||||||
Globals.Logger.User("Populating all output DATs");
|
Globals.Logger.User("Populating all output DATs");
|
||||||
List<string> keys = Keys.ToList();
|
List<string> keys = Keys.ToList();
|
||||||
|
|
||||||
foreach (string key in keys)
|
Parallel.ForEach(keys, Globals.ParallelOptions, key =>
|
||||||
{
|
{
|
||||||
List<DatItem> roms = DatItem.Merge(this[key]);
|
List<DatItem> items = DatItem.Merge(this[key]);
|
||||||
|
|
||||||
if (roms != null && roms.Count > 0)
|
// If the rom list is empty or null, just skip it
|
||||||
|
if (items == null || items.Count == 0)
|
||||||
{
|
{
|
||||||
foreach (DatItem rom in roms)
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Parallel.ForEach(items, Globals.ParallelOptions, item =>
|
||||||
{
|
{
|
||||||
// There's odd cases where there are items with System ID < 0. Skip them for now
|
// There's odd cases where there are items with System ID < 0. Skip them for now
|
||||||
if (rom.SystemID < 0)
|
if (item.SystemID < 0)
|
||||||
{
|
{
|
||||||
Globals.Logger.Warning("Item found with a <0 SystemID: " + rom.Name);
|
Globals.Logger.Warning("Item found with a <0 SystemID: " + item.Name);
|
||||||
continue;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
outDats[rom.SystemID].Add(key, rom);
|
outDats[item.SystemID].Add(key, item);
|
||||||
}
|
});
|
||||||
}
|
});
|
||||||
}
|
|
||||||
Globals.Logger.User("Populating complete in " + DateTime.Now.Subtract(start).ToString(@"hh\:mm\:ss\.fffff"));
|
Globals.Logger.User("Populating complete in " + DateTime.Now.Subtract(start).ToString(@"hh\:mm\:ss\.fffff"));
|
||||||
|
|
||||||
// Finally, loop through and output each of the DATs
|
// Finally, loop through and output each of the DATs
|
||||||
start = DateTime.Now;
|
start = DateTime.Now;
|
||||||
Globals.Logger.User("Outputting all created DATs");
|
Globals.Logger.User("Outputting all created DATs");
|
||||||
for (int j = (skip ? 1 : 0); j < inputs.Count; j++)
|
|
||||||
|
Parallel.For((skip ? 1 : 0), inputs.Count, j =>
|
||||||
{
|
{
|
||||||
// If we have an output directory set, replace the path
|
// If we have an output directory set, replace the path
|
||||||
string path = "";
|
string path = "";
|
||||||
@@ -395,7 +406,8 @@ namespace SabreTools.Helper.Dats
|
|||||||
|
|
||||||
// Try to output the file
|
// Try to output the file
|
||||||
outDats[j].WriteToFile(path);
|
outDats[j].WriteToFile(path);
|
||||||
}
|
});
|
||||||
|
|
||||||
Globals.Logger.User("Outputting complete in " + DateTime.Now.Subtract(start).ToString(@"hh\:mm\:ss\.fffff"));
|
Globals.Logger.User("Outputting complete in " + DateTime.Now.Subtract(start).ToString(@"hh\:mm\:ss\.fffff"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -411,103 +423,37 @@ namespace SabreTools.Helper.Dats
|
|||||||
if (Type == "SuperDAT")
|
if (Type == "SuperDAT")
|
||||||
{
|
{
|
||||||
List<string> keys = Keys.ToList();
|
List<string> keys = Keys.ToList();
|
||||||
foreach (string key in keys)
|
Parallel.ForEach(keys, Globals.ParallelOptions, key =>
|
||||||
{
|
{
|
||||||
List<DatItem> newroms = new List<DatItem>();
|
List<DatItem> items = this[key].ToList();
|
||||||
foreach (DatItem rom in this[key])
|
List<DatItem> newItems = new List<DatItem>();
|
||||||
|
Parallel.ForEach(items, Globals.ParallelOptions, item =>
|
||||||
{
|
{
|
||||||
DatItem newrom = rom;
|
DatItem newItem = item;
|
||||||
string filename = inputs[newrom.SystemID].Split('¬')[0];
|
string filename = inputs[newItem.SystemID].Split('¬')[0];
|
||||||
string rootpath = inputs[newrom.SystemID].Split('¬')[1];
|
string rootpath = inputs[newItem.SystemID].Split('¬')[1];
|
||||||
|
|
||||||
rootpath += (rootpath == "" ? "" : Path.DirectorySeparatorChar.ToString());
|
rootpath += (rootpath == "" ? "" : Path.DirectorySeparatorChar.ToString());
|
||||||
filename = filename.Remove(0, rootpath.Length);
|
filename = filename.Remove(0, rootpath.Length);
|
||||||
newrom.Machine.Name = Path.GetDirectoryName(filename) + Path.DirectorySeparatorChar
|
newItem.Machine.Name = Path.GetDirectoryName(filename) + Path.DirectorySeparatorChar
|
||||||
+ Path.GetFileNameWithoutExtension(filename) + Path.DirectorySeparatorChar
|
+ Path.GetFileNameWithoutExtension(filename) + Path.DirectorySeparatorChar
|
||||||
+ newrom.Machine.Name;
|
+ newItem.Machine.Name;
|
||||||
newroms.Add(newrom);
|
|
||||||
}
|
lock (newItems)
|
||||||
this[key] = newroms;
|
{
|
||||||
|
newItems.Add(newItem);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Remove(key);
|
||||||
|
AddRange(key, newItems);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to output the file
|
// Try to output the file
|
||||||
WriteToFile(outDir);
|
WriteToFile(outDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Strip the given hash types from the DAT
|
|
||||||
/// </summary>
|
|
||||||
private void StripHashesFromItems()
|
|
||||||
{
|
|
||||||
// Output the logging statement
|
|
||||||
Globals.Logger.User("Stripping requested hashes");
|
|
||||||
|
|
||||||
// Now process all of the roms
|
|
||||||
List<string> keys = Keys.ToList();
|
|
||||||
for (int i = 0; i < keys.Count; i++)
|
|
||||||
{
|
|
||||||
List<DatItem> items = this[keys[i]];
|
|
||||||
for (int j = 0; j < items.Count; j++)
|
|
||||||
{
|
|
||||||
DatItem item = items[j];
|
|
||||||
if (item.Type == ItemType.Rom)
|
|
||||||
{
|
|
||||||
Rom rom = (Rom)item;
|
|
||||||
if ((StripHash & Hash.MD5) != 0)
|
|
||||||
{
|
|
||||||
rom.MD5 = null;
|
|
||||||
}
|
|
||||||
if ((StripHash & Hash.SHA1) != 0)
|
|
||||||
{
|
|
||||||
rom.SHA1 = null;
|
|
||||||
}
|
|
||||||
if ((StripHash & Hash.SHA256) != 0)
|
|
||||||
{
|
|
||||||
rom.SHA256 = null;
|
|
||||||
}
|
|
||||||
if ((StripHash & Hash.SHA384) != 0)
|
|
||||||
{
|
|
||||||
rom.SHA384 = null;
|
|
||||||
}
|
|
||||||
if ((StripHash & Hash.SHA512) != 0)
|
|
||||||
{
|
|
||||||
rom.SHA512 = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
items[j] = rom;
|
|
||||||
}
|
|
||||||
else if (item.Type == ItemType.Disk)
|
|
||||||
{
|
|
||||||
Disk disk = (Disk)item;
|
|
||||||
if ((StripHash & Hash.MD5) != 0)
|
|
||||||
{
|
|
||||||
disk.MD5 = null;
|
|
||||||
}
|
|
||||||
if ((StripHash & Hash.SHA1) != 0)
|
|
||||||
{
|
|
||||||
disk.SHA1 = null;
|
|
||||||
}
|
|
||||||
if ((StripHash & Hash.SHA256) != 0)
|
|
||||||
{
|
|
||||||
disk.SHA256 = null;
|
|
||||||
}
|
|
||||||
if ((StripHash & Hash.SHA384) != 0)
|
|
||||||
{
|
|
||||||
disk.SHA384 = null;
|
|
||||||
}
|
|
||||||
if ((StripHash & Hash.SHA512) != 0)
|
|
||||||
{
|
|
||||||
disk.SHA512 = null;
|
|
||||||
}
|
|
||||||
items[j] = disk;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this[keys[i]] = items;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Convert, update, and filter a DAT file or set of files using a base
|
/// Convert, update, and filter a DAT file or set of files using a base
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -224,13 +224,13 @@ namespace SabreTools.Helper.Dats
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// First take care of the found items
|
// First take care of the found items
|
||||||
foreach (Rom rom in extracted)
|
Parallel.ForEach(extracted, Globals.ParallelOptions, rom =>
|
||||||
{
|
{
|
||||||
PopulateFromDirProcessFileHelper(newItem,
|
PopulateFromDirProcessFileHelper(newItem,
|
||||||
rom,
|
rom,
|
||||||
basePath,
|
basePath,
|
||||||
(Path.GetDirectoryName(Path.GetFullPath(item)) + Path.DirectorySeparatorChar).Remove(0, basePath.Length) + Path.GetFileNameWithoutExtension(item));
|
(Path.GetDirectoryName(Path.GetFullPath(item)) + Path.DirectorySeparatorChar).Remove(0, basePath.Length) + Path.GetFileNameWithoutExtension(item));
|
||||||
}
|
});
|
||||||
|
|
||||||
// Then, if we're looking for blanks, get all of the blank folders and add them
|
// Then, if we're looking for blanks, get all of the blank folders and add them
|
||||||
if (addBlanks)
|
if (addBlanks)
|
||||||
|
|||||||
@@ -16,9 +16,9 @@ namespace SabreTools.Helper.Dats
|
|||||||
{
|
{
|
||||||
public partial class DatFile
|
public partial class DatFile
|
||||||
{
|
{
|
||||||
#region Instance Methods
|
#region Instance Methods
|
||||||
|
|
||||||
#region Bucketing
|
#region Bucketing
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Take the arbitrarily sorted Files Dictionary and convert to one sorted by a user-defined method
|
/// Take the arbitrarily sorted Files Dictionary and convert to one sorted by a user-defined method
|
||||||
@@ -151,9 +151,9 @@ namespace SabreTools.Helper.Dats
|
|||||||
_files = sortable;
|
_files = sortable;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Filtering
|
#region Filtering
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Filter a DAT based on input parameters and modify the items
|
/// Filter a DAT based on input parameters and modify the items
|
||||||
@@ -284,9 +284,90 @@ namespace SabreTools.Helper.Dats
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
/// <summary>
|
||||||
|
/// Strip the given hash types from the DAT
|
||||||
|
/// </summary>
|
||||||
|
public void StripHashesFromItems()
|
||||||
|
{
|
||||||
|
// Output the logging statement
|
||||||
|
Globals.Logger.User("Stripping requested hashes");
|
||||||
|
|
||||||
#region Merging/Splitting Methods
|
// Now process all of the roms
|
||||||
|
List<string> keys = Keys.ToList();
|
||||||
|
Parallel.ForEach(keys, Globals.ParallelOptions, key =>
|
||||||
|
{
|
||||||
|
List<DatItem> items = this[key];
|
||||||
|
Parallel.For(0, items.Count, Globals.ParallelOptions, j =>
|
||||||
|
{
|
||||||
|
DatItem item = items[j];
|
||||||
|
if (item.Type == ItemType.Rom)
|
||||||
|
{
|
||||||
|
Rom rom = (Rom)item;
|
||||||
|
if ((StripHash & Hash.MD5) != 0)
|
||||||
|
{
|
||||||
|
rom.MD5 = null;
|
||||||
|
}
|
||||||
|
if ((StripHash & Hash.SHA1) != 0)
|
||||||
|
{
|
||||||
|
rom.SHA1 = null;
|
||||||
|
}
|
||||||
|
if ((StripHash & Hash.SHA256) != 0)
|
||||||
|
{
|
||||||
|
rom.SHA256 = null;
|
||||||
|
}
|
||||||
|
if ((StripHash & Hash.SHA384) != 0)
|
||||||
|
{
|
||||||
|
rom.SHA384 = null;
|
||||||
|
}
|
||||||
|
if ((StripHash & Hash.SHA512) != 0)
|
||||||
|
{
|
||||||
|
rom.SHA512 = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
lock (items)
|
||||||
|
{
|
||||||
|
items[j] = rom;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (item.Type == ItemType.Disk)
|
||||||
|
{
|
||||||
|
Disk disk = (Disk)item;
|
||||||
|
if ((StripHash & Hash.MD5) != 0)
|
||||||
|
{
|
||||||
|
disk.MD5 = null;
|
||||||
|
}
|
||||||
|
if ((StripHash & Hash.SHA1) != 0)
|
||||||
|
{
|
||||||
|
disk.SHA1 = null;
|
||||||
|
}
|
||||||
|
if ((StripHash & Hash.SHA256) != 0)
|
||||||
|
{
|
||||||
|
disk.SHA256 = null;
|
||||||
|
}
|
||||||
|
if ((StripHash & Hash.SHA384) != 0)
|
||||||
|
{
|
||||||
|
disk.SHA384 = null;
|
||||||
|
}
|
||||||
|
if ((StripHash & Hash.SHA512) != 0)
|
||||||
|
{
|
||||||
|
disk.SHA512 = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
lock (items)
|
||||||
|
{
|
||||||
|
items[j] = disk;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Remove(key);
|
||||||
|
AddRange(key, items);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Merging/Splitting Methods
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Use cloneof tags to create non-merged sets and remove the tags plus using the device_ref tags to get full sets
|
/// Use cloneof tags to create non-merged sets and remove the tags plus using the device_ref tags to get full sets
|
||||||
@@ -382,7 +463,7 @@ namespace SabreTools.Helper.Dats
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Merging/Splitting Helper Methods
|
#region Merging/Splitting Helper Methods
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Use romof tags to add roms to the children
|
/// Use romof tags to add roms to the children
|
||||||
@@ -965,6 +1046,6 @@ namespace SabreTools.Helper.Dats
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#endregion // Instance Methods
|
#endregion // Instance Methods
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
using SabreTools.Helper.Data;
|
using SabreTools.Helper.Data;
|
||||||
using SabreTools.Helper.Skippers;
|
using SabreTools.Helper.Skippers;
|
||||||
@@ -126,15 +127,18 @@ namespace SabreTools.Helper.Dats
|
|||||||
|
|
||||||
// Now loop through and get only directories from the input paths
|
// Now loop through and get only directories from the input paths
|
||||||
List<string> directories = new List<string>();
|
List<string> directories = new List<string>();
|
||||||
foreach (string input in inputs)
|
Parallel.ForEach(inputs, Globals.ParallelOptions, input =>
|
||||||
{
|
{
|
||||||
// Add to the list if the input is a directory
|
// Add to the list if the input is a directory
|
||||||
if (Directory.Exists(input))
|
if (Directory.Exists(input))
|
||||||
{
|
{
|
||||||
Globals.Logger.Verbose("Adding depot: '" + input + "'");
|
Globals.Logger.Verbose("Adding depot: '" + input + "'");
|
||||||
|
lock (directories)
|
||||||
|
{
|
||||||
directories.Add(input);
|
directories.Add(input);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// If we don't have any directories, we want to exit
|
// If we don't have any directories, we want to exit
|
||||||
if (directories.Count == 0)
|
if (directories.Count == 0)
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using System.Web;
|
using System.Web;
|
||||||
|
|
||||||
using SabreTools.Helper.Data;
|
using SabreTools.Helper.Data;
|
||||||
@@ -31,17 +32,23 @@ namespace SabreTools.Helper.Dats
|
|||||||
{
|
{
|
||||||
// Make sure all of the extensions have a dot at the beginning
|
// Make sure all of the extensions have a dot at the beginning
|
||||||
List<string> newExtA = new List<string>();
|
List<string> newExtA = new List<string>();
|
||||||
foreach (string s in extA)
|
Parallel.ForEach(extA, Globals.ParallelOptions, s =>
|
||||||
|
{
|
||||||
|
lock (newExtA)
|
||||||
{
|
{
|
||||||
newExtA.Add((s.StartsWith(".") ? s : "." + s).ToUpperInvariant());
|
newExtA.Add((s.StartsWith(".") ? s : "." + s).ToUpperInvariant());
|
||||||
}
|
}
|
||||||
|
});
|
||||||
string newExtAString = string.Join(",", newExtA);
|
string newExtAString = string.Join(",", newExtA);
|
||||||
|
|
||||||
List<string> newExtB = new List<string>();
|
List<string> newExtB = new List<string>();
|
||||||
foreach (string s in extB)
|
Parallel.ForEach(extB, Globals.ParallelOptions, s =>
|
||||||
|
{
|
||||||
|
lock (newExtB)
|
||||||
{
|
{
|
||||||
newExtB.Add((s.StartsWith(".") ? s : "." + s).ToUpperInvariant());
|
newExtB.Add((s.StartsWith(".") ? s : "." + s).ToUpperInvariant());
|
||||||
}
|
}
|
||||||
|
});
|
||||||
string newExtBString = string.Join(",", newExtB);
|
string newExtBString = string.Join(",", newExtB);
|
||||||
|
|
||||||
// Set all of the appropriate outputs for each of the subsets
|
// Set all of the appropriate outputs for each of the subsets
|
||||||
@@ -83,25 +90,27 @@ namespace SabreTools.Helper.Dats
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Now separate the roms accordingly
|
// Now separate the roms accordingly
|
||||||
foreach (string key in Keys)
|
List<string> keys = Keys.ToList();
|
||||||
|
Parallel.ForEach(keys, Globals.ParallelOptions, key =>
|
||||||
{
|
{
|
||||||
foreach (DatItem rom in this[key])
|
List<DatItem> items = this[key];
|
||||||
|
Parallel.ForEach(items, Globals.ParallelOptions, item =>
|
||||||
{
|
{
|
||||||
if (newExtA.Contains(Path.GetExtension(rom.Name.ToUpperInvariant())))
|
if (newExtA.Contains(Path.GetExtension(item.Name.ToUpperInvariant())))
|
||||||
{
|
{
|
||||||
datdataA.Add(key, rom);
|
datdataA.Add(key, item);
|
||||||
}
|
}
|
||||||
else if (newExtB.Contains(Path.GetExtension(rom.Name.ToUpperInvariant())))
|
else if (newExtB.Contains(Path.GetExtension(item.Name.ToUpperInvariant())))
|
||||||
{
|
{
|
||||||
datdataB.Add(key, rom);
|
datdataB.Add(key, item);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
datdataA.Add(key, rom);
|
datdataA.Add(key, item);
|
||||||
datdataB.Add(key, rom);
|
datdataB.Add(key, item);
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// Get the output directory
|
// Get the output directory
|
||||||
if (outDir != "")
|
if (outDir != "")
|
||||||
@@ -304,65 +313,65 @@ namespace SabreTools.Helper.Dats
|
|||||||
|
|
||||||
// Now populate each of the DAT objects in turn
|
// Now populate each of the DAT objects in turn
|
||||||
List<string> keys = Keys.ToList();
|
List<string> keys = Keys.ToList();
|
||||||
foreach (string key in keys)
|
Parallel.ForEach(keys, Globals.ParallelOptions, key =>
|
||||||
{
|
{
|
||||||
List<DatItem> roms = this[key];
|
List<DatItem> items = this[key];
|
||||||
foreach (DatItem rom in roms)
|
Parallel.ForEach(items, Globals.ParallelOptions, item =>
|
||||||
{
|
{
|
||||||
// If the file is not a Rom or Disk, continue
|
// If the file is not a Rom or Disk, continue
|
||||||
if (rom.Type != ItemType.Disk && rom.Type != ItemType.Rom)
|
if (item.Type != ItemType.Disk && item.Type != ItemType.Rom)
|
||||||
{
|
{
|
||||||
continue;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the file is a nodump
|
// If the file is a nodump
|
||||||
if ((rom.Type == ItemType.Rom && ((Rom)rom).ItemStatus == ItemStatus.Nodump)
|
if ((item.Type == ItemType.Rom && ((Rom)item).ItemStatus == ItemStatus.Nodump)
|
||||||
|| (rom.Type == ItemType.Disk && ((Disk)rom).ItemStatus == ItemStatus.Nodump))
|
|| (item.Type == ItemType.Disk && ((Disk)item).ItemStatus == ItemStatus.Nodump))
|
||||||
{
|
{
|
||||||
nodump.Add(key, rom);
|
nodump.Add(key, item);
|
||||||
}
|
}
|
||||||
// If the file has a SHA-512
|
// If the file has a SHA-512
|
||||||
else if ((rom.Type == ItemType.Rom && !String.IsNullOrEmpty(((Rom)rom).SHA512))
|
else if ((item.Type == ItemType.Rom && !String.IsNullOrEmpty(((Rom)item).SHA512))
|
||||||
|| (rom.Type == ItemType.Disk && !String.IsNullOrEmpty(((Disk)rom).SHA512)))
|
|| (item.Type == ItemType.Disk && !String.IsNullOrEmpty(((Disk)item).SHA512)))
|
||||||
{
|
{
|
||||||
sha512.Add(key, rom);
|
sha512.Add(key, item);
|
||||||
}
|
}
|
||||||
// If the file has a SHA-384
|
// If the file has a SHA-384
|
||||||
else if ((rom.Type == ItemType.Rom && !String.IsNullOrEmpty(((Rom)rom).SHA384))
|
else if ((item.Type == ItemType.Rom && !String.IsNullOrEmpty(((Rom)item).SHA384))
|
||||||
|| (rom.Type == ItemType.Disk && !String.IsNullOrEmpty(((Disk)rom).SHA384)))
|
|| (item.Type == ItemType.Disk && !String.IsNullOrEmpty(((Disk)item).SHA384)))
|
||||||
{
|
{
|
||||||
sha384.Add(key, rom);
|
sha384.Add(key, item);
|
||||||
}
|
}
|
||||||
// If the file has a SHA-256
|
// If the file has a SHA-256
|
||||||
else if ((rom.Type == ItemType.Rom && !String.IsNullOrEmpty(((Rom)rom).SHA256))
|
else if ((item.Type == ItemType.Rom && !String.IsNullOrEmpty(((Rom)item).SHA256))
|
||||||
|| (rom.Type == ItemType.Disk && !String.IsNullOrEmpty(((Disk)rom).SHA256)))
|
|| (item.Type == ItemType.Disk && !String.IsNullOrEmpty(((Disk)item).SHA256)))
|
||||||
{
|
{
|
||||||
sha256.Add(key, rom);
|
sha256.Add(key, item);
|
||||||
}
|
}
|
||||||
// If the file has a SHA-1
|
// If the file has a SHA-1
|
||||||
else if ((rom.Type == ItemType.Rom && !String.IsNullOrEmpty(((Rom)rom).SHA1))
|
else if ((item.Type == ItemType.Rom && !String.IsNullOrEmpty(((Rom)item).SHA1))
|
||||||
|| (rom.Type == ItemType.Disk && !String.IsNullOrEmpty(((Disk)rom).SHA1)))
|
|| (item.Type == ItemType.Disk && !String.IsNullOrEmpty(((Disk)item).SHA1)))
|
||||||
{
|
{
|
||||||
sha1.Add(key, rom);
|
sha1.Add(key, item);
|
||||||
}
|
}
|
||||||
// If the file has no SHA-1 but has an MD5
|
// If the file has no SHA-1 but has an MD5
|
||||||
else if ((rom.Type == ItemType.Rom && !String.IsNullOrEmpty(((Rom)rom).MD5))
|
else if ((item.Type == ItemType.Rom && !String.IsNullOrEmpty(((Rom)item).MD5))
|
||||||
|| (rom.Type == ItemType.Disk && !String.IsNullOrEmpty(((Disk)rom).MD5)))
|
|| (item.Type == ItemType.Disk && !String.IsNullOrEmpty(((Disk)item).MD5)))
|
||||||
{
|
{
|
||||||
md5.Add(key, rom);
|
md5.Add(key, item);
|
||||||
}
|
}
|
||||||
// If the file has no MD5 but a CRC
|
// If the file has no MD5 but a CRC
|
||||||
else if ((rom.Type == ItemType.Rom && !String.IsNullOrEmpty(((Rom)rom).SHA1))
|
else if ((item.Type == ItemType.Rom && !String.IsNullOrEmpty(((Rom)item).SHA1))
|
||||||
|| (rom.Type == ItemType.Disk && !String.IsNullOrEmpty(((Disk)rom).SHA1)))
|
|| (item.Type == ItemType.Disk && !String.IsNullOrEmpty(((Disk)item).SHA1)))
|
||||||
{
|
{
|
||||||
crc.Add(key, rom);
|
crc.Add(key, item);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
other.Add(key, rom);
|
other.Add(key, item);
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// Get the output directory
|
// Get the output directory
|
||||||
if (outDir != "")
|
if (outDir != "")
|
||||||
@@ -415,7 +424,7 @@ namespace SabreTools.Helper.Dats
|
|||||||
keys.Sort(SplitByLevelSort);
|
keys.Sort(SplitByLevelSort);
|
||||||
|
|
||||||
// Then, we loop over the games
|
// Then, we loop over the games
|
||||||
foreach (string key in keys)
|
Parallel.ForEach(keys, Globals.ParallelOptions, key =>
|
||||||
{
|
{
|
||||||
// Here, the key is the name of the game to be used for comparison
|
// Here, the key is the name of the game to be used for comparison
|
||||||
if (tempDat.Name != null && tempDat.Name != Style.GetDirectoryName(key))
|
if (tempDat.Name != null && tempDat.Name != Style.GetDirectoryName(key))
|
||||||
@@ -440,7 +449,7 @@ namespace SabreTools.Helper.Dats
|
|||||||
|
|
||||||
// Then set the DAT name to be the parent directory name
|
// Then set the DAT name to be the parent directory name
|
||||||
tempDat.Name = Style.GetDirectoryName(key);
|
tempDat.Name = Style.GetDirectoryName(key);
|
||||||
}
|
});
|
||||||
|
|
||||||
// Then we write the last DAT out since it would be skipped otherwise
|
// Then we write the last DAT out since it would be skipped otherwise
|
||||||
SplitByLevelHelper(tempDat, outDir, shortname, basedat);
|
SplitByLevelHelper(tempDat, outDir, shortname, basedat);
|
||||||
@@ -581,28 +590,28 @@ namespace SabreTools.Helper.Dats
|
|||||||
|
|
||||||
// Now populate each of the DAT objects in turn
|
// Now populate each of the DAT objects in turn
|
||||||
List<string> keys = Keys.ToList();
|
List<string> keys = Keys.ToList();
|
||||||
foreach (string key in keys)
|
Parallel.ForEach(keys, Globals.ParallelOptions, key =>
|
||||||
{
|
{
|
||||||
List<DatItem> roms = this[key];
|
List<DatItem> items = this[key];
|
||||||
foreach (DatItem rom in roms)
|
Parallel.ForEach(items, Globals.ParallelOptions, item =>
|
||||||
{
|
{
|
||||||
// If the file is a Rom
|
// If the file is a Rom
|
||||||
if (rom.Type == ItemType.Rom)
|
if (item.Type == ItemType.Rom)
|
||||||
{
|
{
|
||||||
romdat.Add(key, rom);
|
romdat.Add(key, item);
|
||||||
}
|
}
|
||||||
// If the file is a Disk
|
// If the file is a Disk
|
||||||
else if (rom.Type == ItemType.Disk)
|
else if (item.Type == ItemType.Disk)
|
||||||
{
|
{
|
||||||
diskdat.Add(key, rom);
|
diskdat.Add(key, item);
|
||||||
}
|
}
|
||||||
// If the file is a Sample
|
// If the file is a Sample
|
||||||
else if (rom.Type == ItemType.Sample)
|
else if (item.Type == ItemType.Sample)
|
||||||
{
|
{
|
||||||
sampledat.Add(key, rom);
|
sampledat.Add(key, item);
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// Get the output directory
|
// Get the output directory
|
||||||
if (outDir != "")
|
if (outDir != "")
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using System.Web;
|
using System.Web;
|
||||||
|
|
||||||
using SabreTools.Helper.Data;
|
using SabreTools.Helper.Data;
|
||||||
@@ -51,10 +52,11 @@ namespace SabreTools.Helper.Dats
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Loop through and add
|
// Loop through and add
|
||||||
foreach (string key in Keys)
|
List<string> keys = Keys.ToList();
|
||||||
|
Parallel.ForEach(keys, Globals.ParallelOptions, key =>
|
||||||
{
|
{
|
||||||
List<DatItem> items = this[key];
|
List<DatItem> items = this[key];
|
||||||
foreach (DatItem item in items)
|
Parallel.ForEach(items, Globals.ParallelOptions, item =>
|
||||||
{
|
{
|
||||||
switch (item.Type)
|
switch (item.Type)
|
||||||
{
|
{
|
||||||
@@ -68,6 +70,8 @@ namespace SabreTools.Helper.Dats
|
|||||||
MD5Count += (String.IsNullOrEmpty(disk.MD5) ? 0 : 1);
|
MD5Count += (String.IsNullOrEmpty(disk.MD5) ? 0 : 1);
|
||||||
SHA1Count += (String.IsNullOrEmpty(disk.SHA1) ? 0 : 1);
|
SHA1Count += (String.IsNullOrEmpty(disk.SHA1) ? 0 : 1);
|
||||||
SHA256Count += (String.IsNullOrEmpty(disk.SHA256) ? 0 : 1);
|
SHA256Count += (String.IsNullOrEmpty(disk.SHA256) ? 0 : 1);
|
||||||
|
SHA384Count += (String.IsNullOrEmpty(disk.SHA384) ? 0 : 1);
|
||||||
|
SHA512Count += (String.IsNullOrEmpty(disk.SHA512) ? 0 : 1);
|
||||||
BaddumpCount += (disk.ItemStatus == ItemStatus.BadDump ? 1 : 0);
|
BaddumpCount += (disk.ItemStatus == ItemStatus.BadDump ? 1 : 0);
|
||||||
NodumpCount += (disk.ItemStatus == ItemStatus.Nodump ? 1 : 0);
|
NodumpCount += (disk.ItemStatus == ItemStatus.Nodump ? 1 : 0);
|
||||||
break;
|
break;
|
||||||
@@ -81,14 +85,16 @@ namespace SabreTools.Helper.Dats
|
|||||||
MD5Count += (String.IsNullOrEmpty(rom.MD5) ? 0 : 1);
|
MD5Count += (String.IsNullOrEmpty(rom.MD5) ? 0 : 1);
|
||||||
SHA1Count += (String.IsNullOrEmpty(rom.SHA1) ? 0 : 1);
|
SHA1Count += (String.IsNullOrEmpty(rom.SHA1) ? 0 : 1);
|
||||||
SHA256Count += (String.IsNullOrEmpty(rom.SHA256) ? 0 : 1);
|
SHA256Count += (String.IsNullOrEmpty(rom.SHA256) ? 0 : 1);
|
||||||
|
SHA384Count += (String.IsNullOrEmpty(rom.SHA384) ? 0 : 1);
|
||||||
|
SHA512Count += (String.IsNullOrEmpty(rom.SHA512) ? 0 : 1);
|
||||||
BaddumpCount += (rom.ItemStatus == ItemStatus.BadDump ? 1 : 0);
|
BaddumpCount += (rom.ItemStatus == ItemStatus.BadDump ? 1 : 0);
|
||||||
NodumpCount += (rom.ItemStatus == ItemStatus.Nodump ? 1 : 0);
|
NodumpCount += (rom.ItemStatus == ItemStatus.Nodump ? 1 : 0);
|
||||||
break;
|
break;
|
||||||
case ItemType.Sample:
|
case ItemType.Sample:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using System.Web;
|
using System.Web;
|
||||||
|
|
||||||
using SabreTools.Helper.Data;
|
using SabreTools.Helper.Data;
|
||||||
@@ -134,7 +135,8 @@ namespace SabreTools.Helper.Dats
|
|||||||
List<string> keys = Keys.ToList();
|
List<string> keys = Keys.ToList();
|
||||||
keys.Sort(new NaturalComparer());
|
keys.Sort(new NaturalComparer());
|
||||||
|
|
||||||
foreach (DatFormat datFormat in outfiles.Keys)
|
// Write out all required formats
|
||||||
|
Parallel.ForEach(outfiles.Keys, Globals.ParallelOptions, datFormat =>
|
||||||
{
|
{
|
||||||
string outfile = outfiles[datFormat];
|
string outfile = outfiles[datFormat];
|
||||||
|
|
||||||
@@ -229,7 +231,7 @@ namespace SabreTools.Helper.Dats
|
|||||||
Globals.Logger.Verbose("File written!" + Environment.NewLine);
|
Globals.Logger.Verbose("File written!" + Environment.NewLine);
|
||||||
sw.Dispose();
|
sw.Dispose();
|
||||||
fs.Dispose();
|
fs.Dispose();
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user