mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Add new methods to DB implementation
This commit is contained in:
@@ -609,7 +609,7 @@ namespace SabreTools.DatFiles
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// Reassign the item to the new machine
|
// Reassign the item to the new machine
|
||||||
ItemsDB._itemToMachineMapping[datItem.Key] = newMachineIndex;
|
ItemsDB.RemapDatItemToMachine(datItem.Key, newMachineIndex);
|
||||||
|
|
||||||
// Remove extensions from File and Rom items
|
// Remove extensions from File and Rom items
|
||||||
if (datItem.Value is DatItems.Formats.File || datItem.Value is Rom)
|
if (datItem.Value is DatItems.Formats.File || datItem.Value is Rom)
|
||||||
|
|||||||
@@ -395,6 +395,9 @@ namespace SabreTools.DatFiles
|
|||||||
items = GetItemsForBucketDB(bucket);
|
items = GetItemsForBucketDB(bucket);
|
||||||
foreach (var item in items)
|
foreach (var item in items)
|
||||||
{
|
{
|
||||||
|
// Get the source for the current item
|
||||||
|
var source = ItemsDB.GetSourceForItem(item.Key);
|
||||||
|
|
||||||
// Get the parent items and current machine name
|
// Get the parent items and current machine name
|
||||||
Dictionary<long, DatItem> parentItems = GetItemsForBucketDB(cloneOf);
|
Dictionary<long, DatItem> parentItems = GetItemsForBucketDB(cloneOf);
|
||||||
if (parentItems.Count == 0)
|
if (parentItems.Count == 0)
|
||||||
@@ -423,15 +426,15 @@ namespace SabreTools.DatFiles
|
|||||||
.Select(i => (i as Disk)!.GetName())
|
.Select(i => (i as Disk)!.GetName())
|
||||||
.Contains(mergeTag))
|
.Contains(mergeTag))
|
||||||
{
|
{
|
||||||
ItemsDB._itemToMachineMapping[item.Key] = cloneOfMachine.Key;
|
ItemsDB.RemapDatItemToMachine(item.Key, cloneOfMachine.Key);
|
||||||
ItemsDB._buckets[cloneOf!].Add(item.Key);
|
ItemsDB.AddItem(item.Value, cloneOfMachine.Key, source.Key);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there is no merge tag, add to parent
|
// If there is no merge tag, add to parent
|
||||||
else if (mergeTag == null)
|
else if (mergeTag == null)
|
||||||
{
|
{
|
||||||
ItemsDB._itemToMachineMapping[item.Key] = cloneOfMachine.Key;
|
ItemsDB.RemapDatItemToMachine(item.Key, cloneOfMachine.Key);
|
||||||
ItemsDB._buckets[cloneOf!].Add(item.Key);
|
ItemsDB.AddItem(item.Value, cloneOfMachine.Key, source.Key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -456,8 +459,8 @@ namespace SabreTools.DatFiles
|
|||||||
if (subfolder)
|
if (subfolder)
|
||||||
rom.SetName($"{machineName}\\{rom.GetName()}");
|
rom.SetName($"{machineName}\\{rom.GetName()}");
|
||||||
|
|
||||||
ItemsDB._itemToMachineMapping[item.Key] = cloneOfMachine.Key;
|
ItemsDB.RemapDatItemToMachine(item.Key, machineIndex: cloneOfMachine.Key);
|
||||||
ItemsDB._buckets[cloneOf!].Add(item.Key);
|
ItemsDB.AddItem(item.Value, cloneOfMachine.Key, source.Key);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the parent doesn't already contain this item, add to subfolder of parent
|
// If the parent doesn't already contain this item, add to subfolder of parent
|
||||||
@@ -466,8 +469,8 @@ namespace SabreTools.DatFiles
|
|||||||
if (subfolder)
|
if (subfolder)
|
||||||
rom.SetName($"{machineName}\\{rom.GetName()}");
|
rom.SetName($"{machineName}\\{rom.GetName()}");
|
||||||
|
|
||||||
ItemsDB._itemToMachineMapping[item.Key] = cloneOfMachine.Key;
|
ItemsDB.RemapDatItemToMachine(item.Key, cloneOfMachine.Key);
|
||||||
ItemsDB._buckets[cloneOf!].Add(item.Key);
|
ItemsDB.AddItem(item.Value, cloneOfMachine.Key, source.Key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -477,17 +480,13 @@ namespace SabreTools.DatFiles
|
|||||||
if (subfolder)
|
if (subfolder)
|
||||||
item.Value.SetName($"{machineName}\\{item.Value.GetName()}");
|
item.Value.SetName($"{machineName}\\{item.Value.GetName()}");
|
||||||
|
|
||||||
ItemsDB._itemToMachineMapping[item.Key] = cloneOfMachine.Key;
|
ItemsDB.RemapDatItemToMachine(item.Key, cloneOfMachine.Key);
|
||||||
ItemsDB._buckets[cloneOf!].Add(item.Key);
|
ItemsDB.AddItem(item.Value, cloneOfMachine.Key, source.Key);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Then, remove the old game so it's not picked up by the writer
|
// Remove the current item
|
||||||
#if NET40_OR_GREATER || NETCOREAPP
|
ItemsDB.RemoveItem(item.Key);
|
||||||
ItemsDB._buckets.TryRemove(bucket, out _);
|
}
|
||||||
#else
|
|
||||||
ItemsDB._buckets.Remove(bucket);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -95,12 +95,11 @@ namespace SabreTools.DatFiles
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Internal dictionary for item to machine mappings
|
/// Internal dictionary for item to machine mappings
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// TODO: Make private when access issues are figured out
|
|
||||||
[JsonIgnore, XmlIgnore]
|
[JsonIgnore, XmlIgnore]
|
||||||
#if NET40_OR_GREATER || NETCOREAPP
|
#if NET40_OR_GREATER || NETCOREAPP
|
||||||
internal readonly ConcurrentDictionary<long, long> _itemToMachineMapping = [];
|
private readonly ConcurrentDictionary<long, long> _itemToMachineMapping = [];
|
||||||
#else
|
#else
|
||||||
internal readonly Dictionary<long, long> _itemToMachineMapping = [];
|
private readonly Dictionary<long, long> _itemToMachineMapping = [];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -116,12 +115,11 @@ namespace SabreTools.DatFiles
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Internal dictionary representing the current buckets
|
/// Internal dictionary representing the current buckets
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// TODO: Make private when access issues are figured out
|
|
||||||
[JsonIgnore, XmlIgnore]
|
[JsonIgnore, XmlIgnore]
|
||||||
#if NET40_OR_GREATER || NETCOREAPP
|
#if NET40_OR_GREATER || NETCOREAPP
|
||||||
internal readonly ConcurrentDictionary<string, List<long>> _buckets = [];
|
private readonly ConcurrentDictionary<string, List<long>> _buckets = [];
|
||||||
#else
|
#else
|
||||||
internal readonly Dictionary<string, List<long>> _buckets = [];
|
private readonly Dictionary<string, List<long>> _buckets = [];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -572,6 +570,19 @@ namespace SabreTools.DatFiles
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public IDictionary<long, Source> GetSources() => _sources;
|
public IDictionary<long, Source> GetSources() => _sources;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Remap an item to a new machine index without validation
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="itemIndex">Current item index</param>
|
||||||
|
/// <param name="machineIndex">New machine index</param>
|
||||||
|
public void RemapDatItemToMachine(long itemIndex, long machineIndex)
|
||||||
|
{
|
||||||
|
lock (_itemToMachineMapping)
|
||||||
|
{
|
||||||
|
_itemToMachineMapping[itemIndex] = machineIndex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Remove an item, returning if it could be removed
|
/// Remove an item, returning if it could be removed
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user