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

@@ -28,7 +28,7 @@ namespace SabreTools.DatFiles.Test
DatFile datFile = new Formats.Logiqx(null, deprecated: false);
datFile.SetHeader(header);
datFile.Items.Add("key", new Rom());
datFile.Add("key", new Rom());
Models.Metadata.MetadataFile? actual = datFile.ConvertToMetadata();
Assert.NotNull(actual);
@@ -76,7 +76,7 @@ namespace SabreTools.DatFiles.Test
];
DatFile datFile = new Formats.SabreJSON(null);
datFile.Items.Add("key", datItems);
datFile.Add("key", datItems);
Models.Metadata.MetadataFile? actual = datFile.ConvertToMetadata();
Assert.NotNull(actual);

View File

@@ -29,8 +29,8 @@ namespace SabreTools.DatFiles.Test
{
DatFile? datFile = new Formats.Logiqx(datFile: null, deprecated: false);
datFile.Header.SetFieldValue(Models.Metadata.Header.NameKey, "name");
datFile.Items.Add("key", new Rom());
datFile.ItemsDB.AddItem(new Rom(), 0, 0, false);
datFile.Add("key", new Rom());
datFile.AddItemDB(new Rom(), 0, 0, false);
DatFile created = new Formats.Logiqx(datFile, deprecated: false);
@@ -183,8 +183,8 @@ namespace SabreTools.DatFiles.Test
{
DatFile datFile = new Formats.Logiqx(datFile: null, deprecated: false);
datFile.Header.SetFieldValue(Models.Metadata.Header.NameKey, "name");
datFile.Items.Add("key", new Rom());
datFile.ItemsDB.AddItem(new Rom(), 0, 0, false);
datFile.Add("key", new Rom());
datFile.AddItemDB(new Rom(), 0, 0, false);
datFile.ResetDictionary();

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

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

View File

@@ -145,15 +145,11 @@ namespace SabreTools.DatTools
}
// Remove all marked items
datFile.Items.ClearMarked();
datFile.ItemsDB.ClearMarked();
datFile.ClearMarked();
// We remove any blanks, if we aren't supposed to have any
if (KeepEmptyGames == false)
{
datFile.Items.ClearEmpty();
datFile.ItemsDB.ClearEmpty();
}
datFile.ClearEmpty();
}
catch (Exception ex) when (!throwOnError)
{

View File

@@ -230,7 +230,7 @@ namespace SabreTools.DatTools
{
// Add the list if it doesn't exist already
Rom rom = baseFile.ConvertToRom();
datFile.Items.Add(rom.GetKey(ItemKey.CRC), rom);
datFile.Add(rom.GetKey(ItemKey.CRC), rom);
_staticLogger.Verbose($"File added: {Path.GetFileNameWithoutExtension(item)}");
}
else
@@ -441,7 +441,7 @@ namespace SabreTools.DatTools
// Add the file information to the DAT
string key = datItem.GetKey(ItemKey.CRC);
datFile.Items.Add(key, datItem);
datFile.Add(key, datItem);
_staticLogger.Verbose($"File added: {datItem.GetName() ?? string.Empty}");
}

View File

@@ -639,7 +639,7 @@ namespace SabreTools.DatTools
var machine = new Machine();
machine.SetFieldValue<string?>(Models.Metadata.Machine.DescriptionKey, Path.GetFileNameWithoutExtension(item.GetName()));
machine.SetFieldValue<string?>(Models.Metadata.Machine.NameKey, Path.GetFileNameWithoutExtension(item.GetName()));
long machineIndex = datFile.ItemsDB.AddMachine(machine);
long machineIndex = datFile.AddMachineDB(machine);
// If we are coming from an archive, set the correct machine name
if (machinename != null)
@@ -648,7 +648,7 @@ namespace SabreTools.DatTools
machine.SetFieldValue<string?>(Models.Metadata.Machine.NameKey, machinename);
}
long index = datFile.ItemsDB.AddItem(item, machineIndex, -1, false);
long index = datFile.AddItemDB(item, machineIndex, -1, false);
dupes[index] = item;
return true;
}

View File

