diff --git a/SabreTools.DatFiles/Setter.cs b/SabreTools.DatFiles/Setter.cs index da6d70f0..90e34ba2 100644 --- a/SabreTools.DatFiles/Setter.cs +++ b/SabreTools.DatFiles/Setter.cs @@ -176,6 +176,7 @@ namespace SabreTools.DatFiles /// DatItem to set fields on public void SetFields(DatItem datItem) { + // If we have an invalid input, return if (datItem == null) return; diff --git a/SabreTools.DatItems/DatItem.cs b/SabreTools.DatItems/DatItem.cs index fddb546d..72d9e3a8 100644 --- a/SabreTools.DatItems/DatItem.cs +++ b/SabreTools.DatItems/DatItem.cs @@ -394,7 +394,17 @@ namespace SabreTools.DatItems /// /// Field to remove /// True if the removal was successful, false otherwise - public bool RemoveField(string? fieldName) => FieldManipulator.RemoveField(_internal, fieldName); + public bool RemoveField(string? fieldName) + => FieldManipulator.RemoveField(_internal, fieldName); + + /// + /// Replace a field from another DatItem + /// + /// DatItem to replace field from + /// Field to replace + /// True if the replacement was successful, false otherwise + public bool ReplaceField(DatItem? other, string? fieldName) + => FieldManipulator.ReplaceField(other?._internal, _internal, fieldName); /// /// Set a field in the DatItem from a mapping string @@ -403,7 +413,8 @@ namespace SabreTools.DatItems /// 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); + public bool SetField(string? fieldName, string value) + => FieldManipulator.SetField(_internal, fieldName, value); #endregion diff --git a/SabreTools.DatItems/Machine.cs b/SabreTools.DatItems/Machine.cs index 4ee374b4..128e78a4 100644 --- a/SabreTools.DatItems/Machine.cs +++ b/SabreTools.DatItems/Machine.cs @@ -557,6 +557,15 @@ namespace SabreTools.DatItems public bool RemoveField(string? fieldName) => FieldManipulator.RemoveField(_machine, fieldName); + /// + /// Replace a field from another Machine + /// + /// Machine to replace field from + /// Field to replace + /// True if the replacement was successful, false otherwise + public bool ReplaceField(Machine? other, string? fieldName) + => FieldManipulator.ReplaceField(other?._machine, _machine, fieldName); + /// /// Set a field in the Machine from a mapping string /// diff --git a/SabreTools.DatTools/DatFileTool.cs b/SabreTools.DatTools/DatFileTool.cs index d5b53263..76220d2c 100644 --- a/SabreTools.DatTools/DatFileTool.cs +++ b/SabreTools.DatTools/DatFileTool.cs @@ -95,20 +95,20 @@ namespace SabreTools.DatTools /// /// Current DatFile object to use for updating /// DatFile to replace the values in - /// List of MachineFields representing what should be updated - /// List of DatItemFields representing what should be updated + /// List of machine field names representing what should be updated + /// List of item field names representing what should be updated /// True if descriptions should only be replaced if the game name is the same, false otherwise public static void BaseReplace( DatFile datFile, DatFile intDat, - List machineFields, - List datItemFields, + List machineFieldNames, + Dictionary> itemFieldNames, bool onlySame) { InternalStopwatch watch = new($"Replacing items in '{intDat.Header.FileName}' from the base DAT"); // If we are matching based on DatItem fields of any sort - if (datItemFields.Any()) + if (itemFieldNames.Any()) { // For comparison's sake, we want to use CRC as the base bucketing datFile.Items.BucketBy(ItemKey.CRC, DedupeType.Full); @@ -140,7 +140,7 @@ namespace SabreTools.DatTools // Replace fields from the first duplicate, if we have one if (dupes.Count > 0) - Replacer.ReplaceFields(newDatItem, dupes.First(), datItemFields); + Replacer.ReplaceFields(newDatItem, dupes.First(), itemFieldNames); newDatItems.Add(newDatItem); } @@ -156,7 +156,7 @@ namespace SabreTools.DatTools } // If we are matching based on Machine fields of any sort - if (machineFields.Any()) + if (machineFieldNames.Any()) { // For comparison's sake, we want to use Machine Name as the base bucketing datFile.Items.BucketBy(ItemKey.Machine, DedupeType.Full); @@ -189,7 +189,7 @@ namespace SabreTools.DatTools continue; if (datFile.Items.ContainsKey(key) && list.Count > 0) - Replacer.ReplaceFields(newDatItem.Machine, list[0].Machine, machineFields, onlySame); + Replacer.ReplaceFields(newDatItem.Machine, list[0].Machine, machineFieldNames, onlySame); newDatItems.Add(newDatItem); } diff --git a/SabreTools.Filter/FieldManipulator.cs b/SabreTools.Filter/FieldManipulator.cs index 4bec43f6..b4e2cf47 100644 --- a/SabreTools.Filter/FieldManipulator.cs +++ b/SabreTools.Filter/FieldManipulator.cs @@ -1,7 +1,6 @@ using System; using System.Linq; using System.Text.RegularExpressions; -using SabreTools.Core; using SabreTools.Models.Metadata; namespace SabreTools.Filter diff --git a/SabreTools.Filtering/Replacer.cs b/SabreTools.Filtering/Replacer.cs index a4174e23..2b76ca1b 100644 --- a/SabreTools.Filtering/Replacer.cs +++ b/SabreTools.Filtering/Replacer.cs @@ -1,5 +1,7 @@ using System.Collections.Generic; +using System.Linq; using SabreTools.Core; +using SabreTools.Core.Tools; using SabreTools.DatItems; using SabreTools.DatItems.Formats; @@ -10,15 +12,45 @@ namespace SabreTools.Filtering /// public static class Replacer { + /// + /// Replace fields with given values + /// + /// Machine to replace fields in + /// Machine to pull new information from + /// List of fields representing what should be updated + /// True if descriptions should only be replaced if the game name is the same, false otherwise + public static void ReplaceFields(Machine machine, Machine repMachine, List machineFieldNames, bool onlySame) + { + // If we have an invalid input, return + if (machine == null || repMachine == null || machineFieldNames == null) + return; + + // Loop through and replace fields + foreach (string fieldName in machineFieldNames) + { + // Special case for description + if (machineFieldNames.Contains(Models.Metadata.Machine.DescriptionKey)) + { + if (!onlySame || (onlySame && machine.Name == machine.Description)) + machine.Description = repMachine.Description; + + continue; + } + + machine.ReplaceField(repMachine, fieldName); + } + } + /// /// Replace fields with given values /// /// DatItem to replace fields in /// DatItem to pull new information from - /// List of fields representing what should be updated - public static void ReplaceFields(DatItem datItem, DatItem repDatItem, List datItemFields) + /// List of fields representing what should be updated + public static void ReplaceFields(DatItem datItem, DatItem repDatItem, Dictionary> itemFieldNames) { - if (datItem == null || repDatItem == null || datItemFields == null) + // If we have an invalid input, return + if (datItem == null || repDatItem == null || itemFieldNames == null) return; #region Common @@ -26,539 +58,42 @@ namespace SabreTools.Filtering if (datItem.ItemType != repDatItem.ItemType) return; - if (datItemFields.Contains(DatItemField.Name)) + // 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(repDatItem.GetName()); #endregion #region Item-Specific - if (datItem is Adjuster) ReplaceFields((datItem as Adjuster)!, (repDatItem as Adjuster)!, datItemFields); - else if (datItem is Analog) ReplaceFields((datItem as Analog)!, (repDatItem as Analog)!, datItemFields); - else if (datItem is Archive) ReplaceFields((datItem as Archive)!, (repDatItem as Archive)!, datItemFields); - else if (datItem is BiosSet) ReplaceFields((datItem as BiosSet)!, (repDatItem as BiosSet)!, datItemFields); - else if (datItem is Chip) ReplaceFields((datItem as Chip)!, (repDatItem as Chip)!, datItemFields); - else if (datItem is Condition) ReplaceFields((datItem as Condition)!, (repDatItem as Condition)!, datItemFields); - else if (datItem is Configuration) ReplaceFields((datItem as Configuration)!, (repDatItem as Configuration)!, datItemFields); - else if (datItem is ConfLocation) ReplaceFields((datItem as ConfLocation)!, (repDatItem as ConfLocation)!, datItemFields); - else if (datItem is ConfSetting) ReplaceFields((datItem as ConfSetting)!, (repDatItem as ConfSetting)!, datItemFields); - else if (datItem is Control) ReplaceFields((datItem as Control)!, (repDatItem as Control)!, datItemFields); - else if (datItem is DataArea) ReplaceFields((datItem as DataArea)!, (repDatItem as DataArea)!, datItemFields); - else if (datItem is Device) ReplaceFields((datItem as Device)!, (repDatItem as Device)!, datItemFields); - else if (datItem is DipLocation) ReplaceFields((datItem as DipLocation)!, (repDatItem as DipLocation)!, datItemFields); - else if (datItem is DipSwitch) ReplaceFields((datItem as DipSwitch)!, (repDatItem as DipSwitch)!, datItemFields); - else if (datItem is DipValue) ReplaceFields((datItem as DipValue)!, (repDatItem as DipValue)!, datItemFields); - else if (datItem is Disk) ReplaceFields((datItem as Disk)!, (repDatItem as Disk)!, datItemFields); - else if (datItem is DiskArea) ReplaceFields((datItem as DiskArea)!, (repDatItem as DiskArea)!, datItemFields); - else if (datItem is Display) ReplaceFields((datItem as Display)!, (repDatItem as Display)!, datItemFields); - else if (datItem is Driver) ReplaceFields((datItem as Driver)!, (repDatItem as Driver)!, datItemFields); - else if (datItem is Extension) ReplaceFields((datItem as Extension)!, (repDatItem as Extension)!, datItemFields); - else if (datItem is Feature) ReplaceFields((datItem as Feature)!, (repDatItem as Feature)!, datItemFields); - else if (datItem is Info) ReplaceFields((datItem as Info)!, (repDatItem as Info)!, datItemFields); - else if (datItem is Input) ReplaceFields((datItem as Input)!, (repDatItem as Input)!, datItemFields); - else if (datItem is Instance) ReplaceFields((datItem as Instance)!, (repDatItem as Instance)!, datItemFields); - else if (datItem is Media) ReplaceFields((datItem as Media)!, (repDatItem as Media)!, datItemFields); - else if (datItem is Part) ReplaceFields((datItem as Part)!, (repDatItem as Part)!, datItemFields); - else if (datItem is PartFeature) ReplaceFields((datItem as PartFeature)!, (repDatItem as PartFeature)!, datItemFields); - else if (datItem is Port) ReplaceFields((datItem as Port)!, (repDatItem as Port)!, datItemFields); - else if (datItem is RamOption) ReplaceFields((datItem as RamOption)!, (repDatItem as RamOption)!, datItemFields); - else if (datItem is Release) ReplaceFields((datItem as Release)!, (repDatItem as Release)!, datItemFields); - else if (datItem is Rom) ReplaceFields((datItem as Rom)!, (repDatItem as Rom)!, datItemFields); - else if (datItem is SharedFeature) ReplaceFields((datItem as SharedFeature)!, (repDatItem as SharedFeature)!, datItemFields); - else if (datItem is Slot) ReplaceFields((datItem as Slot)!, (repDatItem as Slot)!, datItemFields); - else if (datItem is SlotOption) ReplaceFields((datItem as SlotOption)!, (repDatItem as SlotOption)!, datItemFields); - else if (datItem is SoftwareList) ReplaceFields((datItem as SoftwareList)!, (repDatItem as SoftwareList)!, datItemFields); - else if (datItem is Sound) ReplaceFields((datItem as Sound)!, (repDatItem as Sound)!, datItemFields); - - #endregion - } - - /// - /// Replace fields with given values - /// - /// Machine to replace fields in - /// Machine to pull new information from - /// List of fields representing what should be updated - /// True if descriptions should only be replaced if the game name is the same, false otherwise - public static void ReplaceFields(Machine machine, Machine repMachine, List machineFields, bool onlySame) - { - if (machineFields.Contains(MachineField.Board)) - machine.Board = repMachine.Board; - - if (machineFields.Contains(MachineField.Buttons)) - machine.Buttons = repMachine.Buttons; - - if (machineFields.Contains(MachineField.Category)) - machine.Category = repMachine.Category; - - if (machineFields.Contains(MachineField.CloneOf)) - machine.CloneOf = repMachine.CloneOf; - - if (machineFields.Contains(MachineField.CloneOfID)) - machine.NoIntroCloneOfId = repMachine.NoIntroCloneOfId; - - if (machineFields.Contains(MachineField.Comment)) - machine.Comment = repMachine.Comment; - - if (machineFields.Contains(MachineField.Control)) - machine.Control = repMachine.Control; - - if (machineFields.Contains(MachineField.Country)) - machine.Country = repMachine.Country; - - if (machineFields.Contains(MachineField.CRC)) - machine.Crc = repMachine.Crc; - - if (machineFields.Contains(MachineField.Description)) + // Handle unnested sets first + foreach (var fieldName in fieldNames) { - if (!onlySame || (onlySame && machine.Name == machine.Description)) - machine.Description = repMachine.Description; + datItem.ReplaceField(repDatItem, fieldName); } - if (machineFields.Contains(MachineField.Developer)) - machine.Developer = repMachine.Developer; - - if (machineFields.Contains(MachineField.DisplayCount)) - machine.DisplayCount = repMachine.DisplayCount; - - if (machineFields.Contains(MachineField.DisplayType)) - machine.DisplayType = repMachine.DisplayType; - - if (machineFields.Contains(MachineField.Enabled)) - machine.Enabled = repMachine.Enabled; - - if (machineFields.Contains(MachineField.GenMSXID)) - machine.GenMSXID = repMachine.GenMSXID; - - if (machineFields.Contains(MachineField.Genre)) - machine.Genre = repMachine.Genre; - - if (machineFields.Contains(MachineField.History)) - machine.History = repMachine.History; - - if (machineFields.Contains(MachineField.ID)) - machine.NoIntroId = repMachine.NoIntroId; - - if (machineFields.Contains(MachineField.Manufacturer)) - machine.Manufacturer = repMachine.Manufacturer; - - if (machineFields.Contains(MachineField.Name)) - machine.Name = repMachine.Name; - - if (machineFields.Contains(MachineField.Players)) - machine.Players = repMachine.Players; - - if (machineFields.Contains(MachineField.Publisher)) - machine.Publisher = repMachine.Publisher; - - if (machineFields.Contains(MachineField.Ratings)) - machine.Ratings = repMachine.Ratings; - - if (machineFields.Contains(MachineField.RebuildTo)) - machine.RebuildTo = repMachine.RebuildTo; - - if (machineFields.Contains(MachineField.RelatedTo)) - machine.RelatedTo = repMachine.RelatedTo; - - if (machineFields.Contains(MachineField.RomOf)) - machine.RomOf = repMachine.RomOf; - - if (machineFields.Contains(MachineField.Rotation)) - machine.Rotation = repMachine.Rotation; - - if (machineFields.Contains(MachineField.Runnable)) - machine.Runnable = repMachine.Runnable; - - if (machineFields.Contains(MachineField.SampleOf)) - machine.SampleOf = repMachine.SampleOf; - - if (machineFields.Contains(MachineField.Score)) - machine.Score = repMachine.Score; - - if (machineFields.Contains(MachineField.SourceFile)) - machine.SourceFile = repMachine.SourceFile; - - if (machineFields.Contains(MachineField.Status)) - machine.Status = repMachine.Status; - - if (machineFields.Contains(MachineField.Subgenre)) - machine.Subgenre = repMachine.Subgenre; - - if (machineFields.Contains(MachineField.Supported)) - machine.Supported = repMachine.Supported; - - if (machineFields.Contains(MachineField.System)) - machine.System = repMachine.System; - - if (machineFields.Contains(MachineField.TitleID)) - machine.TitleID = repMachine.TitleID; - - if (machineFields.Contains(MachineField.Type)) - machine.MachineType = repMachine.MachineType; - - if (machineFields.Contains(MachineField.Year)) - machine.Year = repMachine.Year; - } - - /// - /// Replace fields with given values - /// - /// Adjuster to remove replace fields in - /// Adjuster to pull new information from - /// List of fields representing what should be updated - private static void ReplaceFields(Adjuster adjuster, Adjuster newItem, List datItemFields) - { - if (datItemFields.Contains(DatItemField.Default)) - adjuster.Default = newItem.Default; - - // Condition_* doesn't make sense here - // since not every condition under the other item - // can replace every condition under this item - } - - /// - /// Replace fields with given values - /// - /// Analog to remove replace fields in - /// Analog to pull new information from - /// List of fields representing what should be updated - private static void ReplaceFields(Analog analog, Analog newItem, List datItemFields) - { - if (datItemFields.Contains(DatItemField.Analog_Mask)) - analog.Mask = newItem.Mask; - } - - /// - /// Replace fields with given values - /// - /// Archive to remove replace fields in - /// Archive to pull new information from - /// List of fields representing what should be updated - private static void ReplaceFields(Archive archive, Archive newItem, List datItemFields) - { - if (datItemFields.Contains(DatItemField.Categories)) - archive.Categories = newItem.Categories; - - if (datItemFields.Contains(DatItemField.Clone)) - archive.CloneValue = newItem.CloneValue; - - if (datItemFields.Contains(DatItemField.Complete)) - archive.Complete = newItem.Complete; - - if (datItemFields.Contains(DatItemField.DevStatus)) - archive.DevStatus = newItem.DevStatus; - - if (datItemFields.Contains(DatItemField.Languages)) - archive.Languages = newItem.Languages; - - if (datItemFields.Contains(DatItemField.Number)) - archive.Number = newItem.Number; - - if (datItemFields.Contains(DatItemField.Physical)) - archive.Physical = newItem.Physical; - - if (datItemFields.Contains(DatItemField.Region)) - archive.Region = newItem.Region; - - if (datItemFields.Contains(DatItemField.RegParent)) - archive.RegParent = newItem.RegParent; - } - - /// - /// Replace fields with given values - /// - /// BiosSet to remove replace fields in - /// BiosSet to pull new information from - /// List of fields representing what should be updated - private static void ReplaceFields(BiosSet biosSet, BiosSet newItem, List datItemFields) - { - if (datItemFields.Contains(DatItemField.Default)) - biosSet.Default = newItem.Default; - - if (datItemFields.Contains(DatItemField.Description)) - biosSet.Description = newItem.Description; - } - - /// - /// Replace fields with given values - /// - /// Chip to remove replace fields in - /// Chip to pull new information from - /// List of fields representing what should be updated - private static void ReplaceFields(Chip chip, Chip newItem, List datItemFields) - { - if (datItemFields.Contains(DatItemField.ChipType)) - chip.ChipType = newItem.ChipType; - - if (datItemFields.Contains(DatItemField.Clock)) - chip.Clock = newItem.Clock; - - if (datItemFields.Contains(DatItemField.Tag)) - chip.Tag = newItem.Tag; - } - - /// - /// Replace fields with given values - /// - /// Condition to remove replace fields in - /// Condition to pull new information from - /// List of fields representing what should be updated - private static void ReplaceFields(Condition condition, Condition newItem, List datItemFields) - { - if (datItemFields.Contains(DatItemField.Mask)) - condition.Mask = newItem.Mask; - else if (datItemFields.Contains(DatItemField.Condition_Mask)) - condition.Mask = newItem.Mask; - - if (datItemFields.Contains(DatItemField.Relation)) - condition.Relation = newItem.Relation; - else if (datItemFields.Contains(DatItemField.Condition_Relation)) - condition.Relation = newItem.Relation; - - if (datItemFields.Contains(DatItemField.Tag)) - condition.Tag = newItem.Tag; - else if (datItemFields.Contains(DatItemField.Condition_Tag)) - condition.Tag = newItem.Tag; - - if (datItemFields.Contains(DatItemField.Value)) - condition.Value = newItem.Value; - else if (datItemFields.Contains(DatItemField.Condition_Value)) - condition.Value = newItem.Value; - } - - /// - /// Replace fields with given values - /// - /// Configuration to remove replace fields in - /// Configuration to pull new information from - /// List of fields representing what should be updated - private static void ReplaceFields(Configuration configuration, Configuration newItem, List datItemFields) - { - if (datItemFields.Contains(DatItemField.Mask)) - configuration.Mask = newItem.Mask; - - if (datItemFields.Contains(DatItemField.Tag)) - configuration.Tag = newItem.Tag; - - // Condition_* doesn't make sense here - // since not every condition under the other item - // can replace every condition under this item - - // Location_* doesn't make sense here - // since not every location under the other item - // can replace every location under this item - - // Setting_* doesn't make sense here - // since not every setting under the other item - // can replace every setting under this item - } - - /// - /// Replace fields with given values - /// - /// ConfLocation to remove replace fields in - /// ConfLocation to pull new information from - /// List of fields representing what should be updated - private static void ReplaceFields(ConfLocation location, ConfLocation newItem, List datItemFields) - { - if (datItemFields.Contains(DatItemField.Location_Inverted)) - location.Inverted = newItem.Inverted; - - if (datItemFields.Contains(DatItemField.Location_Name)) - location.Name = newItem.Name; - - if (datItemFields.Contains(DatItemField.Location_Number)) - location.Number = newItem.Number; - } - - /// - /// Replace fields with given values - /// - /// ConfSetting to remove replace fields in - /// ConfSetting to pull new information from - /// List of fields representing what should be updated - private static void ReplaceFields(ConfSetting confSetting, ConfSetting newItem, List datItemFields) - { - if (datItemFields.Contains(DatItemField.Setting_Default)) - confSetting.Default = newItem.Default; - - if (datItemFields.Contains(DatItemField.Setting_Name)) - confSetting.Name = newItem.Name; - - if (datItemFields.Contains(DatItemField.Setting_Value)) - confSetting.Value = newItem.Value; - - // Condition_* doesn't make sense here - // since not every condition under the other item - // can replace every condition under this item - } - - /// - /// Replace fields with given values - /// - /// Control to remove replace fields in - /// Control to pull new information from - /// List of fields representing what should be updated - private static void ReplaceFields(Control control, Control newItem, List datItemFields) - { - if (datItemFields.Contains(DatItemField.Control_Buttons)) - control.Buttons = newItem.Buttons; - - if (datItemFields.Contains(DatItemField.Control_Type)) - control.ControlType = newItem.ControlType; - - if (datItemFields.Contains(DatItemField.Control_KeyDelta)) - control.KeyDelta = newItem.KeyDelta; - - if (datItemFields.Contains(DatItemField.Control_Maximum)) - control.Maximum = newItem.Maximum; - - if (datItemFields.Contains(DatItemField.Control_Minimum)) - control.Minimum = newItem.Minimum; - - if (datItemFields.Contains(DatItemField.Control_Player)) - control.Player = newItem.Player; - - if (datItemFields.Contains(DatItemField.Control_RequiredButtons)) - control.RequiredButtons = newItem.RequiredButtons; - - if (datItemFields.Contains(DatItemField.Control_Reverse)) - control.Reverse = newItem.Reverse; - - if (datItemFields.Contains(DatItemField.Control_Sensitivity)) - control.Sensitivity = newItem.Sensitivity; - - if (datItemFields.Contains(DatItemField.Control_Ways)) - control.Ways = newItem.Ways; - - if (datItemFields.Contains(DatItemField.Control_Ways2)) - control.Ways2 = newItem.Ways2; - - if (datItemFields.Contains(DatItemField.Control_Ways3)) - control.Ways3 = newItem.Ways3; - } - - /// - /// Replace fields with given values - /// - /// DataArea to remove replace fields in - /// DataArea to pull new information from - /// List of fields representing what should be updated - private static void ReplaceFields(DataArea dataArea, DataArea newItem, List datItemFields) - { - if (datItemFields.Contains(DatItemField.AreaEndianness)) - dataArea.Endianness = newItem.Endianness; - - if (datItemFields.Contains(DatItemField.AreaName)) - dataArea.Name = newItem.Name; - - if (datItemFields.Contains(DatItemField.AreaSize)) - dataArea.Size = newItem.Size; - - if (datItemFields.Contains(DatItemField.AreaWidth)) - dataArea.Width = newItem.Width; - } - - /// - /// Replace fields with given values - /// - /// Device to remove replace fields in - /// Device to pull new information from - /// List of fields representing what should be updated - private static void ReplaceFields(Device device, Device newItem, List datItemFields) - { - if (datItemFields.Contains(DatItemField.DeviceType)) - device.DeviceType = newItem.DeviceType; - - if (datItemFields.Contains(DatItemField.FixedImage)) - device.FixedImage = newItem.FixedImage; - - if (datItemFields.Contains(DatItemField.Interface)) - device.Interface = newItem.Interface; - - if (datItemFields.Contains(DatItemField.Mandatory)) - device.Mandatory = newItem.Mandatory; - - if (datItemFields.Contains(DatItemField.Tag)) - device.Tag = newItem.Tag; - - // Instance_* doesn't make sense here - // since not every instance under the other item - // can replace every instance under this item - - // Extension_* doesn't make sense here - // since not every extension under the other item - // can replace every extension under this item - } - - /// - /// Replace fields with given values - /// - /// DipLocation to remove replace fields in - /// DipLocation to pull new information from - /// List of fields representing what should be updated - private static void ReplaceFields(DipLocation location, DipLocation newItem, List datItemFields) - { - if (datItemFields.Contains(DatItemField.Location_Inverted)) - location.Inverted = newItem.Inverted; - - if (datItemFields.Contains(DatItemField.Location_Name)) - location.Name = newItem.Name; - - if (datItemFields.Contains(DatItemField.Location_Number)) - location.Number = newItem.Number; - } - - /// - /// Replace fields with given values - /// - /// DipSwitch to remove replace fields in - /// DipSwitch to pull new information from - /// List of fields representing what should be updated - private static void ReplaceFields(DipSwitch dipSwitch, DipSwitch newItem, List datItemFields) - { - if (datItemFields.Contains(DatItemField.Mask)) - dipSwitch.Mask = newItem.Mask; - - if (datItemFields.Contains(DatItemField.Tag)) - dipSwitch.Tag = newItem.Tag; - - // Condition_* doesn't make sense here - // since not every condition under the other item - // can replace every condition under this item - - // Location_* doesn't make sense here - // since not every location under the other item - // can replace every location under this item - - // Setting_* doesn't make sense here - // since not every value under the other item - // can replace every value under this item - - if (dipSwitch.PartSpecified && newItem.PartSpecified) - ReplaceFields(dipSwitch.Part!, newItem.Part!, datItemFields); - } - - /// - /// Replace fields with given values - /// - /// DipValue to remove replace fields in - /// DipValue to pull new information from - /// List of fields representing what should be updated - private static void ReplaceFields(DipValue dipValue, DipValue newItem, List datItemFields) - { - if (datItemFields.Contains(DatItemField.Setting_Default)) - dipValue.Default = newItem.Default; - - if (datItemFields.Contains(DatItemField.Setting_Name)) - dipValue.Name = newItem.Name; - - if (datItemFields.Contains(DatItemField.Setting_Value)) - dipValue.Value = newItem.Value; - - // Condition_* doesn't make sense here - // since not every condition under the other item - // can replace every condition under this item + // Handle nested sets + switch (datItem, repDatItem) + { + case (Disk disk, Disk repDisk): ReplaceFields(disk, repDisk, fieldNames); break; + case (Media media, Media repMedia): ReplaceFields(media, repMedia, fieldNames); break; + case (Rom rom, Rom repRom): ReplaceFields(rom, repRom, fieldNames); break; + } + + #endregion } /// @@ -567,221 +102,19 @@ namespace SabreTools.Filtering /// Disk to remove replace fields in /// Disk to pull new information from /// List of fields representing what should be updated - private static void ReplaceFields(Disk disk, Disk newItem, List datItemFields) + private static void ReplaceFields(Disk disk, Disk newItem, List datItemFields) { - if (datItemFields.Contains(DatItemField.Index)) - disk.Index = newItem.Index; - - if (datItemFields.Contains(DatItemField.Status)) - disk.ItemStatus = newItem.ItemStatus; - - if (datItemFields.Contains(DatItemField.MD5)) + if (datItemFields.Contains(Models.Metadata.Disk.MD5Key)) { if (string.IsNullOrEmpty(disk.MD5) && !string.IsNullOrEmpty(newItem.MD5)) disk.MD5 = newItem.MD5; } - if (datItemFields.Contains(DatItemField.Merge)) - disk.MergeTag = newItem.MergeTag; - - if (datItemFields.Contains(DatItemField.Optional)) - disk.Optional = newItem.Optional; - - if (datItemFields.Contains(DatItemField.SHA1)) + if (datItemFields.Contains(Models.Metadata.Disk.SHA1Key)) { if (string.IsNullOrEmpty(disk.SHA1) && !string.IsNullOrEmpty(newItem.SHA1)) disk.SHA1 = newItem.SHA1; } - - if (datItemFields.Contains(DatItemField.Region)) - disk.Region = newItem.Region; - - if (datItemFields.Contains(DatItemField.Writable)) - disk.Writable = newItem.Writable; - - if (disk.DiskAreaSpecified && newItem.DiskAreaSpecified) - ReplaceFields(disk.DiskArea!, newItem.DiskArea!, datItemFields); - - if (disk.PartSpecified && newItem.PartSpecified) - ReplaceFields(disk.Part!, newItem.Part!, datItemFields); - } - - /// - /// Replace fields with given values - /// - /// DiskArea to remove replace fields in - /// DiskArea to pull new information from - /// List of fields representing what should be updated - private static void ReplaceFields(DiskArea diskArea, DiskArea newItem, List datItemFields) - { - if (datItemFields.Contains(DatItemField.AreaName)) - diskArea.Name = newItem.Name; - } - - /// - /// Replace fields with given values - /// - /// Display to remove replace fields in - /// Display to pull new information from - /// List of fields representing what should be updated - private static void ReplaceFields(Display display, Display newItem, List datItemFields) - { - if (datItemFields.Contains(DatItemField.DisplayType)) - display.DisplayType = newItem.DisplayType; - - if (datItemFields.Contains(DatItemField.FlipX)) - display.FlipX = newItem.FlipX; - - if (datItemFields.Contains(DatItemField.HBEnd)) - display.HBEnd = newItem.HBEnd; - - if (datItemFields.Contains(DatItemField.HBStart)) - display.HBStart = newItem.HBStart; - - if (datItemFields.Contains(DatItemField.Height)) - display.Height = newItem.Height; - - if (datItemFields.Contains(DatItemField.HTotal)) - display.HTotal = newItem.HTotal; - - if (datItemFields.Contains(DatItemField.PixClock)) - display.PixClock = newItem.PixClock; - - if (datItemFields.Contains(DatItemField.Refresh)) - display.Refresh = newItem.Refresh; - - if (datItemFields.Contains(DatItemField.Rotate)) - display.Rotate = newItem.Rotate; - - if (datItemFields.Contains(DatItemField.Tag)) - display.Tag = newItem.Tag; - - if (datItemFields.Contains(DatItemField.VBEnd)) - display.VBEnd = newItem.VBEnd; - - if (datItemFields.Contains(DatItemField.VBStart)) - display.VBStart = newItem.VBStart; - - if (datItemFields.Contains(DatItemField.VTotal)) - display.VTotal = newItem.VTotal; - - if (datItemFields.Contains(DatItemField.Width)) - display.Width = newItem.Width; - } - - /// - /// Replace fields with given values - /// - /// Driver to remove replace fields in - /// Driver to pull new information from - /// List of fields representing what should be updated - private static void ReplaceFields(Driver driver, Driver newItem, List datItemFields) - { - if (datItemFields.Contains(DatItemField.CocktailStatus)) - driver.Cocktail = newItem.Cocktail; - - if (datItemFields.Contains(DatItemField.EmulationStatus)) - driver.Emulation = newItem.Emulation; - - if (datItemFields.Contains(DatItemField.Incomplete)) - driver.Incomplete = newItem.Incomplete; - - if (datItemFields.Contains(DatItemField.NoSoundHardware)) - driver.NoSoundHardware = newItem.NoSoundHardware; - - if (datItemFields.Contains(DatItemField.RequiresArtwork)) - driver.RequiresArtwork = newItem.RequiresArtwork; - - if (datItemFields.Contains(DatItemField.SaveStateStatus)) - driver.SaveState = newItem.SaveState; - - if (datItemFields.Contains(DatItemField.SupportStatus)) - driver.Status = newItem.Status; - - if (datItemFields.Contains(DatItemField.Unofficial)) - driver.Unofficial = newItem.Unofficial; - } - - /// - /// Replace fields with given values - /// - /// Extension to remove replace fields in - /// Extension to pull new information from - /// List of fields representing what should be updated - private static void ReplaceFields(Extension extension, Extension newItem, List datItemFields) - { - if (datItemFields.Contains(DatItemField.Extension_Name)) - extension.Name = newItem.Name; - } - - /// - /// Replace fields with given values - /// - /// Feature to remove replace fields in - /// Feature to pull new information from - /// List of fields representing what should be updated - private static void ReplaceFields(Feature feature, Feature newItem, List datItemFields) - { - if (datItemFields.Contains(DatItemField.FeatureOverall)) - feature.Overall = newItem.Overall; - - if (datItemFields.Contains(DatItemField.FeatureStatus)) - feature.Status = newItem.Status; - - if (datItemFields.Contains(DatItemField.FeatureType)) - feature.Type = newItem.Type; - } - - /// - /// Replace fields with given values - /// - /// Info to remove replace fields in - /// Info to pull new information from - /// List of fields representing what should be updated - private static void ReplaceFields(Info info, Info newItem, List datItemFields) - { - if (datItemFields.Contains(DatItemField.Value)) - info.Value = newItem.Value; - } - - /// - /// Replace fields with given values - /// - /// Input to remove replace fields in - /// Input to pull new information from - /// List of fields representing what should be updated - private static void ReplaceFields(Input input, Input newItem, List datItemFields) - { - if (datItemFields.Contains(DatItemField.Coins)) - input.Coins = newItem.Coins; - - if (datItemFields.Contains(DatItemField.Players)) - input.Players = newItem.Players; - - if (datItemFields.Contains(DatItemField.Service)) - input.Service = newItem.Service; - - if (datItemFields.Contains(DatItemField.Tilt)) - input.Tilt = newItem.Tilt; - - // Control_* doesn't make sense here - // since not every control under the other item - // can replace every control under this item - } - - /// - /// Replace fields with given values - /// - /// Instance to remove replace fields in - /// Instance to pull new information from - /// List of fields representing what should be updated - private static void ReplaceFields(Instance instance, Instance newItem, List datItemFields) - { - if (datItemFields.Contains(DatItemField.Instance_BriefName)) - instance.BriefName = newItem.BriefName; - - if (datItemFields.Contains(DatItemField.Instance_Name)) - instance.Name = newItem.Name; } /// @@ -790,319 +123,82 @@ namespace SabreTools.Filtering /// Media to remove replace fields in /// Media to pull new information from /// List of fields representing what should be updated - private static void ReplaceFields(Media media, Media newItem, List datItemFields) + private static void ReplaceFields(Media media, Media newItem, List datItemFields) { - if (datItemFields.Contains(DatItemField.MD5)) + if (datItemFields.Contains(Models.Metadata.Media.MD5Key)) { if (string.IsNullOrEmpty(media.MD5) && !string.IsNullOrEmpty(newItem.MD5)) media.MD5 = newItem.MD5; } - if (datItemFields.Contains(DatItemField.SHA1)) + if (datItemFields.Contains(Models.Metadata.Media.SHA1Key)) { if (string.IsNullOrEmpty(media.SHA1) && !string.IsNullOrEmpty(newItem.SHA1)) media.SHA1 = newItem.SHA1; } - if (datItemFields.Contains(DatItemField.SHA256)) + if (datItemFields.Contains(Models.Metadata.Media.SHA256Key)) { if (string.IsNullOrEmpty(media.SHA256) && !string.IsNullOrEmpty(newItem.SHA256)) media.SHA256 = newItem.SHA256; } - if (datItemFields.Contains(DatItemField.SpamSum)) + if (datItemFields.Contains(Models.Metadata.Media.SpamSumKey)) { if (string.IsNullOrEmpty(media.SpamSum) && !string.IsNullOrEmpty(newItem.SpamSum)) media.SpamSum = newItem.SpamSum; } } - /// - /// Replace fields with given values - /// - /// Part to remove replace fields in - /// Part to pull new information from - /// List of fields representing what should be updated - private static void ReplaceFields(Part part, Part newItem, List datItemFields) - { - if (datItemFields.Contains(DatItemField.Part_Interface)) - part.Interface = newItem.Interface; - - if (datItemFields.Contains(DatItemField.Part_Name)) - part.Name = newItem.Name; - - // Part_Feature_* doesn't make sense here - // since not every part feature under the other item - // can replace every part feature under this item - } - - /// - /// Replace fields with given values - /// - /// PartFeature to remove replace fields in - /// PartFeature to pull new information from - /// List of fields representing what should be updated - private static void ReplaceFields(PartFeature partFeature, PartFeature newItem, List datItemFields) - { - if (datItemFields.Contains(DatItemField.Part_Feature_Name)) - partFeature.Name = newItem.Name; - - if (datItemFields.Contains(DatItemField.Part_Feature_Value)) - partFeature.Value = newItem.Value; - } - - /// - /// Replace fields with given values - /// - /// Port to remove replace fields in - /// Port to pull new information from - /// List of fields representing what should be updated - private static void ReplaceFields(Port port, Port newItem, List datItemFields) - { - if (datItemFields.Contains(DatItemField.Tag)) - port.Tag = newItem.Tag; - - // Analog_* doesn't make sense here - // since not every analog under the other item - // can replace every analog under this item - } - - /// - /// Replace fields with given values - /// - /// RamOption to remove replace fields in - /// RamOption to pull new information from - /// List of fields representing what should be updated - private static void ReplaceFields(RamOption ramOption, RamOption newItem, List datItemFields) - { - if (datItemFields.Contains(DatItemField.Content)) - ramOption.Content = newItem.Content; - - if (datItemFields.Contains(DatItemField.Default)) - ramOption.Default = newItem.Default; - } - - /// - /// Replace fields with given values - /// - /// Release to remove replace fields in - /// Release to pull new information from - /// List of fields representing what should be updated - private static void ReplaceFields(Release release, Release newItem, List datItemFields) - { - if (datItemFields.Contains(DatItemField.Date)) - release.Date = newItem.Date; - - if (datItemFields.Contains(DatItemField.Default)) - release.Default = newItem.Default; - - if (datItemFields.Contains(DatItemField.Language)) - release.Language = newItem.Language; - - if (datItemFields.Contains(DatItemField.Region)) - release.Region = newItem.Region; - } - /// /// Replace fields with given values /// /// Rom to remove replace fields in /// Rom to pull new information from /// List of fields representing what should be updated - private static void ReplaceFields(Rom rom, Rom newItem, List datItemFields) + private static void ReplaceFields(Rom rom, Rom newItem, List datItemFields) { - if (datItemFields.Contains(DatItemField.ArchiveDotOrgFormat)) - rom.ArchiveDotOrgFormat = newItem.ArchiveDotOrgFormat; - - if (datItemFields.Contains(DatItemField.ArchiveDotOrgSource)) - rom.ArchiveDotOrgSource = newItem.ArchiveDotOrgSource; - - if (datItemFields.Contains(DatItemField.AltName)) - rom.AltName = newItem.AltName; - - if (datItemFields.Contains(DatItemField.AltTitle)) - rom.AltTitle = newItem.AltTitle; - - if (datItemFields.Contains(DatItemField.Bios)) - rom.Bios = newItem.Bios; - - if (datItemFields.Contains(DatItemField.Boot)) - rom.Boot = newItem.Boot; - - if (datItemFields.Contains(DatItemField.CRC)) + if (datItemFields.Contains(Models.Metadata.Rom.CRCKey)) { if (string.IsNullOrEmpty(rom.CRC) && !string.IsNullOrEmpty(newItem.CRC)) rom.CRC = newItem.CRC; } - if (datItemFields.Contains(DatItemField.Date)) - rom.Date = newItem.Date; - - if (datItemFields.Contains(DatItemField.Inverted)) - rom.Inverted = newItem.Inverted; - - if (datItemFields.Contains(DatItemField.LoadFlag)) - rom.LoadFlag = newItem.LoadFlag; - - if (datItemFields.Contains(DatItemField.MD5)) + if (datItemFields.Contains(Models.Metadata.Rom.MD5Key)) { if (string.IsNullOrEmpty(rom.MD5) && !string.IsNullOrEmpty(newItem.MD5)) rom.MD5 = newItem.MD5; } - if (datItemFields.Contains(DatItemField.Merge)) - rom.MergeTag = newItem.MergeTag; - - if (datItemFields.Contains(DatItemField.MIA)) - rom.MIA = newItem.MIA; - - if (datItemFields.Contains(DatItemField.Offset)) - rom.Offset = newItem.Offset; - - if (datItemFields.Contains(DatItemField.OpenMSXSubType)) - rom.OpenMSXSubType = newItem.OpenMSXSubType; - - if (datItemFields.Contains(DatItemField.OpenMSXType)) - rom.OpenMSXType = newItem.OpenMSXType; - - if (datItemFields.Contains(DatItemField.Optional)) - rom.Optional = newItem.Optional; - - if (datItemFields.Contains(DatItemField.Original)) - rom.Original = newItem.Original; - - if (datItemFields.Contains(DatItemField.OriginalFilename)) - rom.OriginalFilename = newItem.OriginalFilename; - - if (datItemFields.Contains(DatItemField.Region)) - rom.Region = newItem.Region; - - if (datItemFields.Contains(DatItemField.Remark)) - rom.Remark = newItem.Remark; - - if (datItemFields.Contains(DatItemField.Rotation)) - rom.Rotation = newItem.Rotation; - - if (datItemFields.Contains(DatItemField.SHA1)) + if (datItemFields.Contains(Models.Metadata.Rom.SHA1Key)) { if (string.IsNullOrEmpty(rom.SHA1) && !string.IsNullOrEmpty(newItem.SHA1)) rom.SHA1 = newItem.SHA1; } - if (datItemFields.Contains(DatItemField.SHA256)) + if (datItemFields.Contains(Models.Metadata.Rom.SHA256Key)) { if (string.IsNullOrEmpty(rom.SHA256) && !string.IsNullOrEmpty(newItem.SHA256)) rom.SHA256 = newItem.SHA256; } - if (datItemFields.Contains(DatItemField.SHA384)) + if (datItemFields.Contains(Models.Metadata.Rom.SHA384Key)) { if (string.IsNullOrEmpty(rom.SHA384) && !string.IsNullOrEmpty(newItem.SHA384)) rom.SHA384 = newItem.SHA384; } - if (datItemFields.Contains(DatItemField.SHA512)) + if (datItemFields.Contains(Models.Metadata.Rom.SHA512Key)) { if (string.IsNullOrEmpty(rom.SHA512) && !string.IsNullOrEmpty(newItem.SHA512)) rom.SHA512 = newItem.SHA512; } - if (datItemFields.Contains(DatItemField.Size)) - rom.Size = newItem.Size; - - if (datItemFields.Contains(DatItemField.SpamSum)) + if (datItemFields.Contains(Models.Metadata.Rom.SpamSumKey)) { if (string.IsNullOrEmpty(rom.SpamSum) && !string.IsNullOrEmpty(newItem.SpamSum)) rom.SpamSum = newItem.SpamSum; } - - if (datItemFields.Contains(DatItemField.Status)) - rom.ItemStatus = newItem.ItemStatus; - - if (datItemFields.Contains(DatItemField.Summation)) - rom.Summation = newItem.Summation; - - if (datItemFields.Contains(DatItemField.Value)) - rom.Value = newItem.Value; - - if (rom.DataAreaSpecified && newItem.DataAreaSpecified) - ReplaceFields(rom.DataArea!, newItem.DataArea!, datItemFields); - - if (rom.PartSpecified && newItem.PartSpecified) - ReplaceFields(rom.Part!, newItem.Part!, datItemFields); - } - - /// - /// Replace fields with given values - /// - /// SharedFeature to remove replace fields in - /// SharedFeature to pull new information from - /// List of fields representing what should be updated - private static void ReplaceFields(SharedFeature sharedFeature, SharedFeature newItem, List datItemFields) - { - if (datItemFields.Contains(DatItemField.Value)) - sharedFeature.Value = newItem.Value; - } - - /// - /// Replace fields with given values - /// - /// Slot to remove replace fields in - /// Slot to pull new information from - /// List of fields representing what should be updated - private static void ReplaceFields(Slot slot, Slot newItem, List datItemFields) - { - // SlotOption_* doesn't make sense here - // since not every slot option under the other item - // can replace every slot option under this item - } - - /// - /// Replace fields with given values - /// - /// SlotOption to remove replace fields in - /// SlotOption to pull new information from - /// List of fields representing what should be updated - private static void ReplaceFields(SlotOption slotOption, SlotOption newItem, List datItemFields) - { - if (datItemFields.Contains(DatItemField.SlotOption_Default)) - slotOption.Default = newItem.Default; - - if (datItemFields.Contains(DatItemField.SlotOption_DeviceName)) - slotOption.DeviceName = newItem.DeviceName; - - if (datItemFields.Contains(DatItemField.SlotOption_Name)) - slotOption.Name = newItem.Name; - } - - /// - /// Replace fields with given values - /// - /// SoftwareList to remove replace fields in - /// SoftwareList to pull new information from - /// List of fields representing what should be updated - private static void ReplaceFields(SoftwareList softwareList, SoftwareList newItem, List datItemFields) - { - if (datItemFields.Contains(DatItemField.Filter)) - softwareList.Filter = newItem.Filter; - - if (datItemFields.Contains(DatItemField.SoftwareListStatus)) - softwareList.Status = newItem.Status; - - if (datItemFields.Contains(DatItemField.Tag)) - softwareList.Tag = newItem.Tag; - } - - /// - /// Replace fields with given values - /// - /// Sound to remove replace fields in - /// Sound to pull new information from - /// List of fields representing what should be updated - private static void ReplaceFields(Sound sound, Sound newItem, List datItemFields) - { - if (datItemFields.Contains(DatItemField.Channels)) - sound.Channels = newItem.Channels; } } } \ No newline at end of file diff --git a/SabreTools.Test/Filtering/ReplacerTests.cs b/SabreTools.Test/Filtering/ReplacerTests.cs index da4130f5..3bcd947a 100644 --- a/SabreTools.Test/Filtering/ReplacerTests.cs +++ b/SabreTools.Test/Filtering/ReplacerTests.cs @@ -16,7 +16,10 @@ namespace SabreTools.Test.Filtering var datItem = CreateDatItem(); var repDatItem = CreateDatItem(); repDatItem.SetName("bar"); - var fields = new List { DatItemField.Name }; + var fields = new Dictionary> + { + ["item"] = [Models.Metadata.Rom.NameKey] + }; Replacer.ReplaceFields(datItem, repDatItem, fields); Assert.Equal("bar", datItem.GetName()); } @@ -27,7 +30,7 @@ namespace SabreTools.Test.Filtering var datItem = CreateDatItem(); var repDatItem = CreateDatItem(); repDatItem.Machine.Name = "foo"; - var fields = new List { MachineField.Name }; + List fields = [Models.Metadata.Machine.NameKey]; Replacer.ReplaceFields(datItem.Machine, repDatItem.Machine, fields, false); Assert.Equal("foo", datItem.Machine.Name); } diff --git a/SabreTools/Features/BaseFeature.cs b/SabreTools/Features/BaseFeature.cs index 0fe027aa..a293022e 100644 --- a/SabreTools/Features/BaseFeature.cs +++ b/SabreTools/Features/BaseFeature.cs @@ -2046,28 +2046,37 @@ Some special strings that can be used: } /// - /// Get update DatItem fields from feature list + /// Get update Machine fields from feature list /// - protected static List GetUpdateDatItemFields(Dictionary features) + protected static List GetUpdateMachineFields(Dictionary features) { - List updateFields = new(); + List updateFields = []; foreach (string fieldName in GetList(features, UpdateFieldListValue)) { - updateFields.Add(fieldName.AsDatItemField()); + (string? itemType, string? key) = SabreTools.Filter.FilterParser.ParseFilterId(fieldName); + if (itemType == Models.Metadata.MetadataFile.MachineKey) + updateFields.Add(key); } return updateFields; } /// - /// Get update Machine fields from feature list + /// Get update DatItem fields from feature list /// - protected static List GetUpdateMachineFields(Dictionary features) + protected static Dictionary> GetUpdateDatItemFields(Dictionary features) { - List updateFields = new(); + Dictionary> updateFields = []; foreach (string fieldName in GetList(features, UpdateFieldListValue)) { - updateFields.Add(fieldName.AsMachineField()); + (string? itemType, string? key) = SabreTools.Filter.FilterParser.ParseFilterId(fieldName); + if (itemType != Models.Metadata.MetadataFile.HeaderKey && itemType != Models.Metadata.MetadataFile.MachineKey) + { + if (!updateFields.ContainsKey(itemType)) + updateFields[itemType] = []; + + updateFields[itemType].Add(key); + } } return updateFields; diff --git a/SabreTools/Features/Update.cs b/SabreTools/Features/Update.cs index 73053815..94a9add5 100644 --- a/SabreTools/Features/Update.cs +++ b/SabreTools/Features/Update.cs @@ -90,8 +90,8 @@ namespace SabreTools.Features return false; // Get feature flags - var updateDatItemFields = GetUpdateDatItemFields(features); - var updateMachineFields = GetUpdateMachineFields(features); + var updateMachineFieldNames = GetUpdateMachineFields(features); + var updateItemFieldNames = GetUpdateDatItemFields(features); var updateMode = GetUpdateMode(features); // Normalize the extensions @@ -138,8 +138,11 @@ namespace SabreTools.Features } // If no update fields are set, default to Names - if (updateDatItemFields == null || updateDatItemFields.Count == 0) - updateDatItemFields = new List() { DatItemField.Name }; + if (updateItemFieldNames == null || updateItemFieldNames.Count == 0) + { + updateItemFieldNames = []; + updateItemFieldNames["item"] = [Models.Metadata.Rom.NameKey]; + } // Ensure we only have files in the inputs List inputPaths = PathTool.GetFilesOnly(Inputs, appendparent: true); @@ -391,8 +394,8 @@ namespace SabreTools.Features DatFileTool.BaseReplace( userInputDat, repDat, - updateMachineFields, - updateDatItemFields, + updateMachineFieldNames, + updateItemFieldNames, GetBoolean(features, OnlySameValue)); // Finally output the replaced DatFile