Create passthrough methods for scaffolding

This commit is contained in:
Matt Nadareski
2025-01-12 22:10:48 -05:00
parent c8fda8d99d
commit d80a6b173c
16 changed files with 342 additions and 277 deletions

View File

@@ -24,8 +24,8 @@ namespace SabreTools.DatFiles
return;
// Create an internal source and add to the dictionary
var source = new DatItems.Source(indexId, filename);
long sourceIndex = ItemsDB.AddSource(source);
var source = new Source(indexId, filename);
long sourceIndex = AddSourceDB(source);
// Get the header from the metadata
var header = item.Read<Models.Metadata.Header>(Models.Metadata.MetadataFile.HeaderKey);
@@ -203,7 +203,7 @@ namespace SabreTools.DatFiles
// Create an internal machine and add to the dictionary
var machine = new Machine(item);
long machineIndex = ItemsDB.AddMachine(machine);
long machineIndex = AddMachineDB(machine);
// Convert items in the machine
if (item.ContainsKey(Models.Metadata.Machine.AdjusterKey))
@@ -366,8 +366,8 @@ namespace SabreTools.DatFiles
datItem.SetFieldValue<Source?>(DatItem.SourceKey, source);
datItem.CopyMachineInformation(machine);
Items.AddItem(datItem, statsOnly);
ItemsDB.AddItem(datItem, machineIndex, sourceIndex, statsOnly);
AddItem(datItem, statsOnly);
AddItemDB(datItem, machineIndex, sourceIndex, statsOnly);
}
}
@@ -393,8 +393,8 @@ namespace SabreTools.DatFiles
datItem.SetFieldValue<Source?>(DatItem.SourceKey, source);
datItem.CopyMachineInformation(machine);
Items.AddItem(datItem, statsOnly);
ItemsDB.AddItem(datItem, machineIndex, sourceIndex, statsOnly);
AddItem(datItem, statsOnly);
AddItemDB(datItem, machineIndex, sourceIndex, statsOnly);
}
}
@@ -420,8 +420,8 @@ namespace SabreTools.DatFiles
datItem.SetFieldValue<Source?>(DatItem.SourceKey, source);
datItem.CopyMachineInformation(machine);
Items.AddItem(datItem, statsOnly);
ItemsDB.AddItem(datItem, machineIndex, sourceIndex, statsOnly);
AddItem(datItem, statsOnly);
AddItemDB(datItem, machineIndex, sourceIndex, statsOnly);
}
}
@@ -447,8 +447,8 @@ namespace SabreTools.DatFiles
datItem.SetFieldValue<Source?>(DatItem.SourceKey, source);
datItem.CopyMachineInformation(machine);
Items.AddItem(datItem, statsOnly);
ItemsDB.AddItem(datItem, machineIndex, sourceIndex, statsOnly);
AddItem(datItem, statsOnly);
AddItemDB(datItem, machineIndex, sourceIndex, statsOnly);
}
}
@@ -474,8 +474,8 @@ namespace SabreTools.DatFiles
datItem.SetFieldValue<Source?>(DatItem.SourceKey, source);
datItem.CopyMachineInformation(machine);
Items.AddItem(datItem, statsOnly);
ItemsDB.AddItem(datItem, machineIndex, sourceIndex, statsOnly);
AddItem(datItem, statsOnly);
AddItemDB(datItem, machineIndex, sourceIndex, statsOnly);
}
}
@@ -501,8 +501,8 @@ namespace SabreTools.DatFiles
datItem.SetFieldValue<Source?>(DatItem.SourceKey, source);
datItem.CopyMachineInformation(machine);
Items.AddItem(datItem, statsOnly);
ItemsDB.AddItem(datItem, machineIndex, sourceIndex, statsOnly);
AddItem(datItem, statsOnly);
AddItemDB(datItem, machineIndex, sourceIndex, statsOnly);
}
}
@@ -528,8 +528,8 @@ namespace SabreTools.DatFiles
datItem.SetFieldValue<Source?>(DatItem.SourceKey, source);
datItem.CopyMachineInformation(machine);
Items.AddItem(datItem, statsOnly);
ItemsDB.AddItem(datItem, machineIndex, sourceIndex, statsOnly);
AddItem(datItem, statsOnly);
AddItemDB(datItem, machineIndex, sourceIndex, statsOnly);
}
}
@@ -555,8 +555,8 @@ namespace SabreTools.DatFiles
datItem.SetFieldValue<Source?>(DatItem.SourceKey, source);
datItem.CopyMachineInformation(machine);
Items.AddItem(datItem, statsOnly);
ItemsDB.AddItem(datItem, machineIndex, sourceIndex, statsOnly);
AddItem(datItem, statsOnly);
AddItemDB(datItem, machineIndex, sourceIndex, statsOnly);
}
}
@@ -582,8 +582,8 @@ namespace SabreTools.DatFiles
datItem.SetFieldValue<Source?>(DatItem.SourceKey, source);
datItem.CopyMachineInformation(machine);
Items.AddItem(datItem, statsOnly);
ItemsDB.AddItem(datItem, machineIndex, sourceIndex, statsOnly);
AddItem(datItem, statsOnly);
AddItemDB(datItem, machineIndex, sourceIndex, statsOnly);
}
}
@@ -609,8 +609,8 @@ namespace SabreTools.DatFiles
datItem.SetFieldValue<Source?>(DatItem.SourceKey, source);
datItem.CopyMachineInformation(machine);
Items.AddItem(datItem, statsOnly);
ItemsDB.AddItem(datItem, machineIndex, sourceIndex, statsOnly);
AddItem(datItem, statsOnly);
AddItemDB(datItem, machineIndex, sourceIndex, statsOnly);
}
}
@@ -636,8 +636,8 @@ namespace SabreTools.DatFiles
datItem.SetFieldValue<Source?>(DatItem.SourceKey, source);
datItem.CopyMachineInformation(machine);
Items.AddItem(datItem, statsOnly);
ItemsDB.AddItem(datItem, machineIndex, sourceIndex, statsOnly);
AddItem(datItem, statsOnly);
AddItemDB(datItem, machineIndex, sourceIndex, statsOnly);
}
}
@@ -729,8 +729,8 @@ namespace SabreTools.DatFiles
if (datItem.GetStringFieldValue(Models.Metadata.Rom.SHA512Key) != null)
datItem.SetFieldValue<string?>(Models.Metadata.Rom.SHA512Key, TextHelper.NormalizeSHA512(datItem.GetStringFieldValue(Models.Metadata.Rom.SHA512Key)));
Items.AddItem(datItem, statsOnly);
ItemsDB.AddItem(datItem, machineIndex, sourceIndex, statsOnly);
AddItem(datItem, statsOnly);
AddItemDB(datItem, machineIndex, sourceIndex, statsOnly);
}
}
@@ -756,8 +756,8 @@ namespace SabreTools.DatFiles
datItem.SetFieldValue<Source?>(DatItem.SourceKey, source);
datItem.CopyMachineInformation(machine);
Items.AddItem(datItem, statsOnly);
ItemsDB.AddItem(datItem, machineIndex, sourceIndex, statsOnly);
AddItem(datItem, statsOnly);
AddItemDB(datItem, machineIndex, sourceIndex, statsOnly);
}
}
@@ -783,8 +783,8 @@ namespace SabreTools.DatFiles
datItem.SetFieldValue<Source?>(DatItem.SourceKey, source);
datItem.CopyMachineInformation(machine);
Items.AddItem(datItem, statsOnly);
ItemsDB.AddItem(datItem, machineIndex, sourceIndex, statsOnly);
AddItem(datItem, statsOnly);
AddItemDB(datItem, machineIndex, sourceIndex, statsOnly);
}
}
@@ -810,8 +810,8 @@ namespace SabreTools.DatFiles
datItem.SetFieldValue<Source?>(DatItem.SourceKey, source);
datItem.CopyMachineInformation(machine);
Items.AddItem(datItem, statsOnly);
ItemsDB.AddItem(datItem, machineIndex, sourceIndex, statsOnly);
AddItem(datItem, statsOnly);
AddItemDB(datItem, machineIndex, sourceIndex, statsOnly);
}
}
@@ -837,8 +837,8 @@ namespace SabreTools.DatFiles
datItem.SetFieldValue<Source?>(DatItem.SourceKey, source);
datItem.CopyMachineInformation(machine);
Items.AddItem(datItem, statsOnly);
ItemsDB.AddItem(datItem, machineIndex, sourceIndex, statsOnly);
AddItem(datItem, statsOnly);
AddItemDB(datItem, machineIndex, sourceIndex, statsOnly);
}
}
@@ -881,8 +881,8 @@ namespace SabreTools.DatFiles
romItem.SetFieldValue<Source?>(DatItem.SourceKey, source);
romItem.CopyMachineInformation(machine);
Items.AddItem(romItem, statsOnly);
ItemsDB.AddItem(romItem, machineIndex, sourceIndex, statsOnly);
AddItem(romItem, statsOnly);
AddItemDB(romItem, machineIndex, sourceIndex, statsOnly);
}
}
}
@@ -905,8 +905,8 @@ namespace SabreTools.DatFiles
diskItem.SetFieldValue<Source?>(DatItem.SourceKey, source);
diskItem.CopyMachineInformation(machine);
Items.AddItem(diskItem, statsOnly);
ItemsDB.AddItem(diskItem, machineIndex, sourceIndex, statsOnly);
AddItem(diskItem, statsOnly);
AddItemDB(diskItem, machineIndex, sourceIndex, statsOnly);
}
}
}
@@ -921,8 +921,8 @@ namespace SabreTools.DatFiles
dipSwitchItem.SetFieldValue<Source?>(DatItem.SourceKey, source);
dipSwitchItem.CopyMachineInformation(machine);
Items.AddItem(dipSwitchItem, statsOnly);
ItemsDB.AddItem(dipSwitchItem, machineIndex, sourceIndex, statsOnly);
AddItem(dipSwitchItem, statsOnly);
AddItemDB(dipSwitchItem, machineIndex, sourceIndex, statsOnly);
}
}
@@ -936,8 +936,8 @@ namespace SabreTools.DatFiles
partFeatureItem.SetFieldValue<Source?>(DatItem.SourceKey, source);
partFeatureItem.CopyMachineInformation(machine);
Items.AddItem(partFeatureItem, statsOnly);
ItemsDB.AddItem(partFeatureItem, machineIndex, sourceIndex, statsOnly);
AddItem(partFeatureItem, statsOnly);
AddItemDB(partFeatureItem, machineIndex, sourceIndex, statsOnly);
}
}
}
@@ -965,8 +965,8 @@ namespace SabreTools.DatFiles
datItem.SetFieldValue<Source?>(DatItem.SourceKey, source);
datItem.CopyMachineInformation(machine);
Items.AddItem(datItem, statsOnly);
ItemsDB.AddItem(datItem, machineIndex, sourceIndex, statsOnly);
AddItem(datItem, statsOnly);
AddItemDB(datItem, machineIndex, sourceIndex, statsOnly);
}
}
@@ -992,8 +992,8 @@ namespace SabreTools.DatFiles
datItem.SetFieldValue<Source?>(DatItem.SourceKey, source);
datItem.CopyMachineInformation(machine);
Items.AddItem(datItem, statsOnly);
ItemsDB.AddItem(datItem, machineIndex, sourceIndex, statsOnly);
AddItem(datItem, statsOnly);
AddItemDB(datItem, machineIndex, sourceIndex, statsOnly);
}
}
@@ -1019,8 +1019,8 @@ namespace SabreTools.DatFiles
datItem.SetFieldValue<Source?>(DatItem.SourceKey, source);
datItem.CopyMachineInformation(machine);
Items.AddItem(datItem, statsOnly);
ItemsDB.AddItem(datItem, machineIndex, sourceIndex, statsOnly);
AddItem(datItem, statsOnly);
AddItemDB(datItem, machineIndex, sourceIndex, statsOnly);
}
}
@@ -1046,8 +1046,8 @@ namespace SabreTools.DatFiles
datItem.SetFieldValue<Source?>(DatItem.SourceKey, source);
datItem.CopyMachineInformation(machine);
Items.AddItem(datItem, statsOnly);
ItemsDB.AddItem(datItem, machineIndex, sourceIndex, statsOnly);
AddItem(datItem, statsOnly);
AddItemDB(datItem, machineIndex, sourceIndex, statsOnly);
}
}
@@ -1073,8 +1073,8 @@ namespace SabreTools.DatFiles
datItem.SetFieldValue<Source?>(DatItem.SourceKey, source);
datItem.CopyMachineInformation(machine);
Items.AddItem(datItem, statsOnly);
ItemsDB.AddItem(datItem, machineIndex, sourceIndex, statsOnly);
AddItem(datItem, statsOnly);
AddItemDB(datItem, machineIndex, sourceIndex, statsOnly);
}
}
@@ -1100,8 +1100,8 @@ namespace SabreTools.DatFiles
datItem.SetFieldValue<Source?>(DatItem.SourceKey, source);
datItem.CopyMachineInformation(machine);
Items.AddItem(datItem, statsOnly);
ItemsDB.AddItem(datItem, machineIndex, sourceIndex, statsOnly);
AddItem(datItem, statsOnly);
AddItemDB(datItem, machineIndex, sourceIndex, statsOnly);
}
}
@@ -1127,8 +1127,8 @@ namespace SabreTools.DatFiles
datItem.SetFieldValue<Source?>(DatItem.SourceKey, source);
datItem.CopyMachineInformation(machine);
Items.AddItem(datItem, statsOnly);
ItemsDB.AddItem(datItem, machineIndex, sourceIndex, statsOnly);
AddItem(datItem, statsOnly);
AddItemDB(datItem, machineIndex, sourceIndex, statsOnly);
}
}
@@ -1154,8 +1154,8 @@ namespace SabreTools.DatFiles
datItem.SetFieldValue<Source?>(DatItem.SourceKey, source);
datItem.CopyMachineInformation(machine);
Items.AddItem(datItem, statsOnly);
ItemsDB.AddItem(datItem, machineIndex, sourceIndex, statsOnly);
AddItem(datItem, statsOnly);
AddItemDB(datItem, machineIndex, sourceIndex, statsOnly);
}
}
@@ -1181,8 +1181,8 @@ namespace SabreTools.DatFiles
datItem.SetFieldValue<Source?>(DatItem.SourceKey, source);
datItem.CopyMachineInformation(machine);
Items.AddItem(datItem, statsOnly);
ItemsDB.AddItem(datItem, machineIndex, sourceIndex, statsOnly);
AddItem(datItem, statsOnly);
AddItemDB(datItem, machineIndex, sourceIndex, statsOnly);
}
}
@@ -1208,8 +1208,8 @@ namespace SabreTools.DatFiles
datItem.SetFieldValue<Source?>(DatItem.SourceKey, source);
datItem.CopyMachineInformation(machine);
Items.AddItem(datItem, statsOnly);
ItemsDB.AddItem(datItem, machineIndex, sourceIndex, statsOnly);
AddItem(datItem, statsOnly);
AddItemDB(datItem, machineIndex, sourceIndex, statsOnly);
}
}

