mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Reduce unnecessary round-trip conversions
This commit is contained in:
@@ -537,7 +537,7 @@ namespace SabreTools.DatFiles
|
||||
var confLocations = ReadItemArray<Models.Metadata.ConfLocation>(item, Models.Metadata.Configuration.ConfLocationKey);
|
||||
if (confLocations != null)
|
||||
{
|
||||
var subLocations = new List<DatItems.Formats.ConfLocation>();
|
||||
List<DatItems.Formats.ConfLocation> subLocations = [];
|
||||
foreach (var location in confLocations)
|
||||
{
|
||||
var subItem = new DatItems.Formats.ConfLocation(location);
|
||||
@@ -555,7 +555,7 @@ namespace SabreTools.DatFiles
|
||||
var confSettings = ReadItemArray<Models.Metadata.ConfSetting>(item, Models.Metadata.Configuration.ConfSettingKey);
|
||||
if (confSettings != null)
|
||||
{
|
||||
var subValues = new List<DatItems.Formats.ConfSetting>();
|
||||
List<DatItems.Formats.ConfSetting> subValues = [];
|
||||
foreach (var setting in confSettings)
|
||||
{
|
||||
var subItem = new DatItems.Formats.ConfSetting(setting);
|
||||
@@ -626,7 +626,7 @@ namespace SabreTools.DatFiles
|
||||
var extensions = ReadItemArray<Models.Metadata.Extension>(item, Models.Metadata.Device.ExtensionKey);
|
||||
if (extensions != null)
|
||||
{
|
||||
var subExtensions = new List<DatItems.Formats.Extension>();
|
||||
List<DatItems.Formats.Extension> subExtensions = [];
|
||||
foreach (var extension in extensions)
|
||||
{
|
||||
var subItem = new DatItems.Formats.Extension(extension);
|
||||
@@ -709,7 +709,7 @@ namespace SabreTools.DatFiles
|
||||
var dipLocations = ReadItemArray<Models.Metadata.DipLocation>(item, Models.Metadata.DipSwitch.DipLocationKey);
|
||||
if (dipLocations != null)
|
||||
{
|
||||
var subLocations = new List<DatItems.Formats.DipLocation>();
|
||||
List<DatItems.Formats.DipLocation> subLocations = [];
|
||||
foreach (var location in dipLocations)
|
||||
{
|
||||
var subItem = new DatItems.Formats.DipLocation(location);
|
||||
@@ -727,7 +727,7 @@ namespace SabreTools.DatFiles
|
||||
var dipValues = ReadItemArray<Models.Metadata.DipValue>(item, Models.Metadata.DipSwitch.DipValueKey);
|
||||
if (dipValues != null)
|
||||
{
|
||||
var subValues = new List<DatItems.Formats.DipValue>();
|
||||
List<DatItems.Formats.DipValue> subValues = [];
|
||||
foreach (var value in dipValues)
|
||||
{
|
||||
var subItem = new DatItems.Formats.DipValue(value);
|
||||
@@ -1093,7 +1093,7 @@ namespace SabreTools.DatFiles
|
||||
var controls = ReadItemArray<Models.Metadata.Control>(item, Models.Metadata.Input.ControlKey);
|
||||
if (controls != null)
|
||||
{
|
||||
var subControls = new List<DatItems.Formats.Control>();
|
||||
List<DatItems.Formats.Control> subControls = [];
|
||||
foreach (var control in controls)
|
||||
{
|
||||
var subItem = new DatItems.Formats.Control(control);
|
||||
@@ -1319,7 +1319,7 @@ namespace SabreTools.DatFiles
|
||||
var dipLocations = ReadItemArray<Models.Metadata.DipLocation>(dipSwitch, Models.Metadata.DipSwitch.DipLocationKey);
|
||||
if (dipLocations != null)
|
||||
{
|
||||
var subLocations = new List<DatItems.Formats.DipLocation>();
|
||||
List<DatItems.Formats.DipLocation> subLocations = [];
|
||||
foreach (var location in dipLocations)
|
||||
{
|
||||
var subItem = new DatItems.Formats.DipLocation(location);
|
||||
@@ -1337,7 +1337,7 @@ namespace SabreTools.DatFiles
|
||||
var dipValues = ReadItemArray<Models.Metadata.DipValue>(dipSwitch, Models.Metadata.DipSwitch.DipValueKey);
|
||||
if (dipValues != null)
|
||||
{
|
||||
var subValues = new List<DatItems.Formats.DipValue>();
|
||||
List<DatItems.Formats.DipValue> subValues = [];
|
||||
foreach (var value in dipValues)
|
||||
{
|
||||
var subItem = new DatItems.Formats.DipValue(value);
|
||||
@@ -1420,7 +1420,7 @@ namespace SabreTools.DatFiles
|
||||
var analogs = ReadItemArray<Models.Metadata.Analog>(item, Models.Metadata.Port.AnalogKey);
|
||||
if (analogs != null)
|
||||
{
|
||||
var subAnalogs = new List<DatItems.Formats.Analog>();
|
||||
List<DatItems.Formats.Analog> subAnalogs = [];
|
||||
foreach (var analog in analogs)
|
||||
{
|
||||
var subItem = new DatItems.Formats.Analog(analog);
|
||||
@@ -1636,7 +1636,7 @@ namespace SabreTools.DatFiles
|
||||
var slotOptions = ReadItemArray<Models.Metadata.SlotOption>(item, Models.Metadata.Slot.SlotOptionKey);
|
||||
if (slotOptions != null)
|
||||
{
|
||||
var subOptions = new List<DatItems.Formats.SlotOption>();
|
||||
List<DatItems.Formats.SlotOption> subOptions = [];
|
||||
foreach (var slotOption in slotOptions)
|
||||
{
|
||||
var subItem = new DatItems.Formats.SlotOption(slotOption);
|
||||
|
||||
@@ -82,9 +82,9 @@ namespace SabreTools.DatFiles
|
||||
continue;
|
||||
#endif
|
||||
|
||||
for (int j = 0; j < items.Length; j++)
|
||||
foreach (var item in items.Values)
|
||||
{
|
||||
RemoveFields(items[j].Item2, machineFieldNames, itemFieldNames);
|
||||
RemoveFields(item, machineFieldNames, itemFieldNames);
|
||||
}
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
});
|
||||
|
||||
@@ -100,7 +100,7 @@ namespace SabreTools.DatFiles
|
||||
private Models.Metadata.Machine[]? ConvertMachines(bool ignoreblanks = false)
|
||||
{
|
||||
// Create a machine list to hold all outputs
|
||||
var machines = new List<Models.Metadata.Machine>();
|
||||
List<Models.Metadata.Machine> machines = [];
|
||||
|
||||
// Loop through the sorted items and create games for them
|
||||
foreach (string key in Items.SortedKeys)
|
||||
@@ -374,7 +374,7 @@ namespace SabreTools.DatFiles
|
||||
{
|
||||
// Get existing data areas as a list
|
||||
var dataAreasArr = partItems[partName].Read<Models.Metadata.DataArea[]>(Models.Metadata.Part.DataAreaKey) ?? [];
|
||||
var dataAreas = new List<Models.Metadata.DataArea>(dataAreasArr);
|
||||
List<Models.Metadata.DataArea> dataAreas = [.. dataAreasArr];
|
||||
|
||||
// Find the existing disk area to append to, otherwise create a new disk area
|
||||
int dataAreaIndex = dataAreas.FindIndex(da => da.ReadString(Models.Metadata.DataArea.NameKey) == dataAreaName);
|
||||
@@ -397,7 +397,7 @@ namespace SabreTools.DatFiles
|
||||
|
||||
// Get existing roms as a list
|
||||
var romsArr = aggregateDataArea.Read<Models.Metadata.Rom[]>(Models.Metadata.DataArea.RomKey) ?? [];
|
||||
var roms = new List<Models.Metadata.Rom>(romsArr);
|
||||
List<Models.Metadata.Rom> roms = [.. romsArr];
|
||||
|
||||
// Add the rom to the data area
|
||||
roms.Add(romItem);
|
||||
@@ -431,7 +431,7 @@ namespace SabreTools.DatFiles
|
||||
{
|
||||
// Get existing disk areas as a list
|
||||
var diskAreasArr = partItems[partName].Read<Models.Metadata.DiskArea[]>(Models.Metadata.Part.DiskAreaKey) ?? [];
|
||||
var diskAreas = new List<Models.Metadata.DiskArea>(diskAreasArr);
|
||||
List<Models.Metadata.DiskArea> diskAreas = [.. diskAreasArr];
|
||||
|
||||
// Find the existing disk area to append to, otherwise create a new disk area
|
||||
int diskAreaIndex = diskAreas.FindIndex(da => da.ReadString(Models.Metadata.DiskArea.NameKey) == diskAreaName);
|
||||
@@ -451,7 +451,7 @@ namespace SabreTools.DatFiles
|
||||
|
||||
// Get existing disks as a list
|
||||
var disksArr = aggregateDiskArea.Read<Models.Metadata.Disk[]>(Models.Metadata.DiskArea.DiskKey) ?? [];
|
||||
var disks = new List<Models.Metadata.Disk>(disksArr);
|
||||
List<Models.Metadata.Disk> disks = [.. disksArr];
|
||||
|
||||
// Add the disk to the data area
|
||||
disks.Add(diskItem);
|
||||
@@ -475,7 +475,7 @@ namespace SabreTools.DatFiles
|
||||
{
|
||||
// Get existing dipswitches as a list
|
||||
var dipSwitchesArr = partItems[partName].Read<Models.Metadata.DipSwitch[]>(Models.Metadata.Part.DipSwitchKey) ?? [];
|
||||
var dipSwitches = new List<Models.Metadata.DipSwitch>(dipSwitchesArr);
|
||||
List<Models.Metadata.DipSwitch> dipSwitches = [.. dipSwitchesArr];
|
||||
|
||||
// Clear any empty fields
|
||||
ClearEmptyKeys(dipSwitchItem);
|
||||
@@ -492,7 +492,7 @@ namespace SabreTools.DatFiles
|
||||
{
|
||||
// Get existing features as a list
|
||||
var featuresArr = partItems[partName].Read<Models.Metadata.Feature[]>(Models.Metadata.Part.FeatureKey) ?? [];
|
||||
var features = new List<Models.Metadata.Feature>(featuresArr);
|
||||
List<Models.Metadata.Feature> features = [.. featuresArr];
|
||||
|
||||
// Clear any empty fields
|
||||
ClearEmptyKeys(featureItem);
|
||||
@@ -523,17 +523,17 @@ namespace SabreTools.DatFiles
|
||||
private Models.Metadata.Machine[]? ConvertMachinesDB(bool ignoreblanks = false)
|
||||
{
|
||||
// Create a machine list to hold all outputs
|
||||
var machines = new List<Models.Metadata.Machine>();
|
||||
List<Models.Metadata.Machine> machines = [];
|
||||
|
||||
// Loop through the sorted items and create games for them
|
||||
foreach (string key in ItemsDB.SortedKeys)
|
||||
{
|
||||
var items = ItemsDB.GetItemsForBucket(key, filter: true);
|
||||
if (items == null || items.Length == 0)
|
||||
if (items == null || items.Count == 0)
|
||||
continue;
|
||||
|
||||
// Create a machine to hold everything
|
||||
var machine = ItemsDB.GetMachineForItem(items[0].Item1).Item2!.GetInternalClone();
|
||||
var machine = ItemsDB.GetMachineForItem(items.First().Key).Value!.GetInternalClone();
|
||||
|
||||
// Handle Trurip object, if it exists
|
||||
if (machine.ContainsKey(Models.Metadata.Machine.TruripKey))
|
||||
@@ -557,19 +557,16 @@ namespace SabreTools.DatFiles
|
||||
Dictionary<Models.Metadata.Part, (Models.Metadata.DiskArea, Models.Metadata.Disk)> diskAreaMappings = [];
|
||||
|
||||
// Loop through and convert the items to respective lists
|
||||
for (int index = 0; index < items.Length; index++)
|
||||
foreach (var kvp in items)
|
||||
{
|
||||
// Get the item
|
||||
var item = items[index];
|
||||
|
||||
// Check for a "null" item
|
||||
item = ProcessNullifiedItem(item);
|
||||
var item = ProcessNullifiedItem(kvp);
|
||||
|
||||
// Skip if we're ignoring the item
|
||||
if (ShouldIgnore(item, ignoreblanks))
|
||||
if (ShouldIgnore(item.Value, ignoreblanks))
|
||||
continue;
|
||||
|
||||
switch (item.Item2)
|
||||
switch (item.Value)
|
||||
{
|
||||
case DatItems.Formats.Adjuster adjuster:
|
||||
var adjusterItem = ProcessItem(adjuster);
|
||||
@@ -797,7 +794,7 @@ namespace SabreTools.DatFiles
|
||||
{
|
||||
// Get existing data areas as a list
|
||||
var dataAreasArr = partItems[partName].Read<Models.Metadata.DataArea[]>(Models.Metadata.Part.DataAreaKey) ?? [];
|
||||
var dataAreas = new List<Models.Metadata.DataArea>(dataAreasArr);
|
||||
List<Models.Metadata.DataArea> dataAreas = [.. dataAreasArr];
|
||||
|
||||
// Find the existing disk area to append to, otherwise create a new disk area
|
||||
int dataAreaIndex = dataAreas.FindIndex(da => da.ReadString(Models.Metadata.DataArea.NameKey) == dataAreaName);
|
||||
@@ -820,7 +817,7 @@ namespace SabreTools.DatFiles
|
||||
|
||||
// Get existing roms as a list
|
||||
var romsArr = aggregateDataArea.Read<Models.Metadata.Rom[]>(Models.Metadata.DataArea.RomKey) ?? [];
|
||||
var roms = new List<Models.Metadata.Rom>(romsArr);
|
||||
List<Models.Metadata.Rom> roms = [.. romsArr];
|
||||
|
||||
// Add the rom to the data area
|
||||
roms.Add(romItem);
|
||||
@@ -854,7 +851,7 @@ namespace SabreTools.DatFiles
|
||||
{
|
||||
// Get existing disk areas as a list
|
||||
var diskAreasArr = partItems[partName].Read<Models.Metadata.DiskArea[]>(Models.Metadata.Part.DiskAreaKey) ?? [];
|
||||
var diskAreas = new List<Models.Metadata.DiskArea>(diskAreasArr);
|
||||
List<Models.Metadata.DiskArea> diskAreas = [.. diskAreasArr];
|
||||
|
||||
// Find the existing disk area to append to, otherwise create a new disk area
|
||||
int diskAreaIndex = diskAreas.FindIndex(da => da.ReadString(Models.Metadata.DiskArea.NameKey) == diskAreaName);
|
||||
@@ -874,7 +871,7 @@ namespace SabreTools.DatFiles
|
||||
|
||||
// Get existing disks as a list
|
||||
var disksArr = aggregateDiskArea.Read<Models.Metadata.Disk[]>(Models.Metadata.DiskArea.DiskKey) ?? [];
|
||||
var disks = new List<Models.Metadata.Disk>(disksArr);
|
||||
List<Models.Metadata.Disk> disks = [.. disksArr];
|
||||
|
||||
// Add the disk to the data area
|
||||
disks.Add(diskItem);
|
||||
@@ -898,7 +895,7 @@ namespace SabreTools.DatFiles
|
||||
{
|
||||
// Get existing dipswitches as a list
|
||||
var dipSwitchesArr = partItems[partName].Read<Models.Metadata.DipSwitch[]>(Models.Metadata.Part.DipSwitchKey) ?? [];
|
||||
var dipSwitches = new List<Models.Metadata.DipSwitch>(dipSwitchesArr);
|
||||
List<Models.Metadata.DipSwitch> dipSwitches = [.. dipSwitchesArr];
|
||||
|
||||
// Clear any empty fields
|
||||
ClearEmptyKeys(dipSwitchItem);
|
||||
@@ -915,7 +912,7 @@ namespace SabreTools.DatFiles
|
||||
{
|
||||
// Get existing features as a list
|
||||
var featuresArr = partItems[partName].Read<Models.Metadata.Feature[]>(Models.Metadata.Part.FeatureKey) ?? [];
|
||||
var features = new List<Models.Metadata.Feature>(featuresArr);
|
||||
List<Models.Metadata.Feature> features = [.. featuresArr];
|
||||
|
||||
// Clear any empty fields
|
||||
ClearEmptyKeys(featureItem);
|
||||
@@ -970,7 +967,7 @@ namespace SabreTools.DatFiles
|
||||
var confLocations = item.GetFieldValue<DatItems.Formats.ConfLocation[]?>(Models.Metadata.Configuration.ConfLocationKey);
|
||||
if (confLocations != null)
|
||||
{
|
||||
var confLocationItems = new List<Models.Metadata.ConfLocation>();
|
||||
List<Models.Metadata.ConfLocation> confLocationItems = [];
|
||||
foreach (var confLocation in confLocations)
|
||||
{
|
||||
var confLocationItem = confLocation.GetInternalClone();
|
||||
@@ -983,7 +980,7 @@ namespace SabreTools.DatFiles
|
||||
var confSettings = item.GetFieldValue<DatItems.Formats.ConfSetting[]?>(Models.Metadata.Configuration.ConfSettingKey);
|
||||
if (confSettings != null)
|
||||
{
|
||||
var confSettingItems = new List<Models.Metadata.ConfSetting>();
|
||||
List<Models.Metadata.ConfSetting> confSettingItems = [];
|
||||
foreach (var confSetting in confSettings)
|
||||
{
|
||||
var confSettingItem = confSetting.GetInternalClone();
|
||||
@@ -1011,7 +1008,7 @@ namespace SabreTools.DatFiles
|
||||
var extensions = item.GetFieldValue<DatItems.Formats.Extension[]?>(Models.Metadata.Device.ExtensionKey);
|
||||
if (extensions != null)
|
||||
{
|
||||
var extensionItems = new List<Models.Metadata.Extension>();
|
||||
List<Models.Metadata.Extension> extensionItems = [];
|
||||
foreach (var extension in extensions)
|
||||
{
|
||||
var extensionItem = extension.GetInternalClone();
|
||||
@@ -1040,7 +1037,7 @@ namespace SabreTools.DatFiles
|
||||
var dipLocations = item.GetFieldValue<DatItems.Formats.DipLocation[]?>(Models.Metadata.DipSwitch.DipLocationKey);
|
||||
if (dipLocations != null)
|
||||
{
|
||||
var dipLocationItems = new List<Models.Metadata.DipLocation>();
|
||||
List<Models.Metadata.DipLocation> dipLocationItems = [];
|
||||
foreach (var dipLocation in dipLocations)
|
||||
{
|
||||
var extensionItem = dipLocation.GetInternalClone();
|
||||
@@ -1053,7 +1050,7 @@ namespace SabreTools.DatFiles
|
||||
var dipValues = item.GetFieldValue<DatItems.Formats.DipValue[]?>(Models.Metadata.DipSwitch.DipValueKey);
|
||||
if (dipValues != null)
|
||||
{
|
||||
var dipValueItems = new List<Models.Metadata.DipValue>();
|
||||
List<Models.Metadata.DipValue> dipValueItems = [];
|
||||
foreach (var dipValue in dipValues)
|
||||
{
|
||||
var extensionItem = dipValue.GetInternalClone();
|
||||
@@ -1104,7 +1101,7 @@ namespace SabreTools.DatFiles
|
||||
var controls = item.GetFieldValue<DatItems.Formats.Control[]?>(Models.Metadata.Input.ControlKey);
|
||||
if (controls != null)
|
||||
{
|
||||
var controlItems = new List<Models.Metadata.Control>();
|
||||
List<Models.Metadata.Control> controlItems = [];
|
||||
foreach (var control in controls)
|
||||
{
|
||||
var controlItem = control.GetInternalClone();
|
||||
@@ -1128,7 +1125,7 @@ namespace SabreTools.DatFiles
|
||||
var analogs = item.GetFieldValue<DatItems.Formats.Analog[]?>(Models.Metadata.Port.AnalogKey);
|
||||
if (analogs != null)
|
||||
{
|
||||
var analogItems = new List<Models.Metadata.Analog>();
|
||||
List<Models.Metadata.Analog> analogItems = [];
|
||||
foreach (var analog in analogs)
|
||||
{
|
||||
var extensionItem = analog.GetInternalClone();
|
||||
@@ -1252,7 +1249,7 @@ namespace SabreTools.DatFiles
|
||||
var slotOptions = item.GetFieldValue<DatItems.Formats.SlotOption[]?>(Models.Metadata.Slot.SlotOptionKey);
|
||||
if (slotOptions != null)
|
||||
{
|
||||
var slotOptionItems = new List<Models.Metadata.SlotOption>();
|
||||
List<Models.Metadata.SlotOption> slotOptionItems = [];
|
||||
foreach (var slotOption in slotOptions)
|
||||
{
|
||||
var extensionItem = slotOption.GetInternalClone();
|
||||
|
||||
@@ -342,21 +342,21 @@ namespace SabreTools.DatFiles
|
||||
/// <param name="item">DatItem to create a prefix/postfix for</param>
|
||||
/// <param name="prefix">True for prefix, false for postfix</param>
|
||||
/// <returns>Sanitized string representing the postfix or prefix</returns>
|
||||
protected string CreatePrefixPostfixDB((long, DatItem) item, bool prefix)
|
||||
protected string CreatePrefixPostfixDB(KeyValuePair<long, DatItem> item, bool prefix)
|
||||
{
|
||||
// Get machine for the item
|
||||
var machine = ItemsDB.GetMachineForItem(item.Item1);
|
||||
if (machine.Item2 == null)
|
||||
var machine = ItemsDB.GetMachineForItem(item.Key);
|
||||
if (machine.Value == null)
|
||||
return string.Empty;
|
||||
|
||||
// Initialize strings
|
||||
string? type = item.Item2.GetStringFieldValue(Models.Metadata.DatItem.TypeKey);
|
||||
string? type = item.Value.GetStringFieldValue(Models.Metadata.DatItem.TypeKey);
|
||||
string fix,
|
||||
game = machine.Item2.GetStringFieldValue(Models.Metadata.Machine.NameKey) ?? string.Empty,
|
||||
manufacturer = machine.Item2.GetStringFieldValue(Models.Metadata.Machine.ManufacturerKey) ?? string.Empty,
|
||||
publisher = machine.Item2.GetStringFieldValue(Models.Metadata.Machine.PublisherKey) ?? string.Empty,
|
||||
category = machine.Item2.GetStringFieldValue(Models.Metadata.Machine.CategoryKey) ?? string.Empty,
|
||||
name = item.Item2.GetName() ?? type.AsEnumValue<ItemType>().AsStringValue() ?? string.Empty,
|
||||
game = machine.Value.GetStringFieldValue(Models.Metadata.Machine.NameKey) ?? string.Empty,
|
||||
manufacturer = machine.Value.GetStringFieldValue(Models.Metadata.Machine.ManufacturerKey) ?? string.Empty,
|
||||
publisher = machine.Value.GetStringFieldValue(Models.Metadata.Machine.PublisherKey) ?? string.Empty,
|
||||
category = machine.Value.GetStringFieldValue(Models.Metadata.Machine.CategoryKey) ?? string.Empty,
|
||||
name = item.Value.GetName() ?? type.AsEnumValue<ItemType>().AsStringValue() ?? string.Empty,
|
||||
crc = string.Empty,
|
||||
md5 = string.Empty,
|
||||
sha1 = string.Empty,
|
||||
@@ -384,19 +384,19 @@ namespace SabreTools.DatFiles
|
||||
}
|
||||
|
||||
// Ensure we have the proper values for replacement
|
||||
if (item.Item2 is Disk disk)
|
||||
if (item.Value is Disk disk)
|
||||
{
|
||||
md5 = disk.GetStringFieldValue(Models.Metadata.Disk.MD5Key) ?? string.Empty;
|
||||
sha1 = disk.GetStringFieldValue(Models.Metadata.Disk.SHA1Key) ?? string.Empty;
|
||||
}
|
||||
else if (item.Item2 is Media media)
|
||||
else if (item.Value is Media media)
|
||||
{
|
||||
md5 = media.GetStringFieldValue(Models.Metadata.Media.MD5Key) ?? string.Empty;
|
||||
sha1 = media.GetStringFieldValue(Models.Metadata.Media.SHA1Key) ?? string.Empty;
|
||||
sha256 = media.GetStringFieldValue(Models.Metadata.Media.SHA256Key) ?? string.Empty;
|
||||
spamsum = media.GetStringFieldValue(Models.Metadata.Media.SpamSumKey) ?? string.Empty;
|
||||
}
|
||||
else if (item.Item2 is Rom rom)
|
||||
else if (item.Value is Rom rom)
|
||||
{
|
||||
crc = rom.GetStringFieldValue(Models.Metadata.Rom.CRCKey) ?? string.Empty;
|
||||
md5 = rom.GetStringFieldValue(Models.Metadata.Rom.MD5Key) ?? string.Empty;
|
||||
@@ -539,7 +539,7 @@ namespace SabreTools.DatFiles
|
||||
/// <param name="item">DatItem to update</param>
|
||||
/// <param name="forceRemoveQuotes">True if the Quotes flag should be ignored, false otherwise</param>
|
||||
/// <param name="forceRomName">True if the UseRomName should be always on (default), false otherwise</param>
|
||||
protected void ProcessItemNameDB((long, DatItem) item, bool forceRemoveQuotes, bool forceRomName = true)
|
||||
protected void ProcessItemNameDB(KeyValuePair<long, DatItem> item, bool forceRemoveQuotes, bool forceRomName = true)
|
||||
{
|
||||
// Backup relevant values and set new ones accordingly
|
||||
bool? quotesBackup = Header.GetBoolFieldValue(DatHeader.QuotesKey);
|
||||
@@ -550,12 +550,12 @@ namespace SabreTools.DatFiles
|
||||
Header.SetFieldValue<bool>(DatHeader.UseRomNameKey, true);
|
||||
|
||||
// Get machine for the item
|
||||
var machine = ItemsDB.GetMachineForItem(item.Item1);
|
||||
var machine = ItemsDB.GetMachineForItem(item.Key);
|
||||
|
||||
// Get the name to update
|
||||
string? name = (Header.GetBoolFieldValue(DatHeader.UseRomNameKey) == true
|
||||
? item.Item2.GetName()
|
||||
: machine.Item2!.GetStringFieldValue(Models.Metadata.Machine.NameKey)) ?? string.Empty;
|
||||
? item.Value.GetName()
|
||||
: machine.Value!.GetStringFieldValue(Models.Metadata.Machine.NameKey)) ?? string.Empty;
|
||||
|
||||
// Create the proper Prefix and Postfix
|
||||
string pre = CreatePrefixPostfixDB(item, true);
|
||||
@@ -565,34 +565,34 @@ namespace SabreTools.DatFiles
|
||||
var outputDepot = Header.GetFieldValue<DepotInformation?>(DatHeader.OutputDepotKey);
|
||||
if (outputDepot?.IsActive == true)
|
||||
{
|
||||
if (item.Item2 is Disk disk)
|
||||
if (item.Value is Disk disk)
|
||||
{
|
||||
// We can only write out if there's a SHA-1
|
||||
string? sha1 = disk.GetStringFieldValue(Models.Metadata.Disk.SHA1Key);
|
||||
if (!string.IsNullOrEmpty(sha1))
|
||||
{
|
||||
name = Utilities.GetDepotPath(sha1, outputDepot.Depth)?.Replace('\\', '/');
|
||||
item.Item2.SetName($"{pre}{name}{post}");
|
||||
item.Value.SetName($"{pre}{name}{post}");
|
||||
}
|
||||
}
|
||||
else if (item.Item2 is Media media)
|
||||
else if (item.Value is Media media)
|
||||
{
|
||||
// We can only write out if there's a SHA-1
|
||||
string? sha1 = media.GetStringFieldValue(Models.Metadata.Media.SHA1Key);
|
||||
if (!string.IsNullOrEmpty(sha1))
|
||||
{
|
||||
name = Utilities.GetDepotPath(sha1, outputDepot.Depth)?.Replace('\\', '/');
|
||||
item.Item2.SetName($"{pre}{name}{post}");
|
||||
item.Value.SetName($"{pre}{name}{post}");
|
||||
}
|
||||
}
|
||||
else if (item.Item2 is Rom rom)
|
||||
else if (item.Value is Rom rom)
|
||||
{
|
||||
// We can only write out if there's a SHA-1
|
||||
string? sha1 = rom.GetStringFieldValue(Models.Metadata.Rom.SHA1Key);
|
||||
if (!string.IsNullOrEmpty(sha1))
|
||||
{
|
||||
name = Utilities.GetDepotPath(sha1, outputDepot.Depth)?.Replace('\\', '/');
|
||||
item.Item2.SetName($"{pre}{name}{post}");
|
||||
item.Value.SetName($"{pre}{name}{post}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -619,14 +619,14 @@ namespace SabreTools.DatFiles
|
||||
name += addExtension;
|
||||
|
||||
if (Header.GetBoolFieldValue(DatHeader.UseRomNameKey) == true && Header.GetBoolFieldValue(DatHeader.GameNameKey) == true)
|
||||
name = Path.Combine(machine.Item2!.GetStringFieldValue(Models.Metadata.Machine.NameKey) ?? string.Empty, name);
|
||||
name = Path.Combine(machine.Value!.GetStringFieldValue(Models.Metadata.Machine.NameKey) ?? string.Empty, name);
|
||||
|
||||
// Now assign back the formatted name
|
||||
name = $"{pre}{name}{post}";
|
||||
if (Header.GetBoolFieldValue(DatHeader.UseRomNameKey) == true)
|
||||
item.Item2.SetName(name);
|
||||
else if (machine.Item2 != null)
|
||||
machine.Item2.SetFieldValue<string?>(Models.Metadata.Machine.NameKey, name);
|
||||
item.Value.SetName(name);
|
||||
else if (machine.Value != null)
|
||||
machine.Value.SetFieldValue<string?>(Models.Metadata.Machine.NameKey, name);
|
||||
|
||||
// Restore all relevant values
|
||||
if (forceRemoveQuotes)
|
||||
@@ -684,15 +684,15 @@ namespace SabreTools.DatFiles
|
||||
/// </summary>
|
||||
/// <param name="item">DatItem to check for "null" status</param>
|
||||
/// <returns>Cleaned DatItem</returns>
|
||||
protected (long, DatItem) ProcessNullifiedItem((long, DatItem) item)
|
||||
protected KeyValuePair<long, DatItem> ProcessNullifiedItem(KeyValuePair<long, DatItem> item)
|
||||
{
|
||||
// If we don't have a Rom, we can ignore it
|
||||
if (item.Item2 is not Rom rom)
|
||||
if (item.Value is not Rom rom)
|
||||
return item;
|
||||
|
||||
// Get machine for the item
|
||||
var machine = ItemsDB.GetMachineForItem(item.Item1);
|
||||
var machineObj = machine.Item2;
|
||||
var machine = ItemsDB.GetMachineForItem(item.Key);
|
||||
var machineObj = machine.Value;
|
||||
if (machineObj == null)
|
||||
return item;
|
||||
|
||||
@@ -720,7 +720,7 @@ namespace SabreTools.DatFiles
|
||||
rom.GetStringFieldValue(Models.Metadata.Rom.SpamSumKey) == "null" ? ZeroHash.SpamSumStr : null);
|
||||
}
|
||||
|
||||
return (item.Item1, rom);
|
||||
return new KeyValuePair<long, DatItem>(item.Key, rom);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -766,15 +766,15 @@ namespace SabreTools.DatFiles
|
||||
/// <param name="datItems">DatItems to check</param>
|
||||
/// <returns>True if the machine contains at least one writable item, false otherwise</returns>
|
||||
/// <remarks>Empty machines are kept with this</remarks>
|
||||
protected bool ContainsWritable((long, DatItem)[]? datItems)
|
||||
protected bool ContainsWritable(Dictionary<long, DatItem>? datItems)
|
||||
{
|
||||
// Empty machines are considered writable
|
||||
if (datItems == null || datItems.Length == 0)
|
||||
if (datItems == null || datItems.Count == 0)
|
||||
return true;
|
||||
|
||||
foreach ((long, DatItem) datItem in datItems)
|
||||
foreach (var datItem in datItems)
|
||||
{
|
||||
ItemType itemType = datItem.Item2.GetStringFieldValue(Models.Metadata.DatItem.TypeKey).AsEnumValue<ItemType>();
|
||||
ItemType itemType = datItem.Value.GetStringFieldValue(Models.Metadata.DatItem.TypeKey).AsEnumValue<ItemType>();
|
||||
if (Array.Exists(GetSupportedTypes(), t => t == itemType))
|
||||
return true;
|
||||
}
|
||||
@@ -852,76 +852,6 @@ namespace SabreTools.DatFiles
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get if an item should be ignored on write
|
||||
/// </summary>
|
||||
/// <param name="datItem">DatItem to check</param>
|
||||
/// <param name="ignoreBlanks">True if blank roms should be skipped on output, false otherwise</param>
|
||||
/// <returns>True if the item should be skipped on write, false otherwise</returns>
|
||||
protected bool ShouldIgnore((long, DatItem?) datItem, bool ignoreBlanks)
|
||||
{
|
||||
// If this is invoked with a null DatItem, we ignore
|
||||
if (datItem.Item1 < 0 || datItem.Item2 == null)
|
||||
{
|
||||
logger?.Verbose($"Item was skipped because it was null");
|
||||
return true;
|
||||
}
|
||||
|
||||
// If the item is supposed to be removed, we ignore
|
||||
if (datItem.Item2.GetBoolFieldValue(DatItem.RemoveKey) == true)
|
||||
{
|
||||
string itemString = JsonConvert.SerializeObject(datItem, Formatting.None);
|
||||
logger?.Verbose($"Item '{itemString}' was skipped because it was marked for removal");
|
||||
return true;
|
||||
}
|
||||
|
||||
// If we have the Blank dat item, we ignore
|
||||
if (datItem.Item2 is Blank)
|
||||
{
|
||||
string itemString = JsonConvert.SerializeObject(datItem, Formatting.None);
|
||||
logger?.Verbose($"Item '{itemString}' was skipped because it was of type 'Blank'");
|
||||
return true;
|
||||
}
|
||||
|
||||
// If we're ignoring blanks and we have a Rom
|
||||
if (ignoreBlanks && datItem.Item2 is Rom rom)
|
||||
{
|
||||
// If we have a 0-size or blank rom, then we ignore
|
||||
long? size = rom.GetInt64FieldValue(Models.Metadata.Rom.SizeKey);
|
||||
if (size == 0 || size == null)
|
||||
{
|
||||
string itemString = JsonConvert.SerializeObject(datItem, Formatting.None);
|
||||
logger?.Verbose($"Item '{itemString}' was skipped because it had an invalid size");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// If we have an item type not in the list of supported values
|
||||
string datFormat = Header?.GetFieldValue<DatFormat>(DatHeader.DatFormatKey).ToString() ?? "Unknown Format";
|
||||
ItemType itemType = datItem.Item2.GetStringFieldValue(Models.Metadata.DatItem.TypeKey).AsEnumValue<ItemType>();
|
||||
if (!Array.Exists(GetSupportedTypes(), t => t == itemType))
|
||||
{
|
||||
string itemString = JsonConvert.SerializeObject(datItem, Formatting.None);
|
||||
logger?.Verbose($"Item '{itemString}' was skipped because it was not supported in {datFormat}");
|
||||
return true;
|
||||
}
|
||||
|
||||
// If we have an item with missing required fields
|
||||
List<string>? missingFields = GetMissingRequiredFields(datItem.Item2);
|
||||
if (missingFields != null && missingFields.Count != 0)
|
||||
{
|
||||
string itemString = JsonConvert.SerializeObject(datItem, Formatting.None);
|
||||
#if NET20 || NET35
|
||||
logger?.Verbose($"Item '{itemString}' was skipped because it was missing required fields for {datFormat}: {string.Join(", ", [.. missingFields])}");
|
||||
#else
|
||||
logger?.Verbose($"Item '{itemString}' was skipped because it was missing required fields for {datFormat}: {string.Join(", ", missingFields)}");
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace SabreTools.DatFiles.Formats
|
||||
/// <inheritdoc/>
|
||||
protected override List<string>? GetMissingRequiredFields(DatItem datItem)
|
||||
{
|
||||
var missingFields = new List<string>();
|
||||
List<string> missingFields = [];
|
||||
|
||||
// Check item name
|
||||
if (string.IsNullOrEmpty(datItem.GetName()))
|
||||
|
||||
@@ -73,7 +73,7 @@ namespace SabreTools.DatFiles.Formats
|
||||
/// <inheritdoc/>
|
||||
protected override List<string>? GetMissingRequiredFields(DatItem datItem)
|
||||
{
|
||||
var missingFields = new List<string>();
|
||||
List<string> missingFields = [];
|
||||
switch (datItem)
|
||||
{
|
||||
case Release release:
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace SabreTools.DatFiles.Formats
|
||||
/// <inheritdoc/>
|
||||
protected override List<string>? GetMissingRequiredFields(DatItem datItem)
|
||||
{
|
||||
var missingFields = new List<string>();
|
||||
List<string> missingFields = [];
|
||||
|
||||
// Check item name
|
||||
if (string.IsNullOrEmpty(datItem.GetName()))
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace SabreTools.DatFiles.Formats
|
||||
/// <inheritdoc/>
|
||||
protected override List<string>? GetMissingRequiredFields(DatItem datItem)
|
||||
{
|
||||
var missingFields = new List<string>();
|
||||
List<string> missingFields = [];
|
||||
|
||||
// Check item name
|
||||
if (string.IsNullOrEmpty(datItem.GetName()))
|
||||
|
||||
@@ -55,7 +55,7 @@ namespace SabreTools.DatFiles.Formats
|
||||
/// <inheritdoc/>
|
||||
protected override List<string>? GetMissingRequiredFields(DatItem datItem)
|
||||
{
|
||||
var missingFields = new List<string>();
|
||||
List<string> missingFields = [];
|
||||
|
||||
// Check item name
|
||||
if (string.IsNullOrEmpty(datItem.GetName()))
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace SabreTools.DatFiles.Formats
|
||||
/// <inheritdoc/>
|
||||
protected override List<string>? GetMissingRequiredFields(DatItem datItem)
|
||||
{
|
||||
var missingFields = new List<string>();
|
||||
List<string> missingFields = [];
|
||||
|
||||
// Check item name
|
||||
if (string.IsNullOrEmpty(datItem.GetName()))
|
||||
|
||||
@@ -244,7 +244,7 @@ namespace SabreTools.DatFiles.Formats
|
||||
/// <inheritdoc/>
|
||||
protected override List<string>? GetMissingRequiredFields(DatItem datItem)
|
||||
{
|
||||
var missingFields = new List<string>();
|
||||
List<string> missingFields = [];
|
||||
switch (datItem)
|
||||
{
|
||||
case BiosSet biosset:
|
||||
|
||||
@@ -248,7 +248,7 @@ namespace SabreTools.DatFiles.Formats
|
||||
/// <inheritdoc/>
|
||||
protected override List<string>? GetMissingRequiredFields(DatItem datItem)
|
||||
{
|
||||
var missingFields = new List<string>();
|
||||
List<string> missingFields = [];
|
||||
switch (datItem)
|
||||
{
|
||||
case Release release:
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using SabreTools.DatItems;
|
||||
|
||||
@@ -118,28 +119,30 @@ namespace SabreTools.DatFiles.Formats
|
||||
foreach (string key in ItemsDB.SortedKeys)
|
||||
{
|
||||
// If this machine doesn't contain any writable items, skip
|
||||
var items = ItemsDB.GetItemsForBucket(key, filter: true);
|
||||
if (items == null || !ContainsWritable(items))
|
||||
var itemsDict = ItemsDB.GetItemsForBucket(key, filter: true);
|
||||
if (itemsDict == null || !ContainsWritable(itemsDict))
|
||||
continue;
|
||||
|
||||
// Resolve the names in the block
|
||||
items = [.. DatItem.ResolveNamesDB([.. items])];
|
||||
var items = DatItem.ResolveNamesDB([.. itemsDict]);
|
||||
|
||||
for (int index = 0; index < items.Length; index++)
|
||||
foreach (var kvp in items)
|
||||
{
|
||||
// Check for a "null" item
|
||||
var datItem = items[index];
|
||||
datItem = ProcessNullifiedItem(datItem);
|
||||
var datItem = ProcessNullifiedItem(kvp);
|
||||
|
||||
// Get the machine for the item
|
||||
var machine = ItemsDB.GetMachineForItem(datItem.Item1);
|
||||
var machine = ItemsDB.GetMachineForItem(datItem.Key);
|
||||
|
||||
// Write out the item if we're using machine names or we're not ignoring
|
||||
if (!Header.GetBoolFieldValue(DatHeader.UseRomNameKey) == true || !ShouldIgnore(datItem, ignoreblanks))
|
||||
if (!Header.GetBoolFieldValue(DatHeader.UseRomNameKey) == true
|
||||
|| !ShouldIgnore(datItem.Value, ignoreblanks))
|
||||
{
|
||||
WriteDatItemDB(sw, datItem, lastgame);
|
||||
}
|
||||
|
||||
// Set the new data to compare against
|
||||
lastgame = machine.Item2!.GetStringFieldValue(Models.Metadata.Machine.NameKey);
|
||||
lastgame = machine.Value!.GetStringFieldValue(Models.Metadata.Machine.NameKey);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -182,19 +185,25 @@ namespace SabreTools.DatFiles.Formats
|
||||
/// <param name="sw">StreamWriter to output to</param>
|
||||
/// <param name="datItem">DatItem object to be output</param>
|
||||
/// <param name="lastgame">The name of the last game to be output</param>
|
||||
private void WriteDatItemDB(StreamWriter sw, (long, DatItem) datItem, string? lastgame)
|
||||
private void WriteDatItemDB(StreamWriter sw, KeyValuePair<long, DatItem> datItem, string? lastgame)
|
||||
{
|
||||
// Get the machine for the item
|
||||
var machine = ItemsDB.GetMachineForItem(datItem.Item1);
|
||||
var machine = ItemsDB.GetMachineForItem(datItem.Key);
|
||||
|
||||
// Process the item name
|
||||
ProcessItemNameDB(datItem, false, forceRomName: false);
|
||||
|
||||
// Romba mode automatically uses item name
|
||||
if (Header.GetFieldValue<DepotInformation?>(DatHeader.OutputDepotKey)?.IsActive == true || Header.GetBoolFieldValue(DatHeader.UseRomNameKey) == true)
|
||||
sw.Write($"{datItem.Item2.GetName() ?? string.Empty}\n");
|
||||
else if (!Header.GetBoolFieldValue(DatHeader.UseRomNameKey) == true && machine.Item2!.GetStringFieldValue(Models.Metadata.Machine.NameKey) != lastgame)
|
||||
sw.Write($"{machine.Item2!.GetStringFieldValue(Models.Metadata.Machine.NameKey) ?? string.Empty}\n");
|
||||
if (Header.GetFieldValue<DepotInformation?>(DatHeader.OutputDepotKey)?.IsActive == true
|
||||
|| Header.GetBoolFieldValue(DatHeader.UseRomNameKey) == true)
|
||||
{
|
||||
sw.Write($"{datItem.Value.GetName() ?? string.Empty}\n");
|
||||
}
|
||||
else if (!Header.GetBoolFieldValue(DatHeader.UseRomNameKey) == true
|
||||
&& machine.Value!.GetStringFieldValue(Models.Metadata.Machine.NameKey) != lastgame)
|
||||
{
|
||||
sw.Write($"{machine.Value!.GetStringFieldValue(Models.Metadata.Machine.NameKey) ?? string.Empty}\n");
|
||||
}
|
||||
|
||||
sw.Flush();
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace SabreTools.DatFiles.Formats
|
||||
/// <inheritdoc/>
|
||||
protected override List<string>? GetMissingRequiredFields(DatItem datItem)
|
||||
{
|
||||
var missingFields = new List<string>();
|
||||
List<string> missingFields = [];
|
||||
|
||||
switch (datItem)
|
||||
{
|
||||
|
||||
@@ -60,7 +60,7 @@ The softwaredb.xml file contains information about rom mapper types
|
||||
/// <inheritdoc/>
|
||||
protected override List<string>? GetMissingRequiredFields(DatItem datItem)
|
||||
{
|
||||
var missingFields = new List<string>();
|
||||
List<string> missingFields = [];
|
||||
|
||||
// Check item name
|
||||
if (string.IsNullOrEmpty(datItem.GetName()))
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace SabreTools.DatFiles.Formats
|
||||
/// <inheritdoc/>
|
||||
protected override List<string>? GetMissingRequiredFields(DatItem datItem)
|
||||
{
|
||||
var missingFields = new List<string>();
|
||||
List<string> missingFields = [];
|
||||
|
||||
// Check item name
|
||||
if (string.IsNullOrEmpty(datItem.GetName()))
|
||||
|
||||
@@ -406,11 +406,11 @@ namespace SabreTools.DatFiles.Formats
|
||||
|
||||
// If we have a different game and we're not at the start of the list, output the end of last item
|
||||
if (lastgame != null && !string.Equals(lastgame, datItem.GetFieldValue<Machine>(DatItem.MachineKey)!.GetStringFieldValue(Models.Metadata.Machine.NameKey), StringComparison.OrdinalIgnoreCase))
|
||||
SabreJSON.WriteEndGame(jtw);
|
||||
WriteEndGame(jtw);
|
||||
|
||||
// If we have a new game, output the beginning of the new item
|
||||
if (lastgame == null || !string.Equals(lastgame, datItem.GetFieldValue<Machine>(DatItem.MachineKey)!.GetStringFieldValue(Models.Metadata.Machine.NameKey), StringComparison.OrdinalIgnoreCase))
|
||||
SabreJSON.WriteStartGame(jtw, datItem);
|
||||
WriteStartGame(jtw, datItem);
|
||||
|
||||
// Check for a "null" item
|
||||
datItem = ProcessNullifiedItem(datItem);
|
||||
@@ -425,7 +425,7 @@ namespace SabreTools.DatFiles.Formats
|
||||
}
|
||||
|
||||
// Write the file footer out
|
||||
SabreJSON.WriteFooter(jtw);
|
||||
WriteFooter(jtw);
|
||||
|
||||
logger.User($"'{outfile}' written!{Environment.NewLine}");
|
||||
jtw.Close();
|
||||
@@ -473,42 +473,40 @@ namespace SabreTools.DatFiles.Formats
|
||||
foreach (string key in ItemsDB.SortedKeys)
|
||||
{
|
||||
// If this machine doesn't contain any writable items, skip
|
||||
var items = ItemsDB.GetItemsForBucket(key, filter: true);
|
||||
if (items == null || !ContainsWritable(items))
|
||||
var itemsDict = ItemsDB.GetItemsForBucket(key, filter: true);
|
||||
if (itemsDict == null || !ContainsWritable(itemsDict))
|
||||
continue;
|
||||
|
||||
// Resolve the names in the block
|
||||
items = [.. DatItem.ResolveNamesDB([.. items])];
|
||||
var items = DatItem.ResolveNamesDB([.. itemsDict]);
|
||||
|
||||
for (int index = 0; index < items.Length; index++)
|
||||
foreach (var kvp in items)
|
||||
{
|
||||
var datItem = items[index];
|
||||
|
||||
// Get the machine for the item
|
||||
var machine = ItemsDB.GetMachineForItem(datItem.Item1);
|
||||
var machine = ItemsDB.GetMachineForItem(kvp.Key);
|
||||
|
||||
// If we have a different game and we're not at the start of the list, output the end of last item
|
||||
if (lastgame != null && !string.Equals(lastgame, machine.Item2!.GetStringFieldValue(Models.Metadata.Machine.NameKey), StringComparison.OrdinalIgnoreCase))
|
||||
SabreJSON.WriteEndGame(jtw);
|
||||
if (lastgame != null && !string.Equals(lastgame, machine.Value!.GetStringFieldValue(Models.Metadata.Machine.NameKey), StringComparison.OrdinalIgnoreCase))
|
||||
WriteEndGame(jtw);
|
||||
|
||||
// If we have a new game, output the beginning of the new item
|
||||
if (lastgame == null || !string.Equals(lastgame, machine.Item2!.GetStringFieldValue(Models.Metadata.Machine.NameKey), StringComparison.OrdinalIgnoreCase))
|
||||
WriteStartGameDB(jtw, datItem);
|
||||
if (lastgame == null || !string.Equals(lastgame, machine.Value!.GetStringFieldValue(Models.Metadata.Machine.NameKey), StringComparison.OrdinalIgnoreCase))
|
||||
WriteStartGame(jtw, kvp.Value);
|
||||
|
||||
// Check for a "null" item
|
||||
datItem = ProcessNullifiedItem(datItem);
|
||||
var datItem = ProcessNullifiedItem(kvp);
|
||||
|
||||
// Write out the item if we're not ignoring
|
||||
if (!ShouldIgnore(datItem, ignoreblanks))
|
||||
WriteDatItemDB(jtw, datItem);
|
||||
if (!ShouldIgnore(datItem.Value, ignoreblanks))
|
||||
WriteDatItem(jtw, datItem.Value);
|
||||
|
||||
// Set the new data to compare against
|
||||
lastgame = machine.Item2!.GetStringFieldValue(Models.Metadata.Machine.NameKey);
|
||||
lastgame = machine.Value!.GetStringFieldValue(Models.Metadata.Machine.NameKey);
|
||||
}
|
||||
}
|
||||
|
||||
// Write the file footer out
|
||||
SabreJSON.WriteFooter(jtw);
|
||||
WriteFooter(jtw);
|
||||
|
||||
logger.User($"'{outfile}' written!{Environment.NewLine}");
|
||||
jtw.Close();
|
||||
@@ -567,34 +565,6 @@ namespace SabreTools.DatFiles.Formats
|
||||
jtw.Flush();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write out Game start using the supplied JsonTextWriter
|
||||
/// </summary>
|
||||
/// <param name="jtw">JsonTextWriter to output to</param>
|
||||
/// <param name="datItem">DatItem object to be output</param>
|
||||
private void WriteStartGameDB(JsonTextWriter jtw, (long, DatItem) datItem)
|
||||
{
|
||||
// Get the machine for the item
|
||||
var machine = ItemsDB.GetMachineForItem(datItem.Item1);
|
||||
|
||||
// No game should start with a path separator
|
||||
if (!string.IsNullOrEmpty(machine.Item2!.GetStringFieldValue(Models.Metadata.Machine.NameKey)))
|
||||
machine.Item2!.SetFieldValue<string?>(Models.Metadata.Machine.NameKey, machine.Item2!.GetStringFieldValue(Models.Metadata.Machine.NameKey)!.TrimStart(Path.DirectorySeparatorChar));
|
||||
|
||||
// Build the state
|
||||
jtw.WriteStartObject();
|
||||
|
||||
// Write the Machine
|
||||
jtw.WritePropertyName("machine");
|
||||
JsonSerializer js = new() { Formatting = Formatting.Indented };
|
||||
js.Serialize(jtw, machine.Item2!);
|
||||
|
||||
jtw.WritePropertyName("items");
|
||||
jtw.WriteStartArray();
|
||||
|
||||
jtw.Flush();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write out Game end using the supplied JsonTextWriter
|
||||
/// </summary>
|
||||
@@ -634,30 +604,6 @@ namespace SabreTools.DatFiles.Formats
|
||||
jtw.Flush();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write out DatItem using the supplied JsonTextWriter
|
||||
/// </summary>
|
||||
/// <param name="jtw">JsonTextWriter to output to</param>
|
||||
/// <param name="datItem">DatItem object to be output</param>
|
||||
private void WriteDatItemDB(JsonTextWriter jtw, (long, DatItem) datItem)
|
||||
{
|
||||
// Pre-process the item name
|
||||
ProcessItemNameDB(datItem, true);
|
||||
|
||||
// Build the state
|
||||
jtw.WriteStartObject();
|
||||
|
||||
// Write the DatItem
|
||||
jtw.WritePropertyName("datitem");
|
||||
JsonSerializer js = new() { ContractResolver = new BaseFirstContractResolver(), Formatting = Formatting.Indented };
|
||||
js.Serialize(jtw, datItem.Item2);
|
||||
|
||||
// End item
|
||||
jtw.WriteEndObject();
|
||||
|
||||
jtw.Flush();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write out DAT footer using the supplied JsonTextWriter
|
||||
/// </summary>
|
||||
|
||||
@@ -303,37 +303,35 @@ namespace SabreTools.DatFiles.Formats
|
||||
foreach (string key in ItemsDB.SortedKeys)
|
||||
{
|
||||
// If this machine doesn't contain any writable items, skip
|
||||
var items = ItemsDB.GetItemsForBucket(key, filter: true);
|
||||
if (items == null || !ContainsWritable(items))
|
||||
var itemsDict = ItemsDB.GetItemsForBucket(key, filter: true);
|
||||
if (itemsDict == null || !ContainsWritable(itemsDict))
|
||||
continue;
|
||||
|
||||
// Resolve the names in the block
|
||||
items = [.. DatItem.ResolveNamesDB([.. items])];
|
||||
var items = DatItem.ResolveNamesDB([.. itemsDict]);
|
||||
|
||||
for (int index = 0; index < items.Length; index++)
|
||||
foreach (var kvp in items)
|
||||
{
|
||||
var datItem = items[index];
|
||||
|
||||
// Get the machine for the item
|
||||
var machine = ItemsDB.GetMachineForItem(datItem.Item1);
|
||||
var machine = ItemsDB.GetMachineForItem(kvp.Key);
|
||||
|
||||
// If we have a different game and we're not at the start of the list, output the end of last item
|
||||
if (lastgame != null && !string.Equals(lastgame, machine.Item2!.GetStringFieldValue(Models.Metadata.Machine.NameKey), StringComparison.OrdinalIgnoreCase))
|
||||
if (lastgame != null && !string.Equals(lastgame, machine.Value!.GetStringFieldValue(Models.Metadata.Machine.NameKey), StringComparison.OrdinalIgnoreCase))
|
||||
WriteEndGame(xtw);
|
||||
|
||||
// If we have a new game, output the beginning of the new item
|
||||
if (lastgame == null || !string.Equals(lastgame, machine.Item2!.GetStringFieldValue(Models.Metadata.Machine.NameKey), StringComparison.OrdinalIgnoreCase))
|
||||
WriteStartGameDB(xtw, datItem);
|
||||
if (lastgame == null || !string.Equals(lastgame, machine.Value!.GetStringFieldValue(Models.Metadata.Machine.NameKey), StringComparison.OrdinalIgnoreCase))
|
||||
WriteStartGame(xtw, kvp.Value);
|
||||
|
||||
// Check for a "null" item
|
||||
datItem = ProcessNullifiedItem(datItem);
|
||||
var datItem = ProcessNullifiedItem(kvp);
|
||||
|
||||
// Write out the item if we're not ignoring
|
||||
if (!ShouldIgnore(datItem, ignoreblanks))
|
||||
WriteDatItemDB(xtw, datItem);
|
||||
if (!ShouldIgnore(datItem.Value, ignoreblanks))
|
||||
WriteDatItem(xtw, datItem.Value);
|
||||
|
||||
// Set the new data to compare against
|
||||
lastgame = machine.Item2!.GetStringFieldValue(Models.Metadata.Machine.NameKey);
|
||||
lastgame = machine.Value!.GetStringFieldValue(Models.Metadata.Machine.NameKey);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -397,31 +395,6 @@ namespace SabreTools.DatFiles.Formats
|
||||
xtw.Flush();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write out Game start using the supplied StreamWriter
|
||||
/// </summary>
|
||||
/// <param name="xtw">XmlTextWriter to output to</param>
|
||||
/// <param name="datItem">DatItem object to be output</param>
|
||||
private void WriteStartGameDB(XmlTextWriter xtw, (long, DatItem) datItem)
|
||||
{
|
||||
// Get the machine for the item
|
||||
var machine = ItemsDB.GetMachineForItem(datItem.Item1);
|
||||
|
||||
// No game should start with a path separator
|
||||
machine.Item2!.SetFieldValue<string?>(Models.Metadata.Machine.NameKey, machine.Item2!.GetStringFieldValue(Models.Metadata.Machine.NameKey)?.TrimStart(Path.DirectorySeparatorChar) ?? string.Empty);
|
||||
|
||||
// Write the machine
|
||||
xtw.WriteStartElement("directory");
|
||||
XmlSerializer xs = new(typeof(Machine));
|
||||
XmlSerializerNamespaces ns = new();
|
||||
ns.Add("", "");
|
||||
xs.Serialize(xtw, machine.Item2, ns);
|
||||
|
||||
xtw.WriteStartElement("files");
|
||||
|
||||
xtw.Flush();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write out Game start using the supplied StreamWriter
|
||||
/// </summary>
|
||||
@@ -456,25 +429,6 @@ namespace SabreTools.DatFiles.Formats
|
||||
xtw.Flush();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write out DatItem using the supplied StreamWriter
|
||||
/// </summary>
|
||||
/// <param name="xtw">XmlTextWriter to output to</param>
|
||||
/// <param name="datItem">DatItem object to be output</param>
|
||||
private void WriteDatItemDB(XmlTextWriter xtw, (long, DatItem) datItem)
|
||||
{
|
||||
// Pre-process the item name
|
||||
ProcessItemNameDB(datItem, true);
|
||||
|
||||
// Write the DatItem
|
||||
XmlSerializer xs = new(typeof(DatItem));
|
||||
XmlSerializerNamespaces ns = new();
|
||||
ns.Add("", "");
|
||||
xs.Serialize(xtw, datItem.Item2, ns);
|
||||
|
||||
xtw.Flush();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write out DAT footer using the supplied StreamWriter
|
||||
/// </summary>
|
||||
|
||||
@@ -54,7 +54,7 @@ namespace SabreTools.DatFiles.Formats
|
||||
/// <inheritdoc/>
|
||||
protected override List<string>? GetMissingRequiredFields(DatItem datItem)
|
||||
{
|
||||
var missingFields = new List<string>();
|
||||
List<string> missingFields = [];
|
||||
|
||||
// Check item name
|
||||
if (string.IsNullOrEmpty(datItem.GetName()))
|
||||
|
||||
@@ -96,7 +96,7 @@ namespace SabreTools.DatFiles.Formats
|
||||
/// <inheritdoc/>
|
||||
protected override List<string>? GetMissingRequiredFields(DatItem datItem)
|
||||
{
|
||||
var missingFields = new List<string>();
|
||||
List<string> missingFields = [];
|
||||
|
||||
switch (datItem)
|
||||
{
|
||||
|
||||
@@ -846,7 +846,7 @@ namespace SabreTools.DatFiles
|
||||
#endif
|
||||
|
||||
// Filter all items in the current key
|
||||
var newItems = new List<DatItem>();
|
||||
List<DatItem> newItems = [];
|
||||
foreach (var item in items)
|
||||
{
|
||||
if (item.PassesFilter(filterRunner))
|
||||
@@ -1242,15 +1242,16 @@ namespace SabreTools.DatFiles
|
||||
foreach (string machine in machines)
|
||||
{
|
||||
// If the machine doesn't have items, we continue
|
||||
if (this[machine] == null || this[machine]!.Count == 0)
|
||||
var datItems = this[machine];
|
||||
if (datItems == null || datItems.Count == 0)
|
||||
continue;
|
||||
|
||||
// If the machine (is/is not) a device, we want to continue
|
||||
if (dev ^ (this[machine]![0].GetFieldValue<Machine>(DatItem.MachineKey)!.GetBoolFieldValue(Models.Metadata.Machine.IsDeviceKey) == true))
|
||||
if (dev ^ (datItems[0].GetFieldValue<Machine>(DatItem.MachineKey)!.GetBoolFieldValue(Models.Metadata.Machine.IsDeviceKey) == true))
|
||||
continue;
|
||||
|
||||
// Get all device reference names from the current machine
|
||||
List<string?> deviceReferences = this[machine]!
|
||||
List<string?> deviceReferences = datItems
|
||||
.FindAll(i => i is DeviceRef)
|
||||
.ConvertAll(i => i as DeviceRef)
|
||||
.ConvertAll(dr => dr!.GetName())
|
||||
@@ -1258,7 +1259,7 @@ namespace SabreTools.DatFiles
|
||||
.ToList();
|
||||
|
||||
// Get all slot option names from the current machine
|
||||
List<string?> slotOptions = this[machine]!
|
||||
List<string?> slotOptions = datItems
|
||||
.FindAll(i => i is Slot)
|
||||
.ConvertAll(i => i as Slot)
|
||||
.FindAll(s => s!.SlotOptionsSpecified)
|
||||
@@ -1274,13 +1275,13 @@ namespace SabreTools.DatFiles
|
||||
var newDeviceReferences = new HashSet<string>();
|
||||
foreach (string? deviceReference in deviceReferences)
|
||||
{
|
||||
// If the machine doesn't exist then we continue
|
||||
if (deviceReference == null || this[deviceReference] == null || this[deviceReference]!.Count == 0)
|
||||
// If the device reference is missing
|
||||
if (string.IsNullOrEmpty(deviceReference))
|
||||
continue;
|
||||
|
||||
// Add to the list of new device reference names
|
||||
var devItems = this[deviceReference];
|
||||
if (devItems == null)
|
||||
var devItems = this[deviceReference!];
|
||||
if (devItems == null || devItems.Count == 0)
|
||||
continue;
|
||||
|
||||
newDeviceReferences.UnionWith(devItems
|
||||
@@ -1288,11 +1289,11 @@ namespace SabreTools.DatFiles
|
||||
.ConvertAll(i => (i as DeviceRef)!.GetName()!));
|
||||
|
||||
// Set new machine information and add to the current machine
|
||||
DatItem copyFrom = this[machine]![0];
|
||||
DatItem copyFrom = datItems[0];
|
||||
foreach (DatItem item in devItems)
|
||||
{
|
||||
// If the parent machine doesn't already contain this item, add it
|
||||
if (!this[machine]!.Exists(i => i.GetStringFieldValue(Models.Metadata.DatItem.TypeKey) == item.GetStringFieldValue(Models.Metadata.DatItem.TypeKey) && i.GetName() == item.GetName()))
|
||||
if (!datItems.Exists(i => i.GetStringFieldValue(Models.Metadata.DatItem.TypeKey) == item.GetStringFieldValue(Models.Metadata.DatItem.TypeKey) && i.GetName() == item.GetName()))
|
||||
{
|
||||
// Set that we found new items
|
||||
foundnew = true;
|
||||
@@ -1312,7 +1313,7 @@ namespace SabreTools.DatFiles
|
||||
{
|
||||
var deviceRef = new DeviceRef();
|
||||
deviceRef.SetName(deviceReference);
|
||||
this[machine]!.Add(deviceRef);
|
||||
datItems.Add(deviceRef);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1324,13 +1325,14 @@ namespace SabreTools.DatFiles
|
||||
var newSlotOptions = new HashSet<string>();
|
||||
foreach (string? slotOption in slotOptions)
|
||||
{
|
||||
// If the slot option is missing
|
||||
if (string.IsNullOrEmpty(slotOption))
|
||||
// If the machine doesn't exist then we continue
|
||||
if (slotOption == null || this[slotOption] == null || this[slotOption]!.Count == 0)
|
||||
continue;
|
||||
|
||||
// Add to the list of new slot option names
|
||||
var slotItems = this[slotOption];
|
||||
if (slotItems == null)
|
||||
var slotItems = this[slotOption!];
|
||||
if (slotItems == null || slotItems.Count == 0)
|
||||
continue;
|
||||
|
||||
newSlotOptions.UnionWith(slotItems
|
||||
@@ -1340,11 +1342,11 @@ namespace SabreTools.DatFiles
|
||||
.Select(o => o.GetStringFieldValue(Models.Metadata.SlotOption.DevNameKey)!));
|
||||
|
||||
// Set new machine information and add to the current machine
|
||||
DatItem copyFrom = this[machine]![0];
|
||||
DatItem copyFrom = datItems[0];
|
||||
foreach (DatItem item in slotItems)
|
||||
{
|
||||
// If the parent machine doesn't already contain this item, add it
|
||||
if (!this[machine]!.Exists(i => i.GetStringFieldValue(Models.Metadata.DatItem.TypeKey) == item.GetStringFieldValue(Models.Metadata.DatItem.TypeKey) && i.GetName() == item.GetName()))
|
||||
if (!datItems.Exists(i => i.GetStringFieldValue(Models.Metadata.DatItem.TypeKey) == item.GetStringFieldValue(Models.Metadata.DatItem.TypeKey) && i.GetName() == item.GetName()))
|
||||
{
|
||||
// Set that we found new items
|
||||
foundnew = true;
|
||||
@@ -1368,7 +1370,7 @@ namespace SabreTools.DatFiles
|
||||
var slotItem = new Slot();
|
||||
slotItem.SetFieldValue<SlotOption[]?>(Models.Metadata.Slot.SlotOptionKey, [slotOptionItem]);
|
||||
|
||||
this[machine]!.Add(slotItem);
|
||||
datItems.Add(slotItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user