mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[DatFile] Safer code to ensure better description-to-name remapping
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Concurrent;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@@ -226,20 +227,17 @@ namespace SabreTools.Library.Dats
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
// First we want to get a mapping for all games to description
|
// First we want to get a mapping for all games to description
|
||||||
Dictionary<string, string> mapping = new Dictionary<string, string>();
|
ConcurrentDictionary<string, string> mapping = new ConcurrentDictionary<string, string>();
|
||||||
List<string> keys = Keys.ToList();
|
List<string> keys = Keys.ToList();
|
||||||
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 =>
|
Parallel.ForEach(items, Globals.ParallelOptions, item =>
|
||||||
{
|
|
||||||
lock (mapping)
|
|
||||||
{
|
{
|
||||||
// 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.Add(item.Machine.Name, item.Machine.Description.Replace('/', '_').Replace("\"", "''"));
|
mapping.TryAdd(item.Machine.Name, item.Machine.Description.Replace('/', '_').Replace("\"", "''"));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -251,6 +249,8 @@ 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 =>
|
Parallel.ForEach(items, Globals.ParallelOptions, item =>
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
// Update machine name
|
// Update machine name
|
||||||
if (item.Machine.Name != null && mapping.ContainsKey(item.Machine.Name))
|
if (item.Machine.Name != null && mapping.ContainsKey(item.Machine.Name))
|
||||||
@@ -281,6 +281,11 @@ namespace SabreTools.Library.Dats
|
|||||||
{
|
{
|
||||||
newItems.Add(item);
|
newItems.Add(item);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Globals.Logger.Warning(ex.ToString());
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Replace the old list of roms with the new one
|
// Replace the old list of roms with the new one
|
||||||
|
|||||||
Reference in New Issue
Block a user