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