View File

@@ -122,15 +122,6 @@ namespace SabreTools.DatFiles
#region Accessors
/// <summary>
/// Reset the internal item dictionary
/// </summary>
public void ResetDictionary()
{
Items.Clear();
ItemsDB = new ItemDictionaryDB();
}
/// <summary>
/// Set the internal header
/// </summary>
@@ -157,6 +148,106 @@ namespace SabreTools.DatFiles
#endregion
#region Item Dictionary Manipulation
/// <summary>
/// Add a value to the file dictionary
/// </summary>
/// <param name="key">Key in the dictionary to add to</param>
/// <param name="value">Value to add to the dictionary</param>
public void Add(string key, DatItem value)
{
Items.Add(key, value);
}
/// <summary>
/// Add a range of values to the file dictionary
/// </summary>
/// <param name="key">Key in the dictionary to add to</param>
/// <param name="value">Value to add to the dictionary</param>
public void Add(string key, List<DatItem>? value)
{
Items.Add(key, value);
}
/// <summary>
/// Add a DatItem to the dictionary after checking
/// </summary>
/// <param name="item">Item data to check against</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
/// <returns>The key for the item</returns>
public string AddItem(DatItem item, bool statsOnly)
{
return Items.AddItem(item, statsOnly);
}
/// <summary>
/// Add a DatItem to the dictionary after validation
/// </summary>
/// <param name="item">Item data to validate</param>
/// <param name="machineIndex">Index of the machine related to the item</param>
/// <param name="sourceIndex">Index of the source related to the item</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
/// <returns>The index for the added item, -1 on error</returns>
public long AddItemDB(DatItem item, long machineIndex, long sourceIndex, bool statsOnly)
{
return ItemsDB.AddItem(item, machineIndex, sourceIndex, statsOnly);
}
/// <summary>
/// Add a machine, returning the insert index
/// </summary>
public long AddMachineDB(Machine machine)
{
return ItemsDB.AddMachine(machine);
}
/// <summary>
/// Add a source, returning the insert index
/// </summary>
public long AddSourceDB(Source source)
{
return ItemsDB.AddSource(source);
}
/// <summary>
/// Remove any keys that have null or empty values
/// </summary>
public void ClearEmpty()
{
Items.ClearEmpty();
ItemsDB.ClearEmpty();
}
/// <summary>
/// Remove all items marked for removal
/// </summary>
public void ClearMarked()
{
Items.ClearMarked();
ItemsDB.ClearMarked();
}
/// <summary>
/// Remove a key from the file dictionary if it exists
/// </summary>
/// <param name="key">Key in the dictionary to remove</param>
public bool Remove(string key)
{
return Items.Remove(key);
}
/// <summary>
/// Reset the internal item dictionary
/// </summary>
public void ResetDictionary()
{
Items.Clear();
ItemsDB = new ItemDictionaryDB();
}
#endregion
#region Parsing
/// <summary>

