Start adding IDDB in parallel with existing dictionary

This commit is contained in:
Matt Nadareski
2024-03-19 15:21:01 -04:00
parent eda21cdf73
commit b494394249
6 changed files with 191 additions and 100 deletions

View File

@@ -1,6 +1,5 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using SabreTools.Core;
using SabreTools.Core.Tools; using SabreTools.Core.Tools;
using SabreTools.DatItems; using SabreTools.DatItems;
@@ -371,142 +370,145 @@ namespace SabreTools.DatFiles
} }
} }
// Add the machine to the dictionary
long machineIndex = ItemsDB.AddMachine(machine);
// Convert items in the machine // Convert items in the machine
if (item.ContainsKey(Models.Metadata.Machine.AdjusterKey)) if (item.ContainsKey(Models.Metadata.Machine.AdjusterKey))
{ {
var items = ReadItemArray<Models.Metadata.Adjuster>(item, Models.Metadata.Machine.AdjusterKey); var items = ReadItemArray<Models.Metadata.Adjuster>(item, Models.Metadata.Machine.AdjusterKey);
ProcessItems(items, machine, filename, indexId, statsOnly); ProcessItems(items, machine, machineIndex, filename, indexId, statsOnly);
} }
if (item.ContainsKey(Models.Metadata.Machine.ArchiveKey)) if (item.ContainsKey(Models.Metadata.Machine.ArchiveKey))
{ {
var items = ReadItemArray<Models.Metadata.Archive>(item, Models.Metadata.Machine.ArchiveKey); var items = ReadItemArray<Models.Metadata.Archive>(item, Models.Metadata.Machine.ArchiveKey);
ProcessItems(items, machine, filename, indexId, statsOnly); ProcessItems(items, machine, machineIndex, filename, indexId, statsOnly);
} }
if (item.ContainsKey(Models.Metadata.Machine.BiosSetKey)) if (item.ContainsKey(Models.Metadata.Machine.BiosSetKey))
{ {
var items = ReadItemArray<Models.Metadata.BiosSet>(item, Models.Metadata.Machine.BiosSetKey); var items = ReadItemArray<Models.Metadata.BiosSet>(item, Models.Metadata.Machine.BiosSetKey);
ProcessItems(items, machine, filename, indexId, statsOnly); ProcessItems(items, machine, machineIndex, filename, indexId, statsOnly);
} }
if (item.ContainsKey(Models.Metadata.Machine.ChipKey)) if (item.ContainsKey(Models.Metadata.Machine.ChipKey))
{ {
var items = ReadItemArray<Models.Metadata.Chip>(item, Models.Metadata.Machine.ChipKey); var items = ReadItemArray<Models.Metadata.Chip>(item, Models.Metadata.Machine.ChipKey);
ProcessItems(items, machine, filename, indexId, statsOnly); ProcessItems(items, machine, machineIndex, filename, indexId, statsOnly);
} }
if (item.ContainsKey(Models.Metadata.Machine.ConfigurationKey)) if (item.ContainsKey(Models.Metadata.Machine.ConfigurationKey))
{ {
var items = ReadItemArray<Models.Metadata.Configuration>(item, Models.Metadata.Machine.ConfigurationKey); var items = ReadItemArray<Models.Metadata.Configuration>(item, Models.Metadata.Machine.ConfigurationKey);
ProcessItems(items, machine, filename, indexId, statsOnly); ProcessItems(items, machine, machineIndex, filename, indexId, statsOnly);
} }
if (item.ContainsKey(Models.Metadata.Machine.DeviceKey)) if (item.ContainsKey(Models.Metadata.Machine.DeviceKey))
{ {
var items = ReadItemArray<Models.Metadata.Device>(item, Models.Metadata.Machine.DeviceKey); var items = ReadItemArray<Models.Metadata.Device>(item, Models.Metadata.Machine.DeviceKey);
ProcessItems(items, machine, filename, indexId, statsOnly); ProcessItems(items, machine, machineIndex, filename, indexId, statsOnly);
} }
if (item.ContainsKey(Models.Metadata.Machine.DeviceRefKey)) if (item.ContainsKey(Models.Metadata.Machine.DeviceRefKey))
{ {
var items = ReadItemArray<Models.Metadata.DeviceRef>(item, Models.Metadata.Machine.DeviceRefKey); var items = ReadItemArray<Models.Metadata.DeviceRef>(item, Models.Metadata.Machine.DeviceRefKey);
ProcessItems(items, machine, filename, indexId, statsOnly); ProcessItems(items, machine, machineIndex, filename, indexId, statsOnly);
} }
if (item.ContainsKey(Models.Metadata.Machine.DipSwitchKey)) if (item.ContainsKey(Models.Metadata.Machine.DipSwitchKey))
{ {
var items = ReadItemArray<Models.Metadata.DipSwitch>(item, Models.Metadata.Machine.DipSwitchKey); var items = ReadItemArray<Models.Metadata.DipSwitch>(item, Models.Metadata.Machine.DipSwitchKey);
ProcessItems(items, machine, filename, indexId, statsOnly); ProcessItems(items, machine, machineIndex, filename, indexId, statsOnly);
} }
if (item.ContainsKey(Models.Metadata.Machine.DiskKey)) if (item.ContainsKey(Models.Metadata.Machine.DiskKey))
{ {
var items = ReadItemArray<Models.Metadata.Disk>(item, Models.Metadata.Machine.DiskKey); var items = ReadItemArray<Models.Metadata.Disk>(item, Models.Metadata.Machine.DiskKey);
ProcessItems(items, machine, filename, indexId, statsOnly); ProcessItems(items, machine, machineIndex, filename, indexId, statsOnly);
} }
if (item.ContainsKey(Models.Metadata.Machine.DisplayKey)) if (item.ContainsKey(Models.Metadata.Machine.DisplayKey))
{ {
var items = ReadItemArray<Models.Metadata.Display>(item, Models.Metadata.Machine.DisplayKey); var items = ReadItemArray<Models.Metadata.Display>(item, Models.Metadata.Machine.DisplayKey);
ProcessItems(items, machine, filename, indexId, statsOnly); ProcessItems(items, machine, machineIndex, filename, indexId, statsOnly);
} }
if (item.ContainsKey(Models.Metadata.Machine.DriverKey)) if (item.ContainsKey(Models.Metadata.Machine.DriverKey))
{ {
var items = ReadItemArray<Models.Metadata.Driver>(item, Models.Metadata.Machine.DriverKey); var items = ReadItemArray<Models.Metadata.Driver>(item, Models.Metadata.Machine.DriverKey);
ProcessItems(items, machine, filename, indexId, statsOnly); ProcessItems(items, machine, machineIndex, filename, indexId, statsOnly);
} }
if (item.ContainsKey(Models.Metadata.Machine.DumpKey)) if (item.ContainsKey(Models.Metadata.Machine.DumpKey))
{ {
var items = ReadItemArray<Models.Metadata.Dump>(item, Models.Metadata.Machine.DumpKey); var items = ReadItemArray<Models.Metadata.Dump>(item, Models.Metadata.Machine.DumpKey);
string? machineName = machine.GetStringFieldValue(Models.Metadata.Machine.NameKey); string? machineName = machine.GetStringFieldValue(Models.Metadata.Machine.NameKey);
ProcessItems(items, machine, filename, indexId, statsOnly, machineName); ProcessItems(items, machine, machineIndex, filename, indexId, statsOnly, machineName);
} }
if (item.ContainsKey(Models.Metadata.Machine.FeatureKey)) if (item.ContainsKey(Models.Metadata.Machine.FeatureKey))
{ {
var items = ReadItemArray<Models.Metadata.Feature>(item, Models.Metadata.Machine.FeatureKey); var items = ReadItemArray<Models.Metadata.Feature>(item, Models.Metadata.Machine.FeatureKey);
ProcessItems(items, machine, filename, indexId, statsOnly); ProcessItems(items, machine, machineIndex, filename, indexId, statsOnly);
} }
if (item.ContainsKey(Models.Metadata.Machine.InfoKey)) if (item.ContainsKey(Models.Metadata.Machine.InfoKey))
{ {
var items = ReadItemArray<Models.Metadata.Info>(item, Models.Metadata.Machine.InfoKey); var items = ReadItemArray<Models.Metadata.Info>(item, Models.Metadata.Machine.InfoKey);
ProcessItems(items, machine, filename, indexId, statsOnly); ProcessItems(items, machine, machineIndex, filename, indexId, statsOnly);
} }
if (item.ContainsKey(Models.Metadata.Machine.InputKey)) if (item.ContainsKey(Models.Metadata.Machine.InputKey))
{ {
var items = ReadItemArray<Models.Metadata.Input>(item, Models.Metadata.Machine.InputKey); var items = ReadItemArray<Models.Metadata.Input>(item, Models.Metadata.Machine.InputKey);
ProcessItems(items, machine, filename, indexId, statsOnly); ProcessItems(items, machine, machineIndex, filename, indexId, statsOnly);
} }
if (item.ContainsKey(Models.Metadata.Machine.MediaKey)) if (item.ContainsKey(Models.Metadata.Machine.MediaKey))
{ {
var items = ReadItemArray<Models.Metadata.Media>(item, Models.Metadata.Machine.MediaKey); var items = ReadItemArray<Models.Metadata.Media>(item, Models.Metadata.Machine.MediaKey);
ProcessItems(items, machine, filename, indexId, statsOnly); ProcessItems(items, machine, machineIndex, filename, indexId, statsOnly);
} }
if (item.ContainsKey(Models.Metadata.Machine.PartKey)) if (item.ContainsKey(Models.Metadata.Machine.PartKey))
{ {
var items = ReadItemArray<Models.Metadata.Part>(item, Models.Metadata.Machine.PartKey); var items = ReadItemArray<Models.Metadata.Part>(item, Models.Metadata.Machine.PartKey);
ProcessItems(items, machine, filename, indexId, statsOnly); ProcessItems(items, machine, machineIndex, filename, indexId, statsOnly);
} }
if (item.ContainsKey(Models.Metadata.Machine.PortKey)) if (item.ContainsKey(Models.Metadata.Machine.PortKey))
{ {
var items = ReadItemArray<Models.Metadata.Port>(item, Models.Metadata.Machine.PortKey); var items = ReadItemArray<Models.Metadata.Port>(item, Models.Metadata.Machine.PortKey);
ProcessItems(items, machine, filename, indexId, statsOnly); ProcessItems(items, machine, machineIndex, filename, indexId, statsOnly);
} }
if (item.ContainsKey(Models.Metadata.Machine.RamOptionKey)) if (item.ContainsKey(Models.Metadata.Machine.RamOptionKey))
{ {
var items = ReadItemArray<Models.Metadata.RamOption>(item, Models.Metadata.Machine.RamOptionKey); var items = ReadItemArray<Models.Metadata.RamOption>(item, Models.Metadata.Machine.RamOptionKey);
ProcessItems(items, machine, filename, indexId, statsOnly); ProcessItems(items, machine, machineIndex, filename, indexId, statsOnly);
} }
if (item.ContainsKey(Models.Metadata.Machine.ReleaseKey)) if (item.ContainsKey(Models.Metadata.Machine.ReleaseKey))
{ {
var items = ReadItemArray<Models.Metadata.Release>(item, Models.Metadata.Machine.ReleaseKey); var items = ReadItemArray<Models.Metadata.Release>(item, Models.Metadata.Machine.ReleaseKey);
ProcessItems(items, machine, filename, indexId, statsOnly); ProcessItems(items, machine, machineIndex, filename, indexId, statsOnly);
} }
if (item.ContainsKey(Models.Metadata.Machine.RomKey)) if (item.ContainsKey(Models.Metadata.Machine.RomKey))
{ {
var items = ReadItemArray<Models.Metadata.Rom>(item, Models.Metadata.Machine.RomKey); var items = ReadItemArray<Models.Metadata.Rom>(item, Models.Metadata.Machine.RomKey);
ProcessItems(items, machine, filename, indexId, statsOnly); ProcessItems(items, machine, machineIndex, filename, indexId, statsOnly);
} }
if (item.ContainsKey(Models.Metadata.Machine.SampleKey)) if (item.ContainsKey(Models.Metadata.Machine.SampleKey))
{ {
var items = ReadItemArray<Models.Metadata.Sample>(item, Models.Metadata.Machine.SampleKey); var items = ReadItemArray<Models.Metadata.Sample>(item, Models.Metadata.Machine.SampleKey);
ProcessItems(items, machine, filename, indexId, statsOnly); ProcessItems(items, machine, machineIndex, filename, indexId, statsOnly);
} }
if (item.ContainsKey(Models.Metadata.Machine.SharedFeatKey)) if (item.ContainsKey(Models.Metadata.Machine.SharedFeatKey))
{ {
var items = ReadItemArray<Models.Metadata.SharedFeat>(item, Models.Metadata.Machine.SharedFeatKey); var items = ReadItemArray<Models.Metadata.SharedFeat>(item, Models.Metadata.Machine.SharedFeatKey);
ProcessItems(items, machine, filename, indexId, statsOnly); ProcessItems(items, machine, machineIndex, filename, indexId, statsOnly);
} }
if (item.ContainsKey(Models.Metadata.Machine.SlotKey)) if (item.ContainsKey(Models.Metadata.Machine.SlotKey))
{ {
var items = ReadItemArray<Models.Metadata.Slot>(item, Models.Metadata.Machine.SlotKey); var items = ReadItemArray<Models.Metadata.Slot>(item, Models.Metadata.Machine.SlotKey);
ProcessItems(items, machine, filename, indexId, statsOnly); ProcessItems(items, machine, machineIndex, filename, indexId, statsOnly);
} }
if (item.ContainsKey(Models.Metadata.Machine.SoftwareListKey)) if (item.ContainsKey(Models.Metadata.Machine.SoftwareListKey))
{ {
var items = ReadItemArray<Models.Metadata.SoftwareList>(item, Models.Metadata.Machine.SoftwareListKey); var items = ReadItemArray<Models.Metadata.SoftwareList>(item, Models.Metadata.Machine.SoftwareListKey);
ProcessItems(items, machine, filename, indexId, statsOnly); ProcessItems(items, machine, machineIndex, filename, indexId, statsOnly);
} }
if (item.ContainsKey(Models.Metadata.Machine.SoundKey)) if (item.ContainsKey(Models.Metadata.Machine.SoundKey))
{ {
var items = ReadItemArray<Models.Metadata.Sound>(item, Models.Metadata.Machine.SoundKey); var items = ReadItemArray<Models.Metadata.Sound>(item, Models.Metadata.Machine.SoundKey);
ProcessItems(items, machine, filename, indexId, statsOnly); ProcessItems(items, machine, machineIndex, filename, indexId, statsOnly);
} }
if (item.ContainsKey(Models.Metadata.Machine.VideoKey)) if (item.ContainsKey(Models.Metadata.Machine.VideoKey))
{ {
var items = ReadItemArray<Models.Metadata.Video>(item, Models.Metadata.Machine.VideoKey); var items = ReadItemArray<Models.Metadata.Video>(item, Models.Metadata.Machine.VideoKey);
ProcessItems(items, machine, filename, indexId, statsOnly); ProcessItems(items, machine, machineIndex, filename, indexId, statsOnly);
} }
} }
@@ -515,10 +517,11 @@ namespace SabreTools.DatFiles
/// </summary> /// </summary>
/// <param name="items">Array of internal items to convert</param> /// <param name="items">Array of internal items to convert</param>
/// <param name="machine">Machine to use with the converted items</param> /// <param name="machine">Machine to use with the converted items</param>
/// <param name="machineIndex">Index of the Machine to use with the converted items</param>
/// <param name="filename">Name of the file to be parsed</param> /// <param name="filename">Name of the file to be parsed</param>
/// <param name="indexId">Index ID for the DAT</param> /// <param name="indexId">Index ID for the DAT</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param> /// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
private void ProcessItems(Models.Metadata.Adjuster[]? items, DatItems.Machine machine, string filename, int indexId, bool statsOnly) private void ProcessItems(Models.Metadata.Adjuster[]? items, DatItems.Machine machine, long machineIndex, string filename, int indexId, bool statsOnly)
{ {
// If the array is null or empty, return without processing // If the array is null or empty, return without processing
if (items == null || items.Length == 0) if (items == null || items.Length == 0)
@@ -549,6 +552,7 @@ namespace SabreTools.DatFiles
} }
ParseAddHelper(datItem, statsOnly); ParseAddHelper(datItem, statsOnly);
ParseAddHelper(datItem, machineIndex, statsOnly);
} }
} }
@@ -557,10 +561,11 @@ namespace SabreTools.DatFiles
/// </summary> /// </summary>
/// <param name="items">Array of internal items to convert</param> /// <param name="items">Array of internal items to convert</param>
/// <param name="machine">Machine to use with the converted items</param> /// <param name="machine">Machine to use with the converted items</param>
/// <param name="machineIndex">Index of the Machine to use with the converted items</param>
/// <param name="filename">Name of the file to be parsed</param> /// <param name="filename">Name of the file to be parsed</param>
/// <param name="indexId">Index ID for the DAT</param> /// <param name="indexId">Index ID for the DAT</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param> /// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
private void ProcessItems(Models.Metadata.Archive[]? items, DatItems.Machine machine, string filename, int indexId, bool statsOnly) private void ProcessItems(Models.Metadata.Archive[]? items, DatItems.Machine machine, long machineIndex, string filename, int indexId, bool statsOnly)
{ {
// If the array is null or empty, return without processing // If the array is null or empty, return without processing
if (items == null || items.Length == 0) if (items == null || items.Length == 0)
@@ -573,6 +578,7 @@ namespace SabreTools.DatFiles
datItem.SetFieldValue<DatItems.Source?>(DatItems.DatItem.SourceKey, new DatItems.Source { Index = indexId, Name = filename }); datItem.SetFieldValue<DatItems.Source?>(DatItems.DatItem.SourceKey, new DatItems.Source { Index = indexId, Name = filename });
datItem.CopyMachineInformation(machine); datItem.CopyMachineInformation(machine);
ParseAddHelper(datItem, statsOnly); ParseAddHelper(datItem, statsOnly);
ParseAddHelper(datItem, machineIndex, statsOnly);
} }
} }
@@ -581,10 +587,11 @@ namespace SabreTools.DatFiles
/// </summary> /// </summary>
/// <param name="items">Array of internal items to convert</param> /// <param name="items">Array of internal items to convert</param>
/// <param name="machine">Machine to use with the converted items</param> /// <param name="machine">Machine to use with the converted items</param>
/// <param name="machineIndex">Index of the Machine to use with the converted items</param>
/// <param name="filename">Name of the file to be parsed</param> /// <param name="filename">Name of the file to be parsed</param>
/// <param name="indexId">Index ID for the DAT</param> /// <param name="indexId">Index ID for the DAT</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param> /// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
private void ProcessItems(Models.Metadata.BiosSet[]? items, DatItems.Machine machine, string filename, int indexId, bool statsOnly) private void ProcessItems(Models.Metadata.BiosSet[]? items, DatItems.Machine machine, long machineIndex, string filename, int indexId, bool statsOnly)
{ {
// If the array is null or empty, return without processing // If the array is null or empty, return without processing
if (items == null || items.Length == 0) if (items == null || items.Length == 0)
@@ -602,6 +609,7 @@ namespace SabreTools.DatFiles
datItem.SetFieldValue<string?>(Models.Metadata.BiosSet.DefaultKey, datItem.GetBoolFieldValue(Models.Metadata.BiosSet.DefaultKey).FromYesNo()); datItem.SetFieldValue<string?>(Models.Metadata.BiosSet.DefaultKey, datItem.GetBoolFieldValue(Models.Metadata.BiosSet.DefaultKey).FromYesNo());
ParseAddHelper(datItem, statsOnly); ParseAddHelper(datItem, statsOnly);
ParseAddHelper(datItem, machineIndex, statsOnly);
} }
} }
@@ -610,10 +618,11 @@ namespace SabreTools.DatFiles
/// </summary> /// </summary>
/// <param name="items">Array of internal items to convert</param> /// <param name="items">Array of internal items to convert</param>
/// <param name="machine">Machine to use with the converted items</param> /// <param name="machine">Machine to use with the converted items</param>
/// <param name="machineIndex">Index of the Machine to use with the converted items</param>
/// <param name="filename">Name of the file to be parsed</param> /// <param name="filename">Name of the file to be parsed</param>
/// <param name="indexId">Index ID for the DAT</param> /// <param name="indexId">Index ID for the DAT</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param> /// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
private void ProcessItems(Models.Metadata.Chip[]? items, DatItems.Machine machine, string filename, int indexId, bool statsOnly) private void ProcessItems(Models.Metadata.Chip[]? items, DatItems.Machine machine, long machineIndex, string filename, int indexId, bool statsOnly)
{ {
// If the array is null or empty, return without processing // If the array is null or empty, return without processing
if (items == null || items.Length == 0) if (items == null || items.Length == 0)
@@ -633,6 +642,7 @@ namespace SabreTools.DatFiles
datItem.SetFieldValue<string?>(Models.Metadata.Chip.ChipTypeKey, datItem.GetStringFieldValue(Models.Metadata.Chip.ChipTypeKey).AsEnumValue<ChipType>().AsStringValue()); datItem.SetFieldValue<string?>(Models.Metadata.Chip.ChipTypeKey, datItem.GetStringFieldValue(Models.Metadata.Chip.ChipTypeKey).AsEnumValue<ChipType>().AsStringValue());
ParseAddHelper(datItem, statsOnly); ParseAddHelper(datItem, statsOnly);
ParseAddHelper(datItem, machineIndex, statsOnly);
} }
} }
@@ -641,10 +651,11 @@ namespace SabreTools.DatFiles
/// </summary> /// </summary>
/// <param name="items">Array of internal items to convert</param> /// <param name="items">Array of internal items to convert</param>
/// <param name="machine">Machine to use with the converted items</param> /// <param name="machine">Machine to use with the converted items</param>
/// <param name="machineIndex">Index of the Machine to use with the converted items</param>
/// <param name="filename">Name of the file to be parsed</param> /// <param name="filename">Name of the file to be parsed</param>
/// <param name="indexId">Index ID for the DAT</param> /// <param name="indexId">Index ID for the DAT</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param> /// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
private void ProcessItems(Models.Metadata.Configuration[]? items, DatItems.Machine machine, string filename, int indexId, bool statsOnly) private void ProcessItems(Models.Metadata.Configuration[]? items, DatItems.Machine machine, long machineIndex, string filename, int indexId, bool statsOnly)
{ {
// If the array is null or empty, return without processing // If the array is null or empty, return without processing
if (items == null || items.Length == 0) if (items == null || items.Length == 0)
@@ -719,6 +730,7 @@ namespace SabreTools.DatFiles
} }
ParseAddHelper(datItem, statsOnly); ParseAddHelper(datItem, statsOnly);
ParseAddHelper(datItem, machineIndex, statsOnly);
} }
} }
@@ -727,10 +739,11 @@ namespace SabreTools.DatFiles
/// </summary> /// </summary>
/// <param name="items">Array of internal items to convert</param> /// <param name="items">Array of internal items to convert</param>
/// <param name="machine">Machine to use with the converted items</param> /// <param name="machine">Machine to use with the converted items</param>
/// <param name="machineIndex">Index of the Machine to use with the converted items</param>
/// <param name="filename">Name of the file to be parsed</param> /// <param name="filename">Name of the file to be parsed</param>
/// <param name="indexId">Index ID for the DAT</param> /// <param name="indexId">Index ID for the DAT</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param> /// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
private void ProcessItems(Models.Metadata.Device[]? items, DatItems.Machine machine, string filename, int indexId, bool statsOnly) private void ProcessItems(Models.Metadata.Device[]? items, DatItems.Machine machine, long machineIndex, string filename, int indexId, bool statsOnly)
{ {
// If the array is null or empty, return without processing // If the array is null or empty, return without processing
if (items == null || items.Length == 0) if (items == null || items.Length == 0)
@@ -771,6 +784,7 @@ namespace SabreTools.DatFiles
} }
ParseAddHelper(datItem, statsOnly); ParseAddHelper(datItem, statsOnly);
ParseAddHelper(datItem, machineIndex, statsOnly);
} }
} }
@@ -779,10 +793,11 @@ namespace SabreTools.DatFiles
/// </summary> /// </summary>
/// <param name="items">Array of internal items to convert</param> /// <param name="items">Array of internal items to convert</param>
/// <param name="machine">Machine to use with the converted items</param> /// <param name="machine">Machine to use with the converted items</param>
/// <param name="machineIndex">Index of the Machine to use with the converted items</param>
/// <param name="filename">Name of the file to be parsed</param> /// <param name="filename">Name of the file to be parsed</param>
/// <param name="indexId">Index ID for the DAT</param> /// <param name="indexId">Index ID for the DAT</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param> /// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
private void ProcessItems(Models.Metadata.DeviceRef[]? items, DatItems.Machine machine, string filename, int indexId, bool statsOnly) private void ProcessItems(Models.Metadata.DeviceRef[]? items, DatItems.Machine machine, long machineIndex, string filename, int indexId, bool statsOnly)
{ {
// If the array is null or empty, return without processing // If the array is null or empty, return without processing
if (items == null || items.Length == 0) if (items == null || items.Length == 0)
@@ -795,6 +810,7 @@ namespace SabreTools.DatFiles
datItem.SetFieldValue<DatItems.Source?>(DatItems.DatItem.SourceKey, new DatItems.Source { Index = indexId, Name = filename }); datItem.SetFieldValue<DatItems.Source?>(DatItems.DatItem.SourceKey, new DatItems.Source { Index = indexId, Name = filename });
datItem.CopyMachineInformation(machine); datItem.CopyMachineInformation(machine);
ParseAddHelper(datItem, statsOnly); ParseAddHelper(datItem, statsOnly);
ParseAddHelper(datItem, machineIndex, statsOnly);
} }
} }
@@ -803,10 +819,11 @@ namespace SabreTools.DatFiles
/// </summary> /// </summary>
/// <param name="items">Array of internal items to convert</param> /// <param name="items">Array of internal items to convert</param>
/// <param name="machine">Machine to use with the converted items</param> /// <param name="machine">Machine to use with the converted items</param>
/// <param name="machineIndex">Index of the Machine to use with the converted items</param>
/// <param name="filename">Name of the file to be parsed</param> /// <param name="filename">Name of the file to be parsed</param>
/// <param name="indexId">Index ID for the DAT</param> /// <param name="indexId">Index ID for the DAT</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param> /// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
private void ProcessItems(Models.Metadata.DipSwitch[]? items, DatItems.Machine machine, string filename, int indexId, bool statsOnly) private void ProcessItems(Models.Metadata.DipSwitch[]? items, DatItems.Machine machine, long machineIndex, string filename, int indexId, bool statsOnly)
{ {
// If the array is null or empty, return without processing // If the array is null or empty, return without processing
if (items == null || items.Length == 0) if (items == null || items.Length == 0)
@@ -885,6 +902,7 @@ namespace SabreTools.DatFiles
} }
ParseAddHelper(datItem, statsOnly); ParseAddHelper(datItem, statsOnly);
ParseAddHelper(datItem, machineIndex, statsOnly);
} }
} }
@@ -893,10 +911,11 @@ namespace SabreTools.DatFiles
/// </summary> /// </summary>
/// <param name="items">Array of internal items to convert</param> /// <param name="items">Array of internal items to convert</param>
/// <param name="machine">Machine to use with the converted items</param> /// <param name="machine">Machine to use with the converted items</param>
/// <param name="machineIndex">Index of the Machine to use with the converted items</param>
/// <param name="filename">Name of the file to be parsed</param> /// <param name="filename">Name of the file to be parsed</param>
/// <param name="indexId">Index ID for the DAT</param> /// <param name="indexId">Index ID for the DAT</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param> /// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
private void ProcessItems(Models.Metadata.Disk[]? items, DatItems.Machine machine, string filename, int indexId, bool statsOnly) private void ProcessItems(Models.Metadata.Disk[]? items, DatItems.Machine machine, long machineIndex, string filename, int indexId, bool statsOnly)
{ {
// If the array is null or empty, return without processing // If the array is null or empty, return without processing
if (items == null || items.Length == 0) if (items == null || items.Length == 0)
@@ -924,6 +943,7 @@ namespace SabreTools.DatFiles
datItem.SetFieldValue<string?>(Models.Metadata.Disk.SHA1Key, TextHelper.NormalizeSHA1(datItem.GetStringFieldValue(Models.Metadata.Disk.SHA1Key))); datItem.SetFieldValue<string?>(Models.Metadata.Disk.SHA1Key, TextHelper.NormalizeSHA1(datItem.GetStringFieldValue(Models.Metadata.Disk.SHA1Key)));
ParseAddHelper(datItem, statsOnly); ParseAddHelper(datItem, statsOnly);
ParseAddHelper(datItem, machineIndex, statsOnly);
} }
} }
@@ -932,10 +952,11 @@ namespace SabreTools.DatFiles
/// </summary> /// </summary>
/// <param name="items">Array of internal items to convert</param> /// <param name="items">Array of internal items to convert</param>
/// <param name="machine">Machine to use with the converted items</param> /// <param name="machine">Machine to use with the converted items</param>
/// <param name="machineIndex">Index of the Machine to use with the converted items</param>
/// <param name="filename">Name of the file to be parsed</param> /// <param name="filename">Name of the file to be parsed</param>
/// <param name="indexId">Index ID for the DAT</param> /// <param name="indexId">Index ID for the DAT</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param> /// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
private void ProcessItems(Models.Metadata.Display[]? items, DatItems.Machine machine, string filename, int indexId, bool statsOnly) private void ProcessItems(Models.Metadata.Display[]? items, DatItems.Machine machine, long machineIndex, string filename, int indexId, bool statsOnly)
{ {
// If the array is null or empty, return without processing // If the array is null or empty, return without processing
if (items == null || items.Length == 0) if (items == null || items.Length == 0)
@@ -977,6 +998,7 @@ namespace SabreTools.DatFiles
datItem.SetFieldValue<string?>(Models.Metadata.Display.WidthKey, datItem.GetInt64FieldValue(Models.Metadata.Display.WidthKey).ToString()); datItem.SetFieldValue<string?>(Models.Metadata.Display.WidthKey, datItem.GetInt64FieldValue(Models.Metadata.Display.WidthKey).ToString());
ParseAddHelper(datItem, statsOnly); ParseAddHelper(datItem, statsOnly);
ParseAddHelper(datItem, machineIndex, statsOnly);
} }
} }
@@ -985,10 +1007,11 @@ namespace SabreTools.DatFiles
/// </summary> /// </summary>
/// <param name="items">Array of internal items to convert</param> /// <param name="items">Array of internal items to convert</param>
/// <param name="machine">Machine to use with the converted items</param> /// <param name="machine">Machine to use with the converted items</param>
/// <param name="machineIndex">Index of the Machine to use with the converted items</param>
/// <param name="filename">Name of the file to be parsed</param> /// <param name="filename">Name of the file to be parsed</param>
/// <param name="indexId">Index ID for the DAT</param> /// <param name="indexId">Index ID for the DAT</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param> /// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
private void ProcessItems(Models.Metadata.Driver[]? items, DatItems.Machine machine, string filename, int indexId, bool statsOnly) private void ProcessItems(Models.Metadata.Driver[]? items, DatItems.Machine machine, long machineIndex, string filename, int indexId, bool statsOnly)
{ {
// If the array is null or empty, return without processing // If the array is null or empty, return without processing
if (items == null || items.Length == 0) if (items == null || items.Length == 0)
@@ -1026,6 +1049,7 @@ namespace SabreTools.DatFiles
datItem.SetFieldValue<string?>(Models.Metadata.Driver.UnofficialKey, datItem.GetBoolFieldValue(Models.Metadata.Driver.UnofficialKey).FromYesNo()); datItem.SetFieldValue<string?>(Models.Metadata.Driver.UnofficialKey, datItem.GetBoolFieldValue(Models.Metadata.Driver.UnofficialKey).FromYesNo());
ParseAddHelper(datItem, statsOnly); ParseAddHelper(datItem, statsOnly);
ParseAddHelper(datItem, machineIndex, statsOnly);
} }
} }
@@ -1034,11 +1058,12 @@ namespace SabreTools.DatFiles
/// </summary> /// </summary>
/// <param name="items">Array of internal items to convert</param> /// <param name="items">Array of internal items to convert</param>
/// <param name="machine">Machine to use with the converted items</param> /// <param name="machine">Machine to use with the converted items</param>
/// <param name="machineIndex">Index of the Machine to use with the converted items</param>
/// <param name="filename">Name of the file to be parsed</param> /// <param name="filename">Name of the file to be parsed</param>
/// <param name="indexId">Index ID for the DAT</param> /// <param name="indexId">Index ID for the DAT</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param> /// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
/// <param name="machineName">Machine name to use when constructing item names</param> /// <param name="machineName">Machine name to use when constructing item names</param>
private void ProcessItems(Models.Metadata.Dump[]? items, DatItems.Machine machine, string filename, int indexId, bool statsOnly, string? machineName) private void ProcessItems(Models.Metadata.Dump[]? items, DatItems.Machine machine, long machineIndex, string filename, int indexId, bool statsOnly, string? machineName)
{ {
// If the array is null or empty, return without processing // If the array is null or empty, return without processing
if (items == null || items.Length == 0) if (items == null || items.Length == 0)
@@ -1073,45 +1098,46 @@ namespace SabreTools.DatFiles
string name = $"{machineName}_{index++}{(!string.IsNullOrEmpty(rom!.ReadString(Models.Metadata.Rom.RemarkKey)) ? $" {rom.ReadString(Models.Metadata.Rom.RemarkKey)}" : string.Empty)}"; string name = $"{machineName}_{index++}{(!string.IsNullOrEmpty(rom!.ReadString(Models.Metadata.Rom.RemarkKey)) ? $" {rom.ReadString(Models.Metadata.Rom.RemarkKey)}" : string.Empty)}";
var item = new DatItems.Formats.Rom(); var datItem = new DatItems.Formats.Rom();
item.SetName(name); datItem.SetName(name);
item.SetFieldValue<string?>(Models.Metadata.Rom.OffsetKey, rom.ReadString(Models.Metadata.Rom.StartKey)); datItem.SetFieldValue<string?>(Models.Metadata.Rom.OffsetKey, rom.ReadString(Models.Metadata.Rom.StartKey));
item.SetFieldValue<string?>(Models.Metadata.Rom.OpenMSXMediaType, subType.AsStringValue()); datItem.SetFieldValue<string?>(Models.Metadata.Rom.OpenMSXMediaType, subType.AsStringValue());
item.SetFieldValue<string?>(Models.Metadata.Rom.OpenMSXType, rom.ReadString(Models.Metadata.Rom.OpenMSXType) ?? rom.ReadString(Models.Metadata.Rom.TypeKey)); datItem.SetFieldValue<string?>(Models.Metadata.Rom.OpenMSXType, rom.ReadString(Models.Metadata.Rom.OpenMSXType) ?? rom.ReadString(Models.Metadata.Rom.TypeKey));
item.SetFieldValue<string?>(Models.Metadata.Rom.RemarkKey, rom.ReadString(Models.Metadata.Rom.RemarkKey)); datItem.SetFieldValue<string?>(Models.Metadata.Rom.RemarkKey, rom.ReadString(Models.Metadata.Rom.RemarkKey));
item.SetFieldValue<string?>(Models.Metadata.Rom.SHA1Key, rom.ReadString(Models.Metadata.Rom.SHA1Key)); datItem.SetFieldValue<string?>(Models.Metadata.Rom.SHA1Key, rom.ReadString(Models.Metadata.Rom.SHA1Key));
item.SetFieldValue<string?>(Models.Metadata.Rom.StartKey, rom.ReadString(Models.Metadata.Rom.StartKey)); datItem.SetFieldValue<string?>(Models.Metadata.Rom.StartKey, rom.ReadString(Models.Metadata.Rom.StartKey));
item.SetFieldValue<DatItems.Source?>(DatItems.DatItem.SourceKey, new DatItems.Source { Index = indexId, Name = filename }); datItem.SetFieldValue<DatItems.Source?>(DatItems.DatItem.SourceKey, new DatItems.Source { Index = indexId, Name = filename });
if (dump.Read<Models.Metadata.Original>(Models.Metadata.Dump.OriginalKey) != null) if (dump.Read<Models.Metadata.Original>(Models.Metadata.Dump.OriginalKey) != null)
{ {
var original = dump.Read<Models.Metadata.Original>(Models.Metadata.Dump.OriginalKey)!; var original = dump.Read<Models.Metadata.Original>(Models.Metadata.Dump.OriginalKey)!;
item.SetFieldValue<DatItems.Formats.Original?>("ORIGINAL", new DatItems.Formats.Original datItem.SetFieldValue<DatItems.Formats.Original?>("ORIGINAL", new DatItems.Formats.Original
{ {
Value = original.ReadBool(Models.Metadata.Original.ValueKey), Value = original.ReadBool(Models.Metadata.Original.ValueKey),
Content = original.ReadString(Models.Metadata.Original.ContentKey), Content = original.ReadString(Models.Metadata.Original.ContentKey),
}); });
} }
item.CopyMachineInformation(machine); datItem.CopyMachineInformation(machine);
// Process hash values // Process hash values
if (item.GetInt64FieldValue(Models.Metadata.Rom.SizeKey) != null) if (datItem.GetInt64FieldValue(Models.Metadata.Rom.SizeKey) != null)
item.SetFieldValue<string?>(Models.Metadata.Rom.SizeKey, item.GetInt64FieldValue(Models.Metadata.Rom.SizeKey).ToString()); datItem.SetFieldValue<string?>(Models.Metadata.Rom.SizeKey, datItem.GetInt64FieldValue(Models.Metadata.Rom.SizeKey).ToString());
if (item.GetStringFieldValue(Models.Metadata.Rom.CRCKey) != null) if (datItem.GetStringFieldValue(Models.Metadata.Rom.CRCKey) != null)
item.SetFieldValue<string?>(Models.Metadata.Rom.CRCKey, TextHelper.NormalizeCRC32(item.GetStringFieldValue(Models.Metadata.Rom.CRCKey))); datItem.SetFieldValue<string?>(Models.Metadata.Rom.CRCKey, TextHelper.NormalizeCRC32(datItem.GetStringFieldValue(Models.Metadata.Rom.CRCKey)));
if (item.GetStringFieldValue(Models.Metadata.Rom.MD5Key) != null) if (datItem.GetStringFieldValue(Models.Metadata.Rom.MD5Key) != null)
item.SetFieldValue<string?>(Models.Metadata.Rom.MD5Key, TextHelper.NormalizeMD5(item.GetStringFieldValue(Models.Metadata.Rom.MD5Key))); datItem.SetFieldValue<string?>(Models.Metadata.Rom.MD5Key, TextHelper.NormalizeMD5(datItem.GetStringFieldValue(Models.Metadata.Rom.MD5Key)));
if (item.GetStringFieldValue(Models.Metadata.Rom.SHA1Key) != null) if (datItem.GetStringFieldValue(Models.Metadata.Rom.SHA1Key) != null)
item.SetFieldValue<string?>(Models.Metadata.Rom.SHA1Key, TextHelper.NormalizeSHA1(item.GetStringFieldValue(Models.Metadata.Rom.SHA1Key))); datItem.SetFieldValue<string?>(Models.Metadata.Rom.SHA1Key, TextHelper.NormalizeSHA1(datItem.GetStringFieldValue(Models.Metadata.Rom.SHA1Key)));
if (item.GetStringFieldValue(Models.Metadata.Rom.SHA256Key) != null) if (datItem.GetStringFieldValue(Models.Metadata.Rom.SHA256Key) != null)
item.SetFieldValue<string?>(Models.Metadata.Rom.SHA256Key, TextHelper.NormalizeSHA256(item.GetStringFieldValue(Models.Metadata.Rom.SHA256Key))); datItem.SetFieldValue<string?>(Models.Metadata.Rom.SHA256Key, TextHelper.NormalizeSHA256(datItem.GetStringFieldValue(Models.Metadata.Rom.SHA256Key)));
if (item.GetStringFieldValue(Models.Metadata.Rom.SHA384Key) != null) if (datItem.GetStringFieldValue(Models.Metadata.Rom.SHA384Key) != null)
item.SetFieldValue<string?>(Models.Metadata.Rom.SHA384Key, TextHelper.NormalizeSHA384(item.GetStringFieldValue(Models.Metadata.Rom.SHA384Key))); datItem.SetFieldValue<string?>(Models.Metadata.Rom.SHA384Key, TextHelper.NormalizeSHA384(datItem.GetStringFieldValue(Models.Metadata.Rom.SHA384Key)));
if (item.GetStringFieldValue(Models.Metadata.Rom.SHA512Key) != null) if (datItem.GetStringFieldValue(Models.Metadata.Rom.SHA512Key) != null)
item.SetFieldValue<string?>(Models.Metadata.Rom.SHA512Key, TextHelper.NormalizeSHA512(item.GetStringFieldValue(Models.Metadata.Rom.SHA512Key))); datItem.SetFieldValue<string?>(Models.Metadata.Rom.SHA512Key, TextHelper.NormalizeSHA512(datItem.GetStringFieldValue(Models.Metadata.Rom.SHA512Key)));
ParseAddHelper(item, statsOnly); ParseAddHelper(datItem, statsOnly);
ParseAddHelper(datItem, machineIndex, statsOnly);
} }
} }
@@ -1120,10 +1146,11 @@ namespace SabreTools.DatFiles
/// </summary> /// </summary>
/// <param name="items">Array of internal items to convert</param> /// <param name="items">Array of internal items to convert</param>
/// <param name="machine">Machine to use with the converted items</param> /// <param name="machine">Machine to use with the converted items</param>
/// <param name="machineIndex">Index of the Machine to use with the converted items</param>
/// <param name="filename">Name of the file to be parsed</param> /// <param name="filename">Name of the file to be parsed</param>
/// <param name="indexId">Index ID for the DAT</param> /// <param name="indexId">Index ID for the DAT</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param> /// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
private void ProcessItems(Models.Metadata.Feature[]? items, DatItems.Machine machine, string filename, int indexId, bool statsOnly) private void ProcessItems(Models.Metadata.Feature[]? items, DatItems.Machine machine, long machineIndex, string filename, int indexId, bool statsOnly)
{ {
// If the array is null or empty, return without processing // If the array is null or empty, return without processing
if (items == null || items.Length == 0) if (items == null || items.Length == 0)
@@ -1145,6 +1172,7 @@ namespace SabreTools.DatFiles
datItem.SetFieldValue<string?>(Models.Metadata.Feature.FeatureTypeKey, datItem.GetStringFieldValue(Models.Metadata.Feature.FeatureTypeKey).AsEnumValue<FeatureType>().AsStringValue()); datItem.SetFieldValue<string?>(Models.Metadata.Feature.FeatureTypeKey, datItem.GetStringFieldValue(Models.Metadata.Feature.FeatureTypeKey).AsEnumValue<FeatureType>().AsStringValue());
ParseAddHelper(datItem, statsOnly); ParseAddHelper(datItem, statsOnly);
ParseAddHelper(datItem, machineIndex, statsOnly);
} }
} }
@@ -1153,10 +1181,11 @@ namespace SabreTools.DatFiles
/// </summary> /// </summary>
/// <param name="items">Array of internal items to convert</param> /// <param name="items">Array of internal items to convert</param>
/// <param name="machine">Machine to use with the converted items</param> /// <param name="machine">Machine to use with the converted items</param>
/// <param name="machineIndex">Index of the Machine to use with the converted items</param>
/// <param name="filename">Name of the file to be parsed</param> /// <param name="filename">Name of the file to be parsed</param>
/// <param name="indexId">Index ID for the DAT</param> /// <param name="indexId">Index ID for the DAT</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param> /// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
private void ProcessItems(Models.Metadata.Info[]? items, DatItems.Machine machine, string filename, int indexId, bool statsOnly) private void ProcessItems(Models.Metadata.Info[]? items, DatItems.Machine machine, long machineIndex, string filename, int indexId, bool statsOnly)
{ {
// If the array is null or empty, return without processing // If the array is null or empty, return without processing
if (items == null || items.Length == 0) if (items == null || items.Length == 0)
@@ -1169,6 +1198,7 @@ namespace SabreTools.DatFiles
datItem.SetFieldValue<DatItems.Source?>(DatItems.DatItem.SourceKey, new DatItems.Source { Index = indexId, Name = filename }); datItem.SetFieldValue<DatItems.Source?>(DatItems.DatItem.SourceKey, new DatItems.Source { Index = indexId, Name = filename });
datItem.CopyMachineInformation(machine); datItem.CopyMachineInformation(machine);
ParseAddHelper(datItem, statsOnly); ParseAddHelper(datItem, statsOnly);
ParseAddHelper(datItem, machineIndex, statsOnly);
} }
} }
@@ -1177,10 +1207,11 @@ namespace SabreTools.DatFiles
/// </summary> /// </summary>
/// <param name="items">Array of internal items to convert</param> /// <param name="items">Array of internal items to convert</param>
/// <param name="machine">Machine to use with the converted items</param> /// <param name="machine">Machine to use with the converted items</param>
/// <param name="machineIndex">Index of the Machine to use with the converted items</param>
/// <param name="filename">Name of the file to be parsed</param> /// <param name="filename">Name of the file to be parsed</param>
/// <param name="indexId">Index ID for the DAT</param> /// <param name="indexId">Index ID for the DAT</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param> /// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
private void ProcessItems(Models.Metadata.Input[]? items, DatItems.Machine machine, string filename, int indexId, bool statsOnly) private void ProcessItems(Models.Metadata.Input[]? items, DatItems.Machine machine, long machineIndex, string filename, int indexId, bool statsOnly)
{ {
// If the array is null or empty, return without processing // If the array is null or empty, return without processing
if (items == null || items.Length == 0) if (items == null || items.Length == 0)
@@ -1241,6 +1272,7 @@ namespace SabreTools.DatFiles
} }
ParseAddHelper(datItem, statsOnly); ParseAddHelper(datItem, statsOnly);
ParseAddHelper(datItem, machineIndex, statsOnly);
} }
} }
@@ -1249,10 +1281,11 @@ namespace SabreTools.DatFiles
/// </summary> /// </summary>
/// <param name="items">Array of internal items to convert</param> /// <param name="items">Array of internal items to convert</param>
/// <param name="machine">Machine to use with the converted items</param> /// <param name="machine">Machine to use with the converted items</param>
/// <param name="machineIndex">Index of the Machine to use with the converted items</param>
/// <param name="filename">Name of the file to be parsed</param> /// <param name="filename">Name of the file to be parsed</param>
/// <param name="indexId">Index ID for the DAT</param> /// <param name="indexId">Index ID for the DAT</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param> /// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
private void ProcessItems(Models.Metadata.Media[]? items, DatItems.Machine machine, string filename, int indexId, bool statsOnly) private void ProcessItems(Models.Metadata.Media[]? items, DatItems.Machine machine, long machineIndex, string filename, int indexId, bool statsOnly)
{ {
// If the array is null or empty, return without processing // If the array is null or empty, return without processing
if (items == null || items.Length == 0) if (items == null || items.Length == 0)
@@ -1274,6 +1307,7 @@ namespace SabreTools.DatFiles
datItem.SetFieldValue<string?>(Models.Metadata.Media.SHA256Key, TextHelper.NormalizeSHA256(datItem.GetStringFieldValue(Models.Metadata.Media.SHA256Key))); datItem.SetFieldValue<string?>(Models.Metadata.Media.SHA256Key, TextHelper.NormalizeSHA256(datItem.GetStringFieldValue(Models.Metadata.Media.SHA256Key)));
ParseAddHelper(datItem, statsOnly); ParseAddHelper(datItem, statsOnly);
ParseAddHelper(datItem, machineIndex, statsOnly);
} }
} }
@@ -1282,10 +1316,11 @@ namespace SabreTools.DatFiles
/// </summary> /// </summary>
/// <param name="items">Array of internal items to convert</param> /// <param name="items">Array of internal items to convert</param>
/// <param name="machine">Machine to use with the converted items</param> /// <param name="machine">Machine to use with the converted items</param>
/// <param name="machineIndex">Index of the Machine to use with the converted items</param>
/// <param name="filename">Name of the file to be parsed</param> /// <param name="filename">Name of the file to be parsed</param>
/// <param name="indexId">Index ID for the DAT</param> /// <param name="indexId">Index ID for the DAT</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param> /// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
private void ProcessItems(Models.Metadata.Part[]? items, DatItems.Machine machine, string filename, int indexId, bool statsOnly) private void ProcessItems(Models.Metadata.Part[]? items, DatItems.Machine machine, long machineIndex, string filename, int indexId, bool statsOnly)
{ {
// If the array is null or empty, return without processing // If the array is null or empty, return without processing
if (items == null || items.Length == 0) if (items == null || items.Length == 0)
@@ -1358,6 +1393,7 @@ namespace SabreTools.DatFiles
romItem.SetFieldValue<string?>(Models.Metadata.Rom.SHA512Key, TextHelper.NormalizeSHA512(romItem.GetStringFieldValue(Models.Metadata.Rom.SHA512Key))); romItem.SetFieldValue<string?>(Models.Metadata.Rom.SHA512Key, TextHelper.NormalizeSHA512(romItem.GetStringFieldValue(Models.Metadata.Rom.SHA512Key)));
ParseAddHelper(romItem, statsOnly); ParseAddHelper(romItem, statsOnly);
ParseAddHelper(romItem, machineIndex, statsOnly);
} }
} }
} }
@@ -1395,6 +1431,7 @@ namespace SabreTools.DatFiles
diskItem.SetFieldValue<string?>(Models.Metadata.Disk.SHA1Key, TextHelper.NormalizeSHA1(diskItem.GetStringFieldValue(Models.Metadata.Disk.SHA1Key))); diskItem.SetFieldValue<string?>(Models.Metadata.Disk.SHA1Key, TextHelper.NormalizeSHA1(diskItem.GetStringFieldValue(Models.Metadata.Disk.SHA1Key)));
ParseAddHelper(diskItem, statsOnly); ParseAddHelper(diskItem, statsOnly);
ParseAddHelper(diskItem, machineIndex, statsOnly);
} }
} }
} }
@@ -1475,6 +1512,7 @@ namespace SabreTools.DatFiles
} }
ParseAddHelper(dipSwitchItem, statsOnly); ParseAddHelper(dipSwitchItem, statsOnly);
ParseAddHelper(dipSwitchItem, machineIndex, statsOnly);
} }
} }
@@ -1497,6 +1535,7 @@ namespace SabreTools.DatFiles
partFeatureItem.SetFieldValue<string?>(Models.Metadata.Feature.FeatureTypeKey, partFeatureItem.GetStringFieldValue(Models.Metadata.Feature.FeatureTypeKey).AsEnumValue<FeatureType>().AsStringValue()); partFeatureItem.SetFieldValue<string?>(Models.Metadata.Feature.FeatureTypeKey, partFeatureItem.GetStringFieldValue(Models.Metadata.Feature.FeatureTypeKey).AsEnumValue<FeatureType>().AsStringValue());
ParseAddHelper(partFeatureItem, statsOnly); ParseAddHelper(partFeatureItem, statsOnly);
ParseAddHelper(partFeatureItem, machineIndex, statsOnly);
} }
} }
} }
@@ -1507,10 +1546,11 @@ namespace SabreTools.DatFiles
/// </summary> /// </summary>
/// <param name="items">Array of internal items to convert</param> /// <param name="items">Array of internal items to convert</param>
/// <param name="machine">Machine to use with the converted items</param> /// <param name="machine">Machine to use with the converted items</param>
/// <param name="machineIndex">Index of the Machine to use with the converted items</param>
/// <param name="filename">Name of the file to be parsed</param> /// <param name="filename">Name of the file to be parsed</param>
/// <param name="indexId">Index ID for the DAT</param> /// <param name="indexId">Index ID for the DAT</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param> /// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
private void ProcessItems(Models.Metadata.Port[]? items, DatItems.Machine machine, string filename, int indexId, bool statsOnly) private void ProcessItems(Models.Metadata.Port[]? items, DatItems.Machine machine, long machineIndex, string filename, int indexId, bool statsOnly)
{ {
// If the array is null or empty, return without processing // If the array is null or empty, return without processing
if (items == null || items.Length == 0) if (items == null || items.Length == 0)
@@ -1538,6 +1578,7 @@ namespace SabreTools.DatFiles
} }
ParseAddHelper(datItem, statsOnly); ParseAddHelper(datItem, statsOnly);
ParseAddHelper(datItem, machineIndex, statsOnly);
} }
} }
@@ -1546,10 +1587,11 @@ namespace SabreTools.DatFiles
/// </summary> /// </summary>
/// <param name="items">Array of internal items to convert</param> /// <param name="items">Array of internal items to convert</param>
/// <param name="machine">Machine to use with the converted items</param> /// <param name="machine">Machine to use with the converted items</param>
/// <param name="machineIndex">Index of the Machine to use with the converted items</param>
/// <param name="filename">Name of the file to be parsed</param> /// <param name="filename">Name of the file to be parsed</param>
/// <param name="indexId">Index ID for the DAT</param> /// <param name="indexId">Index ID for the DAT</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param> /// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
private void ProcessItems(Models.Metadata.RamOption[]? items, DatItems.Machine machine, string filename, int indexId, bool statsOnly) private void ProcessItems(Models.Metadata.RamOption[]? items, DatItems.Machine machine, long machineIndex, string filename, int indexId, bool statsOnly)
{ {
// If the array is null or empty, return without processing // If the array is null or empty, return without processing
if (items == null || items.Length == 0) if (items == null || items.Length == 0)
@@ -1567,6 +1609,7 @@ namespace SabreTools.DatFiles
datItem.SetFieldValue<string?>(Models.Metadata.RamOption.DefaultKey, datItem.GetBoolFieldValue(Models.Metadata.RamOption.DefaultKey).FromYesNo()); datItem.SetFieldValue<string?>(Models.Metadata.RamOption.DefaultKey, datItem.GetBoolFieldValue(Models.Metadata.RamOption.DefaultKey).FromYesNo());
ParseAddHelper(datItem, statsOnly); ParseAddHelper(datItem, statsOnly);
ParseAddHelper(datItem, machineIndex, statsOnly);
} }
} }
@@ -1575,10 +1618,11 @@ namespace SabreTools.DatFiles
/// </summary> /// </summary>
/// <param name="items">Array of internal items to convert</param> /// <param name="items">Array of internal items to convert</param>
/// <param name="machine">Machine to use with the converted items</param> /// <param name="machine">Machine to use with the converted items</param>
/// <param name="machineIndex">Index of the Machine to use with the converted items</param>
/// <param name="filename">Name of the file to be parsed</param> /// <param name="filename">Name of the file to be parsed</param>
/// <param name="indexId">Index ID for the DAT</param> /// <param name="indexId">Index ID for the DAT</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param> /// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
private void ProcessItems(Models.Metadata.Release[]? items, DatItems.Machine machine, string filename, int indexId, bool statsOnly) private void ProcessItems(Models.Metadata.Release[]? items, DatItems.Machine machine, long machineIndex, string filename, int indexId, bool statsOnly)
{ {
// If the array is null or empty, return without processing // If the array is null or empty, return without processing
if (items == null || items.Length == 0) if (items == null || items.Length == 0)
@@ -1596,6 +1640,7 @@ namespace SabreTools.DatFiles
datItem.SetFieldValue<string?>(Models.Metadata.Release.DefaultKey, datItem.GetBoolFieldValue(Models.Metadata.Release.DefaultKey).FromYesNo()); datItem.SetFieldValue<string?>(Models.Metadata.Release.DefaultKey, datItem.GetBoolFieldValue(Models.Metadata.Release.DefaultKey).FromYesNo());
ParseAddHelper(datItem, statsOnly); ParseAddHelper(datItem, statsOnly);
ParseAddHelper(datItem, machineIndex, statsOnly);
} }
} }
@@ -1604,10 +1649,11 @@ namespace SabreTools.DatFiles
/// </summary> /// </summary>
/// <param name="items">Array of internal items to convert</param> /// <param name="items">Array of internal items to convert</param>
/// <param name="machine">Machine to use with the converted items</param> /// <param name="machine">Machine to use with the converted items</param>
/// <param name="machineIndex">Index of the Machine to use with the converted items</param>
/// <param name="filename">Name of the file to be parsed</param> /// <param name="filename">Name of the file to be parsed</param>
/// <param name="indexId">Index ID for the DAT</param> /// <param name="indexId">Index ID for the DAT</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param> /// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
private void ProcessItems(Models.Metadata.Rom[]? items, DatItems.Machine machine, string filename, int indexId, bool statsOnly) private void ProcessItems(Models.Metadata.Rom[]? items, DatItems.Machine machine, long machineIndex, string filename, int indexId, bool statsOnly)
{ {
// If the array is null or empty, return without processing // If the array is null or empty, return without processing
if (items == null || items.Length == 0) if (items == null || items.Length == 0)
@@ -1655,6 +1701,7 @@ namespace SabreTools.DatFiles
datItem.SetFieldValue<string?>(Models.Metadata.Rom.SHA512Key, TextHelper.NormalizeSHA512(datItem.GetStringFieldValue(Models.Metadata.Rom.SHA512Key))); datItem.SetFieldValue<string?>(Models.Metadata.Rom.SHA512Key, TextHelper.NormalizeSHA512(datItem.GetStringFieldValue(Models.Metadata.Rom.SHA512Key)));
ParseAddHelper(datItem, statsOnly); ParseAddHelper(datItem, statsOnly);
ParseAddHelper(datItem, machineIndex, statsOnly);
} }
} }
@@ -1663,10 +1710,11 @@ namespace SabreTools.DatFiles
/// </summary> /// </summary>
/// <param name="items">Array of internal items to convert</param> /// <param name="items">Array of internal items to convert</param>
/// <param name="machine">Machine to use with the converted items</param> /// <param name="machine">Machine to use with the converted items</param>
/// <param name="machineIndex">Index of the Machine to use with the converted items</param>
/// <param name="filename">Name of the file to be parsed</param> /// <param name="filename">Name of the file to be parsed</param>
/// <param name="indexId">Index ID for the DAT</param> /// <param name="indexId">Index ID for the DAT</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param> /// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
private void ProcessItems(Models.Metadata.Sample[]? items, DatItems.Machine machine, string filename, int indexId, bool statsOnly) private void ProcessItems(Models.Metadata.Sample[]? items, DatItems.Machine machine, long machineIndex, string filename, int indexId, bool statsOnly)
{ {
// If the array is null or empty, return without processing // If the array is null or empty, return without processing
if (items == null || items.Length == 0) if (items == null || items.Length == 0)
@@ -1679,6 +1727,7 @@ namespace SabreTools.DatFiles
datItem.SetFieldValue<DatItems.Source?>(DatItems.DatItem.SourceKey, new DatItems.Source { Index = indexId, Name = filename }); datItem.SetFieldValue<DatItems.Source?>(DatItems.DatItem.SourceKey, new DatItems.Source { Index = indexId, Name = filename });
datItem.CopyMachineInformation(machine); datItem.CopyMachineInformation(machine);
ParseAddHelper(datItem, statsOnly); ParseAddHelper(datItem, statsOnly);
ParseAddHelper(datItem, machineIndex, statsOnly);
} }
} }
@@ -1687,10 +1736,11 @@ namespace SabreTools.DatFiles
/// </summary> /// </summary>
/// <param name="items">Array of internal items to convert</param> /// <param name="items">Array of internal items to convert</param>
/// <param name="machine">Machine to use with the converted items</param> /// <param name="machine">Machine to use with the converted items</param>
/// <param name="machineIndex">Index of the Machine to use with the converted items</param>
/// <param name="filename">Name of the file to be parsed</param> /// <param name="filename">Name of the file to be parsed</param>
/// <param name="indexId">Index ID for the DAT</param> /// <param name="indexId">Index ID for the DAT</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param> /// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
private void ProcessItems(Models.Metadata.SharedFeat[]? items, DatItems.Machine machine, string filename, int indexId, bool statsOnly) private void ProcessItems(Models.Metadata.SharedFeat[]? items, DatItems.Machine machine, long machineIndex, string filename, int indexId, bool statsOnly)
{ {
// If the array is null or empty, return without processing // If the array is null or empty, return without processing
if (items == null || items.Length == 0) if (items == null || items.Length == 0)
@@ -1703,6 +1753,7 @@ namespace SabreTools.DatFiles
datItem.SetFieldValue<DatItems.Source?>(DatItems.DatItem.SourceKey, new DatItems.Source { Index = indexId, Name = filename }); datItem.SetFieldValue<DatItems.Source?>(DatItems.DatItem.SourceKey, new DatItems.Source { Index = indexId, Name = filename });
datItem.CopyMachineInformation(machine); datItem.CopyMachineInformation(machine);
ParseAddHelper(datItem, statsOnly); ParseAddHelper(datItem, statsOnly);
ParseAddHelper(datItem, machineIndex, statsOnly);
} }
} }
@@ -1711,10 +1762,11 @@ namespace SabreTools.DatFiles
/// </summary> /// </summary>
/// <param name="items">Array of internal items to convert</param> /// <param name="items">Array of internal items to convert</param>
/// <param name="machine">Machine to use with the converted items</param> /// <param name="machine">Machine to use with the converted items</param>
/// <param name="machineIndex">Index of the Machine to use with the converted items</param>
/// <param name="filename">Name of the file to be parsed</param> /// <param name="filename">Name of the file to be parsed</param>
/// <param name="indexId">Index ID for the DAT</param> /// <param name="indexId">Index ID for the DAT</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param> /// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
private void ProcessItems(Models.Metadata.Slot[]? items, DatItems.Machine machine, string filename, int indexId, bool statsOnly) private void ProcessItems(Models.Metadata.Slot[]? items, DatItems.Machine machine, long machineIndex, string filename, int indexId, bool statsOnly)
{ {
// If the array is null or empty, return without processing // If the array is null or empty, return without processing
if (items == null || items.Length == 0) if (items == null || items.Length == 0)
@@ -1747,6 +1799,7 @@ namespace SabreTools.DatFiles
} }
ParseAddHelper(datItem, statsOnly); ParseAddHelper(datItem, statsOnly);
ParseAddHelper(datItem, machineIndex, statsOnly);
} }
} }
@@ -1755,10 +1808,11 @@ namespace SabreTools.DatFiles
/// </summary> /// </summary>
/// <param name="items">Array of internal items to convert</param> /// <param name="items">Array of internal items to convert</param>
/// <param name="machine">Machine to use with the converted items</param> /// <param name="machine">Machine to use with the converted items</param>
/// <param name="machineIndex">Index of the Machine to use with the converted items</param>
/// <param name="filename">Name of the file to be parsed</param> /// <param name="filename">Name of the file to be parsed</param>
/// <param name="indexId">Index ID for the DAT</param> /// <param name="indexId">Index ID for the DAT</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param> /// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
private void ProcessItems(Models.Metadata.SoftwareList[]? items, DatItems.Machine machine, string filename, int indexId, bool statsOnly) private void ProcessItems(Models.Metadata.SoftwareList[]? items, DatItems.Machine machine, long machineIndex, string filename, int indexId, bool statsOnly)
{ {
// If the array is null or empty, return without processing // If the array is null or empty, return without processing
if (items == null || items.Length == 0) if (items == null || items.Length == 0)
@@ -1776,6 +1830,7 @@ namespace SabreTools.DatFiles
datItem.SetFieldValue<string?>(Models.Metadata.SoftwareList.StatusKey, datItem.GetStringFieldValue(Models.Metadata.SoftwareList.StatusKey).AsEnumValue<SoftwareListStatus>().AsStringValue()); datItem.SetFieldValue<string?>(Models.Metadata.SoftwareList.StatusKey, datItem.GetStringFieldValue(Models.Metadata.SoftwareList.StatusKey).AsEnumValue<SoftwareListStatus>().AsStringValue());
ParseAddHelper(datItem, statsOnly); ParseAddHelper(datItem, statsOnly);
ParseAddHelper(datItem, machineIndex, statsOnly);
} }
} }
@@ -1784,10 +1839,11 @@ namespace SabreTools.DatFiles
/// </summary> /// </summary>
/// <param name="items">Array of internal items to convert</param> /// <param name="items">Array of internal items to convert</param>
/// <param name="machine">Machine to use with the converted items</param> /// <param name="machine">Machine to use with the converted items</param>
/// <param name="machineIndex">Index of the Machine to use with the converted items</param>
/// <param name="filename">Name of the file to be parsed</param> /// <param name="filename">Name of the file to be parsed</param>
/// <param name="indexId">Index ID for the DAT</param> /// <param name="indexId">Index ID for the DAT</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param> /// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
private void ProcessItems(Models.Metadata.Sound[]? items, DatItems.Machine machine, string filename, int indexId, bool statsOnly) private void ProcessItems(Models.Metadata.Sound[]? items, DatItems.Machine machine, long machineIndex, string filename, int indexId, bool statsOnly)
{ {
// If the array is null or empty, return without processing // If the array is null or empty, return without processing
if (items == null || items.Length == 0) if (items == null || items.Length == 0)
@@ -1805,6 +1861,7 @@ namespace SabreTools.DatFiles
datItem.SetFieldValue<string?>(Models.Metadata.Sound.ChannelsKey, datItem.GetInt64FieldValue(Models.Metadata.Sound.ChannelsKey).ToString()); datItem.SetFieldValue<string?>(Models.Metadata.Sound.ChannelsKey, datItem.GetInt64FieldValue(Models.Metadata.Sound.ChannelsKey).ToString());
ParseAddHelper(datItem, statsOnly); ParseAddHelper(datItem, statsOnly);
ParseAddHelper(datItem, machineIndex, statsOnly);
} }
} }
@@ -1813,10 +1870,11 @@ namespace SabreTools.DatFiles
/// </summary> /// </summary>
/// <param name="items">Array of internal items to convert</param> /// <param name="items">Array of internal items to convert</param>
/// <param name="machine">Machine to use with the converted items</param> /// <param name="machine">Machine to use with the converted items</param>
/// <param name="machineIndex">Index of the Machine to use with the converted items</param>
/// <param name="filename">Name of the file to be parsed</param> /// <param name="filename">Name of the file to be parsed</param>
/// <param name="indexId">Index ID for the DAT</param> /// <param name="indexId">Index ID for the DAT</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param> /// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
private void ProcessItems(Models.Metadata.Video[]? items, DatItems.Machine machine, string filename, int indexId, bool statsOnly) private void ProcessItems(Models.Metadata.Video[]? items, DatItems.Machine machine, long machineIndex, string filename, int indexId, bool statsOnly)
{ {
// If the array is null or empty, return without processing // If the array is null or empty, return without processing
if (items == null || items.Length == 0) if (items == null || items.Length == 0)
@@ -1844,6 +1902,7 @@ namespace SabreTools.DatFiles
datItem.SetFieldValue<string?>(Models.Metadata.Display.WidthKey, datItem.GetInt64FieldValue(Models.Metadata.Video.WidthKey).ToString()); datItem.SetFieldValue<string?>(Models.Metadata.Display.WidthKey, datItem.GetInt64FieldValue(Models.Metadata.Video.WidthKey).ToString());
ParseAddHelper(datItem, statsOnly); ParseAddHelper(datItem, statsOnly);
ParseAddHelper(datItem, machineIndex, statsOnly);
} }
} }