@@ -85,16 +85,16 @@ namespace SabreTools.DatTools
{
if (Array.IndexOf(newExtA, (item.GetName() ?? string.Empty).GetNormalizedExtension()) > -1)
{
extADat.Items.Add(key, item);
extADat.Add(key, item);
}
if (Array.IndexOf(newExtB, (item.GetName() ?? string.Empty).GetNormalizedExtension()) > -1)
{
extBDat.Items.Add(key, item);
extBDat.Add(key, item);
}
else
{
extADat.Items.Add(key, item);
extBDat.Items.Add(key, item);
extADat.Add(key, item);
extBDat.Add(key, item);
}
}
#if NET40_OR_GREATER || NETCOREAPP
@@ -155,16 +155,16 @@ namespace SabreTools.DatTools
// Loop through and add all sources
foreach (var source in sources)
{
long newSourceIndex = extADat.ItemsDB.AddSource(source.Value);
_ = extBDat.ItemsDB.AddSource(source.Value);
long newSourceIndex = extADat.AddSourceDB(source.Value);
_ = extBDat.AddSourceDB(source.Value);
sourceRemapping[source.Key] = newSourceIndex;
}
// Loop through and add all machines
foreach (var machine in machines)
{
long newMachineIndex = extADat.ItemsDB.AddMachine(machine.Value);
_ = extBDat.ItemsDB.AddMachine(machine.Value);
long newMachineIndex = extADat.AddMachineDB(machine.Value);
_ = extBDat.AddMachineDB(machine.Value);
machineRemapping[machine.Key] = newMachineIndex;
}
@@ -183,16 +183,16 @@ namespace SabreTools.DatTools
if (newExtA.Contains((item.Value.GetName() ?? string.Empty).GetNormalizedExtension()))
{
extADat.ItemsDB.AddItem(item.Value, machineRemapping[machineIndex], sourceRemapping[sourceIndex], statsOnly: false);
extADat.AddItemDB(item.Value, machineRemapping[machineIndex], sourceRemapping[sourceIndex], statsOnly: false);
}
else if (newExtB.Contains((item.Value.GetName() ?? string.Empty).GetNormalizedExtension()))
{
extBDat.ItemsDB.AddItem(item.Value, machineRemapping[machineIndex], sourceRemapping[sourceIndex], statsOnly: false);
extBDat.AddItemDB(item.Value, machineRemapping[machineIndex], sourceRemapping[sourceIndex], statsOnly: false);
}
else
{
extADat.ItemsDB.AddItem(item.Value, machineRemapping[machineIndex], sourceRemapping[sourceIndex], statsOnly: false);
extBDat.ItemsDB.AddItem(item.Value, machineRemapping[machineIndex], sourceRemapping[sourceIndex], statsOnly: false);
extADat.AddItemDB(item.Value, machineRemapping[machineIndex], sourceRemapping[sourceIndex], statsOnly: false);
extBDat.AddItemDB(item.Value, machineRemapping[machineIndex], sourceRemapping[sourceIndex], statsOnly: false);
}
#if NET40_OR_GREATER || NETCOREAPP
});
@@ -263,49 +263,49 @@ namespace SabreTools.DatTools
{
case Disk disk:
if (disk.GetStringFieldValue(Models.Metadata.Disk.StatusKey).AsEnumValue<ItemStatus>() == ItemStatus.Nodump)
fieldDats[Models.Metadata.Disk.StatusKey].Items.Add(key, item);
fieldDats[Models.Metadata.Disk.StatusKey].Add(key, item);
else if (!string.IsNullOrEmpty(disk.GetStringFieldValue(Models.Metadata.Disk.SHA1Key)))
fieldDats[Models.Metadata.Disk.SHA1Key].Items.Add(key, item);
fieldDats[Models.Metadata.Disk.SHA1Key].Add(key, item);
else if (!string.IsNullOrEmpty(disk.GetStringFieldValue(Models.Metadata.Disk.MD5Key)))
fieldDats[Models.Metadata.Disk.MD5Key].Items.Add(key, item);
fieldDats[Models.Metadata.Disk.MD5Key].Add(key, item);
else if (!string.IsNullOrEmpty(disk.GetStringFieldValue(Models.Metadata.Disk.MD5Key)))
fieldDats[Models.Metadata.Disk.MD5Key].Items.Add(key, item);
fieldDats[Models.Metadata.Disk.MD5Key].Add(key, item);
else
fieldDats["null"].Items.Add(key, item);
fieldDats["null"].Add(key, item);
break;
case Media media:
if (!string.IsNullOrEmpty(media.GetStringFieldValue(Models.Metadata.Media.SHA256Key)))
fieldDats[Models.Metadata.Media.SHA256Key].Items.Add(key, item);
fieldDats[Models.Metadata.Media.SHA256Key].Add(key, item);
else if (!string.IsNullOrEmpty(media.GetStringFieldValue(Models.Metadata.Media.SHA1Key)))
fieldDats[Models.Metadata.Media.SHA1Key].Items.Add(key, item);
fieldDats[Models.Metadata.Media.SHA1Key].Add(key, item);
else if (!string.IsNullOrEmpty(media.GetStringFieldValue(Models.Metadata.Media.MD5Key)))
fieldDats[Models.Metadata.Media.MD5Key].Items.Add(key, item);
fieldDats[Models.Metadata.Media.MD5Key].Add(key, item);
else
fieldDats["null"].Items.Add(key, item);
fieldDats["null"].Add(key, item);
break;
case Rom rom:
if (rom.GetStringFieldValue(Models.Metadata.Rom.StatusKey).AsEnumValue<ItemStatus>() == ItemStatus.Nodump)
fieldDats[Models.Metadata.Rom.StatusKey].Items.Add(key, item);
fieldDats[Models.Metadata.Rom.StatusKey].Add(key, item);
else if (!string.IsNullOrEmpty(rom.GetStringFieldValue(Models.Metadata.Rom.SHA512Key)))
fieldDats[Models.Metadata.Rom.SHA512Key].Items.Add(key, item);
fieldDats[Models.Metadata.Rom.SHA512Key].Add(key, item);
else if (!string.IsNullOrEmpty(rom.GetStringFieldValue(Models.Metadata.Rom.SHA384Key)))
fieldDats[Models.Metadata.Rom.SHA384Key].Items.Add(key, item);
fieldDats[Models.Metadata.Rom.SHA384Key].Add(key, item);
else if (!string.IsNullOrEmpty(rom.GetStringFieldValue(Models.Metadata.Rom.SHA256Key)))
fieldDats[Models.Metadata.Rom.SHA256Key].Items.Add(key, item);
fieldDats[Models.Metadata.Rom.SHA256Key].Add(key, item);
else if (!string.IsNullOrEmpty(rom.GetStringFieldValue(Models.Metadata.Rom.SHA1Key)))
fieldDats[Models.Metadata.Rom.SHA1Key].Items.Add(key, item);
fieldDats[Models.Metadata.Rom.SHA1Key].Add(key, item);
else if (!string.IsNullOrEmpty(rom.GetStringFieldValue(Models.Metadata.Rom.MD5Key)))
fieldDats[Models.Metadata.Rom.MD5Key].Items.Add(key, item);
fieldDats[Models.Metadata.Rom.MD5Key].Add(key, item);
else if (!string.IsNullOrEmpty(rom.GetStringFieldValue(Models.Metadata.Rom.MD4Key)))
fieldDats[Models.Metadata.Rom.MD4Key].Items.Add(key, item);
fieldDats[Models.Metadata.Rom.MD4Key].Add(key, item);
else if (!string.IsNullOrEmpty(rom.GetStringFieldValue(Models.Metadata.Rom.MD2Key)))
fieldDats[Models.Metadata.Rom.MD2Key].Items.Add(key, item);
fieldDats[Models.Metadata.Rom.MD2Key].Add(key, item);
else if (!string.IsNullOrEmpty(rom.GetStringFieldValue(Models.Metadata.Rom.CRCKey)))
fieldDats[Models.Metadata.Rom.CRCKey].Items.Add(key, item);
fieldDats[Models.Metadata.Rom.CRCKey].Add(key, item);
else
fieldDats["null"].Items.Add(key, item);
fieldDats["null"].Add(key, item);
break;
default:
@@ -371,32 +371,32 @@ namespace SabreTools.DatTools
// Loop through and add all sources
foreach (var source in sources)
{
long newSourceIndex = fieldDats[Models.Metadata.Rom.StatusKey].ItemsDB.AddSource(source.Value);
long newSourceIndex = fieldDats[Models.Metadata.Rom.StatusKey].AddSourceDB(source.Value);
sourceRemapping[source.Key] = newSourceIndex;
_ = fieldDats[Models.Metadata.Rom.SHA512Key].ItemsDB.AddSource(source.Value);
_ = fieldDats[Models.Metadata.Rom.SHA384Key].ItemsDB.AddSource(source.Value);
_ = fieldDats[Models.Metadata.Rom.SHA256Key].ItemsDB.AddSource(source.Value);
_ = fieldDats[Models.Metadata.Rom.SHA1Key].ItemsDB.AddSource(source.Value);
_ = fieldDats[Models.Metadata.Rom.MD5Key].ItemsDB.AddSource(source.Value);
_ = fieldDats[Models.Metadata.Rom.MD4Key].ItemsDB.AddSource(source.Value);
_ = fieldDats[Models.Metadata.Rom.MD2Key].ItemsDB.AddSource(source.Value);
_ = fieldDats[Models.Metadata.Rom.CRCKey].ItemsDB.AddSource(source.Value);
_ = fieldDats["null"].ItemsDB.AddSource(source.Value);
_ = fieldDats[Models.Metadata.Rom.SHA512Key].AddSourceDB(source.Value);
_ = fieldDats[Models.Metadata.Rom.SHA384Key].AddSourceDB(source.Value);
_ = fieldDats[Models.Metadata.Rom.SHA256Key].AddSourceDB(source.Value);
_ = fieldDats[Models.Metadata.Rom.SHA1Key].AddSourceDB(source.Value);
_ = fieldDats[Models.Metadata.Rom.MD5Key].AddSourceDB(source.Value);
_ = fieldDats[Models.Metadata.Rom.MD4Key].AddSourceDB(source.Value);
_ = fieldDats[Models.Metadata.Rom.MD2Key].AddSourceDB(source.Value);
_ = fieldDats[Models.Metadata.Rom.CRCKey].AddSourceDB(source.Value);
_ = fieldDats["null"].AddSourceDB(source.Value);
}
// Loop through and add all machines
foreach (var machine in machines)
{
long newMachineIndex = fieldDats[Models.Metadata.Rom.StatusKey].ItemsDB.AddMachine(machine.Value);
_ = fieldDats[Models.Metadata.Rom.SHA512Key].ItemsDB.AddMachine(machine.Value);
_ = fieldDats[Models.Metadata.Rom.SHA384Key].ItemsDB.AddMachine(machine.Value);
_ = fieldDats[Models.Metadata.Rom.SHA256Key].ItemsDB.AddMachine(machine.Value);
_ = fieldDats[Models.Metadata.Rom.SHA1Key].ItemsDB.AddMachine(machine.Value);
_ = fieldDats[Models.Metadata.Rom.MD5Key].ItemsDB.AddMachine(machine.Value);
_ = fieldDats[Models.Metadata.Rom.MD4Key].ItemsDB.AddMachine(machine.Value);
_ = fieldDats[Models.Metadata.Rom.MD2Key].ItemsDB.AddMachine(machine.Value);
_ = fieldDats[Models.Metadata.Rom.CRCKey].ItemsDB.AddMachine(machine.Value);
_ = fieldDats["null"].ItemsDB.AddMachine(machine.Value);
long newMachineIndex = fieldDats[Models.Metadata.Rom.StatusKey].AddMachineDB(machine.Value);
_ = fieldDats[Models.Metadata.Rom.SHA512Key].AddMachineDB(machine.Value);
_ = fieldDats[Models.Metadata.Rom.SHA384Key].AddMachineDB(machine.Value);
_ = fieldDats[Models.Metadata.Rom.SHA256Key].AddMachineDB(machine.Value);
_ = fieldDats[Models.Metadata.Rom.SHA1Key].AddMachineDB(machine.Value);
_ = fieldDats[Models.Metadata.Rom.MD5Key].AddMachineDB(machine.Value);
_ = fieldDats[Models.Metadata.Rom.MD4Key].AddMachineDB(machine.Value);
_ = fieldDats[Models.Metadata.Rom.MD2Key].AddMachineDB(machine.Value);
_ = fieldDats[Models.Metadata.Rom.CRCKey].AddMachineDB(machine.Value);
_ = fieldDats["null"].AddMachineDB(machine.Value);
machineRemapping[machine.Key] = newMachineIndex;
}
@@ -418,49 +418,49 @@ namespace SabreTools.DatTools
{
case Disk disk:
if (disk.GetStringFieldValue(Models.Metadata.Disk.StatusKey).AsEnumValue<ItemStatus>() == ItemStatus.Nodump)
fieldDats[Models.Metadata.Disk.StatusKey].ItemsDB.AddItem(item.Value, machineRemapping[machineIndex], sourceRemapping[sourceIndex], statsOnly: false);
fieldDats[Models.Metadata.Disk.StatusKey].AddItemDB(item.Value, machineRemapping[machineIndex], sourceRemapping[sourceIndex], statsOnly: false);
else if (!string.IsNullOrEmpty(disk.GetStringFieldValue(Models.Metadata.Disk.SHA1Key)))
fieldDats[Models.Metadata.Disk.SHA1Key].ItemsDB.AddItem(item.Value, machineRemapping[machineIndex], sourceRemapping[sourceIndex], statsOnly: false);
fieldDats[Models.Metadata.Disk.SHA1Key].AddItemDB(item.Value, machineRemapping[machineIndex], sourceRemapping[sourceIndex], statsOnly: false);
else if (!string.IsNullOrEmpty(disk.GetStringFieldValue(Models.Metadata.Disk.MD5Key)))
fieldDats[Models.Metadata.Disk.MD5Key].ItemsDB.AddItem(item.Value, machineRemapping[machineIndex], sourceRemapping[sourceIndex], statsOnly: false);
fieldDats[Models.Metadata.Disk.MD5Key].AddItemDB(item.Value, machineRemapping[machineIndex], sourceRemapping[sourceIndex], statsOnly: false);
else if (!string.IsNullOrEmpty(disk.GetStringFieldValue(Models.Metadata.Disk.MD5Key)))
fieldDats[Models.Metadata.Disk.MD5Key].ItemsDB.AddItem(item.Value, machineRemapping[machineIndex], sourceRemapping[sourceIndex], statsOnly: false);
fieldDats[Models.Metadata.Disk.MD5Key].AddItemDB(item.Value, machineRemapping[machineIndex], sourceRemapping[sourceIndex], statsOnly: false);
else
fieldDats["null"].ItemsDB.AddItem(item.Value, machineRemapping[machineIndex], sourceRemapping[sourceIndex], statsOnly: false);
fieldDats["null"].AddItemDB(item.Value, machineRemapping[machineIndex], sourceRemapping[sourceIndex], statsOnly: false);
break;
case Media media:
if (!string.IsNullOrEmpty(media.GetStringFieldValue(Models.Metadata.Media.SHA256Key)))
fieldDats[Models.Metadata.Media.SHA256Key].ItemsDB.AddItem(item.Value, machineRemapping[machineIndex], sourceRemapping[sourceIndex], statsOnly: false);
fieldDats[Models.Metadata.Media.SHA256Key].AddItemDB(item.Value, machineRemapping[machineIndex], sourceRemapping[sourceIndex], statsOnly: false);
else if (!string.IsNullOrEmpty(media.GetStringFieldValue(Models.Metadata.Media.SHA1Key)))
fieldDats[Models.Metadata.Media.SHA1Key].ItemsDB.AddItem(item.Value, machineRemapping[machineIndex], sourceRemapping[sourceIndex], statsOnly: false);
fieldDats[Models.Metadata.Media.SHA1Key].AddItemDB(item.Value, machineRemapping[machineIndex], sourceRemapping[sourceIndex], statsOnly: false);
else if (!string.IsNullOrEmpty(media.GetStringFieldValue(Models.Metadata.Media.MD5Key)))
fieldDats[Models.Metadata.Media.MD5Key].ItemsDB.AddItem(item.Value, machineRemapping[machineIndex], sourceRemapping[sourceIndex], statsOnly: false);
fieldDats[Models.Metadata.Media.MD5Key].AddItemDB(item.Value, machineRemapping[machineIndex], sourceRemapping[sourceIndex], statsOnly: false);
else
fieldDats["null"].ItemsDB.AddItem(item.Value, machineRemapping[machineIndex], sourceRemapping[sourceIndex], statsOnly: false);
fieldDats["null"].AddItemDB(item.Value, machineRemapping[machineIndex], sourceRemapping[sourceIndex], statsOnly: false);
break;
case Rom rom:
if (rom.GetStringFieldValue(Models.Metadata.Rom.StatusKey).AsEnumValue<ItemStatus>() == ItemStatus.Nodump)
fieldDats[Models.Metadata.Rom.StatusKey].ItemsDB.AddItem(item.Value, machineRemapping[machineIndex], sourceRemapping[sourceIndex], statsOnly: false);
fieldDats[Models.Metadata.Rom.StatusKey].AddItemDB(item.Value, machineRemapping[machineIndex], sourceRemapping[sourceIndex], statsOnly: false);
else if (!string.IsNullOrEmpty(rom.GetStringFieldValue(Models.Metadata.Rom.SHA512Key)))
fieldDats[Models.Metadata.Rom.SHA512Key].ItemsDB.AddItem(item.Value, machineRemapping[machineIndex], sourceRemapping[sourceIndex], statsOnly: false);
fieldDats[Models.Metadata.Rom.SHA512Key].AddItemDB(item.Value, machineRemapping[machineIndex], sourceRemapping[sourceIndex], statsOnly: false);
else if (!string.IsNullOrEmpty(rom.GetStringFieldValue(Models.Metadata.Rom.SHA384Key)))
fieldDats[Models.Metadata.Rom.SHA384Key].ItemsDB.AddItem(item.Value, machineRemapping[machineIndex], sourceRemapping[sourceIndex], statsOnly: false);
fieldDats[Models.Metadata.Rom.SHA384Key].AddItemDB(item.Value, machineRemapping[machineIndex], sourceRemapping[sourceIndex], statsOnly: false);
else if (!string.IsNullOrEmpty(rom.GetStringFieldValue(Models.Metadata.Rom.SHA256Key)))
fieldDats[Models.Metadata.Rom.SHA256Key].ItemsDB.AddItem(item.Value, machineRemapping[machineIndex], sourceRemapping[sourceIndex], statsOnly: false);
fieldDats[Models.Metadata.Rom.SHA256Key].AddItemDB(item.Value, machineRemapping[machineIndex], sourceRemapping[sourceIndex], statsOnly: false);
else if (!string.IsNullOrEmpty(rom.GetStringFieldValue(Models.Metadata.Rom.SHA1Key)))
fieldDats[Models.Metadata.Rom.SHA1Key].ItemsDB.AddItem(item.Value, machineRemapping[machineIndex], sourceRemapping[sourceIndex], statsOnly: false);
fieldDats[Models.Metadata.Rom.SHA1Key].AddItemDB(item.Value, machineRemapping[machineIndex], sourceRemapping[sourceIndex], statsOnly: false);
else if (!string.IsNullOrEmpty(rom.GetStringFieldValue(Models.Metadata.Rom.MD5Key)))
fieldDats[Models.Metadata.Rom.MD5Key].ItemsDB.AddItem(item.Value, machineRemapping[machineIndex], sourceRemapping[sourceIndex], statsOnly: false);
fieldDats[Models.Metadata.Rom.MD5Key].AddItemDB(item.Value, machineRemapping[machineIndex], sourceRemapping[sourceIndex], statsOnly: false);
else if (!string.IsNullOrEmpty(rom.GetStringFieldValue(Models.Metadata.Rom.MD4Key)))
fieldDats[Models.Metadata.Rom.MD4Key].ItemsDB.AddItem(item.Value, machineRemapping[machineIndex], sourceRemapping[sourceIndex], statsOnly: false);
fieldDats[Models.Metadata.Rom.MD4Key].AddItemDB(item.Value, machineRemapping[machineIndex], sourceRemapping[sourceIndex], statsOnly: false);
else if (!string.IsNullOrEmpty(rom.GetStringFieldValue(Models.Metadata.Rom.MD2Key)))
fieldDats[Models.Metadata.Rom.MD2Key].ItemsDB.AddItem(item.Value, machineRemapping[machineIndex], sourceRemapping[sourceIndex], statsOnly: false);
fieldDats[Models.Metadata.Rom.MD2Key].AddItemDB(item.Value, machineRemapping[machineIndex], sourceRemapping[sourceIndex], statsOnly: false);
else if (!string.IsNullOrEmpty(rom.GetStringFieldValue(Models.Metadata.Rom.CRCKey)))
fieldDats[Models.Metadata.Rom.CRCKey].ItemsDB.AddItem(item.Value, machineRemapping[machineIndex], sourceRemapping[sourceIndex], statsOnly: false);
fieldDats[Models.Metadata.Rom.CRCKey].AddItemDB(item.Value, machineRemapping[machineIndex], sourceRemapping[sourceIndex], statsOnly: false);
else
fieldDats["null"].ItemsDB.AddItem(item.Value, machineRemapping[machineIndex], sourceRemapping[sourceIndex], statsOnly: false);
fieldDats["null"].AddItemDB(item.Value, machineRemapping[machineIndex], sourceRemapping[sourceIndex], statsOnly: false);
break;
default:
@@ -532,7 +532,7 @@ namespace SabreTools.DatTools
items.ForEach(item => item.GetFieldValue<Machine>(DatItem.MachineKey)!.SetFieldValue<string?>(Models.Metadata.Machine.DescriptionKey, Path.GetFileName(item.GetFieldValue<Machine>(DatItem.MachineKey)!.GetStringFieldValue(Models.Metadata.Machine.DescriptionKey))));
// Now add the game to the output DAT
tempDat.Items.AddRange(key, items);
tempDat.Add(key, items);
// Then set the DAT name to be the parent directory name
tempDat.Header.SetFieldValue<string?>(Models.Metadata.Header.NameKey, Path.GetDirectoryName(key));
@@ -649,19 +649,19 @@ namespace SabreTools.DatTools
{
// If the file is not a Rom, it automatically goes in the "lesser" dat
if (item is not Rom rom)
lessThan.Items.Add(key, item);
lessThan.Add(key, item);
// If the file is a Rom and has no size, put it in the "lesser" dat
else if (rom.GetInt64FieldValue(Models.Metadata.Rom.SizeKey) == null)
lessThan.Items.Add(key, item);
lessThan.Add(key, item);
// If the file is a Rom and less than the radix, put it in the "lesser" dat
else if (rom.GetInt64FieldValue(Models.Metadata.Rom.SizeKey) < radix)
lessThan.Items.Add(key, item);
lessThan.Add(key, item);
// If the file is a Rom and greater than or equal to the radix, put it in the "greater" dat
else if (rom.GetInt64FieldValue(Models.Metadata.Rom.SizeKey) >= radix)
greaterThan.Items.Add(key, item);
greaterThan.Add(key, item);
}
#if NET40_OR_GREATER || NETCOREAPP
});
@@ -709,16 +709,16 @@ namespace SabreTools.DatTools
// Loop through and add all sources
foreach (var source in sources)
{
long newSourceIndex = lessThan.ItemsDB.AddSource(source.Value);
_ = greaterThan.ItemsDB.AddSource(source.Value);
long newSourceIndex = lessThan.AddSourceDB(source.Value);
_ = greaterThan.AddSourceDB(source.Value);
sourceRemapping[source.Key] = newSourceIndex;
}
// Loop through and add all machines
foreach (var machine in machines)
{
long newMachineIndex = lessThan.ItemsDB.AddMachine(machine.Value);
_ = greaterThan.ItemsDB.AddMachine(machine.Value);
long newMachineIndex = lessThan.AddMachineDB(machine.Value);
_ = greaterThan.AddMachineDB(machine.Value);
machineRemapping[machine.Key] = newMachineIndex;
}
@@ -737,19 +737,19 @@ namespace SabreTools.DatTools
// If the file is not a Rom, it automatically goes in the "lesser" dat
if (item.Value is not Rom rom)
lessThan.ItemsDB.AddItem(item.Value, machineRemapping[machineIndex], sourceRemapping[sourceIndex], statsOnly: false);
lessThan.AddItemDB(item.Value, machineRemapping[machineIndex], sourceRemapping[sourceIndex], statsOnly: false);
// If the file is a Rom and has no size, put it in the "lesser" dat
else if (rom.GetInt64FieldValue(Models.Metadata.Rom.SizeKey) == null)
lessThan.ItemsDB.AddItem(item.Value, machineRemapping[machineIndex], sourceRemapping[sourceIndex], statsOnly: false);
lessThan.AddItemDB(item.Value, machineRemapping[machineIndex], sourceRemapping[sourceIndex], statsOnly: false);
// If the file is a Rom and less than the radix, put it in the "lesser" dat
else if (rom.GetInt64FieldValue(Models.Metadata.Rom.SizeKey) < radix)
lessThan.ItemsDB.AddItem(item.Value, machineRemapping[machineIndex], sourceRemapping[sourceIndex], statsOnly: false);
lessThan.AddItemDB(item.Value, machineRemapping[machineIndex], sourceRemapping[sourceIndex], statsOnly: false);
// If the file is a Rom and greater than or equal to the radix, put it in the "greater" dat
else if (rom.GetInt64FieldValue(Models.Metadata.Rom.SizeKey) >= radix)
greaterThan.ItemsDB.AddItem(item.Value, machineRemapping[machineIndex], sourceRemapping[sourceIndex], statsOnly: false);
greaterThan.AddItemDB(item.Value, machineRemapping[machineIndex], sourceRemapping[sourceIndex], statsOnly: false);
#if NET40_OR_GREATER || NETCOREAPP
});
#else
@@ -933,7 +933,7 @@ namespace SabreTools.DatTools
foreach (DatItem item in items)
{
if (item.GetStringFieldValue(Models.Metadata.DatItem.TypeKey).AsEnumValue<ItemType>() == itemType)
indexDat.Items.Add(key, item);
indexDat.Add(key, item);
}
#if NET40_OR_GREATER || NETCOREAPP
});
@@ -965,14 +965,14 @@ namespace SabreTools.DatTools
// 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;
}
@@ -990,7 +990,7 @@ namespace SabreTools.DatTools
long sourceIndex = itemSourceMappings[item.Key];
if (item.Value.GetStringFieldValue(Models.Metadata.DatItem.TypeKey).AsEnumValue<ItemType>() == itemType)
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

