diff --git a/SabreTools.Metadata.DatFiles/ItemDatabase.cs b/SabreTools.Metadata.DatFiles/ItemDatabase.cs index 18956955..7be5ddde 100644 --- a/SabreTools.Metadata.DatFiles/ItemDatabase.cs +++ b/SabreTools.Metadata.DatFiles/ItemDatabase.cs @@ -102,16 +102,6 @@ namespace SabreTools.Metadata.DatFiles private readonly Dictionary _itemToMachineMapping = []; #endif - /// - /// Internal dictionary for item to source mappings - /// - [JsonIgnore, XmlIgnore] -#if NET40_OR_GREATER || NETCOREAPP || NETSTANDARD2_0_OR_GREATER - private readonly ConcurrentDictionary _itemToSourceMapping = []; -#else - private readonly Dictionary _itemToSourceMapping = []; -#endif - /// /// Internal dictionary representing the current buckets /// @@ -463,25 +453,14 @@ namespace SabreTools.Metadata.DatFiles /// public KeyValuePair GetSourceForItem(long itemIndex) { -#if NET40_OR_GREATER || NETCOREAPP || NETSTANDARD2_0_OR_GREATER - if (!_itemToSourceMapping.TryGetValue(itemIndex, out long sourceIndex)) + if (!_items.TryGetValue(itemIndex, out var item)) return new KeyValuePair(-1, null); + long sourceIndex = item.SourceIndex; if (!_sources.TryGetValue(sourceIndex, out var source)) return new KeyValuePair(-1, null); return new KeyValuePair(sourceIndex, source); -#else - if (!_itemToSourceMapping.ContainsKey(itemIndex)) - return new KeyValuePair(-1, null); - - long sourceIndex = _itemToSourceMapping[itemIndex]; - if (!_sources.ContainsKey(sourceIndex)) - return new KeyValuePair(-1, null); - - var source = _sources[sourceIndex]; - return new KeyValuePair(sourceIndex, source); -#endif } /// @@ -568,14 +547,6 @@ namespace SabreTools.Metadata.DatFiles _itemToMachineMapping.Remove(itemIndex); #endif - // Remove the source mapping -#if NET40_OR_GREATER || NETCOREAPP || NETSTANDARD2_0_OR_GREATER - _itemToSourceMapping.TryRemove(itemIndex, out _); -#else - if (_itemToSourceMapping.ContainsKey(itemIndex)) - _itemToSourceMapping.Remove(itemIndex); -#endif - return true; } @@ -626,6 +597,9 @@ namespace SabreTools.Metadata.DatFiles /// internal long AddItem(DatItem item, long machineIndex, long sourceIndex) { + // Add the source index + item.SourceIndex = sourceIndex; + #if NET40_OR_GREATER || NETCOREAPP || NETSTANDARD2_0_OR_GREATER // Add the item with a new index long index = Interlocked.Increment(ref _itemIndex) - 1; @@ -633,9 +607,6 @@ namespace SabreTools.Metadata.DatFiles // Add the machine mapping _itemToMachineMapping.TryAdd(index, machineIndex); - - // Add the source mapping - _itemToSourceMapping.TryAdd(index, sourceIndex); #else // Add the item with a new index long index = _itemIndex++ - 1; @@ -643,9 +614,6 @@ namespace SabreTools.Metadata.DatFiles // Add the machine mapping _itemToMachineMapping[index] = machineIndex; - - // Add the source mapping - _itemToSourceMapping[index] = sourceIndex; #endif // Add the item statistics @@ -924,8 +892,8 @@ namespace SabreTools.Metadata.DatFiles savedItem.DupeType = dupetype; // Get the sources associated with the items - var savedSource = _sources[_itemToSourceMapping[savedIndex]]; - var itemSource = _sources[_itemToSourceMapping[itemIndex]]; + var savedSource = _sources[GetSourceForItem(savedIndex).Key]; + var itemSource = _sources[GetSourceForItem(itemIndex).Key]; // Get the machines associated with the items var savedMachine = _machines[_itemToMachineMapping[savedIndex]]; @@ -934,7 +902,7 @@ namespace SabreTools.Metadata.DatFiles // If the current source has a lower ID than the saved, use the saved source if (itemSource?.Index < savedSource?.Index) { - _itemToSourceMapping[itemIndex] = _itemToSourceMapping[savedIndex]; + datItem.SourceIndex = savedItem.SourceIndex; _machines[_itemToMachineMapping[savedIndex]] = (itemMachine.Clone() as Machine)!; savedItem.SetName(datItem.GetName()); }