mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Field removal to their own classes
This commit is contained in:
@@ -56,7 +56,15 @@ namespace RombaSharp.Features
|
||||
datfile.Header.Name = string.IsNullOrWhiteSpace(name) ? "untitled" : name;
|
||||
datfile.Header.Description = description;
|
||||
DatFromDir.PopulateFromDir(datfile, source, asFiles: TreatAsFile.NonArchive);
|
||||
Modification.ApplyCleaning(datfile, new Cleaner() { ExcludeDatItemFields = Hash.DeepHashes.AsDatItemFields() });
|
||||
Cleaner cleaner = new Cleaner();
|
||||
cleaner.PopulateExclusionsFromList(new List<string>
|
||||
{
|
||||
"DatItem.SHA256",
|
||||
"DatItem.SHA384",
|
||||
"DatItem.SHA512",
|
||||
"DatItem.SpamSum",
|
||||
});
|
||||
Modification.ApplyCleaning(datfile, cleaner);
|
||||
Writer.Write(datfile, outdat);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Xml.Serialization;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
using SabreTools.Core;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
@@ -13,968 +13,6 @@ namespace SabreTools.DatItems
|
||||
/// </summary>
|
||||
public static class DatItemTool
|
||||
{
|
||||
/// <summary>
|
||||
/// Remove fields with given values
|
||||
/// </summary>
|
||||
/// <param name="datItem">DatItem to remove fields from</param>
|
||||
/// <param name="datItemFields">DatItem fields to remove</param>
|
||||
/// <param name="machineFields">Machine fields to remove</param>
|
||||
/// <param name="sub">True if this is a subitem, false otherwise</param>
|
||||
public static void RemoveFields(
|
||||
DatItem datItem,
|
||||
List<DatItemField> datItemFields = null,
|
||||
List<MachineField> machineFields = null,
|
||||
bool sub = false)
|
||||
{
|
||||
if (datItem == null)
|
||||
return;
|
||||
|
||||
#region Common
|
||||
|
||||
if (machineFields != null && datItem.Machine != null)
|
||||
RemoveFields(datItem.Machine, machineFields);
|
||||
|
||||
if (datItemFields == null)
|
||||
return;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.Name))
|
||||
datItem.SetName(null);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Adjuster
|
||||
|
||||
if (datItem is Adjuster adjuster)
|
||||
{
|
||||
if (datItemFields.Contains(DatItemField.Default))
|
||||
adjuster.Default = null;
|
||||
|
||||
if (adjuster.ConditionsSpecified)
|
||||
{
|
||||
foreach (Condition subCondition in adjuster.Conditions)
|
||||
{
|
||||
RemoveFields(subCondition, datItemFields, machineFields, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Analog
|
||||
|
||||
else if (datItem is Analog analog)
|
||||
{
|
||||
if (datItemFields.Contains(DatItemField.Analog_Mask))
|
||||
analog.Mask = null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region BiosSet
|
||||
|
||||
else if (datItem is BiosSet biosSet)
|
||||
{
|
||||
if (datItemFields.Contains(DatItemField.Description))
|
||||
biosSet.Description = null;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.Default))
|
||||
biosSet.Default = null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Chip
|
||||
|
||||
else if (datItem is Chip chip)
|
||||
{
|
||||
if (datItemFields.Contains(DatItemField.Tag))
|
||||
chip.Tag = null;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.ChipType))
|
||||
chip.ChipType = ChipType.NULL;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.Clock))
|
||||
chip.Clock = null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Condition
|
||||
|
||||
else if (datItem is Condition condition)
|
||||
{
|
||||
if (sub)
|
||||
{
|
||||
if (datItemFields.Contains(DatItemField.Condition_Tag))
|
||||
condition.Tag = null;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.Condition_Mask))
|
||||
condition.Mask = null;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.Condition_Relation))
|
||||
condition.Relation = Relation.NULL;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.Condition_Value))
|
||||
condition.Value = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (datItemFields.Contains(DatItemField.Tag))
|
||||
condition.Tag = null;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.Mask))
|
||||
condition.Mask = null;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.Relation))
|
||||
condition.Relation = Relation.NULL;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.Value))
|
||||
condition.Value = null;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Configuration
|
||||
|
||||
else if (datItem is Configuration configuration)
|
||||
{
|
||||
if (datItemFields.Contains(DatItemField.Tag))
|
||||
configuration.Tag = null;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.Mask))
|
||||
configuration.Mask = null;
|
||||
|
||||
if (configuration.ConditionsSpecified)
|
||||
{
|
||||
foreach (Condition subCondition in configuration.Conditions)
|
||||
{
|
||||
RemoveFields(subCondition, datItemFields, machineFields, true);
|
||||
}
|
||||
}
|
||||
|
||||
if (configuration.LocationsSpecified)
|
||||
{
|
||||
foreach (Location subLocation in configuration.Locations)
|
||||
{
|
||||
RemoveFields(subLocation, datItemFields, machineFields);
|
||||
}
|
||||
}
|
||||
|
||||
if (configuration.SettingsSpecified)
|
||||
{
|
||||
foreach (Setting subSetting in configuration.Settings)
|
||||
{
|
||||
RemoveFields(subSetting, datItemFields, machineFields);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Control
|
||||
|
||||
else if (datItem is Control control)
|
||||
{
|
||||
if (datItemFields.Contains(DatItemField.Control_Type))
|
||||
control.ControlType = ControlType.NULL;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.Control_Player))
|
||||
control.Player = null;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.Control_Buttons))
|
||||
control.Buttons = null;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.Control_RequiredButtons))
|
||||
control.RequiredButtons = null;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.Control_Minimum))
|
||||
control.Minimum = null;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.Control_Maximum))
|
||||
control.Maximum = null;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.Control_Sensitivity))
|
||||
control.Sensitivity = null;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.Control_KeyDelta))
|
||||
control.KeyDelta = null;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.Control_Reverse))
|
||||
control.Reverse = null;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.Control_Ways))
|
||||
control.Ways = null;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.Control_Ways2))
|
||||
control.Ways2 = null;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.Control_Ways3))
|
||||
control.Ways3 = null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region DataArea
|
||||
|
||||
else if (datItem is DataArea dataArea)
|
||||
{
|
||||
if (datItemFields.Contains(DatItemField.AreaName))
|
||||
dataArea.Name = null;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.AreaSize))
|
||||
dataArea.Size = null;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.AreaWidth))
|
||||
dataArea.Width = null;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.AreaEndianness))
|
||||
dataArea.Endianness = Endianness.NULL;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Device
|
||||
|
||||
else if (datItem is Device device)
|
||||
{
|
||||
if (datItemFields.Contains(DatItemField.DeviceType))
|
||||
device.DeviceType = DeviceType.NULL;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.Tag))
|
||||
device.Tag = null;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.FixedImage))
|
||||
device.FixedImage = null;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.Mandatory))
|
||||
device.Mandatory = null;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.Interface))
|
||||
device.Interface = null;
|
||||
|
||||
if (device.InstancesSpecified)
|
||||
{
|
||||
foreach (Instance subInstance in device.Instances)
|
||||
{
|
||||
RemoveFields(subInstance, datItemFields, machineFields);
|
||||
}
|
||||
}
|
||||
|
||||
if (device.ExtensionsSpecified)
|
||||
{
|
||||
foreach (Extension subExtension in device.Extensions)
|
||||
{
|
||||
RemoveFields(subExtension, datItemFields, machineFields);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region DipSwitch
|
||||
|
||||
else if (datItem is DipSwitch dipSwitch)
|
||||
{
|
||||
#region Common
|
||||
|
||||
if (datItemFields.Contains(DatItemField.Tag))
|
||||
dipSwitch.Tag = null;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.Mask))
|
||||
dipSwitch.Mask = null;
|
||||
|
||||
if (dipSwitch.ConditionsSpecified)
|
||||
{
|
||||
foreach (Condition subCondition in dipSwitch.Conditions)
|
||||
{
|
||||
RemoveFields(subCondition, datItemFields, machineFields, true);
|
||||
}
|
||||
}
|
||||
|
||||
if (dipSwitch.LocationsSpecified)
|
||||
{
|
||||
foreach (Location subLocation in dipSwitch.Locations)
|
||||
{
|
||||
RemoveFields(subLocation, datItemFields, machineFields);
|
||||
}
|
||||
}
|
||||
|
||||
if (dipSwitch.ValuesSpecified)
|
||||
{
|
||||
foreach (Setting subValue in dipSwitch.Values)
|
||||
{
|
||||
RemoveFields(subValue, datItemFields, machineFields);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region SoftwareList
|
||||
|
||||
if (dipSwitch.PartSpecified)
|
||||
RemoveFields(dipSwitch.Part, datItemFields, machineFields);
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Disk
|
||||
|
||||
else if (datItem is Disk disk)
|
||||
{
|
||||
#region Common
|
||||
|
||||
if (datItemFields.Contains(DatItemField.MD5))
|
||||
disk.MD5 = null;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.SHA1))
|
||||
disk.SHA1 = null;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.Merge))
|
||||
disk.MergeTag = null;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.Region))
|
||||
disk.Region = null;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.Index))
|
||||
disk.Index = null;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.Writable))
|
||||
disk.Writable = null;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.Status))
|
||||
disk.ItemStatus = ItemStatus.NULL;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.Optional))
|
||||
disk.Optional = null;
|
||||
|
||||
#endregion
|
||||
|
||||
#region SoftwareList
|
||||
|
||||
if (disk.DiskAreaSpecified)
|
||||
RemoveFields(disk.DiskArea, datItemFields, machineFields);
|
||||
|
||||
if (disk.PartSpecified)
|
||||
RemoveFields(disk.Part, datItemFields, machineFields);
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region DiskArea
|
||||
|
||||
else if (datItem is DiskArea diskArea)
|
||||
{
|
||||
if (datItemFields.Contains(DatItemField.AreaName))
|
||||
diskArea.Name = null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Display
|
||||
|
||||
else if (datItem is Display display)
|
||||
{
|
||||
if (datItemFields.Contains(DatItemField.Tag))
|
||||
display.Tag = null;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.DisplayType))
|
||||
display.DisplayType = DisplayType.NULL;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.Rotate))
|
||||
display.Rotate = null;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.FlipX))
|
||||
display.FlipX = null;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.Width))
|
||||
display.Width = null;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.Height))
|
||||
display.Height = null;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.Refresh))
|
||||
display.Refresh = null;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.PixClock))
|
||||
display.PixClock = null;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.HTotal))
|
||||
display.HTotal = null;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.HBEnd))
|
||||
display.HBEnd = null;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.HBStart))
|
||||
display.HBStart = null;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.VTotal))
|
||||
display.VTotal = null;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.VBEnd))
|
||||
display.VBEnd = null;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.VBStart))
|
||||
display.VBStart = null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Driver
|
||||
|
||||
else if (datItem is Driver driver)
|
||||
{
|
||||
if (datItemFields.Contains(DatItemField.SupportStatus))
|
||||
driver.Status = SupportStatus.NULL;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.EmulationStatus))
|
||||
driver.Emulation = SupportStatus.NULL;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.CocktailStatus))
|
||||
driver.Cocktail = SupportStatus.NULL;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.SaveStateStatus))
|
||||
driver.SaveState = Supported.NULL;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Extension
|
||||
|
||||
else if (datItem is Extension extension)
|
||||
{
|
||||
if (datItemFields.Contains(DatItemField.Extension_Name))
|
||||
extension.Name = null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Feature
|
||||
|
||||
else if (datItem is Feature feature)
|
||||
{
|
||||
if (datItemFields.Contains(DatItemField.FeatureType))
|
||||
feature.Type = FeatureType.NULL;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.FeatureStatus))
|
||||
feature.Status = FeatureStatus.NULL;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.FeatureOverall))
|
||||
feature.Overall = FeatureStatus.NULL;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Info
|
||||
|
||||
else if (datItem is Info info)
|
||||
{
|
||||
if (datItemFields.Contains(DatItemField.Value))
|
||||
info.Value = null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Input
|
||||
|
||||
else if (datItem is Input input)
|
||||
{
|
||||
if (datItemFields.Contains(DatItemField.Service))
|
||||
input.Service = null;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.Tilt))
|
||||
input.Tilt = null;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.Players))
|
||||
input.Players = 0;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.Coins))
|
||||
input.Coins = null;
|
||||
|
||||
if (input.ControlsSpecified)
|
||||
{
|
||||
foreach (Control subControl in input.Controls)
|
||||
{
|
||||
RemoveFields(subControl, datItemFields, machineFields);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Instance
|
||||
|
||||
else if (datItem is Instance instance)
|
||||
{
|
||||
if (datItemFields.Contains(DatItemField.Instance_Name))
|
||||
instance.Name = null;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.Instance_BriefName))
|
||||
instance.BriefName = null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Location
|
||||
|
||||
else if (datItem is Location location)
|
||||
{
|
||||
if (datItemFields.Contains(DatItemField.Location_Name))
|
||||
location.Name = null;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.Location_Number))
|
||||
location.Number = null;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.Location_Inverted))
|
||||
location.Inverted = null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Media
|
||||
|
||||
else if (datItem is Media media)
|
||||
{
|
||||
if (datItemFields.Contains(DatItemField.MD5))
|
||||
media.MD5 = null;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.SHA1))
|
||||
media.SHA1 = null;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.SHA256))
|
||||
media.SHA256 = null;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.SpamSum))
|
||||
media.SpamSum = null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Part
|
||||
|
||||
else if (datItem is Part part)
|
||||
{
|
||||
if (datItemFields.Contains(DatItemField.Part_Name))
|
||||
part.Name = null;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.Part_Interface))
|
||||
part.Interface = null;
|
||||
|
||||
if (part.FeaturesSpecified)
|
||||
{
|
||||
foreach (PartFeature subPartFeature in part.Features)
|
||||
{
|
||||
RemoveFields(subPartFeature, datItemFields, machineFields);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region PartFeature
|
||||
|
||||
else if (datItem is PartFeature partFeature)
|
||||
{
|
||||
if (datItemFields.Contains(DatItemField.Part_Feature_Name))
|
||||
partFeature.Name = null;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.Part_Feature_Value))
|
||||
partFeature.Value = null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Port
|
||||
|
||||
else if (datItem is Port port)
|
||||
{
|
||||
if (datItemFields.Contains(DatItemField.Tag))
|
||||
port.Tag = null;
|
||||
|
||||
if (port.AnalogsSpecified)
|
||||
{
|
||||
foreach (Analog subAnalog in port.Analogs)
|
||||
{
|
||||
RemoveFields(subAnalog, datItemFields, machineFields);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region RamOption
|
||||
|
||||
else if (datItem is RamOption ramOption)
|
||||
{
|
||||
if (datItemFields.Contains(DatItemField.Default))
|
||||
ramOption.Default = null;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.Content))
|
||||
ramOption.Content = null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Release
|
||||
|
||||
else if (datItem is Release release)
|
||||
{
|
||||
if (datItemFields.Contains(DatItemField.Region))
|
||||
release.Region = null;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.Language))
|
||||
release.Language = null;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.Date))
|
||||
release.Date = null;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.Default))
|
||||
release.Default = null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Rom
|
||||
|
||||
else if (datItem is Rom rom)
|
||||
{
|
||||
#region Common
|
||||
|
||||
if (datItemFields.Contains(DatItemField.Bios))
|
||||
rom.Bios = null;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.Size))
|
||||
rom.Size = 0;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.CRC))
|
||||
rom.CRC = null;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.MD5))
|
||||
rom.MD5 = null;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.SHA1))
|
||||
rom.SHA1 = null;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.SHA256))
|
||||
rom.SHA256 = null;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.SHA384))
|
||||
rom.SHA384 = null;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.SHA512))
|
||||
rom.SHA512 = null;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.SpamSum))
|
||||
rom.SpamSum = null;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.Merge))
|
||||
rom.MergeTag = null;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.Region))
|
||||
rom.Region = null;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.Offset))
|
||||
rom.Offset = null;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.Date))
|
||||
rom.Date = null;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.Status))
|
||||
rom.ItemStatus = ItemStatus.NULL;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.Optional))
|
||||
rom.Optional = null;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.Inverted))
|
||||
rom.Inverted = null;
|
||||
|
||||
#endregion
|
||||
|
||||
#region AttractMode
|
||||
|
||||
if (datItemFields.Contains(DatItemField.AltName))
|
||||
rom.AltName = null;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.AltTitle))
|
||||
rom.AltTitle = null;
|
||||
|
||||
#endregion
|
||||
|
||||
#region OpenMSX
|
||||
|
||||
if (datItemFields.Contains(DatItemField.Original))
|
||||
rom.Original = null;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.OpenMSXSubType))
|
||||
rom.OpenMSXSubType = OpenMSXSubType.NULL;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.OpenMSXType))
|
||||
rom.OpenMSXType = null;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.Remark))
|
||||
rom.Remark = null;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.Boot))
|
||||
rom.Boot = null;
|
||||
|
||||
#endregion
|
||||
|
||||
#region SoftwareList
|
||||
|
||||
if (datItemFields.Contains(DatItemField.LoadFlag))
|
||||
rom.LoadFlag = LoadFlag.NULL;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.Value))
|
||||
rom.Value = null;
|
||||
|
||||
if (rom.DataAreaSpecified)
|
||||
RemoveFields(rom.DataArea, datItemFields, machineFields);
|
||||
|
||||
if (rom.PartSpecified)
|
||||
RemoveFields(rom.Part, datItemFields, machineFields);
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Setting
|
||||
|
||||
else if (datItem is Setting setting)
|
||||
{
|
||||
if (datItemFields.Contains(DatItemField.Setting_Name))
|
||||
setting.Name = null;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.Setting_Value))
|
||||
setting.Value = null;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.Setting_Default))
|
||||
setting.Default = null;
|
||||
|
||||
if (setting.ConditionsSpecified)
|
||||
{
|
||||
foreach (Condition subCondition in setting.Conditions)
|
||||
{
|
||||
RemoveFields(subCondition, datItemFields, machineFields, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region SharedFeature
|
||||
|
||||
else if (datItem is SharedFeature sharedFeature)
|
||||
{
|
||||
if (datItemFields.Contains(DatItemField.Value))
|
||||
sharedFeature.Value = null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Slot
|
||||
|
||||
else if (datItem is Slot slot)
|
||||
{
|
||||
if (slot.SlotOptionsSpecified)
|
||||
{
|
||||
foreach (SlotOption subSlotOption in slot.SlotOptions)
|
||||
{
|
||||
RemoveFields(subSlotOption, datItemFields, machineFields);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region SlotOption
|
||||
|
||||
else if (datItem is SlotOption slotOption)
|
||||
{
|
||||
if (datItemFields.Contains(DatItemField.SlotOption_Name))
|
||||
slotOption.Name = null;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.SlotOption_DeviceName))
|
||||
slotOption.DeviceName = null;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.SlotOption_Default))
|
||||
slotOption.Default = null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region SoftwareList
|
||||
|
||||
else if (datItem is SoftwareList softwareList)
|
||||
{
|
||||
if (datItemFields.Contains(DatItemField.SoftwareListStatus))
|
||||
softwareList.Status = SoftwareListStatus.NULL;
|
||||
|
||||
if (datItemFields.Contains(DatItemField.Filter))
|
||||
softwareList.Filter = null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Sound
|
||||
|
||||
else if (datItem is Sound sound)
|
||||
{
|
||||
if (datItemFields.Contains(DatItemField.Channels))
|
||||
sound.Channels = null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove fields with given values
|
||||
/// </summary>
|
||||
/// <param name="machine">Machine to remove fields from</param>
|
||||
/// <param name="fields">List of fields to remove</param>
|
||||
public static void RemoveFields(Machine machine, List<MachineField> fields)
|
||||
{
|
||||
#region Common
|
||||
|
||||
if (fields.Contains(MachineField.Name))
|
||||
machine.Name = null;
|
||||
|
||||
if (fields.Contains(MachineField.Comment))
|
||||
machine.Comment = null;
|
||||
|
||||
if (fields.Contains(MachineField.Description))
|
||||
machine.Description = null;
|
||||
|
||||
if (fields.Contains(MachineField.Year))
|
||||
machine.Year = null;
|
||||
|
||||
if (fields.Contains(MachineField.Manufacturer))
|
||||
machine.Manufacturer = null;
|
||||
|
||||
if (fields.Contains(MachineField.Publisher))
|
||||
machine.Publisher = null;
|
||||
|
||||
if (fields.Contains(MachineField.Category))
|
||||
machine.Category = null;
|
||||
|
||||
if (fields.Contains(MachineField.RomOf))
|
||||
machine.RomOf = null;
|
||||
|
||||
if (fields.Contains(MachineField.CloneOf))
|
||||
machine.CloneOf = null;
|
||||
|
||||
if (fields.Contains(MachineField.SampleOf))
|
||||
machine.SampleOf = null;
|
||||
|
||||
if (fields.Contains(MachineField.Type))
|
||||
machine.MachineType = 0x0;
|
||||
|
||||
#endregion
|
||||
|
||||
#region AttractMode
|
||||
|
||||
if (fields.Contains(MachineField.Players))
|
||||
machine.Players = null;
|
||||
|
||||
if (fields.Contains(MachineField.Rotation))
|
||||
machine.Rotation = null;
|
||||
|
||||
if (fields.Contains(MachineField.Control))
|
||||
machine.Control = null;
|
||||
|
||||
if (fields.Contains(MachineField.Status))
|
||||
machine.Status = null;
|
||||
|
||||
if (fields.Contains(MachineField.DisplayCount))
|
||||
machine.DisplayCount = null;
|
||||
|
||||
if (fields.Contains(MachineField.DisplayType))
|
||||
machine.DisplayType = null;
|
||||
|
||||
if (fields.Contains(MachineField.Buttons))
|
||||
machine.Buttons = null;
|
||||
|
||||
#endregion
|
||||
|
||||
#region ListXML
|
||||
|
||||
if (fields.Contains(MachineField.History))
|
||||
machine.History = null;
|
||||
|
||||
if (fields.Contains(MachineField.SourceFile))
|
||||
machine.SourceFile = null;
|
||||
|
||||
if (fields.Contains(MachineField.Runnable))
|
||||
machine.Runnable = Runnable.NULL;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Logiqx
|
||||
|
||||
if (fields.Contains(MachineField.Board))
|
||||
machine.Board = null;
|
||||
|
||||
if (fields.Contains(MachineField.RebuildTo))
|
||||
machine.RebuildTo = null;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Logiqx EmuArc
|
||||
|
||||
if (fields.Contains(MachineField.TitleID))
|
||||
machine.TitleID = null;
|
||||
|
||||
if (fields.Contains(MachineField.Developer))
|
||||
machine.Developer = null;
|
||||
|
||||
if (fields.Contains(MachineField.Genre))
|
||||
machine.Genre = null;
|
||||
|
||||
if (fields.Contains(MachineField.Subgenre))
|
||||
machine.Subgenre = null;
|
||||
|
||||
if (fields.Contains(MachineField.Ratings))
|
||||
machine.Ratings = null;
|
||||
|
||||
if (fields.Contains(MachineField.Score))
|
||||
machine.Score = null;
|
||||
|
||||
if (fields.Contains(MachineField.Enabled))
|
||||
machine.Enabled = null;
|
||||
|
||||
if (fields.Contains(MachineField.CRC))
|
||||
machine.Crc = null;
|
||||
|
||||
if (fields.Contains(MachineField.RelatedTo))
|
||||
machine.RelatedTo = null;
|
||||
|
||||
#endregion
|
||||
|
||||
#region OpenMSX
|
||||
|
||||
if (fields.Contains(MachineField.GenMSXID))
|
||||
machine.GenMSXID = null;
|
||||
|
||||
if (fields.Contains(MachineField.System))
|
||||
machine.System = null;
|
||||
|
||||
if (fields.Contains(MachineField.Country))
|
||||
machine.Country = null;
|
||||
|
||||
#endregion
|
||||
|
||||
#region SoftwareList
|
||||
|
||||
if (fields.Contains(MachineField.Supported))
|
||||
machine.Supported = Supported.NULL;
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Replace fields with given values
|
||||
/// </summary>
|
||||
|
||||
@@ -66,11 +66,7 @@ namespace SabreTools.DatTools
|
||||
OneRomPerGame(datFile);
|
||||
|
||||
// If we are removing fields, do that now
|
||||
if ((cleaner.ExcludeMachineFields != null && cleaner.ExcludeMachineFields.Any())
|
||||
|| cleaner.ExcludeDatItemFields != null && cleaner.ExcludeDatItemFields.Any())
|
||||
{
|
||||
RemoveFieldsFromItems(datFile, cleaner.ExcludeDatItemFields, cleaner.ExcludeMachineFields);
|
||||
}
|
||||
cleaner.RemoveFieldsFromItems(datFile);
|
||||
|
||||
// Remove all marked items
|
||||
datFile.Items.ClearMarked();
|
||||
@@ -495,40 +491,6 @@ namespace SabreTools.DatTools
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove fields as per the header
|
||||
/// </summary>
|
||||
/// <param name="datFile">Current DatFile object to run operations on</param>
|
||||
/// <param name="datItemFields">DatItem fields to remove</param>
|
||||
/// <param name="machineFields">Machine fields to remove</param>
|
||||
public static void RemoveFieldsFromItems(
|
||||
DatFile datFile,
|
||||
List<DatItemField> datItemFields,
|
||||
List<MachineField> machineFields)
|
||||
{
|
||||
// If we have null field list, make it empty
|
||||
if (datItemFields == null)
|
||||
datItemFields = new List<DatItemField>();
|
||||
if (machineFields == null)
|
||||
machineFields = new List<MachineField>();
|
||||
|
||||
// Output the logging statement
|
||||
logger.User("Removing filtered fields");
|
||||
|
||||
// Now process all of the roms
|
||||
Parallel.ForEach(datFile.Items.Keys, Globals.ParallelOptions, key =>
|
||||
{
|
||||
List<DatItem> items = datFile.Items[key];
|
||||
for (int j = 0; j < items.Count; j++)
|
||||
{
|
||||
DatItemTool.RemoveFields(items[j], datItemFields, machineFields);
|
||||
}
|
||||
|
||||
datFile.Items.Remove(key);
|
||||
datFile.Items.AddRange(key, items);
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Strip the dates from the beginning of scene-style set names
|
||||
/// </summary>
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using SabreTools.Core;
|
||||
using SabreTools.Core.Tools;
|
||||
@@ -14,24 +15,20 @@ namespace SabreTools.Filtering
|
||||
/// <summary>
|
||||
/// Represents the cleaning operations that need to be performed on a set of items, usually a DAT
|
||||
/// </summary>
|
||||
/// TODO: Split out helper classes
|
||||
public class Cleaner
|
||||
{
|
||||
#region Exclusion Fields
|
||||
|
||||
/// <summary>
|
||||
/// Dictionary of DatHeader fields to exclude from writing
|
||||
/// DatItemRemover to remove fields from DatHeaders
|
||||
/// </summary>
|
||||
public List<DatHeaderField> ExcludeDatHeaderFields { get; set; } = new List<DatHeaderField>();
|
||||
public DatHeaderRemover DatHeaderRemover { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Dictionary of DatItem fields to exclude from writing
|
||||
/// DatItemRemover to remove fields from DatItems
|
||||
/// </summary>
|
||||
public List<DatItemField> ExcludeDatItemFields { get; set; } = new List<DatItemField>();
|
||||
|
||||
/// <summary>
|
||||
/// Dictionary of Machine fields to exclude from writing
|
||||
/// </summary>
|
||||
public List<MachineField> ExcludeMachineFields { get; set; } = new List<MachineField>();
|
||||
public DatItemRemover DatItemRemover { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -130,10 +127,9 @@ namespace SabreTools.Filtering
|
||||
/// <param name="fields">List of field names</param>
|
||||
public void PopulateExclusionsFromList(List<string> fields)
|
||||
{
|
||||
// Instantiate the lists, if necessary
|
||||
ExcludeDatHeaderFields ??= new List<DatHeaderField>();
|
||||
ExcludeMachineFields ??= new List<MachineField>();
|
||||
ExcludeDatItemFields ??= new List<DatItemField>();
|
||||
// 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)
|
||||
@@ -146,28 +142,12 @@ namespace SabreTools.Filtering
|
||||
continue;
|
||||
|
||||
// DatHeader fields
|
||||
DatHeaderField datHeaderField = field.AsDatHeaderField();
|
||||
if (datHeaderField != DatHeaderField.NULL)
|
||||
{
|
||||
ExcludeDatHeaderFields.Add(datHeaderField);
|
||||
if (DatHeaderRemover.SetRemover(field))
|
||||
continue;
|
||||
}
|
||||
|
||||
// Machine fields
|
||||
MachineField machineField = field.AsMachineField();
|
||||
if (machineField != MachineField.NULL)
|
||||
{
|
||||
ExcludeMachineFields.Add(machineField);
|
||||
// Machine and DatItem fields
|
||||
if (DatItemRemover.SetRemover(field))
|
||||
continue;
|
||||
}
|
||||
|
||||
// DatItem fields
|
||||
DatItemField datItemField = field.AsDatItemField();
|
||||
if (datItemField != DatItemField.NULL)
|
||||
{
|
||||
ExcludeDatItemFields.Add(datItemField);
|
||||
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.");
|
||||
@@ -480,5 +460,43 @@ namespace SabreTools.Filtering
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Removal
|
||||
|
||||
/// <summary>
|
||||
/// Remove fields as per the header
|
||||
/// </summary>
|
||||
/// <param name="datFile">Current DatFile object to run operations on</param>
|
||||
public void RemoveFieldsFromItems(DatFile datFile)
|
||||
{
|
||||
// If the removers don't exist, we can't use it
|
||||
if (DatHeaderRemover == null && DatItemRemover == null)
|
||||
return;
|
||||
|
||||
// Output the logging statement
|
||||
logger.User("Removing filtered fields");
|
||||
|
||||
// Remove DatHeader fields
|
||||
if (DatHeaderRemover != null)
|
||||
DatHeaderRemover.RemoveFields(datFile.Header);
|
||||
|
||||
// Remove DatItem and Machine fields
|
||||
if (DatItemRemover != null)
|
||||
{
|
||||
Parallel.ForEach(datFile.Items.Keys, Globals.ParallelOptions, key =>
|
||||
{
|
||||
List<DatItem> items = datFile.Items[key];
|
||||
for (int j = 0; j < items.Count; j++)
|
||||
{
|
||||
DatItemRemover.RemoveFields(items[j]);
|
||||
}
|
||||
|
||||
datFile.Items.Remove(key);
|
||||
datFile.Items.AddRange(key, items);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
81
SabreTools.Filtering/DatHeaderRemover.cs
Normal file
81
SabreTools.Filtering/DatHeaderRemover.cs
Normal file
@@ -0,0 +1,81 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
using SabreTools.Core;
|
||||
using SabreTools.Core.Tools;
|
||||
using SabreTools.DatFiles;
|
||||
using SabreTools.Logging;
|
||||
|
||||
namespace SabreTools.Filtering
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents the removal operations that need to be performed on a DatHeader
|
||||
/// </summary>
|
||||
public class DatHeaderRemover : Remover
|
||||
{
|
||||
#region Fields
|
||||
|
||||
/// <summary>
|
||||
/// List of DatHeader fields to exclude from writing
|
||||
/// </summary>
|
||||
public List<DatHeaderField> DatHeaderFields { get; private set; } = new List<DatHeaderField>();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
public DatHeaderRemover()
|
||||
{
|
||||
logger = new Logger(this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Remover Population
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool SetRemover(string field)
|
||||
{
|
||||
// If the key is null or empty, return false
|
||||
if (string.IsNullOrWhiteSpace(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 Remover Running
|
||||
|
||||
/// <summary>
|
||||
/// Remove fields with given values
|
||||
/// </summary>
|
||||
/// <param name="datItem">DatHeader to remove fields from</param>
|
||||
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
|
||||
}
|
||||
}
|
||||
1068
SabreTools.Filtering/DatItemRemover.cs
Normal file
1068
SabreTools.Filtering/DatItemRemover.cs
Normal file
File diff suppressed because it is too large
Load Diff
41
SabreTools.Filtering/Remover.cs
Normal file
41
SabreTools.Filtering/Remover.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using SabreTools.Logging;
|
||||
|
||||
namespace SabreTools.Filtering
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents the removal operations that need to be performed on a set of items, usually a DAT
|
||||
/// </summary>
|
||||
public abstract class Remover
|
||||
{
|
||||
#region Logging
|
||||
|
||||
/// <summary>
|
||||
/// Logging object
|
||||
/// </summary>
|
||||
protected Logger logger;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
public Remover()
|
||||
{
|
||||
logger = new Logger(this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Remover Population
|
||||
|
||||
/// <summary>
|
||||
/// Set remover from a value
|
||||
/// </summary>
|
||||
/// <param name="field">Key for the remover to be set</param>
|
||||
public abstract bool SetRemover(string field);
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -8,24 +8,6 @@ namespace SabreTools.Test.DatItems
|
||||
{
|
||||
public class DatItemToolTests
|
||||
{
|
||||
[Fact]
|
||||
public void RemoveFieldsDatItemTest()
|
||||
{
|
||||
var datItem = CreateDatItem();
|
||||
var fields = new List<DatItemField> { DatItemField.Name };
|
||||
DatItemTool.RemoveFields(datItem, datItemFields: fields);
|
||||
Assert.Null(datItem.GetName());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RemoveFieldsMachineTest()
|
||||
{
|
||||
var datItem = CreateDatItem();
|
||||
var fields = new List<MachineField> { MachineField.Name };
|
||||
DatItemTool.RemoveFields(datItem, machineFields: fields);
|
||||
Assert.Null(datItem.Machine.Name);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ReplaceFieldsDatItemTest()
|
||||
{
|
||||
|
||||
@@ -18,9 +18,9 @@ namespace SabreTools.Test.Filtering
|
||||
cleaner.PopulateExclusionsFromList(exclusions);
|
||||
|
||||
// Check the exclusion lists
|
||||
Assert.Empty(cleaner.ExcludeDatHeaderFields);
|
||||
Assert.Empty(cleaner.ExcludeMachineFields);
|
||||
Assert.Empty(cleaner.ExcludeDatItemFields);
|
||||
Assert.Empty(cleaner.DatHeaderRemover.DatHeaderFields);
|
||||
Assert.Empty(cleaner.DatItemRemover.MachineFields);
|
||||
Assert.Empty(cleaner.DatItemRemover.DatItemFields);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -34,9 +34,9 @@ namespace SabreTools.Test.Filtering
|
||||
cleaner.PopulateExclusionsFromList(exclusions);
|
||||
|
||||
// Check the exclusion lists
|
||||
Assert.Empty(cleaner.ExcludeDatHeaderFields);
|
||||
Assert.Empty(cleaner.ExcludeMachineFields);
|
||||
Assert.Empty(cleaner.ExcludeDatItemFields);
|
||||
Assert.Empty(cleaner.DatHeaderRemover.DatHeaderFields);
|
||||
Assert.Empty(cleaner.DatItemRemover.MachineFields);
|
||||
Assert.Empty(cleaner.DatItemRemover.DatItemFields);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -53,9 +53,9 @@ namespace SabreTools.Test.Filtering
|
||||
cleaner.PopulateExclusionsFromList(exclusions);
|
||||
|
||||
// Check the exclusion lists
|
||||
Assert.Single(cleaner.ExcludeDatHeaderFields);
|
||||
Assert.Empty(cleaner.ExcludeMachineFields);
|
||||
Assert.Empty(cleaner.ExcludeDatItemFields);
|
||||
Assert.Single(cleaner.DatHeaderRemover.DatHeaderFields);
|
||||
Assert.Empty(cleaner.DatItemRemover.MachineFields);
|
||||
Assert.Empty(cleaner.DatItemRemover.DatItemFields);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -72,9 +72,9 @@ namespace SabreTools.Test.Filtering
|
||||
cleaner.PopulateExclusionsFromList(exclusions);
|
||||
|
||||
// Check the exclusion lists
|
||||
Assert.Empty(cleaner.ExcludeDatHeaderFields);
|
||||
Assert.Single(cleaner.ExcludeMachineFields);
|
||||
Assert.Empty(cleaner.ExcludeDatItemFields);
|
||||
Assert.Empty(cleaner.DatHeaderRemover.DatHeaderFields);
|
||||
Assert.Single(cleaner.DatItemRemover.MachineFields);
|
||||
Assert.Empty(cleaner.DatItemRemover.DatItemFields);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -91,9 +91,9 @@ namespace SabreTools.Test.Filtering
|
||||
cleaner.PopulateExclusionsFromList(exclusions);
|
||||
|
||||
// Check the exclusion lists
|
||||
Assert.Empty(cleaner.ExcludeDatHeaderFields);
|
||||
Assert.Empty(cleaner.ExcludeMachineFields);
|
||||
Assert.Single(cleaner.ExcludeDatItemFields);
|
||||
Assert.Empty(cleaner.DatHeaderRemover.DatHeaderFields);
|
||||
Assert.Empty(cleaner.DatItemRemover.MachineFields);
|
||||
Assert.Single(cleaner.DatItemRemover.DatItemFields);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
45
SabreTools.Test/Filtering/RemoverTests.cs
Normal file
45
SabreTools.Test/Filtering/RemoverTests.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using SabreTools.DatItems;
|
||||
using SabreTools.Filtering;
|
||||
using Xunit;
|
||||
|
||||
namespace SabreTools.Test.Filtering
|
||||
{
|
||||
public class RemoverTests
|
||||
{
|
||||
[Fact]
|
||||
public void RemoveFieldsDatItemTest()
|
||||
{
|
||||
var datItem = CreateDatItem();
|
||||
var remover = new DatItemRemover();
|
||||
remover.SetRemover("DatItem.Name");
|
||||
remover.RemoveFields(datItem);
|
||||
Assert.Null(datItem.GetName());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RemoveFieldsMachineTest()
|
||||
{
|
||||
var datItem = CreateDatItem();
|
||||
var remover = new DatItemRemover();
|
||||
remover.SetRemover("Machine.Name");
|
||||
remover.RemoveFields(datItem);
|
||||
Assert.Null(datItem.Machine.Name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generate a consistent DatItem for testing
|
||||
/// </summary>
|
||||
private DatItem CreateDatItem()
|
||||
{
|
||||
return new Rom
|
||||
{
|
||||
Name = "foo",
|
||||
Machine = new Machine
|
||||
{
|
||||
Name = "bar",
|
||||
Description = "bar",
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -159,8 +159,15 @@ Reset the internal state: reset();";
|
||||
|
||||
// TODO: We might not want to remove higher order hashes in the future
|
||||
// TODO: We might not want to remove dates in the future
|
||||
Cleaner dfdCleaner = new Cleaner() { ExcludeDatItemFields = Hash.DeepHashes.AsDatItemFields() };
|
||||
dfdCleaner.ExcludeDatItemFields.Add(DatItemField.Date);
|
||||
Cleaner dfdCleaner = new Cleaner();
|
||||
dfdCleaner.PopulateExclusionsFromList(new List<string>
|
||||
{
|
||||
"DatItem.SHA256",
|
||||
"DatItem.SHA384",
|
||||
"DatItem.SHA512",
|
||||
"DatItem.SpamSum",
|
||||
"DatItem.Date",
|
||||
});
|
||||
Modification.ApplyCleaning(datFile, dfdCleaner);
|
||||
|
||||
break;
|
||||
@@ -342,9 +349,9 @@ Reset the internal state: reset();";
|
||||
}
|
||||
|
||||
// Run the removal functionality
|
||||
var removeDatItemFields = command.Arguments.Select(s => s.AsDatItemField()).ToList();
|
||||
var removeMachineFields = command.Arguments.Select(s => s.AsMachineField()).ToList();
|
||||
Modification.RemoveFieldsFromItems(datFile, removeDatItemFields, removeMachineFields);
|
||||
Cleaner remCleaner = new Cleaner();
|
||||
remCleaner.PopulateExclusionsFromList(command.Arguments);
|
||||
remCleaner.RemoveFieldsFromItems(datFile);
|
||||
|
||||
break;
|
||||
|
||||
|
||||
@@ -65,11 +65,7 @@ namespace SabreTools.Features
|
||||
var splitType = GetSplitType(features);
|
||||
|
||||
// Apply the specialized field removals to the cleaner
|
||||
if (Cleaner.ExcludeDatItemFields == null)
|
||||
Cleaner.ExcludeDatItemFields = new List<DatItemField>();
|
||||
|
||||
if (!addFileDates)
|
||||
Cleaner.ExcludeDatItemFields.Add(DatItemField.Date);
|
||||
Cleaner.PopulateExclusionsFromList(new List<string> { "DatItem.Date" });
|
||||
|
||||
// Create a new DATFromDir object and process the inputs
|
||||
DatFile basedat = DatFile.Create(Header);
|
||||
|
||||
Reference in New Issue
Block a user