@@ -106,7 +106,7 @@ namespace SabreTools.DatTools
datFile.Header.SetFieldValue<string?>(DatHeader.FileNameKey, $"fixDAT_{datFile.Header.GetStringFieldValue(DatHeader.FileNameKey)}");
datFile.Header.SetFieldValue<string?>(Models.Metadata.Header.NameKey, $"fixDAT_{datFile.Header.GetStringFieldValue(Models.Metadata.Header.NameKey)}");
datFile.Header.SetFieldValue<string?>(Models.Metadata.Header.DescriptionKey, $"fixDAT_{datFile.Header.GetStringFieldValue(Models.Metadata.Header.DescriptionKey)}");
datFile.Items.ClearMarked();
datFile.ClearMarked();
return success;
}
@@ -191,7 +191,7 @@ namespace SabreTools.DatTools
datFile.Header.SetFieldValue<string?>(DatHeader.FileNameKey, $"fixDAT_{datFile.Header.GetStringFieldValue(DatHeader.FileNameKey)}");
datFile.Header.SetFieldValue<string?>(Models.Metadata.Header.NameKey, $"fixDAT_{datFile.Header.GetStringFieldValue(Models.Metadata.Header.NameKey)}");
datFile.Header.SetFieldValue<string?>(Models.Metadata.Header.DescriptionKey, $"fixDAT_{datFile.Header.GetStringFieldValue(Models.Metadata.Header.DescriptionKey)}");
datFile.ItemsDB.ClearMarked();
datFile.ClearMarked();
return success;
}
@@ -240,7 +240,7 @@ namespace SabreTools.DatTools
datFile.Header.SetFieldValue<string?>(DatHeader.FileNameKey, $"fixDAT_{datFile.Header.GetStringFieldValue(DatHeader.FileNameKey)}");
datFile.Header.SetFieldValue<string?>(Models.Metadata.Header.NameKey, $"fixDAT_{datFile.Header.GetStringFieldValue(Models.Metadata.Header.NameKey)}");
datFile.Header.SetFieldValue<string?>(Models.Metadata.Header.DescriptionKey, $"fixDAT_{datFile.Header.GetStringFieldValue(Models.Metadata.Header.DescriptionKey)}");
datFile.Items.ClearMarked();
datFile.ClearMarked();
return success;
}
@@ -288,7 +288,7 @@ namespace SabreTools.DatTools
datFile.Header.SetFieldValue<string?>(DatHeader.FileNameKey, $"fixDAT_{datFile.Header.GetStringFieldValue(DatHeader.FileNameKey)}");
datFile.Header.SetFieldValue<string?>(Models.Metadata.Header.NameKey, $"fixDAT_{datFile.Header.GetStringFieldValue(Models.Metadata.Header.NameKey)}");
datFile.Header.SetFieldValue<string?>(Models.Metadata.Header.DescriptionKey, $"fixDAT_{datFile.Header.GetStringFieldValue(Models.Metadata.Header.DescriptionKey)}");
datFile.ItemsDB.ClearMarked();
datFile.ClearMarked();
return success;
}

