mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Remove nearly all explict fields
This commit is contained in:
@@ -296,7 +296,7 @@ namespace SabreTools.Filtering
|
||||
{
|
||||
if (configuration.ConditionsSpecified)
|
||||
{
|
||||
foreach (Condition subCondition in configuration.Conditions!)
|
||||
foreach (Condition subCondition in configuration.GetFieldValue<Condition[]?>(Models.Metadata.Configuration.ConditionKey)!)
|
||||
{
|
||||
RemoveFields(subCondition);
|
||||
}
|
||||
@@ -304,7 +304,7 @@ namespace SabreTools.Filtering
|
||||
|
||||
if (configuration.LocationsSpecified)
|
||||
{
|
||||
foreach (ConfLocation subLocation in configuration.Locations!)
|
||||
foreach (ConfLocation subLocation in configuration.GetFieldValue<ConfLocation[]?>(Models.Metadata.Configuration.ConfLocationKey)!)
|
||||
{
|
||||
RemoveFields(subLocation);
|
||||
}
|
||||
@@ -312,7 +312,7 @@ namespace SabreTools.Filtering
|
||||
|
||||
if (configuration.SettingsSpecified)
|
||||
{
|
||||
foreach (ConfSetting subSetting in configuration.Settings!)
|
||||
foreach (ConfSetting subSetting in configuration.GetFieldValue<ConfSetting[]?>(Models.Metadata.Configuration.ConfSettingKey)!)
|
||||
{
|
||||
RemoveFields(subSetting as DatItem);
|
||||
}
|
||||
@@ -327,7 +327,7 @@ namespace SabreTools.Filtering
|
||||
{
|
||||
if (confsetting.ConditionsSpecified)
|
||||
{
|
||||
foreach (Condition subCondition in confsetting.Conditions!)
|
||||
foreach (Condition subCondition in confsetting.GetFieldValue<Condition[]?>(Models.Metadata.ConfSetting.ConditionKey)!)
|
||||
{
|
||||
RemoveFields(subCondition);
|
||||
}
|
||||
@@ -342,7 +342,7 @@ namespace SabreTools.Filtering
|
||||
{
|
||||
if (device.ExtensionsSpecified)
|
||||
{
|
||||
foreach (Extension subExtension in device.Extensions!)
|
||||
foreach (Extension subExtension in device.GetFieldValue<Extension[]?>(Models.Metadata.Device.ExtensionKey)!)
|
||||
{
|
||||
RemoveFields(subExtension);
|
||||
}
|
||||
@@ -350,7 +350,7 @@ namespace SabreTools.Filtering
|
||||
|
||||
if (device.InstancesSpecified)
|
||||
{
|
||||
foreach (Instance subInstance in device.Instances!)
|
||||
foreach (Instance subInstance in device.GetFieldValue<Instance[]?>(Models.Metadata.Device.InstanceKey)!)
|
||||
{
|
||||
RemoveFields(subInstance);
|
||||
}
|
||||
@@ -365,7 +365,7 @@ namespace SabreTools.Filtering
|
||||
{
|
||||
if (dipSwitch.ConditionsSpecified)
|
||||
{
|
||||
foreach (Condition subCondition in dipSwitch.Conditions!)
|
||||
foreach (Condition subCondition in dipSwitch.GetFieldValue<Condition[]?>(Models.Metadata.DipSwitch.ConditionKey)!)
|
||||
{
|
||||
RemoveFields(subCondition);
|
||||
}
|
||||
@@ -373,7 +373,7 @@ namespace SabreTools.Filtering
|
||||
|
||||
if (dipSwitch.LocationsSpecified)
|
||||
{
|
||||
foreach (DipLocation subLocation in dipSwitch.Locations!)
|
||||
foreach (DipLocation subLocation in dipSwitch.GetFieldValue<DipLocation[]?>(Models.Metadata.DipSwitch.DipLocationKey)!)
|
||||
{
|
||||
RemoveFields(subLocation);
|
||||
}
|
||||
@@ -381,14 +381,14 @@ namespace SabreTools.Filtering
|
||||
|
||||
if (dipSwitch.ValuesSpecified)
|
||||
{
|
||||
foreach (DipValue subValue in dipSwitch.Values!)
|
||||
foreach (DipValue subValue in dipSwitch.GetFieldValue<DipValue[]?>(Models.Metadata.DipSwitch.DipValueKey)!)
|
||||
{
|
||||
RemoveFields(subValue as DatItem);
|
||||
}
|
||||
}
|
||||
|
||||
if (dipSwitch.PartSpecified)
|
||||
RemoveFields(dipSwitch.Part! as DatItem);
|
||||
RemoveFields(dipSwitch.GetFieldValue<Part?>("PART")! as DatItem);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -399,7 +399,7 @@ namespace SabreTools.Filtering
|
||||
{
|
||||
if (dipValue.ConditionsSpecified)
|
||||
{
|
||||
foreach (Condition subCondition in dipValue.Conditions!)
|
||||
foreach (Condition subCondition in dipValue.GetFieldValue<Condition[]?>(Models.Metadata.DipValue.ConditionKey)!)
|
||||
{
|
||||
RemoveFields(subCondition);
|
||||
}
|
||||
@@ -413,10 +413,10 @@ namespace SabreTools.Filtering
|
||||
private void RemoveFields(Disk disk)
|
||||
{
|
||||
if (disk.DiskAreaSpecified)
|
||||
RemoveFields(disk.DiskArea);
|
||||
RemoveFields(disk.GetFieldValue<DiskArea?>("DISKAREA")! as DatItem);
|
||||
|
||||
if (disk.PartSpecified)
|
||||
RemoveFields(disk.Part! as DatItem);
|
||||
RemoveFields(disk.GetFieldValue<Part?>("PART")! as DatItem);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -427,7 +427,7 @@ namespace SabreTools.Filtering
|
||||
{
|
||||
if (input.ControlsSpecified)
|
||||
{
|
||||
foreach (Control subControl in input.Controls!)
|
||||
foreach (Control subControl in input.GetFieldValue<Control[]?>(Models.Metadata.Input.ControlKey)!)
|
||||
{
|
||||
RemoveFields(subControl);
|
||||
}
|
||||
@@ -442,7 +442,7 @@ namespace SabreTools.Filtering
|
||||
{
|
||||
if (part.FeaturesSpecified)
|
||||
{
|
||||
foreach (PartFeature subPartFeature in part.Features!)
|
||||
foreach (PartFeature subPartFeature in part.GetFieldValue<PartFeature[]?>(Models.Metadata.Part.FeatureKey)!)
|
||||
{
|
||||
RemoveFields(subPartFeature);
|
||||
}
|
||||
@@ -457,7 +457,7 @@ namespace SabreTools.Filtering
|
||||
{
|
||||
if (port.AnalogsSpecified)
|
||||
{
|
||||
foreach (Analog subAnalog in port.Analogs!)
|
||||
foreach (Analog subAnalog in port.GetFieldValue<Analog[]?>(Models.Metadata.Port.AnalogKey)!)
|
||||
{
|
||||
RemoveFields(subAnalog);
|
||||
}
|
||||
@@ -471,10 +471,10 @@ namespace SabreTools.Filtering
|
||||
private void RemoveFields(Rom rom)
|
||||
{
|
||||
if (rom.DataAreaSpecified)
|
||||
RemoveFields(rom.DataArea!);
|
||||
RemoveFields(rom.GetFieldValue<DataArea?>("DATAAREA")!);
|
||||
|
||||
if (rom.PartSpecified)
|
||||
RemoveFields(rom.Part! as DatItem);
|
||||
RemoveFields(rom.GetFieldValue<Part?>("PART")! as DatItem);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -485,7 +485,7 @@ namespace SabreTools.Filtering
|
||||
{
|
||||
if (slot.SlotOptionsSpecified)
|
||||
{
|
||||
foreach (SlotOption subSlotOption in slot.SlotOptions!)
|
||||
foreach (SlotOption subSlotOption in slot.GetFieldValue<SlotOption[]?>(Models.Metadata.Slot.SlotOptionKey)!)
|
||||
{
|
||||
RemoveFields(subSlotOption);
|
||||
}
|
||||
|
||||
@@ -107,14 +107,14 @@ namespace SabreTools.Filtering
|
||||
{
|
||||
if (datItemFields.Contains(Models.Metadata.Disk.MD5Key))
|
||||
{
|
||||
if (string.IsNullOrEmpty(disk.MD5) && !string.IsNullOrEmpty(newItem.MD5))
|
||||
disk.MD5 = newItem.MD5;
|
||||
if (string.IsNullOrEmpty(disk.GetFieldValue<string?>(Models.Metadata.Disk.MD5Key)) && !string.IsNullOrEmpty(newItem.GetFieldValue<string?>(Models.Metadata.Disk.MD5Key)))
|
||||
disk.SetFieldValue<string?>(Models.Metadata.Disk.MD5Key, newItem.GetFieldValue<string?>(Models.Metadata.Disk.MD5Key));
|
||||
}
|
||||
|
||||
if (datItemFields.Contains(Models.Metadata.Disk.SHA1Key))
|
||||
{
|
||||
if (string.IsNullOrEmpty(disk.SHA1) && !string.IsNullOrEmpty(newItem.SHA1))
|
||||
disk.SHA1 = newItem.SHA1;
|
||||
if (string.IsNullOrEmpty(disk.GetFieldValue<string?>(Models.Metadata.Disk.SHA1Key)) && !string.IsNullOrEmpty(newItem.GetFieldValue<string?>(Models.Metadata.Disk.SHA1Key)))
|
||||
disk.SetFieldValue<string?>(Models.Metadata.Disk.SHA1Key, newItem.GetFieldValue<string?>(Models.Metadata.Disk.SHA1Key));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,26 +128,26 @@ namespace SabreTools.Filtering
|
||||
{
|
||||
if (datItemFields.Contains(Models.Metadata.Media.MD5Key))
|
||||
{
|
||||
if (string.IsNullOrEmpty(media.MD5) && !string.IsNullOrEmpty(newItem.MD5))
|
||||
media.MD5 = newItem.MD5;
|
||||
if (string.IsNullOrEmpty(media.GetFieldValue<string?>(Models.Metadata.Media.MD5Key)) && !string.IsNullOrEmpty(newItem.GetFieldValue<string?>(Models.Metadata.Media.MD5Key)))
|
||||
media.SetFieldValue<string?>(Models.Metadata.Media.MD5Key, newItem.GetFieldValue<string?>(Models.Metadata.Media.MD5Key));
|
||||
}
|
||||
|
||||
if (datItemFields.Contains(Models.Metadata.Media.SHA1Key))
|
||||
{
|
||||
if (string.IsNullOrEmpty(media.SHA1) && !string.IsNullOrEmpty(newItem.SHA1))
|
||||
media.SHA1 = newItem.SHA1;
|
||||
if (string.IsNullOrEmpty(media.GetFieldValue<string?>(Models.Metadata.Media.SHA1Key)) && !string.IsNullOrEmpty(newItem.GetFieldValue<string?>(Models.Metadata.Media.SHA1Key)))
|
||||
media.SetFieldValue<string?>(Models.Metadata.Media.SHA1Key, newItem.GetFieldValue<string?>(Models.Metadata.Media.SHA1Key));
|
||||
}
|
||||
|
||||
if (datItemFields.Contains(Models.Metadata.Media.SHA256Key))
|
||||
{
|
||||
if (string.IsNullOrEmpty(media.SHA256) && !string.IsNullOrEmpty(newItem.SHA256))
|
||||
media.SHA256 = newItem.SHA256;
|
||||
if (string.IsNullOrEmpty(media.GetFieldValue<string?>(Models.Metadata.Media.SHA256Key)) && !string.IsNullOrEmpty(newItem.GetFieldValue<string?>(Models.Metadata.Media.SHA256Key)))
|
||||
media.SetFieldValue<string?>(Models.Metadata.Media.SHA256Key, newItem.GetFieldValue<string?>(Models.Metadata.Media.SHA256Key));
|
||||
}
|
||||
|
||||
if (datItemFields.Contains(Models.Metadata.Media.SpamSumKey))
|
||||
{
|
||||
if (string.IsNullOrEmpty(media.SpamSum) && !string.IsNullOrEmpty(newItem.SpamSum))
|
||||
media.SpamSum = newItem.SpamSum;
|
||||
if (string.IsNullOrEmpty(media.GetFieldValue<string?>(Models.Metadata.Media.SpamSumKey)) && !string.IsNullOrEmpty(newItem.GetFieldValue<string?>(Models.Metadata.Media.SpamSumKey)))
|
||||
media.SetFieldValue<string?>(Models.Metadata.Media.SpamSumKey, newItem.GetFieldValue<string?>(Models.Metadata.Media.SpamSumKey));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,44 +161,44 @@ namespace SabreTools.Filtering
|
||||
{
|
||||
if (datItemFields.Contains(Models.Metadata.Rom.CRCKey))
|
||||
{
|
||||
if (string.IsNullOrEmpty(rom.CRC) && !string.IsNullOrEmpty(newItem.CRC))
|
||||
rom.CRC = newItem.CRC;
|
||||
if (string.IsNullOrEmpty(rom.GetFieldValue<string?>(Models.Metadata.Rom.CRCKey)) && !string.IsNullOrEmpty(newItem.GetFieldValue<string?>(Models.Metadata.Rom.CRCKey)))
|
||||
rom.SetFieldValue<string?>(Models.Metadata.Rom.CRCKey, newItem.GetFieldValue<string?>(Models.Metadata.Rom.CRCKey));
|
||||
}
|
||||
|
||||
if (datItemFields.Contains(Models.Metadata.Rom.MD5Key))
|
||||
{
|
||||
if (string.IsNullOrEmpty(rom.MD5) && !string.IsNullOrEmpty(newItem.MD5))
|
||||
rom.MD5 = newItem.MD5;
|
||||
if (string.IsNullOrEmpty(rom.GetFieldValue<string?>(Models.Metadata.Rom.MD5Key)) && !string.IsNullOrEmpty(newItem.GetFieldValue<string?>(Models.Metadata.Rom.MD5Key)))
|
||||
rom.SetFieldValue<string?>(Models.Metadata.Rom.MD5Key, newItem.GetFieldValue<string?>(Models.Metadata.Rom.MD5Key));
|
||||
}
|
||||
|
||||
if (datItemFields.Contains(Models.Metadata.Rom.SHA1Key))
|
||||
{
|
||||
if (string.IsNullOrEmpty(rom.SHA1) && !string.IsNullOrEmpty(newItem.SHA1))
|
||||
rom.SHA1 = newItem.SHA1;
|
||||
if (string.IsNullOrEmpty(rom.GetFieldValue<string?>(Models.Metadata.Rom.SHA1Key)) && !string.IsNullOrEmpty(newItem.GetFieldValue<string?>(Models.Metadata.Rom.SHA1Key)))
|
||||
rom.SetFieldValue<string?>(Models.Metadata.Rom.SHA1Key, newItem.GetFieldValue<string?>(Models.Metadata.Rom.SHA1Key));
|
||||
}
|
||||
|
||||
if (datItemFields.Contains(Models.Metadata.Rom.SHA256Key))
|
||||
{
|
||||
if (string.IsNullOrEmpty(rom.SHA256) && !string.IsNullOrEmpty(newItem.SHA256))
|
||||
rom.SHA256 = newItem.SHA256;
|
||||
if (string.IsNullOrEmpty(rom.GetFieldValue<string?>(Models.Metadata.Rom.SHA256Key)) && !string.IsNullOrEmpty(newItem.GetFieldValue<string?>(Models.Metadata.Rom.SHA256Key)))
|
||||
rom.SetFieldValue<string?>(Models.Metadata.Rom.SHA256Key, newItem.GetFieldValue<string?>(Models.Metadata.Rom.SHA256Key));
|
||||
}
|
||||
|
||||
if (datItemFields.Contains(Models.Metadata.Rom.SHA384Key))
|
||||
{
|
||||
if (string.IsNullOrEmpty(rom.SHA384) && !string.IsNullOrEmpty(newItem.SHA384))
|
||||
rom.SHA384 = newItem.SHA384;
|
||||
if (string.IsNullOrEmpty(rom.GetFieldValue<string?>(Models.Metadata.Rom.SHA384Key)) && !string.IsNullOrEmpty(newItem.GetFieldValue<string?>(Models.Metadata.Rom.SHA384Key)))
|
||||
rom.SetFieldValue<string?>(Models.Metadata.Rom.SHA384Key, newItem.GetFieldValue<string?>(Models.Metadata.Rom.SHA384Key));
|
||||
}
|
||||
|
||||
if (datItemFields.Contains(Models.Metadata.Rom.SHA512Key))
|
||||
{
|
||||
if (string.IsNullOrEmpty(rom.SHA512) && !string.IsNullOrEmpty(newItem.SHA512))
|
||||
rom.SHA512 = newItem.SHA512;
|
||||
if (string.IsNullOrEmpty(rom.GetFieldValue<string?>(Models.Metadata.Rom.SHA512Key)) && !string.IsNullOrEmpty(newItem.GetFieldValue<string?>(Models.Metadata.Rom.SHA512Key)))
|
||||
rom.SetFieldValue<string?>(Models.Metadata.Rom.SHA512Key, newItem.GetFieldValue<string?>(Models.Metadata.Rom.SHA512Key));
|
||||
}
|
||||
|
||||
if (datItemFields.Contains(Models.Metadata.Rom.SpamSumKey))
|
||||
{
|
||||
if (string.IsNullOrEmpty(rom.SpamSum) && !string.IsNullOrEmpty(newItem.SpamSum))
|
||||
rom.SpamSum = newItem.SpamSum;
|
||||
if (string.IsNullOrEmpty(rom.GetFieldValue<string?>(Models.Metadata.Rom.SpamSumKey)) && !string.IsNullOrEmpty(newItem.GetFieldValue<string?>(Models.Metadata.Rom.SpamSumKey)))
|
||||
rom.SetFieldValue<string?>(Models.Metadata.Rom.SpamSumKey, newItem.GetFieldValue<string?>(Models.Metadata.Rom.SpamSumKey));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -310,8 +310,8 @@ namespace SabreTools.Filtering
|
||||
.Where(i => i.ItemType == ItemType.Slot)
|
||||
.Select(i => i as Slot)
|
||||
.Where(s => s!.SlotOptionsSpecified)
|
||||
.SelectMany(s => s!.SlotOptions!)
|
||||
.Select(so => so.DeviceName)
|
||||
.SelectMany(s => s!.GetFieldValue<SlotOption[]?>(Models.Metadata.Slot.SlotOptionKey)!)
|
||||
.Select(so => so.GetFieldValue<string?>(Models.Metadata.SlotOption.DevNameKey))
|
||||
.Distinct()
|
||||
.ToList();
|
||||
|
||||
@@ -384,8 +384,8 @@ namespace SabreTools.Filtering
|
||||
newSlotOptions.AddRange(slotItems
|
||||
.Where(i => i.ItemType == ItemType.Slot)
|
||||
.Where(s => (s as Slot)!.SlotOptionsSpecified)
|
||||
.SelectMany(s => (s as Slot)!.SlotOptions!)
|
||||
.Select(o => o.DeviceName!));
|
||||
.SelectMany(s => (s as Slot)!.GetFieldValue<SlotOption[]?>(Models.Metadata.Slot.SlotOptionKey)!)
|
||||
.Select(o => o.GetFieldValue<string?>(Models.Metadata.SlotOption.DevNameKey)!));
|
||||
|
||||
// Set new machine information and add to the current machine
|
||||
DatItem copyFrom = datFile.Items[machine]![0];
|
||||
@@ -409,7 +409,15 @@ namespace SabreTools.Filtering
|
||||
foreach (string slotOption in newSlotOptions.Distinct())
|
||||
{
|
||||
if (!slotOptions.Contains(slotOption))
|
||||
datFile.Items[machine]!.Add(new Slot() { SlotOptions = new List<SlotOption> { new SlotOption { DeviceName = slotOption } } });
|
||||
{
|
||||
var slotOptionItem = new SlotOption();
|
||||
slotOptionItem.SetFieldValue<string?>(Models.Metadata.SlotOption.DevNameKey, slotOption);
|
||||
|
||||
var slotItem = new Slot();
|
||||
slotItem.SetFieldValue<SlotOption[]?>(Models.Metadata.Slot.SlotOptionKey, [slotOptionItem]);
|
||||
|
||||
datFile.Items[machine]!.Add(slotItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -513,22 +521,23 @@ namespace SabreTools.Filtering
|
||||
if (item.ItemType == ItemType.Disk)
|
||||
{
|
||||
Disk disk = (item as Disk)!;
|
||||
string? mergeTag = disk.GetFieldValue<string?>(Models.Metadata.Disk.MergeKey);
|
||||
|
||||
// If the merge tag exists and the parent already contains it, skip
|
||||
if (disk.MergeTag != null && datFile.Items[parent!]!.Where(i => i.ItemType == ItemType.Disk).Select(i => (i as Disk)!.GetName()).Contains(disk.MergeTag))
|
||||
if (mergeTag != null && datFile.Items[parent!]!.Where(i => i.ItemType == ItemType.Disk).Select(i => (i as Disk)!.GetName()).Contains(mergeTag))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// If the merge tag exists but the parent doesn't contain it, add to parent
|
||||
else if (disk.MergeTag != null && !datFile.Items[parent!]!.Where(i => i.ItemType == ItemType.Disk).Select(i => (i as Disk)!.GetName()).Contains(disk.MergeTag))
|
||||
else if (mergeTag != null && !datFile.Items[parent!]!.Where(i => i.ItemType == ItemType.Disk).Select(i => (i as Disk)!.GetName()).Contains(mergeTag))
|
||||
{
|
||||
disk.CopyMachineInformation(copyFrom);
|
||||
datFile.Items.Add(parent!, disk);
|
||||
}
|
||||
|
||||
// If there is no merge tag, add to parent
|
||||
else if (disk.MergeTag == null)
|
||||
else if (mergeTag == null)
|
||||
{
|
||||
disk.CopyMachineInformation(copyFrom);
|
||||
datFile.Items.Add(parent!, disk);
|
||||
@@ -541,13 +550,13 @@ namespace SabreTools.Filtering
|
||||
Rom rom = (item as Rom)!;
|
||||
|
||||
// If the merge tag exists and the parent already contains it, skip
|
||||
if (rom.MergeTag != null && datFile.Items[parent!]!.Where(i => i.ItemType == ItemType.Rom).Select(i => (i as Rom)!.GetName()).Contains(rom.MergeTag))
|
||||
if (rom.GetFieldValue<string?>(Models.Metadata.Rom.MergeKey) != null && datFile.Items[parent!]!.Where(i => i.ItemType == ItemType.Rom).Select(i => (i as Rom)!.GetName()).Contains(rom.GetFieldValue<string?>(Models.Metadata.Rom.MergeKey)))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// If the merge tag exists but the parent doesn't contain it, add to subfolder of parent
|
||||
else if (rom.MergeTag != null && !datFile.Items[parent!]!.Where(i => i.ItemType == ItemType.Rom).Select(i => (i as Rom)!.GetName()).Contains(rom.MergeTag))
|
||||
else if (rom.GetFieldValue<string?>(Models.Metadata.Rom.MergeKey) != null && !datFile.Items[parent!]!.Where(i => i.ItemType == ItemType.Rom).Select(i => (i as Rom)!.GetName()).Contains(rom.GetFieldValue<string?>(Models.Metadata.Rom.MergeKey)))
|
||||
{
|
||||
if (subfolder)
|
||||
rom.SetName($"{rom.Machine.Name}\\{rom.GetName()}");
|
||||
|
||||
Reference in New Issue
Block a user