using System.Collections.Generic; using System.Linq; using SabreTools.Core; using SabreTools.Core.Tools; namespace SabreTools.DatFiles { public partial class DatFile { #region From Metadata /// /// Convert metadata information /// /// Metadata file to convert /// Name of the file to be parsed /// Index ID for the DAT /// True if full pathnames are to be kept, false otherwise /// True to only add item statistics while parsing, false otherwise public void ConvertMetadata(Models.Metadata.MetadataFile? item, string filename, int indexId, bool keep, bool statsOnly) { // If the metadata file is invalid, we can't do anything if (item == null || !item.Any()) return; // Get the header from the metadata var header = item.Read(Models.Metadata.MetadataFile.HeaderKey); if (header != null) ConvertHeader(header, keep); // Get the machines from the metadata var machines = ReadItemArray(item, Models.Metadata.MetadataFile.MachineKey); if (machines != null) ConvertMachines(machines, filename, indexId, statsOnly); } /// /// Convert header information /// /// Header to convert /// True if full pathnames are to be kept, false otherwise private void ConvertHeader(Models.Metadata.Header? item, bool keep) { // If the header is invalid, we can't do anything if (item == null || !item.Any()) return; // Create an internal header var header = new DatFiles.DatHeader(item); // Convert subheader values if (item.ContainsKey(Models.Metadata.Header.CanOpenKey)) { var canOpen = item.Read(Models.Metadata.Header.CanOpenKey); if (canOpen?.Extension != null) Header.SetFieldValue(Models.Metadata.Header.CanOpenKey, canOpen.Extension); } if (item.ContainsKey(Models.Metadata.Header.ImagesKey)) { // TODO: Add to internal model } if (item.ContainsKey(Models.Metadata.Header.InfosKey)) { var infos = item.Read(Models.Metadata.Header.InfosKey); if (infos != null) { var offlineListInfos = new List(); if (infos.Title != null) { offlineListInfos.Add(new Formats.OfflineListInfo { Name = "title", Visible = infos.Title.Visible.AsYesNo(), InNamingOption = infos.Title.InNamingOption.AsYesNo(), Default = infos.Title.Default.AsYesNo(), }); } if (infos.Location != null) { offlineListInfos.Add(new Formats.OfflineListInfo { Name = "location", Visible = infos.Location.Visible.AsYesNo(), InNamingOption = infos.Location.InNamingOption.AsYesNo(), Default = infos.Location.Default.AsYesNo(), }); } if (infos.Publisher != null) { offlineListInfos.Add(new Formats.OfflineListInfo { Name = "publisher", Visible = infos.Publisher.Visible.AsYesNo(), InNamingOption = infos.Publisher.InNamingOption.AsYesNo(), Default = infos.Publisher.Default.AsYesNo(), }); } if (infos.SourceRom != null) { offlineListInfos.Add(new Formats.OfflineListInfo { Name = "sourceRom", Visible = infos.SourceRom.Visible.AsYesNo(), InNamingOption = infos.SourceRom.InNamingOption.AsYesNo(), Default = infos.SourceRom.Default.AsYesNo(), }); } if (infos.SaveType != null) { offlineListInfos.Add(new Formats.OfflineListInfo { Name = "saveType", Visible = infos.SaveType.Visible.AsYesNo(), InNamingOption = infos.SaveType.InNamingOption.AsYesNo(), Default = infos.SaveType.Default.AsYesNo(), }); } if (infos.RomSize != null) { offlineListInfos.Add(new Formats.OfflineListInfo { Name = "romSize", Visible = infos.RomSize.Visible.AsYesNo(), InNamingOption = infos.RomSize.InNamingOption.AsYesNo(), Default = infos.RomSize.Default.AsYesNo(), }); } if (infos.ReleaseNumber != null) { offlineListInfos.Add(new Formats.OfflineListInfo { Name = "releaseNumber", Visible = infos.ReleaseNumber.Visible.AsYesNo(), InNamingOption = infos.ReleaseNumber.InNamingOption.AsYesNo(), Default = infos.ReleaseNumber.Default.AsYesNo(), }); } if (infos.LanguageNumber != null) { offlineListInfos.Add(new Formats.OfflineListInfo { Name = "languageNumber", Visible = infos.LanguageNumber.Visible.AsYesNo(), InNamingOption = infos.LanguageNumber.InNamingOption.AsYesNo(), Default = infos.LanguageNumber.Default.AsYesNo(), }); } if (infos.Comment != null) { offlineListInfos.Add(new Formats.OfflineListInfo { Name = "comment", Visible = infos.Comment.Visible.AsYesNo(), InNamingOption = infos.Comment.InNamingOption.AsYesNo(), Default = infos.Comment.Default.AsYesNo(), }); } if (infos.RomCRC != null) { offlineListInfos.Add(new Formats.OfflineListInfo { Name = "romCRC", Visible = infos.RomCRC.Visible.AsYesNo(), InNamingOption = infos.RomCRC.InNamingOption.AsYesNo(), Default = infos.RomCRC.Default.AsYesNo(), }); } if (infos.Im1CRC != null) { offlineListInfos.Add(new Formats.OfflineListInfo { Name = "im1CRC", Visible = infos.Im1CRC.Visible.AsYesNo(), InNamingOption = infos.Im1CRC.InNamingOption.AsYesNo(), Default = infos.Im1CRC.Default.AsYesNo(), }); } if (infos.Im2CRC != null) { offlineListInfos.Add(new Formats.OfflineListInfo { Name = "im2CRC", Visible = infos.Im2CRC.Visible.AsYesNo(), InNamingOption = infos.Im2CRC.InNamingOption.AsYesNo(), Default = infos.Im2CRC.Default.AsYesNo(), }); } if (infos.Languages != null) { offlineListInfos.Add(new Formats.OfflineListInfo { Name = "languages", Visible = infos.Languages.Visible.AsYesNo(), InNamingOption = infos.Languages.InNamingOption.AsYesNo(), Default = infos.Languages.Default.AsYesNo(), }); } Header.SetFieldValue(Models.Metadata.Header.InfosKey, [.. offlineListInfos]); } } if (item.ContainsKey(Models.Metadata.Header.NewDatKey)) { var newDat = item.Read(Models.Metadata.Header.NewDatKey); if (newDat != null) { Header.SetFieldValue("DATVERSIONURL", newDat.DatVersionUrl); //Header.SetFieldValue("DATURL", newDat.DatUrl); // TODO: Add to internal model Header.SetFieldValue("IMURL", newDat.ImUrl); } } if (item.ContainsKey(Models.Metadata.Header.SearchKey)) { // TODO: Add to internal model } // Selectively set all possible fields -- TODO: Figure out how to make this less manual if (Header.GetFieldValue(Models.Metadata.Header.AuthorKey) == null) Header.SetFieldValue(Models.Metadata.Header.AuthorKey, header.GetFieldValue(Models.Metadata.Header.AuthorKey)); if (Header.GetFieldValue(Models.Metadata.Header.BiosModeKey) == MergingFlag.None) Header.SetFieldValue(Models.Metadata.Header.BiosModeKey, header.GetFieldValue(Models.Metadata.Header.BiosModeKey)); if (Header.GetFieldValue(Models.Metadata.Header.BuildKey) == null) Header.SetFieldValue(Models.Metadata.Header.BuildKey, header.GetFieldValue(Models.Metadata.Header.BuildKey)); if (Header.GetFieldValue(Models.Metadata.Header.CategoryKey) == null) Header.SetFieldValue(Models.Metadata.Header.CategoryKey, header.GetFieldValue(Models.Metadata.Header.CategoryKey)); if (Header.GetFieldValue(Models.Metadata.Header.CommentKey) == null) Header.SetFieldValue(Models.Metadata.Header.CommentKey, header.GetFieldValue(Models.Metadata.Header.CommentKey)); if (Header.GetFieldValue(Models.Metadata.Header.DateKey) == null) Header.SetFieldValue(Models.Metadata.Header.DateKey, header.GetFieldValue(Models.Metadata.Header.DateKey)); if (Header.GetFieldValue(Models.Metadata.Header.DatVersionKey) == null) Header.SetFieldValue(Models.Metadata.Header.DatVersionKey, header.GetFieldValue(Models.Metadata.Header.DatVersionKey)); if (Header.GetFieldValue(Models.Metadata.Header.DebugKey) == null) Header.SetFieldValue(Models.Metadata.Header.DebugKey, header.GetFieldValue(Models.Metadata.Header.DebugKey)); if (Header.GetFieldValue(Models.Metadata.Header.DescriptionKey) == null) Header.SetFieldValue(Models.Metadata.Header.DescriptionKey, header.GetFieldValue(Models.Metadata.Header.DescriptionKey)); if (Header.GetFieldValue(Models.Metadata.Header.EmailKey) == null) Header.SetFieldValue(Models.Metadata.Header.EmailKey, header.GetFieldValue(Models.Metadata.Header.EmailKey)); if (Header.GetFieldValue(Models.Metadata.Header.EmulatorVersionKey) == null) Header.SetFieldValue(Models.Metadata.Header.EmulatorVersionKey, header.GetFieldValue(Models.Metadata.Header.EmulatorVersionKey)); if (Header.GetFieldValue(Models.Metadata.Header.ForceMergingKey) == MergingFlag.None) Header.SetFieldValue(Models.Metadata.Header.ForceMergingKey, header.GetFieldValue(Models.Metadata.Header.ForceMergingKey)); if (Header.GetFieldValue(Models.Metadata.Header.ForceNodumpKey) == NodumpFlag.None) Header.SetFieldValue(Models.Metadata.Header.ForceNodumpKey, header.GetFieldValue(Models.Metadata.Header.ForceNodumpKey)); if (Header.GetFieldValue(Models.Metadata.Header.ForcePackingKey) == PackingFlag.None) Header.SetFieldValue(Models.Metadata.Header.ForcePackingKey, header.GetFieldValue(Models.Metadata.Header.ForcePackingKey)); if (Header.GetFieldValue(Models.Metadata.Header.HeaderKey) == null) Header.SetFieldValue(Models.Metadata.Header.HeaderKey, header.GetFieldValue(Models.Metadata.Header.HeaderKey)); if (Header.GetFieldValue(Models.Metadata.Header.HomepageKey) == null) Header.SetFieldValue(Models.Metadata.Header.HomepageKey, header.GetFieldValue(Models.Metadata.Header.HomepageKey)); if (Header.GetFieldValue(Models.Metadata.Header.IdKey) == null) Header.SetFieldValue(Models.Metadata.Header.IdKey, header.GetFieldValue(Models.Metadata.Header.IdKey)); if (Header.GetFieldValue(Models.Metadata.Header.ImFolderKey) == null) Header.SetFieldValue(Models.Metadata.Header.ImFolderKey, header.GetFieldValue(Models.Metadata.Header.ImFolderKey)); if (Header.GetFieldValue(Models.Metadata.Header.LockBiosModeKey) == null) Header.SetFieldValue(Models.Metadata.Header.LockBiosModeKey, header.GetFieldValue(Models.Metadata.Header.LockBiosModeKey)); if (Header.GetFieldValue(Models.Metadata.Header.LockRomModeKey) == null) Header.SetFieldValue(Models.Metadata.Header.LockRomModeKey, header.GetFieldValue(Models.Metadata.Header.LockRomModeKey)); if (Header.GetFieldValue(Models.Metadata.Header.LockSampleModeKey) == null) Header.SetFieldValue(Models.Metadata.Header.LockSampleModeKey, header.GetFieldValue(Models.Metadata.Header.LockSampleModeKey)); if (Header.GetFieldValue(Models.Metadata.Header.MameConfigKey) == null) Header.SetFieldValue(Models.Metadata.Header.MameConfigKey, header.GetFieldValue(Models.Metadata.Header.NameKey)); if (Header.GetFieldValue(Models.Metadata.Header.NameKey) == null) Header.SetFieldValue(Models.Metadata.Header.NameKey, header.GetFieldValue(Models.Metadata.Header.MameConfigKey)); if (Header.GetFieldValue(Models.Metadata.Header.PluginKey) == null) Header.SetFieldValue(Models.Metadata.Header.PluginKey, header.GetFieldValue(Models.Metadata.Header.PluginKey)); if (Header.GetFieldValue(Models.Metadata.Header.RefNameKey) == null) Header.SetFieldValue(Models.Metadata.Header.RefNameKey, header.GetFieldValue(Models.Metadata.Header.RefNameKey)); if (Header.GetFieldValue(Models.Metadata.Header.RomModeKey) == MergingFlag.None) Header.SetFieldValue(Models.Metadata.Header.RomModeKey, header.GetFieldValue(Models.Metadata.Header.RomModeKey)); if (Header.GetFieldValue(Models.Metadata.Header.RomTitleKey) == null) Header.SetFieldValue(Models.Metadata.Header.RomTitleKey, header.GetFieldValue(Models.Metadata.Header.RomTitleKey)); if (Header.GetFieldValue(Models.Metadata.Header.RootDirKey) == null) Header.SetFieldValue(Models.Metadata.Header.RootDirKey, header.GetFieldValue(Models.Metadata.Header.RootDirKey)); if (Header.GetFieldValue(Models.Metadata.Header.SampleModeKey) == MergingFlag.None) Header.SetFieldValue(Models.Metadata.Header.SampleModeKey, header.GetFieldValue(Models.Metadata.Header.SampleModeKey)); if (Header.GetFieldValue(Models.Metadata.Header.ScreenshotsHeightKey) == null) Header.SetFieldValue(Models.Metadata.Header.ScreenshotsHeightKey, header.GetFieldValue(Models.Metadata.Header.ScreenshotsHeightKey)); if (Header.GetFieldValue(Models.Metadata.Header.ScreenshotsWidthKey) == null) Header.SetFieldValue(Models.Metadata.Header.ScreenshotsWidthKey, header.GetFieldValue(Models.Metadata.Header.ScreenshotsWidthKey)); if (Header.GetFieldValue(Models.Metadata.Header.SystemKey) == null) Header.SetFieldValue(Models.Metadata.Header.SystemKey, header.GetFieldValue(Models.Metadata.Header.SystemKey)); if (Header.GetFieldValue(Models.Metadata.Header.TypeKey) == null) Header.SetFieldValue(Models.Metadata.Header.TypeKey, header.GetFieldValue(Models.Metadata.Header.TypeKey)); if (Header.GetFieldValue(Models.Metadata.Header.UrlKey) == null) Header.SetFieldValue(Models.Metadata.Header.UrlKey, header.GetFieldValue(Models.Metadata.Header.UrlKey)); if (Header.GetFieldValue(Models.Metadata.Header.VersionKey) == null) Header.SetFieldValue(Models.Metadata.Header.VersionKey, header.GetFieldValue(Models.Metadata.Header.VersionKey)); // Handle implied SuperDAT if (Header.GetFieldValue(Models.Metadata.Header.NameKey)?.Contains(" - SuperDAT") == true && keep) { if (Header.GetFieldValue(Models.Metadata.Header.TypeKey) == null) Header.SetFieldValue(Models.Metadata.Header.TypeKey, "SuperDAT"); } } /// /// Convert machines information /// /// Machine array to convert /// Name of the file to be parsed /// Index ID for the DAT /// True to only add item statistics while parsing, false otherwise private void ConvertMachines(Models.Metadata.Machine[]? items, string filename, int indexId, bool statsOnly) { // If the array is invalid, we can't do anything if (items == null || !items.Any()) return; // Loop through the machines and add foreach (var machine in items) { ConvertMachine(machine, filename, indexId, statsOnly); } } /// /// Convert machine information /// /// Machine to convert /// Name of the file to be parsed /// Index ID for the DAT /// True to only add item statistics while parsing, false otherwise private void ConvertMachine(Models.Metadata.Machine? item, string filename, int indexId, bool statsOnly) { // If the machine is invalid, we can't do anything if (item == null || !item.Any()) return; // Create an internal machine var machine = new DatItems.Machine(item); // Convert items in the machine if (item.ContainsKey(Models.Metadata.Machine.AdjusterKey)) { var items = ReadItemArray(item, Models.Metadata.Machine.AdjusterKey); ProcessItems(items, machine, filename, indexId, statsOnly); } if (item.ContainsKey(Models.Metadata.Machine.ArchiveKey)) { var items = ReadItemArray(item, Models.Metadata.Machine.ArchiveKey); ProcessItems(items, machine, filename, indexId, statsOnly); } if (item.ContainsKey(Models.Metadata.Machine.BiosSetKey)) { var items = ReadItemArray(item, Models.Metadata.Machine.BiosSetKey); ProcessItems(items, machine, filename, indexId, statsOnly); } if (item.ContainsKey(Models.Metadata.Machine.ChipKey)) { var items = ReadItemArray(item, Models.Metadata.Machine.ChipKey); ProcessItems(items, machine, filename, indexId, statsOnly); } if (item.ContainsKey(Models.Metadata.Machine.ConfigurationKey)) { var items = ReadItemArray(item, Models.Metadata.Machine.ConfigurationKey); ProcessItems(items, machine, filename, indexId, statsOnly); } if (item.ContainsKey(Models.Metadata.Machine.DeviceKey)) { var items = ReadItemArray(item, Models.Metadata.Machine.DeviceKey); ProcessItems(items, machine, filename, indexId, statsOnly); } if (item.ContainsKey(Models.Metadata.Machine.DeviceRefKey)) { var items = ReadItemArray(item, Models.Metadata.Machine.DeviceRefKey); ProcessItems(items, machine, filename, indexId, statsOnly); } if (item.ContainsKey(Models.Metadata.Machine.DipSwitchKey)) { var items = ReadItemArray(item, Models.Metadata.Machine.DipSwitchKey); ProcessItems(items, machine, filename, indexId, statsOnly); } if (item.ContainsKey(Models.Metadata.Machine.DiskKey)) { var items = ReadItemArray(item, Models.Metadata.Machine.DiskKey); ProcessItems(items, machine, filename, indexId, statsOnly); } if (item.ContainsKey(Models.Metadata.Machine.DisplayKey)) { var items = ReadItemArray(item, Models.Metadata.Machine.DisplayKey); ProcessItems(items, machine, filename, indexId, statsOnly); } if (item.ContainsKey(Models.Metadata.Machine.DriverKey)) { var items = ReadItemArray(item, Models.Metadata.Machine.DriverKey); ProcessItems(items, machine, filename, indexId, statsOnly); } if (item.ContainsKey(Models.Metadata.Machine.DumpKey)) { var items = ReadItemArray(item, Models.Metadata.Machine.DumpKey); ProcessItems(items, machine, filename, indexId, statsOnly); } if (item.ContainsKey(Models.Metadata.Machine.FeatureKey)) { var items = ReadItemArray(item, Models.Metadata.Machine.FeatureKey); ProcessItems(items, machine, filename, indexId, statsOnly); } if (item.ContainsKey(Models.Metadata.Machine.InfoKey)) { var items = ReadItemArray(item, Models.Metadata.Machine.InfoKey); ProcessItems(items, machine, filename, indexId, statsOnly); } if (item.ContainsKey(Models.Metadata.Machine.InputKey)) { var items = ReadItemArray(item, Models.Metadata.Machine.InputKey); ProcessItems(items, machine, filename, indexId, statsOnly); } if (item.ContainsKey(Models.Metadata.Machine.MediaKey)) { var items = ReadItemArray(item, Models.Metadata.Machine.MediaKey); ProcessItems(items, machine, filename, indexId, statsOnly); } if (item.ContainsKey(Models.Metadata.Machine.PartKey)) { var items = ReadItemArray(item, Models.Metadata.Machine.PartKey); ProcessItems(items, machine, filename, indexId, statsOnly); } if (item.ContainsKey(Models.Metadata.Machine.PortKey)) { var items = ReadItemArray(item, Models.Metadata.Machine.PortKey); ProcessItems(items, machine, filename, indexId, statsOnly); } if (item.ContainsKey(Models.Metadata.Machine.RamOptionKey)) { var items = ReadItemArray(item, Models.Metadata.Machine.RamOptionKey); ProcessItems(items, machine, filename, indexId, statsOnly); } if (item.ContainsKey(Models.Metadata.Machine.ReleaseKey)) { var items = ReadItemArray(item, Models.Metadata.Machine.ReleaseKey); ProcessItems(items, machine, filename, indexId, statsOnly); } if (item.ContainsKey(Models.Metadata.Machine.RomKey)) { var items = ReadItemArray(item, Models.Metadata.Machine.RomKey); ProcessItems(items, machine, filename, indexId, statsOnly); } if (item.ContainsKey(Models.Metadata.Machine.SampleKey)) { var items = ReadItemArray(item, Models.Metadata.Machine.SampleKey); ProcessItems(items, machine, filename, indexId, statsOnly); } if (item.ContainsKey(Models.Metadata.Machine.SharedFeatKey)) { var items = ReadItemArray(item, Models.Metadata.Machine.SharedFeatKey); ProcessItems(items, machine, filename, indexId, statsOnly); } if (item.ContainsKey(Models.Metadata.Machine.SlotKey)) { var items = ReadItemArray(item, Models.Metadata.Machine.SlotKey); ProcessItems(items, machine, filename, indexId, statsOnly); } if (item.ContainsKey(Models.Metadata.Machine.SoftwareListKey)) { var items = ReadItemArray(item, Models.Metadata.Machine.SoftwareListKey); ProcessItems(items, machine, filename, indexId, statsOnly); } if (item.ContainsKey(Models.Metadata.Machine.SoundKey)) { var items = ReadItemArray(item, Models.Metadata.Machine.SoundKey); ProcessItems(items, machine, filename, indexId, statsOnly); } if (item.ContainsKey(Models.Metadata.Machine.TruripKey)) { // TODO: Figure out what this maps to } if (item.ContainsKey(Models.Metadata.Machine.VideoKey)) { var items = ReadItemArray(item, Models.Metadata.Machine.VideoKey); ProcessItems(items, machine, filename, indexId, statsOnly); } } /// /// Convert Adjuster information /// /// Array of internal items to convert /// Machine to use with the converted items /// Name of the file to be parsed /// Index ID for the DAT /// True to only add item statistics while parsing, false otherwise private void ProcessItems(Models.Metadata.Adjuster[]? items, DatItems.Machine machine, string filename, int indexId, bool statsOnly) { // If the array is null or empty, return without processing if (items == null || items.Length == 0) return; // Loop through the items and add foreach (var item in items) { var datItem = new DatItems.Formats.Adjuster(item); datItem.SetFieldValue(DatItems.DatItem.SourceKey, new DatItems.Source { Index = indexId, Name = filename }); datItem.CopyMachineInformation(machine); // Handle subitems var condition = item.Read(Models.Metadata.Adjuster.ConditionKey); if (condition != null) { var subItem = new DatItems.Formats.Condition(condition); datItem.SetFieldValue(Models.Metadata.Adjuster.ConditionKey, subItem); } ParseAddHelper(datItem, statsOnly); } } /// /// Convert Archive information /// /// Array of internal items to convert /// Machine to use with the converted items /// Name of the file to be parsed /// Index ID for the DAT /// True to only add item statistics while parsing, false otherwise private void ProcessItems(Models.Metadata.Archive[]? items, DatItems.Machine machine, string filename, int indexId, bool statsOnly) { // If the array is null or empty, return without processing if (items == null || items.Length == 0) return; // Loop through the items and add foreach (var item in items) { var datItem = new DatItems.Formats.Archive(item); datItem.SetFieldValue(DatItems.DatItem.SourceKey, new DatItems.Source { Index = indexId, Name = filename }); datItem.CopyMachineInformation(machine); ParseAddHelper(datItem, statsOnly); } } /// /// Convert BiosSet information /// /// Array of internal items to convert /// Machine to use with the converted items /// Name of the file to be parsed /// Index ID for the DAT /// True to only add item statistics while parsing, false otherwise private void ProcessItems(Models.Metadata.BiosSet[]? items, DatItems.Machine machine, string filename, int indexId, bool statsOnly) { // If the array is null or empty, return without processing if (items == null || items.Length == 0) return; // Loop through the items and add foreach (var item in items) { var datItem = new DatItems.Formats.BiosSet(item); datItem.SetFieldValue(DatItems.DatItem.SourceKey, new DatItems.Source { Index = indexId, Name = filename }); datItem.CopyMachineInformation(machine); ParseAddHelper(datItem, statsOnly); } } /// /// Convert Chip information /// /// Array of internal items to convert /// Machine to use with the converted items /// Name of the file to be parsed /// Index ID for the DAT /// True to only add item statistics while parsing, false otherwise private void ProcessItems(Models.Metadata.Chip[]? items, DatItems.Machine machine, string filename, int indexId, bool statsOnly) { // If the array is null or empty, return without processing if (items == null || items.Length == 0) return; // Loop through the items and add foreach (var item in items) { var datItem = new DatItems.Formats.Chip(item); datItem.SetFieldValue(DatItems.DatItem.SourceKey, new DatItems.Source { Index = indexId, Name = filename }); datItem.CopyMachineInformation(machine); ParseAddHelper(datItem, statsOnly); } } /// /// Convert Configuration information /// /// Array of internal items to convert /// Machine to use with the converted items /// Name of the file to be parsed /// Index ID for the DAT /// True to only add item statistics while parsing, false otherwise private void ProcessItems(Models.Metadata.Configuration[]? items, DatItems.Machine machine, string filename, int indexId, bool statsOnly) { // If the array is null or empty, return without processing if (items == null || items.Length == 0) return; // Loop through the items and add foreach (var item in items) { var datItem = new DatItems.Formats.Configuration(item); datItem.SetFieldValue(DatItems.DatItem.SourceKey, new DatItems.Source { Index = indexId, Name = filename }); datItem.CopyMachineInformation(machine); // Handle subitems var condition = item.Read(Models.Metadata.Configuration.ConditionKey); if (condition != null) { var subItem = new DatItems.Formats.Condition(condition); datItem.SetFieldValue(Models.Metadata.Configuration.ConditionKey, subItem); } var confLocations = ReadItemArray(item, Models.Metadata.Configuration.ConfLocationKey); if (confLocations != null) { var subLocations = new List(); foreach (var location in confLocations) { var subItem = new DatItems.Formats.ConfLocation(location); subLocations.Add(subItem); } datItem.SetFieldValue(Models.Metadata.Configuration.ConfLocationKey, [.. subLocations]); } var confSettings = ReadItemArray(item, Models.Metadata.Configuration.ConfSettingKey); if (confSettings != null) { var subValues = new List(); foreach (var setting in confSettings) { var subItem = new DatItems.Formats.ConfSetting(setting); var subCondition = item.Read(Models.Metadata.ConfSetting.ConditionKey); if (subCondition != null) { var subSubItem = new DatItems.Formats.Condition(subCondition); subItem.SetFieldValue(Models.Metadata.ConfSetting.ConditionKey, subSubItem); } subValues.Add(subItem); } datItem.SetFieldValue(Models.Metadata.Configuration.ConfSettingKey, [.. subValues]); } ParseAddHelper(datItem, statsOnly); } } /// /// Convert Device information /// /// Array of internal items to convert /// Machine to use with the converted items /// Name of the file to be parsed /// Index ID for the DAT /// True to only add item statistics while parsing, false otherwise private void ProcessItems(Models.Metadata.Device[]? items, DatItems.Machine machine, string filename, int indexId, bool statsOnly) { // If the array is null or empty, return without processing if (items == null || items.Length == 0) return; // Loop through the items and add foreach (var item in items) { var datItem = new DatItems.Formats.Device(item); datItem.SetFieldValue(DatItems.DatItem.SourceKey, new DatItems.Source { Index = indexId, Name = filename }); datItem.CopyMachineInformation(machine); // Handle subitems var instance = item.Read(Models.Metadata.Device.InstanceKey); if (instance != null) { var subItem = new DatItems.Formats.Instance(instance); datItem.SetFieldValue(Models.Metadata.Device.InstanceKey, subItem); } var extensions = ReadItemArray(item, Models.Metadata.Device.ExtensionKey); if (extensions != null) { var subExtensions = new List(); foreach (var extension in extensions) { var subItem = new DatItems.Formats.Extension(extension); subExtensions.Add(subItem); } datItem.SetFieldValue(Models.Metadata.Device.ExtensionKey, [.. subExtensions]); } ParseAddHelper(datItem, statsOnly); } } /// /// Convert DeviceRef information /// /// Array of internal items to convert /// Machine to use with the converted items /// Name of the file to be parsed /// Index ID for the DAT /// True to only add item statistics while parsing, false otherwise private void ProcessItems(Models.Metadata.DeviceRef[]? items, DatItems.Machine machine, string filename, int indexId, bool statsOnly) { // If the array is null or empty, return without processing if (items == null || items.Length == 0) return; // Loop through the items and add foreach (var item in items) { var datItem = new DatItems.Formats.DeviceRef(item); datItem.SetFieldValue(DatItems.DatItem.SourceKey, new DatItems.Source { Index = indexId, Name = filename }); datItem.CopyMachineInformation(machine); ParseAddHelper(datItem, statsOnly); } } /// /// Convert DipSwitch information /// /// Array of internal items to convert /// Machine to use with the converted items /// Name of the file to be parsed /// Index ID for the DAT /// True to only add item statistics while parsing, false otherwise private void ProcessItems(Models.Metadata.DipSwitch[]? items, DatItems.Machine machine, string filename, int indexId, bool statsOnly) { // If the array is null or empty, return without processing if (items == null || items.Length == 0) return; // Loop through the items and add foreach (var item in items) { var datItem = new DatItems.Formats.DipSwitch(item); datItem.SetFieldValue(DatItems.DatItem.SourceKey, new DatItems.Source { Index = indexId, Name = filename }); datItem.CopyMachineInformation(machine); // Handle subitems var condition = item.Read(Models.Metadata.DipSwitch.ConditionKey); if (condition != null) { var subItem = new DatItems.Formats.Condition(condition); datItem.SetFieldValue(Models.Metadata.DipSwitch.ConditionKey, subItem); } var dipLocations = ReadItemArray(item, Models.Metadata.DipSwitch.DipLocationKey); if (dipLocations != null) { var subLocations = new List(); foreach (var location in dipLocations) { var subItem = new DatItems.Formats.DipLocation(location); subLocations.Add(subItem); } datItem.SetFieldValue(Models.Metadata.DipSwitch.DipLocationKey, [.. subLocations]); } var dipValues = ReadItemArray(item, Models.Metadata.DipSwitch.DipValueKey); if (dipValues != null) { var subValues = new List(); foreach (var value in dipValues) { var subItem = new DatItems.Formats.DipValue(value); var subCondition = item.Read(Models.Metadata.DipValue.ConditionKey); if (subCondition != null) { var subSubItem = new DatItems.Formats.Condition(subCondition); subItem.SetFieldValue(Models.Metadata.DipValue.ConditionKey, subSubItem); } subValues.Add(subItem); } datItem.SetFieldValue(Models.Metadata.DipSwitch.DipValueKey, [.. subValues]); } ParseAddHelper(datItem, statsOnly); } } /// /// Convert Disk information /// /// Array of internal items to convert /// Machine to use with the converted items /// Name of the file to be parsed /// Index ID for the DAT /// True to only add item statistics while parsing, false otherwise private void ProcessItems(Models.Metadata.Disk[]? items, DatItems.Machine machine, string filename, int indexId, bool statsOnly) { // If the array is null or empty, return without processing if (items == null || items.Length == 0) return; // Loop through the items and add foreach (var item in items) { var datItem = new DatItems.Formats.Disk(item); datItem.SetFieldValue(DatItems.DatItem.SourceKey, new DatItems.Source { Index = indexId, Name = filename }); datItem.CopyMachineInformation(machine); ParseAddHelper(datItem, statsOnly); } } /// /// Convert Display information /// /// Array of internal items to convert /// Machine to use with the converted items /// Name of the file to be parsed /// Index ID for the DAT /// True to only add item statistics while parsing, false otherwise private void ProcessItems(Models.Metadata.Display[]? items, DatItems.Machine machine, string filename, int indexId, bool statsOnly) { // If the array is null or empty, return without processing if (items == null || items.Length == 0) return; // Loop through the items and add foreach (var item in items) { var datItem = new DatItems.Formats.Display(item); datItem.SetFieldValue(DatItems.DatItem.SourceKey, new DatItems.Source { Index = indexId, Name = filename }); datItem.CopyMachineInformation(machine); ParseAddHelper(datItem, statsOnly); } } /// /// Convert Driver information /// /// Array of internal items to convert /// Machine to use with the converted items /// Name of the file to be parsed /// Index ID for the DAT /// True to only add item statistics while parsing, false otherwise private void ProcessItems(Models.Metadata.Driver[]? items, DatItems.Machine machine, string filename, int indexId, bool statsOnly) { // If the array is null or empty, return without processing if (items == null || items.Length == 0) return; // Loop through the items and add foreach (var item in items) { var datItem = new DatItems.Formats.Driver(item); datItem.SetFieldValue(DatItems.DatItem.SourceKey, new DatItems.Source { Index = indexId, Name = filename }); datItem.CopyMachineInformation(machine); ParseAddHelper(datItem, statsOnly); } } /// /// Convert Dump information /// /// Array of internal items to convert /// Machine to use with the converted items /// Name of the file to be parsed /// Index ID for the DAT /// True to only add item statistics while parsing, false otherwise private void ProcessItems(Models.Metadata.Dump[]? items, DatItems.Machine machine, string filename, int indexId, bool statsOnly) { // If the array is null or empty, return without processing if (items == null || items.Length == 0) return; // Loop through the items and add int index = 0; foreach (var dump in items) { // If we don't have rom data, we can't do anything Models.Metadata.Rom? rom = null; OpenMSXSubType subType = OpenMSXSubType.NULL; if (dump?.Read(Models.Metadata.Dump.RomKey) != null) { rom = dump.Read(Models.Metadata.Dump.RomKey); subType = OpenMSXSubType.Rom; } else if (dump?.Read(Models.Metadata.Dump.MegaRomKey) != null) { rom = dump.Read(Models.Metadata.Dump.MegaRomKey); subType = OpenMSXSubType.MegaRom; } else if (dump?.Read(Models.Metadata.Dump.SCCPlusCartKey) != null) { rom = dump.Read(Models.Metadata.Dump.SCCPlusCartKey); subType = OpenMSXSubType.SCCPlusCart; } else { continue; } string name = $"{machine.GetFieldValue(Models.Metadata.Machine.NameKey)}_{index++}{(!string.IsNullOrEmpty(rom!.ReadString(Models.Metadata.Rom.RemarkKey)) ? $" {rom.ReadString(Models.Metadata.Rom.RemarkKey)}" : string.Empty)}"; var item = new DatItems.Formats.Rom(); item.SetName(name); item.SetFieldValue(Models.Metadata.Rom.OffsetKey, rom.ReadString(Models.Metadata.Rom.OffsetKey)); item.SetFieldValue(Models.Metadata.Rom.OpenMSXMediaType, subType); item.SetFieldValue(Models.Metadata.Rom.OpenMSXType, rom.ReadString(Models.Metadata.Rom.OpenMSXType)); item.SetFieldValue(Models.Metadata.Rom.RemarkKey, rom.ReadString(Models.Metadata.Rom.RemarkKey)); item.SetFieldValue(Models.Metadata.Rom.SHA1Key, rom.ReadString(Models.Metadata.Rom.SHA1Key)); item.SetFieldValue(DatItems.DatItem.SourceKey, new DatItems.Source { Index = indexId, Name = filename }); if (dump.Read(Models.Metadata.Dump.OriginalKey) != null) { var original = dump.Read(Models.Metadata.Dump.OriginalKey)!; item.SetFieldValue("ORIGINAL", new DatItems.Formats.Original { Value = original.Value.AsYesNo(), Content = original.Content, }); } item.CopyMachineInformation(machine); ParseAddHelper(item, statsOnly); } } /// /// Convert Feature information /// /// Array of internal items to convert /// Machine to use with the converted items /// Name of the file to be parsed /// Index ID for the DAT /// True to only add item statistics while parsing, false otherwise private void ProcessItems(Models.Metadata.Feature[]? items, DatItems.Machine machine, string filename, int indexId, bool statsOnly) { // If the array is null or empty, return without processing if (items == null || items.Length == 0) return; // Loop through the items and add foreach (var item in items) { var datItem = new DatItems.Formats.Feature(item); datItem.SetFieldValue(DatItems.DatItem.SourceKey, new DatItems.Source { Index = indexId, Name = filename }); datItem.CopyMachineInformation(machine); ParseAddHelper(datItem, statsOnly); } } /// /// Convert Info information /// /// Array of internal items to convert /// Machine to use with the converted items /// Name of the file to be parsed /// Index ID for the DAT /// True to only add item statistics while parsing, false otherwise private void ProcessItems(Models.Metadata.Info[]? items, DatItems.Machine machine, string filename, int indexId, bool statsOnly) { // If the array is null or empty, return without processing if (items == null || items.Length == 0) return; // Loop through the items and add foreach (var item in items) { var datItem = new DatItems.Formats.Info(item); datItem.SetFieldValue(DatItems.DatItem.SourceKey, new DatItems.Source { Index = indexId, Name = filename }); datItem.CopyMachineInformation(machine); ParseAddHelper(datItem, statsOnly); } } /// /// Convert Input information /// /// Array of internal items to convert /// Machine to use with the converted items /// Name of the file to be parsed /// Index ID for the DAT /// True to only add item statistics while parsing, false otherwise private void ProcessItems(Models.Metadata.Input[]? items, DatItems.Machine machine, string filename, int indexId, bool statsOnly) { // If the array is null or empty, return without processing if (items == null || items.Length == 0) return; // Loop through the items and add foreach (var item in items) { var datItem = new DatItems.Formats.Input(item); datItem.SetFieldValue(DatItems.DatItem.SourceKey, new DatItems.Source { Index = indexId, Name = filename }); datItem.CopyMachineInformation(machine); // Handle subitems var controls = ReadItemArray(item, Models.Metadata.Input.ControlKey); if (controls != null) { var subControls = new List(); foreach (var control in controls) { var subItem = new DatItems.Formats.Control(control); subControls.Add(subItem); } datItem.SetFieldValue(Models.Metadata.Input.ControlKey, [.. subControls]); } ParseAddHelper(datItem, statsOnly); } } /// /// Convert Media information /// /// Array of internal items to convert /// Machine to use with the converted items /// Name of the file to be parsed /// Index ID for the DAT /// True to only add item statistics while parsing, false otherwise private void ProcessItems(Models.Metadata.Media[]? items, DatItems.Machine machine, string filename, int indexId, bool statsOnly) { // If the array is null or empty, return without processing if (items == null || items.Length == 0) return; // Loop through the items and add foreach (var item in items) { var datItem = new DatItems.Formats.Media(item); datItem.SetFieldValue(DatItems.DatItem.SourceKey, new DatItems.Source { Index = indexId, Name = filename }); datItem.CopyMachineInformation(machine); ParseAddHelper(datItem, statsOnly); } } /// /// Convert Part information /// /// Array of internal items to convert /// Machine to use with the converted items /// Name of the file to be parsed /// Index ID for the DAT /// True to only add item statistics while parsing, false otherwise private void ProcessItems(Models.Metadata.Part[]? items, DatItems.Machine machine, string filename, int indexId, bool statsOnly) { // If the array is null or empty, return without processing if (items == null || items.Length == 0) return; // Loop through the items and add foreach (var item in items) { var partItem = new DatItems.Formats.Part(item); // Handle subitems var dataAreas = ReadItemArray(item, Models.Metadata.Part.DataAreaKey); if (dataAreas != null) { foreach (var dataArea in dataAreas) { var dataAreaItem = new DatItems.Formats.DataArea(dataArea); var roms = ReadItemArray(dataArea, Models.Metadata.DataArea.RomKey); if (roms == null) continue; foreach (var rom in roms) { var romItem = new DatItems.Formats.Rom(rom); romItem.SetFieldValue(DatItems.Formats.Rom.DataAreaKey, dataAreaItem); romItem.SetFieldValue(DatItems.Formats.Rom.PartKey, partItem); romItem.SetFieldValue(DatItems.DatItem.SourceKey, new DatItems.Source { Index = indexId, Name = filename }); romItem.CopyMachineInformation(machine); ParseAddHelper(romItem, statsOnly); } } } var diskAreas = ReadItemArray(item, Models.Metadata.Part.DiskAreaKey); if (diskAreas != null) { foreach (var diskArea in diskAreas) { var diskAreaitem = new DatItems.Formats.DiskArea(diskArea); var disks = ReadItemArray(diskArea, Models.Metadata.DiskArea.DiskKey); if (disks == null) continue; foreach (var disk in disks) { var diskItem = new DatItems.Formats.Disk(disk); diskItem.SetFieldValue(DatItems.Formats.Disk.DiskAreaKey, diskAreaitem); diskItem.SetFieldValue(DatItems.Formats.Disk.PartKey, partItem); diskItem.SetFieldValue(DatItems.DatItem.SourceKey, new DatItems.Source { Index = indexId, Name = filename }); diskItem.CopyMachineInformation(machine); ParseAddHelper(diskItem, statsOnly); } } var dipSwitches = ReadItemArray(item, Models.Metadata.Part.DipSwitchKey); if (dipSwitches != null) { foreach (var dipSwitch in dipSwitches) { var dipSwitchItem = new DatItems.Formats.DipSwitch(dipSwitch); dipSwitchItem.SetFieldValue(DatItems.DatItem.SourceKey, new DatItems.Source { Index = indexId, Name = filename }); dipSwitchItem.CopyMachineInformation(machine); var dipValues = ReadItemArray(dipSwitch, Models.Metadata.DipSwitch.DipValueKey); if (dipValues != null) { var subValues = new List(); foreach (var value in dipValues) { var subItem = new DatItems.Formats.DipValue(value); subValues.Add(subItem); } dipSwitchItem.SetFieldValue(Models.Metadata.DipSwitch.DipValueKey, [.. subValues]); } ParseAddHelper(dipSwitchItem, statsOnly); } } } } } /// /// Convert Port information /// /// Array of internal items to convert /// Machine to use with the converted items /// Name of the file to be parsed /// Index ID for the DAT /// True to only add item statistics while parsing, false otherwise private void ProcessItems(Models.Metadata.Port[]? items, DatItems.Machine machine, string filename, int indexId, bool statsOnly) { // If the array is null or empty, return without processing if (items == null || items.Length == 0) return; // Loop through the items and add foreach (var item in items) { var datItem = new DatItems.Formats.Port(item); datItem.SetFieldValue(DatItems.DatItem.SourceKey, new DatItems.Source { Index = indexId, Name = filename }); datItem.CopyMachineInformation(machine); // Handle subitems var analogs = ReadItemArray(item, Models.Metadata.Port.AnalogKey); if (analogs != null) { var subAnalogs = new List(); foreach (var analog in analogs) { var subItem = new DatItems.Formats.Analog(analog); subAnalogs.Add(subItem); } datItem.SetFieldValue(Models.Metadata.Port.AnalogKey, [.. subAnalogs]); } ParseAddHelper(datItem, statsOnly); } } /// /// Convert RamOption information /// /// Array of internal items to convert /// Machine to use with the converted items /// Name of the file to be parsed /// Index ID for the DAT /// True to only add item statistics while parsing, false otherwise private void ProcessItems(Models.Metadata.RamOption[]? items, DatItems.Machine machine, string filename, int indexId, bool statsOnly) { // If the array is null or empty, return without processing if (items == null || items.Length == 0) return; // Loop through the items and add foreach (var item in items) { var datItem = new DatItems.Formats.RamOption(item); datItem.SetFieldValue(DatItems.DatItem.SourceKey, new DatItems.Source { Index = indexId, Name = filename }); datItem.CopyMachineInformation(machine); ParseAddHelper(datItem, statsOnly); } } /// /// Convert Release information /// /// Array of internal items to convert /// Machine to use with the converted items /// Name of the file to be parsed /// Index ID for the DAT /// True to only add item statistics while parsing, false otherwise private void ProcessItems(Models.Metadata.Release[]? items, DatItems.Machine machine, string filename, int indexId, bool statsOnly) { // If the array is null or empty, return without processing if (items == null || items.Length == 0) return; // Loop through the items and add foreach (var item in items) { var datItem = new DatItems.Formats.Release(item); datItem.SetFieldValue(DatItems.DatItem.SourceKey, new DatItems.Source { Index = indexId, Name = filename }); datItem.CopyMachineInformation(machine); ParseAddHelper(datItem, statsOnly); } } /// /// Convert Rom information /// /// Array of internal items to convert /// Machine to use with the converted items /// Name of the file to be parsed /// Index ID for the DAT /// True to only add item statistics while parsing, false otherwise private void ProcessItems(Models.Metadata.Rom[]? items, DatItems.Machine machine, string filename, int indexId, bool statsOnly) { // If the array is null or empty, return without processing if (items == null || items.Length == 0) return; // Loop through the items and add foreach (var item in items) { var datItem = new DatItems.Formats.Rom(item); datItem.SetFieldValue(DatItems.DatItem.SourceKey, new DatItems.Source { Index = indexId, Name = filename }); datItem.CopyMachineInformation(machine); ParseAddHelper(datItem, statsOnly); } } /// /// Convert Sample information /// /// Array of internal items to convert /// Machine to use with the converted items /// Name of the file to be parsed /// Index ID for the DAT /// True to only add item statistics while parsing, false otherwise private void ProcessItems(Models.Metadata.Sample[]? items, DatItems.Machine machine, string filename, int indexId, bool statsOnly) { // If the array is null or empty, return without processing if (items == null || items.Length == 0) return; // Loop through the items and add foreach (var item in items) { var datItem = new DatItems.Formats.Sample(item); datItem.SetFieldValue(DatItems.DatItem.SourceKey, new DatItems.Source { Index = indexId, Name = filename }); datItem.CopyMachineInformation(machine); ParseAddHelper(datItem, statsOnly); } } /// /// Convert SharedFeat information /// /// Array of internal items to convert /// Machine to use with the converted items /// Name of the file to be parsed /// Index ID for the DAT /// True to only add item statistics while parsing, false otherwise private void ProcessItems(Models.Metadata.SharedFeat[]? items, DatItems.Machine machine, string filename, int indexId, bool statsOnly) { // If the array is null or empty, return without processing if (items == null || items.Length == 0) return; // Loop through the items and add foreach (var item in items) { var datItem = new DatItems.Formats.SharedFeat(item); datItem.SetFieldValue(DatItems.DatItem.SourceKey, new DatItems.Source { Index = indexId, Name = filename }); datItem.CopyMachineInformation(machine); ParseAddHelper(datItem, statsOnly); } } /// /// Convert Slot information /// /// Array of internal items to convert /// Machine to use with the converted items /// Name of the file to be parsed /// Index ID for the DAT /// True to only add item statistics while parsing, false otherwise private void ProcessItems(Models.Metadata.Slot[]? items, DatItems.Machine machine, string filename, int indexId, bool statsOnly) { // If the array is null or empty, return without processing if (items == null || items.Length == 0) return; // Loop through the items and add foreach (var item in items) { var datItem = new DatItems.Formats.Slot(item); datItem.SetFieldValue(DatItems.DatItem.SourceKey, new DatItems.Source { Index = indexId, Name = filename }); datItem.CopyMachineInformation(machine); // Handle subitems var slotOptions = ReadItemArray(item, Models.Metadata.Slot.SlotOptionKey); if (slotOptions != null) { var subOptions = new List(); foreach (var slotOption in slotOptions) { var subItem = new DatItems.Formats.SlotOption(slotOption); subOptions.Add(subItem); } datItem.SetFieldValue(Models.Metadata.Slot.SlotOptionKey, [.. subOptions]); } ParseAddHelper(datItem, statsOnly); } } /// /// Convert SoftwareList information /// /// Array of internal items to convert /// Machine to use with the converted items /// Name of the file to be parsed /// Index ID for the DAT /// True to only add item statistics while parsing, false otherwise private void ProcessItems(Models.Metadata.SoftwareList[]? items, DatItems.Machine machine, string filename, int indexId, bool statsOnly) { // If the array is null or empty, return without processing if (items == null || items.Length == 0) return; // Loop through the items and add foreach (var item in items) { var datItem = new DatItems.Formats.SoftwareList(item); datItem.SetFieldValue(DatItems.DatItem.SourceKey, new DatItems.Source { Index = indexId, Name = filename }); datItem.CopyMachineInformation(machine); ParseAddHelper(datItem, statsOnly); } } /// /// Convert Sound information /// /// Array of internal items to convert /// Machine to use with the converted items /// Name of the file to be parsed /// Index ID for the DAT /// True to only add item statistics while parsing, false otherwise private void ProcessItems(Models.Metadata.Sound[]? items, DatItems.Machine machine, string filename, int indexId, bool statsOnly) { // If the array is null or empty, return without processing if (items == null || items.Length == 0) return; // Loop through the items and add foreach (var item in items) { var datItem = new DatItems.Formats.Sound(item); datItem.SetFieldValue(DatItems.DatItem.SourceKey, new DatItems.Source { Index = indexId, Name = filename }); datItem.CopyMachineInformation(machine); ParseAddHelper(datItem, statsOnly); } } /// /// Convert Video information /// /// Array of internal items to convert /// Machine to use with the converted items /// Name of the file to be parsed /// Index ID for the DAT /// True to only add item statistics while parsing, false otherwise private void ProcessItems(Models.Metadata.Video[]? items, DatItems.Machine machine, string filename, int indexId, bool statsOnly) { // If the array is null or empty, return without processing if (items == null || items.Length == 0) return; // Loop through the items and add foreach (var item in items) { var datItem = new DatItems.Formats.Display(item); datItem.SetFieldValue(DatItems.DatItem.SourceKey, new DatItems.Source { Index = indexId, Name = filename }); datItem.CopyMachineInformation(machine); ParseAddHelper(datItem, statsOnly); } } /// /// Read an item array from a given key, if possible /// private static T[]? ReadItemArray(Models.Metadata.DictionaryBase item, string key) where T : Models.Metadata.DictionaryBase { var items = item.Read(key); if (items == default) { var single = item.Read(key); if (single != default) items = [single]; } return items; } #endregion } }