diff --git a/SabreTools.Library/DatFiles/DatFile.cs b/SabreTools.Library/DatFiles/DatFile.cs index 05ac99e5..d5bcf58c 100644 --- a/SabreTools.Library/DatFiles/DatFile.cs +++ b/SabreTools.Library/DatFiles/DatFile.cs @@ -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 /// Value to add to the dictionary 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); + } } /// @@ -95,16 +103,20 @@ namespace SabreTools.Library.DatFiles /// Value to add to the dictionary public void AddRange(string key, List 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); + } } /// @@ -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; } diff --git a/SabreTools.Library/DatFiles/Filter.cs b/SabreTools.Library/DatFiles/Filter.cs index de9ef15c..d153881f 100644 --- a/SabreTools.Library/DatFiles/Filter.cs +++ b/SabreTools.Library/DatFiles/Filter.cs @@ -804,11 +804,8 @@ namespace SabreTools.Library.DatFiles } } - // Lock the list and add the item back - lock (newitems) - { - newitems.Add(item); - } + // Add the item to the output + newitems.Add(item); } } diff --git a/SabreTools.Library/DatItems/DatItem.cs b/SabreTools.Library/DatItems/DatItem.cs index 633ac29c..fddf9e6f 100644 --- a/SabreTools.Library/DatItems/DatItem.cs +++ b/SabreTools.Library/DatItems/DatItem.cs @@ -1116,8 +1116,10 @@ namespace SabreTools.Library.DatItems // Then deduplicate them by checking to see if data matches previous saved roms 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 (file.ItemType != ItemType.Rom && file.ItemType != ItemType.Disk) continue;