mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[DatFile] Take care of more unnecessary nested threading
This commit is contained in:
@@ -541,7 +541,7 @@ namespace SabreTools.Library.Dats
|
|||||||
{
|
{
|
||||||
List<DatItem> items = this[key].ToList();
|
List<DatItem> items = this[key].ToList();
|
||||||
List<DatItem> newItems = new List<DatItem>();
|
List<DatItem> newItems = new List<DatItem>();
|
||||||
Parallel.ForEach(items, Globals.ParallelOptions, item =>
|
foreach (DatItem item in items)
|
||||||
{
|
{
|
||||||
DatItem newItem = item;
|
DatItem newItem = item;
|
||||||
string filename = inputs[newItem.SystemID].Split('¬')[0];
|
string filename = inputs[newItem.SystemID].Split('¬')[0];
|
||||||
@@ -553,11 +553,8 @@ namespace SabreTools.Library.Dats
|
|||||||
+ Path.GetFileNameWithoutExtension(filename) + Path.DirectorySeparatorChar
|
+ Path.GetFileNameWithoutExtension(filename) + Path.DirectorySeparatorChar
|
||||||
+ newItem.Machine.Name;
|
+ newItem.Machine.Name;
|
||||||
|
|
||||||
lock (newItems)
|
newItems.Add(newItem);
|
||||||
{
|
}
|
||||||
newItems.Add(newItem);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Remove(key);
|
Remove(key);
|
||||||
AddRange(key, newItems);
|
AddRange(key, newItems);
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ namespace SabreTools.Library.Dats
|
|||||||
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, Globals.ParallelOptions, rom =>
|
foreach (DatItem rom in roms)
|
||||||
{
|
{
|
||||||
string newkey = "";
|
string newkey = "";
|
||||||
|
|
||||||
@@ -132,7 +132,7 @@ namespace SabreTools.Library.Dats
|
|||||||
}
|
}
|
||||||
sortable[newkey].Add(rom);
|
sortable[newkey].Add(rom);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Now go through and sort all of the individual lists
|
// Now go through and sort all of the individual lists
|
||||||
@@ -182,7 +182,7 @@ namespace SabreTools.Library.Dats
|
|||||||
// For every item in the current key
|
// For every item in the current key
|
||||||
List<DatItem> items = this[key];
|
List<DatItem> items = this[key];
|
||||||
List<DatItem> newitems = new List<DatItem>();
|
List<DatItem> newitems = new List<DatItem>();
|
||||||
Parallel.ForEach(items, Globals.ParallelOptions, item =>
|
foreach (DatItem item in items)
|
||||||
{
|
{
|
||||||
// If the rom passes the filter, include it
|
// If the rom passes the filter, include it
|
||||||
if (filter.ItemPasses(item))
|
if (filter.ItemPasses(item))
|
||||||
@@ -212,7 +212,7 @@ namespace SabreTools.Library.Dats
|
|||||||
newitems.Add(item);
|
newitems.Add(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
Remove(key);
|
Remove(key);
|
||||||
AddRange(key, newitems);
|
AddRange(key, newitems);
|
||||||
@@ -232,14 +232,14 @@ namespace SabreTools.Library.Dats
|
|||||||
Parallel.ForEach(keys, Globals.ParallelOptions, key =>
|
Parallel.ForEach(keys, Globals.ParallelOptions, key =>
|
||||||
{
|
{
|
||||||
List<DatItem> items = this[key];
|
List<DatItem> items = this[key];
|
||||||
Parallel.ForEach(items, Globals.ParallelOptions, item =>
|
foreach (DatItem item in items)
|
||||||
{
|
{
|
||||||
// If the key mapping doesn't exist, add it
|
// If the key mapping doesn't exist, add it
|
||||||
if (!mapping.ContainsKey(item.Machine.Name))
|
if (!mapping.ContainsKey(item.Machine.Name))
|
||||||
{
|
{
|
||||||
mapping.TryAdd(item.Machine.Name, item.Machine.Description.Replace('/', '_').Replace("\"", "''"));
|
mapping.TryAdd(item.Machine.Name, item.Machine.Description.Replace('/', '_').Replace("\"", "''"));
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Now we loop through every item and update accordingly
|
// Now we loop through every item and update accordingly
|
||||||
@@ -248,41 +248,35 @@ namespace SabreTools.Library.Dats
|
|||||||
{
|
{
|
||||||
List<DatItem> items = this[key];
|
List<DatItem> items = this[key];
|
||||||
List<DatItem> newItems = new List<DatItem>();
|
List<DatItem> newItems = new List<DatItem>();
|
||||||
Parallel.ForEach(items, Globals.ParallelOptions, item =>
|
foreach (DatItem item in items)
|
||||||
{
|
{
|
||||||
// Clone the item first for easier working
|
|
||||||
DatItem newItem = (DatItem)item.Clone();
|
|
||||||
|
|
||||||
// Update machine name
|
// Update machine name
|
||||||
if (!String.IsNullOrEmpty(newItem.Machine.Name) && mapping.ContainsKey(newItem.Machine.Name))
|
if (!String.IsNullOrEmpty(item.Machine.Name) && mapping.ContainsKey(item.Machine.Name))
|
||||||
{
|
{
|
||||||
newItem.Machine.Name = mapping[newItem.Machine.Name];
|
item.Machine.Name = mapping[item.Machine.Name];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update cloneof
|
// Update cloneof
|
||||||
if (!String.IsNullOrEmpty(newItem.Machine.CloneOf) && mapping.ContainsKey(newItem.Machine.CloneOf))
|
if (!String.IsNullOrEmpty(item.Machine.CloneOf) && mapping.ContainsKey(item.Machine.CloneOf))
|
||||||
{
|
{
|
||||||
newItem.Machine.CloneOf = mapping[newItem.Machine.CloneOf];
|
item.Machine.CloneOf = mapping[item.Machine.CloneOf];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update romof
|
// Update romof
|
||||||
if (!String.IsNullOrEmpty(newItem.Machine.RomOf) && mapping.ContainsKey(newItem.Machine.RomOf))
|
if (!String.IsNullOrEmpty(item.Machine.RomOf) && mapping.ContainsKey(item.Machine.RomOf))
|
||||||
{
|
{
|
||||||
newItem.Machine.RomOf = mapping[newItem.Machine.RomOf];
|
item.Machine.RomOf = mapping[item.Machine.RomOf];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update sampleof
|
// Update sampleof
|
||||||
if (!String.IsNullOrEmpty(newItem.Machine.SampleOf) && mapping.ContainsKey(newItem.Machine.SampleOf))
|
if (!String.IsNullOrEmpty(item.Machine.SampleOf) && mapping.ContainsKey(item.Machine.SampleOf))
|
||||||
{
|
{
|
||||||
newItem.Machine.SampleOf = mapping[newItem.Machine.SampleOf];
|
item.Machine.SampleOf = mapping[item.Machine.SampleOf];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the new newItem to the output list
|
// Add the new item to the output list
|
||||||
lock (newItems)
|
items.Add(item);
|
||||||
{
|
}
|
||||||
newItems.Add(newItem);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Replace the old list of roms with the new one
|
// Replace the old list of roms with the new one
|
||||||
Remove(key);
|
Remove(key);
|
||||||
@@ -308,7 +302,7 @@ namespace SabreTools.Library.Dats
|
|||||||
Parallel.ForEach(keys, Globals.ParallelOptions, key =>
|
Parallel.ForEach(keys, Globals.ParallelOptions, key =>
|
||||||
{
|
{
|
||||||
List<DatItem> items = this[key];
|
List<DatItem> items = this[key];
|
||||||
Parallel.For(0, items.Count, Globals.ParallelOptions, j =>
|
for (int j = 0; j < items.Count; j++)
|
||||||
{
|
{
|
||||||
DatItem item = items[j];
|
DatItem item = items[j];
|
||||||
if (item.Type == ItemType.Rom)
|
if (item.Type == ItemType.Rom)
|
||||||
@@ -335,10 +329,7 @@ namespace SabreTools.Library.Dats
|
|||||||
rom.SHA512 = null;
|
rom.SHA512 = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
lock (items)
|
items[j] = rom;
|
||||||
{
|
|
||||||
items[j] = rom;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (item.Type == ItemType.Disk)
|
else if (item.Type == ItemType.Disk)
|
||||||
{
|
{
|
||||||
@@ -364,12 +355,9 @@ namespace SabreTools.Library.Dats
|
|||||||
disk.SHA512 = null;
|
disk.SHA512 = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
lock (items)
|
items[j] = disk;
|
||||||
{
|
|
||||||
items[j] = disk;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
Remove(key);
|
Remove(key);
|
||||||
AddRange(key, items);
|
AddRange(key, items);
|
||||||
|
|||||||
@@ -32,23 +32,17 @@ namespace SabreTools.Library.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>();
|
||||||
Parallel.ForEach(extA, Globals.ParallelOptions, s =>
|
foreach (string s in extA)
|
||||||
{
|
{
|
||||||
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>();
|
||||||
Parallel.ForEach(extB, Globals.ParallelOptions, s =>
|
foreach (string s in extB)
|
||||||
{
|
{
|
||||||
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
|
||||||
@@ -94,7 +88,7 @@ namespace SabreTools.Library.Dats
|
|||||||
Parallel.ForEach(keys, Globals.ParallelOptions, key =>
|
Parallel.ForEach(keys, Globals.ParallelOptions, key =>
|
||||||
{
|
{
|
||||||
List<DatItem> items = this[key];
|
List<DatItem> items = this[key];
|
||||||
Parallel.ForEach(items, Globals.ParallelOptions, item =>
|
foreach (DatItem item in items)
|
||||||
{
|
{
|
||||||
if (newExtA.Contains(Path.GetExtension(item.Name.ToUpperInvariant())))
|
if (newExtA.Contains(Path.GetExtension(item.Name.ToUpperInvariant())))
|
||||||
{
|
{
|
||||||
@@ -109,7 +103,7 @@ namespace SabreTools.Library.Dats
|
|||||||
datdataA.Add(key, item);
|
datdataA.Add(key, item);
|
||||||
datdataB.Add(key, item);
|
datdataB.Add(key, item);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Get the output directory
|
// Get the output directory
|
||||||
@@ -316,7 +310,7 @@ namespace SabreTools.Library.Dats
|
|||||||
Parallel.ForEach(keys, Globals.ParallelOptions, key =>
|
Parallel.ForEach(keys, Globals.ParallelOptions, key =>
|
||||||
{
|
{
|
||||||
List<DatItem> items = this[key];
|
List<DatItem> items = this[key];
|
||||||
Parallel.ForEach(items, Globals.ParallelOptions, item =>
|
foreach (DatItem item in items)
|
||||||
{
|
{
|
||||||
// If the file is not a Rom or Disk, continue
|
// If the file is not a Rom or Disk, continue
|
||||||
if (item.Type != ItemType.Disk && item.Type != ItemType.Rom)
|
if (item.Type != ItemType.Disk && item.Type != ItemType.Rom)
|
||||||
@@ -370,7 +364,7 @@ namespace SabreTools.Library.Dats
|
|||||||
{
|
{
|
||||||
other.Add(key, item);
|
other.Add(key, item);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Get the output directory
|
// Get the output directory
|
||||||
@@ -593,7 +587,7 @@ namespace SabreTools.Library.Dats
|
|||||||
Parallel.ForEach(keys, Globals.ParallelOptions, key =>
|
Parallel.ForEach(keys, Globals.ParallelOptions, key =>
|
||||||
{
|
{
|
||||||
List<DatItem> items = this[key];
|
List<DatItem> items = this[key];
|
||||||
Parallel.ForEach(items, Globals.ParallelOptions, item =>
|
foreach(DatItem item in items)
|
||||||
{
|
{
|
||||||
// If the file is a Rom
|
// If the file is a Rom
|
||||||
if (item.Type == ItemType.Rom)
|
if (item.Type == ItemType.Rom)
|
||||||
@@ -610,7 +604,7 @@ namespace SabreTools.Library.Dats
|
|||||||
{
|
{
|
||||||
sampledat.Add(key, item);
|
sampledat.Add(key, item);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Get the output directory
|
// Get the output directory
|
||||||
|
|||||||
Reference in New Issue
Block a user