2021-02-01 12:11:32 -08:00
|
|
|
using System.Collections.Generic;
|
2021-02-03 09:07:29 -08:00
|
|
|
using System.Linq;
|
2024-03-05 03:04:47 -05:00
|
|
|
#if NET40_OR_GREATER || NETCOREAPP
|
2021-02-01 12:11:32 -08:00
|
|
|
using System.Threading.Tasks;
|
2024-03-05 03:04:47 -05:00
|
|
|
#endif
|
2021-02-01 12:11:32 -08:00
|
|
|
using SabreTools.Core;
|
2024-03-05 16:37:52 -05:00
|
|
|
using SabreTools.Core.Tools;
|
2021-02-01 12:11:32 -08:00
|
|
|
using SabreTools.DatFiles;
|
|
|
|
|
using SabreTools.DatItems;
|
2024-03-05 16:37:52 -05:00
|
|
|
using SabreTools.DatItems.Formats;
|
|
|
|
|
using SabreTools.Filter;
|
2021-01-29 22:54:16 -08:00
|
|
|
using SabreTools.Logging;
|
|
|
|
|
|
|
|
|
|
namespace SabreTools.Filtering
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Represents the removal operations that need to be performed on a set of items, usually a DAT
|
|
|
|
|
/// </summary>
|
2021-02-01 12:11:32 -08:00
|
|
|
public class Remover
|
2021-01-29 22:54:16 -08:00
|
|
|
{
|
2021-02-01 12:11:32 -08:00
|
|
|
#region Fields
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2024-03-05 16:37:52 -05:00
|
|
|
/// List of header fields to exclude from writing
|
2021-02-01 12:11:32 -08:00
|
|
|
/// </summary>
|
2024-03-05 16:37:52 -05:00
|
|
|
public List<string> HeaderFieldNames { get; } = [];
|
2021-02-01 12:11:32 -08:00
|
|
|
|
|
|
|
|
/// <summary>
|
2024-03-05 16:37:52 -05:00
|
|
|
/// List of machine fields to exclude from writing
|
2021-02-01 12:11:32 -08:00
|
|
|
/// </summary>
|
2024-03-05 16:37:52 -05:00
|
|
|
public List<string> MachineFieldNames { get; } = [];
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// List of fields to exclude from writing
|
|
|
|
|
/// </summary>
|
|
|
|
|
public Dictionary<string, List<string>> ItemFieldNames { get; } = [];
|
2021-02-01 12:11:32 -08:00
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2021-01-29 22:54:16 -08:00
|
|
|
#region Logging
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Logging object
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected Logger logger;
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Constructors
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Constructor
|
|
|
|
|
/// </summary>
|
|
|
|
|
public Remover()
|
|
|
|
|
{
|
|
|
|
|
logger = new Logger(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2021-02-01 12:11:32 -08:00
|
|
|
#region Population
|
2021-01-29 22:54:16 -08:00
|
|
|
|
2024-03-05 16:37:52 -05:00
|
|
|
/// <summary>
|
|
|
|
|
/// Populate the exclusion objects using a field name
|
|
|
|
|
/// </summary>
|
2024-03-05 17:17:40 -05:00
|
|
|
/// <param name="field">Field name</param>
|
2024-03-05 16:37:52 -05:00
|
|
|
public void PopulateExclusions(string field)
|
|
|
|
|
=> PopulateExclusionsFromList([field]);
|
|
|
|
|
|
2021-01-29 22:54:16 -08:00
|
|
|
/// <summary>
|
2021-02-01 12:11:32 -08:00
|
|
|
/// Populate the exclusion objects using a set of field names
|
2021-01-29 22:54:16 -08:00
|
|
|
/// </summary>
|
2021-02-01 12:11:32 -08:00
|
|
|
/// <param name="fields">List of field names</param>
|
2024-03-05 13:32:49 -05:00
|
|
|
public void PopulateExclusionsFromList(List<string>? fields)
|
2021-02-01 12:11:32 -08:00
|
|
|
{
|
|
|
|
|
// If the list is null or empty, just return
|
|
|
|
|
if (fields == null || fields.Count == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
2024-03-05 16:37:52 -05:00
|
|
|
var watch = new InternalStopwatch("Populating removals from list");
|
2021-02-03 09:07:29 -08:00
|
|
|
|
2021-02-01 12:11:32 -08:00
|
|
|
foreach (string field in fields)
|
2024-02-28 21:59:13 -05:00
|
|
|
{
|
2024-03-05 16:37:52 -05:00
|
|
|
bool removerSet = SetRemover(field);
|
|
|
|
|
if (!removerSet)
|
|
|
|
|
logger.Warning($"The value {field} did not match any known field names. Please check the wiki for more details on supported field names.");
|
|
|
|
|
}
|
2021-02-01 12:11:32 -08:00
|
|
|
|
2024-03-05 16:37:52 -05:00
|
|
|
watch.Stop();
|
|
|
|
|
}
|
2021-02-01 12:11:32 -08:00
|
|
|
|
2024-03-05 16:37:52 -05:00
|
|
|
/// <summary>
|
|
|
|
|
/// Set remover from a value
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="field">Key for the remover to be set</param>
|
|
|
|
|
private bool SetRemover(string field)
|
|
|
|
|
{
|
|
|
|
|
// If the key is null or empty, return false
|
|
|
|
|
if (string.IsNullOrEmpty(field))
|
|
|
|
|
return false;
|
2021-02-01 12:11:32 -08:00
|
|
|
|
2024-03-05 16:37:52 -05:00
|
|
|
// Get the parser pair out of it, if possible
|
2024-03-05 17:17:40 -05:00
|
|
|
(string? type, string? key) = FilterParser.ParseFilterId(field);
|
|
|
|
|
if (type == null || key == null)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
switch (type)
|
2024-03-05 16:37:52 -05:00
|
|
|
{
|
2024-03-05 17:17:40 -05:00
|
|
|
case Models.Metadata.MetadataFile.HeaderKey:
|
|
|
|
|
HeaderFieldNames.Add(key);
|
|
|
|
|
return true;
|
2024-03-05 16:37:52 -05:00
|
|
|
|
2024-03-05 17:17:40 -05:00
|
|
|
case Models.Metadata.MetadataFile.MachineKey:
|
|
|
|
|
MachineFieldNames.Add(key);
|
|
|
|
|
return true;
|
2024-03-05 16:37:52 -05:00
|
|
|
|
2024-03-05 17:17:40 -05:00
|
|
|
default:
|
|
|
|
|
if (!ItemFieldNames.ContainsKey(type))
|
|
|
|
|
ItemFieldNames[type] = [];
|
2024-03-05 16:37:52 -05:00
|
|
|
|
2024-03-05 17:17:40 -05:00
|
|
|
ItemFieldNames[type].Add(key);
|
|
|
|
|
return true;
|
2021-02-01 12:11:32 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Running
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Remove fields from a DatFile
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="datFile">Current DatFile object to run operations on</param>
|
|
|
|
|
public void ApplyRemovals(DatFile datFile)
|
|
|
|
|
{
|
2023-04-19 16:39:58 -04:00
|
|
|
InternalStopwatch watch = new("Applying removals to DAT");
|
2021-02-01 12:11:32 -08:00
|
|
|
|
|
|
|
|
// Remove DatHeader fields
|
2024-03-05 16:37:52 -05:00
|
|
|
if (HeaderFieldNames.Any())
|
|
|
|
|
RemoveFields(datFile.Header);
|
2021-02-01 12:11:32 -08:00
|
|
|
|
|
|
|
|
// Remove DatItem and Machine fields
|
2024-03-05 16:37:52 -05:00
|
|
|
if (MachineFieldNames.Any() || ItemFieldNames.Any())
|
2021-02-01 12:11:32 -08:00
|
|
|
{
|
2024-02-28 21:59:13 -05:00
|
|
|
#if NET452_OR_GREATER || NETCOREAPP
|
2021-02-01 12:11:32 -08:00
|
|
|
Parallel.ForEach(datFile.Items.Keys, Globals.ParallelOptions, key =>
|
2024-02-28 21:59:13 -05:00
|
|
|
#elif NET40_OR_GREATER
|
|
|
|
|
Parallel.ForEach(datFile.Items.Keys, key =>
|
|
|
|
|
#else
|
|
|
|
|
foreach (var key in datFile.Items.Keys)
|
|
|
|
|
#endif
|
2021-02-01 12:11:32 -08:00
|
|
|
{
|
2024-02-28 19:19:50 -05:00
|
|
|
ConcurrentList<DatItem>? items = datFile.Items[key];
|
|
|
|
|
if (items == null)
|
2024-03-05 02:52:53 -05:00
|
|
|
#if NET40_OR_GREATER || NETCOREAPP
|
2024-02-28 19:19:50 -05:00
|
|
|
return;
|
2024-03-05 02:52:53 -05:00
|
|
|
#else
|
|
|
|
|
continue;
|
|
|
|
|
#endif
|
2024-02-28 19:19:50 -05:00
|
|
|
|
2021-02-01 12:11:32 -08:00
|
|
|
for (int j = 0; j < items.Count; j++)
|
|
|
|
|
{
|
2024-03-05 16:37:52 -05:00
|
|
|
RemoveFields(items[j]);
|
2021-02-01 12:11:32 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
datFile.Items.Remove(key);
|
|
|
|
|
datFile.Items.AddRange(key, items);
|
2024-02-28 21:59:13 -05:00
|
|
|
#if NET40_OR_GREATER || NETCOREAPP
|
2021-02-01 12:11:32 -08:00
|
|
|
});
|
2024-02-28 21:59:13 -05:00
|
|
|
#else
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2021-02-01 12:11:32 -08:00
|
|
|
}
|
2021-02-02 14:09:49 -08:00
|
|
|
|
|
|
|
|
watch.Stop();
|
2021-02-01 12:11:32 -08:00
|
|
|
}
|
2021-01-29 22:54:16 -08:00
|
|
|
|
2024-03-05 16:37:52 -05:00
|
|
|
/// <summary>
|
|
|
|
|
/// Remove fields with given values
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="datItem">DatHeader to remove fields from</param>
|
|
|
|
|
public void RemoveFields(DatHeader datHeader)
|
|
|
|
|
{
|
2024-03-05 17:17:40 -05:00
|
|
|
// If we have an invalid input, return
|
|
|
|
|
if (datHeader == null || !HeaderFieldNames.Any())
|
2024-03-05 16:37:52 -05:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
foreach (var fieldName in HeaderFieldNames)
|
|
|
|
|
{
|
2024-03-06 00:33:45 -05:00
|
|
|
datHeader.RemoveField(fieldName);
|
2024-03-05 16:37:52 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Remove fields with given values
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="machine">Machine to remove fields from</param>
|
|
|
|
|
public void RemoveFields(Machine? machine)
|
|
|
|
|
{
|
2024-03-05 17:17:40 -05:00
|
|
|
// If we have an invalid input, return
|
|
|
|
|
if (machine == null || !MachineFieldNames.Any())
|
2024-03-05 16:37:52 -05:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
foreach (var fieldName in MachineFieldNames)
|
|
|
|
|
{
|
|
|
|
|
machine.RemoveField(fieldName);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Remove fields with given values
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="datItem">DatItem to remove fields from</param>
|
|
|
|
|
public void RemoveFields(DatItem? datItem)
|
|
|
|
|
{
|
|
|
|
|
if (datItem == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
#region Common
|
|
|
|
|
|
|
|
|
|
// Handle Machine fields
|
2024-03-05 17:17:40 -05:00
|
|
|
if (MachineFieldNames.Any() && datItem.Machine != null)
|
2024-03-05 16:37:52 -05:00
|
|
|
RemoveFields(datItem.Machine);
|
|
|
|
|
|
|
|
|
|
// If there are no field names, return
|
|
|
|
|
if (ItemFieldNames == null || !ItemFieldNames.Any())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// If there are no field names for this type or generic, return
|
|
|
|
|
string? itemType = datItem.ItemType.AsStringValue<ItemType>();
|
|
|
|
|
if (itemType == null || (!ItemFieldNames.ContainsKey(itemType) && !ItemFieldNames.ContainsKey("item")))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// Get the combined list of fields to remove
|
|
|
|
|
var fieldNames = new List<string>();
|
|
|
|
|
if (ItemFieldNames.ContainsKey(itemType))
|
|
|
|
|
fieldNames.AddRange(ItemFieldNames[itemType]);
|
|
|
|
|
if (ItemFieldNames.ContainsKey("item"))
|
|
|
|
|
fieldNames.AddRange(ItemFieldNames["item"]);
|
|
|
|
|
fieldNames = fieldNames.Distinct().ToList();
|
|
|
|
|
|
|
|
|
|
// If the field specifically contains Name, set it separately
|
|
|
|
|
if (fieldNames.Contains(Models.Metadata.Rom.NameKey))
|
|
|
|
|
datItem.SetName(null);
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Item-Specific
|
|
|
|
|
|
|
|
|
|
// Handle unnested removals first
|
|
|
|
|
foreach (var datItemField in fieldNames)
|
|
|
|
|
{
|
|
|
|
|
datItem.RemoveField(datItemField);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Handle nested removals
|
|
|
|
|
switch (datItem)
|
|
|
|
|
{
|
|
|
|
|
case Adjuster adjuster: RemoveFields(adjuster); break;
|
|
|
|
|
case Configuration configuration: RemoveFields(configuration); break;
|
|
|
|
|
case ConfSetting confSetting: RemoveFields(confSetting); break;
|
|
|
|
|
case Device device: RemoveFields(device); break;
|
|
|
|
|
case DipSwitch dipSwitch: RemoveFields(dipSwitch); break;
|
|
|
|
|
case DipValue dipValue: RemoveFields(dipValue); break;
|
|
|
|
|
case Disk disk: RemoveFields(disk); break;
|
|
|
|
|
case Input input: RemoveFields(input); break;
|
|
|
|
|
case Part part: RemoveFields(part); break;
|
|
|
|
|
case Port port: RemoveFields(port); break;
|
|
|
|
|
case Rom rom: RemoveFields(rom); break;
|
|
|
|
|
case Slot slot: RemoveFields(slot); break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Remove fields with given values
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="adjuster">Adjuster to remove fields from</param>
|
|
|
|
|
private void RemoveFields(Adjuster adjuster)
|
|
|
|
|
{
|
|
|
|
|
if (!adjuster.ConditionsSpecified)
|
|
|
|
|
return;
|
|
|
|
|
|
2024-03-08 21:12:13 -05:00
|
|
|
foreach (Condition subCondition in adjuster.GetFieldValue<Condition[]?>(Models.Metadata.Adjuster.ConditionKey)!)
|
2024-03-05 16:37:52 -05:00
|
|
|
{
|
|
|
|
|
RemoveFields(subCondition);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Remove fields with given values
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="configuration">Configuration to remove fields from</param>
|
|
|
|
|
private void RemoveFields(Configuration configuration)
|
|
|
|
|
{
|
|
|
|
|
if (configuration.ConditionsSpecified)
|
|
|
|
|
{
|
2024-03-09 21:34:26 -05:00
|
|
|
foreach (Condition subCondition in configuration.GetFieldValue<Condition[]?>(Models.Metadata.Configuration.ConditionKey)!)
|
2024-03-05 16:37:52 -05:00
|
|
|
{
|
|
|
|
|
RemoveFields(subCondition);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (configuration.LocationsSpecified)
|
|
|
|
|
{
|
2024-03-09 21:34:26 -05:00
|
|
|
foreach (ConfLocation subLocation in configuration.GetFieldValue<ConfLocation[]?>(Models.Metadata.Configuration.ConfLocationKey)!)
|
2024-03-05 16:37:52 -05:00
|
|
|
{
|
|
|
|
|
RemoveFields(subLocation);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (configuration.SettingsSpecified)
|
|
|
|
|
{
|
2024-03-09 21:34:26 -05:00
|
|
|
foreach (ConfSetting subSetting in configuration.GetFieldValue<ConfSetting[]?>(Models.Metadata.Configuration.ConfSettingKey)!)
|
2024-03-05 16:37:52 -05:00
|
|
|
{
|
|
|
|
|
RemoveFields(subSetting as DatItem);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Remove fields with given values
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="confsetting">ConfSetting to remove fields from</param>
|
|
|
|
|
private void RemoveFields(ConfSetting confsetting)
|
|
|
|
|
{
|
|
|
|
|
if (confsetting.ConditionsSpecified)
|
|
|
|
|
{
|
2024-03-09 21:34:26 -05:00
|
|
|
foreach (Condition subCondition in confsetting.GetFieldValue<Condition[]?>(Models.Metadata.ConfSetting.ConditionKey)!)
|
2024-03-05 16:37:52 -05:00
|
|
|
{
|
|
|
|
|
RemoveFields(subCondition);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Remove fields with given values
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="device">Device to remove fields from</param>
|
|
|
|
|
private void RemoveFields(Device device)
|
|
|
|
|
{
|
|
|
|
|
if (device.ExtensionsSpecified)
|
|
|
|
|
{
|
2024-03-09 21:34:26 -05:00
|
|
|
foreach (Extension subExtension in device.GetFieldValue<Extension[]?>(Models.Metadata.Device.ExtensionKey)!)
|
2024-03-05 16:37:52 -05:00
|
|
|
{
|
|
|
|
|
RemoveFields(subExtension);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (device.InstancesSpecified)
|
|
|
|
|
{
|
2024-03-09 21:34:26 -05:00
|
|
|
foreach (Instance subInstance in device.GetFieldValue<Instance[]?>(Models.Metadata.Device.InstanceKey)!)
|
2024-03-05 16:37:52 -05:00
|
|
|
{
|
|
|
|
|
RemoveFields(subInstance);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Remove fields with given values
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="dipSwitch">DipSwitch to remove fields from</param>
|
|
|
|
|
private void RemoveFields(DipSwitch dipSwitch)
|
|
|
|
|
{
|
|
|
|
|
if (dipSwitch.ConditionsSpecified)
|
|
|
|
|
{
|
2024-03-09 21:34:26 -05:00
|
|
|
foreach (Condition subCondition in dipSwitch.GetFieldValue<Condition[]?>(Models.Metadata.DipSwitch.ConditionKey)!)
|
2024-03-05 16:37:52 -05:00
|
|
|
{
|
|
|
|
|
RemoveFields(subCondition);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (dipSwitch.LocationsSpecified)
|
|
|
|
|
{
|
2024-03-09 21:34:26 -05:00
|
|
|
foreach (DipLocation subLocation in dipSwitch.GetFieldValue<DipLocation[]?>(Models.Metadata.DipSwitch.DipLocationKey)!)
|
2024-03-05 16:37:52 -05:00
|
|
|
{
|
|
|
|
|
RemoveFields(subLocation);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (dipSwitch.ValuesSpecified)
|
|
|
|
|
{
|
2024-03-09 21:34:26 -05:00
|
|
|
foreach (DipValue subValue in dipSwitch.GetFieldValue<DipValue[]?>(Models.Metadata.DipSwitch.DipValueKey)!)
|
2024-03-05 16:37:52 -05:00
|
|
|
{
|
|
|
|
|
RemoveFields(subValue as DatItem);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (dipSwitch.PartSpecified)
|
2024-03-09 21:34:26 -05:00
|
|
|
RemoveFields(dipSwitch.GetFieldValue<Part?>("PART")! as DatItem);
|
2024-03-05 16:37:52 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Remove fields with given values
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="dipValue">DipValue to remove fields from</param>
|
|
|
|
|
private void RemoveFields(DipValue dipValue)
|
|
|
|
|
{
|
|
|
|
|
if (dipValue.ConditionsSpecified)
|
|
|
|
|
{
|
2024-03-09 21:34:26 -05:00
|
|
|
foreach (Condition subCondition in dipValue.GetFieldValue<Condition[]?>(Models.Metadata.DipValue.ConditionKey)!)
|
2024-03-05 16:37:52 -05:00
|
|
|
{
|
|
|
|
|
RemoveFields(subCondition);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Remove fields with given values
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="disk">Disk to remove fields from</param>
|
|
|
|
|
private void RemoveFields(Disk disk)
|
|
|
|
|
{
|
|
|
|
|
if (disk.DiskAreaSpecified)
|
2024-03-09 21:34:26 -05:00
|
|
|
RemoveFields(disk.GetFieldValue<DiskArea?>("DISKAREA")! as DatItem);
|
2024-03-05 16:37:52 -05:00
|
|
|
|
|
|
|
|
if (disk.PartSpecified)
|
2024-03-09 21:34:26 -05:00
|
|
|
RemoveFields(disk.GetFieldValue<Part?>("PART")! as DatItem);
|
2024-03-05 16:37:52 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Remove fields with given values
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input">Input to remove fields from</param>
|
|
|
|
|
private void RemoveFields(Input input)
|
|
|
|
|
{
|
|
|
|
|
if (input.ControlsSpecified)
|
|
|
|
|
{
|
2024-03-09 21:34:26 -05:00
|
|
|
foreach (Control subControl in input.GetFieldValue<Control[]?>(Models.Metadata.Input.ControlKey)!)
|
2024-03-05 16:37:52 -05:00
|
|
|
{
|
|
|
|
|
RemoveFields(subControl);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Remove fields with given values
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="part">Part to remove fields from</param>
|
|
|
|
|
private void RemoveFields(Part part)
|
|
|
|
|
{
|
|
|
|
|
if (part.FeaturesSpecified)
|
|
|
|
|
{
|
2024-03-09 21:34:26 -05:00
|
|
|
foreach (PartFeature subPartFeature in part.GetFieldValue<PartFeature[]?>(Models.Metadata.Part.FeatureKey)!)
|
2024-03-05 16:37:52 -05:00
|
|
|
{
|
|
|
|
|
RemoveFields(subPartFeature);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Remove fields with given values
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="port">Port to remove fields from</param>
|
|
|
|
|
private void RemoveFields(Port port)
|
|
|
|
|
{
|
|
|
|
|
if (port.AnalogsSpecified)
|
|
|
|
|
{
|
2024-03-09 21:34:26 -05:00
|
|
|
foreach (Analog subAnalog in port.GetFieldValue<Analog[]?>(Models.Metadata.Port.AnalogKey)!)
|
2024-03-05 16:37:52 -05:00
|
|
|
{
|
|
|
|
|
RemoveFields(subAnalog);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Remove fields with given values
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="rom">Rom to remove fields from</param>
|
|
|
|
|
private void RemoveFields(Rom rom)
|
|
|
|
|
{
|
|
|
|
|
if (rom.DataAreaSpecified)
|
2024-03-09 21:34:26 -05:00
|
|
|
RemoveFields(rom.GetFieldValue<DataArea?>("DATAAREA")!);
|
2024-03-05 16:37:52 -05:00
|
|
|
|
|
|
|
|
if (rom.PartSpecified)
|
2024-03-09 21:34:26 -05:00
|
|
|
RemoveFields(rom.GetFieldValue<Part?>("PART")! as DatItem);
|
2024-03-05 16:37:52 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Remove fields with given values
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="slot">Slot to remove fields from</param>
|
|
|
|
|
private void RemoveFields(Slot slot)
|
|
|
|
|
{
|
|
|
|
|
if (slot.SlotOptionsSpecified)
|
|
|
|
|
{
|
2024-03-09 21:34:26 -05:00
|
|
|
foreach (SlotOption subSlotOption in slot.GetFieldValue<SlotOption[]?>(Models.Metadata.Slot.SlotOptionKey)!)
|
2024-03-05 16:37:52 -05:00
|
|
|
{
|
|
|
|
|
RemoveFields(subSlotOption);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-29 22:54:16 -08:00
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|