mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Fix some issues with DB RemoveItem
This commit is contained in:
@@ -516,7 +516,6 @@ namespace SabreTools.DatFiles
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
RemoveItem(index);
|
RemoveItem(index);
|
||||||
DatStatistics.RemoveItemStatistics(datItem);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return removed;
|
return removed;
|
||||||
@@ -527,22 +526,38 @@ namespace SabreTools.DatFiles
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public bool RemoveItem(long itemIndex)
|
public bool RemoveItem(long itemIndex)
|
||||||
{
|
{
|
||||||
|
// If the key doesn't exist, return
|
||||||
|
#if NET40_OR_GREATER || NETCOREAPP
|
||||||
|
if (!_items.TryRemove(itemIndex, out var datItem))
|
||||||
|
return false;
|
||||||
|
#else
|
||||||
if (!_items.ContainsKey(itemIndex))
|
if (!_items.ContainsKey(itemIndex))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
#if NET40_OR_GREATER || NETCOREAPP
|
var datItem = _items[itemIndex];
|
||||||
_items.TryRemove(itemIndex, out _);
|
|
||||||
#else
|
|
||||||
_items.Remove(itemIndex);
|
_items.Remove(itemIndex);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (_itemToMachineMapping.ContainsKey(itemIndex))
|
// Remove statistics, if possible
|
||||||
|
if (datItem != null)
|
||||||
|
DatStatistics.RemoveItemStatistics(datItem);
|
||||||
|
|
||||||
|
// Remove the machine mapping
|
||||||
#if NET40_OR_GREATER || NETCOREAPP
|
#if NET40_OR_GREATER || NETCOREAPP
|
||||||
_itemToMachineMapping.TryRemove(itemIndex, out _);
|
_itemToMachineMapping.TryRemove(itemIndex, out _);
|
||||||
#else
|
#else
|
||||||
|
if (_itemToMachineMapping.ContainsKey(itemIndex))
|
||||||
_itemToMachineMapping.Remove(itemIndex);
|
_itemToMachineMapping.Remove(itemIndex);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Remove the source mapping
|
||||||
|
#if NET40_OR_GREATER || NETCOREAPP
|
||||||
|
_itemToSourceMapping.TryRemove(itemIndex, out _);
|
||||||
|
#else
|
||||||
|
if (_itemToSourceMapping.ContainsKey(itemIndex))
|
||||||
|
_itemToSourceMapping.Remove(itemIndex);
|
||||||
|
#endif
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user