View File

@@ -432,10 +432,8 @@ Reset the internal state: reset();";
// Cleanup after the filter
// TODO: We might not want to remove immediately
batchState.DatFile.Items.ClearMarked();
batchState.DatFile.ItemsDB.ClearMarked();
batchState.DatFile.Items.ClearEmpty();
batchState.DatFile.ItemsDB.ClearEmpty();
batchState.DatFile.ClearMarked();
batchState.DatFile.ClearEmpty();
}
}

View File

@@ -121,8 +121,7 @@ namespace SabreTools.Features
datdata.Header.SetFieldValue<string?>(DatHeader.FileNameKey, $"fixDAT_{Header.GetStringFieldValue(DatHeader.FileNameKey)}");
datdata.Header.SetFieldValue<string?>(Models.Metadata.Header.NameKey, $"fixDAT_{Header.GetStringFieldValue(Models.Metadata.Header.NameKey)}");
datdata.Header.SetFieldValue<string?>(Models.Metadata.Header.DescriptionKey, $"fixDAT_{Header.GetStringFieldValue(Models.Metadata.Header.DescriptionKey)}");
datdata.Items.ClearMarked();
datdata.ItemsDB.ClearMarked();
datdata.ClearMarked();
Writer.Write(datdata, OutputDir);
}
}
@@ -168,8 +167,7 @@ namespace SabreTools.Features
datdata.Header.SetFieldValue<string?>(Models.Metadata.Header.DescriptionKey,
$"fixDAT_{Header.GetStringFieldValue(Models.Metadata.Header.DescriptionKey)}");
datdata.Items.ClearMarked();
datdata.ItemsDB.ClearMarked();
datdata.ClearMarked();
Writer.Write(datdata, OutputDir);
}
}