View File

@@ -366,8 +366,8 @@ namespace SabreTools.DatFiles
newItems.Add(newItem);
}
datFile.Items.Remove(key);
datFile.Items.AddRange(key, newItems);
datFile.Remove(key);
datFile.Add(key, newItems);
#if NET40_OR_GREATER || NETCOREAPP
});
#else
@@ -497,8 +497,8 @@ namespace SabreTools.DatFiles
}
// Now add the new list to the key
intDat.Items.Remove(key);
intDat.Items.AddRange(key, newDatItems);
intDat.Remove(key);
intDat.Add(key, newDatItems);
#if NET40_OR_GREATER || NETCOREAPP
});
#else
@@ -546,8 +546,8 @@ namespace SabreTools.DatFiles
}
// Now add the new list to the key
intDat.Items.Remove(key);
intDat.Items.AddRange(key, newDatItems);
intDat.Remove(key);
intDat.Add(key, newDatItems);
#if NET40_OR_GREATER || NETCOREAPP
});
#else
@@ -734,7 +734,7 @@ namespace SabreTools.DatFiles
// If we have an exact match, remove the game
if (exactMatch)
intDat.Items.Remove(key);
intDat.Remove(key);
}
// Standard Against uses hashes
@@ -756,8 +756,8 @@ namespace SabreTools.DatFiles
}
// Now add the new list to the key
intDat.Items.Remove(key);
intDat.Items.AddRange(key, keepDatItems);
intDat.Remove(key);
intDat.Add(key, keepDatItems);
}
#if NET40_OR_GREATER || NETCOREAPP
});
@@ -888,7 +888,7 @@ namespace SabreTools.DatFiles
if (item.GetFieldValue<Source?>(DatItem.SourceKey) != null)
newrom.GetFieldValue<Machine>(DatItem.MachineKey)!.SetFieldValue<string?>(Models.Metadata.Machine.NameKey, newrom.GetFieldValue<Machine>(DatItem.MachineKey)!.GetStringFieldValue(Models.Metadata.Machine.NameKey) + $" ({Path.GetFileNameWithoutExtension(inputs[item.GetFieldValue<Source?>(DatItem.SourceKey)!.Index].CurrentPath)})");
dupeData.Items.Add(key, newrom);
dupeData.Add(key, newrom);
}
}
#if NET40_OR_GREATER || NETCOREAPP
@@ -947,14 +947,14 @@ namespace SabreTools.DatFiles
// Loop through and add all sources
foreach (var source in sources)
{
long newSourceIndex = dupeData.ItemsDB.AddSource(source.Value);
long newSourceIndex = dupeData.AddSourceDB(source.Value);
sourceRemapping[source.Key] = newSourceIndex;
}
// Loop through and add all machines
foreach (var machine in machines)
{
long newMachineIndex = dupeData.ItemsDB.AddMachine(machine.Value);
long newMachineIndex = dupeData.AddMachineDB(machine.Value);
machineRemapping[machine.Key] = newMachineIndex;
}
@@ -1001,11 +1001,11 @@ namespace SabreTools.DatFiles
{
var newMachine = currentMachine.Value.Clone() as Machine;
newMachine!.SetFieldValue<string?>(Models.Metadata.Machine.NameKey, renamedMachineName);
long newMachineIndex = dupeData.ItemsDB.AddMachine(newMachine!);
long newMachineIndex = dupeData.AddMachineDB(newMachine!);
renamedMachine = new KeyValuePair<long, Machine?>(newMachineIndex, newMachine);
}
dupeData.ItemsDB.AddItem(item.Value, renamedMachine.Key, sourceRemapping[sourceIndex], statsOnly: false);
dupeData.AddItemDB(item.Value, renamedMachine.Key, sourceRemapping[sourceIndex], statsOnly: false);
#if NET40_OR_GREATER || NETCOREAPP
});
#else
@@ -1109,7 +1109,7 @@ namespace SabreTools.DatFiles
#else
if (item.GetFieldValue<DupeType>(DatItem.DupeTypeKey).HasFlag(DupeType.Internal) || item.GetFieldValue<DupeType>(DatItem.DupeTypeKey) == 0x00)
#endif
outDats[item.GetFieldValue<Source?>(DatItem.SourceKey)!.Index].Items.Add(key, item);
outDats[item.GetFieldValue<Source?>(DatItem.SourceKey)!.Index].Add(key, item);
}
#if NET40_OR_GREATER || NETCOREAPP
});
@@ -1187,24 +1187,24 @@ namespace SabreTools.DatFiles
// Loop through and add all sources
foreach (var source in sources)
{
long newSourceIndex = outDats[0].ItemsDB.AddSource(source.Value);
long newSourceIndex = outDats[0].AddSourceDB(source.Value);
sourceRemapping[source.Key] = newSourceIndex;
for (int i = 1; i < outDats.Count; i++)
{
_ = outDats[i].ItemsDB.AddSource(source.Value);
_ = outDats[i].AddSourceDB(source.Value);
}
}
// Loop through and add all machines
foreach (var machine in machines)
{
long newMachineIndex = outDats[0].ItemsDB.AddMachine(machine.Value);
long newMachineIndex = outDats[0].AddMachineDB(machine.Value);
machineRemapping[machine.Key] = newMachineIndex;
for (int i = 1; i < outDats.Count; i++)
{
_ = outDats[i].ItemsDB.AddMachine(machine.Value);
_ = outDats[i].AddMachineDB(machine.Value);
}
}
@@ -1235,7 +1235,7 @@ namespace SabreTools.DatFiles
#else
if (item.Value.GetFieldValue<DupeType>(DatItem.DupeTypeKey).HasFlag(DupeType.Internal) || item.Value.GetFieldValue<DupeType>(DatItem.DupeTypeKey) == 0x00)
#endif
outDats[source.Index].ItemsDB.AddItem(item.Value, machineRemapping[machineIndex], sourceRemapping[sourceIndex], statsOnly: false);
outDats[source.Index].AddItemDB(item.Value, machineRemapping[machineIndex], sourceRemapping[sourceIndex], statsOnly: false);
#if NET40_OR_GREATER || NETCOREAPP
});
#else
@@ -1321,7 +1321,7 @@ namespace SabreTools.DatFiles
continue;
newrom.GetFieldValue<Machine>(DatItem.MachineKey)!.SetFieldValue<string?>(Models.Metadata.Machine.NameKey, newrom.GetFieldValue<Machine>(DatItem.MachineKey)!.GetStringFieldValue(Models.Metadata.Machine.NameKey) + $" ({Path.GetFileNameWithoutExtension(inputs[newrom.GetFieldValue<Source?>(DatItem.SourceKey)!.Index].CurrentPath)})");
outerDiffData.Items.Add(key, newrom);
outerDiffData.Add(key, newrom);
}
}
#if NET40_OR_GREATER || NETCOREAPP
@@ -1380,14 +1380,14 @@ namespace SabreTools.DatFiles
// Loop through and add all sources
foreach (var source in sources)
{
long newSourceIndex = outerDiffData.ItemsDB.AddSource(source.Value);
long newSourceIndex = outerDiffData.AddSourceDB(source.Value);
sourceRemapping[source.Key] = newSourceIndex;
}
// Loop through and add all machines
foreach (var machine in machines)
{
long newMachineIndex = outerDiffData.ItemsDB.AddMachine(machine.Value);
long newMachineIndex = outerDiffData.AddMachineDB(machine.Value);
machineRemapping[machine.Key] = newMachineIndex;
}
@@ -1434,11 +1434,11 @@ namespace SabreTools.DatFiles
{
var newMachine = currentMachine.Value.Clone() as Machine;
newMachine!.SetFieldValue<string?>(Models.Metadata.Machine.NameKey, renamedMachineName);
long newMachineIndex = outerDiffData.ItemsDB.AddMachine(newMachine);
long newMachineIndex = outerDiffData.AddMachineDB(newMachine);
renamedMachine = new KeyValuePair<long, Machine?>(newMachineIndex, newMachine);
}
outerDiffData.ItemsDB.AddItem(item.Value, renamedMachine.Key, sourceRemapping[sourceIndex], statsOnly: false);
outerDiffData.AddItemDB(item.Value, renamedMachine.Key, sourceRemapping[sourceIndex], statsOnly: false);
#if NET40_OR_GREATER || NETCOREAPP
});
#else
@@ -1523,11 +1523,11 @@ namespace SabreTools.DatFiles
foreach (string key in keys)
{
// Add everything from the key to the internal DAT
addTo.Items.AddRange(key, addFrom.Items[key]);
addTo.Add(key, addFrom.Items[key]);
// Now remove the key from the source DAT
if (delete)
addFrom.Items.Remove(key);
addFrom.Remove(key);
}
// Now remove the file dictionary from the source DAT
@@ -1557,14 +1557,14 @@ namespace SabreTools.DatFiles
// Loop through and add all sources
foreach (var source in sources)
{
long newSourceIndex = addTo.ItemsDB.AddSource(source.Value);
long newSourceIndex = addTo.AddSourceDB(source.Value);
sourceRemapping[source.Key] = newSourceIndex;
}
// Loop through and add all machines
foreach (var machine in machines)
{
long newMachineIndex = addTo.ItemsDB.AddMachine(machine.Value);
long newMachineIndex = addTo.AddMachineDB(machine.Value);
machineRemapping[machine.Key] = newMachineIndex;
}
@@ -1581,7 +1581,7 @@ namespace SabreTools.DatFiles
long machineIndex = itemMachineMappings[item.Key];
long sourceIndex = itemSourceMappings[item.Key];
addTo.ItemsDB.AddItem(item.Value, machineRemapping[machineIndex], sourceRemapping[sourceIndex], statsOnly: false);
addTo.AddItemDB(item.Value, machineRemapping[machineIndex], sourceRemapping[sourceIndex], statsOnly: false);
// Now remove the key from the source DAT
if (delete)
@@ -1630,7 +1630,7 @@ namespace SabreTools.DatFiles
{
var source = item.GetFieldValue<Source?>(DatItem.SourceKey);
if (source != null && source.Index == index)
indexDat.Items.Add(key, item);
indexDat.Add(key, item);
}
#if NET40_OR_GREATER || NETCOREAPP
});
@@ -1662,14 +1662,14 @@ namespace SabreTools.DatFiles
// Loop through and add all sources
foreach (var source in sources)
{
long newSourceIndex = indexDat.ItemsDB.AddSource(source.Value);
long newSourceIndex = indexDat.AddSourceDB(source.Value);
sourceRemapping[source.Key] = newSourceIndex;
}
// Loop through and add all machines
foreach (var machine in machines)
{
long newMachineIndex = indexDat.ItemsDB.AddMachine(machine.Value);
long newMachineIndex = indexDat.AddMachineDB(machine.Value);
machineRemapping[machine.Key] = newMachineIndex;
}
@@ -1690,7 +1690,7 @@ namespace SabreTools.DatFiles
var source = datFile.ItemsDB.GetSource(sourceIndex);
if (source != null && source.Index == index)
indexDat.ItemsDB.AddItem(item.Value, machineRemapping[machineIndex], sourceRemapping[sourceIndex], statsOnly: false);
indexDat.AddItemDB(item.Value, machineRemapping[machineIndex], sourceRemapping[sourceIndex], statsOnly: false);
#if NET40_OR_GREATER || NETCOREAPP
});
#else