View File

@@ -67,6 +67,7 @@ namespace SabreTools.DatFiles
{ {
Header = datFile.Header; Header = datFile.Header;
Items = datFile.Items; Items = datFile.Items;
ItemsDB = datFile.ItemsDB;
} }
} }
@@ -161,7 +162,10 @@ namespace SabreTools.DatFiles
/// </summary> /// </summary>
/// <param name="filterRunner">Preconfigured filter runner to use</param> /// <param name="filterRunner">Preconfigured filter runner to use</param>
public void ExecuteFilters(FilterRunner filterRunner) public void ExecuteFilters(FilterRunner filterRunner)
=> Items.ExecuteFilters(filterRunner); {
Items.ExecuteFilters(filterRunner);
ItemsDB.ExecuteFilters(filterRunner);
}
#endregion #endregion

View File

@@ -141,9 +141,14 @@ namespace SabreTools.DatFiles.Formats
if (machineObj.ContainsKey("machine")) if (machineObj.ContainsKey("machine"))
machine = machineObj["machine"]?.ToObject<Machine>(); machine = machineObj["machine"]?.ToObject<Machine>();
// Add the machine to the dictionary
long machineIndex = -1;
if (machine != null)
machineIndex = ItemsDB.AddMachine(machine);
// Read items, if possible // Read items, if possible
if (machineObj.ContainsKey("items")) if (machineObj.ContainsKey("items"))
ReadItems(machineObj["items"] as JArray, statsOnly, filename, indexId, machine); ReadItems(machineObj["items"] as JArray, statsOnly, filename, indexId, machine, machineIndex);
} }
/// <summary> /// <summary>
@@ -154,6 +159,7 @@ namespace SabreTools.DatFiles.Formats
/// <param name="filename">Name of the file to be parsed</param> /// <param name="filename">Name of the file to be parsed</param>
/// <param name="indexId">Index ID for the DAT</param> /// <param name="indexId">Index ID for the DAT</param>
/// <param name="machine">Machine information to add to the parsed items</param> /// <param name="machine">Machine information to add to the parsed items</param>
/// <param name="machineIndex">Index of the Machine to add to the parsed items</param>
private void ReadItems( private void ReadItems(
JArray? itemsArr, JArray? itemsArr,
bool statsOnly, bool statsOnly,
@@ -163,7 +169,8 @@ namespace SabreTools.DatFiles.Formats
int indexId, int indexId,
// Miscellaneous // Miscellaneous
Machine? machine) Machine? machine,
long machineIndex)
{ {
// If the array is invalid, skip // If the array is invalid, skip
if (itemsArr == null) if (itemsArr == null)
@@ -172,18 +179,19 @@ namespace SabreTools.DatFiles.Formats
// Loop through each datitem object and process // Loop through each datitem object and process
foreach (JObject itemObj in itemsArr.Cast<JObject>()) foreach (JObject itemObj in itemsArr.Cast<JObject>())
{ {
ReadItem(itemObj, statsOnly, filename, indexId, machine); ReadItem(itemObj, statsOnly, filename, indexId, machine, machineIndex);
} }
} }
/// <summary> /// <summary>
/// Read item information /// Read item information
/// </summary> /// </summary>
/// <param name="machineObj">JObject representing a single datitem</param> /// <param name="itemObj">JObject representing a single datitem</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param> /// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
/// <param name="filename">Name of the file to be parsed</param> /// <param name="filename">Name of the file to be parsed</param>
/// <param name="indexId">Index ID for the DAT</param> /// <param name="indexId">Index ID for the DAT</param>
/// <param name="machine">Machine information to add to the parsed items</param> /// <param name="machine">Machine information to add to the parsed items</param>
/// <param name="machineIndex">Index of the Machine to add to the parsed items</param>
private void ReadItem( private void ReadItem(
JObject itemObj, JObject itemObj,
bool statsOnly, bool statsOnly,
@@ -193,7 +201,8 @@ namespace SabreTools.DatFiles.Formats
int indexId, int indexId,
// Miscellaneous // Miscellaneous
Machine? machine) Machine? machine,
long machineIndex)
{ {
// If we have an empty item, skip it // If we have an empty item, skip it
if (itemObj == null) if (itemObj == null)
@@ -346,6 +355,7 @@ namespace SabreTools.DatFiles.Formats
datItem.CopyMachineInformation(machine); datItem.CopyMachineInformation(machine);
datItem.SetFieldValue<Source?>(DatItem.SourceKey, new Source { Index = indexId, Name = filename }); datItem.SetFieldValue<Source?>(DatItem.SourceKey, new Source { Index = indexId, Name = filename });
ParseAddHelper(datItem, statsOnly); ParseAddHelper(datItem, statsOnly);
ParseAddHelper(datItem, machineIndex, statsOnly);
} }
} }

