using System.Collections.Generic;
using System.Linq;
using SabreTools.Core;
using SabreTools.Core.Tools;
namespace SabreTools.DatFiles
{
// TODO: Convert nested items (e.g. Configuration, DipLocation)
public partial class DatFile
{
#region Converters
///
/// 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.DatVersionUrl);
}
}
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.NameKey) == null)
Header.SetFieldValue(Models.Metadata.Header.NameKey, header.GetFieldValue(Models.Metadata.Header.NameKey));
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.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);
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);
ParseAddHelper(datItem, statsOnly);
}
}
///
/// Convert DataArea 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.DataArea[]? 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;
// TODO: Extract Roms
// Loop through the items and add
foreach (var item in items)
{
var datItem = new DatItems.Formats.DataArea(item);
datItem.SetFieldValue(DatItems.DatItem.SourceKey, new DatItems.Source { Index = indexId, Name = filename });
datItem.CopyMachineInformation(machine);
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);
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 DipLocation 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.DipLocation[]? 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.DipLocation(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);
ParseAddHelper(datItem, statsOnly);
}
}
///
/// Convert DipValue 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.DipValue[]? 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.DipValue(item);
datItem.SetFieldValue(DatItems.DatItem.SourceKey, new DatItems.Source { Index = indexId, Name = filename });
datItem.CopyMachineInformation(machine);
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 DiskArea 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.DiskArea[]? 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;
// TODO: Extract Disks
// Loop through the items and add
foreach (var item in items)
{
var datItem = new DatItems.Formats.DiskArea(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
foreach (var item in items)
{
// TODO: Handle processing of Dump items (rom, megarom, sccpluscart)
}
}
///
/// 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);
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;
// TODO: Extract DataAreas
// TODO: Extract DiskAreas
// TODO: Extract DipSwitches
// Loop through the items and add
foreach (var item in items)
{
var datItem = new DatItems.Formats.Part(item);
datItem.SetFieldValue(DatItems.DatItem.SourceKey, new DatItems.Source { Index = indexId, Name = filename });
datItem.CopyMachineInformation(machine);
ParseAddHelper(datItem, 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);
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 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
}
}