Fix issue with CHD-only dats

This commit is contained in:
Matt Nadareski
2020-07-19 13:42:07 -07:00
parent 75490b7e13
commit 4596c7b299
3 changed files with 50 additions and 31 deletions

View File

@@ -59,11 +59,15 @@ namespace SabreTools.Library.DatFiles
{ {
get get
{ {
// Ensure the key exists // Explicit lock for some weird corner cases
EnsureKey(key); lock (key)
{
// Ensure the key exists
EnsureKey(key);
// Now return the value // Now return the value
return Items[key]; return Items[key];
}
} }
} }
@@ -74,18 +78,22 @@ namespace SabreTools.Library.DatFiles
/// <param name="value">Value to add to the dictionary</param> /// <param name="value">Value to add to the dictionary</param>
public void Add(string key, DatItem value) public void Add(string key, DatItem value)
{ {
// Ensure the key exists // Explicit lock for some weird corner cases
EnsureKey(key); lock (key)
{
// Ensure the key exists
EnsureKey(key);
// If item is null, don't add it // If item is null, don't add it
if (value == null) if (value == null)
return; return;
// Now add the value // Now add the value
Items[key].Add(value); Items[key].Add(value);
// Now update the statistics // Now update the statistics
DatStats.AddItem(value); DatStats.AddItem(value);
}
} }
/// <summary> /// <summary>
@@ -95,16 +103,20 @@ namespace SabreTools.Library.DatFiles
/// <param name="value">Value to add to the dictionary</param> /// <param name="value">Value to add to the dictionary</param>
public void AddRange(string key, List<DatItem> value) public void AddRange(string key, List<DatItem> value)
{ {
// Ensure the key exists // Explicit lock for some weird corner cases
EnsureKey(key); lock (key)
// Now add the value
Items[key].AddRange(value);
// Now update the statistics
foreach (DatItem item in value)
{ {
DatStats.AddItem(item); // Ensure the key exists
EnsureKey(key);
// Now add the value
Items[key].AddRange(value);
// Now update the statistics
foreach (DatItem item in value)
{
DatStats.AddItem(item);
}
} }
} }
@@ -119,7 +131,11 @@ namespace SabreTools.Library.DatFiles
if (key == null) if (key == null)
return false; return false;
return Items.ContainsKey(key); // Explicit lock for some weird corner cases
lock (key)
{
return Items.ContainsKey(key);
}
} }
/// <summary> /// <summary>
@@ -134,8 +150,12 @@ namespace SabreTools.Library.DatFiles
if (key == null) if (key == null)
return false; return false;
if (Items.ContainsKey(key)) // Explicit lock for some weird corner cases
return Items[key].Contains(value); lock (key)
{
if (Items.ContainsKey(key))
return Items[key].Contains(value);
}
return false; return false;
} }

View File

@@ -804,11 +804,8 @@ namespace SabreTools.Library.DatFiles
} }
} }
// Lock the list and add the item back // Add the item to the output
lock (newitems) newitems.Add(item);
{
newitems.Add(item);
}
} }
} }

View File

@@ -1116,8 +1116,10 @@ namespace SabreTools.Library.DatItems
// Then deduplicate them by checking to see if data matches previous saved roms // Then deduplicate them by checking to see if data matches previous saved roms
int nodumpCount = 0; int nodumpCount = 0;
foreach (DatItem file in infiles) for (int f = 0; f < infiles.Count; f++)
{ {
DatItem file = infiles[f];
// If we don't have a Rom or a Disk, we skip checking for duplicates // If we don't have a Rom or a Disk, we skip checking for duplicates
if (file.ItemType != ItemType.Rom && file.ItemType != ItemType.Disk) if (file.ItemType != ItemType.Rom && file.ItemType != ItemType.Disk)
continue; continue;