View File

@@ -105,6 +105,7 @@ namespace SabreTools.DatFiles.Formats
// Prepare internal variables // Prepare internal variables
Machine? machine = null; Machine? machine = null;
long machineIndex = -1;
// Otherwise, read the directory // Otherwise, read the directory
xtr.MoveToContent(); xtr.MoveToContent();
@@ -122,11 +123,14 @@ namespace SabreTools.DatFiles.Formats
case "machine": case "machine":
XmlSerializer xs = new(typeof(Machine)); XmlSerializer xs = new(typeof(Machine));
machine = xs?.Deserialize(xtr.ReadSubtree()) as Machine; machine = xs?.Deserialize(xtr.ReadSubtree()) as Machine;
if (machine != null)
machineIndex = ItemsDB.AddMachine(machine);
xtr.Skip(); xtr.Skip();
break; break;
case "files": case "files":
ReadFiles(xtr.ReadSubtree(), machine, statsOnly, filename, indexId); ReadFiles(xtr.ReadSubtree(), machine, machineIndex, statsOnly, filename, indexId);
// Skip the directory node now that we've processed it // Skip the directory node now that we've processed it
xtr.Read(); xtr.Read();
@@ -143,10 +147,11 @@ namespace SabreTools.DatFiles.Formats
/// </summary> /// </summary>
/// <param name="xtr">XmlReader to use to parse the header</param> /// <param name="xtr">XmlReader to use to parse the header</param>
/// <param name="machine">Machine to copy information from</param> /// <param name="machine">Machine to copy information from</param>
/// <param name="machineIndex">Index of the Machine to add to the parsed items</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param> /// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
/// <param name="filename">Name of the file to be parsed</param> /// <param name="filename">Name of the file to be parsed</param>
/// <param name="indexId">Index ID for the DAT</param> /// <param name="indexId">Index ID for the DAT</param>
private void ReadFiles(XmlReader xtr, Machine? machine, bool statsOnly, string filename, int indexId) private void ReadFiles(XmlReader xtr, Machine? machine, long machineIndex, bool statsOnly, string filename, int indexId)
{ {
// If the reader is invalid, skip // If the reader is invalid, skip
if (xtr == null) if (xtr == null)
@@ -172,6 +177,7 @@ namespace SabreTools.DatFiles.Formats
item.CopyMachineInformation(machine); item.CopyMachineInformation(machine);
item.SetFieldValue<Source?>(DatItem.SourceKey, new Source { Index = indexId, Name = filename }); item.SetFieldValue<Source?>(DatItem.SourceKey, new Source { Index = indexId, Name = filename });
ParseAddHelper(item, statsOnly); ParseAddHelper(item, statsOnly);
ParseAddHelper(item, machineIndex, statsOnly);
} }
xtr.Skip(); xtr.Skip();
break; break;