View File

@@ -37,7 +37,7 @@ namespace SabreTools.DatFiles.Formats
var sr = new StreamReader(fs, new UTF8Encoding(false));
var jtr = new JsonTextReader(sr);
var source = new Source(indexId, filename);
long sourceIndex = ItemsDB.AddSource(source);
long sourceIndex = AddSourceDB(source);
// If we got a null reader, just return
if (jtr == null)
@@ -149,7 +149,7 @@ namespace SabreTools.DatFiles.Formats
// Add the machine to the dictionary
long machineIndex = -1;
if (machine != null)
machineIndex = ItemsDB.AddMachine(machine);
machineIndex = AddMachineDB(machine);
// Read items, if possible
if (machineObj.ContainsKey("items"))
@@ -359,8 +359,8 @@ namespace SabreTools.DatFiles.Formats
{
datItem.CopyMachineInformation(machine);
datItem.SetFieldValue<Source?>(DatItem.SourceKey, source);
Items.AddItem(datItem, statsOnly);
ItemsDB.AddItem(datItem, machineIndex, sourceIndex, statsOnly);
AddItem(datItem, statsOnly);
AddItemDB(datItem, machineIndex, sourceIndex, statsOnly);
}
}

View File

@@ -42,7 +42,7 @@ namespace SabreTools.DatFiles.Formats
ValidationType = ValidationType.None,
});
var source = new Source(indexId, filename);
long sourceIndex = ItemsDB.AddSource(source);
long sourceIndex = AddSourceDB(source);
// If we got a null reader, just return
if (xtr == null)
@@ -129,7 +129,7 @@ namespace SabreTools.DatFiles.Formats
XmlSerializer xs = new(typeof(Machine));
machine = xs?.Deserialize(xtr.ReadSubtree()) as Machine;
if (machine != null)
machineIndex = ItemsDB.AddMachine(machine);
machineIndex = AddMachineDB(machine);
xtr.Skip();
break;
@@ -181,8 +181,8 @@ namespace SabreTools.DatFiles.Formats
{
item.CopyMachineInformation(machine);
item.SetFieldValue<Source?>(DatItem.SourceKey, source);
Items.AddItem(item, statsOnly);
ItemsDB.AddItem(item, machineIndex, sourceIndex, statsOnly);
AddItem(item, statsOnly);
AddItemDB(item, machineIndex, sourceIndex, statsOnly);
}
xtr.Skip();
break;

