diff --git a/SabreTools.DatItems/DatItem.cs b/SabreTools.DatItems/DatItem.cs index 4c993aef..57d0a8b7 100644 --- a/SabreTools.DatItems/DatItem.cs +++ b/SabreTools.DatItems/DatItem.cs @@ -392,19 +392,28 @@ namespace SabreTools.DatItems /// /// Remove a field from the DatItem /// - /// Item field to remove + /// Field to remove /// True if the removal was successful, false otherwise - public abstract bool RemoveField(DatItemField datItemField); + public bool RemoveField(string? fieldName) => FieldManipulator.RemoveField(_internal, fieldName); /// /// Set a field in the DatItem from a mapping string /// - /// Item field to set + /// Item field to set /// String representing the value to set /// True if the setting was successful, false otherwise /// This only performs minimal validation before setting public abstract bool SetField(DatItemField datItemField, string value); + /// + /// Set a field in the DatItem from a mapping string + /// + /// Field to set + /// String representing the value to set + /// True if the removal was successful, false otherwise + /// This only performs minimal validation before setting + public bool SetField(string? fieldName, string value) => FieldManipulator.SetField(_internal, fieldName, value); + #endregion #region Sorting and Merging diff --git a/SabreTools.DatItems/Formats/Adjuster.cs b/SabreTools.DatItems/Formats/Adjuster.cs index 0c8b0957..00fd36ad 100644 --- a/SabreTools.DatItems/Formats/Adjuster.cs +++ b/SabreTools.DatItems/Formats/Adjuster.cs @@ -101,20 +101,6 @@ namespace SabreTools.DatItems.Formats #region Manipulation - /// - public override bool RemoveField(DatItemField datItemField) - { - // Get the correct internal field name - string? fieldName = datItemField switch - { - DatItemField.Default => Models.Metadata.Adjuster.DefaultKey, - _ => null, - }; - - // Remove the field and return - return FieldManipulator.RemoveField(_internal, fieldName); - } - /// public override bool SetField(DatItemField datItemField, string value) { diff --git a/SabreTools.DatItems/Formats/Analog.cs b/SabreTools.DatItems/Formats/Analog.cs index ce62cd56..cfc5d0b4 100644 --- a/SabreTools.DatItems/Formats/Analog.cs +++ b/SabreTools.DatItems/Formats/Analog.cs @@ -62,20 +62,6 @@ namespace SabreTools.DatItems.Formats #region Manipulation - /// - public override bool RemoveField(DatItemField datItemField) - { - // Get the correct internal field name - string? fieldName = datItemField switch - { - DatItemField.Analog_Mask => Models.Metadata.Analog.MaskKey, - _ => null, - }; - - // Remove the field and return - return FieldManipulator.RemoveField(_internal, fieldName); - } - /// public override bool SetField(DatItemField datItemField, string value) { diff --git a/SabreTools.DatItems/Formats/Archive.cs b/SabreTools.DatItems/Formats/Archive.cs index bb323fdf..f1d6dc65 100644 --- a/SabreTools.DatItems/Formats/Archive.cs +++ b/SabreTools.DatItems/Formats/Archive.cs @@ -138,19 +138,6 @@ namespace SabreTools.DatItems.Formats #region Manipulation - /// - public override bool RemoveField(DatItemField datItemField) - { - // Get the correct internal field name - string? fieldName = datItemField switch - { - _ => null, - }; - - // Remove the field and return - return FieldManipulator.RemoveField(_internal, fieldName); - } - /// public override bool SetField(DatItemField datItemField, string value) { diff --git a/SabreTools.DatItems/Formats/BiosSet.cs b/SabreTools.DatItems/Formats/BiosSet.cs index 813b7d9d..bca15982 100644 --- a/SabreTools.DatItems/Formats/BiosSet.cs +++ b/SabreTools.DatItems/Formats/BiosSet.cs @@ -96,21 +96,6 @@ namespace SabreTools.DatItems.Formats #region Manipulation - /// - public override bool RemoveField(DatItemField datItemField) - { - // Get the correct internal field name - string? fieldName = datItemField switch - { - DatItemField.Default => Models.Metadata.BiosSet.DefaultKey, - DatItemField.Description => Models.Metadata.BiosSet.DescriptionKey, - _ => null, - }; - - // Remove the field and return - return FieldManipulator.RemoveField(_internal, fieldName); - } - /// public override bool SetField(DatItemField datItemField, string value) { diff --git a/SabreTools.DatItems/Formats/Blank.cs b/SabreTools.DatItems/Formats/Blank.cs index f47680c1..34128dae 100644 --- a/SabreTools.DatItems/Formats/Blank.cs +++ b/SabreTools.DatItems/Formats/Blank.cs @@ -60,9 +60,6 @@ namespace SabreTools.DatItems.Formats #region Manipulation - /// - public override bool RemoveField(DatItemField datItemField) => true; - /// public override bool SetField(DatItemField datItemField, string value) => true; diff --git a/SabreTools.DatItems/Formats/Chip.cs b/SabreTools.DatItems/Formats/Chip.cs index 6a8f95f3..673d34ff 100644 --- a/SabreTools.DatItems/Formats/Chip.cs +++ b/SabreTools.DatItems/Formats/Chip.cs @@ -112,22 +112,6 @@ namespace SabreTools.DatItems.Formats #region Manipulation - /// - public override bool RemoveField(DatItemField datItemField) - { - // Get the correct internal field name - string? fieldName = datItemField switch - { - DatItemField.ChipType => Models.Metadata.Chip.ChipTypeKey, - DatItemField.Clock => Models.Metadata.Chip.ClockKey, - DatItemField.Tag => Models.Metadata.Chip.TagKey, - _ => null, - }; - - // Remove the field and return - return FieldManipulator.RemoveField(_internal, fieldName); - } - /// public override bool SetField(DatItemField datItemField, string value) { diff --git a/SabreTools.DatItems/Formats/Condition.cs b/SabreTools.DatItems/Formats/Condition.cs index 02be34e8..ed2e86fe 100644 --- a/SabreTools.DatItems/Formats/Condition.cs +++ b/SabreTools.DatItems/Formats/Condition.cs @@ -98,27 +98,6 @@ namespace SabreTools.DatItems.Formats #region Manipulation - /// - public override bool RemoveField(DatItemField datItemField) - { - // Get the correct internal field name - string? fieldName = datItemField switch - { - DatItemField.Mask => Models.Metadata.Condition.MaskKey, - DatItemField.Condition_Mask => Models.Metadata.Condition.MaskKey, - DatItemField.Relation => Models.Metadata.Condition.RelationKey, - DatItemField.Condition_Relation => Models.Metadata.Condition.RelationKey, - DatItemField.Tag => Models.Metadata.Condition.TagKey, - DatItemField.Condition_Tag => Models.Metadata.Condition.TagKey, - DatItemField.Value => Models.Metadata.Condition.ValueKey, - DatItemField.Condition_Value => Models.Metadata.Condition.ValueKey, - _ => null, - }; - - // Remove the field and return - return FieldManipulator.RemoveField(_internal, fieldName); - } - /// public override bool SetField(DatItemField datItemField, string value) { diff --git a/SabreTools.DatItems/Formats/ConfLocation.cs b/SabreTools.DatItems/Formats/ConfLocation.cs index 80bf3098..9c79188f 100644 --- a/SabreTools.DatItems/Formats/ConfLocation.cs +++ b/SabreTools.DatItems/Formats/ConfLocation.cs @@ -99,23 +99,6 @@ namespace SabreTools.DatItems.Formats #region Manipulation - /// - public override bool RemoveField(DatItemField datItemField) - { - // Get the correct internal field name - string? fieldName = datItemField switch - { - DatItemField.Inverted => Models.Metadata.ConfLocation.InvertedKey, - DatItemField.Location_Inverted => Models.Metadata.ConfLocation.InvertedKey, - DatItemField.Number => Models.Metadata.ConfLocation.NumberKey, - DatItemField.Location_Number => Models.Metadata.ConfLocation.NumberKey, - _ => null, - }; - - // Remove the field and return - return FieldManipulator.RemoveField(_internal, fieldName); - } - /// public override bool SetField(DatItemField datItemField, string value) { diff --git a/SabreTools.DatItems/Formats/ConfSetting.cs b/SabreTools.DatItems/Formats/ConfSetting.cs index cb215da6..3a52e813 100644 --- a/SabreTools.DatItems/Formats/ConfSetting.cs +++ b/SabreTools.DatItems/Formats/ConfSetting.cs @@ -111,23 +111,6 @@ namespace SabreTools.DatItems.Formats #region Manipulation - /// - public override bool RemoveField(DatItemField datItemField) - { - // Get the correct internal field name - string? fieldName = datItemField switch - { - DatItemField.Default => Models.Metadata.ConfSetting.DefaultKey, - DatItemField.Setting_Default => Models.Metadata.ConfSetting.DefaultKey, - DatItemField.Value => Models.Metadata.ConfSetting.ValueKey, - DatItemField.Setting_Value => Models.Metadata.ConfSetting.ValueKey, - _ => null, - }; - - // Remove the field and return - return FieldManipulator.RemoveField(_internal, fieldName); - } - /// public override bool SetField(DatItemField datItemField, string value) { diff --git a/SabreTools.DatItems/Formats/Configuration.cs b/SabreTools.DatItems/Formats/Configuration.cs index 98f92617..1df2491c 100644 --- a/SabreTools.DatItems/Formats/Configuration.cs +++ b/SabreTools.DatItems/Formats/Configuration.cs @@ -134,21 +134,6 @@ namespace SabreTools.DatItems.Formats #region Manipulation - /// - public override bool RemoveField(DatItemField datItemField) - { - // Get the correct internal field name - string? fieldName = datItemField switch - { - DatItemField.Mask => Models.Metadata.Configuration.MaskKey, - DatItemField.Tag => Models.Metadata.Configuration.TagKey, - _ => null, - }; - - // Remove the field and return - return FieldManipulator.RemoveField(_internal, fieldName); - } - /// public override bool SetField(DatItemField datItemField, string value) { diff --git a/SabreTools.DatItems/Formats/Control.cs b/SabreTools.DatItems/Formats/Control.cs index 0d1f0c12..a53de733 100644 --- a/SabreTools.DatItems/Formats/Control.cs +++ b/SabreTools.DatItems/Formats/Control.cs @@ -202,31 +202,6 @@ namespace SabreTools.DatItems.Formats #region Manipulation - /// - public override bool RemoveField(DatItemField datItemField) - { - // Get the correct internal field name - string? fieldName = datItemField switch - { - DatItemField.Control_Buttons => Models.Metadata.Control.ButtonsKey, - DatItemField.Control_KeyDelta => Models.Metadata.Control.KeyDeltaKey, - DatItemField.Control_Maximum => Models.Metadata.Control.MaximumKey, - DatItemField.Control_Minimum => Models.Metadata.Control.MinimumKey, - DatItemField.Control_Player => Models.Metadata.Control.PlayerKey, - DatItemField.Control_RequiredButtons => Models.Metadata.Control.ReqButtonsKey, - DatItemField.Control_Reverse => Models.Metadata.Control.ReverseKey, - DatItemField.Control_Sensitivity => Models.Metadata.Control.SensitivityKey, - DatItemField.Control_Type => Models.Metadata.Control.ControlTypeKey, - DatItemField.Control_Ways => Models.Metadata.Control.WaysKey, - DatItemField.Control_Ways2 => Models.Metadata.Control.Ways2Key, - DatItemField.Control_Ways3 => Models.Metadata.Control.Ways3Key, - _ => null, - }; - - // Remove the field and return - return FieldManipulator.RemoveField(_internal, fieldName); - } - /// public override bool SetField(DatItemField datItemField, string value) { diff --git a/SabreTools.DatItems/Formats/DataArea.cs b/SabreTools.DatItems/Formats/DataArea.cs index dbaff897..dcee4d6d 100644 --- a/SabreTools.DatItems/Formats/DataArea.cs +++ b/SabreTools.DatItems/Formats/DataArea.cs @@ -114,22 +114,6 @@ namespace SabreTools.DatItems.Formats #region Manipulation - /// - public override bool RemoveField(DatItemField datItemField) - { - // Get the correct internal field name - string? fieldName = datItemField switch - { - DatItemField.AreaEndianness => Models.Metadata.DataArea.EndiannessKey, - DatItemField.AreaSize => Models.Metadata.DataArea.SizeKey, - DatItemField.AreaWidth => Models.Metadata.DataArea.WidthKey, - _ => null, - }; - - // Remove the field and return - return FieldManipulator.RemoveField(_internal, fieldName); - } - /// public override bool SetField(DatItemField datItemField, string value) { diff --git a/SabreTools.DatItems/Formats/Device.cs b/SabreTools.DatItems/Formats/Device.cs index 0b8169b2..2b61cadc 100644 --- a/SabreTools.DatItems/Formats/Device.cs +++ b/SabreTools.DatItems/Formats/Device.cs @@ -140,24 +140,6 @@ namespace SabreTools.DatItems.Formats #region Manipulation - /// - public override bool RemoveField(DatItemField datItemField) - { - // Get the correct internal field name - string? fieldName = datItemField switch - { - DatItemField.DeviceType => Models.Metadata.Device.DeviceTypeKey, - DatItemField.FixedImage => Models.Metadata.Device.FixedImageKey, - DatItemField.Interface => Models.Metadata.Device.InterfaceKey, - DatItemField.Mandatory => Models.Metadata.Device.MandatoryKey, - DatItemField.Tag => Models.Metadata.Device.TagKey, - _ => null, - }; - - // Remove the field and return - return FieldManipulator.RemoveField(_internal, fieldName); - } - /// public override bool SetField(DatItemField datItemField, string value) { diff --git a/SabreTools.DatItems/Formats/DeviceReference.cs b/SabreTools.DatItems/Formats/DeviceReference.cs index 3c58cc3a..5cf94600 100644 --- a/SabreTools.DatItems/Formats/DeviceReference.cs +++ b/SabreTools.DatItems/Formats/DeviceReference.cs @@ -73,19 +73,6 @@ namespace SabreTools.DatItems.Formats #region Manipulation - /// - public override bool RemoveField(DatItemField datItemField) - { - // Get the correct internal field name - string? fieldName = datItemField switch - { - _ => null, - }; - - // Remove the field and return - return FieldManipulator.RemoveField(_internal, fieldName); - } - /// public override bool SetField(DatItemField datItemField, string value) { diff --git a/SabreTools.DatItems/Formats/DipLocation.cs b/SabreTools.DatItems/Formats/DipLocation.cs index eef25719..5966617e 100644 --- a/SabreTools.DatItems/Formats/DipLocation.cs +++ b/SabreTools.DatItems/Formats/DipLocation.cs @@ -99,23 +99,6 @@ namespace SabreTools.DatItems.Formats #region Manipulation - /// - public override bool RemoveField(DatItemField datItemField) - { - // Get the correct internal field name - string? fieldName = datItemField switch - { - DatItemField.Inverted => Models.Metadata.DipLocation.InvertedKey, - DatItemField.Location_Inverted => Models.Metadata.DipLocation.InvertedKey, - DatItemField.Number => Models.Metadata.DipLocation.NumberKey, - DatItemField.Location_Number => Models.Metadata.DipLocation.NumberKey, - _ => null, - }; - - // Remove the field and return - return FieldManipulator.RemoveField(_internal, fieldName); - } - /// public override bool SetField(DatItemField datItemField, string value) { diff --git a/SabreTools.DatItems/Formats/DipSwitch.cs b/SabreTools.DatItems/Formats/DipSwitch.cs index 987896a1..d12b23ce 100644 --- a/SabreTools.DatItems/Formats/DipSwitch.cs +++ b/SabreTools.DatItems/Formats/DipSwitch.cs @@ -162,21 +162,6 @@ namespace SabreTools.DatItems.Formats #region Manipulation - /// - public override bool RemoveField(DatItemField datItemField) - { - // Get the correct internal field name - string? fieldName = datItemField switch - { - DatItemField.Mask => Models.Metadata.DipSwitch.MaskKey, - DatItemField.Tag => Models.Metadata.DipSwitch.TagKey, - _ => null, - }; - - // Remove the field and return - return FieldManipulator.RemoveField(_internal, fieldName); - } - /// public override bool SetField(DatItemField datItemField, string value) { diff --git a/SabreTools.DatItems/Formats/DipValue.cs b/SabreTools.DatItems/Formats/DipValue.cs index d3a5ac2c..b0b13426 100644 --- a/SabreTools.DatItems/Formats/DipValue.cs +++ b/SabreTools.DatItems/Formats/DipValue.cs @@ -111,23 +111,6 @@ namespace SabreTools.DatItems.Formats #region Manipulation - /// - public override bool RemoveField(DatItemField datItemField) - { - // Get the correct internal field name - string? fieldName = datItemField switch - { - DatItemField.Default => Models.Metadata.DipValue.DefaultKey, - DatItemField.Setting_Default => Models.Metadata.DipValue.DefaultKey, - DatItemField.Value => Models.Metadata.DipValue.ValueKey, - DatItemField.Setting_Value => Models.Metadata.DipValue.ValueKey, - _ => null, - }; - - // Remove the field and return - return FieldManipulator.RemoveField(_internal, fieldName); - } - /// public override bool SetField(DatItemField datItemField, string value) { diff --git a/SabreTools.DatItems/Formats/Disk.cs b/SabreTools.DatItems/Formats/Disk.cs index f2421d2d..516f9460 100644 --- a/SabreTools.DatItems/Formats/Disk.cs +++ b/SabreTools.DatItems/Formats/Disk.cs @@ -288,27 +288,6 @@ namespace SabreTools.DatItems.Formats #region Manipulation - /// - public override bool RemoveField(DatItemField datItemField) - { - // Get the correct internal field name - string? fieldName = datItemField switch - { - DatItemField.Index => Models.Metadata.Disk.IndexKey, - DatItemField.MD5 => Models.Metadata.Disk.MD5Key, - DatItemField.Merge => Models.Metadata.Disk.MergeKey, - DatItemField.Optional => Models.Metadata.Disk.OptionalKey, - DatItemField.Region => Models.Metadata.Disk.RegionKey, - DatItemField.SHA1 => Models.Metadata.Disk.SHA1Key, - DatItemField.Status => Models.Metadata.Disk.StatusKey, - DatItemField.Writable => Models.Metadata.Disk.WritableKey, - _ => null, - }; - - // Remove the field and return - return FieldManipulator.RemoveField(_internal, fieldName); - } - /// public override bool SetField(DatItemField datItemField, string value) { diff --git a/SabreTools.DatItems/Formats/DiskArea.cs b/SabreTools.DatItems/Formats/DiskArea.cs index 932a7487..8ad516cf 100644 --- a/SabreTools.DatItems/Formats/DiskArea.cs +++ b/SabreTools.DatItems/Formats/DiskArea.cs @@ -74,19 +74,6 @@ namespace SabreTools.DatItems.Formats #region Manipulation - /// - public override bool RemoveField(DatItemField datItemField) - { - // Get the correct internal field name - string? fieldName = datItemField switch - { - _ => null, - }; - - // Remove the field and return - return FieldManipulator.RemoveField(_internal, fieldName); - } - /// public override bool SetField(DatItemField datItemField, string value) { diff --git a/SabreTools.DatItems/Formats/Display.cs b/SabreTools.DatItems/Formats/Display.cs index 07ba6105..90fc8970 100644 --- a/SabreTools.DatItems/Formats/Display.cs +++ b/SabreTools.DatItems/Formats/Display.cs @@ -234,33 +234,6 @@ namespace SabreTools.DatItems.Formats #region Manipulation - /// - public override bool RemoveField(DatItemField datItemField) - { - // Get the correct internal field name - string? fieldName = datItemField switch - { - DatItemField.DisplayType => Models.Metadata.Display.DisplayTypeKey, - DatItemField.FlipX => Models.Metadata.Display.FlipXKey, - DatItemField.HBEnd => Models.Metadata.Display.HBEndKey, - DatItemField.HBStart => Models.Metadata.Display.HBStartKey, - DatItemField.Height => Models.Metadata.Display.HeightKey, - DatItemField.HTotal => Models.Metadata.Display.HTotalKey, - DatItemField.PixClock => Models.Metadata.Display.PixClockKey, - DatItemField.Refresh => Models.Metadata.Display.RefreshKey, - DatItemField.Rotate => Models.Metadata.Display.RotateKey, - DatItemField.Tag => Models.Metadata.Display.TagKey, - DatItemField.VBEnd => Models.Metadata.Display.VBEndKey, - DatItemField.VBStart => Models.Metadata.Display.VBStartKey, - DatItemField.VTotal => Models.Metadata.Display.VTotalKey, - DatItemField.Width => Models.Metadata.Display.WidthKey, - _ => null, - }; - - // Remove the field and return - return FieldManipulator.RemoveField(_internal, fieldName); - } - /// public override bool SetField(DatItemField datItemField, string value) { diff --git a/SabreTools.DatItems/Formats/Driver.cs b/SabreTools.DatItems/Formats/Driver.cs index 549392cb..18a55115 100644 --- a/SabreTools.DatItems/Formats/Driver.cs +++ b/SabreTools.DatItems/Formats/Driver.cs @@ -165,27 +165,6 @@ namespace SabreTools.DatItems.Formats #region Manipulation - /// - public override bool RemoveField(DatItemField datItemField) - { - // Get the correct internal field name - string? fieldName = datItemField switch - { - DatItemField.CocktailStatus => Models.Metadata.Driver.CocktailKey, - DatItemField.EmulationStatus => Models.Metadata.Driver.EmulationKey, - DatItemField.Incomplete => Models.Metadata.Driver.IncompleteKey, - DatItemField.NoSoundHardware => Models.Metadata.Driver.NoSoundHardwareKey, - DatItemField.RequiresArtwork => Models.Metadata.Driver.RequiresArtworkKey, - DatItemField.SaveStateStatus => Models.Metadata.Driver.SaveStateKey, - DatItemField.SupportStatus => Models.Metadata.Driver.StatusKey, - DatItemField.Unofficial => Models.Metadata.Driver.UnofficialKey, - _ => null, - }; - - // Remove the field and return - return FieldManipulator.RemoveField(_internal, fieldName); - } - /// public override bool SetField(DatItemField datItemField, string value) { diff --git a/SabreTools.DatItems/Formats/Extension.cs b/SabreTools.DatItems/Formats/Extension.cs index 301a22c8..4712fd0d 100644 --- a/SabreTools.DatItems/Formats/Extension.cs +++ b/SabreTools.DatItems/Formats/Extension.cs @@ -73,19 +73,6 @@ namespace SabreTools.DatItems.Formats #region Manipulation - /// - public override bool RemoveField(DatItemField datItemField) - { - // Get the correct internal field name - string? fieldName = datItemField switch - { - _ => null, - }; - - // Remove the field and return - return FieldManipulator.RemoveField(_internal, fieldName); - } - /// public override bool SetField(DatItemField datItemField, string value) { diff --git a/SabreTools.DatItems/Formats/Feature.cs b/SabreTools.DatItems/Formats/Feature.cs index 4e72f04e..c7ae19ac 100644 --- a/SabreTools.DatItems/Formats/Feature.cs +++ b/SabreTools.DatItems/Formats/Feature.cs @@ -96,22 +96,6 @@ namespace SabreTools.DatItems.Formats #region Manipulation - /// - public override bool RemoveField(DatItemField datItemField) - { - // Get the correct internal field name - string? fieldName = datItemField switch - { - DatItemField.FeatureOverall => Models.Metadata.Feature.OverallKey, - DatItemField.FeatureStatus => Models.Metadata.Feature.StatusKey, - DatItemField.FeatureType => Models.Metadata.Feature.FeatureTypeKey, - _ => null, - }; - - // Remove the field and return - return FieldManipulator.RemoveField(_internal, fieldName); - } - /// public override bool SetField(DatItemField datItemField, string value) { diff --git a/SabreTools.DatItems/Formats/File.cs b/SabreTools.DatItems/Formats/File.cs index 8a5fbc41..292ca61d 100644 --- a/SabreTools.DatItems/Formats/File.cs +++ b/SabreTools.DatItems/Formats/File.cs @@ -328,20 +328,6 @@ namespace SabreTools.DatItems.Formats #region Manipulation - /// - public override bool RemoveField(DatItemField datItemField) - { - // Get the correct internal field name - string? fieldName = datItemField switch - { - // TODO: Figure out what fields go here - _ => null, - }; - - // Remove the field and return - return FieldManipulator.RemoveField(_internal, fieldName); - } - /// public override bool SetField(DatItemField datItemField, string value) { diff --git a/SabreTools.DatItems/Formats/Info.cs b/SabreTools.DatItems/Formats/Info.cs index 0676a919..4474ffd1 100644 --- a/SabreTools.DatItems/Formats/Info.cs +++ b/SabreTools.DatItems/Formats/Info.cs @@ -83,20 +83,6 @@ namespace SabreTools.DatItems.Formats #region Manipulation - /// - public override bool RemoveField(DatItemField datItemField) - { - // Get the correct internal field name - string? fieldName = datItemField switch - { - DatItemField.Value => Models.Metadata.Info.ValueKey, - _ => null, - }; - - // Remove the field and return - return FieldManipulator.RemoveField(_internal, fieldName); - } - /// public override bool SetField(DatItemField datItemField, string value) { diff --git a/SabreTools.DatItems/Formats/Input.cs b/SabreTools.DatItems/Formats/Input.cs index 295c2d6b..abbdb8bf 100644 --- a/SabreTools.DatItems/Formats/Input.cs +++ b/SabreTools.DatItems/Formats/Input.cs @@ -119,23 +119,6 @@ namespace SabreTools.DatItems.Formats #region Manipulation - /// - public override bool RemoveField(DatItemField datItemField) - { - // Get the correct internal field name - string? fieldName = datItemField switch - { - DatItemField.Coins => Models.Metadata.Input.CoinsKey, - DatItemField.Players => Models.Metadata.Input.PlayersKey, - DatItemField.Service => Models.Metadata.Input.ServiceKey, - DatItemField.Tilt => Models.Metadata.Input.TiltKey, - _ => null, - }; - - // Remove the field and return - return FieldManipulator.RemoveField(_internal, fieldName); - } - /// public override bool SetField(DatItemField datItemField, string value) { diff --git a/SabreTools.DatItems/Formats/Instance.cs b/SabreTools.DatItems/Formats/Instance.cs index 25ce80c6..f493a6b2 100644 --- a/SabreTools.DatItems/Formats/Instance.cs +++ b/SabreTools.DatItems/Formats/Instance.cs @@ -83,20 +83,6 @@ namespace SabreTools.DatItems.Formats #region Manipulation - /// - public override bool RemoveField(DatItemField datItemField) - { - // Get the correct internal field name - string? fieldName = datItemField switch - { - DatItemField.Instance_BriefName => Models.Metadata.Instance.BriefNameKey, - _ => null, - }; - - // Remove the field and return - return FieldManipulator.RemoveField(_internal, fieldName); - } - /// public override bool SetField(DatItemField datItemField, string value) { diff --git a/SabreTools.DatItems/Formats/Media.cs b/SabreTools.DatItems/Formats/Media.cs index 5f89a264..57615abc 100644 --- a/SabreTools.DatItems/Formats/Media.cs +++ b/SabreTools.DatItems/Formats/Media.cs @@ -186,23 +186,6 @@ namespace SabreTools.DatItems.Formats #region Manipulation - /// - public override bool RemoveField(DatItemField datItemField) - { - // Get the correct internal field name - string? fieldName = datItemField switch - { - DatItemField.MD5 => Models.Metadata.Media.MD5Key, - DatItemField.SHA1 => Models.Metadata.Media.SHA1Key, - DatItemField.SHA256 => Models.Metadata.Media.SHA256Key, - DatItemField.SpamSum => Models.Metadata.Media.SpamSumKey, - _ => null, - }; - - // Remove the field and return - return FieldManipulator.RemoveField(_internal, fieldName); - } - /// public override bool SetField(DatItemField datItemField, string value) { diff --git a/SabreTools.DatItems/Formats/Part.cs b/SabreTools.DatItems/Formats/Part.cs index 5cfbb696..d18a401a 100644 --- a/SabreTools.DatItems/Formats/Part.cs +++ b/SabreTools.DatItems/Formats/Part.cs @@ -90,20 +90,6 @@ namespace SabreTools.DatItems.Formats #region Manipulation - /// - public override bool RemoveField(DatItemField datItemField) - { - // Get the correct internal field name - string? fieldName = datItemField switch - { - DatItemField.Part_Interface => Models.Metadata.Part.InterfaceKey, - _ => null, - }; - - // Remove the field and return - return FieldManipulator.RemoveField(_internal, fieldName); - } - /// public override bool SetField(DatItemField datItemField, string value) { diff --git a/SabreTools.DatItems/Formats/PartFeature.cs b/SabreTools.DatItems/Formats/PartFeature.cs index 62271973..3850a382 100644 --- a/SabreTools.DatItems/Formats/PartFeature.cs +++ b/SabreTools.DatItems/Formats/PartFeature.cs @@ -83,21 +83,6 @@ namespace SabreTools.DatItems.Formats #region Manipulation - /// - public override bool RemoveField(DatItemField datItemField) - { - // Get the correct internal field name - string? fieldName = datItemField switch - { - DatItemField.Value => Models.Metadata.Feature.ValueKey, - DatItemField.Part_Feature_Value => Models.Metadata.Feature.ValueKey, - _ => null, - }; - - // Remove the field and return - return FieldManipulator.RemoveField(_internal, fieldName); - } - /// public override bool SetField(DatItemField datItemField, string value) { diff --git a/SabreTools.DatItems/Formats/Port.cs b/SabreTools.DatItems/Formats/Port.cs index 5bce067c..fc3196e2 100644 --- a/SabreTools.DatItems/Formats/Port.cs +++ b/SabreTools.DatItems/Formats/Port.cs @@ -77,20 +77,6 @@ namespace SabreTools.DatItems.Formats #region Manipulation - /// - public override bool RemoveField(DatItemField datItemField) - { - // Get the correct internal field name - string? fieldName = datItemField switch - { - DatItemField.Tag => Models.Metadata.Port.TagKey, - _ => null, - }; - - // Remove the field and return - return FieldManipulator.RemoveField(_internal, fieldName); - } - /// public override bool SetField(DatItemField datItemField, string value) { diff --git a/SabreTools.DatItems/Formats/RamOption.cs b/SabreTools.DatItems/Formats/RamOption.cs index 7ff9603b..97f97fdb 100644 --- a/SabreTools.DatItems/Formats/RamOption.cs +++ b/SabreTools.DatItems/Formats/RamOption.cs @@ -96,21 +96,6 @@ namespace SabreTools.DatItems.Formats #region Manipulation - /// - public override bool RemoveField(DatItemField datItemField) - { - // Get the correct internal field name - string? fieldName = datItemField switch - { - DatItemField.Content => Models.Metadata.RamOption.ContentKey, - DatItemField.Default => Models.Metadata.RamOption.DefaultKey, - _ => null, - }; - - // Remove the field and return - return FieldManipulator.RemoveField(_internal, fieldName); - } - /// public override bool SetField(DatItemField datItemField, string value) { diff --git a/SabreTools.DatItems/Formats/Release.cs b/SabreTools.DatItems/Formats/Release.cs index c1907dfc..78d3c288 100644 --- a/SabreTools.DatItems/Formats/Release.cs +++ b/SabreTools.DatItems/Formats/Release.cs @@ -120,23 +120,6 @@ namespace SabreTools.DatItems.Formats #region Manipulation - /// - public override bool RemoveField(DatItemField datItemField) - { - // Get the correct internal field name - string? fieldName = datItemField switch - { - DatItemField.Date => Models.Metadata.Release.DateKey, - DatItemField.Default => Models.Metadata.Release.DefaultKey, - DatItemField.Language => Models.Metadata.Release.LanguageKey, - DatItemField.Region => Models.Metadata.Release.RegionKey, - _ => null, - }; - - // Remove the field and return - return FieldManipulator.RemoveField(_internal, fieldName); - } - /// public override bool SetField(DatItemField datItemField, string value) { diff --git a/SabreTools.DatItems/Formats/ReleaseDetails.cs b/SabreTools.DatItems/Formats/ReleaseDetails.cs index 5bd4cc1f..36f8bde0 100644 --- a/SabreTools.DatItems/Formats/ReleaseDetails.cs +++ b/SabreTools.DatItems/Formats/ReleaseDetails.cs @@ -190,20 +190,6 @@ namespace SabreTools.DatItems.Formats #region Manipulation - /// - public override bool RemoveField(DatItemField datItemField) - { - // Get the correct internal field name - string? fieldName = datItemField switch - { - // TODO: Figure out what fields go here - _ => null, - }; - - // Remove the field and return - return FieldManipulator.RemoveField(_internal, fieldName); - } - /// public override bool SetField(DatItemField datItemField, string value) { diff --git a/SabreTools.DatItems/Formats/Rom.cs b/SabreTools.DatItems/Formats/Rom.cs index b9b98a8a..3fe10f62 100644 --- a/SabreTools.DatItems/Formats/Rom.cs +++ b/SabreTools.DatItems/Formats/Rom.cs @@ -599,60 +599,6 @@ namespace SabreTools.DatItems.Formats #region Manipulation - /// - public override bool RemoveField(DatItemField datItemField) - { - // Get the correct internal field name - string? fieldName = datItemField switch - { - DatItemField.AltName => Models.Metadata.Rom.AltRomnameKey, - DatItemField.AltTitle => Models.Metadata.Rom.AltTitleKey, - DatItemField.ArchiveDotOrgFormat => Models.Metadata.Rom.FormatKey, - DatItemField.ArchiveDotOrgSource => Models.Metadata.Rom.SourceKey, - DatItemField.Bios => Models.Metadata.Rom.BiosKey, - //DatItemField.Boot => Models.Metadata.Rom.BootKey, - DatItemField.CRC => Models.Metadata.Rom.CRCKey, - DatItemField.Date => Models.Metadata.Rom.DateKey, - DatItemField.Inverted => Models.Metadata.Rom.InvertedKey, - DatItemField.LoadFlag => Models.Metadata.Rom.LoadFlagKey, - DatItemField.MD5 => Models.Metadata.Rom.MD5Key, - DatItemField.Merge => Models.Metadata.Rom.MergeKey, - DatItemField.MIA => Models.Metadata.Rom.MIAKey, - DatItemField.Offset => Models.Metadata.Rom.OffsetKey, - DatItemField.OpenMSXSubType => Models.Metadata.Rom.OpenMSXMediaType, // TODO: Fix with Key suffix - DatItemField.OpenMSXType => Models.Metadata.Rom.OpenMSXType, // TODO: Fix with Key suffix - DatItemField.Optional => Models.Metadata.Rom.OptionalKey, - //DatItemField.Original => Models.Metadata.Rom.OriginalKey, - DatItemField.OriginalFilename => Models.Metadata.Rom.OriginalKey, - DatItemField.Region => Models.Metadata.Rom.RegionKey, - DatItemField.Remark => Models.Metadata.Rom.RemarkKey, - DatItemField.Rotation => Models.Metadata.Rom.RotationKey, - DatItemField.SHA1 => Models.Metadata.Rom.SHA1Key, - DatItemField.SHA256 => Models.Metadata.Rom.SHA256Key, - DatItemField.SHA384 => Models.Metadata.Rom.SHA384Key, - DatItemField.SHA512 => Models.Metadata.Rom.SHA512Key, - DatItemField.Size => Models.Metadata.Rom.SizeKey, - DatItemField.SpamSum => Models.Metadata.Rom.SpamSumKey, - DatItemField.Status => Models.Metadata.Rom.StatusKey, - DatItemField.Summation => Models.Metadata.Rom.SummationKey, - DatItemField.Value => Models.Metadata.Rom.ValueKey, - _ => null, - }; - - // A null value means special handling is needed - if (fieldName == null) - { - switch (datItemField) - { - case DatItemField.Boot: Boot = null; return true; - case DatItemField.Original: Original = null; return true; - } - } - - // Remove the field and return - return FieldManipulator.RemoveField(_internal, fieldName); - } - /// public override bool SetField(DatItemField datItemField, string value) { diff --git a/SabreTools.DatItems/Formats/Sample.cs b/SabreTools.DatItems/Formats/Sample.cs index 60c388e7..f1465081 100644 --- a/SabreTools.DatItems/Formats/Sample.cs +++ b/SabreTools.DatItems/Formats/Sample.cs @@ -73,19 +73,6 @@ namespace SabreTools.DatItems.Formats #region Manipulation - /// - public override bool RemoveField(DatItemField datItemField) - { - // Get the correct internal field name - string? fieldName = datItemField switch - { - _ => null, - }; - - // Remove the field and return - return FieldManipulator.RemoveField(_internal, fieldName); - } - /// public override bool SetField(DatItemField datItemField, string value) { diff --git a/SabreTools.DatItems/Formats/Serials.cs b/SabreTools.DatItems/Formats/Serials.cs index 5b0cc581..cd4f4ac0 100644 --- a/SabreTools.DatItems/Formats/Serials.cs +++ b/SabreTools.DatItems/Formats/Serials.cs @@ -178,20 +178,6 @@ namespace SabreTools.DatItems.Formats #region Manipulation - /// - public override bool RemoveField(DatItemField datItemField) - { - // Get the correct internal field name - string? fieldName = datItemField switch - { - // TODO: Figure out what fields go here - _ => null, - }; - - // Remove the field and return - return FieldManipulator.RemoveField(_internal, fieldName); - } - /// public override bool SetField(DatItemField datItemField, string value) { diff --git a/SabreTools.DatItems/Formats/SharedFeature.cs b/SabreTools.DatItems/Formats/SharedFeature.cs index c28e935e..2b1f08d2 100644 --- a/SabreTools.DatItems/Formats/SharedFeature.cs +++ b/SabreTools.DatItems/Formats/SharedFeature.cs @@ -83,20 +83,6 @@ namespace SabreTools.DatItems.Formats #region Manipulation - /// - public override bool RemoveField(DatItemField datItemField) - { - // Get the correct internal field name - string? fieldName = datItemField switch - { - DatItemField.Value => Models.Metadata.SharedFeat.ValueKey, - _ => null, - }; - - // Remove the field and return - return FieldManipulator.RemoveField(_internal, fieldName); - } - /// public override bool SetField(DatItemField datItemField, string value) { diff --git a/SabreTools.DatItems/Formats/Slot.cs b/SabreTools.DatItems/Formats/Slot.cs index 069765b3..09b90223 100644 --- a/SabreTools.DatItems/Formats/Slot.cs +++ b/SabreTools.DatItems/Formats/Slot.cs @@ -88,19 +88,6 @@ namespace SabreTools.DatItems.Formats #region Manipulation - /// - public override bool RemoveField(DatItemField datItemField) - { - // Get the correct internal field name - string? fieldName = datItemField switch - { - _ => null, - }; - - // Remove the field and return - return FieldManipulator.RemoveField(_internal, fieldName); - } - /// public override bool SetField(DatItemField datItemField, string value) { diff --git a/SabreTools.DatItems/Formats/SlotOption.cs b/SabreTools.DatItems/Formats/SlotOption.cs index bd0e5dd1..91721a69 100644 --- a/SabreTools.DatItems/Formats/SlotOption.cs +++ b/SabreTools.DatItems/Formats/SlotOption.cs @@ -96,22 +96,6 @@ namespace SabreTools.DatItems.Formats #region Manipulation - /// - public override bool RemoveField(DatItemField datItemField) - { - // Get the correct internal field name - string? fieldName = datItemField switch - { - DatItemField.Default => Models.Metadata.SlotOption.DefaultKey, - DatItemField.SlotOption_Default => Models.Metadata.SlotOption.DefaultKey, - DatItemField.SlotOption_DeviceName => Models.Metadata.SlotOption.DevNameKey, - _ => null, - }; - - // Remove the field and return - return FieldManipulator.RemoveField(_internal, fieldName); - } - /// public override bool SetField(DatItemField datItemField, string value) { diff --git a/SabreTools.DatItems/Formats/SoftwareList.cs b/SabreTools.DatItems/Formats/SoftwareList.cs index e306a8fa..a677dd10 100644 --- a/SabreTools.DatItems/Formats/SoftwareList.cs +++ b/SabreTools.DatItems/Formats/SoftwareList.cs @@ -115,22 +115,6 @@ namespace SabreTools.DatItems.Formats #region Manipulation - /// - public override bool RemoveField(DatItemField datItemField) - { - // Get the correct internal field name - string? fieldName = datItemField switch - { - DatItemField.Filter => Models.Metadata.SoftwareList.FilterKey, - DatItemField.SoftwareListStatus => Models.Metadata.SoftwareList.StatusKey, - DatItemField.Tag => Models.Metadata.SoftwareList.TagKey, - _ => null, - }; - - // Remove the field and return - return FieldManipulator.RemoveField(_internal, fieldName); - } - /// public override bool SetField(DatItemField datItemField, string value) { diff --git a/SabreTools.DatItems/Formats/Sound.cs b/SabreTools.DatItems/Formats/Sound.cs index a9c43745..c299212d 100644 --- a/SabreTools.DatItems/Formats/Sound.cs +++ b/SabreTools.DatItems/Formats/Sound.cs @@ -65,20 +65,6 @@ namespace SabreTools.DatItems.Formats #region Manipulation - /// - public override bool RemoveField(DatItemField datItemField) - { - // Get the correct internal field name - string? fieldName = datItemField switch - { - DatItemField.Default => Models.Metadata.Sound.ChannelsKey, - _ => null, - }; - - // Remove the field and return - return FieldManipulator.RemoveField(_internal, fieldName); - } - /// public override bool SetField(DatItemField datItemField, string value) { diff --git a/SabreTools.DatItems/Formats/SourceDetails.cs b/SabreTools.DatItems/Formats/SourceDetails.cs index dc779a18..72a36dfd 100644 --- a/SabreTools.DatItems/Formats/SourceDetails.cs +++ b/SabreTools.DatItems/Formats/SourceDetails.cs @@ -228,20 +228,6 @@ namespace SabreTools.DatItems.Formats #region Manipulation - /// - public override bool RemoveField(DatItemField datItemField) - { - // Get the correct internal field name - string? fieldName = datItemField switch - { - // TODO: Figure out what fields go here - _ => null, - }; - - // Remove the field and return - return FieldManipulator.RemoveField(_internal, fieldName); - } - /// public override bool SetField(DatItemField datItemField, string value) { diff --git a/SabreTools.DatItems/Machine.cs b/SabreTools.DatItems/Machine.cs index e84f268a..dff29e78 100644 --- a/SabreTools.DatItems/Machine.cs +++ b/SabreTools.DatItems/Machine.cs @@ -552,75 +552,10 @@ namespace SabreTools.DatItems /// /// Remove a field from the Machine /// - /// Machine field to remove + /// Field to remove /// True if the removal was successful, false otherwise - public bool RemoveField(MachineField machineField) - { - // Get the correct internal field name - string? fieldName = machineField switch - { - MachineField.Board => Models.Metadata.Machine.BoardKey, - MachineField.Buttons => Models.Metadata.Machine.ButtonsKey, - MachineField.Category => Models.Metadata.Machine.CategoryKey, - MachineField.CloneOf => Models.Metadata.Machine.CloneOfKey, - MachineField.CloneOfID => Models.Metadata.Machine.CloneOfIdKey, - MachineField.Comment => Models.Metadata.Machine.CommentKey, - MachineField.Control => Models.Metadata.Machine.ControlKey, - MachineField.Country => Models.Metadata.Machine.CountryKey, - //MachineField.CRC => Models.Metadata.Machine.CRCKey, - MachineField.Description => Models.Metadata.Machine.DescriptionKey, - //MachineField.Developer => Models.Metadata.Machine.DeveloperKey, - MachineField.DisplayCount => Models.Metadata.Machine.DisplayCountKey, - MachineField.DisplayType => Models.Metadata.Machine.DisplayTypeKey, - //MachineField.Enabled => Models.Metadata.Machine.EnabledKey, - MachineField.GenMSXID => Models.Metadata.Machine.GenMSXIDKey, - //MachineField.Genre => Models.Metadata.Machine.GenreKey, - MachineField.History => Models.Metadata.Machine.HistoryKey, - MachineField.ID => Models.Metadata.Machine.IdKey, - MachineField.Manufacturer => Models.Metadata.Machine.ManufacturerKey, - MachineField.Name => Models.Metadata.Machine.NameKey, - MachineField.Players => Models.Metadata.Machine.PlayersKey, - MachineField.Publisher => Models.Metadata.Machine.PublisherKey, - //MachineField.Ratings => Models.Metadata.Machine.RatingsKey, - MachineField.RebuildTo => Models.Metadata.Machine.RebuildToKey, - //MachineField.RelatedTo => Models.Metadata.Machine.RelatedToKey, - MachineField.RomOf => Models.Metadata.Machine.RomOfKey, - MachineField.Rotation => Models.Metadata.Machine.RotationKey, - MachineField.Runnable => Models.Metadata.Machine.RunnableKey, - MachineField.SampleOf => Models.Metadata.Machine.SampleOfKey, - //MachineField.Score => Models.Metadata.Machine.ScoreKey, - MachineField.SourceFile => Models.Metadata.Machine.SourceFileKey, - MachineField.Status => Models.Metadata.Machine.StatusKey, - //MachineField.Subgenre => Models.Metadata.Machine.SubgenreKey, - MachineField.Supported => Models.Metadata.Machine.SupportedKey, - MachineField.System => Models.Metadata.Machine.SystemKey, - //MachineField.TitleID => Models.Metadata.Machine.TitleIDKey, - //MachineField.Type => Models.Metadata.Machine.TypeKey, - MachineField.Year => Models.Metadata.Machine.YearKey, - _ => null, - }; - - // A null value means special handling is needed - if (fieldName == null) - { - switch (machineField) - { - case MachineField.CRC: Crc = null; return true; - case MachineField.Developer: Developer = null; return true; - case MachineField.Enabled: Enabled = null; return true; - case MachineField.Genre: Genre = null; return true; - case MachineField.Ratings: Ratings = null; return true; - case MachineField.RelatedTo: RelatedTo = null; return true; - case MachineField.Score: Score = null; return true; - case MachineField.Subgenre: Subgenre = null; return true; - case MachineField.TitleID: TitleID = null; return true; - case MachineField.Type: MachineType = MachineType.None; return true; - } - } - - // Remove the field and return - return FieldManipulator.RemoveField(_machine, fieldName); - } + public bool RemoveField(string? fieldName) + => FieldManipulator.RemoveField(_machine, fieldName); /// /// Set a field in the Machine from a mapping string diff --git a/SabreTools.Filter/FilterParser.cs b/SabreTools.Filter/FilterParser.cs index b0bbd40b..95eccbc5 100644 --- a/SabreTools.Filter/FilterParser.cs +++ b/SabreTools.Filter/FilterParser.cs @@ -4,7 +4,7 @@ using SabreTools.Models.Metadata; namespace SabreTools.Filter { - internal static class FilterParser + public static class FilterParser { /// /// Parse a filter ID string into the item name and field name, if possible diff --git a/SabreTools.Filter/TypeHelper.cs b/SabreTools.Filter/TypeHelper.cs index d382b46d..68514799 100644 --- a/SabreTools.Filter/TypeHelper.cs +++ b/SabreTools.Filter/TypeHelper.cs @@ -9,7 +9,7 @@ using SabreTools.Models.Metadata; namespace SabreTools.Filter { - internal static class TypeHelper + public static class TypeHelper { /// /// Get constant values for the given type, if possible diff --git a/SabreTools.Filtering/DatHeaderRemover.cs b/SabreTools.Filtering/DatHeaderRemover.cs deleted file mode 100644 index 0de49489..00000000 --- a/SabreTools.Filtering/DatHeaderRemover.cs +++ /dev/null @@ -1,71 +0,0 @@ -using System.Collections.Generic; - -using SabreTools.Core; -using SabreTools.Core.Tools; -using SabreTools.DatFiles; - -namespace SabreTools.Filtering -{ - /// - /// Represents the removal operations that need to be performed on a DatHeader - /// - public class DatHeaderRemover - { - #region Fields - - /// - /// List of DatHeader fields to exclude from writing - /// - public List DatHeaderFields { get; private set; } = new List(); - - #endregion - - #region Population - - /// - /// Set remover from a value - /// - /// Key for the remover to be set - public bool SetRemover(string field) - { - // If the key is null or empty, return false - if (string.IsNullOrEmpty(field)) - return false; - - // If we have a DatHeader field - DatHeaderField datHeaderField = field.AsDatHeaderField(); - if (datHeaderField != DatHeaderField.NULL) - { - DatHeaderFields.Add(datHeaderField); - return true; - } - - return false; - } - - #endregion - - #region Running - - /// - /// Remove fields with given values - /// - /// DatHeader to remove fields from - public void RemoveFields(DatHeader datHeader) - { - if (datHeader == null) - return; - - #region Common - - if (DatHeaderFields == null) - return; - - #endregion - - // TODO: Figure out how to properly implement DatHeader field removal - } - - #endregion - } -} \ No newline at end of file diff --git a/SabreTools.Filtering/DatItemRemover.cs b/SabreTools.Filtering/DatItemRemover.cs deleted file mode 100644 index e4218aee..00000000 --- a/SabreTools.Filtering/DatItemRemover.cs +++ /dev/null @@ -1,350 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using SabreTools.Core; -using SabreTools.Core.Tools; -using SabreTools.DatItems; -using SabreTools.DatItems.Formats; - -namespace SabreTools.Filtering -{ - /// - /// Represents the removal operations that need to be performed on a set of items, usually a DAT - /// - public class DatItemRemover - { - #region Fields - - /// - /// List of Machine fields to exclude from writing - /// - public List MachineFields { get; private set; } = new List(); - - /// - /// List of DatItem fields to exclude from writing - /// - public List DatItemFields { get; private set; } = new List(); - - #endregion - - #region Population - - /// - /// Set remover from a value - /// - /// Key for the remover to be set - public bool SetRemover(string field) - { - // If the key is null or empty, return false - if (string.IsNullOrEmpty(field)) - return false; - - // If we have a Machine field - MachineField machineField = field.AsMachineField(); - if (machineField != MachineField.NULL) - { - MachineFields.Add(machineField); - return true; - } - - // If we have a DatItem field - DatItemField datItemField = field.AsDatItemField(); - if (datItemField != DatItemField.NULL) - { - DatItemFields.Add(datItemField); - return true; - } - - return false; - } - - #endregion - - #region Running - - /// - /// Remove fields with given values - /// - /// DatItem to remove fields from - public void RemoveFields(DatItem? datItem) - { - if (datItem == null) - return; - - #region Common - - if (MachineFields != null && MachineFields.Any() && datItem.Machine != null) - RemoveFields(datItem.Machine); - - if (DatItemFields == null || !DatItemFields.Any()) - return; - - if (DatItemFields.Contains(DatItemField.Name)) - datItem.SetName(null); - - #endregion - - #region Item-Specific - - // Handle unnested removals first - foreach (var datItemField in DatItemFields) - { - 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 - } - - /// - /// Remove fields with given values - /// - /// Machine to remove fields from - private void RemoveFields(Machine? machine) - { - if (machine == null) - return; - - foreach (var machineField in MachineFields) - { - machine.RemoveField(machineField); - } - } - - /// - /// Remove fields with given values - /// - /// Adjuster to remove fields from - private void RemoveFields(Adjuster adjuster) - { - if (!adjuster.ConditionsSpecified) - return; - - foreach (Condition subCondition in adjuster.Conditions!) - { - RemoveFields(subCondition); - } - } - - /// - /// Remove fields with given values - /// - /// Configuration to remove fields from - private void RemoveFields(Configuration configuration) - { - if (configuration.ConditionsSpecified) - { - foreach (Condition subCondition in configuration.Conditions!) - { - RemoveFields(subCondition); - } - } - - if (configuration.LocationsSpecified) - { - foreach (ConfLocation subLocation in configuration.Locations!) - { - RemoveFields(subLocation); - } - } - - if (configuration.SettingsSpecified) - { - foreach (ConfSetting subSetting in configuration.Settings!) - { - RemoveFields(subSetting as DatItem); - } - } - } - - /// - /// Remove fields with given values - /// - /// ConfSetting to remove fields from - private void RemoveFields(ConfSetting confsetting) - { - if (confsetting.ConditionsSpecified) - { - foreach (Condition subCondition in confsetting.Conditions!) - { - RemoveFields(subCondition); - } - } - } - - /// - /// Remove fields with given values - /// - /// Device to remove fields from - private void RemoveFields(Device device) - { - if (device.ExtensionsSpecified) - { - foreach (Extension subExtension in device.Extensions!) - { - RemoveFields(subExtension); - } - } - - if (device.InstancesSpecified) - { - foreach (Instance subInstance in device.Instances!) - { - RemoveFields(subInstance); - } - } - } - - /// - /// Remove fields with given values - /// - /// DipSwitch to remove fields from - private void RemoveFields(DipSwitch dipSwitch) - { - if (dipSwitch.ConditionsSpecified) - { - foreach (Condition subCondition in dipSwitch.Conditions!) - { - RemoveFields(subCondition); - } - } - - if (dipSwitch.LocationsSpecified) - { - foreach (DipLocation subLocation in dipSwitch.Locations!) - { - RemoveFields(subLocation); - } - } - - if (dipSwitch.ValuesSpecified) - { - foreach (DipValue subValue in dipSwitch.Values!) - { - RemoveFields(subValue as DatItem); - } - } - - if (dipSwitch.PartSpecified) - RemoveFields(dipSwitch.Part! as DatItem); - } - - /// - /// Remove fields with given values - /// - /// DipValue to remove fields from - private void RemoveFields(DipValue dipValue) - { - if (dipValue.ConditionsSpecified) - { - foreach (Condition subCondition in dipValue.Conditions!) - { - RemoveFields(subCondition); - } - } - } - - /// - /// Remove fields with given values - /// - /// Disk to remove fields from - private void RemoveFields(Disk disk) - { - if (disk.DiskAreaSpecified) - RemoveFields(disk.DiskArea); - - if (disk.PartSpecified) - RemoveFields(disk.Part! as DatItem); - } - - /// - /// Remove fields with given values - /// - /// Input to remove fields from - private void RemoveFields(Input input) - { - if (input.ControlsSpecified) - { - foreach (Control subControl in input.Controls!) - { - RemoveFields(subControl); - } - } - } - - /// - /// Remove fields with given values - /// - /// Part to remove fields from - private void RemoveFields(Part part) - { - if (part.FeaturesSpecified) - { - foreach (PartFeature subPartFeature in part.Features!) - { - RemoveFields(subPartFeature); - } - } - } - - /// - /// Remove fields with given values - /// - /// Port to remove fields from - private void RemoveFields(Port port) - { - if (port.AnalogsSpecified) - { - foreach (Analog subAnalog in port.Analogs!) - { - RemoveFields(subAnalog); - } - } - } - - /// - /// Remove fields with given values - /// - /// Rom to remove fields from - private void RemoveFields(Rom rom) - { - if (rom.DataAreaSpecified) - RemoveFields(rom.DataArea!); - - if (rom.PartSpecified) - RemoveFields(rom.Part! as DatItem); - } - - /// - /// Remove fields with given values - /// - /// Slot to remove fields from - private void RemoveFields(Slot slot) - { - if (slot.SlotOptionsSpecified) - { - foreach (SlotOption subSlotOption in slot.SlotOptions!) - { - RemoveFields(subSlotOption); - } - } - } - - #endregion - } -} \ No newline at end of file diff --git a/SabreTools.Filtering/Remover.cs b/SabreTools.Filtering/Remover.cs index e53dd822..dca6ebfa 100644 --- a/SabreTools.Filtering/Remover.cs +++ b/SabreTools.Filtering/Remover.cs @@ -4,8 +4,11 @@ using System.Linq; using System.Threading.Tasks; #endif using SabreTools.Core; +using SabreTools.Core.Tools; using SabreTools.DatFiles; using SabreTools.DatItems; +using SabreTools.DatItems.Formats; +using SabreTools.Filter; using SabreTools.Logging; namespace SabreTools.Filtering @@ -18,14 +21,19 @@ namespace SabreTools.Filtering #region Fields /// - /// DatItemRemover to remove fields from DatHeaders + /// List of header fields to exclude from writing /// - public DatHeaderRemover? DatHeaderRemover { get; set; } + public List HeaderFieldNames { get; } = []; /// - /// DatItemRemover to remove fields from DatItems + /// List of machine fields to exclude from writing /// - public DatItemRemover? DatItemRemover { get; set; } + public List MachineFieldNames { get; } = []; + + /// + /// List of fields to exclude from writing + /// + public Dictionary> ItemFieldNames { get; } = []; #endregion @@ -52,43 +60,71 @@ namespace SabreTools.Filtering #region Population + /// + /// Populate the exclusion objects using a field name + /// + /// Field names + public void PopulateExclusions(string field) + => PopulateExclusionsFromList([field]); + /// /// Populate the exclusion objects using a set of field names /// /// List of field names public void PopulateExclusionsFromList(List? fields) { - // Instantiate the removers, if necessary - DatHeaderRemover ??= new DatHeaderRemover(); - DatItemRemover ??= new DatItemRemover(); - // If the list is null or empty, just return if (fields == null || fields.Count == 0) return; - InternalStopwatch watch = new("Populating removals from list"); + var watch = new InternalStopwatch("Populating removals from list"); foreach (string field in fields) { - // If we don't even have a possible field name - if (field == null) - continue; - - // DatHeader fields - if (DatHeaderRemover.SetRemover(field)) - continue; - - // Machine and DatItem fields - if (DatItemRemover.SetRemover(field)) - continue; - - // If we didn't match anything, log an error - logger.Warning($"The value {field} did not match any known field names. Please check the wiki for more details on supported field names."); + 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."); } watch.Stop(); } + /// + /// Set remover from a value + /// + /// Key for the remover to be set + private bool SetRemover(string field) + { + // If the key is null or empty, return false + if (string.IsNullOrEmpty(field)) + return false; + + // Get the parser pair out of it, if possible + (string? key, string? value) = FilterParser.ParseFilterId(field); + if (key != null && value != null) + { + switch (key) + { + case Models.Metadata.MetadataFile.HeaderKey: + HeaderFieldNames.Add(value); + return true; + + case Models.Metadata.MetadataFile.MachineKey: + MachineFieldNames.Add(value); + return true; + + default: + if (!ItemFieldNames.ContainsKey(key)) + ItemFieldNames[key] = []; + + ItemFieldNames[key].Add(value); + return true; + } + } + + return false; + } + #endregion #region Running @@ -99,18 +135,14 @@ namespace SabreTools.Filtering /// Current DatFile object to run operations on public void ApplyRemovals(DatFile datFile) { - // If the removers don't exist, we can't use it - if (DatHeaderRemover == null && DatItemRemover == null) - return; - InternalStopwatch watch = new("Applying removals to DAT"); // Remove DatHeader fields - if (DatHeaderRemover != null && DatHeaderRemover.DatHeaderFields.Any()) - DatHeaderRemover.RemoveFields(datFile.Header); + if (HeaderFieldNames.Any()) + RemoveFields(datFile.Header); // Remove DatItem and Machine fields - if (DatItemRemover != null && (DatItemRemover.MachineFields.Any() || DatItemRemover.DatItemFields.Any())) + if (MachineFieldNames.Any() || ItemFieldNames.Any()) { #if NET452_OR_GREATER || NETCOREAPP Parallel.ForEach(datFile.Items.Keys, Globals.ParallelOptions, key => @@ -130,7 +162,7 @@ namespace SabreTools.Filtering for (int j = 0; j < items.Count; j++) { - DatItemRemover.RemoveFields(items[j]); + RemoveFields(items[j]); } datFile.Items.Remove(key); @@ -145,6 +177,330 @@ namespace SabreTools.Filtering watch.Stop(); } + /// + /// Remove fields with given values + /// + /// DatHeader to remove fields from + public void RemoveFields(DatHeader datHeader) + { + if (datHeader == null) + return; + + // If there are no field names, return + if (HeaderFieldNames == null || !HeaderFieldNames.Any()) + return; + + foreach (var fieldName in HeaderFieldNames) + { + // TODO: Impelement in DatHeader + //datHeader.RemoveField(fieldName); + } + } + + /// + /// Remove fields with given values + /// + /// Machine to remove fields from + public void RemoveFields(Machine? machine) + { + if (machine == null) + return; + + // If there are no field names, return + if (MachineFieldNames == null || !MachineFieldNames.Any()) + return; + + foreach (var fieldName in MachineFieldNames) + { + machine.RemoveField(fieldName); + } + } + + /// + /// Remove fields with given values + /// + /// DatItem to remove fields from + public void RemoveFields(DatItem? datItem) + { + if (datItem == null) + return; + + #region Common + + // Handle Machine fields + if (MachineFieldNames != null && MachineFieldNames.Any() && datItem.Machine != null) + 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(); + if (itemType == null || (!ItemFieldNames.ContainsKey(itemType) && !ItemFieldNames.ContainsKey("item"))) + return; + + // Get the combined list of fields to remove + var fieldNames = new List(); + 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 + } + + /// + /// Remove fields with given values + /// + /// Adjuster to remove fields from + private void RemoveFields(Adjuster adjuster) + { + if (!adjuster.ConditionsSpecified) + return; + + foreach (Condition subCondition in adjuster.Conditions!) + { + RemoveFields(subCondition); + } + } + + /// + /// Remove fields with given values + /// + /// Configuration to remove fields from + private void RemoveFields(Configuration configuration) + { + if (configuration.ConditionsSpecified) + { + foreach (Condition subCondition in configuration.Conditions!) + { + RemoveFields(subCondition); + } + } + + if (configuration.LocationsSpecified) + { + foreach (ConfLocation subLocation in configuration.Locations!) + { + RemoveFields(subLocation); + } + } + + if (configuration.SettingsSpecified) + { + foreach (ConfSetting subSetting in configuration.Settings!) + { + RemoveFields(subSetting as DatItem); + } + } + } + + /// + /// Remove fields with given values + /// + /// ConfSetting to remove fields from + private void RemoveFields(ConfSetting confsetting) + { + if (confsetting.ConditionsSpecified) + { + foreach (Condition subCondition in confsetting.Conditions!) + { + RemoveFields(subCondition); + } + } + } + + /// + /// Remove fields with given values + /// + /// Device to remove fields from + private void RemoveFields(Device device) + { + if (device.ExtensionsSpecified) + { + foreach (Extension subExtension in device.Extensions!) + { + RemoveFields(subExtension); + } + } + + if (device.InstancesSpecified) + { + foreach (Instance subInstance in device.Instances!) + { + RemoveFields(subInstance); + } + } + } + + /// + /// Remove fields with given values + /// + /// DipSwitch to remove fields from + private void RemoveFields(DipSwitch dipSwitch) + { + if (dipSwitch.ConditionsSpecified) + { + foreach (Condition subCondition in dipSwitch.Conditions!) + { + RemoveFields(subCondition); + } + } + + if (dipSwitch.LocationsSpecified) + { + foreach (DipLocation subLocation in dipSwitch.Locations!) + { + RemoveFields(subLocation); + } + } + + if (dipSwitch.ValuesSpecified) + { + foreach (DipValue subValue in dipSwitch.Values!) + { + RemoveFields(subValue as DatItem); + } + } + + if (dipSwitch.PartSpecified) + RemoveFields(dipSwitch.Part! as DatItem); + } + + /// + /// Remove fields with given values + /// + /// DipValue to remove fields from + private void RemoveFields(DipValue dipValue) + { + if (dipValue.ConditionsSpecified) + { + foreach (Condition subCondition in dipValue.Conditions!) + { + RemoveFields(subCondition); + } + } + } + + /// + /// Remove fields with given values + /// + /// Disk to remove fields from + private void RemoveFields(Disk disk) + { + if (disk.DiskAreaSpecified) + RemoveFields(disk.DiskArea); + + if (disk.PartSpecified) + RemoveFields(disk.Part! as DatItem); + } + + /// + /// Remove fields with given values + /// + /// Input to remove fields from + private void RemoveFields(Input input) + { + if (input.ControlsSpecified) + { + foreach (Control subControl in input.Controls!) + { + RemoveFields(subControl); + } + } + } + + /// + /// Remove fields with given values + /// + /// Part to remove fields from + private void RemoveFields(Part part) + { + if (part.FeaturesSpecified) + { + foreach (PartFeature subPartFeature in part.Features!) + { + RemoveFields(subPartFeature); + } + } + } + + /// + /// Remove fields with given values + /// + /// Port to remove fields from + private void RemoveFields(Port port) + { + if (port.AnalogsSpecified) + { + foreach (Analog subAnalog in port.Analogs!) + { + RemoveFields(subAnalog); + } + } + } + + /// + /// Remove fields with given values + /// + /// Rom to remove fields from + private void RemoveFields(Rom rom) + { + if (rom.DataAreaSpecified) + RemoveFields(rom.DataArea!); + + if (rom.PartSpecified) + RemoveFields(rom.Part! as DatItem); + } + + /// + /// Remove fields with given values + /// + /// Slot to remove fields from + private void RemoveFields(Slot slot) + { + if (slot.SlotOptionsSpecified) + { + foreach (SlotOption subSlotOption in slot.SlotOptions!) + { + RemoveFields(subSlotOption); + } + } + } + #endregion } } \ No newline at end of file diff --git a/SabreTools.Test/Filtering/PopulationTests.cs b/SabreTools.Test/Filtering/PopulationTests.cs index a6a14d3c..933db414 100644 --- a/SabreTools.Test/Filtering/PopulationTests.cs +++ b/SabreTools.Test/Filtering/PopulationTests.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; - using SabreTools.Filtering; using Xunit; @@ -18,29 +17,25 @@ namespace SabreTools.Test.Filtering remover.PopulateExclusionsFromList(exclusions); // Check the exclusion lists - Assert.NotNull(remover.DatHeaderRemover); - Assert.NotNull(remover.DatItemRemover); - Assert.Empty(remover.DatHeaderRemover.DatHeaderFields); - Assert.Empty(remover.DatItemRemover.MachineFields); - Assert.Empty(remover.DatItemRemover.DatItemFields); + Assert.Empty(remover.HeaderFieldNames); + Assert.Empty(remover.MachineFieldNames); + Assert.Empty(remover.ItemFieldNames); } [Fact] public void PopulateExclusionEmptyListTest() { // Setup the list - List exclusions = new(); + List exclusions = []; // Setup the remover var remover = new Remover(); remover.PopulateExclusionsFromList(exclusions); // Check the exclusion lists - Assert.NotNull(remover.DatHeaderRemover); - Assert.NotNull(remover.DatItemRemover); - Assert.Empty(remover.DatHeaderRemover.DatHeaderFields); - Assert.Empty(remover.DatItemRemover.MachineFields); - Assert.Empty(remover.DatItemRemover.DatItemFields); + Assert.Empty(remover.HeaderFieldNames); + Assert.Empty(remover.MachineFieldNames); + Assert.Empty(remover.ItemFieldNames); } [Fact] @@ -57,11 +52,9 @@ namespace SabreTools.Test.Filtering remover.PopulateExclusionsFromList(exclusions); // Check the exclusion lists - Assert.NotNull(remover.DatHeaderRemover); - Assert.NotNull(remover.DatItemRemover); - Assert.Single(remover.DatHeaderRemover.DatHeaderFields); - Assert.Empty(remover.DatItemRemover.MachineFields); - Assert.Empty(remover.DatItemRemover.DatItemFields); + Assert.Empty(remover.HeaderFieldNames); + Assert.Empty(remover.MachineFieldNames); + Assert.Empty(remover.ItemFieldNames); } [Fact] @@ -78,11 +71,9 @@ namespace SabreTools.Test.Filtering remover.PopulateExclusionsFromList(exclusions); // Check the exclusion lists - Assert.NotNull(remover.DatHeaderRemover); - Assert.NotNull(remover.DatItemRemover); - Assert.Empty(remover.DatHeaderRemover.DatHeaderFields); - Assert.Single(remover.DatItemRemover.MachineFields); - Assert.Empty(remover.DatItemRemover.DatItemFields); + Assert.Empty(remover.HeaderFieldNames); + Assert.Single(remover.MachineFieldNames); + Assert.Empty(remover.ItemFieldNames); } [Fact] @@ -99,11 +90,9 @@ namespace SabreTools.Test.Filtering remover.PopulateExclusionsFromList(exclusions); // Check the exclusion lists - Assert.NotNull(remover.DatHeaderRemover); - Assert.NotNull(remover.DatItemRemover); - Assert.Empty(remover.DatHeaderRemover.DatHeaderFields); - Assert.Empty(remover.DatItemRemover.MachineFields); - Assert.Single(remover.DatItemRemover.DatItemFields); + Assert.Empty(remover.HeaderFieldNames); + Assert.Empty(remover.MachineFieldNames); + Assert.Single(remover.ItemFieldNames); } [Fact] diff --git a/SabreTools.Test/Filtering/RemoverTests.cs b/SabreTools.Test/Filtering/RemoverTests.cs index d0c64c7c..b706fd52 100644 --- a/SabreTools.Test/Filtering/RemoverTests.cs +++ b/SabreTools.Test/Filtering/RemoverTests.cs @@ -11,8 +11,8 @@ namespace SabreTools.Test.Filtering public void RemoveFieldsDatItemTest() { var datItem = CreateDatItem(); - var remover = new DatItemRemover(); - remover.SetRemover("DatItem.Name"); + var remover = new Remover(); + remover.PopulateExclusions("DatItem.Name"); remover.RemoveFields(datItem); Assert.Null(datItem.GetName()); } @@ -21,8 +21,8 @@ namespace SabreTools.Test.Filtering public void RemoveFieldsMachineTest() { var datItem = CreateDatItem(); - var remover = new DatItemRemover(); - remover.SetRemover("Machine.Name"); + var remover = new Remover(); + remover.PopulateExclusions("Machine.Name"); remover.RemoveFields(datItem); Assert.Null(datItem.Machine.Name); }