View File

@@ -105,6 +105,21 @@ namespace SabreTools.DatFiles
#region Fields #region Fields
/// <summary>
/// Get the keys in sorted order from the file dictionary
/// </summary>
/// <returns>List of the keys in sorted order</returns>
[JsonIgnore, XmlIgnore]
public string[] SortedKeys
{
get
{
List<string> keys = [.. _buckets.Keys];
keys.Sort(new NaturalComparer());
return keys.ToArray();
}
}
/// <summary> /// <summary>
/// DAT statistics /// DAT statistics
/// </summary> /// </summary>
@@ -232,16 +247,6 @@ namespace SabreTools.DatFiles
} }
} }
/// <summary>
/// Get all bucket keys
/// </summary>
public string[] GetBucketKeys()
{
List<string> keys = [.. _buckets.Keys];
keys.Sort(new NaturalComparer());
return keys.ToArray();
}
/// <summary> /// <summary>
/// Get an item based on the index /// Get an item based on the index
/// </summary> /// </summary>
@@ -849,7 +854,7 @@ namespace SabreTools.DatFiles
/// <param name="filterRunner">Preconfigured filter runner to use</param> /// <param name="filterRunner">Preconfigured filter runner to use</param>
public void ExecuteFilters(FilterRunner filterRunner) public void ExecuteFilters(FilterRunner filterRunner)
{ {
List<string> keys = [.. GetBucketKeys()]; List<string> keys = [.. SortedKeys];
#if NET452_OR_GREATER || NETCOREAPP #if NET452_OR_GREATER || NETCOREAPP
Parallel.ForEach(keys, Globals.ParallelOptions, key => Parallel.ForEach(keys, Globals.ParallelOptions, key =>
#elif NET40_OR_GREATER #elif NET40_OR_GREATER

View File

@@ -343,6 +343,7 @@ namespace SabreTools.DatTools
{ {
DatFile diffData = DatFile.Create(datHeaders[j]); DatFile diffData = DatFile.Create(datHeaders[j]);
diffData.Items = []; diffData.Items = [];
diffData.ItemsDB = new ItemDictionaryDB();
FillWithSourceIndex(datFile, diffData, j); FillWithSourceIndex(datFile, diffData, j);
outDatsArray[j] = diffData; outDatsArray[j] = diffData;
#if NET40_OR_GREATER || NETCOREAPP #if NET40_OR_GREATER || NETCOREAPP
@@ -393,6 +394,7 @@ namespace SabreTools.DatTools
dupeData.Header.SetFieldValue<string?>(Models.Metadata.Header.NameKey, dupeData.Header.GetStringFieldValue(Models.Metadata.Header.NameKey) + post); dupeData.Header.SetFieldValue<string?>(Models.Metadata.Header.NameKey, dupeData.Header.GetStringFieldValue(Models.Metadata.Header.NameKey) + post);
dupeData.Header.SetFieldValue<string?>(Models.Metadata.Header.DescriptionKey, dupeData.Header.GetStringFieldValue(Models.Metadata.Header.DescriptionKey) + post); dupeData.Header.SetFieldValue<string?>(Models.Metadata.Header.DescriptionKey, dupeData.Header.GetStringFieldValue(Models.Metadata.Header.DescriptionKey) + post);
dupeData.Items = []; dupeData.Items = [];
dupeData.ItemsDB = new ItemDictionaryDB();
watch.Stop(); watch.Stop();
@@ -493,6 +495,7 @@ namespace SabreTools.DatTools
diffData.Header.SetFieldValue<string?>(Models.Metadata.Header.NameKey, diffData.Header.GetStringFieldValue(Models.Metadata.Header.NameKey) + innerpost); diffData.Header.SetFieldValue<string?>(Models.Metadata.Header.NameKey, diffData.Header.GetStringFieldValue(Models.Metadata.Header.NameKey) + innerpost);
diffData.Header.SetFieldValue<string?>(Models.Metadata.Header.DescriptionKey, diffData.Header.GetStringFieldValue(Models.Metadata.Header.DescriptionKey) + innerpost); diffData.Header.SetFieldValue<string?>(Models.Metadata.Header.DescriptionKey, diffData.Header.GetStringFieldValue(Models.Metadata.Header.DescriptionKey) + innerpost);
diffData.Items = []; diffData.Items = [];
diffData.ItemsDB = new ItemDictionaryDB();
outDatsArray[j] = diffData; outDatsArray[j] = diffData;
#if NET40_OR_GREATER || NETCOREAPP #if NET40_OR_GREATER || NETCOREAPP
}); });
@@ -586,6 +589,7 @@ namespace SabreTools.DatTools
outerDiffData.Header.SetFieldValue<string?>(Models.Metadata.Header.NameKey, outerDiffData.Header.GetStringFieldValue(Models.Metadata.Header.NameKey) + post); outerDiffData.Header.SetFieldValue<string?>(Models.Metadata.Header.NameKey, outerDiffData.Header.GetStringFieldValue(Models.Metadata.Header.NameKey) + post);
outerDiffData.Header.SetFieldValue<string?>(Models.Metadata.Header.DescriptionKey, outerDiffData.Header.GetStringFieldValue(Models.Metadata.Header.DescriptionKey) + post); outerDiffData.Header.SetFieldValue<string?>(Models.Metadata.Header.DescriptionKey, outerDiffData.Header.GetStringFieldValue(Models.Metadata.Header.DescriptionKey) + post);
outerDiffData.Items = []; outerDiffData.Items = [];
outerDiffData.ItemsDB = new ItemDictionaryDB();
watch.Stop(); watch.Stop();
@@ -714,7 +718,10 @@ namespace SabreTools.DatTools
// Now remove the file dictionary from the source DAT // Now remove the file dictionary from the source DAT
if (delete) if (delete)
{
addFrom.Items = []; addFrom.Items = [];
addFrom.ItemsDB = new ItemDictionaryDB();
}
} }
/// <summary> /// <summary>