mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Handle Configuration; promote Location, Setting
This commit is contained in:
@@ -262,6 +262,9 @@ namespace SabreTools.Library.DatFiles
|
||||
case ItemType.Instance:
|
||||
datItem = datItemObj.ToObject<Instance>();
|
||||
break;
|
||||
case ItemType.Location:
|
||||
datItem = datItemObj.ToObject<Location>();
|
||||
break;
|
||||
case ItemType.Media:
|
||||
datItem = datItemObj.ToObject<Media>();
|
||||
break;
|
||||
@@ -280,6 +283,9 @@ namespace SabreTools.Library.DatFiles
|
||||
case ItemType.Sample:
|
||||
datItem = datItemObj.ToObject<Sample>();
|
||||
break;
|
||||
case ItemType.Setting:
|
||||
datItem = datItemObj.ToObject<Setting>();
|
||||
break;
|
||||
case ItemType.Slot:
|
||||
datItem = datItemObj.ToObject<Slot>();
|
||||
break;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
using SabreTools.Library.DatItems;
|
||||
@@ -99,70 +100,6 @@ namespace SabreTools.Library.DatItems
|
||||
#endregion
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents one ListXML conflocation or diplocation
|
||||
/// </summary>
|
||||
[JsonObject("location")]
|
||||
public class Location
|
||||
{
|
||||
#region Fields
|
||||
|
||||
/// <summary>
|
||||
/// Location name
|
||||
/// </summary>
|
||||
[JsonProperty("name")]
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Location ID
|
||||
/// </summary>
|
||||
[JsonProperty("number", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public string Number { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Determines if location is inverted or not
|
||||
/// </summary>
|
||||
[JsonProperty("inverted", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public bool? Inverted { get; set; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents one ListXML confsetting or dipvalue
|
||||
/// </summary>
|
||||
[JsonObject("setting")]
|
||||
public class Setting
|
||||
{
|
||||
#region Fields
|
||||
|
||||
/// <summary>
|
||||
/// Setting name
|
||||
/// </summary>
|
||||
[JsonProperty("name")]
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Setting value
|
||||
/// </summary>
|
||||
[JsonProperty("value", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public string Value { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Determines if the setting is default or not
|
||||
/// </summary>
|
||||
[JsonProperty("default", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public bool? Default { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// List of conditions on the setting
|
||||
/// </summary>
|
||||
[JsonProperty("conditions", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public List<Condition> Conditions { get; set; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents one ListXML slotoption
|
||||
/// </summary>
|
||||
|
||||
@@ -4,9 +4,6 @@ using System.Linq;
|
||||
using SabreTools.Library.Filtering;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
/// <summary>
|
||||
/// This holds all of the auxiliary types needed for proper parsing
|
||||
/// </summary>
|
||||
namespace SabreTools.Library.DatItems
|
||||
{
|
||||
/// <summary>
|
||||
|
||||
@@ -84,9 +84,32 @@ namespace SabreTools.Library.DatItems
|
||||
if (mappings.Keys.Contains(Field.DatItem_Mask))
|
||||
Mask = mappings[Field.DatItem_Mask];
|
||||
|
||||
// TODO: Handle DatItem_Condition*
|
||||
// TODO: Handle DatItem_Location*
|
||||
// TODO: Handle DatItem_Setting*
|
||||
// Field.DatItem_Conditions does not apply here
|
||||
if (Conditions != null)
|
||||
{
|
||||
foreach (Condition condition in Conditions)
|
||||
{
|
||||
condition.SetFields(mappings);
|
||||
}
|
||||
}
|
||||
|
||||
// Field.DatItem_Locations does not apply here
|
||||
if (Locations != null)
|
||||
{
|
||||
foreach (Location location in Locations)
|
||||
{
|
||||
location.SetFields(mappings);
|
||||
}
|
||||
}
|
||||
|
||||
// Field.DatItem_Settings does not apply here
|
||||
if (Settings != null)
|
||||
{
|
||||
foreach (Setting setting in Settings)
|
||||
{
|
||||
setting.SetFields(mappings);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -158,11 +181,38 @@ namespace SabreTools.Library.DatItems
|
||||
Configuration newOther = other as Configuration;
|
||||
|
||||
// If the Configuration information matches
|
||||
return (Name == newOther.Name && Tag == newOther.Tag && Mask == newOther.Mask);
|
||||
|
||||
// TODO: Handle DatItem_Condition*
|
||||
// TODO: Handle DatItem_Location*
|
||||
// TODO: Handle DatItem_Setting*
|
||||
bool match = (Name == newOther.Name && Tag == newOther.Tag && Mask == newOther.Mask);
|
||||
if (!match)
|
||||
return match;
|
||||
|
||||
// If the conditions match
|
||||
if (Conditions != null)
|
||||
{
|
||||
foreach (Condition condition in Conditions)
|
||||
{
|
||||
match &= newOther.Conditions.Contains(condition);
|
||||
}
|
||||
}
|
||||
|
||||
// If the locations match
|
||||
if (Locations != null)
|
||||
{
|
||||
foreach (Location location in Locations)
|
||||
{
|
||||
match &= newOther.Locations.Contains(location);
|
||||
}
|
||||
}
|
||||
|
||||
// If the settings match
|
||||
if (Settings != null)
|
||||
{
|
||||
foreach (Setting setting in Settings)
|
||||
{
|
||||
match &= newOther.Settings.Contains(setting);
|
||||
}
|
||||
}
|
||||
|
||||
return match;
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -225,9 +275,47 @@ namespace SabreTools.Library.DatItems
|
||||
if (filter.DatItem_Mask.MatchesNegativeSet(Mask) == true)
|
||||
return false;
|
||||
|
||||
// TODO: Handle DatItem_Condition*
|
||||
// TODO: Handle DatItem_Location*
|
||||
// TODO: Handle DatItem_Setting*
|
||||
// Filter on conditions
|
||||
if (filter.DatItem_Conditions.MatchesNeutral(null, Conditions != null ? (bool?)(Conditions.Count > 0) : null) == false)
|
||||
return false;
|
||||
|
||||
// Filter on individual conditions
|
||||
if (Conditions != null)
|
||||
{
|
||||
foreach (Condition condition in Conditions)
|
||||
{
|
||||
if (!condition.PassesFilter(filter))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Filter on locations
|
||||
if (filter.DatItem_Locations.MatchesNeutral(null, Locations != null ? (bool?)(Locations.Count > 0) : null) == false)
|
||||
return false;
|
||||
|
||||
// Filter on individual locations
|
||||
if (Locations != null)
|
||||
{
|
||||
foreach (Location location in Locations)
|
||||
{
|
||||
if (!location.PassesFilter(filter))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Filter on settings
|
||||
if (filter.DatItem_Settings.MatchesNeutral(null, Settings != null ? (bool?)(Settings.Count > 0) : null) == false)
|
||||
return false;
|
||||
|
||||
// Filter on individual conditions
|
||||
if (Settings != null)
|
||||
{
|
||||
foreach (Setting setting in Settings)
|
||||
{
|
||||
if (!setting.PassesFilter(filter))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -254,15 +342,35 @@ namespace SabreTools.Library.DatItems
|
||||
if (fields.Contains(Field.DatItem_Conditions))
|
||||
Conditions = null;
|
||||
|
||||
if (Conditions != null)
|
||||
{
|
||||
foreach (Condition condition in Conditions)
|
||||
{
|
||||
condition.RemoveFields(fields);
|
||||
}
|
||||
}
|
||||
|
||||
if (fields.Contains(Field.DatItem_Locations))
|
||||
Locations = null;
|
||||
|
||||
if (Locations != null)
|
||||
{
|
||||
foreach (Location location in Locations)
|
||||
{
|
||||
location.RemoveFields(fields);
|
||||
}
|
||||
}
|
||||
|
||||
if (fields.Contains(Field.DatItem_Settings))
|
||||
Settings = null;
|
||||
|
||||
// TODO: Handle DatItem_Condition*
|
||||
// TODO: Handle DatItem_Location*
|
||||
// TODO: Handle DatItem_Setting*
|
||||
if (Settings != null)
|
||||
{
|
||||
foreach (Setting setting in Settings)
|
||||
{
|
||||
setting.RemoveFields(fields);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -309,15 +417,17 @@ namespace SabreTools.Library.DatItems
|
||||
if (fields.Contains(Field.DatItem_Conditions))
|
||||
Conditions = newItem.Conditions;
|
||||
|
||||
// Field replacement doesn't make sense for DatItem_Condition*
|
||||
|
||||
if (fields.Contains(Field.DatItem_Locations))
|
||||
Locations = newItem.Locations;
|
||||
|
||||
// Field replacement doesn't make sense for DatItem_Location*
|
||||
|
||||
if (fields.Contains(Field.DatItem_Settings))
|
||||
Settings = newItem.Settings;
|
||||
|
||||
// TODO: Handle DatItem_Condition*
|
||||
// TODO: Handle DatItem_Location*
|
||||
// TODO: Handle DatItem_Setting*
|
||||
// Field replacement doesn't make sense for DatItem_Setting*
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -509,6 +509,9 @@ namespace SabreTools.Library.DatItems
|
||||
case ItemType.Instance:
|
||||
return new Instance();
|
||||
|
||||
case ItemType.Location:
|
||||
return new Location();
|
||||
|
||||
case ItemType.Media:
|
||||
return new Media();
|
||||
|
||||
@@ -527,6 +530,9 @@ namespace SabreTools.Library.DatItems
|
||||
case ItemType.Sample:
|
||||
return new Sample();
|
||||
|
||||
case ItemType.Setting:
|
||||
return new Setting();
|
||||
|
||||
case ItemType.Slot:
|
||||
return new Slot();
|
||||
|
||||
@@ -559,6 +565,7 @@ namespace SabreTools.Library.DatItems
|
||||
ItemType.Extension => new Extension(),
|
||||
ItemType.Feature => new Feature(),
|
||||
ItemType.Instance => new Instance(),
|
||||
ItemType.Location => new Location(),
|
||||
ItemType.Media => new Media(),
|
||||
ItemType.Port => new Port(),
|
||||
ItemType.RamOption => new RamOption(),
|
||||
|
||||
@@ -4,9 +4,6 @@ using System.Linq;
|
||||
using SabreTools.Library.Filtering;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
/// <summary>
|
||||
/// This holds all of the auxiliary types needed for proper parsing
|
||||
/// </summary>
|
||||
namespace SabreTools.Library.DatItems
|
||||
{
|
||||
/// <summary>
|
||||
|
||||
@@ -4,9 +4,6 @@ using SabreTools.Library.Filtering;
|
||||
using Newtonsoft.Json;
|
||||
using SabreTools.Library.Tools;
|
||||
|
||||
/// <summary>
|
||||
/// This holds all of the auxiliary types needed for proper parsing
|
||||
/// </summary>
|
||||
namespace SabreTools.Library.DatItems
|
||||
{
|
||||
/// <summary>
|
||||
|
||||
@@ -492,10 +492,12 @@ namespace SabreTools.Library.DatItems
|
||||
Feature,
|
||||
Input,
|
||||
Instance,
|
||||
Location,
|
||||
Port,
|
||||
RamOption,
|
||||
Release,
|
||||
Sample,
|
||||
Setting,
|
||||
Slot,
|
||||
SoftwareList,
|
||||
Sound,
|
||||
|
||||
@@ -4,9 +4,6 @@ using SabreTools.Library.Filtering;
|
||||
using Newtonsoft.Json;
|
||||
using SabreTools.Library.Tools;
|
||||
|
||||
/// <summary>
|
||||
/// This holds all of the auxiliary types needed for proper parsing
|
||||
/// </summary>
|
||||
namespace SabreTools.Library.DatItems
|
||||
{
|
||||
/// <summary>
|
||||
|
||||
265
SabreTools.Library/DatItems/Location.cs
Normal file
265
SabreTools.Library/DatItems/Location.cs
Normal file
@@ -0,0 +1,265 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using SabreTools.Library.Filtering;
|
||||
using Newtonsoft.Json;
|
||||
using SabreTools.Library.Tools;
|
||||
|
||||
namespace SabreTools.Library.DatItems
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents one conflocation or diplocation
|
||||
/// </summary>
|
||||
[JsonObject("location")]
|
||||
public class Location : DatItem
|
||||
{
|
||||
#region Fields
|
||||
|
||||
/// <summary>
|
||||
/// Location name
|
||||
/// </summary>
|
||||
[JsonProperty("name")]
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Location ID
|
||||
/// </summary>
|
||||
[JsonProperty("number", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public string Number { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Determines if location is inverted or not
|
||||
/// </summary>
|
||||
[JsonProperty("inverted", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public bool? Inverted { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Accessors
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name to use for a DatItem
|
||||
/// </summary>
|
||||
/// <returns>Name if available, null otherwise</returns>
|
||||
public override string GetName()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set fields with given values
|
||||
/// </summary>
|
||||
/// <param name="mappings">Mappings dictionary</param>
|
||||
public override void SetFields(Dictionary<Field, string> mappings)
|
||||
{
|
||||
// Set base fields
|
||||
base.SetFields(mappings);
|
||||
|
||||
// Handle Location-specific fields
|
||||
if (mappings.Keys.Contains(Field.DatItem_Location_Name))
|
||||
Name = mappings[Field.DatItem_Location_Name];
|
||||
|
||||
if (mappings.Keys.Contains(Field.DatItem_Location_Number))
|
||||
Number = mappings[Field.DatItem_Location_Number];
|
||||
|
||||
if (mappings.Keys.Contains(Field.DatItem_Location_Inverted))
|
||||
Inverted = mappings[Field.DatItem_Location_Inverted].AsYesNo();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Create a default, empty Location object
|
||||
/// </summary>
|
||||
public Location()
|
||||
{
|
||||
Name = string.Empty;
|
||||
ItemType = ItemType.Location;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Cloning Methods
|
||||
|
||||
public override object Clone()
|
||||
{
|
||||
return new Location()
|
||||
{
|
||||
Name = this.Name,
|
||||
ItemType = this.ItemType,
|
||||
DupeType = this.DupeType,
|
||||
|
||||
AltName = this.AltName,
|
||||
AltTitle = this.AltTitle,
|
||||
|
||||
Original = this.Original,
|
||||
OpenMSXSubType = this.OpenMSXSubType,
|
||||
OpenMSXType = this.OpenMSXType,
|
||||
Remark = this.Remark,
|
||||
Boot = this.Boot,
|
||||
|
||||
Part = this.Part,
|
||||
Features = this.Features,
|
||||
AreaName = this.AreaName,
|
||||
AreaSize = this.AreaSize,
|
||||
AreaWidth = this.AreaWidth,
|
||||
AreaEndianness = this.AreaEndianness,
|
||||
Value = this.Value,
|
||||
LoadFlag = this.LoadFlag,
|
||||
|
||||
Machine = this.Machine.Clone() as Machine,
|
||||
Source = this.Source.Clone() as Source,
|
||||
Remove = this.Remove,
|
||||
|
||||
Number = this.Number,
|
||||
Inverted = this.Inverted,
|
||||
};
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Comparision Methods
|
||||
|
||||
public override bool Equals(DatItem other)
|
||||
{
|
||||
// If we don't have a Location, return false
|
||||
if (ItemType != other.ItemType)
|
||||
return false;
|
||||
|
||||
// Otherwise, treat it as a Location
|
||||
Location newOther = other as Location;
|
||||
|
||||
// If the Location information matches
|
||||
return (Name == newOther.Name
|
||||
&& Number == newOther.Number
|
||||
&& Inverted == newOther.Inverted);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Filtering
|
||||
|
||||
/// <summary>
|
||||
/// Clean a DatItem according to the cleaner
|
||||
/// </summary>
|
||||
/// <param name="cleaner">Cleaner to implement</param>
|
||||
public override void Clean(Cleaner cleaner)
|
||||
{
|
||||
// Clean common items first
|
||||
base.Clean(cleaner);
|
||||
|
||||
// If we're stripping unicode characters, strip item name
|
||||
if (cleaner?.RemoveUnicode == true)
|
||||
Name = Sanitizer.RemoveUnicodeCharacters(Name);
|
||||
|
||||
// If we are in NTFS trim mode, trim the game name
|
||||
if (cleaner?.Trim == true)
|
||||
{
|
||||
// Windows max name length is 260
|
||||
int usableLength = 260 - Machine.Name.Length - (cleaner.Root?.Length ?? 0);
|
||||
if (Name.Length > usableLength)
|
||||
{
|
||||
string ext = Path.GetExtension(Name);
|
||||
Name = Name.Substring(0, usableLength - ext.Length);
|
||||
Name += ext;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check to see if a DatItem passes the filter
|
||||
/// </summary>
|
||||
/// <param name="filter">Filter to check against</param>
|
||||
/// <returns>True if the item passed the filter, false otherwise</returns>
|
||||
public override bool PassesFilter(Filter filter)
|
||||
{
|
||||
// Check common fields first
|
||||
if (!base.PassesFilter(filter))
|
||||
return false;
|
||||
|
||||
// Filter on item name
|
||||
if (filter.DatItem_Location_Name.MatchesPositiveSet(Name) == false)
|
||||
return false;
|
||||
if (filter.DatItem_Location_Name.MatchesNegativeSet(Name) == true)
|
||||
return false;
|
||||
|
||||
// Filter on number
|
||||
if (filter.DatItem_Location_Number.MatchesPositiveSet(Number) == false)
|
||||
return false;
|
||||
if (filter.DatItem_Location_Number.MatchesNegativeSet(Number) == true)
|
||||
return false;
|
||||
|
||||
// Filter on inverted
|
||||
if (filter.DatItem_Location_Inverted.MatchesNeutral(null, Inverted) == false)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove fields from the DatItem
|
||||
/// </summary>
|
||||
/// <param name="fields">List of Fields to remove</param>
|
||||
public override void RemoveFields(List<Field> fields)
|
||||
{
|
||||
// Remove common fields first
|
||||
base.RemoveFields(fields);
|
||||
|
||||
// Remove the fields
|
||||
if (fields.Contains(Field.DatItem_Location_Name))
|
||||
Name = null;
|
||||
|
||||
if (fields.Contains(Field.DatItem_Location_Number))
|
||||
Number = null;
|
||||
|
||||
if (fields.Contains(Field.DatItem_Location_Inverted))
|
||||
Inverted = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set internal names to match One Rom Per Game (ORPG) logic
|
||||
/// </summary>
|
||||
public override void SetOneRomPerGame()
|
||||
{
|
||||
string[] splitname = Name.Split('.');
|
||||
Machine.Name += $"/{string.Join(".", splitname.Take(splitname.Length > 1 ? splitname.Length - 1 : 1))}";
|
||||
Name = Path.GetFileName(Name);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Sorting and Merging
|
||||
|
||||
/// <summary>
|
||||
/// Replace fields from another item
|
||||
/// </summary>
|
||||
/// <param name="item">DatItem to pull new information from</param>
|
||||
/// <param name="fields">List of Fields representing what should be updated</param>
|
||||
public override void ReplaceFields(DatItem item, List<Field> fields)
|
||||
{
|
||||
// Replace common fields first
|
||||
base.ReplaceFields(item, fields);
|
||||
|
||||
// If we don't have a Location to replace from, ignore specific fields
|
||||
if (item.ItemType != ItemType.Location)
|
||||
return;
|
||||
|
||||
// Cast for easier access
|
||||
Location newItem = item as Location;
|
||||
|
||||
// Replace the fields
|
||||
if (fields.Contains(Field.DatItem_Location_Name))
|
||||
Name = newItem.Name;
|
||||
|
||||
if (fields.Contains(Field.DatItem_Location_Number))
|
||||
Number = newItem.Number;
|
||||
|
||||
if (fields.Contains(Field.DatItem_Location_Inverted))
|
||||
Inverted = newItem.Inverted;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
321
SabreTools.Library/DatItems/Setting.cs
Normal file
321
SabreTools.Library/DatItems/Setting.cs
Normal file
@@ -0,0 +1,321 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using SabreTools.Library.Filtering;
|
||||
using Newtonsoft.Json;
|
||||
using SabreTools.Library.Tools;
|
||||
|
||||
namespace SabreTools.Library.DatItems
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents one ListXML confsetting or dipvalue
|
||||
/// </summary>
|
||||
[JsonObject("setting")]
|
||||
public class Setting : DatItem
|
||||
{
|
||||
#region Fields
|
||||
|
||||
/// <summary>
|
||||
/// Setting name
|
||||
/// </summary>
|
||||
[JsonProperty("name")]
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Setting value
|
||||
/// </summary>
|
||||
[JsonProperty("value", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public string SettingValue { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Determines if the setting is default or not
|
||||
/// </summary>
|
||||
[JsonProperty("default", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public bool? Default { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// List of conditions on the setting
|
||||
/// </summary>
|
||||
[JsonProperty("conditions", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public List<Condition> Conditions { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Accessors
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name to use for a DatItem
|
||||
/// </summary>
|
||||
/// <returns>Name if available, null otherwise</returns>
|
||||
public override string GetName()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set fields with given values
|
||||
/// </summary>
|
||||
/// <param name="mappings">Mappings dictionary</param>
|
||||
public override void SetFields(Dictionary<Field, string> mappings)
|
||||
{
|
||||
// Set base fields
|
||||
base.SetFields(mappings);
|
||||
|
||||
// Handle Setting-specific fields
|
||||
if (mappings.Keys.Contains(Field.DatItem_Setting_Name))
|
||||
Name = mappings[Field.DatItem_Setting_Name];
|
||||
|
||||
if (mappings.Keys.Contains(Field.DatItem_Setting_Value))
|
||||
SettingValue = mappings[Field.DatItem_Setting_Value];
|
||||
|
||||
if (mappings.Keys.Contains(Field.DatItem_Setting_Default))
|
||||
Default = mappings[Field.DatItem_Setting_Default].AsYesNo();
|
||||
|
||||
// Field.DatItem_Conditions does not apply here
|
||||
if (Conditions != null)
|
||||
{
|
||||
foreach (Condition condition in Conditions)
|
||||
{
|
||||
condition.SetFields(mappings);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Create a default, empty Setting object
|
||||
/// </summary>
|
||||
public Setting()
|
||||
{
|
||||
Name = string.Empty;
|
||||
ItemType = ItemType.Setting;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Cloning Methods
|
||||
|
||||
public override object Clone()
|
||||
{
|
||||
return new Setting()
|
||||
{
|
||||
Name = this.Name,
|
||||
ItemType = this.ItemType,
|
||||
DupeType = this.DupeType,
|
||||
|
||||
AltName = this.AltName,
|
||||
AltTitle = this.AltTitle,
|
||||
|
||||
Original = this.Original,
|
||||
OpenMSXSubType = this.OpenMSXSubType,
|
||||
OpenMSXType = this.OpenMSXType,
|
||||
Remark = this.Remark,
|
||||
Boot = this.Boot,
|
||||
|
||||
Part = this.Part,
|
||||
Features = this.Features,
|
||||
AreaName = this.AreaName,
|
||||
AreaSize = this.AreaSize,
|
||||
AreaWidth = this.AreaWidth,
|
||||
AreaEndianness = this.AreaEndianness,
|
||||
Value = this.Value,
|
||||
LoadFlag = this.LoadFlag,
|
||||
|
||||
Machine = this.Machine.Clone() as Machine,
|
||||
Source = this.Source.Clone() as Source,
|
||||
Remove = this.Remove,
|
||||
|
||||
SettingValue = this.SettingValue,
|
||||
Default = this.Default,
|
||||
Conditions = this.Conditions,
|
||||
};
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Comparision Methods
|
||||
|
||||
public override bool Equals(DatItem other)
|
||||
{
|
||||
// If we don't have a Setting, return false
|
||||
if (ItemType != other.ItemType)
|
||||
return false;
|
||||
|
||||
// Otherwise, treat it as a Setting
|
||||
Setting newOther = other as Setting;
|
||||
|
||||
// If the Setting information matches
|
||||
bool match = (Name == newOther.Name
|
||||
&& SettingValue == newOther.SettingValue
|
||||
&& Default == newOther.Default);
|
||||
if (!match)
|
||||
return match;
|
||||
|
||||
// If the conditions match
|
||||
if (Conditions != null)
|
||||
{
|
||||
foreach (Condition condition in Conditions)
|
||||
{
|
||||
match &= newOther.Conditions.Contains(condition);
|
||||
}
|
||||
}
|
||||
|
||||
return match;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Filtering
|
||||
|
||||
/// <summary>
|
||||
/// Clean a DatItem according to the cleaner
|
||||
/// </summary>
|
||||
/// <param name="cleaner">Cleaner to implement</param>
|
||||
public override void Clean(Cleaner cleaner)
|
||||
{
|
||||
// Clean common items first
|
||||
base.Clean(cleaner);
|
||||
|
||||
// If we're stripping unicode characters, strip item name
|
||||
if (cleaner?.RemoveUnicode == true)
|
||||
Name = Sanitizer.RemoveUnicodeCharacters(Name);
|
||||
|
||||
// If we are in NTFS trim mode, trim the game name
|
||||
if (cleaner?.Trim == true)
|
||||
{
|
||||
// Windows max name length is 260
|
||||
int usableLength = 260 - Machine.Name.Length - (cleaner.Root?.Length ?? 0);
|
||||
if (Name.Length > usableLength)
|
||||
{
|
||||
string ext = Path.GetExtension(Name);
|
||||
Name = Name.Substring(0, usableLength - ext.Length);
|
||||
Name += ext;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check to see if a DatItem passes the filter
|
||||
/// </summary>
|
||||
/// <param name="filter">Filter to check against</param>
|
||||
/// <returns>True if the item passed the filter, false otherwise</returns>
|
||||
public override bool PassesFilter(Filter filter)
|
||||
{
|
||||
// Check common fields first
|
||||
if (!base.PassesFilter(filter))
|
||||
return false;
|
||||
|
||||
// Filter on item name
|
||||
if (filter.DatItem_Setting_Name.MatchesPositiveSet(Name) == false)
|
||||
return false;
|
||||
if (filter.DatItem_Setting_Name.MatchesNegativeSet(Name) == true)
|
||||
return false;
|
||||
|
||||
// Filter on value
|
||||
if (filter.DatItem_Setting_Value.MatchesPositiveSet(SettingValue) == false)
|
||||
return false;
|
||||
if (filter.DatItem_Setting_Value.MatchesNegativeSet(SettingValue) == true)
|
||||
return false;
|
||||
|
||||
// Filter on default
|
||||
if (filter.DatItem_Setting_Default.MatchesNeutral(null, Default) == false)
|
||||
return false;
|
||||
|
||||
// Filter on conditions
|
||||
if (filter.DatItem_Conditions.MatchesNeutral(null, Conditions != null ? (bool?)(Conditions.Count > 0) : null) == false)
|
||||
return false;
|
||||
|
||||
// Filter on individual conditions
|
||||
if (Conditions != null)
|
||||
{
|
||||
foreach (Condition condition in Conditions)
|
||||
{
|
||||
if (!condition.PassesFilter(filter))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove fields from the DatItem
|
||||
/// </summary>
|
||||
/// <param name="fields">List of Fields to remove</param>
|
||||
public override void RemoveFields(List<Field> fields)
|
||||
{
|
||||
// Remove common fields first
|
||||
base.RemoveFields(fields);
|
||||
|
||||
// Remove the fields
|
||||
if (fields.Contains(Field.DatItem_Setting_Name))
|
||||
Name = null;
|
||||
|
||||
if (fields.Contains(Field.DatItem_Setting_Value))
|
||||
SettingValue = null;
|
||||
|
||||
if (fields.Contains(Field.DatItem_Setting_Default))
|
||||
Default = null;
|
||||
|
||||
if (fields.Contains(Field.DatItem_Conditions))
|
||||
Conditions = null;
|
||||
|
||||
if (Conditions != null)
|
||||
{
|
||||
foreach (Condition condition in Conditions)
|
||||
{
|
||||
condition.RemoveFields(fields);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set internal names to match One Rom Per Game (ORPG) logic
|
||||
/// </summary>
|
||||
public override void SetOneRomPerGame()
|
||||
{
|
||||
string[] splitname = Name.Split('.');
|
||||
Machine.Name += $"/{string.Join(".", splitname.Take(splitname.Length > 1 ? splitname.Length - 1 : 1))}";
|
||||
Name = Path.GetFileName(Name);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Sorting and Merging
|
||||
|
||||
/// <summary>
|
||||
/// Replace fields from another item
|
||||
/// </summary>
|
||||
/// <param name="item">DatItem to pull new information from</param>
|
||||
/// <param name="fields">List of Fields representing what should be updated</param>
|
||||
public override void ReplaceFields(DatItem item, List<Field> fields)
|
||||
{
|
||||
// Replace common fields first
|
||||
base.ReplaceFields(item, fields);
|
||||
|
||||
// If we don't have a Setting to replace from, ignore specific fields
|
||||
if (item.ItemType != ItemType.Setting)
|
||||
return;
|
||||
|
||||
// Cast for easier access
|
||||
Setting newItem = item as Setting;
|
||||
|
||||
// Replace the fields
|
||||
if (fields.Contains(Field.DatItem_Setting_Name))
|
||||
Name = newItem.Name;
|
||||
|
||||
if (fields.Contains(Field.DatItem_Setting_Value))
|
||||
SettingValue = newItem.SettingValue;
|
||||
|
||||
if (fields.Contains(Field.DatItem_Setting_Default))
|
||||
Default = newItem.Default;
|
||||
|
||||
// Field replacement doesn't make sense for DatItem_Condition*
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1675,6 +1675,8 @@ namespace SabreTools.Library.Tools
|
||||
return ItemType.Input;
|
||||
case "instance":
|
||||
return ItemType.Instance;
|
||||
case "location":
|
||||
return ItemType.Location;
|
||||
case "media":
|
||||
return ItemType.Media;
|
||||
case "port":
|
||||
@@ -1687,6 +1689,8 @@ namespace SabreTools.Library.Tools
|
||||
return ItemType.Rom;
|
||||
case "sample":
|
||||
return ItemType.Sample;
|
||||
case "setting":
|
||||
return ItemType.Setting;
|
||||
case "slot":
|
||||
return ItemType.Slot;
|
||||
case "softwarelist":
|
||||
@@ -1717,12 +1721,14 @@ namespace SabreTools.Library.Tools
|
||||
"feature" => ItemType.Feature,
|
||||
"input" => ItemType.Input,
|
||||
"instance" => ItemType.Instance,
|
||||
"location" => ItemType.Location,
|
||||
"media" => ItemType.Media,
|
||||
"port" => ItemType.Port,
|
||||
"ramoption" => ItemType.RamOption,
|
||||
"release" => ItemType.Release,
|
||||
"rom" => ItemType.Rom,
|
||||
"sample" => ItemType.Sample,
|
||||
"setting" => ItemType.Setting,
|
||||
"slot" => ItemType.Slot,
|
||||
"softwarelist" => ItemType.SoftwareList,
|
||||
"sound" => ItemType.Sound,
|
||||
@@ -2304,6 +2310,8 @@ namespace SabreTools.Library.Tools
|
||||
return "input";
|
||||
case ItemType.Instance:
|
||||
return "instance";
|
||||
case ItemType.Location:
|
||||
return "location";
|
||||
case ItemType.Media:
|
||||
return "media";
|
||||
case ItemType.Port:
|
||||
@@ -2316,6 +2324,8 @@ namespace SabreTools.Library.Tools
|
||||
return "rom";
|
||||
case ItemType.Sample:
|
||||
return "sample";
|
||||
case ItemType.Setting:
|
||||
return "setting";
|
||||
case ItemType.Slot:
|
||||
return "slot";
|
||||
case ItemType.SoftwareList:
|
||||
@@ -2346,12 +2356,14 @@ namespace SabreTools.Library.Tools
|
||||
ItemType.Feature => "feature",
|
||||
ItemType.Input => "input",
|
||||
ItemType.Instance => "instance",
|
||||
ItemType.Location => "location",
|
||||
ItemType.Media => "media",
|
||||
ItemType.Port => "port",
|
||||
ItemType.RamOption => "ramoption",
|
||||
ItemType.Release => "release",
|
||||
ItemType.Rom => "rom",
|
||||
ItemType.Sample => "sample",
|
||||
ItemType.Setting => "setting",
|
||||
ItemType.Slot => "slot",
|
||||
ItemType.SoftwareList => "softwarelist",
|
||||
ItemType.Sound => "sound",
|
||||
|
||||
Reference in New Issue
Block a user