mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Consolidate setter code
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using SabreTools.Core;
|
||||
using SabreTools.Core.Tools;
|
||||
using SabreTools.DatItems;
|
||||
using SabreTools.DatItems.Formats;
|
||||
using SabreTools.Filter;
|
||||
using SabreTools.Logging;
|
||||
|
||||
namespace SabreTools.DatFiles
|
||||
@@ -18,17 +20,17 @@ namespace SabreTools.DatFiles
|
||||
/// <summary>
|
||||
/// Mappings to set DatHeader fields
|
||||
/// </summary>
|
||||
public Dictionary<DatHeaderField, string>? DatHeaderMappings { get; set; }
|
||||
public Dictionary<string, string> HeaderFieldMappings { get; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Mappings to set Machine fields
|
||||
/// </summary>
|
||||
public Dictionary<MachineField, string>? MachineMappings { get; set; }
|
||||
public Dictionary<string, string> MachineFieldMappings { get; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Mappings to set DatItem fields
|
||||
/// </summary>
|
||||
public Dictionary<DatItemField, string>? DatItemMappings { get; set; }
|
||||
public Dictionary<(string, string), string> ItemFieldMappings { get; } = [];
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -43,49 +45,68 @@ namespace SabreTools.DatFiles
|
||||
|
||||
#region Population
|
||||
|
||||
/// <summary>
|
||||
/// Populate the setters using a field name and a value
|
||||
/// </summary>
|
||||
/// <param name="field">Field name</param>
|
||||
/// <param name="value">Field value</param>
|
||||
public void PopulateSetters(string field, string value)
|
||||
=> PopulateSettersFromList([field], [value]);
|
||||
|
||||
/// <summary>
|
||||
/// Populate the setters using a set of field names
|
||||
/// </summary>
|
||||
/// <param name="headers">List of header names</param>
|
||||
/// <param name="fields">List of field names</param>
|
||||
public void PopulateSettersFromList(List<string> headers, List<string> fields)
|
||||
/// <param name="values">List of field values</param>
|
||||
public void PopulateSettersFromList(List<string> fields, List<string> values)
|
||||
{
|
||||
// Instantiate the setters, if necessary
|
||||
DatHeaderMappings ??= [];
|
||||
MachineMappings ??= [];
|
||||
DatItemMappings ??= [];
|
||||
|
||||
// If the list is null or empty, just return
|
||||
if (fields == null || fields.Count == 0)
|
||||
if (values == null || values.Count == 0)
|
||||
return;
|
||||
|
||||
var watch = new InternalStopwatch("Populating setters from list");
|
||||
|
||||
// Now we loop through and get values for everything
|
||||
for (int i = 0; i < headers.Count; i++)
|
||||
for (int i = 0; i < fields.Count; i++)
|
||||
{
|
||||
string field = fields[i];
|
||||
DatHeaderField dhf = headers[i].AsDatHeaderField();
|
||||
if (dhf != DatHeaderField.NULL)
|
||||
{
|
||||
DatHeaderMappings[dhf] = field;
|
||||
continue;
|
||||
string value = values[i];
|
||||
|
||||
if (!SetSetter(field, value))
|
||||
logger.Warning($"The value {value} did not match any known field names. Please check the wiki for more details on supported field names.");
|
||||
}
|
||||
|
||||
MachineField mf = headers[i].AsMachineField();
|
||||
if (mf != MachineField.NULL)
|
||||
{
|
||||
MachineMappings[mf] = field;
|
||||
continue;
|
||||
watch.Stop();
|
||||
}
|
||||
|
||||
DatItemField dif = headers[i].AsDatItemField();
|
||||
if (dif != DatItemField.NULL)
|
||||
/// <summary>
|
||||
/// Set remover from a value
|
||||
/// </summary>
|
||||
/// <param name="field">Key for the remover to be set</param>
|
||||
private bool SetSetter(string field, string value)
|
||||
{
|
||||
DatItemMappings[dif] = field;
|
||||
continue;
|
||||
}
|
||||
// If the key is null or empty, return false
|
||||
if (string.IsNullOrEmpty(field))
|
||||
return false;
|
||||
|
||||
// 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.");
|
||||
// Get the parser pair out of it, if possible
|
||||
(string? type, string? key) = FilterParser.ParseFilterId(field);
|
||||
if (type == null || key == null)
|
||||
return false;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case Models.Metadata.MetadataFile.HeaderKey:
|
||||
HeaderFieldMappings[key] = value;
|
||||
return true;
|
||||
|
||||
case Models.Metadata.MetadataFile.MachineKey:
|
||||
MachineFieldMappings[key] = value;
|
||||
return true;
|
||||
|
||||
default:
|
||||
ItemFieldMappings[(type, key)] = value;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,111 +118,31 @@ namespace SabreTools.DatFiles
|
||||
/// <param name="datHeader">DatHeader to set fields on</param>
|
||||
public void SetFields(DatHeader datHeader)
|
||||
{
|
||||
if (datHeader == null || DatHeaderMappings == null)
|
||||
// If we have an invalid input, return
|
||||
if (datHeader == null || !HeaderFieldMappings.Any())
|
||||
return;
|
||||
|
||||
if (DatHeaderMappings.ContainsKey(DatHeaderField.Author))
|
||||
datHeader.Author = DatHeaderMappings[DatHeaderField.Author];
|
||||
foreach (var fieldName in HeaderFieldMappings.Keys)
|
||||
{
|
||||
// TODO: Impelement in DatHeader
|
||||
//datHeader.SetField(fieldName);
|
||||
}
|
||||
}
|
||||
|
||||
if (DatHeaderMappings.ContainsKey(DatHeaderField.BiosMode))
|
||||
datHeader.BiosMode = DatHeaderMappings[DatHeaderField.BiosMode].AsEnumValue<MergingFlag>();
|
||||
/// <summary>
|
||||
/// Set fields with given values
|
||||
/// </summary>
|
||||
/// <param name="machine">Machine to set fields on</param>
|
||||
public void SetFields(Machine? machine)
|
||||
{
|
||||
// If we have an invalid input, return
|
||||
if (machine == null || !MachineFieldMappings.Any())
|
||||
return;
|
||||
|
||||
if (DatHeaderMappings.ContainsKey(DatHeaderField.Build))
|
||||
datHeader.Build = DatHeaderMappings[DatHeaderField.Build];
|
||||
|
||||
// TODO: Support CanOpen
|
||||
|
||||
if (DatHeaderMappings.ContainsKey(DatHeaderField.Category))
|
||||
datHeader.Category = DatHeaderMappings[DatHeaderField.Category];
|
||||
|
||||
if (DatHeaderMappings.ContainsKey(DatHeaderField.Comment))
|
||||
datHeader.Comment = DatHeaderMappings[DatHeaderField.Comment];
|
||||
|
||||
if (DatHeaderMappings.ContainsKey(DatHeaderField.Date))
|
||||
datHeader.Date = DatHeaderMappings[DatHeaderField.Date];
|
||||
|
||||
if (DatHeaderMappings.ContainsKey(DatHeaderField.Debug))
|
||||
datHeader.Debug = DatHeaderMappings[DatHeaderField.Debug].AsYesNo();
|
||||
|
||||
if (DatHeaderMappings.ContainsKey(DatHeaderField.Description))
|
||||
datHeader.Description = DatHeaderMappings[DatHeaderField.Description];
|
||||
|
||||
if (DatHeaderMappings.ContainsKey(DatHeaderField.Email))
|
||||
datHeader.Email = DatHeaderMappings[DatHeaderField.Email];
|
||||
|
||||
if (DatHeaderMappings.ContainsKey(DatHeaderField.FileName))
|
||||
datHeader.FileName = DatHeaderMappings[DatHeaderField.FileName];
|
||||
|
||||
if (DatHeaderMappings.ContainsKey(DatHeaderField.ForceMerging))
|
||||
datHeader.ForceMerging = DatHeaderMappings[DatHeaderField.ForceMerging].AsEnumValue<MergingFlag>();
|
||||
|
||||
if (DatHeaderMappings.ContainsKey(DatHeaderField.ForceNodump))
|
||||
datHeader.ForceNodump = DatHeaderMappings[DatHeaderField.ForceNodump].AsEnumValue<NodumpFlag>();
|
||||
|
||||
if (DatHeaderMappings.ContainsKey(DatHeaderField.ForcePacking))
|
||||
datHeader.ForcePacking = DatHeaderMappings[DatHeaderField.ForcePacking].AsEnumValue<PackingFlag>();
|
||||
|
||||
if (DatHeaderMappings.ContainsKey(DatHeaderField.HeaderSkipper))
|
||||
datHeader.HeaderSkipper = DatHeaderMappings[DatHeaderField.HeaderSkipper];
|
||||
|
||||
if (DatHeaderMappings.ContainsKey(DatHeaderField.Homepage))
|
||||
datHeader.Homepage = DatHeaderMappings[DatHeaderField.Homepage];
|
||||
|
||||
if (DatHeaderMappings.ContainsKey(DatHeaderField.ID))
|
||||
datHeader.NoIntroID = DatHeaderMappings[DatHeaderField.ID];
|
||||
|
||||
// TODO: Support Info_Default
|
||||
// TODO: Support Info_IsNamingOption
|
||||
// TODO: Support Info_Name
|
||||
// TODO: Support Info_Visible
|
||||
|
||||
if (DatHeaderMappings.ContainsKey(DatHeaderField.LockBiosMode))
|
||||
datHeader.LockBiosMode = DatHeaderMappings[DatHeaderField.LockBiosMode].AsYesNo();
|
||||
|
||||
if (DatHeaderMappings.ContainsKey(DatHeaderField.LockRomMode))
|
||||
datHeader.LockRomMode = DatHeaderMappings[DatHeaderField.LockRomMode].AsYesNo();
|
||||
|
||||
if (DatHeaderMappings.ContainsKey(DatHeaderField.LockSampleMode))
|
||||
datHeader.LockSampleMode = DatHeaderMappings[DatHeaderField.LockSampleMode].AsYesNo();
|
||||
|
||||
if (DatHeaderMappings.ContainsKey(DatHeaderField.MameConfig))
|
||||
datHeader.MameConfig = DatHeaderMappings[DatHeaderField.MameConfig];
|
||||
|
||||
if (DatHeaderMappings.ContainsKey(DatHeaderField.Name))
|
||||
datHeader.Name = DatHeaderMappings[DatHeaderField.Name];
|
||||
|
||||
if (DatHeaderMappings.ContainsKey(DatHeaderField.RomCenterVersion))
|
||||
datHeader.RomCenterVersion = DatHeaderMappings[DatHeaderField.RomCenterVersion];
|
||||
|
||||
if (DatHeaderMappings.ContainsKey(DatHeaderField.RomMode))
|
||||
datHeader.RomMode = DatHeaderMappings[DatHeaderField.RomMode].AsEnumValue<MergingFlag>();
|
||||
|
||||
if (DatHeaderMappings.ContainsKey(DatHeaderField.RomTitle))
|
||||
datHeader.RomTitle = DatHeaderMappings[DatHeaderField.RomTitle];
|
||||
|
||||
if (DatHeaderMappings.ContainsKey(DatHeaderField.RootDir))
|
||||
datHeader.RootDir = DatHeaderMappings[DatHeaderField.RootDir];
|
||||
|
||||
if (DatHeaderMappings.ContainsKey(DatHeaderField.SampleMode))
|
||||
datHeader.SampleMode = DatHeaderMappings[DatHeaderField.SampleMode].AsEnumValue<MergingFlag>();
|
||||
|
||||
if (DatHeaderMappings.ContainsKey(DatHeaderField.ScreenshotsHeight))
|
||||
datHeader.ScreenshotsHeight = DatHeaderMappings[DatHeaderField.ScreenshotsHeight];
|
||||
|
||||
if (DatHeaderMappings.ContainsKey(DatHeaderField.ScreenshotsWidth))
|
||||
datHeader.ScreenshotsWidth = DatHeaderMappings[DatHeaderField.ScreenshotsWidth];
|
||||
|
||||
if (DatHeaderMappings.ContainsKey(DatHeaderField.System))
|
||||
datHeader.System = DatHeaderMappings[DatHeaderField.System];
|
||||
|
||||
if (DatHeaderMappings.ContainsKey(DatHeaderField.Type))
|
||||
datHeader.Type = DatHeaderMappings[DatHeaderField.Type];
|
||||
|
||||
if (DatHeaderMappings.ContainsKey(DatHeaderField.Url))
|
||||
datHeader.Url = DatHeaderMappings[DatHeaderField.Url];
|
||||
|
||||
if (DatHeaderMappings.ContainsKey(DatHeaderField.Version))
|
||||
datHeader.Version = DatHeaderMappings[DatHeaderField.Version];
|
||||
foreach (var kvp in MachineFieldMappings)
|
||||
{
|
||||
machine.SetField(kvp.Key, kvp.Value);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -210,20 +151,45 @@ namespace SabreTools.DatFiles
|
||||
/// <param name="datItem">DatItem to set fields on</param>
|
||||
public void SetFields(DatItem datItem)
|
||||
{
|
||||
if (datItem == null || DatItemMappings == null)
|
||||
if (datItem == null)
|
||||
return;
|
||||
|
||||
#region Common
|
||||
|
||||
if (DatItemMappings!.ContainsKey(DatItemField.Name))
|
||||
datItem.SetName(DatItemMappings[DatItemField.Name]);
|
||||
// Handle Machine fields
|
||||
if (MachineFieldMappings.Any() && datItem.Machine != null)
|
||||
SetFields(datItem.Machine);
|
||||
|
||||
// If there are no field names, return
|
||||
if (ItemFieldMappings == null || !ItemFieldMappings.Any())
|
||||
return;
|
||||
|
||||
// If there are no field names for this type or generic, return
|
||||
string? itemType = datItem.ItemType.AsStringValue<ItemType>();
|
||||
if (itemType == null || (!ItemFieldMappings.Keys.Any(kvp => kvp.Item1 == itemType) && !ItemFieldMappings.Keys.Any(kvp => kvp.Item1 == "item")))
|
||||
return;
|
||||
|
||||
// Get the combined list of fields to remove
|
||||
var fieldMappings = new Dictionary<string, string>();
|
||||
foreach (var mapping in ItemFieldMappings.Where(kvp => kvp.Key.Item1 == "item").ToDictionary(kvp => kvp.Key.Item2, kvp => kvp.Value))
|
||||
{
|
||||
fieldMappings[mapping.Key] = mapping.Value;
|
||||
}
|
||||
foreach (var mapping in ItemFieldMappings.Where(kvp => kvp.Key.Item1 == itemType).ToDictionary(kvp => kvp.Key.Item2, kvp => kvp.Value))
|
||||
{
|
||||
fieldMappings[mapping.Key] = mapping.Value;
|
||||
}
|
||||
|
||||
// If the field specifically contains Name, set it separately
|
||||
if (fieldMappings.Keys.Contains(Models.Metadata.Rom.NameKey))
|
||||
datItem.SetName(fieldMappings[Models.Metadata.Rom.NameKey]);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Item-Specific
|
||||
|
||||
// Handle unnested sets first
|
||||
foreach (var kvp in DatItemMappings)
|
||||
foreach (var kvp in fieldMappings)
|
||||
{
|
||||
datItem.SetField(kvp.Key, kvp.Value);
|
||||
}
|
||||
@@ -248,21 +214,6 @@ namespace SabreTools.DatFiles
|
||||
#endregion
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set fields with given values
|
||||
/// </summary>
|
||||
/// <param name="machine">Machine to set fields on</param>
|
||||
public void SetFields(Machine? machine)
|
||||
{
|
||||
if (machine == null || MachineMappings == null)
|
||||
return;
|
||||
|
||||
foreach (var kvp in MachineMappings)
|
||||
{
|
||||
machine.SetField(kvp.Key, kvp.Value);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set fields with given values
|
||||
/// </summary>
|
||||
|
||||
@@ -396,15 +396,6 @@ namespace SabreTools.DatItems
|
||||
/// <returns>True if the removal was successful, false otherwise</returns>
|
||||
public bool RemoveField(string? fieldName) => FieldManipulator.RemoveField(_internal, fieldName);
|
||||
|
||||
/// <summary>
|
||||
/// Set a field in the DatItem from a mapping string
|
||||
/// </summary>
|
||||
/// <param name="fieldName">Item field to set</param>
|
||||
/// <param name="value">String representing the value to set</param>
|
||||
/// <returns>True if the setting was successful, false otherwise</returns>
|
||||
/// <remarks>This only performs minimal validation before setting</remarks>
|
||||
public abstract bool SetField(DatItemField datItemField, string value);
|
||||
|
||||
/// <summary>
|
||||
/// Set a field in the DatItem from a mapping string
|
||||
/// </summary>
|
||||
|
||||
@@ -98,23 +98,5 @@ namespace SabreTools.DatItems.Formats
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Manipulation
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool SetField(DatItemField datItemField, string value)
|
||||
{
|
||||
// Get the correct internal field name
|
||||
string? fieldName = datItemField switch
|
||||
{
|
||||
DatItemField.Default => Models.Metadata.Adjuster.DefaultKey,
|
||||
_ => null,
|
||||
};
|
||||
|
||||
// Set the field and return
|
||||
return FieldManipulator.SetField(_internal, fieldName, value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,23 +59,5 @@ namespace SabreTools.DatItems.Formats
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Manipulation
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool SetField(DatItemField datItemField, string value)
|
||||
{
|
||||
// Get the correct internal field name
|
||||
string? fieldName = datItemField switch
|
||||
{
|
||||
DatItemField.Analog_Mask => Models.Metadata.Analog.MaskKey,
|
||||
_ => null,
|
||||
};
|
||||
|
||||
// Set the field and return
|
||||
return FieldManipulator.SetField(_internal, fieldName, value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,22 +135,5 @@ namespace SabreTools.DatItems.Formats
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Manipulation
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool SetField(DatItemField datItemField, string value)
|
||||
{
|
||||
// Get the correct internal field name
|
||||
string? fieldName = datItemField switch
|
||||
{
|
||||
_ => null,
|
||||
};
|
||||
|
||||
// Set the field and return
|
||||
return FieldManipulator.SetField(_internal, fieldName, value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,24 +93,5 @@ namespace SabreTools.DatItems.Formats
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Manipulation
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool SetField(DatItemField datItemField, string value)
|
||||
{
|
||||
// Get the correct internal field name
|
||||
string? fieldName = datItemField switch
|
||||
{
|
||||
DatItemField.Default => Models.Metadata.BiosSet.DefaultKey,
|
||||
DatItemField.Description => Models.Metadata.BiosSet.DescriptionKey,
|
||||
_ => null,
|
||||
};
|
||||
|
||||
// Set the field and return
|
||||
return FieldManipulator.SetField(_internal, fieldName, value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,12 +57,5 @@ namespace SabreTools.DatItems.Formats
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Manipulation
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool SetField(DatItemField datItemField, string value) => true;
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,25 +109,5 @@ namespace SabreTools.DatItems.Formats
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Manipulation
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool SetField(DatItemField datItemField, string value)
|
||||
{
|
||||
// Get the correct internal field name
|
||||
string? fieldName = datItemField switch
|
||||
{
|
||||
DatItemField.ChipType => Models.Metadata.Chip.ChipTypeKey,
|
||||
DatItemField.Clock => Models.Metadata.Chip.ClockKey,
|
||||
DatItemField.Tag => Models.Metadata.Chip.TagKey,
|
||||
_ => null,
|
||||
};
|
||||
|
||||
// Set the field and return
|
||||
return FieldManipulator.SetField(_internal, fieldName, value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,30 +95,5 @@ namespace SabreTools.DatItems.Formats
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Manipulation
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool SetField(DatItemField datItemField, string value)
|
||||
{
|
||||
// Get the correct internal field name
|
||||
string? fieldName = datItemField switch
|
||||
{
|
||||
DatItemField.Mask => Models.Metadata.Condition.MaskKey,
|
||||
DatItemField.Condition_Mask => Models.Metadata.Condition.MaskKey,
|
||||
DatItemField.Relation => Models.Metadata.Condition.RelationKey,
|
||||
DatItemField.Condition_Relation => Models.Metadata.Condition.RelationKey,
|
||||
DatItemField.Tag => Models.Metadata.Condition.TagKey,
|
||||
DatItemField.Condition_Tag => Models.Metadata.Condition.TagKey,
|
||||
DatItemField.Value => Models.Metadata.Condition.ValueKey,
|
||||
DatItemField.Condition_Value => Models.Metadata.Condition.ValueKey,
|
||||
_ => null,
|
||||
};
|
||||
|
||||
// Set the field and return
|
||||
return FieldManipulator.SetField(_internal, fieldName, value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,26 +96,5 @@ namespace SabreTools.DatItems.Formats
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Manipulation
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool SetField(DatItemField datItemField, string value)
|
||||
{
|
||||
// Get the correct internal field name
|
||||
string? fieldName = datItemField switch
|
||||
{
|
||||
DatItemField.Inverted => Models.Metadata.ConfLocation.InvertedKey,
|
||||
DatItemField.Location_Inverted => Models.Metadata.ConfLocation.InvertedKey,
|
||||
DatItemField.Number => Models.Metadata.ConfLocation.NumberKey,
|
||||
DatItemField.Location_Number => Models.Metadata.ConfLocation.NumberKey,
|
||||
_ => null,
|
||||
};
|
||||
|
||||
// Set the field and return
|
||||
return FieldManipulator.SetField(_internal, fieldName, value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,26 +108,5 @@ namespace SabreTools.DatItems.Formats
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Manipulation
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool SetField(DatItemField datItemField, string value)
|
||||
{
|
||||
// Get the correct internal field name
|
||||
string? fieldName = datItemField switch
|
||||
{
|
||||
DatItemField.Default => Models.Metadata.ConfSetting.DefaultKey,
|
||||
DatItemField.Setting_Default => Models.Metadata.ConfSetting.DefaultKey,
|
||||
DatItemField.Value => Models.Metadata.ConfSetting.ValueKey,
|
||||
DatItemField.Setting_Value => Models.Metadata.ConfSetting.ValueKey,
|
||||
_ => null,
|
||||
};
|
||||
|
||||
// Set the field and return
|
||||
return FieldManipulator.SetField(_internal, fieldName, value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,24 +131,5 @@ namespace SabreTools.DatItems.Formats
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Manipulation
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool SetField(DatItemField datItemField, string value)
|
||||
{
|
||||
// Get the correct internal field name
|
||||
string? fieldName = datItemField switch
|
||||
{
|
||||
DatItemField.Mask => Models.Metadata.Configuration.MaskKey,
|
||||
DatItemField.Tag => Models.Metadata.Configuration.TagKey,
|
||||
_ => null,
|
||||
};
|
||||
|
||||
// Set the field and return
|
||||
return FieldManipulator.SetField(_internal, fieldName, value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -199,34 +199,5 @@ namespace SabreTools.DatItems.Formats
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Manipulation
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool SetField(DatItemField datItemField, string value)
|
||||
{
|
||||
// Get the correct internal field name
|
||||
string? fieldName = datItemField switch
|
||||
{
|
||||
DatItemField.Control_Buttons => Models.Metadata.Control.ButtonsKey,
|
||||
DatItemField.Control_KeyDelta => Models.Metadata.Control.KeyDeltaKey,
|
||||
DatItemField.Control_Maximum => Models.Metadata.Control.MaximumKey,
|
||||
DatItemField.Control_Minimum => Models.Metadata.Control.MinimumKey,
|
||||
DatItemField.Control_Player => Models.Metadata.Control.PlayerKey,
|
||||
DatItemField.Control_RequiredButtons => Models.Metadata.Control.ReqButtonsKey,
|
||||
DatItemField.Control_Reverse => Models.Metadata.Control.ReverseKey,
|
||||
DatItemField.Control_Sensitivity => Models.Metadata.Control.SensitivityKey,
|
||||
DatItemField.Control_Type => Models.Metadata.Control.ControlTypeKey,
|
||||
DatItemField.Control_Ways => Models.Metadata.Control.WaysKey,
|
||||
DatItemField.Control_Ways2 => Models.Metadata.Control.Ways2Key,
|
||||
DatItemField.Control_Ways3 => Models.Metadata.Control.Ways3Key,
|
||||
_ => null,
|
||||
};
|
||||
|
||||
// Set the field and return
|
||||
return FieldManipulator.SetField(_internal, fieldName, value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,25 +111,5 @@ namespace SabreTools.DatItems.Formats
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Manipulation
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool SetField(DatItemField datItemField, string value)
|
||||
{
|
||||
// Get the correct internal field name
|
||||
string? fieldName = datItemField switch
|
||||
{
|
||||
DatItemField.AreaEndianness => Models.Metadata.DataArea.EndiannessKey,
|
||||
DatItemField.AreaSize => Models.Metadata.DataArea.SizeKey,
|
||||
DatItemField.AreaWidth => Models.Metadata.DataArea.WidthKey,
|
||||
_ => null,
|
||||
};
|
||||
|
||||
// Set the field and return
|
||||
return FieldManipulator.SetField(_internal, fieldName, value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,27 +137,5 @@ namespace SabreTools.DatItems.Formats
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Manipulation
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool SetField(DatItemField datItemField, string value)
|
||||
{
|
||||
// Get the correct internal field name
|
||||
string? fieldName = datItemField switch
|
||||
{
|
||||
DatItemField.DeviceType => Models.Metadata.Device.DeviceTypeKey,
|
||||
DatItemField.FixedImage => Models.Metadata.Device.FixedImageKey,
|
||||
DatItemField.Interface => Models.Metadata.Device.InterfaceKey,
|
||||
DatItemField.Mandatory => Models.Metadata.Device.MandatoryKey,
|
||||
DatItemField.Tag => Models.Metadata.Device.TagKey,
|
||||
_ => null,
|
||||
};
|
||||
|
||||
// Set the field and return
|
||||
return FieldManipulator.SetField(_internal, fieldName, value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,22 +70,5 @@ namespace SabreTools.DatItems.Formats
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Manipulation
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool SetField(DatItemField datItemField, string value)
|
||||
{
|
||||
// Get the correct internal field name
|
||||
string? fieldName = datItemField switch
|
||||
{
|
||||
_ => null,
|
||||
};
|
||||
|
||||
// Set the field and return
|
||||
return FieldManipulator.SetField(_internal, fieldName, value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,26 +96,5 @@ namespace SabreTools.DatItems.Formats
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Manipulation
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool SetField(DatItemField datItemField, string value)
|
||||
{
|
||||
// Get the correct internal field name
|
||||
string? fieldName = datItemField switch
|
||||
{
|
||||
DatItemField.Inverted => Models.Metadata.DipLocation.InvertedKey,
|
||||
DatItemField.Location_Inverted => Models.Metadata.DipLocation.InvertedKey,
|
||||
DatItemField.Number => Models.Metadata.DipLocation.NumberKey,
|
||||
DatItemField.Location_Number => Models.Metadata.DipLocation.NumberKey,
|
||||
_ => null,
|
||||
};
|
||||
|
||||
// Set the field and return
|
||||
return FieldManipulator.SetField(_internal, fieldName, value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,24 +159,5 @@ namespace SabreTools.DatItems.Formats
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Manipulation
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool SetField(DatItemField datItemField, string value)
|
||||
{
|
||||
// Get the correct internal field name
|
||||
string? fieldName = datItemField switch
|
||||
{
|
||||
DatItemField.Mask => Models.Metadata.DipSwitch.MaskKey,
|
||||
DatItemField.Tag => Models.Metadata.DipSwitch.TagKey,
|
||||
_ => null,
|
||||
};
|
||||
|
||||
// Set the field and return
|
||||
return FieldManipulator.SetField(_internal, fieldName, value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,26 +108,5 @@ namespace SabreTools.DatItems.Formats
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Manipulation
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool SetField(DatItemField datItemField, string value)
|
||||
{
|
||||
// Get the correct internal field name
|
||||
string? fieldName = datItemField switch
|
||||
{
|
||||
DatItemField.Default => Models.Metadata.DipValue.DefaultKey,
|
||||
DatItemField.Setting_Default => Models.Metadata.DipValue.DefaultKey,
|
||||
DatItemField.Value => Models.Metadata.DipValue.ValueKey,
|
||||
DatItemField.Setting_Value => Models.Metadata.DipValue.ValueKey,
|
||||
_ => null,
|
||||
};
|
||||
|
||||
// Set the field and return
|
||||
return FieldManipulator.SetField(_internal, fieldName, value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -286,31 +286,6 @@ namespace SabreTools.DatItems.Formats
|
||||
|
||||
#endregion
|
||||
|
||||
#region Manipulation
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool SetField(DatItemField datItemField, string value)
|
||||
{
|
||||
// Get the correct internal field name
|
||||
string? fieldName = datItemField switch
|
||||
{
|
||||
DatItemField.Index => Models.Metadata.Disk.IndexKey,
|
||||
DatItemField.MD5 => Models.Metadata.Disk.MD5Key,
|
||||
DatItemField.Merge => Models.Metadata.Disk.MergeKey,
|
||||
DatItemField.Optional => Models.Metadata.Disk.OptionalKey,
|
||||
DatItemField.Region => Models.Metadata.Disk.RegionKey,
|
||||
DatItemField.SHA1 => Models.Metadata.Disk.SHA1Key,
|
||||
DatItemField.Status => Models.Metadata.Disk.StatusKey,
|
||||
DatItemField.Writable => Models.Metadata.Disk.WritableKey,
|
||||
_ => null,
|
||||
};
|
||||
|
||||
// Set the field and return
|
||||
return FieldManipulator.SetField(_internal, fieldName, value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Sorting and Merging
|
||||
|
||||
/// <inheritdoc/>
|
||||
|
||||
@@ -71,22 +71,5 @@ namespace SabreTools.DatItems.Formats
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Manipulation
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool SetField(DatItemField datItemField, string value)
|
||||
{
|
||||
// Get the correct internal field name
|
||||
string? fieldName = datItemField switch
|
||||
{
|
||||
_ => null,
|
||||
};
|
||||
|
||||
// Set the field and return
|
||||
return FieldManipulator.SetField(_internal, fieldName, value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -231,36 +231,5 @@ namespace SabreTools.DatItems.Formats
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Manipulation
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool SetField(DatItemField datItemField, string value)
|
||||
{
|
||||
// Get the correct internal field name
|
||||
string? fieldName = datItemField switch
|
||||
{
|
||||
DatItemField.DisplayType => Models.Metadata.Display.DisplayTypeKey,
|
||||
DatItemField.FlipX => Models.Metadata.Display.FlipXKey,
|
||||
DatItemField.HBEnd => Models.Metadata.Display.HBEndKey,
|
||||
DatItemField.HBStart => Models.Metadata.Display.HBStartKey,
|
||||
DatItemField.Height => Models.Metadata.Display.HeightKey,
|
||||
DatItemField.HTotal => Models.Metadata.Display.HTotalKey,
|
||||
DatItemField.PixClock => Models.Metadata.Display.PixClockKey,
|
||||
DatItemField.Refresh => Models.Metadata.Display.RefreshKey,
|
||||
DatItemField.Rotate => Models.Metadata.Display.RotateKey,
|
||||
DatItemField.Tag => Models.Metadata.Display.TagKey,
|
||||
DatItemField.VBEnd => Models.Metadata.Display.VBEndKey,
|
||||
DatItemField.VBStart => Models.Metadata.Display.VBStartKey,
|
||||
DatItemField.VTotal => Models.Metadata.Display.VTotalKey,
|
||||
DatItemField.Width => Models.Metadata.Display.WidthKey,
|
||||
_ => null,
|
||||
};
|
||||
|
||||
// Set the field and return
|
||||
return FieldManipulator.SetField(_internal, fieldName, value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -162,30 +162,5 @@ namespace SabreTools.DatItems.Formats
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Manipulation
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool SetField(DatItemField datItemField, string value)
|
||||
{
|
||||
// Get the correct internal field name
|
||||
string? fieldName = datItemField switch
|
||||
{
|
||||
DatItemField.CocktailStatus => Models.Metadata.Driver.CocktailKey,
|
||||
DatItemField.EmulationStatus => Models.Metadata.Driver.EmulationKey,
|
||||
DatItemField.Incomplete => Models.Metadata.Driver.IncompleteKey,
|
||||
DatItemField.NoSoundHardware => Models.Metadata.Driver.NoSoundHardwareKey,
|
||||
DatItemField.RequiresArtwork => Models.Metadata.Driver.RequiresArtworkKey,
|
||||
DatItemField.SaveStateStatus => Models.Metadata.Driver.SaveStateKey,
|
||||
DatItemField.SupportStatus => Models.Metadata.Driver.StatusKey,
|
||||
DatItemField.Unofficial => Models.Metadata.Driver.UnofficialKey,
|
||||
_ => null,
|
||||
};
|
||||
|
||||
// Set the field and return
|
||||
return FieldManipulator.SetField(_internal, fieldName, value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,22 +70,5 @@ namespace SabreTools.DatItems.Formats
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Manipulation
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool SetField(DatItemField datItemField, string value)
|
||||
{
|
||||
// Get the correct internal field name
|
||||
string? fieldName = datItemField switch
|
||||
{
|
||||
_ => null,
|
||||
};
|
||||
|
||||
// Set the field and return
|
||||
return FieldManipulator.SetField(_internal, fieldName, value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,25 +93,5 @@ namespace SabreTools.DatItems.Formats
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Manipulation
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool SetField(DatItemField datItemField, string value)
|
||||
{
|
||||
// Get the correct internal field name
|
||||
string? fieldName = datItemField switch
|
||||
{
|
||||
DatItemField.FeatureOverall => Models.Metadata.Feature.OverallKey,
|
||||
DatItemField.FeatureStatus => Models.Metadata.Feature.StatusKey,
|
||||
DatItemField.FeatureType => Models.Metadata.Feature.FeatureTypeKey,
|
||||
_ => null,
|
||||
};
|
||||
|
||||
// Set the field and return
|
||||
return FieldManipulator.SetField(_internal, fieldName, value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -326,24 +326,6 @@ namespace SabreTools.DatItems.Formats
|
||||
|
||||
#endregion
|
||||
|
||||
#region Manipulation
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool SetField(DatItemField datItemField, string value)
|
||||
{
|
||||
// Get the correct internal field name
|
||||
string? fieldName = datItemField switch
|
||||
{
|
||||
// TODO: Figure out what fields go here
|
||||
_ => null,
|
||||
};
|
||||
|
||||
// Set the field and return
|
||||
return FieldManipulator.SetField(_internal, fieldName, value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Sorting and Merging
|
||||
|
||||
/// <inheritdoc/>
|
||||
|
||||
@@ -80,23 +80,5 @@ namespace SabreTools.DatItems.Formats
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Manipulation
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool SetField(DatItemField datItemField, string value)
|
||||
{
|
||||
// Get the correct internal field name
|
||||
string? fieldName = datItemField switch
|
||||
{
|
||||
DatItemField.Value => Models.Metadata.Info.ValueKey,
|
||||
_ => null,
|
||||
};
|
||||
|
||||
// Set the field and return
|
||||
return FieldManipulator.SetField(_internal, fieldName, value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,26 +116,5 @@ namespace SabreTools.DatItems.Formats
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Manipulation
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool SetField(DatItemField datItemField, string value)
|
||||
{
|
||||
// Get the correct internal field name
|
||||
string? fieldName = datItemField switch
|
||||
{
|
||||
DatItemField.Coins => Models.Metadata.Input.CoinsKey,
|
||||
DatItemField.Players => Models.Metadata.Input.PlayersKey,
|
||||
DatItemField.Service => Models.Metadata.Input.ServiceKey,
|
||||
DatItemField.Tilt => Models.Metadata.Input.TiltKey,
|
||||
_ => null,
|
||||
};
|
||||
|
||||
// Set the field and return
|
||||
return FieldManipulator.SetField(_internal, fieldName, value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,23 +80,5 @@ namespace SabreTools.DatItems.Formats
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Manipulation
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool SetField(DatItemField datItemField, string value)
|
||||
{
|
||||
// Get the correct internal field name
|
||||
string? fieldName = datItemField switch
|
||||
{
|
||||
DatItemField.Instance_BriefName => Models.Metadata.Instance.BriefNameKey,
|
||||
_ => null,
|
||||
};
|
||||
|
||||
// Set the field and return
|
||||
return FieldManipulator.SetField(_internal, fieldName, value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -184,27 +184,6 @@ namespace SabreTools.DatItems.Formats
|
||||
|
||||
#endregion
|
||||
|
||||
#region Manipulation
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool SetField(DatItemField datItemField, string value)
|
||||
{
|
||||
// Get the correct internal field name
|
||||
string? fieldName = datItemField switch
|
||||
{
|
||||
DatItemField.MD5 => Models.Metadata.Media.MD5Key,
|
||||
DatItemField.SHA1 => Models.Metadata.Media.SHA1Key,
|
||||
DatItemField.SHA256 => Models.Metadata.Media.SHA256Key,
|
||||
DatItemField.SpamSum => Models.Metadata.Media.SpamSumKey,
|
||||
_ => null,
|
||||
};
|
||||
|
||||
// Set the field and return
|
||||
return FieldManipulator.SetField(_internal, fieldName, value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Sorting and Merging
|
||||
|
||||
/// <inheritdoc/>
|
||||
|
||||
@@ -87,23 +87,5 @@ namespace SabreTools.DatItems.Formats
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Manipulation
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool SetField(DatItemField datItemField, string value)
|
||||
{
|
||||
// Get the correct internal field name
|
||||
string? fieldName = datItemField switch
|
||||
{
|
||||
DatItemField.Part_Interface => Models.Metadata.Part.InterfaceKey,
|
||||
_ => null,
|
||||
};
|
||||
|
||||
// Set the field and return
|
||||
return FieldManipulator.SetField(_internal, fieldName, value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,24 +80,5 @@ namespace SabreTools.DatItems.Formats
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Manipulation
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool SetField(DatItemField datItemField, string value)
|
||||
{
|
||||
// Get the correct internal field name
|
||||
string? fieldName = datItemField switch
|
||||
{
|
||||
DatItemField.Value => Models.Metadata.Feature.ValueKey,
|
||||
DatItemField.Part_Feature_Value => Models.Metadata.Feature.ValueKey,
|
||||
_ => null,
|
||||
};
|
||||
|
||||
// Set the field and return
|
||||
return FieldManipulator.SetField(_internal, fieldName, value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,23 +74,5 @@ namespace SabreTools.DatItems.Formats
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Manipulation
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool SetField(DatItemField datItemField, string value)
|
||||
{
|
||||
// Get the correct internal field name
|
||||
string? fieldName = datItemField switch
|
||||
{
|
||||
DatItemField.Tag => Models.Metadata.Port.TagKey,
|
||||
_ => null,
|
||||
};
|
||||
|
||||
// Set the field and return
|
||||
return FieldManipulator.SetField(_internal, fieldName, value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,24 +93,5 @@ namespace SabreTools.DatItems.Formats
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Manipulation
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool SetField(DatItemField datItemField, string value)
|
||||
{
|
||||
// Get the correct internal field name
|
||||
string? fieldName = datItemField switch
|
||||
{
|
||||
DatItemField.Content => Models.Metadata.RamOption.ContentKey,
|
||||
DatItemField.Default => Models.Metadata.RamOption.DefaultKey,
|
||||
_ => null,
|
||||
};
|
||||
|
||||
// Set the field and return
|
||||
return FieldManipulator.SetField(_internal, fieldName, value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,26 +117,5 @@ namespace SabreTools.DatItems.Formats
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Manipulation
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool SetField(DatItemField datItemField, string value)
|
||||
{
|
||||
// Get the correct internal field name
|
||||
string? fieldName = datItemField switch
|
||||
{
|
||||
DatItemField.Date => Models.Metadata.Release.DateKey,
|
||||
DatItemField.Default => Models.Metadata.Release.DefaultKey,
|
||||
DatItemField.Language => Models.Metadata.Release.LanguageKey,
|
||||
DatItemField.Region => Models.Metadata.Release.RegionKey,
|
||||
_ => null,
|
||||
};
|
||||
|
||||
// Set the field and return
|
||||
return FieldManipulator.SetField(_internal, fieldName, value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -187,23 +187,5 @@ namespace SabreTools.DatItems.Formats
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Manipulation
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool SetField(DatItemField datItemField, string value)
|
||||
{
|
||||
// Get the correct internal field name
|
||||
string? fieldName = datItemField switch
|
||||
{
|
||||
// TODO: Figure out what fields go here
|
||||
_ => null,
|
||||
};
|
||||
|
||||
// Set the field and return
|
||||
return FieldManipulator.SetField(_internal, fieldName, value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -597,64 +597,6 @@ namespace SabreTools.DatItems.Formats
|
||||
|
||||
#endregion
|
||||
|
||||
#region Manipulation
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool SetField(DatItemField datItemField, string value)
|
||||
{
|
||||
// Get the correct internal field name
|
||||
string? fieldName = datItemField switch
|
||||
{
|
||||
DatItemField.AltName => Models.Metadata.Rom.AltRomnameKey,
|
||||
DatItemField.AltTitle => Models.Metadata.Rom.AltTitleKey,
|
||||
DatItemField.ArchiveDotOrgFormat => Models.Metadata.Rom.FormatKey,
|
||||
DatItemField.ArchiveDotOrgSource => Models.Metadata.Rom.SourceKey,
|
||||
DatItemField.Bios => Models.Metadata.Rom.BiosKey,
|
||||
//DatItemField.Boot => Models.Metadata.Rom.BootKey,
|
||||
DatItemField.CRC => Models.Metadata.Rom.CRCKey,
|
||||
DatItemField.Date => Models.Metadata.Rom.DateKey,
|
||||
DatItemField.Inverted => Models.Metadata.Rom.InvertedKey,
|
||||
DatItemField.LoadFlag => Models.Metadata.Rom.LoadFlagKey,
|
||||
DatItemField.MD5 => Models.Metadata.Rom.MD5Key,
|
||||
DatItemField.Merge => Models.Metadata.Rom.MergeKey,
|
||||
DatItemField.MIA => Models.Metadata.Rom.MIAKey,
|
||||
DatItemField.Offset => Models.Metadata.Rom.OffsetKey,
|
||||
DatItemField.OpenMSXSubType => Models.Metadata.Rom.OpenMSXMediaType, // TODO: Fix with Key suffix
|
||||
DatItemField.OpenMSXType => Models.Metadata.Rom.OpenMSXType, // TODO: Fix with Key suffix
|
||||
DatItemField.Optional => Models.Metadata.Rom.OptionalKey,
|
||||
//DatItemField.Original => Models.Metadata.Rom.OriginalKey,
|
||||
DatItemField.OriginalFilename => Models.Metadata.Rom.OriginalKey,
|
||||
DatItemField.Region => Models.Metadata.Rom.RegionKey,
|
||||
DatItemField.Remark => Models.Metadata.Rom.RemarkKey,
|
||||
DatItemField.Rotation => Models.Metadata.Rom.RotationKey,
|
||||
DatItemField.SHA1 => Models.Metadata.Rom.SHA1Key,
|
||||
DatItemField.SHA256 => Models.Metadata.Rom.SHA256Key,
|
||||
DatItemField.SHA384 => Models.Metadata.Rom.SHA384Key,
|
||||
DatItemField.SHA512 => Models.Metadata.Rom.SHA512Key,
|
||||
DatItemField.Size => Models.Metadata.Rom.SizeKey,
|
||||
DatItemField.SpamSum => Models.Metadata.Rom.SpamSumKey,
|
||||
DatItemField.Status => Models.Metadata.Rom.StatusKey,
|
||||
DatItemField.Summation => Models.Metadata.Rom.SummationKey,
|
||||
DatItemField.Value => Models.Metadata.Rom.ValueKey,
|
||||
_ => null,
|
||||
};
|
||||
|
||||
// A null value means special handling is needed
|
||||
if (fieldName == null)
|
||||
{
|
||||
switch (datItemField)
|
||||
{
|
||||
case DatItemField.Boot: Boot = value; return true;
|
||||
case DatItemField.Original: Original = new Original { Content = value }; return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Set the field and return
|
||||
return FieldManipulator.SetField(_internal, fieldName, value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Sorting and Merging
|
||||
|
||||
/// <inheritdoc/>
|
||||
|
||||
@@ -70,22 +70,5 @@ namespace SabreTools.DatItems.Formats
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Manipulation
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool SetField(DatItemField datItemField, string value)
|
||||
{
|
||||
// Get the correct internal field name
|
||||
string? fieldName = datItemField switch
|
||||
{
|
||||
_ => null,
|
||||
};
|
||||
|
||||
// Set the field and return
|
||||
return FieldManipulator.SetField(_internal, fieldName, value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,23 +175,5 @@ namespace SabreTools.DatItems.Formats
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Manipulation
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool SetField(DatItemField datItemField, string value)
|
||||
{
|
||||
// Get the correct internal field name
|
||||
string? fieldName = datItemField switch
|
||||
{
|
||||
// TODO: Figure out what fields go here
|
||||
_ => null,
|
||||
};
|
||||
|
||||
// Set the field and return
|
||||
return FieldManipulator.SetField(_internal, fieldName, value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,23 +80,5 @@ namespace SabreTools.DatItems.Formats
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Manipulation
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool SetField(DatItemField datItemField, string value)
|
||||
{
|
||||
// Get the correct internal field name
|
||||
string? fieldName = datItemField switch
|
||||
{
|
||||
DatItemField.Value => Models.Metadata.SharedFeat.ValueKey,
|
||||
_ => null,
|
||||
};
|
||||
|
||||
// Set the field and return
|
||||
return FieldManipulator.SetField(_internal, fieldName, value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,22 +85,5 @@ namespace SabreTools.DatItems.Formats
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Manipulation
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool SetField(DatItemField datItemField, string value)
|
||||
{
|
||||
// Get the correct internal field name
|
||||
string? fieldName = datItemField switch
|
||||
{
|
||||
_ => null,
|
||||
};
|
||||
|
||||
// Set the field and return
|
||||
return FieldManipulator.SetField(_internal, fieldName, value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,25 +93,5 @@ namespace SabreTools.DatItems.Formats
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Manipulation
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool SetField(DatItemField datItemField, string value)
|
||||
{
|
||||
// Get the correct internal field name
|
||||
string? fieldName = datItemField switch
|
||||
{
|
||||
DatItemField.Default => Models.Metadata.SlotOption.DefaultKey,
|
||||
DatItemField.SlotOption_Default => Models.Metadata.SlotOption.DefaultKey,
|
||||
DatItemField.SlotOption_DeviceName => Models.Metadata.SlotOption.DevNameKey,
|
||||
_ => null,
|
||||
};
|
||||
|
||||
// Set the field and return
|
||||
return FieldManipulator.SetField(_internal, fieldName, value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,25 +112,5 @@ namespace SabreTools.DatItems.Formats
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Manipulation
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool SetField(DatItemField datItemField, string value)
|
||||
{
|
||||
// Get the correct internal field name
|
||||
string? fieldName = datItemField switch
|
||||
{
|
||||
DatItemField.Filter => Models.Metadata.SoftwareList.FilterKey,
|
||||
DatItemField.SoftwareListStatus => Models.Metadata.SoftwareList.StatusKey,
|
||||
DatItemField.Tag => Models.Metadata.SoftwareList.TagKey,
|
||||
_ => null,
|
||||
};
|
||||
|
||||
// Set the field and return
|
||||
return FieldManipulator.SetField(_internal, fieldName, value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,23 +62,5 @@ namespace SabreTools.DatItems.Formats
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Manipulation
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool SetField(DatItemField datItemField, string value)
|
||||
{
|
||||
// Get the correct internal field name
|
||||
string? fieldName = datItemField switch
|
||||
{
|
||||
DatItemField.Default => Models.Metadata.Sound.ChannelsKey,
|
||||
_ => null,
|
||||
};
|
||||
|
||||
// Set the field and return
|
||||
return FieldManipulator.SetField(_internal, fieldName, value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -225,23 +225,5 @@ namespace SabreTools.DatItems.Formats
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Manipulation
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool SetField(DatItemField datItemField, string value)
|
||||
{
|
||||
// Get the correct internal field name
|
||||
string? fieldName = datItemField switch
|
||||
{
|
||||
// TODO: Figure out what fields go here
|
||||
_ => null,
|
||||
};
|
||||
|
||||
// Set the field and return
|
||||
return FieldManipulator.SetField(_internal, fieldName, value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -560,77 +560,12 @@ namespace SabreTools.DatItems
|
||||
/// <summary>
|
||||
/// Set a field in the Machine from a mapping string
|
||||
/// </summary>
|
||||
/// <param name="machineField">Machine field to set</param>
|
||||
/// <param name="fieldName">Field to set</param>
|
||||
/// <param name="value">String representing the value to set</param>
|
||||
/// <returns>True if the setting was successful, false otherwise</returns>
|
||||
/// <remarks>This only performs minimal validation before setting</remarks>
|
||||
public bool SetField(MachineField machineField, string value)
|
||||
{
|
||||
// Get the correct internal field name
|
||||
string? fieldName = machineField switch
|
||||
{
|
||||
MachineField.Board => Models.Metadata.Machine.BoardKey,
|
||||
MachineField.Buttons => Models.Metadata.Machine.ButtonsKey,
|
||||
MachineField.Category => Models.Metadata.Machine.CategoryKey,
|
||||
MachineField.CloneOf => Models.Metadata.Machine.CloneOfKey,
|
||||
MachineField.CloneOfID => Models.Metadata.Machine.CloneOfIdKey,
|
||||
MachineField.Comment => Models.Metadata.Machine.CommentKey,
|
||||
MachineField.Control => Models.Metadata.Machine.ControlKey,
|
||||
MachineField.Country => Models.Metadata.Machine.CountryKey,
|
||||
//MachineField.CRC => Models.Metadata.Machine.CRCKey,
|
||||
MachineField.Description => Models.Metadata.Machine.DescriptionKey,
|
||||
//MachineField.Developer => Models.Metadata.Machine.DeveloperKey,
|
||||
MachineField.DisplayCount => Models.Metadata.Machine.DisplayCountKey,
|
||||
MachineField.DisplayType => Models.Metadata.Machine.DisplayTypeKey,
|
||||
//MachineField.Enabled => Models.Metadata.Machine.EnabledKey,
|
||||
MachineField.GenMSXID => Models.Metadata.Machine.GenMSXIDKey,
|
||||
//MachineField.Genre => Models.Metadata.Machine.GenreKey,
|
||||
MachineField.History => Models.Metadata.Machine.HistoryKey,
|
||||
MachineField.ID => Models.Metadata.Machine.IdKey,
|
||||
MachineField.Manufacturer => Models.Metadata.Machine.ManufacturerKey,
|
||||
MachineField.Name => Models.Metadata.Machine.NameKey,
|
||||
MachineField.Players => Models.Metadata.Machine.PlayersKey,
|
||||
MachineField.Publisher => Models.Metadata.Machine.PublisherKey,
|
||||
//MachineField.Ratings => Models.Metadata.Machine.RatingsKey,
|
||||
MachineField.RebuildTo => Models.Metadata.Machine.RebuildToKey,
|
||||
//MachineField.RelatedTo => Models.Metadata.Machine.RelatedToKey,
|
||||
MachineField.RomOf => Models.Metadata.Machine.RomOfKey,
|
||||
MachineField.Rotation => Models.Metadata.Machine.RotationKey,
|
||||
MachineField.Runnable => Models.Metadata.Machine.RunnableKey,
|
||||
MachineField.SampleOf => Models.Metadata.Machine.SampleOfKey,
|
||||
//MachineField.Score => Models.Metadata.Machine.ScoreKey,
|
||||
MachineField.SourceFile => Models.Metadata.Machine.SourceFileKey,
|
||||
MachineField.Status => Models.Metadata.Machine.StatusKey,
|
||||
//MachineField.Subgenre => Models.Metadata.Machine.SubgenreKey,
|
||||
MachineField.Supported => Models.Metadata.Machine.SupportedKey,
|
||||
MachineField.System => Models.Metadata.Machine.SystemKey,
|
||||
//MachineField.TitleID => Models.Metadata.Machine.TitleIDKey,
|
||||
//MachineField.Type => Models.Metadata.Machine.TypeKey,
|
||||
MachineField.Year => Models.Metadata.Machine.YearKey,
|
||||
_ => null,
|
||||
};
|
||||
|
||||
// A null value means special handling is needed
|
||||
if (fieldName == null)
|
||||
{
|
||||
switch (machineField)
|
||||
{
|
||||
case MachineField.CRC: Crc = value.AsYesNo(); return true;
|
||||
case MachineField.Developer: Developer = value; return true;
|
||||
case MachineField.Enabled: Enabled = value; return true;
|
||||
case MachineField.Genre: Genre = value; return true;
|
||||
case MachineField.Ratings: Ratings = value; return true;
|
||||
case MachineField.RelatedTo: RelatedTo = value; return true;
|
||||
case MachineField.Score: Score = value; return true;
|
||||
case MachineField.Subgenre: Subgenre = value; return true;
|
||||
case MachineField.TitleID: TitleID = value; return true;
|
||||
case MachineField.Type: MachineType = value.AsEnumValue<MachineType>(); return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Remove the field and return
|
||||
return FieldManipulator.SetField(_machine, fieldName, value);
|
||||
}
|
||||
public bool SetField(string? fieldName, string value)
|
||||
=> FieldManipulator.SetField(_machine, fieldName, value);
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using SabreTools.Core;
|
||||
using SabreTools.Core.Tools;
|
||||
using SabreTools.DatFiles;
|
||||
using SabreTools.DatItems;
|
||||
using SabreTools.Logging;
|
||||
@@ -17,7 +14,7 @@ namespace SabreTools.Filtering
|
||||
/// <summary>
|
||||
/// List of extras to apply
|
||||
/// </summary>
|
||||
public List<ExtraIniItem> Items { get; set; } = new List<ExtraIniItem>();
|
||||
public List<ExtraIniItem> Items { get; set; } = [];
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -71,8 +68,7 @@ namespace SabreTools.Filtering
|
||||
string fieldString = inputTrimmed.Split(':')[0].ToLowerInvariant().Trim('"', ' ', '\t');
|
||||
string fileString = inputTrimmed.Substring(fieldString.Length + 1).Trim('"', ' ', '\t');
|
||||
|
||||
item.DatItemField = fieldString.AsDatItemField();
|
||||
item.MachineField = fieldString.AsMachineField();
|
||||
item.FieldName = SabreTools.Filter.FilterParser.ParseFilterId(fieldString);
|
||||
if (item.PopulateFromFile(fileString))
|
||||
Items.Add(item);
|
||||
}
|
||||
@@ -96,7 +92,7 @@ namespace SabreTools.Filtering
|
||||
if (Items == null || !Items.Any())
|
||||
return true;
|
||||
|
||||
InternalStopwatch watch = new("Applying extra mappings to DAT");
|
||||
var watch = new InternalStopwatch("Applying extra mappings to DAT");
|
||||
|
||||
try
|
||||
{
|
||||
@@ -127,10 +123,11 @@ namespace SabreTools.Filtering
|
||||
combinedDatItemMaps.TryGetValue(machine, out var datItemMappings);
|
||||
|
||||
// Create a setter with the new mappings
|
||||
Setter setter = new()
|
||||
var setter = new Setter();
|
||||
setter.PopulateSettersFromList()
|
||||
{
|
||||
MachineMappings = machineMappings,
|
||||
DatItemMappings = datItemMappings,
|
||||
MachineFieldMappings = machineMappings,
|
||||
ItemFieldMappings = datItemMappings,
|
||||
};
|
||||
|
||||
// Loop through and set the fields accordingly
|
||||
@@ -154,25 +151,54 @@ namespace SabreTools.Filtering
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Combine ExtraIni fields
|
||||
/// </summary>
|
||||
/// <returns>Mapping dictionary from machine name to field mapping</returns>
|
||||
private (List<string> Keys, List<string> Values) CombineExtras()
|
||||
{
|
||||
var keys = new List<string>();
|
||||
var values = new List<string>();
|
||||
|
||||
// Loop through each of the extras
|
||||
foreach (ExtraIniItem item in Items)
|
||||
{
|
||||
|
||||
|
||||
foreach (var mapping in item.Mappings)
|
||||
{
|
||||
string machineName = mapping.Key;
|
||||
string value = mapping.Value;
|
||||
|
||||
mapping[machineName] = new Dictionary<string, string>
|
||||
{
|
||||
[item.FieldName!] = value,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return mapping;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Combine MachineField-based ExtraIni fields
|
||||
/// </summary>
|
||||
/// <returns>Mapping dictionary from machine name to field mapping</returns>
|
||||
private Dictionary<string, Dictionary<MachineField, string>> CombineMachineExtras()
|
||||
private Dictionary<string, Dictionary<string, string>> CombineMachineExtras()
|
||||
{
|
||||
var machineMap = new Dictionary<string, Dictionary<MachineField, string>>();
|
||||
var machineMap = new Dictionary<string, Dictionary<string, string>>();
|
||||
|
||||
// Loop through each of the extras
|
||||
foreach (ExtraIniItem item in Items.Where(i => i.MachineField != MachineField.NULL))
|
||||
foreach (ExtraIniItem item in Items.Where(i => i.MachineField != null))
|
||||
{
|
||||
foreach (var mapping in item.Mappings)
|
||||
{
|
||||
string machineName = mapping.Key;
|
||||
string value = mapping.Value;
|
||||
|
||||
machineMap[machineName] = new Dictionary<MachineField, string>
|
||||
machineMap[machineName] = new Dictionary<string, string>
|
||||
{
|
||||
[item.MachineField] = value,
|
||||
[item.MachineField!] = value,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -184,21 +210,21 @@ namespace SabreTools.Filtering
|
||||
/// Combine DatItemField-based ExtraIni fields
|
||||
/// </summary>
|
||||
/// <returns>Mapping dictionary from machine name to field mapping</returns>
|
||||
private Dictionary<string, Dictionary<DatItemField, string>> CombineDatItemExtras()
|
||||
private Dictionary<string, Dictionary<string, string>> CombineDatItemExtras()
|
||||
{
|
||||
var datItemMap = new Dictionary<string, Dictionary<DatItemField, string>>();
|
||||
var datItemMap = new Dictionary<string, Dictionary<string, string>>();
|
||||
|
||||
// Loop through each of the extras
|
||||
foreach (ExtraIniItem item in Items.Where(i => i.DatItemField != DatItemField.NULL))
|
||||
foreach (ExtraIniItem item in Items.Where(i => i.ItemField != null))
|
||||
{
|
||||
foreach (var mapping in item.Mappings)
|
||||
{
|
||||
string machineName = mapping.Key;
|
||||
string value = mapping.Value;
|
||||
|
||||
datItemMap[machineName] = new Dictionary<DatItemField, string>()
|
||||
datItemMap[machineName] = new Dictionary<string, string>()
|
||||
{
|
||||
[item.DatItemField] = value,
|
||||
[item.ItemField!] = value,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using SabreTools.Core;
|
||||
using SabreTools.IO.Readers;
|
||||
using SabreTools.Logging;
|
||||
|
||||
@@ -12,19 +10,14 @@ namespace SabreTools.Filtering
|
||||
#region Fields
|
||||
|
||||
/// <summary>
|
||||
/// MachineField to update with INI information
|
||||
/// Type and field to update with INI information
|
||||
/// </summary>
|
||||
public MachineField MachineField { get; set; } = MachineField.NULL;
|
||||
|
||||
/// <summary>
|
||||
/// DatItemField to update with INI information
|
||||
/// </summary>
|
||||
public DatItemField DatItemField { get; set; } = DatItemField.NULL;
|
||||
public (string?, string?) FieldName { get; set; } = (null, null);
|
||||
|
||||
/// <summary>
|
||||
/// Mappings from machine names to value
|
||||
/// </summary>
|
||||
public Dictionary<string, string> Mappings { get; set; } = new Dictionary<string, string>();
|
||||
public Dictionary<string, string> Mappings { get; } = [];
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ namespace SabreTools.Filtering
|
||||
/// <summary>
|
||||
/// Populate the exclusion objects using a field name
|
||||
/// </summary>
|
||||
/// <param name="field">Field names</param>
|
||||
/// <param name="field">Field name</param>
|
||||
public void PopulateExclusions(string field)
|
||||
=> PopulateExclusionsFromList([field]);
|
||||
|
||||
@@ -100,31 +100,29 @@ namespace SabreTools.Filtering
|
||||
return false;
|
||||
|
||||
// Get the parser pair out of it, if possible
|
||||
(string? key, string? value) = FilterParser.ParseFilterId(field);
|
||||
if (key != null && value != null)
|
||||
{
|
||||
switch (key)
|
||||
(string? type, string? key) = FilterParser.ParseFilterId(field);
|
||||
if (type == null || key == null)
|
||||
return false;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case Models.Metadata.MetadataFile.HeaderKey:
|
||||
HeaderFieldNames.Add(value);
|
||||
HeaderFieldNames.Add(key);
|
||||
return true;
|
||||
|
||||
case Models.Metadata.MetadataFile.MachineKey:
|
||||
MachineFieldNames.Add(value);
|
||||
MachineFieldNames.Add(key);
|
||||
return true;
|
||||
|
||||
default:
|
||||
if (!ItemFieldNames.ContainsKey(key))
|
||||
ItemFieldNames[key] = [];
|
||||
if (!ItemFieldNames.ContainsKey(type))
|
||||
ItemFieldNames[type] = [];
|
||||
|
||||
ItemFieldNames[key].Add(value);
|
||||
ItemFieldNames[type].Add(key);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Running
|
||||
@@ -183,11 +181,8 @@ namespace SabreTools.Filtering
|
||||
/// <param name="datItem">DatHeader to remove fields from</param>
|
||||
public void RemoveFields(DatHeader datHeader)
|
||||
{
|
||||
if (datHeader == null)
|
||||
return;
|
||||
|
||||
// If there are no field names, return
|
||||
if (HeaderFieldNames == null || !HeaderFieldNames.Any())
|
||||
// If we have an invalid input, return
|
||||
if (datHeader == null || !HeaderFieldNames.Any())
|
||||
return;
|
||||
|
||||
foreach (var fieldName in HeaderFieldNames)
|
||||
@@ -203,11 +198,8 @@ namespace SabreTools.Filtering
|
||||
/// <param name="machine">Machine to remove fields from</param>
|
||||
public void RemoveFields(Machine? machine)
|
||||
{
|
||||
if (machine == null)
|
||||
return;
|
||||
|
||||
// If there are no field names, return
|
||||
if (MachineFieldNames == null || !MachineFieldNames.Any())
|
||||
// If we have an invalid input, return
|
||||
if (machine == null || !MachineFieldNames.Any())
|
||||
return;
|
||||
|
||||
foreach (var fieldName in MachineFieldNames)
|
||||
@@ -228,7 +220,7 @@ namespace SabreTools.Filtering
|
||||
#region Common
|
||||
|
||||
// Handle Machine fields
|
||||
if (MachineFieldNames != null && MachineFieldNames.Any() && datItem.Machine != null)
|
||||
if (MachineFieldNames.Any() && datItem.Machine != null)
|
||||
RemoveFields(datItem.Machine);
|
||||
|
||||
// If there are no field names, return
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace SabreTools.Test.DatFiles
|
||||
var datItem = CreateDatItem();
|
||||
Setter setter = new()
|
||||
{
|
||||
DatItemMappings = new Dictionary<DatItemField, string> { [DatItemField.Name] = "bar" }
|
||||
ItemFieldMappings = new Dictionary<DatItemField, string> { [DatItemField.Name] = "bar" }
|
||||
};
|
||||
setter.SetFields(datItem);
|
||||
Assert.Equal("bar", datItem.GetName());
|
||||
@@ -28,7 +28,7 @@ namespace SabreTools.Test.DatFiles
|
||||
var datItem = CreateDatItem();
|
||||
Setter setter = new()
|
||||
{
|
||||
MachineMappings = new Dictionary<MachineField, string> { [MachineField.Name] = "foo" }
|
||||
MachineFieldMappings = new Dictionary<MachineField, string> { [MachineField.Name] = "foo" }
|
||||
};
|
||||
setter.SetFields(datItem.Machine);
|
||||
Assert.Equal("foo", datItem.Machine.Name);
|
||||
|
||||
@@ -350,7 +350,7 @@ Reset the internal state: reset();";
|
||||
ExtraIniItem extraIniItem = new()
|
||||
{
|
||||
MachineField = extraMachineField,
|
||||
DatItemField = extraDatItemField,
|
||||
ItemField = extraDatItemField,
|
||||
};
|
||||
extraIniItem.PopulateFromFile(extraFile);
|
||||
extraIni.Items.Add(extraIniItem);
|
||||
|
||||
Reference in New Issue
Block a user