View File

@@ -139,7 +139,7 @@ namespace SabreTools.DatFiles
if (value == null)
items[key] = null;
else
AddRange(key, value);
Add(key, value);
}
}
@@ -175,7 +175,25 @@ namespace SabreTools.DatFiles
/// <param name="value">Value to add to the dictionary</param>
public void Add(string key, List<DatItem>? value)
{
AddRange(key, value);
// Explicit lock for some weird corner cases
lock (key)
{
// If the value is null or empty, just return
if (value == null || value.Count == 0)
return;
// Ensure the key exists
EnsureKey(key);
// Now add the value
items[key]!.AddRange(value);
// Now update the statistics
foreach (DatItem item in value)
{
DatStatistics.AddItemStatistics(item);
}
}
}
/// <summary>
@@ -278,40 +296,12 @@ namespace SabreTools.DatFiles
return key;
}
/// <summary>
/// Add a range of values to the file dictionary
/// </summary>
/// <param name="key">Key in the dictionary to add to</param>
/// <param name="value">Value to add to the dictionary</param>
public void AddRange(string key, List<DatItem>? value)
{
// Explicit lock for some weird corner cases
lock (key)
{
// If the value is null or empty, just return
if (value == null || value.Count == 0)
return;
// Ensure the key exists
EnsureKey(key);
// Now add the value
items[key]!.AddRange(value);
// Now update the statistics
foreach (DatItem item in value)
{
DatStatistics.AddItemStatistics(item);
}
}
}
/// <summary>
/// Remove any keys that have null or empty values
/// </summary>
public void ClearEmpty()
{
List<string> keys = [.. items.Keys];
string[] keys = [.. Keys];
foreach (string key in keys)
{
#if NET40_OR_GREATER || NETCOREAPP
@@ -347,18 +337,18 @@ namespace SabreTools.DatFiles
/// </summary>
public void ClearMarked()
{
List<string> keys = [.. items.Keys];
string[] keys = [.. Keys];
foreach (string key in keys)
{
// Skip invalid item lists
List<DatItem>? oldItemList = items[key];
List<DatItem>? oldItemList = this[key];
if (oldItemList == null)
return;
List<DatItem> newItemList = oldItemList.FindAll(i => i.GetBoolFieldValue(DatItem.RemoveKey) != true);
Remove(key);
AddRange(key, newItemList);
Add(key, newItemList);
}
}
@@ -605,8 +595,8 @@ namespace SabreTools.DatFiles
// Add back all roms with the proper flags
Remove(key);
AddRange(key, output);
AddRange(key, left);
Add(key, output);
Add(key, left);
return output;
}
@@ -777,7 +767,7 @@ namespace SabreTools.DatFiles
// Add the list back to the dictionary
Reset(key);
AddRange(key, sortedlist);
Add(key, sortedlist);
#if NET40_OR_GREATER || NETCOREAPP
});
#else
@@ -1057,7 +1047,7 @@ namespace SabreTools.DatFiles
}
Remove(key);
AddRange(key, items);
Add(key, items);
#if NET40_OR_GREATER || NETCOREAPP
});
#else
@@ -1184,7 +1174,7 @@ namespace SabreTools.DatFiles
// Replace the old list of roms with the new one
Remove(key);
AddRange(key, newItems);
Add(key, newItems);
#if NET40_OR_GREATER || NETCOREAPP
});
#else
@@ -1337,7 +1327,7 @@ namespace SabreTools.DatFiles
{
// If the slot option is missing
if (string.IsNullOrEmpty(slotOption))
// If the machine doesn't exist then we continue
// If the machine doesn't exist then we continue
continue;
// Add to the list of new slot option names

View File

@@ -295,14 +295,6 @@ namespace SabreTools.DatFiles
if (!_buckets.ContainsKey(key))
continue;
// If the value is null, remove
else if (_buckets[key] == null)
#if NET40_OR_GREATER || NETCOREAPP
_buckets.TryRemove(key, out _);
#else
_buckets.Remove(key);
#endif
// If there are no non-blank items, remove
else if (!_buckets[key].Exists(i => GetItem(i) != null && GetItem(i) is not Blank))
#if NET40_OR_GREATER || NETCOREAPP