mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Add nullable context to SabreTools.DatItems
This change also starts migrating the internals of the DatItem formats to the new internal models. Right now, it's basically just acting like a wrapper around those models.
This commit is contained in:
@@ -2,15 +2,14 @@
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
using NaturalSort;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using SabreTools.Core;
|
||||
using SabreTools.Core.Tools;
|
||||
using SabreTools.DatItems.Formats;
|
||||
using SabreTools.FileTypes;
|
||||
using SabreTools.Logging;
|
||||
using NaturalSort;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
|
||||
namespace SabreTools.DatItems
|
||||
{
|
||||
@@ -29,11 +28,15 @@ namespace SabreTools.DatItems
|
||||
[XmlInclude(typeof(Chip))]
|
||||
[XmlInclude(typeof(Condition))]
|
||||
[XmlInclude(typeof(Configuration))]
|
||||
[XmlInclude(typeof(ConfLocation))]
|
||||
[XmlInclude(typeof(ConfSetting))]
|
||||
[XmlInclude(typeof(Control))]
|
||||
[XmlInclude(typeof(DataArea))]
|
||||
[XmlInclude(typeof(Device))]
|
||||
[XmlInclude(typeof(DeviceReference))]
|
||||
[XmlInclude(typeof(DipLocation))]
|
||||
[XmlInclude(typeof(DipSwitch))]
|
||||
[XmlInclude(typeof(DipValue))]
|
||||
[XmlInclude(typeof(Disk))]
|
||||
[XmlInclude(typeof(DiskArea))]
|
||||
[XmlInclude(typeof(Display))]
|
||||
@@ -43,7 +46,6 @@ namespace SabreTools.DatItems
|
||||
[XmlInclude(typeof(Info))]
|
||||
[XmlInclude(typeof(Input))]
|
||||
[XmlInclude(typeof(Instance))]
|
||||
[XmlInclude(typeof(Location))]
|
||||
[XmlInclude(typeof(Media))]
|
||||
[XmlInclude(typeof(Part))]
|
||||
[XmlInclude(typeof(PartFeature))]
|
||||
@@ -52,7 +54,6 @@ namespace SabreTools.DatItems
|
||||
[XmlInclude(typeof(Release))]
|
||||
[XmlInclude(typeof(Rom))]
|
||||
[XmlInclude(typeof(Sample))]
|
||||
[XmlInclude(typeof(Setting))]
|
||||
[XmlInclude(typeof(SharedFeature))]
|
||||
[XmlInclude(typeof(Slot))]
|
||||
[XmlInclude(typeof(SlotOption))]
|
||||
@@ -86,7 +87,7 @@ namespace SabreTools.DatItems
|
||||
/// Machine values
|
||||
/// </summary>
|
||||
[JsonIgnore, XmlIgnore]
|
||||
public Machine Machine { get; set; } = new Machine();
|
||||
public Machine? Machine { get; set; } = new Machine();
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -96,7 +97,7 @@ namespace SabreTools.DatItems
|
||||
/// Source information
|
||||
/// </summary>
|
||||
[JsonIgnore, XmlIgnore]
|
||||
public Source Source { get; set; } = new Source();
|
||||
public Source? Source { get; set; } = new Source();
|
||||
|
||||
/// <summary>
|
||||
/// Flag if item should be removed
|
||||
@@ -132,13 +133,13 @@ namespace SabreTools.DatItems
|
||||
/// Gets the name to use for a DatItem
|
||||
/// </summary>
|
||||
/// <returns>Name if available, null otherwise</returns>
|
||||
public virtual string GetName() => null;
|
||||
public virtual string? GetName() => null;
|
||||
|
||||
/// <summary>
|
||||
/// Sets the name to use for a DatItem
|
||||
/// </summary>
|
||||
/// <param name="name">Name to set for the item</param>
|
||||
public virtual void SetName(string name) { }
|
||||
public virtual void SetName(string? name) { }
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -169,8 +170,10 @@ namespace SabreTools.DatItems
|
||||
ItemType.Chip => new Chip(),
|
||||
ItemType.Condition => new Condition(),
|
||||
ItemType.Configuration => new Configuration(),
|
||||
ItemType.ConfLocation => new ConfLocation(),
|
||||
ItemType.Device => new Device(),
|
||||
ItemType.DeviceReference => new DeviceReference(),
|
||||
ItemType.DipLocation => new DipLocation(),
|
||||
ItemType.DipSwitch => new DipSwitch(),
|
||||
ItemType.Disk => new Disk(),
|
||||
ItemType.Display => new Display(),
|
||||
@@ -180,7 +183,6 @@ namespace SabreTools.DatItems
|
||||
ItemType.File => new Formats.File(),
|
||||
ItemType.Info => new Info(),
|
||||
ItemType.Instance => new Instance(),
|
||||
ItemType.Location => new Location(),
|
||||
ItemType.Media => new Media(),
|
||||
ItemType.PartFeature => new PartFeature(),
|
||||
ItemType.Port => new Port(),
|
||||
@@ -205,7 +207,7 @@ namespace SabreTools.DatItems
|
||||
/// </summary>
|
||||
/// <param name="baseFile">BaseFile containing information to be created</param>
|
||||
/// <returns>DatItem of the specific internal type that corresponds to the inputs</returns>
|
||||
public static DatItem Create(BaseFile baseFile)
|
||||
public static DatItem? Create(BaseFile baseFile)
|
||||
{
|
||||
return baseFile.Type switch
|
||||
{
|
||||
@@ -265,14 +267,14 @@ namespace SabreTools.DatItems
|
||||
#region Comparision Methods
|
||||
|
||||
/// <inheritdoc/>
|
||||
public int CompareTo(DatItem other)
|
||||
public int CompareTo(DatItem? other)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (GetName() == other.GetName())
|
||||
if (GetName() == other?.GetName())
|
||||
return Equals(other) ? 0 : 1;
|
||||
|
||||
return string.Compare(GetName(), other.GetName());
|
||||
return string.Compare(GetName(), other?.GetName());
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -285,14 +287,14 @@ namespace SabreTools.DatItems
|
||||
/// </summary>
|
||||
/// <param name="other">DatItem to use as a baseline</param>
|
||||
/// <returns>True if the items are duplicates, false otherwise</returns>
|
||||
public abstract bool Equals(DatItem other);
|
||||
public abstract bool Equals(DatItem? other);
|
||||
|
||||
/// <summary>
|
||||
/// Return the duplicate status of two items
|
||||
/// </summary>
|
||||
/// <param name="lastItem">DatItem to check against</param>
|
||||
/// <returns>The DupeType corresponding to the relationship between the two</returns>
|
||||
public DupeType GetDuplicateStatus(DatItem lastItem)
|
||||
public DupeType GetDuplicateStatus(DatItem? lastItem)
|
||||
{
|
||||
DupeType output = 0x00;
|
||||
|
||||
@@ -301,9 +303,9 @@ namespace SabreTools.DatItems
|
||||
return output;
|
||||
|
||||
// If the duplicate is external already or should be, set it
|
||||
if (lastItem.DupeType.HasFlag(DupeType.External) || lastItem.Source.Index != Source.Index)
|
||||
if (lastItem.DupeType.HasFlag(DupeType.External) || lastItem?.Source?.Index != Source?.Index)
|
||||
{
|
||||
if (lastItem.Machine.Name == Machine.Name && lastItem.GetName() == GetName())
|
||||
if (lastItem?.Machine?.Name == Machine?.Name && lastItem?.GetName() == GetName())
|
||||
output = DupeType.External | DupeType.All;
|
||||
else
|
||||
output = DupeType.External | DupeType.Hash;
|
||||
@@ -312,7 +314,7 @@ namespace SabreTools.DatItems
|
||||
// Otherwise, it's considered an internal dupe
|
||||
else
|
||||
{
|
||||
if (lastItem.Machine.Name == Machine.Name && lastItem.GetName() == GetName())
|
||||
if (lastItem?.Machine?.Name == Machine?.Name && lastItem?.GetName() == GetName())
|
||||
output = DupeType.Internal | DupeType.All;
|
||||
else
|
||||
output = DupeType.Internal | DupeType.Hash;
|
||||
@@ -323,113 +325,6 @@ namespace SabreTools.DatItems
|
||||
|
||||
#endregion
|
||||
|
||||
#region Filtering
|
||||
|
||||
/// <summary>
|
||||
/// Clean a CRC32 string and pad to the correct size
|
||||
/// </summary>
|
||||
/// <param name="hash">Hash string to sanitize</param>
|
||||
/// <returns>Cleaned string</returns>
|
||||
protected static string CleanCRC32(string hash)
|
||||
{
|
||||
return CleanHashData(hash, Constants.CRCLength);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clean a MD5 string and pad to the correct size
|
||||
/// </summary>
|
||||
/// <param name="hash">Hash string to sanitize</param>
|
||||
/// <returns>Cleaned string</returns>
|
||||
protected static string CleanMD5(string hash)
|
||||
{
|
||||
return CleanHashData(hash, Constants.MD5Length);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clean a SHA1 string and pad to the correct size
|
||||
/// </summary>
|
||||
/// <param name="hash">Hash string to sanitize</param>
|
||||
/// <returns>Cleaned string</returns>
|
||||
protected static string CleanSHA1(string hash)
|
||||
{
|
||||
return CleanHashData(hash, Constants.SHA1Length);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clean a SHA256 string and pad to the correct size
|
||||
/// </summary>
|
||||
/// <param name="hash">Hash string to sanitize</param>
|
||||
/// <returns>Cleaned string</returns>
|
||||
protected static string CleanSHA256(string hash)
|
||||
{
|
||||
return CleanHashData(hash, Constants.SHA256Length);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clean a SHA384 string and pad to the correct size
|
||||
/// </summary>
|
||||
/// <param name="hash">Hash string to sanitize</param>
|
||||
/// <returns>Cleaned string</returns>
|
||||
protected static string CleanSHA384(string hash)
|
||||
{
|
||||
return CleanHashData(hash, Constants.SHA384Length);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clean a SHA512 string and pad to the correct size
|
||||
/// </summary>
|
||||
/// <param name="hash">Hash string to sanitize</param>
|
||||
/// <returns>Cleaned string</returns>
|
||||
protected static string CleanSHA512(string hash)
|
||||
{
|
||||
return CleanHashData(hash, Constants.SHA512Length);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clean a hash string and pad to the correct size
|
||||
/// </summary>
|
||||
/// <param name="hash">Hash string to sanitize</param>
|
||||
/// <param name="padding">Amount of characters to pad to</param>
|
||||
/// <returns>Cleaned string</returns>
|
||||
private static string CleanHashData(string hash, int padding)
|
||||
{
|
||||
// If we have a known blank hash, return blank
|
||||
if (string.IsNullOrWhiteSpace(hash) || hash == "-" || hash == "_")
|
||||
return string.Empty;
|
||||
|
||||
// Check to see if it's a "hex" hash
|
||||
hash = hash.Trim().Replace("0x", string.Empty);
|
||||
|
||||
// If we have a blank hash now, return blank
|
||||
if (string.IsNullOrWhiteSpace(hash))
|
||||
return string.Empty;
|
||||
|
||||
// If the hash shorter than the required length, pad it
|
||||
if (hash.Length < padding)
|
||||
hash = hash.PadLeft(padding, '0');
|
||||
|
||||
// If the hash is longer than the required length, it's invalid
|
||||
else if (hash.Length > padding)
|
||||
return string.Empty;
|
||||
|
||||
// Now normalize the hash
|
||||
hash = hash.ToLowerInvariant();
|
||||
|
||||
// Otherwise, make sure that every character is a proper match
|
||||
for (int i = 0; i < hash.Length; i++)
|
||||
{
|
||||
if ((hash[i] < '0' || hash[i] > '9') && (hash[i] < 'a' || hash[i] > 'f'))
|
||||
{
|
||||
hash = string.Empty;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Sorting and Merging
|
||||
|
||||
/// <summary>
|
||||
@@ -453,9 +348,9 @@ namespace SabreTools.DatItems
|
||||
|
||||
case ItemKey.Machine:
|
||||
key = (norename ? string.Empty
|
||||
: Source.Index.ToString().PadLeft(10, '0')
|
||||
: Source?.Index.ToString().PadLeft(10, '0')
|
||||
+ "-")
|
||||
+ (string.IsNullOrWhiteSpace(Machine.Name)
|
||||
+ (string.IsNullOrWhiteSpace(Machine?.Name)
|
||||
? "Default"
|
||||
: Machine.Name);
|
||||
if (lower)
|
||||
@@ -510,14 +405,14 @@ namespace SabreTools.DatItems
|
||||
/// <param name="firstHash">First hash to compare</param>
|
||||
/// <param name="secondHash">Second hash to compare</param>
|
||||
/// <returns>True if either is empty OR the hashes exactly match, false otherwise</returns>
|
||||
public static bool ConditionalHashEquals(byte[] firstHash, byte[] secondHash)
|
||||
public static bool ConditionalHashEquals(byte[]? firstHash, byte[]? secondHash)
|
||||
{
|
||||
// If either hash is empty, we say they're equal for merging
|
||||
if (firstHash.IsNullOrEmpty() || secondHash.IsNullOrEmpty())
|
||||
return true;
|
||||
|
||||
// If they're different sizes, they can't match
|
||||
if (firstHash.Length != secondHash.Length)
|
||||
if (firstHash!.Length != secondHash!.Length)
|
||||
return false;
|
||||
|
||||
// Otherwise, they need to match exactly
|
||||
@@ -556,13 +451,13 @@ namespace SabreTools.DatItems
|
||||
}
|
||||
|
||||
// If it's a nodump, add and skip
|
||||
if (file.ItemType == ItemType.Rom && (file as Rom).ItemStatus == ItemStatus.Nodump)
|
||||
if (file is Rom rom && rom.ItemStatus == ItemStatus.Nodump)
|
||||
{
|
||||
outfiles.Add(file);
|
||||
nodumpCount++;
|
||||
continue;
|
||||
}
|
||||
else if (file.ItemType == ItemType.Disk && (file as Disk).ItemStatus == ItemStatus.Nodump)
|
||||
else if (file is Disk disk && disk.ItemStatus == ItemStatus.Nodump)
|
||||
{
|
||||
outfiles.Add(file);
|
||||
nodumpCount++;
|
||||
@@ -593,19 +488,19 @@ namespace SabreTools.DatItems
|
||||
pos = i;
|
||||
|
||||
// Disks, Media, and Roms have more information to fill
|
||||
if (file.ItemType == ItemType.Disk)
|
||||
(saveditem as Disk).FillMissingInformation(file as Disk);
|
||||
else if (file.ItemType == ItemType.File)
|
||||
(saveditem as Formats.File).FillMissingInformation(file as Formats.File);
|
||||
else if (file.ItemType == ItemType.Media)
|
||||
(saveditem as Media).FillMissingInformation(file as Media);
|
||||
else if (file.ItemType == ItemType.Rom)
|
||||
(saveditem as Rom).FillMissingInformation(file as Rom);
|
||||
if (file is Disk disk && saveditem is Disk savedDisk)
|
||||
savedDisk.FillMissingInformation(disk);
|
||||
else if (file is Formats.File fileItem && saveditem is Formats.File savedFile)
|
||||
savedFile.FillMissingInformation(fileItem);
|
||||
else if (file is Media media && saveditem is Media savedMedia)
|
||||
savedMedia.FillMissingInformation(media);
|
||||
else if (file is Rom romItem && saveditem is Rom savedRom)
|
||||
savedRom.FillMissingInformation(romItem);
|
||||
|
||||
saveditem.DupeType = dupetype;
|
||||
|
||||
// If the current system has a lower ID than the previous, set the system accordingly
|
||||
if (file.Source.Index < saveditem.Source.Index)
|
||||
if (file.Source?.Index < saveditem.Source?.Index)
|
||||
{
|
||||
saveditem.Source = file.Source.Clone() as Source;
|
||||
saveditem.CopyMachineInformation(file);
|
||||
@@ -613,7 +508,7 @@ namespace SabreTools.DatItems
|
||||
}
|
||||
|
||||
// If the current machine is a child of the new machine, use the new machine instead
|
||||
if (saveditem.Machine.CloneOf == file.Machine.Name || saveditem.Machine.RomOf == file.Machine.Name)
|
||||
if (saveditem.Machine?.CloneOf == file.Machine?.Name || saveditem.Machine?.RomOf == file.Machine?.Name)
|
||||
{
|
||||
saveditem.CopyMachineInformation(file);
|
||||
saveditem.SetName(file.GetName());
|
||||
@@ -654,8 +549,8 @@ namespace SabreTools.DatItems
|
||||
Sort(ref infiles, true);
|
||||
|
||||
// Now we want to loop through and check names
|
||||
DatItem lastItem = null;
|
||||
string lastrenamed = null;
|
||||
DatItem? lastItem = null;
|
||||
string? lastrenamed = null;
|
||||
int lastid = 0;
|
||||
for (int i = 0; i < infiles.Count; i++)
|
||||
{
|
||||
@@ -735,16 +630,14 @@ namespace SabreTools.DatItems
|
||||
/// </summary>
|
||||
private static string GetDuplicateSuffix(DatItem datItem)
|
||||
{
|
||||
if (datItem.ItemType == ItemType.Disk)
|
||||
return (datItem as Disk).GetDuplicateSuffix();
|
||||
else if (datItem.ItemType == ItemType.File)
|
||||
return (datItem as Formats.File).GetDuplicateSuffix();
|
||||
else if (datItem.ItemType == ItemType.Media)
|
||||
return (datItem as Media).GetDuplicateSuffix();
|
||||
else if (datItem.ItemType == ItemType.Rom)
|
||||
return (datItem as Rom).GetDuplicateSuffix();
|
||||
|
||||
return "_1";
|
||||
return datItem switch
|
||||
{
|
||||
Disk disk => disk.GetDuplicateSuffix(),
|
||||
Formats.File file => file.GetDuplicateSuffix(),
|
||||
Media media => media.GetDuplicateSuffix(),
|
||||
Rom rom => rom.GetDuplicateSuffix(),
|
||||
_ => "_1",
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -762,23 +655,23 @@ namespace SabreTools.DatItems
|
||||
NaturalComparer nc = new();
|
||||
|
||||
// If machine names match, more refinement is needed
|
||||
if (x.Machine.Name == y.Machine.Name)
|
||||
if (x.Machine?.Name == y.Machine?.Name)
|
||||
{
|
||||
// If item types match, more refinement is needed
|
||||
if (x.ItemType == y.ItemType)
|
||||
{
|
||||
string xDirectoryName = Path.GetDirectoryName(TextHelper.RemovePathUnsafeCharacters(x.GetName() ?? string.Empty));
|
||||
string yDirectoryName = Path.GetDirectoryName(TextHelper.RemovePathUnsafeCharacters(y.GetName() ?? string.Empty));
|
||||
string? xDirectoryName = Path.GetDirectoryName(TextHelper.RemovePathUnsafeCharacters(x.GetName() ?? string.Empty));
|
||||
string? yDirectoryName = Path.GetDirectoryName(TextHelper.RemovePathUnsafeCharacters(y.GetName() ?? string.Empty));
|
||||
|
||||
// If item directory names match, more refinement is needed
|
||||
if (xDirectoryName == yDirectoryName)
|
||||
{
|
||||
string xName = Path.GetFileName(TextHelper.RemovePathUnsafeCharacters(x.GetName() ?? string.Empty));
|
||||
string yName = Path.GetFileName(TextHelper.RemovePathUnsafeCharacters(y.GetName() ?? string.Empty));
|
||||
string? xName = Path.GetFileName(TextHelper.RemovePathUnsafeCharacters(x.GetName() ?? string.Empty));
|
||||
string? yName = Path.GetFileName(TextHelper.RemovePathUnsafeCharacters(y.GetName() ?? string.Empty));
|
||||
|
||||
// If item names match, then compare on machine or source, depending on the flag
|
||||
if (xName == yName)
|
||||
return (norename ? nc.Compare(x.Machine.Name, y.Machine.Name) : x.Source.Index - y.Source.Index);
|
||||
return (norename ? nc.Compare(x.Machine?.Name, y.Machine?.Name) : (x.Source?.Index - y.Source?.Index) ?? 0);
|
||||
|
||||
// Otherwise, just sort based on item names
|
||||
return nc.Compare(xName, yName);
|
||||
@@ -793,7 +686,7 @@ namespace SabreTools.DatItems
|
||||
}
|
||||
|
||||
// Otherwise, just sort based on machine name
|
||||
return nc.Compare(x.Machine.Name, y.Machine.Name);
|
||||
return nc.Compare(x.Machine?.Name, y.Machine?.Name);
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Xml.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
using SabreTools.Core;
|
||||
@@ -17,13 +18,21 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Name of the item
|
||||
/// </summary>
|
||||
[JsonProperty("name"), XmlElement("name")]
|
||||
public string Name { get; set; }
|
||||
public string? Name
|
||||
{
|
||||
get => _adjuster.ReadString(Models.Internal.Adjuster.NameKey);
|
||||
set => _adjuster[Models.Internal.Adjuster.NameKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determine whether the value is default
|
||||
/// </summary>
|
||||
[JsonProperty("default", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("default")]
|
||||
public bool? Default { get; set; }
|
||||
public bool? Default
|
||||
{
|
||||
get => _adjuster.ReadBool(Models.Internal.Adjuster.DefaultKey);
|
||||
set => _adjuster[Models.Internal.Adjuster.DefaultKey] = value;
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool DefaultSpecified { get { return Default != null; } }
|
||||
@@ -32,20 +41,30 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Conditions associated with the adjustment
|
||||
/// </summary>
|
||||
[JsonProperty("conditions", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("conditions")]
|
||||
public List<Condition> Conditions { get; set; }
|
||||
public List<Condition>? Conditions
|
||||
{
|
||||
get => _adjuster.Read<Condition[]>(Models.Internal.Adjuster.ConditionKey)?.ToList();
|
||||
set => _adjuster[Models.Internal.Adjuster.ConditionKey] = value?.ToArray();
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool ConditionsSpecified { get { return Conditions != null && Conditions.Count > 0; } }
|
||||
|
||||
/// <summary>
|
||||
/// Internal Adjuster model
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
private Models.Internal.Adjuster _adjuster = new();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Accessors
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string GetName() => Name;
|
||||
public override string? GetName() => Name;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void SetName(string name) => Name = name;
|
||||
public override void SetName(string? name) => Name = name;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -72,13 +91,11 @@ namespace SabreTools.DatItems.Formats
|
||||
ItemType = this.ItemType,
|
||||
DupeType = this.DupeType,
|
||||
|
||||
Machine = this.Machine.Clone() as Machine,
|
||||
Source = this.Source.Clone() as Source,
|
||||
Machine = this.Machine?.Clone() as Machine,
|
||||
Source = this.Source?.Clone() as Source,
|
||||
Remove = this.Remove,
|
||||
|
||||
Name = this.Name,
|
||||
Default = this.Default,
|
||||
Conditions = this.Conditions,
|
||||
_adjuster = this._adjuster?.Clone() as Models.Internal.Adjuster ?? new Models.Internal.Adjuster(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -87,31 +104,14 @@ namespace SabreTools.DatItems.Formats
|
||||
#region Comparision Methods
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Equals(DatItem other)
|
||||
public override bool Equals(DatItem? other)
|
||||
{
|
||||
// If we don't have a Adjuster, return false
|
||||
if (ItemType != other.ItemType)
|
||||
if (ItemType != other?.ItemType || other is not Adjuster otherInternal)
|
||||
return false;
|
||||
|
||||
// Otherwise, treat it as a Adjuster
|
||||
Adjuster newOther = other as Adjuster;
|
||||
|
||||
// If the Adjuster information matches
|
||||
bool match = (Name == newOther.Name
|
||||
&& Default == newOther.Default);
|
||||
if (!match)
|
||||
return match;
|
||||
|
||||
// If the conditions match
|
||||
if (ConditionsSpecified)
|
||||
{
|
||||
foreach (Condition condition in Conditions)
|
||||
{
|
||||
match &= newOther.Conditions.Contains(condition);
|
||||
}
|
||||
}
|
||||
|
||||
return match;
|
||||
// Compare the internal models
|
||||
return _adjuster.EqualTo(otherInternal._adjuster);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -16,7 +16,17 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Analog mask value
|
||||
/// </summary>
|
||||
[JsonProperty("mask", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("mask")]
|
||||
public string Mask { get; set; }
|
||||
public string? Mask
|
||||
{
|
||||
get => _analog.ReadString(Models.Internal.Analog.MaskKey);
|
||||
set => _analog[Models.Internal.Analog.MaskKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Internal Analog model
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
private Models.Internal.Analog _analog = new();
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -42,11 +52,11 @@ namespace SabreTools.DatItems.Formats
|
||||
ItemType = this.ItemType,
|
||||
DupeType = this.DupeType,
|
||||
|
||||
Machine = this.Machine.Clone() as Machine,
|
||||
Source = this.Source.Clone() as Source,
|
||||
Machine = this.Machine?.Clone() as Machine,
|
||||
Source = this.Source?.Clone() as Source,
|
||||
Remove = this.Remove,
|
||||
|
||||
Mask = this.Mask,
|
||||
_analog = this._analog?.Clone() as Models.Internal.Analog ?? new Models.Internal.Analog(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -55,17 +65,14 @@ namespace SabreTools.DatItems.Formats
|
||||
#region Comparision Methods
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Equals(DatItem other)
|
||||
public override bool Equals(DatItem? other)
|
||||
{
|
||||
// If we don't have a Analog, return false
|
||||
if (ItemType != other.ItemType)
|
||||
if (ItemType != other?.ItemType || other is not Analog otherInternal)
|
||||
return false;
|
||||
|
||||
// Otherwise, treat it as a Analog
|
||||
Analog newOther = other as Analog;
|
||||
|
||||
// If the Feature information matches
|
||||
return (Mask == newOther.Mask);
|
||||
// Compare the internal models
|
||||
return _analog.EqualTo(otherInternal._analog);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -16,82 +16,92 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Name of the item
|
||||
/// </summary>
|
||||
[JsonProperty("name"), XmlElement("name")]
|
||||
public string Name { get; set; }
|
||||
public string? Name
|
||||
{
|
||||
get => _archive.ReadString(Models.Internal.Archive.NameKey);
|
||||
set => _archive[Models.Internal.Archive.NameKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Archive ID number
|
||||
/// </summary>
|
||||
/// <remarks>No-Intro database export only</remarks>
|
||||
/// <remarks>TODO: No-Intro database export only</remarks>
|
||||
[JsonProperty("number"), XmlElement("number")]
|
||||
public string Number { get; set; }
|
||||
public string? Number { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Clone value
|
||||
/// </summary>
|
||||
/// <remarks>No-Intro database export only</remarks>
|
||||
/// <remarks>TODO: No-Intro database export only</remarks>
|
||||
[JsonProperty("clone"), XmlElement("clone")]
|
||||
public string CloneValue { get; set; }
|
||||
public string? CloneValue { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Regional parent value
|
||||
/// </summary>
|
||||
/// <remarks>No-Intro database export only</remarks>
|
||||
/// <remarks>TODO: No-Intro database export only</remarks>
|
||||
[JsonProperty("regparent"), XmlElement("regparent")]
|
||||
public string RegParent { get; set; }
|
||||
public string? RegParent { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Region value
|
||||
/// </summary>
|
||||
/// <remarks>No-Intro database export only</remarks>
|
||||
/// <remarks>TODO: No-Intro database export only</remarks>
|
||||
[JsonProperty("region"), XmlElement("region")]
|
||||
public string Region { get; set; }
|
||||
public string? Region { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Languages value
|
||||
/// </summary>
|
||||
/// <remarks>No-Intro database export only</remarks>
|
||||
/// <remarks>TODO: No-Intro database export only</remarks>
|
||||
[JsonProperty("languages"), XmlElement("languages")]
|
||||
public string Languages { get; set; }
|
||||
public string? Languages { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Development status value
|
||||
/// </summary>
|
||||
/// <remarks>No-Intro database export only</remarks>
|
||||
/// <remarks>TODO: No-Intro database export only</remarks>
|
||||
[JsonProperty("devstatus"), XmlElement("devstatus")]
|
||||
public string DevStatus { get; set; }
|
||||
public string? DevStatus { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Physical value
|
||||
/// </summary>
|
||||
/// <remarks>No-Intro database export only</remarks>
|
||||
/// <remarks>TODO: No-Intro database export only</remarks>
|
||||
/// <remarks>TODO: Is this numeric or a flag?</remarks>
|
||||
[JsonProperty("physical"), XmlElement("physical")]
|
||||
public string Physical { get; set; }
|
||||
public string? Physical { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Complete value
|
||||
/// </summary>
|
||||
/// <remarks>No-Intro database export only</remarks>
|
||||
/// <remarks>TODO: No-Intro database export only</remarks>
|
||||
/// <remarks>TODO: Is this numeric or a flag?</remarks>
|
||||
[JsonProperty("complete"), XmlElement("complete")]
|
||||
public string Complete { get; set; }
|
||||
public string? Complete { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Categories value
|
||||
/// </summary>
|
||||
/// <remarks>No-Intro database export only</remarks>
|
||||
/// <remarks>TODO: No-Intro database export only</remarks>
|
||||
[JsonProperty("categories"), XmlElement("categories")]
|
||||
public string Categories { get; set; }
|
||||
public string? Categories { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Internal Archive model
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
private Models.Internal.Archive _archive = new();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Accessors
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string GetName() => Name;
|
||||
public override string? GetName() => Name;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void SetName(string name) => Name = name;
|
||||
public override void SetName(string? name) => Name = name;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -118,20 +128,11 @@ namespace SabreTools.DatItems.Formats
|
||||
ItemType = this.ItemType,
|
||||
DupeType = this.DupeType,
|
||||
|
||||
Machine = this.Machine.Clone() as Machine,
|
||||
Source = this.Source.Clone() as Source,
|
||||
Machine = this.Machine?.Clone() as Machine,
|
||||
Source = this.Source?.Clone() as Source,
|
||||
Remove = this.Remove,
|
||||
|
||||
Name = this.Name,
|
||||
Number = this.Number,
|
||||
CloneValue = this.CloneValue,
|
||||
RegParent = this.RegParent,
|
||||
Region = this.Region,
|
||||
Languages = this.Languages,
|
||||
DevStatus = this.DevStatus,
|
||||
Physical = this.Physical,
|
||||
Complete = this.Complete,
|
||||
Categories = this.Categories,
|
||||
_archive = this._archive?.Clone() as Models.Internal.Archive ?? new Models.Internal.Archive(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -140,26 +141,14 @@ namespace SabreTools.DatItems.Formats
|
||||
#region Comparision Methods
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Equals(DatItem other)
|
||||
public override bool Equals(DatItem? other)
|
||||
{
|
||||
// If we don't have an archive, return false
|
||||
if (ItemType != other.ItemType)
|
||||
// If we don't have a Archive, return false
|
||||
if (ItemType != other?.ItemType || other is not Archive otherInternal)
|
||||
return false;
|
||||
|
||||
// Otherwise, treat it as an archive
|
||||
Archive newOther = other as Archive;
|
||||
|
||||
// If the archive information matches
|
||||
return (Name == newOther.Name
|
||||
&& Number == newOther.Number
|
||||
&& CloneValue == newOther.CloneValue
|
||||
&& RegParent == newOther.RegParent
|
||||
&& Region == newOther.Region
|
||||
&& Languages == newOther.Languages
|
||||
&& DevStatus == newOther.DevStatus
|
||||
&& Physical == newOther.Physical
|
||||
&& Complete == newOther.Complete
|
||||
&& Categories == newOther.Categories);
|
||||
// Compare the internal models
|
||||
return _archive.EqualTo(otherInternal._archive);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -17,10 +17,24 @@ namespace SabreTools.DatItems.Formats
|
||||
public class Original
|
||||
{
|
||||
[JsonProperty("value"), XmlElement("value")]
|
||||
public bool? Value { get; set; }
|
||||
public bool? Value
|
||||
{
|
||||
get => _original.ReadBool(Models.Internal.Original.ValueKey);
|
||||
set => _original[Models.Internal.Original.ValueKey] = value;
|
||||
}
|
||||
|
||||
[JsonProperty("content"), XmlElement("content")]
|
||||
public string Content { get; set; }
|
||||
public string? Content
|
||||
{
|
||||
get => _original.ReadString(Models.Internal.Original.ContentKey);
|
||||
set => _original[Models.Internal.Original.ContentKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Internal Original model
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
private readonly Models.Internal.Original _original = new();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -16,32 +16,50 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Name of the item
|
||||
/// </summary>
|
||||
[JsonProperty("name"), XmlElement("name")]
|
||||
public string Name { get; set; }
|
||||
public string? Name
|
||||
{
|
||||
get => _biosSet.ReadString(Models.Internal.BiosSet.NameKey);
|
||||
set => _biosSet[Models.Internal.BiosSet.NameKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Description of the BIOS
|
||||
/// </summary>
|
||||
[JsonProperty("description", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("description")]
|
||||
public string Description { get; set; }
|
||||
public string? Description
|
||||
{
|
||||
get => _biosSet.ReadString(Models.Internal.BiosSet.DescriptionKey);
|
||||
set => _biosSet[Models.Internal.BiosSet.DescriptionKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determine whether the BIOS is default
|
||||
/// </summary>
|
||||
[JsonProperty("default", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("default")]
|
||||
public bool? Default { get; set; }
|
||||
public bool? Default
|
||||
{
|
||||
get => _biosSet.ReadBool(Models.Internal.BiosSet.DefaultKey);
|
||||
set => _biosSet[Models.Internal.BiosSet.DefaultKey] = value;
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool DefaultSpecified { get { return Default != null; } }
|
||||
|
||||
/// <summary>
|
||||
/// Internal BiosSet model
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
private Models.Internal.BiosSet _biosSet = new();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Accessors
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string GetName() => Name;
|
||||
public override string? GetName() => Name;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void SetName(string name) => Name = name;
|
||||
public override void SetName(string? name) => Name = name;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -68,13 +86,11 @@ namespace SabreTools.DatItems.Formats
|
||||
ItemType = this.ItemType,
|
||||
DupeType = this.DupeType,
|
||||
|
||||
Machine = this.Machine.Clone() as Machine,
|
||||
Source = this.Source.Clone() as Source,
|
||||
Machine = this.Machine?.Clone() as Machine,
|
||||
Source = this.Source?.Clone() as Source,
|
||||
Remove = this.Remove,
|
||||
|
||||
Name = this.Name,
|
||||
Description = this.Description,
|
||||
Default = this.Default,
|
||||
_biosSet = this._biosSet?.Clone() as Models.Internal.BiosSet ?? new Models.Internal.BiosSet(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -83,19 +99,14 @@ namespace SabreTools.DatItems.Formats
|
||||
#region Comparision Methods
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Equals(DatItem other)
|
||||
public override bool Equals(DatItem? other)
|
||||
{
|
||||
// If we don't have a BiosSet, return false
|
||||
if (ItemType != other.ItemType)
|
||||
if (ItemType != other?.ItemType || other is not BiosSet otherInternal)
|
||||
return false;
|
||||
|
||||
// Otherwise, treat it as a BiosSet
|
||||
BiosSet newOther = other as BiosSet;
|
||||
|
||||
// If the BiosSet information matches
|
||||
return (Name == newOther.Name
|
||||
&& Description == newOther.Description
|
||||
&& Default == newOther.Default);
|
||||
// Compare the internal models
|
||||
return _biosSet.EqualTo(otherInternal._biosSet);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -32,8 +32,8 @@ namespace SabreTools.DatItems.Formats
|
||||
ItemType = this.ItemType,
|
||||
DupeType = this.DupeType,
|
||||
|
||||
Machine = this.Machine.Clone() as Machine,
|
||||
Source = this.Source.Clone() as Source,
|
||||
Machine = this.Machine?.Clone() as Machine,
|
||||
Source = this.Source?.Clone() as Source,
|
||||
Remove = this.Remove,
|
||||
};
|
||||
}
|
||||
@@ -43,17 +43,17 @@ namespace SabreTools.DatItems.Formats
|
||||
#region Comparision Methods
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Equals(DatItem other)
|
||||
public override bool Equals(DatItem? other)
|
||||
{
|
||||
// If we don't have a blank, return false
|
||||
if (ItemType != other.ItemType)
|
||||
if (ItemType != other?.ItemType)
|
||||
return false;
|
||||
|
||||
// Otherwise, treat it as a Blank
|
||||
Blank newOther = other as Blank;
|
||||
Blank? newOther = other as Blank;
|
||||
|
||||
// If the archive information matches
|
||||
return (Machine == newOther.Machine);
|
||||
return (Machine == newOther!.Machine);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using SabreTools.Core;
|
||||
using SabreTools.Core.Tools;
|
||||
|
||||
namespace SabreTools.DatItems.Formats
|
||||
{
|
||||
@@ -17,20 +18,32 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Name of the item
|
||||
/// </summary>
|
||||
[JsonProperty("name"), XmlElement("name")]
|
||||
public string Name { get; set; }
|
||||
public string? Name
|
||||
{
|
||||
get => _chip.ReadString(Models.Internal.Chip.NameKey);
|
||||
set => _chip[Models.Internal.Chip.NameKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Internal tag
|
||||
/// </summary>
|
||||
[JsonProperty("tag", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("tag")]
|
||||
public string Tag { get; set; }
|
||||
public string? Tag
|
||||
{
|
||||
get => _chip.ReadString(Models.Internal.Chip.TagKey);
|
||||
set => _chip[Models.Internal.Chip.TagKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Type of the chip
|
||||
/// </summary>
|
||||
[JsonProperty("type", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("type")]
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
public ChipType ChipType { get; set; }
|
||||
public ChipType ChipType
|
||||
{
|
||||
get => _chip.ReadString(Models.Internal.Chip.ChipTypeKey).AsChipType();
|
||||
set => _chip[Models.Internal.Chip.ChipTypeKey] = value.FromChipType();
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool ChipTypeSpecified { get { return ChipType != ChipType.NULL; } }
|
||||
@@ -39,20 +52,30 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Clock speed
|
||||
/// </summary>
|
||||
[JsonProperty("clock", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("clock")]
|
||||
public long? Clock { get; set; }
|
||||
public long? Clock
|
||||
{
|
||||
get => _chip.ReadLong(Models.Internal.Chip.ClockKey);
|
||||
set => _chip[Models.Internal.Chip.ClockKey] = value;
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool ClockSpecified { get { return Clock != null; } }
|
||||
|
||||
/// <summary>
|
||||
/// Internal Chip model
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
private Models.Internal.Chip _chip = new();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Accessors
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string GetName() => Name;
|
||||
public override string? GetName() => Name;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void SetName(string name) => Name = name;
|
||||
public override void SetName(string? name) => Name = name;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -79,14 +102,11 @@ namespace SabreTools.DatItems.Formats
|
||||
ItemType = this.ItemType,
|
||||
DupeType = this.DupeType,
|
||||
|
||||
Machine = this.Machine.Clone() as Machine,
|
||||
Source = this.Source.Clone() as Source,
|
||||
Machine = this.Machine?.Clone() as Machine,
|
||||
Source = this.Source?.Clone() as Source,
|
||||
Remove = this.Remove,
|
||||
|
||||
Name = this.Name,
|
||||
Tag = this.Tag,
|
||||
ChipType = this.ChipType,
|
||||
Clock = this.Clock,
|
||||
_chip = this._chip?.Clone() as Models.Internal.Chip ?? new Models.Internal.Chip(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -95,20 +115,14 @@ namespace SabreTools.DatItems.Formats
|
||||
#region Comparision Methods
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Equals(DatItem other)
|
||||
public override bool Equals(DatItem? other)
|
||||
{
|
||||
// If we don't have a chip, return false
|
||||
if (ItemType != other.ItemType)
|
||||
// If we don't have a Chip, return false
|
||||
if (ItemType != other?.ItemType || other is not Chip otherInternal)
|
||||
return false;
|
||||
|
||||
// Otherwise, treat it as a chip
|
||||
Chip newOther = other as Chip;
|
||||
|
||||
// If the chip information matches
|
||||
return (Name == newOther.Name
|
||||
&& Tag == newOther.Tag
|
||||
&& ChipType == newOther.ChipType
|
||||
&& Clock == newOther.Clock);
|
||||
// Compare the internal models
|
||||
return _chip.EqualTo(otherInternal._chip);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using SabreTools.Core;
|
||||
using SabreTools.Core.Tools;
|
||||
|
||||
namespace SabreTools.DatItems.Formats
|
||||
{
|
||||
@@ -17,29 +18,51 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Condition tag value
|
||||
/// </summary>
|
||||
[JsonProperty("tag", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("tag")]
|
||||
public string Tag { get; set; }
|
||||
public string? Tag
|
||||
{
|
||||
get => _condition.ReadString(Models.Internal.Condition.TagKey);
|
||||
set => _condition[Models.Internal.Condition.TagKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Condition mask
|
||||
/// </summary>
|
||||
[JsonProperty("mask", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("mask")]
|
||||
public string Mask { get; set; }
|
||||
public string? Mask
|
||||
{
|
||||
get => _condition.ReadString(Models.Internal.Condition.MaskKey);
|
||||
set => _condition[Models.Internal.Condition.MaskKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Condition relationship
|
||||
/// </summary>
|
||||
[JsonProperty("relation", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("relation")]
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
public Relation Relation { get; set; }
|
||||
public Relation Relation
|
||||
{
|
||||
get => _condition.ReadString(Models.Internal.Condition.RelationKey).AsRelation();
|
||||
set => _condition[Models.Internal.Condition.RelationKey] = value.FromRelation();
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool RelationSpecified { get { return Relation != Relation.NULL; } }
|
||||
public bool RelationSpecified { get { return Relation != Core.Relation.NULL; } }
|
||||
|
||||
/// <summary>
|
||||
/// Condition value
|
||||
/// </summary>
|
||||
[JsonProperty("value", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("value")]
|
||||
public string Value { get; set; }
|
||||
public string? Value
|
||||
{
|
||||
get => _condition.ReadString(Models.Internal.Condition.ValueKey);
|
||||
set => _condition[Models.Internal.Condition.ValueKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Internal Condition model
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
private Models.Internal.Condition _condition = new();
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -65,14 +88,11 @@ namespace SabreTools.DatItems.Formats
|
||||
ItemType = this.ItemType,
|
||||
DupeType = this.DupeType,
|
||||
|
||||
Machine = this.Machine.Clone() as Machine,
|
||||
Source = this.Source.Clone() as Source,
|
||||
Machine = this.Machine?.Clone() as Machine,
|
||||
Source = this.Source?.Clone() as Source,
|
||||
Remove = this.Remove,
|
||||
|
||||
Tag = this.Tag,
|
||||
Mask = this.Mask,
|
||||
Relation = this.Relation,
|
||||
Value = this.Value,
|
||||
_condition = this._condition?.Clone() as Models.Internal.Condition ?? new Models.Internal.Condition(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -81,20 +101,14 @@ namespace SabreTools.DatItems.Formats
|
||||
#region Comparision Methods
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Equals(DatItem other)
|
||||
public override bool Equals(DatItem? other)
|
||||
{
|
||||
// If we don't have a Condition, return false
|
||||
if (ItemType != other.ItemType)
|
||||
if (ItemType != other?.ItemType || other is not Condition otherInternal)
|
||||
return false;
|
||||
|
||||
// Otherwise, treat it as a Condition
|
||||
Condition newOther = other as Condition;
|
||||
|
||||
// If the Feature information matches
|
||||
return (Tag == newOther.Tag
|
||||
&& Mask == newOther.Mask
|
||||
&& Relation == newOther.Relation
|
||||
&& Value == newOther.Value);
|
||||
// Compare the internal models
|
||||
return _condition.EqualTo(otherInternal._condition);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
117
SabreTools.DatItems/Formats/ConfLocation.cs
Normal file
117
SabreTools.DatItems/Formats/ConfLocation.cs
Normal file
@@ -0,0 +1,117 @@
|
||||
using System.Xml.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
using SabreTools.Core;
|
||||
|
||||
namespace SabreTools.DatItems.Formats
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents one conflocation
|
||||
/// </summary>
|
||||
[JsonObject("conflocation"), XmlRoot("conflocation")]
|
||||
public class ConfLocation : DatItem
|
||||
{
|
||||
#region Fields
|
||||
|
||||
/// <summary>
|
||||
/// Location name
|
||||
/// </summary>
|
||||
[JsonProperty("name"), XmlElement("name")]
|
||||
public string? Name
|
||||
{
|
||||
get => _confLocation.ReadString(Models.Internal.ConfLocation.NameKey);
|
||||
set => _confLocation[Models.Internal.ConfLocation.NameKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Location ID
|
||||
/// </summary>
|
||||
[JsonProperty("number", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("number")]
|
||||
public long? Number
|
||||
{
|
||||
get => _confLocation.ReadLong(Models.Internal.ConfLocation.NumberKey);
|
||||
set => _confLocation[Models.Internal.ConfLocation.NumberKey] = value;
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool NumberSpecified { get { return Number != null; } }
|
||||
|
||||
/// <summary>
|
||||
/// Determines if location is inverted or not
|
||||
/// </summary>
|
||||
[JsonProperty("inverted", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("inverted")]
|
||||
public bool? Inverted
|
||||
{
|
||||
get => _confLocation.ReadBool(Models.Internal.ConfLocation.InvertedKey);
|
||||
set => _confLocation[Models.Internal.ConfLocation.InvertedKey] = value;
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool InvertedSpecified { get { return Inverted != null; } }
|
||||
|
||||
/// <summary>
|
||||
/// Internal ConfLocation model
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
private Models.Internal.ConfLocation _confLocation = new();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Accessors
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string? GetName() => Name;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void SetName(string? name) => Name = name;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Create a default, empty ConfLocation object
|
||||
/// </summary>
|
||||
public ConfLocation()
|
||||
{
|
||||
Name = string.Empty;
|
||||
ItemType = ItemType.ConfLocation;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Cloning Methods
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override object Clone()
|
||||
{
|
||||
return new ConfLocation()
|
||||
{
|
||||
ItemType = this.ItemType,
|
||||
DupeType = this.DupeType,
|
||||
|
||||
Machine = this.Machine?.Clone() as Machine,
|
||||
Source = this.Source?.Clone() as Source,
|
||||
Remove = this.Remove,
|
||||
|
||||
_confLocation = this._confLocation?.Clone() as Models.Internal.ConfLocation ?? new Models.Internal.ConfLocation(),
|
||||
};
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Comparision Methods
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Equals(DatItem? other)
|
||||
{
|
||||
// If we don't have a v, return false
|
||||
if (ItemType != other?.ItemType || other is not ConfLocation otherInternal)
|
||||
return false;
|
||||
|
||||
// Compare the internal models
|
||||
return _confLocation.EqualTo(otherInternal._confLocation);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
129
SabreTools.DatItems/Formats/ConfSetting.cs
Normal file
129
SabreTools.DatItems/Formats/ConfSetting.cs
Normal file
@@ -0,0 +1,129 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Xml.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
using SabreTools.Core;
|
||||
|
||||
namespace SabreTools.DatItems.Formats
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents one ListXML confsetting
|
||||
/// </summary>
|
||||
[JsonObject("confsetting"), XmlRoot("confsetting")]
|
||||
public class ConfSetting : DatItem
|
||||
{
|
||||
#region Fields
|
||||
|
||||
/// <summary>
|
||||
/// Setting name
|
||||
/// </summary>
|
||||
[JsonProperty("name"), XmlElement("name")]
|
||||
public string? Name
|
||||
{
|
||||
get => _confSetting.ReadString(Models.Internal.ConfSetting.NameKey);
|
||||
set => _confSetting[Models.Internal.ConfSetting.NameKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Setting value
|
||||
/// </summary>
|
||||
[JsonProperty("value", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("value")]
|
||||
public string? Value
|
||||
{
|
||||
get => _confSetting.ReadString(Models.Internal.ConfSetting.ValueKey);
|
||||
set => _confSetting[Models.Internal.ConfSetting.ValueKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines if the setting is default or not
|
||||
/// </summary>
|
||||
[JsonProperty("default", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("default")]
|
||||
public bool? Default
|
||||
{
|
||||
get => _confSetting.ReadBool(Models.Internal.ConfSetting.DefaultKey);
|
||||
set => _confSetting[Models.Internal.ConfSetting.DefaultKey] = value;
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool DefaultSpecified { get { return Default != null; } }
|
||||
|
||||
/// <summary>
|
||||
/// List of conditions on the setting
|
||||
/// </summary>
|
||||
[JsonProperty("conditions", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("conditions")]
|
||||
public List<Condition>? Conditions
|
||||
{
|
||||
get => _confSetting.Read<Condition[]>(Models.Internal.ConfSetting.ConditionKey)?.ToList();
|
||||
set => _confSetting[Models.Internal.ConfSetting.ConditionKey] = value?.ToArray();
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool ConditionsSpecified { get { return Conditions != null && Conditions.Count > 0; } }
|
||||
|
||||
/// <summary>
|
||||
/// Internal ConfSetting model
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
private Models.Internal.ConfSetting _confSetting = new();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Accessors
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string? GetName() => Name;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void SetName(string? name) => Name = name;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Create a default, empty ConfSetting object
|
||||
/// </summary>
|
||||
public ConfSetting()
|
||||
{
|
||||
Name = string.Empty;
|
||||
ItemType = ItemType.ConfSetting;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Cloning Methods
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override object Clone()
|
||||
{
|
||||
return new ConfSetting()
|
||||
{
|
||||
ItemType = this.ItemType,
|
||||
DupeType = this.DupeType,
|
||||
|
||||
Machine = this.Machine?.Clone() as Machine,
|
||||
Source = this.Source?.Clone() as Source,
|
||||
Remove = this.Remove,
|
||||
|
||||
_confSetting = this._confSetting?.Clone() as Models.Internal.ConfSetting ?? new Models.Internal.ConfSetting(),
|
||||
};
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Comparision Methods
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Equals(DatItem? other)
|
||||
{
|
||||
// If we don't have a ConfSetting, return false
|
||||
if (ItemType != other?.ItemType || other is not ConfSetting otherInternal)
|
||||
return false;
|
||||
|
||||
// Compare the internal models
|
||||
return _confSetting.EqualTo(otherInternal._confSetting);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Xml.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
using SabreTools.Core;
|
||||
@@ -17,25 +18,41 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Name of the item
|
||||
/// </summary>
|
||||
[JsonProperty("name"), XmlElement("name")]
|
||||
public string Name { get; set; }
|
||||
public string? Name
|
||||
{
|
||||
get => _configuration.ReadString(Models.Internal.Configuration.NameKey);
|
||||
set => _configuration[Models.Internal.Configuration.NameKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tag associated with the configuration
|
||||
/// </summary>
|
||||
[JsonProperty("tag", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("tag")]
|
||||
public string Tag { get; set; }
|
||||
public string? Tag
|
||||
{
|
||||
get => _configuration.ReadString(Models.Internal.Configuration.TagKey);
|
||||
set => _configuration[Models.Internal.Configuration.TagKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Mask associated with the configuration
|
||||
/// </summary>
|
||||
[JsonProperty("mask", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("mask")]
|
||||
public string Mask { get; set; }
|
||||
public string? Mask
|
||||
{
|
||||
get => _configuration.ReadString(Models.Internal.Configuration.MaskKey);
|
||||
set => _configuration[Models.Internal.Configuration.MaskKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Conditions associated with the configuration
|
||||
/// </summary>
|
||||
[JsonProperty("conditions", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("conditions")]
|
||||
public List<Condition> Conditions { get; set; }
|
||||
public List<Condition>? Conditions
|
||||
{
|
||||
get => _configuration.Read<Condition[]>(Models.Internal.Configuration.ConditionKey)?.ToList();
|
||||
set => _configuration[Models.Internal.Configuration.ConditionKey] = value?.ToArray();
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool ConditionsSpecified { get { return Conditions != null && Conditions.Count > 0; } }
|
||||
@@ -44,7 +61,11 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Locations associated with the configuration
|
||||
/// </summary>
|
||||
[JsonProperty("locations", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("locations")]
|
||||
public List<Location> Locations { get; set; }
|
||||
public List<ConfLocation>? Locations
|
||||
{
|
||||
get => _configuration.Read<ConfLocation[]>(Models.Internal.Configuration.ConfLocationKey)?.ToList();
|
||||
set => _configuration[Models.Internal.Configuration.ConfLocationKey] = value?.ToArray();
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool LocationsSpecified { get { return Locations != null && Locations.Count > 0; } }
|
||||
@@ -53,20 +74,30 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Settings associated with the configuration
|
||||
/// </summary>
|
||||
[JsonProperty("settings", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("settings")]
|
||||
public List<Setting> Settings { get; set; }
|
||||
public List<ConfSetting>? Settings
|
||||
{
|
||||
get => _configuration.Read<List<ConfSetting>>(Models.Internal.Configuration.ConfSettingKey);
|
||||
set => _configuration[Models.Internal.Configuration.ConfSettingKey] = value;
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool SettingsSpecified { get { return Settings != null && Settings.Count > 0; } }
|
||||
|
||||
/// <summary>
|
||||
/// Internal Configuration model
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
private Models.Internal.Configuration _configuration = new();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Accessors
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string GetName() => Name;
|
||||
public override string? GetName() => Name;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void SetName(string name) => Name = name;
|
||||
public override void SetName(string? name) => Name = name;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -93,16 +124,11 @@ namespace SabreTools.DatItems.Formats
|
||||
ItemType = this.ItemType,
|
||||
DupeType = this.DupeType,
|
||||
|
||||
Machine = this.Machine.Clone() as Machine,
|
||||
Source = this.Source.Clone() as Source,
|
||||
Machine = this.Machine?.Clone() as Machine,
|
||||
Source = this.Source?.Clone() as Source,
|
||||
Remove = this.Remove,
|
||||
|
||||
Name = this.Name,
|
||||
Tag = this.Tag,
|
||||
Mask = this.Mask,
|
||||
Conditions = this.Conditions,
|
||||
Locations = this.Locations,
|
||||
Settings = this.Settings,
|
||||
_configuration = this._configuration?.Clone() as Models.Internal.Configuration ?? new Models.Internal.Configuration(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -111,50 +137,14 @@ namespace SabreTools.DatItems.Formats
|
||||
#region Comparision Methods
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Equals(DatItem other)
|
||||
public override bool Equals(DatItem? other)
|
||||
{
|
||||
// If we don't have a Configuration, return false
|
||||
if (ItemType != other.ItemType)
|
||||
if (ItemType != other?.ItemType || other is not Configuration otherInternal)
|
||||
return false;
|
||||
|
||||
// Otherwise, treat it as a Configuration
|
||||
Configuration newOther = other as Configuration;
|
||||
|
||||
// If the Configuration information matches
|
||||
bool match = (Name == newOther.Name
|
||||
&& Tag == newOther.Tag
|
||||
&& Mask == newOther.Mask);
|
||||
if (!match)
|
||||
return match;
|
||||
|
||||
// If the conditions match
|
||||
if (ConditionsSpecified)
|
||||
{
|
||||
foreach (Condition condition in Conditions)
|
||||
{
|
||||
match &= newOther.Conditions.Contains(condition);
|
||||
}
|
||||
}
|
||||
|
||||
// If the locations match
|
||||
if (LocationsSpecified)
|
||||
{
|
||||
foreach (Location location in Locations)
|
||||
{
|
||||
match &= newOther.Locations.Contains(location);
|
||||
}
|
||||
}
|
||||
|
||||
// If the settings match
|
||||
if (SettingsSpecified)
|
||||
{
|
||||
foreach (Setting setting in Settings)
|
||||
{
|
||||
match &= newOther.Settings.Contains(setting);
|
||||
}
|
||||
}
|
||||
|
||||
return match;
|
||||
// Compare the internal models
|
||||
return _configuration.EqualTo(otherInternal._configuration);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using SabreTools.Core;
|
||||
using SabreTools.Core.Tools;
|
||||
|
||||
namespace SabreTools.DatItems.Formats
|
||||
{
|
||||
@@ -18,7 +19,11 @@ namespace SabreTools.DatItems.Formats
|
||||
/// </summary>
|
||||
[JsonProperty("type", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("type")]
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
public ControlType ControlType { get; set; }
|
||||
public ControlType ControlType
|
||||
{
|
||||
get => _control.ReadString(Models.Internal.Control.ControlTypeKey).AsControlType();
|
||||
set => _control[Models.Internal.Control.ControlTypeKey] = value.FromControlType();
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool ControlTypeSpecified { get { return ControlType != ControlType.NULL; } }
|
||||
@@ -27,7 +32,11 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Player which the input belongs to
|
||||
/// </summary>
|
||||
[JsonProperty("player", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("player")]
|
||||
public long? Player { get; set; }
|
||||
public long? Player
|
||||
{
|
||||
get => _control.ReadLong(Models.Internal.Control.PlayerKey);
|
||||
set => _control[Models.Internal.Control.PlayerKey] = value;
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool PlayerSpecified { get { return Player != null; } }
|
||||
@@ -36,7 +45,11 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Total number of buttons
|
||||
/// </summary>
|
||||
[JsonProperty("buttons", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("buttons")]
|
||||
public long? Buttons { get; set; }
|
||||
public long? Buttons
|
||||
{
|
||||
get => _control.ReadLong(Models.Internal.Control.ButtonsKey);
|
||||
set => _control[Models.Internal.Control.ButtonsKey] = value;
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool ButtonsSpecified { get { return Buttons != null; } }
|
||||
@@ -45,7 +58,11 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Total number of non-optional buttons
|
||||
/// </summary>
|
||||
[JsonProperty("reqbuttons", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("reqbuttons")]
|
||||
public long? RequiredButtons { get; set; }
|
||||
public long? RequiredButtons
|
||||
{
|
||||
get => _control.ReadLong(Models.Internal.Control.ReqButtonsKey);
|
||||
set => _control[Models.Internal.Control.ReqButtonsKey] = value;
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool RequiredButtonsSpecified { get { return RequiredButtons != null; } }
|
||||
@@ -54,7 +71,11 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Analog minimum value
|
||||
/// </summary>
|
||||
[JsonProperty("minimum", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("minimum")]
|
||||
public long? Minimum { get; set; }
|
||||
public long? Minimum
|
||||
{
|
||||
get => _control.ReadLong(Models.Internal.Control.MinimumKey);
|
||||
set => _control[Models.Internal.Control.MinimumKey] = value;
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool MinimumSpecified { get { return Minimum != null; } }
|
||||
@@ -63,7 +84,11 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Analog maximum value
|
||||
/// </summary>
|
||||
[JsonProperty("maximum", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("maximum")]
|
||||
public long? Maximum { get; set; }
|
||||
public long? Maximum
|
||||
{
|
||||
get => _control.ReadLong(Models.Internal.Control.MaximumKey);
|
||||
set => _control[Models.Internal.Control.MaximumKey] = value;
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool MaximumSpecified { get { return Maximum != null; } }
|
||||
@@ -72,7 +97,11 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Default analog sensitivity
|
||||
/// </summary>
|
||||
[JsonProperty("sensitivity", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("sensitivity")]
|
||||
public long? Sensitivity { get; set; }
|
||||
public long? Sensitivity
|
||||
{
|
||||
get => _control.ReadLong(Models.Internal.Control.SensitivityKey);
|
||||
set => _control[Models.Internal.Control.SensitivityKey] = value;
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool SensitivitySpecified { get { return Sensitivity != null; } }
|
||||
@@ -81,7 +110,11 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Default analog keydelta
|
||||
/// </summary>
|
||||
[JsonProperty("keydelta", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("keydelta")]
|
||||
public long? KeyDelta { get; set; }
|
||||
public long? KeyDelta
|
||||
{
|
||||
get => _control.ReadLong(Models.Internal.Control.KeyDeltaKey);
|
||||
set => _control[Models.Internal.Control.KeyDeltaKey] = value;
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool KeyDeltaSpecified { get { return KeyDelta != null; } }
|
||||
@@ -90,7 +123,11 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Default analog reverse setting
|
||||
/// </summary>
|
||||
[JsonProperty("reverse", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("reverse")]
|
||||
public bool? Reverse { get; set; }
|
||||
public bool? Reverse
|
||||
{
|
||||
get => _control.ReadBool(Models.Internal.Control.ReverseKey);
|
||||
set => _control[Models.Internal.Control.ReverseKey] = value;
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool ReverseSpecified { get { return Reverse != null; } }
|
||||
@@ -99,19 +136,37 @@ namespace SabreTools.DatItems.Formats
|
||||
/// First set of ways
|
||||
/// </summary>
|
||||
[JsonProperty("ways", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("ways")]
|
||||
public string Ways { get; set; }
|
||||
public string? Ways
|
||||
{
|
||||
get => _control.ReadString(Models.Internal.Control.WaysKey);
|
||||
set => _control[Models.Internal.Control.WaysKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Second set of ways
|
||||
/// </summary>
|
||||
[JsonProperty("ways2", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("ways2")]
|
||||
public string Ways2 { get; set; }
|
||||
public string? Ways2
|
||||
{
|
||||
get => _control.ReadString(Models.Internal.Control.Ways2Key);
|
||||
set => _control[Models.Internal.Control.Ways2Key] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Third set of ways
|
||||
/// </summary>
|
||||
[JsonProperty("ways3", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("ways3")]
|
||||
public string Ways3 { get; set; }
|
||||
public string? Ways3
|
||||
{
|
||||
get => _control.ReadString(Models.Internal.Control.Ways3Key);
|
||||
set => _control[Models.Internal.Control.Ways3Key] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Internal Control model
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
private Models.Internal.Control _control = new();
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -137,22 +192,11 @@ namespace SabreTools.DatItems.Formats
|
||||
ItemType = this.ItemType,
|
||||
DupeType = this.DupeType,
|
||||
|
||||
Machine = this.Machine.Clone() as Machine,
|
||||
Source = this.Source.Clone() as Source,
|
||||
Machine = this.Machine?.Clone() as Machine,
|
||||
Source = this.Source?.Clone() as Source,
|
||||
Remove = this.Remove,
|
||||
|
||||
ControlType = this.ControlType,
|
||||
Player = this.Player,
|
||||
Buttons = this.Buttons,
|
||||
RequiredButtons = this.RequiredButtons,
|
||||
Minimum = this.Minimum,
|
||||
Maximum = this.Maximum,
|
||||
Sensitivity = this.Sensitivity,
|
||||
KeyDelta = this.KeyDelta,
|
||||
Reverse = this.Reverse,
|
||||
Ways = this.Ways,
|
||||
Ways2 = this.Ways2,
|
||||
Ways3 = this.Ways3,
|
||||
_control = this._control?.Clone() as Models.Internal.Control ?? new Models.Internal.Control(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -161,28 +205,14 @@ namespace SabreTools.DatItems.Formats
|
||||
#region Comparision Methods
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Equals(DatItem other)
|
||||
public override bool Equals(DatItem? other)
|
||||
{
|
||||
// If we don't have a Control, return false
|
||||
if (ItemType != other.ItemType)
|
||||
if (ItemType != other?.ItemType || other is not Control otherInternal)
|
||||
return false;
|
||||
|
||||
// Otherwise, treat it as a Control
|
||||
Control newOther = other as Control;
|
||||
|
||||
// If the Control information matches
|
||||
return (ControlType == newOther.ControlType
|
||||
&& Player == newOther.Player
|
||||
&& Buttons == newOther.Buttons
|
||||
&& RequiredButtons == newOther.RequiredButtons
|
||||
&& Minimum == newOther.Minimum
|
||||
&& Maximum == newOther.Maximum
|
||||
&& Sensitivity == newOther.Sensitivity
|
||||
&& KeyDelta == newOther.KeyDelta
|
||||
&& Reverse == newOther.Reverse
|
||||
&& Ways == newOther.Ways
|
||||
&& Ways2 == newOther.Ways2
|
||||
&& Ways3 == newOther.Ways3);
|
||||
// Compare the internal models
|
||||
return _control.EqualTo(otherInternal._control);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System.Xml.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
using SabreTools.Core;
|
||||
using SabreTools.Core.Tools;
|
||||
|
||||
namespace SabreTools.DatItems.Formats
|
||||
{
|
||||
@@ -17,13 +18,21 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Name of the item
|
||||
/// </summary>
|
||||
[JsonProperty("name", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("name")]
|
||||
public string Name { get; set; }
|
||||
public string? Name
|
||||
{
|
||||
get => _dataArea.ReadString(Models.Internal.DataArea.NameKey);
|
||||
set => _dataArea[Models.Internal.DataArea.NameKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Total size of the area
|
||||
/// </summary>
|
||||
[JsonProperty("size", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("size")]
|
||||
public long? Size { get; set; }
|
||||
public long? Size
|
||||
{
|
||||
get => _dataArea.ReadLong(Models.Internal.DataArea.SizeKey);
|
||||
set => _dataArea[Models.Internal.DataArea.SizeKey] = value;
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool SizeSpecified { get { return Size != null; } }
|
||||
@@ -32,7 +41,11 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Word width for the area
|
||||
/// </summary>
|
||||
[JsonProperty("width", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("width")]
|
||||
public long? Width { get; set; }
|
||||
public long? Width
|
||||
{
|
||||
get => _dataArea.ReadLong(Models.Internal.DataArea.WidthKey);
|
||||
set => _dataArea[Models.Internal.DataArea.WidthKey] = value;
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool WidthSpecified { get { return Width != null; } }
|
||||
@@ -41,20 +54,30 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Byte endianness of the area
|
||||
/// </summary>
|
||||
[JsonProperty("endianness", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("endianness")]
|
||||
public Endianness Endianness { get; set; }
|
||||
public Endianness Endianness
|
||||
{
|
||||
get => _dataArea.ReadString(Models.Internal.DataArea.WidthKey).AsEndianness();
|
||||
set => _dataArea[Models.Internal.DataArea.WidthKey] = value.FromEndianness();
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool EndiannessSpecified { get { return Endianness != Endianness.NULL; } }
|
||||
|
||||
/// <summary>
|
||||
/// Internal DataArea model
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
private Models.Internal.DataArea _dataArea = new();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Accessors
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string GetName() => Name;
|
||||
public override string? GetName() => Name;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void SetName(string name) => Name = name;
|
||||
public override void SetName(string? name) => Name = name;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -81,14 +104,11 @@ namespace SabreTools.DatItems.Formats
|
||||
ItemType = this.ItemType,
|
||||
DupeType = this.DupeType,
|
||||
|
||||
Machine = this.Machine.Clone() as Machine,
|
||||
Source = this.Source.Clone() as Source,
|
||||
Machine = this.Machine?.Clone() as Machine,
|
||||
Source = this.Source?.Clone() as Source,
|
||||
Remove = this.Remove,
|
||||
|
||||
Name = this.Name,
|
||||
Size = this.Size,
|
||||
Width = this.Width,
|
||||
Endianness = this.Endianness,
|
||||
_dataArea = this._dataArea?.Clone() as Models.Internal.DataArea ?? new Models.Internal.DataArea(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -97,20 +117,14 @@ namespace SabreTools.DatItems.Formats
|
||||
#region Comparision Methods
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Equals(DatItem other)
|
||||
public override bool Equals(DatItem? other)
|
||||
{
|
||||
// If we don't have a DataArea, return false
|
||||
if (ItemType != other.ItemType)
|
||||
if (ItemType != other?.ItemType || other is not DataArea otherInternal)
|
||||
return false;
|
||||
|
||||
// Otherwise, treat it as a DataArea
|
||||
DataArea newOther = other as DataArea;
|
||||
|
||||
// If the DataArea information matches
|
||||
return (Name == newOther.Name
|
||||
&& Size == newOther.Size
|
||||
&& Width == newOther.Width
|
||||
&& Endianness == newOther.Endianness);
|
||||
// Compare the internal models
|
||||
return _dataArea.EqualTo(otherInternal._dataArea);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Xml.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using SabreTools.Core;
|
||||
using SabreTools.Core.Tools;
|
||||
|
||||
namespace SabreTools.DatItems.Formats
|
||||
{
|
||||
@@ -19,7 +21,11 @@ namespace SabreTools.DatItems.Formats
|
||||
/// </summary>
|
||||
[JsonProperty("type", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("type")]
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
public DeviceType DeviceType { get; set; }
|
||||
public DeviceType DeviceType
|
||||
{
|
||||
get => _device.ReadString(Models.Internal.Device.DeviceTypeKey).AsDeviceType();
|
||||
set => _device[Models.Internal.Device.DeviceTypeKey] = value.FromDeviceType();
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool DeviceTypeSpecified { get { return DeviceType != DeviceType.NULL; } }
|
||||
@@ -28,20 +34,32 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Device tag
|
||||
/// </summary>
|
||||
[JsonProperty("tag", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("tag")]
|
||||
public string Tag { get; set; }
|
||||
public string? Tag
|
||||
{
|
||||
get => _device.ReadString(Models.Internal.Device.TagKey);
|
||||
set => _device[Models.Internal.Device.TagKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fixed image format
|
||||
/// </summary>
|
||||
[JsonProperty("fixed_image", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("fixed_image")]
|
||||
public string FixedImage { get; set; }
|
||||
public string? FixedImage
|
||||
{
|
||||
get => _device.ReadString(Models.Internal.Device.FixedImageKey);
|
||||
set => _device[Models.Internal.Device.FixedImageKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines if the devices is mandatory
|
||||
/// </summary>
|
||||
/// <remarks>Only value used seems to be 1. Used like bool, but actually int</remarks>
|
||||
[JsonProperty("mandatory", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("mandatory")]
|
||||
public long? Mandatory { get; set; }
|
||||
public long? Mandatory
|
||||
{
|
||||
get => _device.ReadLong(Models.Internal.Device.MandatoryKey);
|
||||
set => _device[Models.Internal.Device.MandatoryKey] = value;
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool MandatorySpecified { get { return Mandatory != null; } }
|
||||
@@ -50,13 +68,21 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Device interface
|
||||
/// </summary>
|
||||
[JsonProperty("interface", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("interface")]
|
||||
public string Interface { get; set; }
|
||||
public string? Interface
|
||||
{
|
||||
get => _device.ReadString(Models.Internal.Device.InterfaceKey);
|
||||
set => _device[Models.Internal.Device.InterfaceKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Device instances
|
||||
/// </summary>
|
||||
[JsonProperty("instances", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("instances")]
|
||||
public List<Instance> Instances { get; set; }
|
||||
public List<Instance>? Instances
|
||||
{
|
||||
get => _device.Read<Instance[]>(Models.Internal.Device.InstanceKey)?.ToList();
|
||||
set => _device[Models.Internal.Device.InstanceKey] = value?.ToArray();
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool InstancesSpecified { get { return Instances != null && Instances.Count > 0; } }
|
||||
@@ -65,11 +91,21 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Device extensions
|
||||
/// </summary>
|
||||
[JsonProperty("extensions", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("extensions")]
|
||||
public List<Extension> Extensions { get; set; }
|
||||
public List<Extension>? Extensions
|
||||
{
|
||||
get => _device.Read<Extension[]>(Models.Internal.Device.ExtensionKey)?.ToList();
|
||||
set => _device[Models.Internal.Device.ExtensionKey] = value?.ToArray();
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool ExtensionsSpecified { get { return Extensions != null && Extensions.Count > 0; } }
|
||||
|
||||
/// <summary>
|
||||
/// Internal Device model
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
private Models.Internal.Device _device = new();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
@@ -94,17 +130,11 @@ namespace SabreTools.DatItems.Formats
|
||||
ItemType = this.ItemType,
|
||||
DupeType = this.DupeType,
|
||||
|
||||
Machine = this.Machine.Clone() as Machine,
|
||||
Source = this.Source.Clone() as Source,
|
||||
Machine = this.Machine?.Clone() as Machine,
|
||||
Source = this.Source?.Clone() as Source,
|
||||
Remove = this.Remove,
|
||||
|
||||
DeviceType = this.DeviceType,
|
||||
Tag = this.Tag,
|
||||
FixedImage = this.FixedImage,
|
||||
Mandatory = this.Mandatory,
|
||||
Interface = this.Interface,
|
||||
Instances = this.Instances,
|
||||
Extensions = this.Extensions,
|
||||
_device = this._device?.Clone() as Models.Internal.Device ?? new Models.Internal.Device(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -113,43 +143,14 @@ namespace SabreTools.DatItems.Formats
|
||||
#region Comparision Methods
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Equals(DatItem other)
|
||||
public override bool Equals(DatItem? other)
|
||||
{
|
||||
// If we don't have a Device, return false
|
||||
if (ItemType != other.ItemType)
|
||||
// If we don't have a Adjuster, return false
|
||||
if (ItemType != other?.ItemType || other is not Device otherInternal)
|
||||
return false;
|
||||
|
||||
// Otherwise, treat it as a Device
|
||||
Device newOther = other as Device;
|
||||
|
||||
// If the Device information matches
|
||||
bool match = (DeviceType == newOther.DeviceType
|
||||
&& Tag == newOther.Tag
|
||||
&& FixedImage == newOther.FixedImage
|
||||
&& Mandatory == newOther.Mandatory
|
||||
&& Interface == newOther.Interface);
|
||||
if (!match)
|
||||
return match;
|
||||
|
||||
// If the instances match
|
||||
if (InstancesSpecified)
|
||||
{
|
||||
foreach (Instance instance in Instances)
|
||||
{
|
||||
match &= newOther.Instances.Contains(instance);
|
||||
}
|
||||
}
|
||||
|
||||
// If the extensions match
|
||||
if (ExtensionsSpecified)
|
||||
{
|
||||
foreach (Extension extension in Extensions)
|
||||
{
|
||||
match &= newOther.Extensions.Contains(extension);
|
||||
}
|
||||
}
|
||||
|
||||
return match;
|
||||
// Compare the internal models
|
||||
return _device.EqualTo(otherInternal._device);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -16,17 +16,27 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Name of the item
|
||||
/// </summary>
|
||||
[JsonProperty("name"), XmlElement("name")]
|
||||
public string Name { get; set; }
|
||||
public string? Name
|
||||
{
|
||||
get => _deviceRef.ReadString(Models.Internal.DeviceRef.NameKey);
|
||||
set => _deviceRef[Models.Internal.DeviceRef.NameKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Internal DeviceRef model
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
private Models.Internal.DeviceRef _deviceRef = new();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Accessors
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string GetName() => Name;
|
||||
public override string? GetName() => Name;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void SetName(string name) => Name = name;
|
||||
public override void SetName(string? name) => Name = name;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -53,11 +63,11 @@ namespace SabreTools.DatItems.Formats
|
||||
ItemType = this.ItemType,
|
||||
DupeType = this.DupeType,
|
||||
|
||||
Machine = this.Machine.Clone() as Machine,
|
||||
Source = this.Source.Clone() as Source,
|
||||
Machine = this.Machine?.Clone() as Machine,
|
||||
Source = this.Source?.Clone() as Source,
|
||||
Remove = this.Remove,
|
||||
|
||||
Name = this.Name,
|
||||
_deviceRef = this._deviceRef?.Clone() as Models.Internal.DeviceRef ?? new Models.Internal.DeviceRef(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -66,17 +76,14 @@ namespace SabreTools.DatItems.Formats
|
||||
#region Comparision Methods
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Equals(DatItem other)
|
||||
public override bool Equals(DatItem? other)
|
||||
{
|
||||
// If we don't have a device reference, return false
|
||||
if (ItemType != other.ItemType)
|
||||
// If we don't have a Adjuster, return false
|
||||
if (ItemType != other?.ItemType || other is not DeviceReference otherInternal)
|
||||
return false;
|
||||
|
||||
// Otherwise, treat it as a device reference
|
||||
DeviceReference newOther = other as DeviceReference;
|
||||
|
||||
// If the device reference information matches
|
||||
return (Name == newOther.Name);
|
||||
// Compare the internal models
|
||||
return _deviceRef.EqualTo(otherInternal._deviceRef);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
117
SabreTools.DatItems/Formats/DipLocation.cs
Normal file
117
SabreTools.DatItems/Formats/DipLocation.cs
Normal file
@@ -0,0 +1,117 @@
|
||||
using System.Xml.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
using SabreTools.Core;
|
||||
|
||||
namespace SabreTools.DatItems.Formats
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents one diplocation
|
||||
/// </summary>
|
||||
[JsonObject("diplocation"), XmlRoot("diplocation")]
|
||||
public class DipLocation : DatItem
|
||||
{
|
||||
#region Fields
|
||||
|
||||
/// <summary>
|
||||
/// Location name
|
||||
/// </summary>
|
||||
[JsonProperty("name"), XmlElement("name")]
|
||||
public string? Name
|
||||
{
|
||||
get => _dipLocation.ReadString(Models.Internal.DipLocation.NameKey);
|
||||
set => _dipLocation[Models.Internal.DipLocation.NameKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Location ID
|
||||
/// </summary>
|
||||
[JsonProperty("number", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("number")]
|
||||
public long? Number
|
||||
{
|
||||
get => _dipLocation.ReadLong(Models.Internal.DipLocation.NameKey);
|
||||
set => _dipLocation[Models.Internal.DipLocation.NameKey] = value;
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool NumberSpecified { get { return Number != null; } }
|
||||
|
||||
/// <summary>
|
||||
/// Determines if location is inverted or not
|
||||
/// </summary>
|
||||
[JsonProperty("inverted", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("inverted")]
|
||||
public bool? Inverted
|
||||
{
|
||||
get => _dipLocation.ReadBool(Models.Internal.DipLocation.InvertedKey);
|
||||
set => _dipLocation[Models.Internal.DipLocation.InvertedKey] = value;
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool InvertedSpecified { get { return Inverted != null; } }
|
||||
|
||||
/// <summary>
|
||||
/// Internal DipLocation model
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
private Models.Internal.DipLocation _dipLocation = new();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Accessors
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string? GetName() => Name;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void SetName(string? name) => Name = name;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Create a default, empty DipLocation object
|
||||
/// </summary>
|
||||
public DipLocation()
|
||||
{
|
||||
Name = string.Empty;
|
||||
ItemType = ItemType.DipLocation;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Cloning Methods
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override object Clone()
|
||||
{
|
||||
return new DipLocation()
|
||||
{
|
||||
ItemType = this.ItemType,
|
||||
DupeType = this.DupeType,
|
||||
|
||||
Machine = this.Machine?.Clone() as Machine,
|
||||
Source = this.Source?.Clone() as Source,
|
||||
Remove = this.Remove,
|
||||
|
||||
_dipLocation = this._dipLocation?.Clone() as Models.Internal.DipLocation ?? new Models.Internal.DipLocation(),
|
||||
};
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Comparision Methods
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Equals(DatItem? other)
|
||||
{
|
||||
// If we don't have a DipLocation, return false
|
||||
if (ItemType != other?.ItemType || other is not DipLocation otherInternal)
|
||||
return false;
|
||||
|
||||
// Compare the internal models
|
||||
return _dipLocation.EqualTo(otherInternal._dipLocation);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Xml.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
using SabreTools.Core;
|
||||
@@ -19,25 +20,41 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Name of the item
|
||||
/// </summary>
|
||||
[JsonProperty("name"), XmlElement("name")]
|
||||
public string Name { get; set; }
|
||||
public string? Name
|
||||
{
|
||||
get => _dipSwitch.ReadString(Models.Internal.DipSwitch.NameKey);
|
||||
set => _dipSwitch[Models.Internal.DipSwitch.NameKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tag associated with the dipswitch
|
||||
/// </summary>
|
||||
[JsonProperty("tag", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("tag")]
|
||||
public string Tag { get; set; }
|
||||
public string? Tag
|
||||
{
|
||||
get => _dipSwitch.ReadString(Models.Internal.DipSwitch.TagKey);
|
||||
set => _dipSwitch[Models.Internal.DipSwitch.TagKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Mask associated with the dipswitch
|
||||
/// </summary>
|
||||
[JsonProperty("mask", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("mask")]
|
||||
public string Mask { get; set; }
|
||||
public string? Mask
|
||||
{
|
||||
get => _dipSwitch.ReadString(Models.Internal.DipSwitch.MaskKey);
|
||||
set => _dipSwitch[Models.Internal.DipSwitch.MaskKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Conditions associated with the dipswitch
|
||||
/// </summary>
|
||||
[JsonProperty("conditions", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("conditions")]
|
||||
public List<Condition> Conditions { get; set; }
|
||||
public List<Condition>? Conditions
|
||||
{
|
||||
get => _dipSwitch.Read<Condition[]>(Models.Internal.DipSwitch.ConditionKey)?.ToList();
|
||||
set => _dipSwitch[Models.Internal.DipSwitch.ConditionKey] = value?.ToArray();
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool ConditionsSpecified { get { return Conditions != null && Conditions.Count > 0; } }
|
||||
@@ -46,7 +63,11 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Locations associated with the dipswitch
|
||||
/// </summary>
|
||||
[JsonProperty("locations", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("locations")]
|
||||
public List<Location> Locations { get; set; }
|
||||
public List<DipLocation>? Locations
|
||||
{
|
||||
get => _dipSwitch.Read<DipLocation[]>(Models.Internal.DipSwitch.DipLocationKey)?.ToList();
|
||||
set => _dipSwitch[Models.Internal.DipSwitch.DipLocationKey] = value?.ToArray();
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool LocationsSpecified { get { return Locations != null && Locations.Count > 0; } }
|
||||
@@ -55,7 +76,11 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Settings associated with the dipswitch
|
||||
/// </summary>
|
||||
[JsonProperty("values", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("values")]
|
||||
public List<Setting> Values { get; set; }
|
||||
public List<DipValue>? Values
|
||||
{
|
||||
get => _dipSwitch.Read<DipValue[]>(Models.Internal.DipSwitch.DipValueKey)?.ToList();
|
||||
set => _dipSwitch[Models.Internal.DipSwitch.DipValueKey] = value?.ToArray();
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool ValuesSpecified { get { return Values != null && Values.Count > 0; } }
|
||||
@@ -67,8 +92,9 @@ namespace SabreTools.DatItems.Formats
|
||||
/// <summary>
|
||||
/// Original hardware part associated with the item
|
||||
/// </summary>
|
||||
/// <remarks>This is inverted from the internal model</remarks>
|
||||
[JsonProperty("part", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("part")]
|
||||
public Part Part { get; set; } = null;
|
||||
public Part? Part { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public bool PartSpecified
|
||||
@@ -83,15 +109,21 @@ namespace SabreTools.DatItems.Formats
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Internal DipSwitch model
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
private Models.Internal.DipSwitch _dipSwitch = new();
|
||||
|
||||
#endregion // Fields
|
||||
|
||||
#region Accessors
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string GetName() => Name;
|
||||
public override string? GetName() => Name;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void SetName(string name) => Name = name;
|
||||
public override void SetName(string? name) => Name = name;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -118,16 +150,11 @@ namespace SabreTools.DatItems.Formats
|
||||
ItemType = this.ItemType,
|
||||
DupeType = this.DupeType,
|
||||
|
||||
Machine = this.Machine.Clone() as Machine,
|
||||
Source = this.Source.Clone() as Source,
|
||||
Machine = this.Machine?.Clone() as Machine,
|
||||
Source = this.Source?.Clone() as Source,
|
||||
Remove = this.Remove,
|
||||
|
||||
Name = this.Name,
|
||||
Tag = this.Tag,
|
||||
Mask = this.Mask,
|
||||
Conditions = this.Conditions,
|
||||
Locations = this.Locations,
|
||||
Values = this.Values,
|
||||
_dipSwitch = this._dipSwitch?.Clone() as Models.Internal.DipSwitch ?? new Models.Internal.DipSwitch(),
|
||||
|
||||
Part = this.Part,
|
||||
};
|
||||
@@ -138,54 +165,14 @@ namespace SabreTools.DatItems.Formats
|
||||
#region Comparision Methods
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Equals(DatItem other)
|
||||
public override bool Equals(DatItem? other)
|
||||
{
|
||||
// If we don't have a DipSwitch, return false
|
||||
if (ItemType != other.ItemType)
|
||||
if (ItemType != other?.ItemType || other is not DipSwitch otherInternal)
|
||||
return false;
|
||||
|
||||
// Otherwise, treat it as a DipSwitch
|
||||
DipSwitch newOther = other as DipSwitch;
|
||||
|
||||
// If the DipSwitch information matches
|
||||
bool match = (Name == newOther.Name
|
||||
&& Tag == newOther.Tag
|
||||
&& Mask == newOther.Mask);
|
||||
if (!match)
|
||||
return match;
|
||||
|
||||
// If the part matches
|
||||
if (PartSpecified)
|
||||
match &= (Part == newOther.Part);
|
||||
|
||||
// If the conditions match
|
||||
if (ConditionsSpecified)
|
||||
{
|
||||
foreach (Condition condition in Conditions)
|
||||
{
|
||||
match &= newOther.Conditions.Contains(condition);
|
||||
}
|
||||
}
|
||||
|
||||
// If the locations match
|
||||
if (LocationsSpecified)
|
||||
{
|
||||
foreach (Location location in Locations)
|
||||
{
|
||||
match &= newOther.Locations.Contains(location);
|
||||
}
|
||||
}
|
||||
|
||||
// If the values match
|
||||
if (ValuesSpecified)
|
||||
{
|
||||
foreach (Setting value in Values)
|
||||
{
|
||||
match &= newOther.Values.Contains(value);
|
||||
}
|
||||
}
|
||||
|
||||
return match;
|
||||
// Compare the internal models
|
||||
return _dipSwitch.EqualTo(otherInternal._dipSwitch);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
129
SabreTools.DatItems/Formats/DipValue.cs
Normal file
129
SabreTools.DatItems/Formats/DipValue.cs
Normal file
@@ -0,0 +1,129 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Xml.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
using SabreTools.Core;
|
||||
|
||||
namespace SabreTools.DatItems.Formats
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents one ListXML dipvalue
|
||||
/// </summary>
|
||||
[JsonObject("dipvalue"), XmlRoot("dipvalue")]
|
||||
public class DipValue : DatItem
|
||||
{
|
||||
#region Fields
|
||||
|
||||
/// <summary>
|
||||
/// Setting name
|
||||
/// </summary>
|
||||
[JsonProperty("name"), XmlElement("name")]
|
||||
public string? Name
|
||||
{
|
||||
get => _dipValue.ReadString(Models.Internal.DipValue.NameKey);
|
||||
set => _dipValue[Models.Internal.DipValue.NameKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Setting value
|
||||
/// </summary>
|
||||
[JsonProperty("value", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("value")]
|
||||
public string? Value
|
||||
{
|
||||
get => _dipValue.ReadString(Models.Internal.DipValue.ValueKey);
|
||||
set => _dipValue[Models.Internal.DipValue.ValueKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines if the setting is default or not
|
||||
/// </summary>
|
||||
[JsonProperty("default", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("default")]
|
||||
public bool? Default
|
||||
{
|
||||
get => _dipValue.ReadBool(Models.Internal.DipValue.DefaultKey);
|
||||
set => _dipValue[Models.Internal.DipValue.DefaultKey] = value;
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool DefaultSpecified { get { return Default != null; } }
|
||||
|
||||
/// <summary>
|
||||
/// List of conditions on the setting
|
||||
/// </summary>
|
||||
[JsonProperty("conditions", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("conditions")]
|
||||
public List<Condition>? Conditions
|
||||
{
|
||||
get => _dipValue.Read<Condition[]>(Models.Internal.DipValue.ConditionKey)?.ToList();
|
||||
set => _dipValue[Models.Internal.DipValue.ConditionKey] = value?.ToArray();
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool ConditionsSpecified { get { return Conditions != null && Conditions.Count > 0; } }
|
||||
|
||||
/// <summary>
|
||||
/// Internal DipValue model
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
private Models.Internal.DipValue _dipValue = new();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Accessors
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string? GetName() => Name;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void SetName(string? name) => Name = name;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Create a default, empty DipValue object
|
||||
/// </summary>
|
||||
public DipValue()
|
||||
{
|
||||
Name = string.Empty;
|
||||
ItemType = ItemType.DipValue;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Cloning Methods
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override object Clone()
|
||||
{
|
||||
return new DipValue()
|
||||
{
|
||||
ItemType = this.ItemType,
|
||||
DupeType = this.DupeType,
|
||||
|
||||
Machine = this.Machine?.Clone() as Machine,
|
||||
Source = this.Source?.Clone() as Source,
|
||||
Remove = this.Remove,
|
||||
|
||||
_dipValue = this._dipValue?.Clone() as Models.Internal.DipValue ?? new Models.Internal.DipValue(),
|
||||
};
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Comparision Methods
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Equals(DatItem? other)
|
||||
{
|
||||
// If we don't have a DipValue, return false
|
||||
if (ItemType != other?.ItemType || other is not DipValue otherInternal)
|
||||
return false;
|
||||
|
||||
// Compare the internal models
|
||||
return _dipValue.EqualTo(otherInternal._dipValue);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -13,13 +13,6 @@ namespace SabreTools.DatItems.Formats
|
||||
[JsonObject("disk"), XmlRoot("disk")]
|
||||
public class Disk : DatItem
|
||||
{
|
||||
#region Private instance variables
|
||||
|
||||
private byte[] _md5; // 16 bytes
|
||||
private byte[] _sha1; // 20 bytes
|
||||
|
||||
#endregion
|
||||
|
||||
#region Fields
|
||||
|
||||
#region Common
|
||||
@@ -28,51 +21,71 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Name of the item
|
||||
/// </summary>
|
||||
[JsonProperty("name"), XmlElement("name")]
|
||||
public string Name { get; set; }
|
||||
public string? Name
|
||||
{
|
||||
get => _disk.ReadString(Models.Internal.Disk.NameKey);
|
||||
set => _disk[Models.Internal.Disk.NameKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Data MD5 hash
|
||||
/// </summary>
|
||||
[JsonProperty("md5", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("md5")]
|
||||
public string MD5
|
||||
public string? MD5
|
||||
{
|
||||
get { return _md5.IsNullOrEmpty() ? null : Utilities.ByteArrayToString(_md5); }
|
||||
set { _md5 = Utilities.StringToByteArray(CleanMD5(value)); }
|
||||
get => _disk.ReadString(Models.Internal.Disk.MD5Key);
|
||||
set => _disk[Models.Internal.Disk.MD5Key] = TextHelper.NormalizeMD5(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Data SHA-1 hash
|
||||
/// </summary>
|
||||
[JsonProperty("sha1", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("sha1")]
|
||||
public string SHA1
|
||||
public string? SHA1
|
||||
{
|
||||
get { return _sha1.IsNullOrEmpty() ? null : Utilities.ByteArrayToString(_sha1); }
|
||||
set { _sha1 = Utilities.StringToByteArray(CleanSHA1(value)); }
|
||||
get => _disk.ReadString(Models.Internal.Disk.SHA1Key);
|
||||
set => _disk[Models.Internal.Disk.SHA1Key] = TextHelper.NormalizeSHA1(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disk name to merge from parent
|
||||
/// </summary>
|
||||
[JsonProperty("merge", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("merge")]
|
||||
public string MergeTag { get; set; }
|
||||
public string? MergeTag
|
||||
{
|
||||
get => _disk.ReadString(Models.Internal.Disk.MergeKey);
|
||||
set => _disk[Models.Internal.Disk.MergeKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disk region
|
||||
/// </summary>
|
||||
[JsonProperty("region", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("region")]
|
||||
public string Region { get; set; }
|
||||
public string? Region
|
||||
{
|
||||
get => _disk.ReadString(Models.Internal.Disk.RegionKey);
|
||||
set => _disk[Models.Internal.Disk.RegionKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disk index
|
||||
/// </summary>
|
||||
[JsonProperty("index", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("index")]
|
||||
public string Index { get; set; }
|
||||
public string? Index
|
||||
{
|
||||
get => _disk.ReadString(Models.Internal.Disk.IndexKey);
|
||||
set => _disk[Models.Internal.Disk.IndexKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disk writable flag
|
||||
/// </summary>
|
||||
[JsonProperty("writable", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("writable")]
|
||||
public bool? Writable { get; set; } = null;
|
||||
public bool? Writable
|
||||
{
|
||||
get => _disk.ReadBool(Models.Internal.Disk.WritableKey);
|
||||
set => _disk[Models.Internal.Disk.WritableKey] = value;
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool WritableSpecified { get { return Writable != null; } }
|
||||
@@ -82,7 +95,11 @@ namespace SabreTools.DatItems.Formats
|
||||
/// </summary>
|
||||
[JsonProperty("status", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("status")]
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
public ItemStatus ItemStatus { get; set; }
|
||||
public ItemStatus ItemStatus
|
||||
{
|
||||
get => _disk.ReadString(Models.Internal.Disk.StatusKey).AsItemStatus();
|
||||
set => _disk[Models.Internal.Disk.StatusKey] = value.FromItemStatus(yesno: false);
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool ItemStatusSpecified { get { return ItemStatus != ItemStatus.NULL; } }
|
||||
@@ -91,7 +108,11 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Determine if the disk is optional in the set
|
||||
/// </summary>
|
||||
[JsonProperty("optional", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("optional")]
|
||||
public bool? Optional { get; set; } = null;
|
||||
public bool? Optional
|
||||
{
|
||||
get => _disk.ReadBool(Models.Internal.Disk.OptionalKey);
|
||||
set => _disk[Models.Internal.Disk.OptionalKey] = value;
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool OptionalSpecified { get { return Optional != null; } }
|
||||
@@ -103,8 +124,9 @@ namespace SabreTools.DatItems.Formats
|
||||
/// <summary>
|
||||
/// Disk area information
|
||||
/// </summary>
|
||||
/// <remarks>This is inverted from the internal model</remarks>
|
||||
[JsonProperty("diskarea", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("diskarea")]
|
||||
public DiskArea DiskArea { get; set; } = null;
|
||||
public DiskArea? DiskArea { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public bool DiskAreaSpecified
|
||||
@@ -119,8 +141,9 @@ namespace SabreTools.DatItems.Formats
|
||||
/// <summary>
|
||||
/// Original hardware part associated with the item
|
||||
/// </summary>
|
||||
/// <remarks>This is inverted from the internal model</remarks>
|
||||
[JsonProperty("part", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("part")]
|
||||
public Part Part { get; set; } = null;
|
||||
public Part? Part { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public bool PartSpecified
|
||||
@@ -135,15 +158,21 @@ namespace SabreTools.DatItems.Formats
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Internal Disk model
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
private Models.Internal.Disk _disk = new();
|
||||
|
||||
#endregion // Fields
|
||||
|
||||
#region Accessors
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string GetName() => Name;
|
||||
public override string? GetName() => Name;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void SetName(string name) => Name = name;
|
||||
public override void SetName(string? name) => Name = name;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -167,8 +196,8 @@ namespace SabreTools.DatItems.Formats
|
||||
public Disk(BaseFile baseFile)
|
||||
{
|
||||
Name = baseFile.Filename;
|
||||
_md5 = baseFile.MD5;
|
||||
_sha1 = baseFile.SHA1;
|
||||
MD5 = Utilities.ByteArrayToString(baseFile.MD5);
|
||||
SHA1 = Utilities.ByteArrayToString(baseFile.SHA1);
|
||||
|
||||
ItemType = ItemType.Disk;
|
||||
DupeType = 0x00;
|
||||
@@ -188,18 +217,11 @@ namespace SabreTools.DatItems.Formats
|
||||
ItemType = this.ItemType,
|
||||
DupeType = this.DupeType,
|
||||
|
||||
Machine = this.Machine.Clone() as Machine,
|
||||
Source = this.Source.Clone() as Source,
|
||||
Machine = this.Machine?.Clone() as Machine,
|
||||
Source = this.Source?.Clone() as Source,
|
||||
Remove = this.Remove,
|
||||
|
||||
_md5 = this._md5,
|
||||
_sha1 = this._sha1,
|
||||
MergeTag = this.MergeTag,
|
||||
Region = this.Region,
|
||||
Index = this.Index,
|
||||
Writable = this.Writable,
|
||||
ItemStatus = this.ItemStatus,
|
||||
Optional = this.Optional,
|
||||
_disk = this._disk?.Clone() as Models.Internal.Disk ?? new Models.Internal.Disk(),
|
||||
|
||||
DiskArea = this.DiskArea,
|
||||
Part = this.Part,
|
||||
@@ -215,8 +237,8 @@ namespace SabreTools.DatItems.Formats
|
||||
{
|
||||
Filename = this.Name,
|
||||
Parent = this.Machine?.Name,
|
||||
MD5 = this._md5,
|
||||
SHA1 = this._sha1,
|
||||
MD5 = Utilities.StringToByteArray(this.MD5),
|
||||
SHA1 = Utilities.StringToByteArray(this.SHA1),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -232,8 +254,8 @@ namespace SabreTools.DatItems.Formats
|
||||
ItemType = ItemType.Rom,
|
||||
DupeType = this.DupeType,
|
||||
|
||||
Machine = this.Machine.Clone() as Machine,
|
||||
Source = this.Source.Clone() as Source,
|
||||
Machine = this.Machine?.Clone() as Machine,
|
||||
Source = this.Source?.Clone() as Source,
|
||||
Remove = this.Remove,
|
||||
|
||||
MergeTag = this.MergeTag,
|
||||
@@ -244,7 +266,7 @@ namespace SabreTools.DatItems.Formats
|
||||
MD5 = this.MD5,
|
||||
SHA1 = this.SHA1,
|
||||
|
||||
DataArea = new DataArea { Name = this.DiskArea.Name },
|
||||
DataArea = new DataArea { Name = this.DiskArea?.Name },
|
||||
Part = this.Part,
|
||||
};
|
||||
|
||||
@@ -256,32 +278,14 @@ namespace SabreTools.DatItems.Formats
|
||||
#region Comparision Methods
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Equals(DatItem other)
|
||||
public override bool Equals(DatItem? other)
|
||||
{
|
||||
bool dupefound = false;
|
||||
// If we don't have a Disk, return false
|
||||
if (ItemType != other?.ItemType || other is not Disk otherInternal)
|
||||
return false;
|
||||
|
||||
// If we don't have a rom, return false
|
||||
if (ItemType != other.ItemType)
|
||||
return dupefound;
|
||||
|
||||
// Otherwise, treat it as a Disk
|
||||
Disk newOther = other as Disk;
|
||||
|
||||
// If all hashes are empty but they're both nodump and the names match, then they're dupes
|
||||
if ((ItemStatus == ItemStatus.Nodump && newOther.ItemStatus == ItemStatus.Nodump)
|
||||
&& Name == newOther.Name
|
||||
&& !HasHashes() && !newOther.HasHashes())
|
||||
{
|
||||
dupefound = true;
|
||||
}
|
||||
|
||||
// Otherwise if we get a partial match
|
||||
else if (HashMatch(newOther))
|
||||
{
|
||||
dupefound = true;
|
||||
}
|
||||
|
||||
return dupefound;
|
||||
// Compare the internal models
|
||||
return _disk.EqualTo(otherInternal._disk);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -290,11 +294,11 @@ namespace SabreTools.DatItems.Formats
|
||||
/// <param name="other">Disk to fill information from</param>
|
||||
public void FillMissingInformation(Disk other)
|
||||
{
|
||||
if (_md5.IsNullOrEmpty() && !other._md5.IsNullOrEmpty())
|
||||
_md5 = other._md5;
|
||||
if (string.IsNullOrWhiteSpace(MD5) && !string.IsNullOrWhiteSpace(other.MD5))
|
||||
MD5 = other.MD5;
|
||||
|
||||
if (_sha1.IsNullOrEmpty() && !other._sha1.IsNullOrEmpty())
|
||||
_sha1 = other._sha1;
|
||||
if (string.IsNullOrWhiteSpace(SHA1) && !string.IsNullOrWhiteSpace(other.SHA1))
|
||||
SHA1 = other.SHA1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -303,55 +307,14 @@ namespace SabreTools.DatItems.Formats
|
||||
/// <returns>String representing the suffix</returns>
|
||||
public string GetDuplicateSuffix()
|
||||
{
|
||||
if (!_md5.IsNullOrEmpty())
|
||||
if (!string.IsNullOrWhiteSpace(MD5))
|
||||
return $"_{MD5}";
|
||||
else if (!_sha1.IsNullOrEmpty())
|
||||
else if (!string.IsNullOrWhiteSpace(SHA1))
|
||||
return $"_{SHA1}";
|
||||
else
|
||||
return "_1";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns if there are no, non-empty hashes in common with another Disk
|
||||
/// </summary>
|
||||
/// <param name="other">Disk to compare against</param>
|
||||
/// <returns>True if at least one hash is not mutually exclusive, false otherwise</returns>
|
||||
private bool HasCommonHash(Disk other)
|
||||
{
|
||||
return !(_md5.IsNullOrEmpty() ^ other._md5.IsNullOrEmpty())
|
||||
|| !(_sha1.IsNullOrEmpty() ^ other._sha1.IsNullOrEmpty());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns if the Disk contains any hashes
|
||||
/// </summary>
|
||||
/// <returns>True if any hash exists, false otherwise</returns>
|
||||
private bool HasHashes()
|
||||
{
|
||||
return !_md5.IsNullOrEmpty()
|
||||
|| !_sha1.IsNullOrEmpty();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns if any hashes are common with another Disk
|
||||
/// </summary>
|
||||
/// <param name="other">Disk to compare against</param>
|
||||
/// <returns>True if any hashes are in common, false otherwise</returns>
|
||||
private bool HashMatch(Disk other)
|
||||
{
|
||||
// If either have no hashes, we return false, otherwise this would be a false positive
|
||||
if (!HasHashes() || !other.HasHashes())
|
||||
return false;
|
||||
|
||||
// If neither have hashes in common, we return false, otherwise this would be a false positive
|
||||
if (!HasCommonHash(other))
|
||||
return false;
|
||||
|
||||
// Return if all hashes match according to merge rules
|
||||
return ConditionalHashEquals(_md5, other._md5)
|
||||
&& ConditionalHashEquals(_sha1, other._sha1);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Sorting and Merging
|
||||
@@ -360,7 +323,7 @@ namespace SabreTools.DatItems.Formats
|
||||
public override string GetKey(ItemKey bucketedBy, bool lower = true, bool norename = true)
|
||||
{
|
||||
// Set the output key as the default blank string
|
||||
string key;
|
||||
string? key;
|
||||
|
||||
// Now determine what the key should be based on the bucketedBy value
|
||||
switch (bucketedBy)
|
||||
|
||||
@@ -17,17 +17,27 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Name of the item
|
||||
/// </summary>
|
||||
[JsonProperty("name", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("name")]
|
||||
public string Name { get; set; }
|
||||
public string? Name
|
||||
{
|
||||
get => _diskArea.ReadString(Models.Internal.DiskArea.NameKey);
|
||||
set => _diskArea[Models.Internal.DiskArea.NameKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Internal DiskArea model
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
private Models.Internal.DiskArea _diskArea = new();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Accessors
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string GetName() => Name;
|
||||
public override string? GetName() => Name;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void SetName(string name) => Name = name;
|
||||
public override void SetName(string? name) => Name = name;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -54,11 +64,11 @@ namespace SabreTools.DatItems.Formats
|
||||
ItemType = this.ItemType,
|
||||
DupeType = this.DupeType,
|
||||
|
||||
Machine = this.Machine.Clone() as Machine,
|
||||
Source = this.Source.Clone() as Source,
|
||||
Machine = this.Machine?.Clone() as Machine,
|
||||
Source = this.Source?.Clone() as Source,
|
||||
Remove = this.Remove,
|
||||
|
||||
Name = this.Name,
|
||||
_diskArea = this._diskArea?.Clone() as Models.Internal.DiskArea ?? new Models.Internal.DiskArea(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -67,17 +77,14 @@ namespace SabreTools.DatItems.Formats
|
||||
#region Comparision Methods
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Equals(DatItem other)
|
||||
public override bool Equals(DatItem? other)
|
||||
{
|
||||
// If we don't have a DiskArea, return false
|
||||
if (ItemType != other.ItemType)
|
||||
if (ItemType != other?.ItemType || other is not DiskArea otherInternal)
|
||||
return false;
|
||||
|
||||
// Otherwise, treat it as a DiskArea
|
||||
DiskArea newOther = other as DiskArea;
|
||||
|
||||
// If the DiskArea information matches
|
||||
return (Name == newOther.Name);
|
||||
// Compare the internal models
|
||||
return _diskArea.EqualTo(otherInternal._diskArea);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using SabreTools.Core;
|
||||
using SabreTools.Core.Tools;
|
||||
|
||||
namespace SabreTools.DatItems.Formats
|
||||
{
|
||||
@@ -17,14 +18,22 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Display tag
|
||||
/// </summary>
|
||||
[JsonProperty("tag", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("tag")]
|
||||
public string Tag { get; set; }
|
||||
public string? Tag
|
||||
{
|
||||
get => _display.ReadString(Models.Internal.Display.TagKey);
|
||||
set => _display[Models.Internal.Display.TagKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Display type
|
||||
/// </summary>
|
||||
[JsonProperty("type", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("type")]
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
public DisplayType DisplayType { get; set; }
|
||||
public DisplayType DisplayType
|
||||
{
|
||||
get => _display.ReadString(Models.Internal.Display.DisplayTypeKey).AsDisplayType();
|
||||
set => _display[Models.Internal.Display.DisplayTypeKey] = value.FromDisplayType();
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool DisplayTypeSpecified { get { return DisplayType != DisplayType.NULL; } }
|
||||
@@ -33,7 +42,11 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Display rotation
|
||||
/// </summary>
|
||||
[JsonProperty("rotate", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("rotate")]
|
||||
public long? Rotate { get; set; }
|
||||
public long? Rotate
|
||||
{
|
||||
get => _display.ReadLong(Models.Internal.Display.RotateKey);
|
||||
set => _display[Models.Internal.Display.RotateKey] = value;
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool RotateSpecified { get { return Rotate != null; } }
|
||||
@@ -42,7 +55,11 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Determines if display is flipped in the X-coordinates
|
||||
/// </summary>
|
||||
[JsonProperty("flipx", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("flipx")]
|
||||
public bool? FlipX { get; set; }
|
||||
public bool? FlipX
|
||||
{
|
||||
get => _display.ReadBool(Models.Internal.Display.FlipXKey);
|
||||
set => _display[Models.Internal.Display.FlipXKey] = value;
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool FlipXSpecified { get { return FlipX != null; } }
|
||||
@@ -51,7 +68,11 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Display width
|
||||
/// </summary>
|
||||
[JsonProperty("width", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("width")]
|
||||
public long? Width { get; set; }
|
||||
public long? Width
|
||||
{
|
||||
get => _display.ReadLong(Models.Internal.Display.WidthKey);
|
||||
set => _display[Models.Internal.Display.WidthKey] = value;
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool WidthSpecified { get { return Width != null; } }
|
||||
@@ -60,7 +81,11 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Display height
|
||||
/// </summary>
|
||||
[JsonProperty("height", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("height")]
|
||||
public long? Height { get; set; }
|
||||
public long? Height
|
||||
{
|
||||
get => _display.ReadLong(Models.Internal.Display.HeightKey);
|
||||
set => _display[Models.Internal.Display.HeightKey] = value;
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool HeightSpecified { get { return Height != null; } }
|
||||
@@ -69,7 +94,11 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Refresh rate
|
||||
/// </summary>
|
||||
[JsonProperty("refresh", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("refresh")]
|
||||
public double? Refresh { get; set; }
|
||||
public double? Refresh
|
||||
{
|
||||
get => _display.ReadDouble(Models.Internal.Display.RefreshKey);
|
||||
set => _display[Models.Internal.Display.RefreshKey] = value;
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool RefreshSpecified { get { return Refresh != null; } }
|
||||
@@ -78,7 +107,11 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Pixel clock timer
|
||||
/// </summary>
|
||||
[JsonProperty("pixclock", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("pixclock")]
|
||||
public long? PixClock { get; set; }
|
||||
public long? PixClock
|
||||
{
|
||||
get => _display.ReadLong(Models.Internal.Display.PixClockKey);
|
||||
set => _display[Models.Internal.Display.PixClockKey] = value;
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool PixClockSpecified { get { return PixClock != null; } }
|
||||
@@ -87,7 +120,11 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Total horizontal lines
|
||||
/// </summary>
|
||||
[JsonProperty("htotal", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("htotal")]
|
||||
public long? HTotal { get; set; }
|
||||
public long? HTotal
|
||||
{
|
||||
get => _display.ReadLong(Models.Internal.Display.HTotalKey);
|
||||
set => _display[Models.Internal.Display.HTotalKey] = value;
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool HTotalSpecified { get { return HTotal != null; } }
|
||||
@@ -96,7 +133,11 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Horizontal blank end
|
||||
/// </summary>
|
||||
[JsonProperty("hbend", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("hbend")]
|
||||
public long? HBEnd { get; set; }
|
||||
public long? HBEnd
|
||||
{
|
||||
get => _display.ReadLong(Models.Internal.Display.HBEndKey);
|
||||
set => _display[Models.Internal.Display.HBEndKey] = value;
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool HBEndSpecified { get { return HBEnd != null; } }
|
||||
@@ -105,7 +146,11 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Horizontal blank start
|
||||
/// </summary>
|
||||
[JsonProperty("hbstart", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("hbstart")]
|
||||
public long? HBStart { get; set; }
|
||||
public long? HBStart
|
||||
{
|
||||
get => _display.ReadLong(Models.Internal.Display.HBStartKey);
|
||||
set => _display[Models.Internal.Display.HBStartKey] = value;
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool HBStartSpecified { get { return HBStart != null; } }
|
||||
@@ -114,7 +159,11 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Total vertical lines
|
||||
/// </summary>
|
||||
[JsonProperty("vtotal", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("vtotal")]
|
||||
public long? VTotal { get; set; }
|
||||
public long? VTotal
|
||||
{
|
||||
get => _display.ReadLong(Models.Internal.Display.VTotalKey);
|
||||
set => _display[Models.Internal.Display.VTotalKey] = value;
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool VTotalSpecified { get { return VTotal != null; } }
|
||||
@@ -123,7 +172,11 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Vertical blank end
|
||||
/// </summary>
|
||||
[JsonProperty("vbend", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("vbend")]
|
||||
public long? VBEnd { get; set; }
|
||||
public long? VBEnd
|
||||
{
|
||||
get => _display.ReadLong(Models.Internal.Display.VBEndKey);
|
||||
set => _display[Models.Internal.Display.VBEndKey] = value;
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool VBEndSpecified { get { return VBEnd != null; } }
|
||||
@@ -132,11 +185,21 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Vertical blank start
|
||||
/// </summary>
|
||||
[JsonProperty("vbstart", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("vbstart")]
|
||||
public long? VBStart { get; set; }
|
||||
public long? VBStart
|
||||
{
|
||||
get => _display.ReadLong(Models.Internal.Display.VBStartKey);
|
||||
set => _display[Models.Internal.Display.VBStartKey] = value;
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool VBStartSpecified { get { return VBStart != null; } }
|
||||
|
||||
/// <summary>
|
||||
/// Internal Display model
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
private Models.Internal.Display _display = new();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
@@ -161,24 +224,11 @@ namespace SabreTools.DatItems.Formats
|
||||
ItemType = this.ItemType,
|
||||
DupeType = this.DupeType,
|
||||
|
||||
Machine = this.Machine.Clone() as Machine,
|
||||
Source = this.Source.Clone() as Source,
|
||||
Machine = this.Machine?.Clone() as Machine,
|
||||
Source = this.Source?.Clone() as Source,
|
||||
Remove = this.Remove,
|
||||
|
||||
Tag = this.Tag,
|
||||
DisplayType = this.DisplayType,
|
||||
Rotate = this.Rotate,
|
||||
FlipX = this.FlipX,
|
||||
Width = this.Width,
|
||||
Height = this.Height,
|
||||
Refresh = this.Refresh,
|
||||
PixClock = this.PixClock,
|
||||
HTotal = this.HTotal,
|
||||
HBEnd = this.HBEnd,
|
||||
HBStart = this.HBStart,
|
||||
VTotal = this.VTotal,
|
||||
VBEnd = this.VBEnd,
|
||||
VBStart = this.VBStart,
|
||||
_display = this._display?.Clone() as Models.Internal.Display ?? new Models.Internal.Display(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -187,30 +237,14 @@ namespace SabreTools.DatItems.Formats
|
||||
#region Comparision Methods
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Equals(DatItem other)
|
||||
public override bool Equals(DatItem? other)
|
||||
{
|
||||
// If we don't have a Display, return false
|
||||
if (ItemType != other.ItemType)
|
||||
if (ItemType != other?.ItemType || other is not Display otherInternal)
|
||||
return false;
|
||||
|
||||
// Otherwise, treat it as a Display
|
||||
Display newOther = other as Display;
|
||||
|
||||
// If the Display information matches
|
||||
return (Tag == newOther.Tag
|
||||
&& DisplayType == newOther.DisplayType
|
||||
&& Rotate == newOther.Rotate
|
||||
&& FlipX == newOther.FlipX
|
||||
&& Width == newOther.Width
|
||||
&& Height == newOther.Height
|
||||
&& Refresh == newOther.Refresh
|
||||
&& PixClock == newOther.PixClock
|
||||
&& HTotal == newOther.HTotal
|
||||
&& HBEnd == newOther.HBEnd
|
||||
&& HBStart == newOther.HBStart
|
||||
&& VTotal == newOther.VTotal
|
||||
&& VBEnd == newOther.VBEnd
|
||||
&& VBStart == newOther.VBStart);
|
||||
// Compare the internal models
|
||||
return _display.EqualTo(otherInternal._display);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using SabreTools.Core;
|
||||
using SabreTools.Core.Tools;
|
||||
|
||||
namespace SabreTools.DatItems.Formats
|
||||
{
|
||||
@@ -21,7 +22,11 @@ namespace SabreTools.DatItems.Formats
|
||||
/// </summary>
|
||||
[JsonProperty("status", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("status")]
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
public SupportStatus Status { get; set; }
|
||||
public SupportStatus Status
|
||||
{
|
||||
get => _driver.ReadString(Models.Internal.Driver.StatusKey).AsSupportStatus();
|
||||
set => _driver[Models.Internal.Driver.StatusKey] = value.FromSupportStatus();
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool StatusSpecified { get { return Status != SupportStatus.NULL; } }
|
||||
@@ -31,7 +36,11 @@ namespace SabreTools.DatItems.Formats
|
||||
/// </summary>
|
||||
[JsonProperty("emulation", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("emulation")]
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
public SupportStatus Emulation { get; set; }
|
||||
public SupportStatus Emulation
|
||||
{
|
||||
get => _driver.ReadString(Models.Internal.Driver.EmulationKey).AsSupportStatus();
|
||||
set => _driver[Models.Internal.Driver.EmulationKey] = value.FromSupportStatus();
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool EmulationSpecified { get { return Emulation != SupportStatus.NULL; } }
|
||||
@@ -41,7 +50,11 @@ namespace SabreTools.DatItems.Formats
|
||||
/// </summary>
|
||||
[JsonProperty("cocktail", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("cocktail")]
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
public SupportStatus Cocktail { get; set; }
|
||||
public SupportStatus Cocktail
|
||||
{
|
||||
get => _driver.ReadString(Models.Internal.Driver.CocktailKey).AsSupportStatus();
|
||||
set => _driver[Models.Internal.Driver.CocktailKey] = value.FromSupportStatus();
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool CocktailSpecified { get { return Cocktail != SupportStatus.NULL; } }
|
||||
@@ -51,7 +64,11 @@ namespace SabreTools.DatItems.Formats
|
||||
/// </summary>
|
||||
[JsonProperty("savestate", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("savestate")]
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
public Supported SaveState { get; set; }
|
||||
public Supported SaveState
|
||||
{
|
||||
get => _driver.ReadString(Models.Internal.Driver.SaveStateKey).AsSupported();
|
||||
set => _driver[Models.Internal.Driver.SaveStateKey] = value.FromSupported(verbose: true);
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool SaveStateSpecified { get { return SaveState != Supported.NULL; } }
|
||||
@@ -60,7 +77,11 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Requires artwork
|
||||
/// </summary>
|
||||
[JsonProperty("requiresartwork", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("requiresartwork")]
|
||||
public bool? RequiresArtwork { get; set; }
|
||||
public bool? RequiresArtwork
|
||||
{
|
||||
get => _driver.ReadBool(Models.Internal.Driver.RequiresArtworkKey);
|
||||
set => _driver[Models.Internal.Driver.RequiresArtworkKey] = value;
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool RequiresArtworkSpecified { get { return RequiresArtwork != null; } }
|
||||
@@ -69,7 +90,11 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Unofficial
|
||||
/// </summary>
|
||||
[JsonProperty("unofficial", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("unofficial")]
|
||||
public bool? Unofficial { get; set; }
|
||||
public bool? Unofficial
|
||||
{
|
||||
get => _driver.ReadBool(Models.Internal.Driver.UnofficialKey);
|
||||
set => _driver[Models.Internal.Driver.UnofficialKey] = value;
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool UnofficialSpecified { get { return Unofficial != null; } }
|
||||
@@ -78,7 +103,11 @@ namespace SabreTools.DatItems.Formats
|
||||
/// No sound hardware
|
||||
/// </summary>
|
||||
[JsonProperty("nosoundhardware", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("nosoundhardware")]
|
||||
public bool? NoSoundHardware { get; set; }
|
||||
public bool? NoSoundHardware
|
||||
{
|
||||
get => _driver.ReadBool(Models.Internal.Driver.NoSoundHardwareKey);
|
||||
set => _driver[Models.Internal.Driver.NoSoundHardwareKey] = value;
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool NoSoundHardwareSpecified { get { return NoSoundHardware != null; } }
|
||||
@@ -87,11 +116,21 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Incomplete
|
||||
/// </summary>
|
||||
[JsonProperty("incomplete", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("incomplete")]
|
||||
public bool? Incomplete { get; set; }
|
||||
public bool? Incomplete
|
||||
{
|
||||
get => _driver.ReadBool(Models.Internal.Driver.IncompleteKey);
|
||||
set => _driver[Models.Internal.Driver.IncompleteKey] = value;
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool IncompleteSpecified { get { return Incomplete != null; } }
|
||||
|
||||
/// <summary>
|
||||
/// Internal Driver model
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
private Models.Internal.Driver _driver = new();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
@@ -116,18 +155,11 @@ namespace SabreTools.DatItems.Formats
|
||||
ItemType = this.ItemType,
|
||||
DupeType = this.DupeType,
|
||||
|
||||
Machine = this.Machine.Clone() as Machine,
|
||||
Source = this.Source.Clone() as Source,
|
||||
Machine = this.Machine?.Clone() as Machine,
|
||||
Source = this.Source?.Clone() as Source,
|
||||
Remove = this.Remove,
|
||||
|
||||
Status = this.Status,
|
||||
Emulation = this.Emulation,
|
||||
Cocktail = this.Cocktail,
|
||||
SaveState = this.SaveState,
|
||||
RequiresArtwork = this.RequiresArtwork,
|
||||
Unofficial = this.Unofficial,
|
||||
NoSoundHardware = this.NoSoundHardware,
|
||||
Incomplete = this.Incomplete,
|
||||
_driver = this._driver?.Clone() as Models.Internal.Driver ?? new Models.Internal.Driver(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -136,24 +168,14 @@ namespace SabreTools.DatItems.Formats
|
||||
#region Comparision Methods
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Equals(DatItem other)
|
||||
public override bool Equals(DatItem? other)
|
||||
{
|
||||
// If we don't have a Driver, return false
|
||||
if (ItemType != other.ItemType)
|
||||
if (ItemType != other?.ItemType || other is not Driver otherInternal)
|
||||
return false;
|
||||
|
||||
// Otherwise, treat it as a Driver
|
||||
Driver newOther = other as Driver;
|
||||
|
||||
// If the Feature information matches
|
||||
return (Status == newOther.Status
|
||||
&& Emulation == newOther.Emulation
|
||||
&& Cocktail == newOther.Cocktail
|
||||
&& SaveState == newOther.SaveState
|
||||
&& RequiresArtwork == newOther.RequiresArtwork
|
||||
&& Unofficial == newOther.Unofficial
|
||||
&& NoSoundHardware == newOther.NoSoundHardware
|
||||
&& Incomplete == newOther.Incomplete);
|
||||
// Compare the internal models
|
||||
return _driver.EqualTo(otherInternal._driver);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -16,17 +16,27 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Name of the item
|
||||
/// </summary>
|
||||
[JsonProperty("name"), XmlElement("name")]
|
||||
public string Name { get; set; }
|
||||
public string? Name
|
||||
{
|
||||
get => _extension.ReadString(Models.Internal.Extension.NameKey);
|
||||
set => _extension[Models.Internal.Extension.NameKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Internal Extension model
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
private Models.Internal.Extension _extension = new();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Accessors
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string GetName() => Name;
|
||||
public override string? GetName() => Name;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void SetName(string name) => Name = name;
|
||||
public override void SetName(string? name) => Name = name;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -53,11 +63,11 @@ namespace SabreTools.DatItems.Formats
|
||||
ItemType = this.ItemType,
|
||||
DupeType = this.DupeType,
|
||||
|
||||
Machine = this.Machine.Clone() as Machine,
|
||||
Source = this.Source.Clone() as Source,
|
||||
Machine = this.Machine?.Clone() as Machine,
|
||||
Source = this.Source?.Clone() as Source,
|
||||
Remove = this.Remove,
|
||||
|
||||
Name = this.Name,
|
||||
_extension = this._extension?.Clone() as Models.Internal.Extension ?? new Models.Internal.Extension(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -66,17 +76,14 @@ namespace SabreTools.DatItems.Formats
|
||||
#region Comparision Methods
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Equals(DatItem other)
|
||||
public override bool Equals(DatItem? other)
|
||||
{
|
||||
// If we don't have a Extension, return false
|
||||
if (ItemType != other.ItemType)
|
||||
// If we don't have a Adjuster, return false
|
||||
if (ItemType != other?.ItemType || other is not Extension otherInternal)
|
||||
return false;
|
||||
|
||||
// Otherwise, treat it as a Extension
|
||||
Extension newOther = other as Extension;
|
||||
|
||||
// If the Extension information matches
|
||||
return (Name == newOther.Name);
|
||||
// Compare the internal models
|
||||
return _extension.EqualTo(otherInternal._extension);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using SabreTools.Core;
|
||||
using SabreTools.Core.Tools;
|
||||
|
||||
namespace SabreTools.DatItems.Formats
|
||||
{
|
||||
@@ -18,7 +19,11 @@ namespace SabreTools.DatItems.Formats
|
||||
/// </summary>
|
||||
[JsonProperty("type", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("type")]
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
public FeatureType Type { get; set; }
|
||||
public FeatureType Type
|
||||
{
|
||||
get => _feature.ReadString(Models.Internal.Feature.FeatureTypeKey).AsFeatureType();
|
||||
set => _feature[Models.Internal.Feature.FeatureTypeKey] = value.FromFeatureType();
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool TypeSpecified { get { return Type != FeatureType.NULL; } }
|
||||
@@ -28,7 +33,11 @@ namespace SabreTools.DatItems.Formats
|
||||
/// </summary>
|
||||
[JsonProperty("status", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("status")]
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
public FeatureStatus Status { get; set; }
|
||||
public FeatureStatus Status
|
||||
{
|
||||
get => _feature.ReadString(Models.Internal.Feature.StatusKey).AsFeatureStatus();
|
||||
set => _feature[Models.Internal.Feature.StatusKey] = value.FromFeatureStatus();
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool StatusSpecified { get { return Status != FeatureStatus.NULL; } }
|
||||
@@ -38,11 +47,21 @@ namespace SabreTools.DatItems.Formats
|
||||
/// </summary>
|
||||
[JsonProperty("overall", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("overall")]
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
public FeatureStatus Overall { get; set; }
|
||||
public FeatureStatus Overall
|
||||
{
|
||||
get => _feature.ReadString(Models.Internal.Feature.OverallKey).AsFeatureStatus();
|
||||
set => _feature[Models.Internal.Feature.OverallKey] = value.FromFeatureStatus();
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool OverallSpecified { get { return Overall != FeatureStatus.NULL; } }
|
||||
|
||||
/// <summary>
|
||||
/// Internal Feature model
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
private Models.Internal.Feature _feature = new();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
@@ -67,13 +86,11 @@ namespace SabreTools.DatItems.Formats
|
||||
ItemType = this.ItemType,
|
||||
DupeType = this.DupeType,
|
||||
|
||||
Machine = this.Machine.Clone() as Machine,
|
||||
Source = this.Source.Clone() as Source,
|
||||
Machine = this.Machine?.Clone() as Machine,
|
||||
Source = this.Source?.Clone() as Source,
|
||||
Remove = this.Remove,
|
||||
|
||||
Type = this.Type,
|
||||
Status = this.Status,
|
||||
Overall = this.Overall,
|
||||
_feature = this._feature?.Clone() as Models.Internal.Feature ?? new Models.Internal.Feature(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -82,19 +99,14 @@ namespace SabreTools.DatItems.Formats
|
||||
#region Comparision Methods
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Equals(DatItem other)
|
||||
public override bool Equals(DatItem? other)
|
||||
{
|
||||
// If we don't have a Feature, return false
|
||||
if (ItemType != other.ItemType)
|
||||
if (ItemType != other?.ItemType || other is not Feature otherInternal)
|
||||
return false;
|
||||
|
||||
// Otherwise, treat it as a Feature
|
||||
Feature newOther = other as Feature;
|
||||
|
||||
// If the Feature information matches
|
||||
return (Type == newOther.Type
|
||||
&& Status == newOther.Status
|
||||
&& Overall == newOther.Overall);
|
||||
// Compare the internal models
|
||||
return _feature.EqualTo(otherInternal._feature);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -17,10 +17,10 @@ namespace SabreTools.DatItems.Formats
|
||||
{
|
||||
#region Private instance variables
|
||||
|
||||
private byte[] _crc; // 8 bytes
|
||||
private byte[] _md5; // 16 bytes
|
||||
private byte[] _sha1; // 20 bytes
|
||||
private byte[] _sha256; // 32 bytes
|
||||
private byte[]? _crc; // 8 bytes
|
||||
private byte[]? _md5; // 16 bytes
|
||||
private byte[]? _sha1; // 20 bytes
|
||||
private byte[]? _sha256; // 32 bytes
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -30,13 +30,13 @@ namespace SabreTools.DatItems.Formats
|
||||
/// ID value
|
||||
/// </summary>
|
||||
[JsonProperty("id", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("id")]
|
||||
public string Id { get; set; }
|
||||
public string? Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Extension value
|
||||
/// </summary>
|
||||
[JsonProperty("extension", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("extension")]
|
||||
public string Extension { get; set; }
|
||||
public string? Extension { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Byte size of the rom
|
||||
@@ -51,47 +51,47 @@ namespace SabreTools.DatItems.Formats
|
||||
/// File CRC32 hash
|
||||
/// </summary>
|
||||
[JsonProperty("crc", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("crc")]
|
||||
public string CRC
|
||||
public string? CRC
|
||||
{
|
||||
get { return _crc.IsNullOrEmpty() ? null : Utilities.ByteArrayToString(_crc); }
|
||||
set { _crc = (value == "null" ? Constants.CRCZeroBytes : Utilities.StringToByteArray(CleanCRC32(value))); }
|
||||
set { _crc = (value == "null" ? Constants.CRCZeroBytes : Utilities.StringToByteArray(TextHelper.NormalizeCRC32(value))); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// File MD5 hash
|
||||
/// </summary>
|
||||
[JsonProperty("md5", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("md5")]
|
||||
public string MD5
|
||||
public string? MD5
|
||||
{
|
||||
get { return _md5.IsNullOrEmpty() ? null : Utilities.ByteArrayToString(_md5); }
|
||||
set { _md5 = Utilities.StringToByteArray(CleanMD5(value)); }
|
||||
set { _md5 = Utilities.StringToByteArray(TextHelper.NormalizeMD5(value)); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// File SHA-1 hash
|
||||
/// </summary>
|
||||
[JsonProperty("sha1", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("sha1")]
|
||||
public string SHA1
|
||||
public string? SHA1
|
||||
{
|
||||
get { return _sha1.IsNullOrEmpty() ? null : Utilities.ByteArrayToString(_sha1); }
|
||||
set { _sha1 = Utilities.StringToByteArray(CleanSHA1(value)); }
|
||||
set { _sha1 = Utilities.StringToByteArray(TextHelper.NormalizeSHA1(value)); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// File SHA-256 hash
|
||||
/// </summary>
|
||||
[JsonProperty("sha256", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("sha256")]
|
||||
public string SHA256
|
||||
public string? SHA256
|
||||
{
|
||||
get { return _sha256.IsNullOrEmpty() ? null : Utilities.ByteArrayToString(_sha256); }
|
||||
set { _sha256 = Utilities.StringToByteArray(CleanSHA256(value)); }
|
||||
set { _sha256 = Utilities.StringToByteArray(TextHelper.NormalizeSHA256(value)); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Format value
|
||||
/// </summary>
|
||||
[JsonProperty("format", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("format")]
|
||||
public string Format { get; set; }
|
||||
public string? Format { get; set; }
|
||||
|
||||
#endregion // Fields
|
||||
|
||||
@@ -132,8 +132,8 @@ namespace SabreTools.DatItems.Formats
|
||||
ItemType = this.ItemType,
|
||||
DupeType = this.DupeType,
|
||||
|
||||
Machine = this.Machine.Clone() as Machine,
|
||||
Source = this.Source.Clone() as Source,
|
||||
Machine = this.Machine?.Clone() as Machine,
|
||||
Source = this.Source?.Clone() as Source,
|
||||
Remove = this.Remove,
|
||||
|
||||
Id = this.Id,
|
||||
@@ -174,8 +174,8 @@ namespace SabreTools.DatItems.Formats
|
||||
ItemType = ItemType.Rom,
|
||||
DupeType = this.DupeType,
|
||||
|
||||
Machine = this.Machine.Clone() as Machine,
|
||||
Source = this.Source.Clone() as Source,
|
||||
Machine = this.Machine?.Clone() as Machine,
|
||||
Source = this.Source?.Clone() as Source,
|
||||
Remove = this.Remove,
|
||||
|
||||
CRC = this.CRC,
|
||||
@@ -192,31 +192,31 @@ namespace SabreTools.DatItems.Formats
|
||||
#region Comparision Methods
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Equals(DatItem other)
|
||||
public override bool Equals(DatItem? other)
|
||||
{
|
||||
bool dupefound = false;
|
||||
|
||||
// If we don't have a file, return false
|
||||
if (ItemType != other.ItemType)
|
||||
if (ItemType != other?.ItemType)
|
||||
return dupefound;
|
||||
|
||||
// Otherwise, treat it as a File
|
||||
File newOther = other as File;
|
||||
File? newOther = other as File;
|
||||
|
||||
// If all hashes are empty, then they're dupes
|
||||
if (!HasHashes() && !newOther.HasHashes())
|
||||
if (!HasHashes() && !newOther!.HasHashes())
|
||||
{
|
||||
dupefound = true;
|
||||
}
|
||||
|
||||
// If we have a file that has no known size, rely on the hashes only
|
||||
else if (Size == null && HashMatch(newOther))
|
||||
else if (Size == null && HashMatch(newOther!))
|
||||
{
|
||||
dupefound = true;
|
||||
}
|
||||
|
||||
// Otherwise if we get a partial match
|
||||
else if (Size == newOther.Size && HashMatch(newOther))
|
||||
else if (Size == newOther!.Size && HashMatch(newOther))
|
||||
{
|
||||
dupefound = true;
|
||||
}
|
||||
@@ -331,7 +331,7 @@ namespace SabreTools.DatItems.Formats
|
||||
public override string GetKey(ItemKey bucketedBy, bool lower = true, bool norename = true)
|
||||
{
|
||||
// Set the output key as the default blank string
|
||||
string key;
|
||||
string? key;
|
||||
|
||||
// Now determine what the key should be based on the bucketedBy value
|
||||
switch (bucketedBy)
|
||||
|
||||
@@ -16,23 +16,37 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Name of the item
|
||||
/// </summary>
|
||||
[JsonProperty("name"), XmlElement("name")]
|
||||
public string Name { get; set; }
|
||||
public string? Name
|
||||
{
|
||||
get => _info.ReadString(Models.Internal.Info.NameKey);
|
||||
set => _info[Models.Internal.Info.NameKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Information value
|
||||
/// </summary>
|
||||
[JsonProperty("value"), XmlElement("value")]
|
||||
public string Value { get; set; }
|
||||
public string? Value
|
||||
{
|
||||
get => _info.ReadString(Models.Internal.Info.ValueKey);
|
||||
set => _info[Models.Internal.Info.ValueKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Internal Info model
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
private Models.Internal.Info _info = new();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Accessors
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string GetName() => Name;
|
||||
public override string? GetName() => Name;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void SetName(string name) => Name = name;
|
||||
public override void SetName(string? name) => Name = name;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -59,12 +73,11 @@ namespace SabreTools.DatItems.Formats
|
||||
ItemType = this.ItemType,
|
||||
DupeType = this.DupeType,
|
||||
|
||||
Machine = this.Machine.Clone() as Machine,
|
||||
Source = this.Source.Clone() as Source,
|
||||
Machine = this.Machine?.Clone() as Machine,
|
||||
Source = this.Source?.Clone() as Source,
|
||||
Remove = this.Remove,
|
||||
|
||||
Name = this.Name,
|
||||
Value = this.Value,
|
||||
_info = this._info?.Clone() as Models.Internal.Info ?? new Models.Internal.Info(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -73,18 +86,14 @@ namespace SabreTools.DatItems.Formats
|
||||
#region Comparision Methods
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Equals(DatItem other)
|
||||
public override bool Equals(DatItem? other)
|
||||
{
|
||||
// If we don't have a sample, return false
|
||||
if (ItemType != other.ItemType)
|
||||
// If we don't have a Info, return false
|
||||
if (ItemType != other?.ItemType || other is not Info otherInternal)
|
||||
return false;
|
||||
|
||||
// Otherwise, treat it as a Info
|
||||
Info newOther = other as Info;
|
||||
|
||||
// If the archive information matches
|
||||
return (Name == newOther.Name
|
||||
&& Value == newOther.Value);
|
||||
// Compare the internal models
|
||||
return _info.EqualTo(otherInternal._info);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Xml.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
using SabreTools.Core;
|
||||
@@ -17,7 +18,11 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Input service ID
|
||||
/// </summary>
|
||||
[JsonProperty("service", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("service")]
|
||||
public bool? Service { get; set; }
|
||||
public bool? Service
|
||||
{
|
||||
get => _input.ReadBool(Models.Internal.Input.ServiceKey);
|
||||
set => _input[Models.Internal.Input.ServiceKey] = value;
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool ServiceSpecified { get { return Service != null; } }
|
||||
@@ -26,7 +31,11 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Determins if this has a tilt sensor
|
||||
/// </summary>
|
||||
[JsonProperty("tilt", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("tilt")]
|
||||
public bool? Tilt { get; set; }
|
||||
public bool? Tilt
|
||||
{
|
||||
get => _input.ReadBool(Models.Internal.Input.TiltKey);
|
||||
set => _input[Models.Internal.Input.TiltKey] = value;
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool TiltSpecified { get { return Tilt != null; } }
|
||||
@@ -35,7 +44,11 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Number of players on the input
|
||||
/// </summary>
|
||||
[JsonProperty("players", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("players")]
|
||||
public long? Players { get; set; }
|
||||
public long? Players
|
||||
{
|
||||
get => _input.ReadLong(Models.Internal.Input.PlayersKey);
|
||||
set => _input[Models.Internal.Input.PlayersKey] = value;
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool PlayersSpecified { get { return Players != null; } }
|
||||
@@ -44,7 +57,11 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Number of coins required
|
||||
/// </summary>
|
||||
[JsonProperty("coins", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("coins")]
|
||||
public long? Coins { get; set; }
|
||||
public long? Coins
|
||||
{
|
||||
get => _input.ReadLong(Models.Internal.Input.CoinsKey);
|
||||
set => _input[Models.Internal.Input.CoinsKey] = value;
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool CoinsSpecified { get { return Coins != null; } }
|
||||
@@ -53,11 +70,21 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Set of controls for the input
|
||||
/// </summary>
|
||||
[JsonProperty("controls", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("controls")]
|
||||
public List<Control> Controls { get; set; }
|
||||
public List<Control>? Controls
|
||||
{
|
||||
get => _input.Read<Control[]>(Models.Internal.Input.ControlKey)?.ToList();
|
||||
set => _input[Models.Internal.Input.ControlKey] = value?.ToArray();
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool ControlsSpecified { get { return Controls != null && Controls.Count > 0; } }
|
||||
|
||||
/// <summary>
|
||||
/// Internal Input model
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
private Models.Internal.Input _input = new();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
@@ -82,15 +109,11 @@ namespace SabreTools.DatItems.Formats
|
||||
ItemType = this.ItemType,
|
||||
DupeType = this.DupeType,
|
||||
|
||||
Machine = this.Machine.Clone() as Machine,
|
||||
Source = this.Source.Clone() as Source,
|
||||
Machine = this.Machine?.Clone() as Machine,
|
||||
Source = this.Source?.Clone() as Source,
|
||||
Remove = this.Remove,
|
||||
|
||||
Service = this.Service,
|
||||
Tilt = this.Tilt,
|
||||
Players = this.Players,
|
||||
Coins = this.Coins,
|
||||
Controls = this.Controls,
|
||||
_input = this._input?.Clone() as Models.Internal.Input ?? new Models.Internal.Input(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -99,33 +122,14 @@ namespace SabreTools.DatItems.Formats
|
||||
#region Comparision Methods
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Equals(DatItem other)
|
||||
public override bool Equals(DatItem? other)
|
||||
{
|
||||
// If we don't have a Input, return false
|
||||
if (ItemType != other.ItemType)
|
||||
if (ItemType != other?.ItemType || other is not Input otherInternal)
|
||||
return false;
|
||||
|
||||
// Otherwise, treat it as a Input
|
||||
Input newOther = other as Input;
|
||||
|
||||
// If the Input information matches
|
||||
bool match = (Service == newOther.Service
|
||||
&& Tilt == newOther.Tilt
|
||||
&& Players == newOther.Players
|
||||
&& Coins == newOther.Coins);
|
||||
if (!match)
|
||||
return match;
|
||||
|
||||
// If the controls match
|
||||
if (ControlsSpecified)
|
||||
{
|
||||
foreach (Control control in Controls)
|
||||
{
|
||||
match &= newOther.Controls.Contains(control);
|
||||
}
|
||||
}
|
||||
|
||||
return match;
|
||||
// Compare the internal models
|
||||
return _input.EqualTo(otherInternal._input);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -16,23 +16,37 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Name of the item
|
||||
/// </summary>
|
||||
[JsonProperty("name"), XmlElement("name")]
|
||||
public string Name { get; set; }
|
||||
public string? Name
|
||||
{
|
||||
get => _instance.ReadString(Models.Internal.Instance.NameKey);
|
||||
set => _instance[Models.Internal.Instance.NameKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Short name for the instance
|
||||
/// </summary>
|
||||
[JsonProperty("briefname", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("briefname")]
|
||||
public string BriefName { get; set; }
|
||||
public string? BriefName
|
||||
{
|
||||
get => _instance.ReadString(Models.Internal.Instance.BriefNameKey);
|
||||
set => _instance[Models.Internal.Instance.BriefNameKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Internal Instance model
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
private Models.Internal.Instance _instance = new();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Accessors
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string GetName() => Name;
|
||||
public override string? GetName() => Name;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void SetName(string name) => Name = name;
|
||||
public override void SetName(string? name) => Name = name;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -59,12 +73,11 @@ namespace SabreTools.DatItems.Formats
|
||||
ItemType = this.ItemType,
|
||||
DupeType = this.DupeType,
|
||||
|
||||
Machine = this.Machine.Clone() as Machine,
|
||||
Source = this.Source.Clone() as Source,
|
||||
Machine = this.Machine?.Clone() as Machine,
|
||||
Source = this.Source?.Clone() as Source,
|
||||
Remove = this.Remove,
|
||||
|
||||
Name = this.Name,
|
||||
BriefName = this.BriefName,
|
||||
_instance = this._instance?.Clone() as Models.Internal.Instance ?? new Models.Internal.Instance(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -73,18 +86,14 @@ namespace SabreTools.DatItems.Formats
|
||||
#region Comparision Methods
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Equals(DatItem other)
|
||||
public override bool Equals(DatItem? other)
|
||||
{
|
||||
// If we don't have a Instance, return false
|
||||
if (ItemType != other.ItemType)
|
||||
if (ItemType != other?.ItemType || other is not Instance otherInternal)
|
||||
return false;
|
||||
|
||||
// Otherwise, treat it as a Instance
|
||||
Instance newOther = other as Instance;
|
||||
|
||||
// If the Instance information matches
|
||||
return (Name == newOther.Name
|
||||
&& BriefName == newOther.BriefName);
|
||||
// Compare the internal models
|
||||
return _instance.EqualTo(otherInternal._instance);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -1,106 +0,0 @@
|
||||
using System.Xml.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
using SabreTools.Core;
|
||||
|
||||
namespace SabreTools.DatItems.Formats
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents one conflocation or diplocation
|
||||
/// </summary>
|
||||
[JsonObject("location"), XmlRoot("location")]
|
||||
public class Location : DatItem
|
||||
{
|
||||
#region Fields
|
||||
|
||||
/// <summary>
|
||||
/// Location name
|
||||
/// </summary>
|
||||
[JsonProperty("name"), XmlElement("name")]
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Location ID
|
||||
/// </summary>
|
||||
[JsonProperty("number", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("number")]
|
||||
public long? Number { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public bool NumberSpecified { get { return Number != null; } }
|
||||
|
||||
/// <summary>
|
||||
/// Determines if location is inverted or not
|
||||
/// </summary>
|
||||
[JsonProperty("inverted", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("inverted")]
|
||||
public bool? Inverted { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public bool InvertedSpecified { get { return Inverted != null; } }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Accessors
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string GetName() => Name;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void SetName(string name) => Name = name;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Create a default, empty Location object
|
||||
/// </summary>
|
||||
public Location()
|
||||
{
|
||||
Name = string.Empty;
|
||||
ItemType = ItemType.Location;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Cloning Methods
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override object Clone()
|
||||
{
|
||||
return new Location()
|
||||
{
|
||||
ItemType = this.ItemType,
|
||||
DupeType = this.DupeType,
|
||||
|
||||
Machine = this.Machine.Clone() as Machine,
|
||||
Source = this.Source.Clone() as Source,
|
||||
Remove = this.Remove,
|
||||
|
||||
Name = this.Name,
|
||||
Number = this.Number,
|
||||
Inverted = this.Inverted,
|
||||
};
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Comparision Methods
|
||||
|
||||
/// <inheritdoc/>
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using System.Text;
|
||||
using System.Xml.Serialization;
|
||||
using System.Xml.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
using SabreTools.Core;
|
||||
using SabreTools.Core.Tools;
|
||||
@@ -13,72 +12,73 @@ namespace SabreTools.DatItems.Formats
|
||||
[JsonObject("media"), XmlRoot("media")]
|
||||
public class Media : DatItem
|
||||
{
|
||||
#region Private instance variables
|
||||
|
||||
private byte[] _md5; // 16 bytes
|
||||
private byte[] _sha1; // 20 bytes
|
||||
private byte[] _sha256; // 32 bytes
|
||||
private byte[] _spamsum; // variable bytes
|
||||
|
||||
#endregion
|
||||
|
||||
#region Fields
|
||||
|
||||
/// <summary>
|
||||
/// Name of the item
|
||||
/// </summary>
|
||||
[JsonProperty("name"), XmlElement("name")]
|
||||
public string Name { get; set; }
|
||||
public string? Name
|
||||
{
|
||||
get => _media.ReadString(Models.Internal.Media.NameKey);
|
||||
set => _media[Models.Internal.Media.NameKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Data MD5 hash
|
||||
/// </summary>
|
||||
[JsonProperty("md5", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("md5")]
|
||||
public string MD5
|
||||
public string? MD5
|
||||
{
|
||||
get { return _md5.IsNullOrEmpty() ? null : Utilities.ByteArrayToString(_md5); }
|
||||
set { _md5 = Utilities.StringToByteArray(CleanMD5(value)); }
|
||||
get => _media.ReadString(Models.Internal.Media.MD5Key);
|
||||
set => _media[Models.Internal.Media.MD5Key] = TextHelper.NormalizeMD5(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Data SHA-1 hash
|
||||
/// </summary>
|
||||
[JsonProperty("sha1", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("sha1")]
|
||||
public string SHA1
|
||||
public string? SHA1
|
||||
{
|
||||
get { return _sha1.IsNullOrEmpty() ? null : Utilities.ByteArrayToString(_sha1); }
|
||||
set { _sha1 = Utilities.StringToByteArray(CleanSHA1(value)); }
|
||||
get => _media.ReadString(Models.Internal.Media.SHA1Key);
|
||||
set => _media[Models.Internal.Media.SHA1Key] = TextHelper.NormalizeSHA1(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Data SHA-256 hash
|
||||
/// </summary>
|
||||
[JsonProperty("sha256", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("sha256")]
|
||||
public string SHA256
|
||||
public string? SHA256
|
||||
{
|
||||
get { return _sha256.IsNullOrEmpty() ? null : Utilities.ByteArrayToString(_sha256); }
|
||||
set { _sha256 = Utilities.StringToByteArray(CleanSHA256(value)); }
|
||||
get => _media.ReadString(Models.Internal.Media.SHA256Key);
|
||||
set => _media[Models.Internal.Media.SHA256Key] = TextHelper.NormalizeSHA256(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// File SpamSum fuzzy hash
|
||||
/// </summary>
|
||||
[JsonProperty("spamsum", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("spamsum")]
|
||||
public string SpamSum
|
||||
public string? SpamSum
|
||||
{
|
||||
get { return _spamsum.IsNullOrEmpty() ? null : Encoding.UTF8.GetString(_spamsum); }
|
||||
set { _spamsum = Encoding.UTF8.GetBytes(value ?? string.Empty); }
|
||||
get => _media.ReadString(Models.Internal.Media.SpamSumKey);
|
||||
set => _media[Models.Internal.Media.SpamSumKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Internal Media model
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
private Models.Internal.Media _media = new();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Accessors
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string GetName() => Name;
|
||||
public override string? GetName() => Name;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void SetName(string name) => Name = name;
|
||||
public override void SetName(string? name) => Name = name;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -101,10 +101,10 @@ namespace SabreTools.DatItems.Formats
|
||||
public Media(BaseFile baseFile)
|
||||
{
|
||||
Name = baseFile.Filename;
|
||||
_md5 = baseFile.MD5;
|
||||
_sha1 = baseFile.SHA1;
|
||||
_sha256 = baseFile.SHA256;
|
||||
_spamsum = baseFile.SpamSum;
|
||||
MD5 = Utilities.ByteArrayToString(baseFile.MD5);
|
||||
SHA1 = Utilities.ByteArrayToString(baseFile.SHA1);
|
||||
SHA256 = Utilities.ByteArrayToString(baseFile.SHA256);
|
||||
SpamSum = Utilities.ByteArrayToString(baseFile.SpamSum);
|
||||
|
||||
ItemType = ItemType.Media;
|
||||
DupeType = 0x00;
|
||||
@@ -122,15 +122,11 @@ namespace SabreTools.DatItems.Formats
|
||||
ItemType = this.ItemType,
|
||||
DupeType = this.DupeType,
|
||||
|
||||
Machine = this.Machine.Clone() as Machine,
|
||||
Source = this.Source.Clone() as Source,
|
||||
Machine = this.Machine?.Clone() as Machine,
|
||||
Source = this.Source?.Clone() as Source,
|
||||
Remove = this.Remove,
|
||||
|
||||
Name = this.Name,
|
||||
_md5 = this._md5,
|
||||
_sha1 = this._sha1,
|
||||
_sha256 = this._sha256,
|
||||
_spamsum = this._spamsum,
|
||||
_media = this._media?.Clone() as Models.Internal.Media ?? new Models.Internal.Media(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -143,10 +139,10 @@ namespace SabreTools.DatItems.Formats
|
||||
{
|
||||
Filename = this.Name,
|
||||
Parent = this.Machine?.Name,
|
||||
MD5 = this._md5,
|
||||
SHA1 = this._sha1,
|
||||
SHA256 = this._sha256,
|
||||
SpamSum = this._spamsum,
|
||||
MD5 = Utilities.StringToByteArray(this.MD5),
|
||||
SHA1 = Utilities.StringToByteArray(this.SHA1),
|
||||
SHA256 = Utilities.StringToByteArray(this.SHA256),
|
||||
SpamSum = Utilities.StringToByteArray(this.SpamSum),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -161,8 +157,8 @@ namespace SabreTools.DatItems.Formats
|
||||
ItemType = ItemType.Rom,
|
||||
DupeType = this.DupeType,
|
||||
|
||||
Machine = this.Machine.Clone() as Machine,
|
||||
Source = this.Source.Clone() as Source,
|
||||
Machine = this.Machine?.Clone() as Machine,
|
||||
Source = this.Source?.Clone() as Source,
|
||||
Remove = this.Remove,
|
||||
|
||||
Name = this.Name + ".aif",
|
||||
@@ -180,22 +176,14 @@ namespace SabreTools.DatItems.Formats
|
||||
#region Comparision Methods
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Equals(DatItem other)
|
||||
public override bool Equals(DatItem? other)
|
||||
{
|
||||
bool dupefound = false;
|
||||
|
||||
// If we don't have a Media, return false
|
||||
if (ItemType != other.ItemType)
|
||||
return dupefound;
|
||||
if (ItemType != other?.ItemType || other is not Media otherInternal)
|
||||
return false;
|
||||
|
||||
// Otherwise, treat it as a Media
|
||||
Media newOther = other as Media;
|
||||
|
||||
// If we get a partial match
|
||||
if (HashMatch(newOther))
|
||||
dupefound = true;
|
||||
|
||||
return dupefound;
|
||||
// Compare the internal models
|
||||
return _media.EqualTo(otherInternal._media);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -204,17 +192,17 @@ namespace SabreTools.DatItems.Formats
|
||||
/// <param name="other">Media to fill information from</param>
|
||||
public void FillMissingInformation(Media other)
|
||||
{
|
||||
if (_md5.IsNullOrEmpty() && !other._md5.IsNullOrEmpty())
|
||||
_md5 = other._md5;
|
||||
if (string.IsNullOrWhiteSpace(MD5) && !string.IsNullOrWhiteSpace(other.MD5))
|
||||
MD5 = other.MD5;
|
||||
|
||||
if (_sha1.IsNullOrEmpty() && !other._sha1.IsNullOrEmpty())
|
||||
_sha1 = other._sha1;
|
||||
if (string.IsNullOrWhiteSpace(SHA1) && !string.IsNullOrWhiteSpace(other.SHA1))
|
||||
SHA1 = other.SHA1;
|
||||
|
||||
if (_sha256.IsNullOrEmpty() && !other._sha256.IsNullOrEmpty())
|
||||
_sha256 = other._sha256;
|
||||
if (string.IsNullOrWhiteSpace(SHA256) && !string.IsNullOrWhiteSpace(other.SHA256))
|
||||
SHA256 = other.SHA256;
|
||||
|
||||
if (_spamsum.IsNullOrEmpty() && !other._spamsum.IsNullOrEmpty())
|
||||
_spamsum = other._spamsum;
|
||||
if (string.IsNullOrWhiteSpace(SpamSum) && !string.IsNullOrWhiteSpace(other.SpamSum))
|
||||
SpamSum = other.SpamSum;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -223,64 +211,18 @@ namespace SabreTools.DatItems.Formats
|
||||
/// <returns>String representing the suffix</returns>
|
||||
public string GetDuplicateSuffix()
|
||||
{
|
||||
if (!_md5.IsNullOrEmpty())
|
||||
if (!string.IsNullOrWhiteSpace(MD5))
|
||||
return $"_{MD5}";
|
||||
else if (!_sha1.IsNullOrEmpty())
|
||||
else if (!string.IsNullOrWhiteSpace(SHA1))
|
||||
return $"_{SHA1}";
|
||||
else if (!_sha256.IsNullOrEmpty())
|
||||
else if (!string.IsNullOrWhiteSpace(SHA256))
|
||||
return $"_{SHA256}";
|
||||
else if (!_spamsum.IsNullOrEmpty())
|
||||
else if (!string.IsNullOrWhiteSpace(SpamSum))
|
||||
return $"_{SpamSum}";
|
||||
else
|
||||
return "_1";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns if there are no, non-empty hashes in common with another Media
|
||||
/// </summary>
|
||||
/// <param name="other">Media to compare against</param>
|
||||
/// <returns>True if at least one hash is not mutually exclusive, false otherwise</returns>
|
||||
private bool HasCommonHash(Media other)
|
||||
{
|
||||
return !(_md5.IsNullOrEmpty() ^ other._md5.IsNullOrEmpty())
|
||||
|| !(_sha1.IsNullOrEmpty() ^ other._sha1.IsNullOrEmpty())
|
||||
|| !(_sha256.IsNullOrEmpty() ^ other._sha256.IsNullOrEmpty())
|
||||
|| !(_spamsum.IsNullOrEmpty() ^ other._spamsum.IsNullOrEmpty());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns if the Media contains any hashes
|
||||
/// </summary>
|
||||
/// <returns>True if any hash exists, false otherwise</returns>
|
||||
private bool HasHashes()
|
||||
{
|
||||
return !_md5.IsNullOrEmpty()
|
||||
|| !_sha1.IsNullOrEmpty()
|
||||
|| !_sha256.IsNullOrEmpty()
|
||||
|| !_spamsum.IsNullOrEmpty();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns if any hashes are common with another Media
|
||||
/// </summary>
|
||||
/// <param name="other">Media to compare against</param>
|
||||
/// <returns>True if any hashes are in common, false otherwise</returns>
|
||||
private bool HashMatch(Media other)
|
||||
{
|
||||
// If either have no hashes, we return false, otherwise this would be a false positive
|
||||
if (!HasHashes() || !other.HasHashes())
|
||||
return false;
|
||||
|
||||
// If neither have hashes in common, we return false, otherwise this would be a false positive
|
||||
if (!HasCommonHash(other))
|
||||
return false;
|
||||
|
||||
// Return if all hashes match according to merge rules
|
||||
return ConditionalHashEquals(_md5, other._md5)
|
||||
&& ConditionalHashEquals(_sha1, other._sha1)
|
||||
&& ConditionalHashEquals(_spamsum, other._spamsum);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Sorting and Merging
|
||||
@@ -289,7 +231,7 @@ namespace SabreTools.DatItems.Formats
|
||||
public override string GetKey(ItemKey bucketedBy, bool lower = true, bool norename = true)
|
||||
{
|
||||
// Set the output key as the default blank string
|
||||
string key;
|
||||
string? key;
|
||||
|
||||
// Now determine what the key should be based on the bucketedBy value
|
||||
switch (bucketedBy)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Xml.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
using SabreTools.Core;
|
||||
@@ -15,26 +16,44 @@ namespace SabreTools.DatItems.Formats
|
||||
#region Fields
|
||||
|
||||
[JsonProperty("name"), XmlElement("name")]
|
||||
public string Name { get; set; }
|
||||
public string? Name
|
||||
{
|
||||
get => _part.ReadString(Models.Internal.Part.NameKey);
|
||||
set => _part[Models.Internal.Part.NameKey] = value;
|
||||
}
|
||||
|
||||
[JsonProperty("interface"), XmlElement("interface")]
|
||||
public string Interface { get; set; }
|
||||
public string? Interface
|
||||
{
|
||||
get => _part.ReadString(Models.Internal.Part.InterfaceKey);
|
||||
set => _part[Models.Internal.Part.InterfaceKey] = value;
|
||||
}
|
||||
|
||||
[JsonProperty("features", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("features")]
|
||||
public List<PartFeature> Features { get; set; }
|
||||
public List<PartFeature>? Features
|
||||
{
|
||||
get => _part.Read<PartFeature[]>(Models.Internal.Part.FeatureKey)?.ToList();
|
||||
set => _part[Models.Internal.Part.FeatureKey] = value?.ToArray();
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool FeaturesSpecified { get { return Features != null && Features.Count > 0; } }
|
||||
|
||||
/// <summary>
|
||||
/// Internal Part model
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
private Models.Internal.Part _part = new();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Accessors
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string GetName() => Name;
|
||||
public override string? GetName() => Name;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void SetName(string name) => Name = name;
|
||||
public override void SetName(string? name) => Name = name;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -61,13 +80,11 @@ namespace SabreTools.DatItems.Formats
|
||||
ItemType = this.ItemType,
|
||||
DupeType = this.DupeType,
|
||||
|
||||
Machine = this.Machine.Clone() as Machine,
|
||||
Source = this.Source.Clone() as Source,
|
||||
Machine = this.Machine?.Clone() as Machine,
|
||||
Source = this.Source?.Clone() as Source,
|
||||
Remove = this.Remove,
|
||||
|
||||
Name = this.Name,
|
||||
Interface = this.Interface,
|
||||
Features = this.Features,
|
||||
_part = this._part?.Clone() as Models.Internal.Part ?? new Models.Internal.Part(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -76,31 +93,14 @@ namespace SabreTools.DatItems.Formats
|
||||
#region Comparision Methods
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Equals(DatItem other)
|
||||
public override bool Equals(DatItem? other)
|
||||
{
|
||||
// If we don't have a Part, return false
|
||||
if (ItemType != other.ItemType)
|
||||
if (ItemType != other?.ItemType || other is not Part otherInternal)
|
||||
return false;
|
||||
|
||||
// Otherwise, treat it as a Part
|
||||
Part newOther = other as Part;
|
||||
|
||||
// If the Part information matches
|
||||
bool match = (Name == newOther.Name
|
||||
&& Interface == newOther.Interface);
|
||||
if (!match)
|
||||
return match;
|
||||
|
||||
// If the features match
|
||||
if (FeaturesSpecified)
|
||||
{
|
||||
foreach (PartFeature partFeature in Features)
|
||||
{
|
||||
match &= newOther.Features.Contains(partFeature);
|
||||
}
|
||||
}
|
||||
|
||||
return match;
|
||||
// Compare the internal models
|
||||
return _part.EqualTo(otherInternal._part);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -16,23 +16,37 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Name of the item
|
||||
/// </summary>
|
||||
[JsonProperty("name"), XmlElement("name")]
|
||||
public string Name { get; set; }
|
||||
public string? Name
|
||||
{
|
||||
get => _feature.ReadString(Models.Internal.Feature.NameKey);
|
||||
set => _feature[Models.Internal.Feature.NameKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// PartFeature value
|
||||
/// </summary>
|
||||
[JsonProperty("value"), XmlElement("value")]
|
||||
public string Value { get; set; }
|
||||
public string? Value
|
||||
{
|
||||
get => _feature.ReadString(Models.Internal.Feature.ValueKey);
|
||||
set => _feature[Models.Internal.Feature.ValueKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Internal Feature model
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
private Models.Internal.Feature _feature = new();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Accessors
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string GetName() => Name;
|
||||
public override string? GetName() => Name;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void SetName(string name) => Name = name;
|
||||
public override void SetName(string? name) => Name = name;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -59,12 +73,11 @@ namespace SabreTools.DatItems.Formats
|
||||
ItemType = this.ItemType,
|
||||
DupeType = this.DupeType,
|
||||
|
||||
Machine = this.Machine.Clone() as Machine,
|
||||
Source = this.Source.Clone() as Source,
|
||||
Machine = this.Machine?.Clone() as Machine,
|
||||
Source = this.Source?.Clone() as Source,
|
||||
Remove = this.Remove,
|
||||
|
||||
Name = this.Name,
|
||||
Value = this.Value,
|
||||
_feature = this._feature?.Clone() as Models.Internal.Feature ?? new Models.Internal.Feature(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -73,18 +86,14 @@ namespace SabreTools.DatItems.Formats
|
||||
#region Comparision Methods
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Equals(DatItem other)
|
||||
public override bool Equals(DatItem? other)
|
||||
{
|
||||
// If we don't have a sample, return false
|
||||
if (ItemType != other.ItemType)
|
||||
// If we don't have a PartFeature, return false
|
||||
if (ItemType != other?.ItemType || other is not PartFeature otherInternal)
|
||||
return false;
|
||||
|
||||
// Otherwise, treat it as a PartFeature
|
||||
PartFeature newOther = other as PartFeature;
|
||||
|
||||
// If the archive information matches
|
||||
return (Name == newOther.Name
|
||||
&& Value == newOther.Value);
|
||||
// Compare the internal models
|
||||
return _feature.EqualTo(otherInternal._feature);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Xml.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
using SabreTools.Core;
|
||||
@@ -17,17 +18,31 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Tag for the port
|
||||
/// </summary>
|
||||
[JsonProperty("tag", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("tag")]
|
||||
public string Tag { get; set; }
|
||||
public string? Tag
|
||||
{
|
||||
get => _port.ReadString(Models.Internal.Port.TagKey);
|
||||
set => _port[Models.Internal.Port.TagKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// List of analogs on the port
|
||||
/// </summary>
|
||||
[JsonProperty("analogs", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("analogs")]
|
||||
public List<Analog> Analogs { get; set; }
|
||||
public List<Analog>? Analogs
|
||||
{
|
||||
get => _port.Read<Analog[]>(Models.Internal.Port.AnalogKey)?.ToList();
|
||||
set => _port[Models.Internal.Port.AnalogKey] = value?.ToArray();
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool AnalogsSpecified { get { return Analogs != null && Analogs.Count > 0; } }
|
||||
|
||||
/// <summary>
|
||||
/// Internal Port model
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
private Models.Internal.Port _port = new();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
@@ -52,12 +67,11 @@ namespace SabreTools.DatItems.Formats
|
||||
ItemType = this.ItemType,
|
||||
DupeType = this.DupeType,
|
||||
|
||||
Machine = this.Machine.Clone() as Machine,
|
||||
Source = this.Source.Clone() as Source,
|
||||
Machine = this.Machine?.Clone() as Machine,
|
||||
Source = this.Source?.Clone() as Source,
|
||||
Remove = this.Remove,
|
||||
|
||||
Tag = this.Tag,
|
||||
Analogs = this.Analogs,
|
||||
_port = this._port?.Clone() as Models.Internal.Port ?? new Models.Internal.Port(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -66,30 +80,14 @@ namespace SabreTools.DatItems.Formats
|
||||
#region Comparision Methods
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Equals(DatItem other)
|
||||
public override bool Equals(DatItem? other)
|
||||
{
|
||||
// If we don't have a Port, return false
|
||||
if (ItemType != other.ItemType)
|
||||
if (ItemType != other?.ItemType || other is not Port otherInternal)
|
||||
return false;
|
||||
|
||||
// Otherwise, treat it as a Port
|
||||
Port newOther = other as Port;
|
||||
|
||||
// If the Port information matches
|
||||
bool match = (Tag == newOther.Tag);
|
||||
if (!match)
|
||||
return match;
|
||||
|
||||
// If the analogs match
|
||||
if (AnalogsSpecified)
|
||||
{
|
||||
foreach (Analog analog in Analogs)
|
||||
{
|
||||
match &= newOther.Analogs.Contains(analog);
|
||||
}
|
||||
}
|
||||
|
||||
return match;
|
||||
// Compare the internal models
|
||||
return _port.EqualTo(otherInternal._port);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -16,13 +16,21 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Name of the item
|
||||
/// </summary>
|
||||
[JsonProperty("name"), XmlElement("name")]
|
||||
public string Name { get; set; }
|
||||
public string? Name
|
||||
{
|
||||
get => _ramOption.ReadString(Models.Internal.RamOption.NameKey);
|
||||
set => _ramOption[Models.Internal.RamOption.NameKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determine whether the RamOption is default
|
||||
/// </summary>
|
||||
[JsonProperty("default", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("default")]
|
||||
public bool? Default { get; set; }
|
||||
public bool? Default
|
||||
{
|
||||
get => _ramOption.ReadBool(Models.Internal.RamOption.DefaultKey);
|
||||
set => _ramOption[Models.Internal.RamOption.DefaultKey] = value;
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool DefaultSpecified { get { return Default != null; } }
|
||||
@@ -31,17 +39,27 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Determines the content of the RamOption
|
||||
/// </summary>
|
||||
[JsonProperty("content", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("content")]
|
||||
public string Content { get; set; }
|
||||
public string? Content
|
||||
{
|
||||
get => _ramOption.ReadString(Models.Internal.RamOption.ContentKey);
|
||||
set => _ramOption[Models.Internal.RamOption.ContentKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Internal RamOption model
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
private Models.Internal.RamOption _ramOption = new();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Accessors
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string GetName() => Name;
|
||||
public override string? GetName() => Name;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void SetName(string name) => Name = name;
|
||||
public override void SetName(string? name) => Name = name;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -68,13 +86,11 @@ namespace SabreTools.DatItems.Formats
|
||||
ItemType = this.ItemType,
|
||||
DupeType = this.DupeType,
|
||||
|
||||
Machine = this.Machine.Clone() as Machine,
|
||||
Source = this.Source.Clone() as Source,
|
||||
Machine = this.Machine?.Clone() as Machine,
|
||||
Source = this.Source?.Clone() as Source,
|
||||
Remove = this.Remove,
|
||||
|
||||
Name = this.Name,
|
||||
Default = this.Default,
|
||||
Content = this.Content,
|
||||
_ramOption = this._ramOption?.Clone() as Models.Internal.RamOption ?? new Models.Internal.RamOption(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -83,19 +99,14 @@ namespace SabreTools.DatItems.Formats
|
||||
#region Comparision Methods
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Equals(DatItem other)
|
||||
public override bool Equals(DatItem? other)
|
||||
{
|
||||
// If we don't have a RamOption, return false
|
||||
if (ItemType != other.ItemType)
|
||||
// If we don't have a RamOption, return false
|
||||
if (ItemType != other?.ItemType || other is not RamOption otherInternal)
|
||||
return false;
|
||||
|
||||
// Otherwise, treat it as a RamOption
|
||||
RamOption newOther = other as RamOption;
|
||||
|
||||
// If the BiosSet information matches
|
||||
return (Name == newOther.Name
|
||||
&& Default == newOther.Default
|
||||
&& Content == newOther.Content);
|
||||
// Compare the internal models
|
||||
return _ramOption.EqualTo(otherInternal._ramOption);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -16,44 +16,70 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Name of the item
|
||||
/// </summary>
|
||||
[JsonProperty("name"), XmlElement("name")]
|
||||
public string Name { get; set; }
|
||||
public string? Name
|
||||
{
|
||||
get => _release.ReadString(Models.Internal.Release.NameKey);
|
||||
set => _release[Models.Internal.Release.NameKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Release region(s)
|
||||
/// </summary>
|
||||
[JsonProperty("region", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("region")]
|
||||
public string Region { get; set; }
|
||||
public string? Region
|
||||
{
|
||||
get => _release.ReadString(Models.Internal.Release.RegionKey);
|
||||
set => _release[Models.Internal.Release.RegionKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Release language(s)
|
||||
/// </summary>
|
||||
[JsonProperty("language", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("language")]
|
||||
public string Language { get; set; }
|
||||
public string? Language
|
||||
{
|
||||
get => _release.ReadString(Models.Internal.Release.LanguageKey);
|
||||
set => _release[Models.Internal.Release.LanguageKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Date of release
|
||||
/// </summary>
|
||||
[JsonProperty("date", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("date")]
|
||||
public string Date { get; set; }
|
||||
public string? Date
|
||||
{
|
||||
get => _release.ReadString(Models.Internal.Release.DateKey);
|
||||
set => _release[Models.Internal.Release.DateKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Default release, if applicable
|
||||
/// </summary>
|
||||
[JsonProperty("default", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("default")]
|
||||
public bool? Default { get; set; }
|
||||
public bool? Default
|
||||
{
|
||||
get => _release.ReadBool(Models.Internal.Release.DefaultKey);
|
||||
set => _release[Models.Internal.Release.DefaultKey] = value;
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool DefaultSpecified { get { return Default != null; } }
|
||||
|
||||
/// <summary>
|
||||
/// Internal Release model
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
private Models.Internal.Release _release = new();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Accessors
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string GetName() => Name;
|
||||
public override string? GetName() => Name;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void SetName(string name) => Name = name;
|
||||
public override void SetName(string? name) => Name = name;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -84,15 +110,11 @@ namespace SabreTools.DatItems.Formats
|
||||
ItemType = this.ItemType,
|
||||
DupeType = this.DupeType,
|
||||
|
||||
Machine = this.Machine.Clone() as Machine,
|
||||
Source = this.Source.Clone() as Source,
|
||||
Machine = this.Machine?.Clone() as Machine,
|
||||
Source = this.Source?.Clone() as Source,
|
||||
Remove = this.Remove,
|
||||
|
||||
Name = this.Name,
|
||||
Region = this.Region,
|
||||
Language = this.Language,
|
||||
Date = this.Date,
|
||||
Default = this.Default,
|
||||
_release = this._release?.Clone() as Models.Internal.Release ?? new Models.Internal.Release(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -101,21 +123,14 @@ namespace SabreTools.DatItems.Formats
|
||||
#region Comparision Methods
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Equals(DatItem other)
|
||||
public override bool Equals(DatItem? other)
|
||||
{
|
||||
// If we don't have a release return false
|
||||
if (ItemType != other.ItemType)
|
||||
// If we don't have a Release, return false
|
||||
if (ItemType != other?.ItemType || other is not Release otherInternal)
|
||||
return false;
|
||||
|
||||
// Otherwise, treat it as a Release
|
||||
Release newOther = other as Release;
|
||||
|
||||
// If the archive information matches
|
||||
return (Name == newOther.Name
|
||||
&& Region == newOther.Region
|
||||
&& Language == newOther.Language
|
||||
&& Date == newOther.Date
|
||||
&& Default == newOther.Default);
|
||||
// Compare the internal models
|
||||
return _release.EqualTo(otherInternal._release);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -18,31 +18,31 @@ namespace SabreTools.DatItems.Formats
|
||||
/// </summary>
|
||||
/// <remarks>TODO: Is this required?</remarks>
|
||||
[JsonProperty("id", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("id")]
|
||||
public string Id { get; set; }
|
||||
public string? Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Directory name value
|
||||
/// </summary>
|
||||
[JsonProperty("dirname", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("dirname")]
|
||||
public string DirName { get; set; }
|
||||
public string? DirName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Rom info value
|
||||
/// </summary>
|
||||
[JsonProperty("rominfo", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("rominfo")]
|
||||
public string RomInfo { get; set; }
|
||||
public string? RomInfo { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Category value
|
||||
/// </summary>
|
||||
[JsonProperty("category", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("category")]
|
||||
public string Category { get; set; }
|
||||
public string? Category { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// NFO name value
|
||||
/// </summary>
|
||||
[JsonProperty("nfoname", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("nfoname")]
|
||||
public string NfoName { get; set; }
|
||||
public string? NfoName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// NFO size value
|
||||
@@ -57,55 +57,55 @@ namespace SabreTools.DatItems.Formats
|
||||
/// NFO CRC value
|
||||
/// </summary>
|
||||
[JsonProperty("nfocrc", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("nfocrc")]
|
||||
public string NfoCrc { get; set; }
|
||||
public string? NfoCrc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Archive name value
|
||||
/// </summary>
|
||||
[JsonProperty("archivename", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("archivename")]
|
||||
public string ArchiveName { get; set; }
|
||||
public string? ArchiveName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Original format value
|
||||
/// </summary>
|
||||
[JsonProperty("originalformat", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("originalformat")]
|
||||
public string OriginalFormat { get; set; }
|
||||
public string? OriginalFormat { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Date value
|
||||
/// </summary>
|
||||
[JsonProperty("date", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("date")]
|
||||
public string Date { get; set; }
|
||||
public string? Date { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Grpup value
|
||||
/// </summary>
|
||||
[JsonProperty("group", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("group")]
|
||||
public string Group { get; set; }
|
||||
public string? Group { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Comment value
|
||||
/// </summary>
|
||||
[JsonProperty("comment", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("comment")]
|
||||
public string Comment { get; set; }
|
||||
public string? Comment { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Tool value
|
||||
/// </summary>
|
||||
[JsonProperty("tool", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("tool")]
|
||||
public string Tool { get; set; }
|
||||
public string? Tool { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Region value
|
||||
/// </summary>
|
||||
[JsonProperty("region", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("region")]
|
||||
public string Region { get; set; }
|
||||
public string? Region { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Origin value
|
||||
/// </summary>
|
||||
[JsonProperty("origin", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("origin")]
|
||||
public string Origin { get; set; }
|
||||
public string? Origin { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -131,8 +131,8 @@ namespace SabreTools.DatItems.Formats
|
||||
ItemType = this.ItemType,
|
||||
DupeType = this.DupeType,
|
||||
|
||||
Machine = this.Machine.Clone() as Machine,
|
||||
Source = this.Source.Clone() as Source,
|
||||
Machine = this.Machine?.Clone() as Machine,
|
||||
Source = this.Source?.Clone() as Source,
|
||||
Remove = this.Remove,
|
||||
|
||||
Id = this.Id,
|
||||
@@ -158,17 +158,17 @@ namespace SabreTools.DatItems.Formats
|
||||
#region Comparision Methods
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Equals(DatItem other)
|
||||
public override bool Equals(DatItem? other)
|
||||
{
|
||||
// If we don't have a Details, return false
|
||||
if (ItemType != other.ItemType)
|
||||
if (ItemType != other?.ItemType)
|
||||
return false;
|
||||
|
||||
// Otherwise, treat it as a Details
|
||||
ReleaseDetails newOther = other as ReleaseDetails;
|
||||
ReleaseDetails? newOther = other as ReleaseDetails;
|
||||
|
||||
// If the Details information matches
|
||||
return (Id == newOther.Id
|
||||
return (Id == newOther!.Id
|
||||
&& DirName == newOther.DirName
|
||||
&& RomInfo == newOther.RomInfo
|
||||
&& Category == newOther.Category
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Xml.Serialization;
|
||||
using System.Xml.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using SabreTools.Core;
|
||||
@@ -16,18 +13,6 @@ namespace SabreTools.DatItems.Formats
|
||||
[JsonObject("rom"), XmlRoot("rom")]
|
||||
public class Rom : DatItem
|
||||
{
|
||||
#region Private instance variables
|
||||
|
||||
private byte[] _crc; // 8 bytes
|
||||
private byte[] _md5; // 16 bytes
|
||||
private byte[] _sha1; // 20 bytes
|
||||
private byte[] _sha256; // 32 bytes
|
||||
private byte[] _sha384; // 48 bytes
|
||||
private byte[] _sha512; // 64 bytes
|
||||
private byte[] _spamsum; // variable bytes
|
||||
|
||||
#endregion
|
||||
|
||||
#region Fields
|
||||
|
||||
#region Common
|
||||
@@ -36,19 +21,31 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Name of the item
|
||||
/// </summary>
|
||||
[JsonProperty("name"), XmlElement("name")]
|
||||
public string Name { get; set; }
|
||||
public string? Name
|
||||
{
|
||||
get => _rom.ReadString(Models.Internal.Rom.NameKey);
|
||||
set => _rom[Models.Internal.Rom.NameKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// What BIOS is required for this rom
|
||||
/// </summary>
|
||||
[JsonProperty("bios", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("bios")]
|
||||
public string Bios { get; set; }
|
||||
public string? Bios
|
||||
{
|
||||
get => _rom.ReadString(Models.Internal.Rom.BiosKey);
|
||||
set => _rom[Models.Internal.Rom.BiosKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Byte size of the rom
|
||||
/// </summary>
|
||||
[JsonProperty("size", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("size")]
|
||||
public long? Size { get; set; } = null;
|
||||
public long? Size
|
||||
{
|
||||
get => _rom.ReadLong(Models.Internal.Rom.SizeKey);
|
||||
set => _rom[Models.Internal.Rom.SizeKey] = value;
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool SizeSpecified { get { return Size != null; } }
|
||||
@@ -57,102 +54,122 @@ namespace SabreTools.DatItems.Formats
|
||||
/// File CRC32 hash
|
||||
/// </summary>
|
||||
[JsonProperty("crc", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("crc")]
|
||||
public string CRC
|
||||
public string? CRC
|
||||
{
|
||||
get { return _crc.IsNullOrEmpty() ? null : Utilities.ByteArrayToString(_crc); }
|
||||
set { _crc = (value == "null" ? Constants.CRCZeroBytes : Utilities.StringToByteArray(CleanCRC32(value))); }
|
||||
get => _rom.ReadString(Models.Internal.Rom.CRCKey);
|
||||
set => _rom[Models.Internal.Rom.CRCKey] = TextHelper.NormalizeCRC32(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// File MD5 hash
|
||||
/// </summary>
|
||||
[JsonProperty("md5", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("md5")]
|
||||
public string MD5
|
||||
public string? MD5
|
||||
{
|
||||
get { return _md5.IsNullOrEmpty() ? null : Utilities.ByteArrayToString(_md5); }
|
||||
set { _md5 = Utilities.StringToByteArray(CleanMD5(value)); }
|
||||
get => _rom.ReadString(Models.Internal.Rom.MD5Key);
|
||||
set => _rom[Models.Internal.Rom.MD5Key] = TextHelper.NormalizeMD5(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// File SHA-1 hash
|
||||
/// </summary>
|
||||
[JsonProperty("sha1", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("sha1")]
|
||||
public string SHA1
|
||||
public string? SHA1
|
||||
{
|
||||
get { return _sha1.IsNullOrEmpty() ? null : Utilities.ByteArrayToString(_sha1); }
|
||||
set { _sha1 = Utilities.StringToByteArray(CleanSHA1(value)); }
|
||||
get => _rom.ReadString(Models.Internal.Rom.SHA1Key);
|
||||
set => _rom[Models.Internal.Rom.SHA1Key] = TextHelper.NormalizeSHA1(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// File SHA-256 hash
|
||||
/// </summary>
|
||||
[JsonProperty("sha256", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("sha256")]
|
||||
public string SHA256
|
||||
public string? SHA256
|
||||
{
|
||||
get { return _sha256.IsNullOrEmpty() ? null : Utilities.ByteArrayToString(_sha256); }
|
||||
set { _sha256 = Utilities.StringToByteArray(CleanSHA256(value)); }
|
||||
get => _rom.ReadString(Models.Internal.Rom.SHA256Key);
|
||||
set => _rom[Models.Internal.Rom.SHA256Key] = TextHelper.NormalizeSHA256(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// File SHA-384 hash
|
||||
/// </summary>
|
||||
[JsonProperty("sha384", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("sha384")]
|
||||
public string SHA384
|
||||
public string? SHA384
|
||||
{
|
||||
get { return _sha384.IsNullOrEmpty() ? null : Utilities.ByteArrayToString(_sha384); }
|
||||
set { _sha384 = Utilities.StringToByteArray(CleanSHA384(value)); }
|
||||
get => _rom.ReadString(Models.Internal.Rom.SHA384Key);
|
||||
set => _rom[Models.Internal.Rom.SHA384Key] = TextHelper.NormalizeSHA384(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// File SHA-512 hash
|
||||
/// </summary>
|
||||
[JsonProperty("sha512", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("sha512")]
|
||||
public string SHA512
|
||||
public string? SHA512
|
||||
{
|
||||
get { return _sha512.IsNullOrEmpty() ? null : Utilities.ByteArrayToString(_sha512); }
|
||||
set { _sha512 = Utilities.StringToByteArray(CleanSHA512(value)); }
|
||||
get => _rom.ReadString(Models.Internal.Rom.SHA512Key);
|
||||
set => _rom[Models.Internal.Rom.SHA512Key] = TextHelper.NormalizeSHA512(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// File SpamSum fuzzy hash
|
||||
/// </summary>
|
||||
[JsonProperty("spamsum", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("spamsum")]
|
||||
public string SpamSum
|
||||
public string? SpamSum
|
||||
{
|
||||
get { return _spamsum.IsNullOrEmpty() ? null : Encoding.UTF8.GetString(_spamsum); }
|
||||
set { _spamsum = Encoding.UTF8.GetBytes(value ?? string.Empty); }
|
||||
get => _rom.ReadString(Models.Internal.Rom.SpamSumKey);
|
||||
set => _rom[Models.Internal.Rom.SpamSumKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Rom name to merge from parent
|
||||
/// </summary>
|
||||
[JsonProperty("merge", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("merge")]
|
||||
public string MergeTag { get; set; }
|
||||
public string? MergeTag
|
||||
{
|
||||
get => _rom.ReadString(Models.Internal.Rom.MergeKey);
|
||||
set => _rom[Models.Internal.Rom.MergeKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Rom region
|
||||
/// </summary>
|
||||
[JsonProperty("region", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("biregionos")]
|
||||
public string Region { get; set; }
|
||||
public string? Region
|
||||
{
|
||||
get => _rom.ReadString(Models.Internal.Rom.RegionKey);
|
||||
set => _rom[Models.Internal.Rom.RegionKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Data offset within rom
|
||||
/// </summary>
|
||||
[JsonProperty("offset", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("offset")]
|
||||
public string Offset { get; set; }
|
||||
public string? Offset
|
||||
{
|
||||
get => _rom.ReadString(Models.Internal.Rom.OffsetKey);
|
||||
set => _rom[Models.Internal.Rom.OffsetKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// File created date
|
||||
/// </summary>
|
||||
[JsonProperty("date", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("date")]
|
||||
public string Date { get; set; }
|
||||
public string? Date
|
||||
{
|
||||
get => _rom.ReadString(Models.Internal.Rom.DateKey);
|
||||
set => _rom[Models.Internal.Rom.DateKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Rom dump status
|
||||
/// </summary>
|
||||
[JsonProperty("status", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("status")]
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
public ItemStatus ItemStatus { get; set; }
|
||||
public ItemStatus ItemStatus
|
||||
{
|
||||
get => _rom.ReadString(Models.Internal.Rom.StatusKey).AsItemStatus();
|
||||
set => _rom[Models.Internal.Rom.StatusKey] = value.FromItemStatus(yesno: false);
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool ItemStatusSpecified { get { return ItemStatus != ItemStatus.NULL && ItemStatus != ItemStatus.None; } }
|
||||
@@ -161,7 +178,11 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Determine if the rom is optional in the set
|
||||
/// </summary>
|
||||
[JsonProperty("optional", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("optional")]
|
||||
public bool? Optional { get; set; } = null;
|
||||
public bool? Optional
|
||||
{
|
||||
get => _rom.ReadBool(Models.Internal.Rom.OptionalKey);
|
||||
set => _rom[Models.Internal.Rom.OptionalKey] = value;
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool OptionalSpecified { get { return Optional != null; } }
|
||||
@@ -170,7 +191,11 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Determine if the CRC32 hash is inverted
|
||||
/// </summary>
|
||||
[JsonProperty("inverted", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("inverted")]
|
||||
public bool? Inverted { get; set; } = null;
|
||||
public bool? Inverted
|
||||
{
|
||||
get => _rom.ReadBool(Models.Internal.Rom.InvertedKey);
|
||||
set => _rom[Models.Internal.Rom.InvertedKey] = value;
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool InvertedSpecified { get { return Inverted != null; } }
|
||||
@@ -183,19 +208,31 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Source of file
|
||||
/// </summary>
|
||||
[JsonProperty("ado_source", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("ado_source")]
|
||||
public string ArchiveDotOrgSource { get; set; }
|
||||
public string? ArchiveDotOrgSource
|
||||
{
|
||||
get => _rom.ReadString(Models.Internal.Rom.SourceKey);
|
||||
set => _rom[Models.Internal.Rom.SourceKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Archive.org recognized file format
|
||||
/// </summary>
|
||||
[JsonProperty("ado_format", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("ado_format")]
|
||||
public string ArchiveDotOrgFormat { get; set; }
|
||||
public string? ArchiveDotOrgFormat
|
||||
{
|
||||
get => _rom.ReadString(Models.Internal.Rom.FormatKey);
|
||||
set => _rom[Models.Internal.Rom.FormatKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Original filename
|
||||
/// </summary>
|
||||
[JsonProperty("original_filename", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("original_filename")]
|
||||
public string OriginalFilename { get; set; }
|
||||
public string? OriginalFilename
|
||||
{
|
||||
get => _rom.ReadString(Models.Internal.Rom.OriginalKey);
|
||||
set => _rom[Models.Internal.Rom.OriginalKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Image rotation
|
||||
@@ -204,13 +241,21 @@ namespace SabreTools.DatItems.Formats
|
||||
/// TODO: This might be Int32?
|
||||
/// </remarks>
|
||||
[JsonProperty("rotation", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("rotation")]
|
||||
public string Rotation { get; set; }
|
||||
public string? Rotation
|
||||
{
|
||||
get => _rom.ReadString(Models.Internal.Rom.RotationKey);
|
||||
set => _rom[Models.Internal.Rom.RotationKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Summation value?
|
||||
/// </summary>
|
||||
[JsonProperty("summation", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("summation")]
|
||||
public string Summation { get; set; }
|
||||
public string? Summation
|
||||
{
|
||||
get => _rom.ReadString(Models.Internal.Rom.SummationKey);
|
||||
set => _rom[Models.Internal.Rom.SummationKey] = value;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -220,13 +265,21 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Alternate name for the item
|
||||
/// </summary>
|
||||
[JsonProperty("alt_romname", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("alt_romname")]
|
||||
public string AltName { get; set; }
|
||||
public string? AltName
|
||||
{
|
||||
get => _rom.ReadString(Models.Internal.Rom.AltRomnameKey);
|
||||
set => _rom[Models.Internal.Rom.AltRomnameKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Alternate title for the item
|
||||
/// </summary>
|
||||
[JsonProperty("alt_title", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("alt_title")]
|
||||
public string AltTitle { get; set; }
|
||||
public string? AltTitle
|
||||
{
|
||||
get => _rom.ReadString(Models.Internal.Rom.AltTitleKey);
|
||||
set => _rom[Models.Internal.Rom.AltTitleKey] = value;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -236,7 +289,11 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Alternate title for the item
|
||||
/// </summary>
|
||||
[JsonProperty("mia", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("mia")]
|
||||
public bool? MIA { get; set; } = null;
|
||||
public bool? MIA
|
||||
{
|
||||
get => _rom.ReadBool(Models.Internal.Rom.MIAKey);
|
||||
set => _rom[Models.Internal.Rom.MIAKey] = value;
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool MIASpecified { get { return MIA != null; } }
|
||||
@@ -248,8 +305,9 @@ namespace SabreTools.DatItems.Formats
|
||||
/// <summary>
|
||||
/// OpenMSX sub item type
|
||||
/// </summary>
|
||||
/// <remarks>This is inverted from the internal model</remarks>
|
||||
[JsonProperty("original", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("original")]
|
||||
public Original Original { get; set; } = null;
|
||||
public Original? Original { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public bool OriginalSpecified { get { return Original != null && Original != default; } }
|
||||
@@ -259,7 +317,11 @@ namespace SabreTools.DatItems.Formats
|
||||
/// </summary>
|
||||
[JsonProperty("openmsx_subtype", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("openmsx_subtype")]
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
public OpenMSXSubType OpenMSXSubType { get; set; }
|
||||
public OpenMSXSubType OpenMSXSubType
|
||||
{
|
||||
get => _rom.ReadString(Models.Internal.Rom.OpenMSXMediaType).AsOpenMSXSubType();
|
||||
set => _rom[Models.Internal.Rom.OpenMSXMediaType] = value.FromOpenMSXSubType();
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool OpenMSXSubTypeSpecified { get { return OpenMSXSubType != OpenMSXSubType.NULL; } }
|
||||
@@ -269,19 +331,28 @@ namespace SabreTools.DatItems.Formats
|
||||
/// </summary>
|
||||
/// <remarks>Not related to the subtype above</remarks>
|
||||
[JsonProperty("openmsx_type", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("openmsx_type")]
|
||||
public string OpenMSXType { get; set; }
|
||||
public string? OpenMSXType
|
||||
{
|
||||
get => _rom.ReadString(Models.Internal.Rom.OpenMSXType);
|
||||
set => _rom[Models.Internal.Rom.OpenMSXType] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Item remark (like a comment)
|
||||
/// </summary>
|
||||
[JsonProperty("remark", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("remark")]
|
||||
public string Remark { get; set; }
|
||||
public string? Remark
|
||||
{
|
||||
get => _rom.ReadString(Models.Internal.Rom.RemarkKey);
|
||||
set => _rom[Models.Internal.Rom.RemarkKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Boot state
|
||||
/// </summary>
|
||||
/// TODO: Investigate where this value came from?
|
||||
[JsonProperty("boot", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("boot")]
|
||||
public string Boot { get; set; }
|
||||
public string? Boot { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -290,8 +361,9 @@ namespace SabreTools.DatItems.Formats
|
||||
/// <summary>
|
||||
/// Data area information
|
||||
/// </summary>
|
||||
/// <remarks>This is inverted from the internal model</remarks>
|
||||
[JsonProperty("dataarea", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("dataarea")]
|
||||
public DataArea DataArea { get; set; } = null;
|
||||
public DataArea? DataArea { get; set; } = null;
|
||||
|
||||
[JsonIgnore]
|
||||
public bool DataAreaSpecified
|
||||
@@ -311,7 +383,11 @@ namespace SabreTools.DatItems.Formats
|
||||
/// </summary>
|
||||
[JsonProperty("loadflag", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("loadflag")]
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
public LoadFlag LoadFlag { get; set; }
|
||||
public LoadFlag LoadFlag
|
||||
{
|
||||
get => _rom.ReadString(Models.Internal.Rom.LoadFlagKey).AsLoadFlag();
|
||||
set => _rom[Models.Internal.Rom.LoadFlagKey] = value.FromLoadFlag();
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool LoadFlagSpecified { get { return LoadFlag != LoadFlag.NULL; } }
|
||||
@@ -319,8 +395,9 @@ namespace SabreTools.DatItems.Formats
|
||||
/// <summary>
|
||||
/// Original hardware part associated with the item
|
||||
/// </summary>
|
||||
/// <remarks>This is inverted from the internal model</remarks>
|
||||
[JsonProperty("part", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("part")]
|
||||
public Part Part { get; set; } = null;
|
||||
public Part? Part { get; set; } = null;
|
||||
|
||||
[JsonIgnore]
|
||||
public bool PartSpecified
|
||||
@@ -337,19 +414,29 @@ namespace SabreTools.DatItems.Formats
|
||||
/// SoftwareList value associated with the item
|
||||
/// </summary>
|
||||
[JsonProperty("value", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("value")]
|
||||
public string Value { get; set; }
|
||||
public string? Value
|
||||
{
|
||||
get => _rom.ReadString(Models.Internal.Rom.ValueKey);
|
||||
set => _rom[Models.Internal.Rom.ValueKey] = value;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Internal Rom model
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
private Models.Internal.Rom _rom = new();
|
||||
|
||||
#endregion // Fields
|
||||
|
||||
#region Accessors
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string GetName() => Name;
|
||||
public override string? GetName() => Name;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void SetName(string name) => Name = name;
|
||||
public override void SetName(string? name) => Name = name;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -394,13 +481,13 @@ namespace SabreTools.DatItems.Formats
|
||||
{
|
||||
Name = baseFile.Filename;
|
||||
Size = baseFile.Size;
|
||||
_crc = baseFile.CRC;
|
||||
_md5 = baseFile.MD5;
|
||||
_sha1 = baseFile.SHA1;
|
||||
_sha256 = baseFile.SHA256;
|
||||
_sha384 = baseFile.SHA384;
|
||||
_sha512 = baseFile.SHA512;
|
||||
_spamsum = baseFile.SpamSum;
|
||||
CRC = Utilities.ByteArrayToString(baseFile.CRC);
|
||||
MD5 = Utilities.ByteArrayToString(baseFile.MD5);
|
||||
SHA1 = Utilities.ByteArrayToString(baseFile.SHA1);
|
||||
SHA256 = Utilities.ByteArrayToString(baseFile.SHA256);
|
||||
SHA384 = Utilities.ByteArrayToString(baseFile.SHA384);
|
||||
SHA512 = Utilities.ByteArrayToString(baseFile.SHA512);
|
||||
SpamSum = Utilities.ByteArrayToString(baseFile.SpamSum);
|
||||
|
||||
ItemType = ItemType.Rom;
|
||||
DupeType = 0x00;
|
||||
@@ -421,42 +508,14 @@ namespace SabreTools.DatItems.Formats
|
||||
ItemType = this.ItemType,
|
||||
DupeType = this.DupeType,
|
||||
|
||||
Machine = this.Machine.Clone() as Machine,
|
||||
Source = this.Source.Clone() as Source,
|
||||
Machine = this.Machine?.Clone() as Machine,
|
||||
Source = this.Source?.Clone() as Source,
|
||||
Remove = this.Remove,
|
||||
|
||||
Bios = this.Bios,
|
||||
Size = this.Size,
|
||||
_crc = this._crc,
|
||||
_md5 = this._md5,
|
||||
_sha1 = this._sha1,
|
||||
_sha256 = this._sha256,
|
||||
_sha384 = this._sha384,
|
||||
_sha512 = this._sha512,
|
||||
_spamsum = this._spamsum,
|
||||
MergeTag = this.MergeTag,
|
||||
Region = this.Region,
|
||||
Offset = this.Offset,
|
||||
Date = this.Date,
|
||||
ItemStatus = this.ItemStatus,
|
||||
Optional = this.Optional,
|
||||
Inverted = this.Inverted,
|
||||
|
||||
AltName = this.AltName,
|
||||
AltTitle = this.AltTitle,
|
||||
|
||||
MIA = this.MIA,
|
||||
|
||||
Original = this.Original,
|
||||
OpenMSXSubType = this.OpenMSXSubType,
|
||||
OpenMSXType = this.OpenMSXType,
|
||||
Remark = this.Remark,
|
||||
Boot = this.Boot,
|
||||
|
||||
_rom = this._rom?.Clone() as Models.Internal.Rom ?? new Models.Internal.Rom(),
|
||||
|
||||
DataArea = this.DataArea,
|
||||
LoadFlag = this.LoadFlag,
|
||||
Part = this.Part,
|
||||
Value = this.Value,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -471,13 +530,13 @@ namespace SabreTools.DatItems.Formats
|
||||
Parent = this.Machine?.Name,
|
||||
Date = this.Date,
|
||||
Size = this.Size,
|
||||
CRC = this._crc,
|
||||
MD5 = this._md5,
|
||||
SHA1 = this._sha1,
|
||||
SHA256 = this._sha256,
|
||||
SHA384 = this._sha384,
|
||||
SHA512 = this._sha512,
|
||||
SpamSum = this._spamsum,
|
||||
CRC = Utilities.StringToByteArray(this.CRC),
|
||||
MD5 = Utilities.StringToByteArray(this.MD5),
|
||||
SHA1 = Utilities.StringToByteArray(this.SHA1),
|
||||
SHA256 = Utilities.StringToByteArray(this.SHA256),
|
||||
SHA384 = Utilities.StringToByteArray(this.SHA384),
|
||||
SHA512 = Utilities.StringToByteArray(this.SHA512),
|
||||
SpamSum = Utilities.StringToByteArray(this.SpamSum),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -486,38 +545,14 @@ namespace SabreTools.DatItems.Formats
|
||||
#region Comparision Methods
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Equals(DatItem other)
|
||||
public override bool Equals(DatItem? other)
|
||||
{
|
||||
bool dupefound = false;
|
||||
// If we don't have a Rom, return false
|
||||
if (ItemType != other?.ItemType || other is not Rom otherInternal)
|
||||
return false;
|
||||
|
||||
// If we don't have a rom, return false
|
||||
if (ItemType != other.ItemType)
|
||||
return dupefound;
|
||||
|
||||
// Otherwise, treat it as a Rom
|
||||
Rom newOther = other as Rom;
|
||||
|
||||
// If all hashes are empty but they're both nodump and the names match, then they're dupes
|
||||
if ((ItemStatus == ItemStatus.Nodump && newOther.ItemStatus == ItemStatus.Nodump)
|
||||
&& Name == newOther.Name
|
||||
&& !HasHashes() && !newOther.HasHashes())
|
||||
{
|
||||
dupefound = true;
|
||||
}
|
||||
|
||||
// If we have a file that has no known size, rely on the hashes only
|
||||
else if (Size == null && HashMatch(newOther))
|
||||
{
|
||||
dupefound = true;
|
||||
}
|
||||
|
||||
// Otherwise if we get a partial match
|
||||
else if (Size == newOther.Size && HashMatch(newOther))
|
||||
{
|
||||
dupefound = true;
|
||||
}
|
||||
|
||||
return dupefound;
|
||||
// Compare the internal models
|
||||
return _rom.EqualTo(otherInternal._rom);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -529,26 +564,26 @@ namespace SabreTools.DatItems.Formats
|
||||
if (Size == null && other.Size != null)
|
||||
Size = other.Size;
|
||||
|
||||
if (_crc.IsNullOrEmpty() && !other._crc.IsNullOrEmpty())
|
||||
_crc = other._crc;
|
||||
if (string.IsNullOrWhiteSpace(CRC) && !string.IsNullOrWhiteSpace(other.CRC))
|
||||
CRC = other.CRC;
|
||||
|
||||
if (_md5.IsNullOrEmpty() && !other._md5.IsNullOrEmpty())
|
||||
_md5 = other._md5;
|
||||
if (string.IsNullOrWhiteSpace(MD5) && !string.IsNullOrWhiteSpace(other.MD5))
|
||||
MD5 = other.MD5;
|
||||
|
||||
if (_sha1.IsNullOrEmpty() && !other._sha1.IsNullOrEmpty())
|
||||
_sha1 = other._sha1;
|
||||
if (string.IsNullOrWhiteSpace(SHA1) && !string.IsNullOrWhiteSpace(other.SHA1))
|
||||
SHA1 = other.SHA1;
|
||||
|
||||
if (_sha256.IsNullOrEmpty() && !other._sha256.IsNullOrEmpty())
|
||||
_sha256 = other._sha256;
|
||||
if (string.IsNullOrWhiteSpace(SHA256) && !string.IsNullOrWhiteSpace(other.SHA256))
|
||||
SHA256 = other.SHA256;
|
||||
|
||||
if (_sha384.IsNullOrEmpty() && !other._sha384.IsNullOrEmpty())
|
||||
_sha384 = other._sha384;
|
||||
if (string.IsNullOrWhiteSpace(SHA384) && !string.IsNullOrWhiteSpace(other.SHA384))
|
||||
SHA384 = other.SHA384;
|
||||
|
||||
if (_sha512.IsNullOrEmpty() && !other._sha512.IsNullOrEmpty())
|
||||
_sha512 = other._sha512;
|
||||
if (string.IsNullOrWhiteSpace(SHA512) && !string.IsNullOrWhiteSpace(other.SHA512))
|
||||
SHA512 = other.SHA512;
|
||||
|
||||
if (_spamsum.IsNullOrEmpty() && !other._spamsum.IsNullOrEmpty())
|
||||
_spamsum = other._spamsum;
|
||||
if (string.IsNullOrWhiteSpace(SpamSum) && !string.IsNullOrWhiteSpace(other.SpamSum))
|
||||
SpamSum = other.SpamSum;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -557,19 +592,19 @@ namespace SabreTools.DatItems.Formats
|
||||
/// <returns>String representing the suffix</returns>
|
||||
public string GetDuplicateSuffix()
|
||||
{
|
||||
if (!_crc.IsNullOrEmpty())
|
||||
if (!string.IsNullOrWhiteSpace(CRC))
|
||||
return $"_{CRC}";
|
||||
else if (!_md5.IsNullOrEmpty())
|
||||
else if (!string.IsNullOrWhiteSpace(MD5))
|
||||
return $"_{MD5}";
|
||||
else if (!_sha1.IsNullOrEmpty())
|
||||
else if (!string.IsNullOrWhiteSpace(SHA1))
|
||||
return $"_{SHA1}";
|
||||
else if (!_sha256.IsNullOrEmpty())
|
||||
else if (!string.IsNullOrWhiteSpace(SHA256))
|
||||
return $"_{SHA256}";
|
||||
else if (!_sha384.IsNullOrEmpty())
|
||||
else if (!string.IsNullOrWhiteSpace(SHA384))
|
||||
return $"_{SHA384}";
|
||||
else if (!_sha512.IsNullOrEmpty())
|
||||
else if (!string.IsNullOrWhiteSpace(SHA512))
|
||||
return $"_{SHA512}";
|
||||
else if (!_spamsum.IsNullOrEmpty())
|
||||
else if (!string.IsNullOrWhiteSpace(SpamSum))
|
||||
return $"_{SpamSum}";
|
||||
else
|
||||
return "_1";
|
||||
@@ -579,72 +614,13 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Returns if the Rom contains any hashes
|
||||
/// </summary>
|
||||
/// <returns>True if any hash exists, false otherwise</returns>
|
||||
public bool HasHashes()
|
||||
{
|
||||
return !_crc.IsNullOrEmpty()
|
||||
|| !_md5.IsNullOrEmpty()
|
||||
|| !_sha1.IsNullOrEmpty()
|
||||
|| !_sha256.IsNullOrEmpty()
|
||||
|| !_sha384.IsNullOrEmpty()
|
||||
|| !_sha512.IsNullOrEmpty()
|
||||
|| !_spamsum.IsNullOrEmpty();
|
||||
}
|
||||
public bool HasHashes() => _rom.HasHashes();
|
||||
|
||||
/// <summary>
|
||||
/// Returns if all of the hashes are set to their 0-byte values
|
||||
/// </summary>
|
||||
/// <returns>True if any hash matches the 0-byte value, false otherwise</returns>
|
||||
public bool HasZeroHash()
|
||||
{
|
||||
return (_crc != null && _crc.SequenceEqual(Constants.CRCZeroBytes))
|
||||
|| (_md5 != null && _md5.SequenceEqual(Constants.MD5ZeroBytes))
|
||||
|| (_sha1 != null && _sha1.SequenceEqual(Constants.SHA1ZeroBytes))
|
||||
|| (_sha256 != null && _sha256.SequenceEqual(Constants.SHA256ZeroBytes))
|
||||
|| (_sha384 != null && _sha384.SequenceEqual(Constants.SHA384ZeroBytes))
|
||||
|| (_sha512 != null && _sha512.SequenceEqual(Constants.SHA512ZeroBytes))
|
||||
|| (_spamsum != null && _spamsum.SequenceEqual(Constants.SpamSumZeroBytes));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns if there are no, non-empty hashes in common with another Rom
|
||||
/// </summary>
|
||||
/// <param name="other">Rom to compare against</param>
|
||||
/// <returns>True if at least one hash is not mutually exclusive, false otherwise</returns>
|
||||
private bool HasCommonHash(Rom other)
|
||||
{
|
||||
return !(_crc.IsNullOrEmpty() ^ other._crc.IsNullOrEmpty())
|
||||
|| !(_md5.IsNullOrEmpty() ^ other._md5.IsNullOrEmpty())
|
||||
|| !(_sha1.IsNullOrEmpty() ^ other._sha1.IsNullOrEmpty())
|
||||
|| !(_sha256.IsNullOrEmpty() ^ other._sha256.IsNullOrEmpty())
|
||||
|| !(_sha384.IsNullOrEmpty() ^ other._sha384.IsNullOrEmpty())
|
||||
|| !(_sha512.IsNullOrEmpty() ^ other._sha512.IsNullOrEmpty())
|
||||
|| !(_spamsum.IsNullOrEmpty() ^ other._spamsum.IsNullOrEmpty());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns if any hashes are common with another Rom
|
||||
/// </summary>
|
||||
/// <param name="other">Rom to compare against</param>
|
||||
/// <returns>True if any hashes are in common, false otherwise</returns>
|
||||
private bool HashMatch(Rom other)
|
||||
{
|
||||
// If either have no hashes, we return false, otherwise this would be a false positive
|
||||
if (!HasHashes() || !other.HasHashes())
|
||||
return false;
|
||||
|
||||
// If neither have hashes in common, we return false, otherwise this would be a false positive
|
||||
if (!HasCommonHash(other))
|
||||
return false;
|
||||
|
||||
// Return if all hashes match according to merge rules
|
||||
return ConditionalHashEquals(_crc, other._crc)
|
||||
&& ConditionalHashEquals(_md5, other._md5)
|
||||
&& ConditionalHashEquals(_sha1, other._sha1)
|
||||
&& ConditionalHashEquals(_sha256, other._sha256)
|
||||
&& ConditionalHashEquals(_sha384, other._sha384)
|
||||
&& ConditionalHashEquals(_sha512, other._sha512)
|
||||
&& ConditionalHashEquals(_spamsum, other._spamsum);
|
||||
}
|
||||
public bool HasZeroHash() => _rom.HasZeroHash();
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -654,7 +630,7 @@ namespace SabreTools.DatItems.Formats
|
||||
public override string GetKey(ItemKey bucketedBy, bool lower = true, bool norename = true)
|
||||
{
|
||||
// Set the output key as the default blank string
|
||||
string key;
|
||||
string? key;
|
||||
|
||||
// Now determine what the key should be based on the bucketedBy value
|
||||
switch (bucketedBy)
|
||||
|
||||
@@ -16,17 +16,27 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Name of the item
|
||||
/// </summary>
|
||||
[JsonProperty("name"), XmlElement("name")]
|
||||
public string Name { get; set; }
|
||||
public string? Name
|
||||
{
|
||||
get => _sample.ReadString(Models.Internal.Sample.NameKey);
|
||||
set => _sample[Models.Internal.Sample.NameKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Internal Sample model
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
private Models.Internal.Sample _sample = new();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Accessors
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string GetName() => Name;
|
||||
public override string? GetName() => Name;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void SetName(string name) => Name = name;
|
||||
public override void SetName(string? name) => Name = name;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -53,11 +63,11 @@ namespace SabreTools.DatItems.Formats
|
||||
ItemType = this.ItemType,
|
||||
DupeType = this.DupeType,
|
||||
|
||||
Machine = this.Machine.Clone() as Machine,
|
||||
Source = this.Source.Clone() as Source,
|
||||
Machine = this.Machine?.Clone() as Machine,
|
||||
Source = this.Source?.Clone() as Source,
|
||||
Remove = this.Remove,
|
||||
|
||||
Name = this.Name,
|
||||
_sample = this._sample?.Clone() as Models.Internal.Sample ?? new Models.Internal.Sample(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -66,17 +76,14 @@ namespace SabreTools.DatItems.Formats
|
||||
#region Comparision Methods
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Equals(DatItem other)
|
||||
public override bool Equals(DatItem? other)
|
||||
{
|
||||
// If we don't have a sample, return false
|
||||
if (ItemType != other.ItemType)
|
||||
// If we don't have a Sample, return false
|
||||
if (ItemType != other?.ItemType || other is not Sample otherInternal)
|
||||
return false;
|
||||
|
||||
// Otherwise, treat it as a Sample
|
||||
Sample newOther = other as Sample;
|
||||
|
||||
// If the archive information matches
|
||||
return (Name == newOther.Name);
|
||||
// Compare the internal models
|
||||
return _sample.EqualTo(otherInternal._sample);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -17,85 +17,85 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Digital serial 1 value
|
||||
/// </summary>
|
||||
[JsonProperty("digital_serial1", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("digital_serial1")]
|
||||
public string DigitalSerial1 { get; set; }
|
||||
public string? DigitalSerial1 { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Digital serial 2 value
|
||||
/// </summary>
|
||||
[JsonProperty("digital_serial2", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("digital_serial2")]
|
||||
public string DigitalSerial2 { get; set; }
|
||||
public string? DigitalSerial2 { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Media serial 1 value
|
||||
/// </summary>
|
||||
[JsonProperty("media_serial1", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("media_serial1")]
|
||||
public string MediaSerial1 { get; set; }
|
||||
public string? MediaSerial1 { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Media serial 2 value
|
||||
/// </summary>
|
||||
[JsonProperty("media_serial2", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("media_serial2")]
|
||||
public string MediaSerial2 { get; set; }
|
||||
public string? MediaSerial2 { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Media serial 3 value
|
||||
/// </summary>
|
||||
[JsonProperty("media_serial3", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("media_serial3")]
|
||||
public string MediaSerial3 { get; set; }
|
||||
public string? MediaSerial3 { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// PCB serial value
|
||||
/// </summary>
|
||||
[JsonProperty("pcb_serial", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("pcb_serial")]
|
||||
public string PcbSerial { get; set; }
|
||||
public string? PcbSerial { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Rom chip serial 1 value
|
||||
/// </summary>
|
||||
[JsonProperty("romchip_serial1", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("romchip_serial1")]
|
||||
public string RomChipSerial1 { get; set; }
|
||||
public string? RomChipSerial1 { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Rom chip serial 2 value
|
||||
/// </summary>
|
||||
[JsonProperty("romchip_serial2", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("romchip_serial2")]
|
||||
public string RomChipSerial2 { get; set; }
|
||||
public string? RomChipSerial2 { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Lockout serial value
|
||||
/// </summary>
|
||||
[JsonProperty("lockout_serial", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("lockout_serial")]
|
||||
public string LockoutSerial { get; set; }
|
||||
public string? LockoutSerial { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Save chip serial value
|
||||
/// </summary>
|
||||
[JsonProperty("savechip_serial", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("savechip_serial")]
|
||||
public string SaveChipSerial { get; set; }
|
||||
public string? SaveChipSerial { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Chip serial value
|
||||
/// </summary>
|
||||
[JsonProperty("chip_serial", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("chip_serial")]
|
||||
public string ChipSerial { get; set; }
|
||||
public string? ChipSerial { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Box serial value
|
||||
/// </summary>
|
||||
[JsonProperty("box_serial", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("box_serial")]
|
||||
public string BoxSerial { get; set; }
|
||||
public string? BoxSerial { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Media stamp value
|
||||
/// </summary>
|
||||
[JsonProperty("mediastamp", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("mediastamp")]
|
||||
public string MediaStamp { get; set; }
|
||||
public string? MediaStamp { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Box barcode value
|
||||
/// </summary>
|
||||
[JsonProperty("box_barcode", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("box_barcode")]
|
||||
public string BoxBarcode { get; set; }
|
||||
public string? BoxBarcode { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -121,8 +121,8 @@ namespace SabreTools.DatItems.Formats
|
||||
ItemType = this.ItemType,
|
||||
DupeType = this.DupeType,
|
||||
|
||||
Machine = this.Machine.Clone() as Machine,
|
||||
Source = this.Source.Clone() as Source,
|
||||
Machine = this.Machine?.Clone() as Machine,
|
||||
Source = this.Source?.Clone() as Source,
|
||||
Remove = this.Remove,
|
||||
|
||||
DigitalSerial1 = this.DigitalSerial1,
|
||||
@@ -147,17 +147,17 @@ namespace SabreTools.DatItems.Formats
|
||||
#region Comparision Methods
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Equals(DatItem other)
|
||||
public override bool Equals(DatItem? other)
|
||||
{
|
||||
// If we don't have a Serials, return false
|
||||
if (ItemType != other.ItemType)
|
||||
if (ItemType != other?.ItemType)
|
||||
return false;
|
||||
|
||||
// Otherwise, treat it as a Serials
|
||||
Serials newOther = other as Serials;
|
||||
Serials? newOther = other as Serials;
|
||||
|
||||
// If the Serials information matches
|
||||
return (DigitalSerial1 == newOther.DigitalSerial1
|
||||
return (DigitalSerial1 == newOther!.DigitalSerial1
|
||||
&& DigitalSerial2 == newOther.DigitalSerial2
|
||||
&& MediaSerial1 == newOther.MediaSerial1
|
||||
&& MediaSerial2 == newOther.MediaSerial2
|
||||
|
||||
@@ -1,127 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Xml.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
using SabreTools.Core;
|
||||
|
||||
namespace SabreTools.DatItems.Formats
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents one ListXML confsetting or dipvalue
|
||||
/// </summary>
|
||||
[JsonObject("setting"), XmlRoot("setting")]
|
||||
public class Setting : DatItem
|
||||
{
|
||||
#region Fields
|
||||
|
||||
/// <summary>
|
||||
/// Setting name
|
||||
/// </summary>
|
||||
[JsonProperty("name"), XmlElement("name")]
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Setting value
|
||||
/// </summary>
|
||||
[JsonProperty("value", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("value")]
|
||||
public string Value { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Determines if the setting is default or not
|
||||
/// </summary>
|
||||
[JsonProperty("default", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("default")]
|
||||
public bool? Default { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public bool DefaultSpecified { get { return Default != null; } }
|
||||
|
||||
/// <summary>
|
||||
/// List of conditions on the setting
|
||||
/// </summary>
|
||||
[JsonProperty("conditions", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("conditions")]
|
||||
public List<Condition> Conditions { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public bool ConditionsSpecified { get { return Conditions != null && Conditions.Count > 0; } }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Accessors
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string GetName() => Name;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void SetName(string name) => Name = name;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Create a default, empty Setting object
|
||||
/// </summary>
|
||||
public Setting()
|
||||
{
|
||||
Name = string.Empty;
|
||||
ItemType = ItemType.Setting;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Cloning Methods
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override object Clone()
|
||||
{
|
||||
return new Setting()
|
||||
{
|
||||
ItemType = this.ItemType,
|
||||
DupeType = this.DupeType,
|
||||
|
||||
Machine = this.Machine.Clone() as Machine,
|
||||
Source = this.Source.Clone() as Source,
|
||||
Remove = this.Remove,
|
||||
|
||||
Name = this.Name,
|
||||
Value = this.Value,
|
||||
Default = this.Default,
|
||||
Conditions = this.Conditions,
|
||||
};
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Comparision Methods
|
||||
|
||||
/// <inheritdoc/>
|
||||
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
|
||||
&& Value == newOther.Value
|
||||
&& Default == newOther.Default);
|
||||
if (!match)
|
||||
return match;
|
||||
|
||||
// If the conditions match
|
||||
if (ConditionsSpecified)
|
||||
{
|
||||
foreach (Condition condition in Conditions)
|
||||
{
|
||||
match &= newOther.Conditions.Contains(condition);
|
||||
}
|
||||
}
|
||||
|
||||
return match;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -16,23 +16,37 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Name of the item
|
||||
/// </summary>
|
||||
[JsonProperty("name"), XmlElement("name")]
|
||||
public string Name { get; set; }
|
||||
public string? Name
|
||||
{
|
||||
get => _sharedFeat.ReadString(Models.Internal.SharedFeat.NameKey);
|
||||
set => _sharedFeat[Models.Internal.SharedFeat.NameKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// SharedFeature value
|
||||
/// </summary>
|
||||
[JsonProperty("value"), XmlElement("value")]
|
||||
public string Value { get; set; }
|
||||
public string? Value
|
||||
{
|
||||
get => _sharedFeat.ReadString(Models.Internal.SharedFeat.ValueKey);
|
||||
set => _sharedFeat[Models.Internal.SharedFeat.ValueKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Internal SharedFeat model
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
private Models.Internal.SharedFeat _sharedFeat = new();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Accessors
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string GetName() => Name;
|
||||
public override string? GetName() => Name;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void SetName(string name) => Name = name;
|
||||
public override void SetName(string? name) => Name = name;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -59,12 +73,11 @@ namespace SabreTools.DatItems.Formats
|
||||
ItemType = this.ItemType,
|
||||
DupeType = this.DupeType,
|
||||
|
||||
Machine = this.Machine.Clone() as Machine,
|
||||
Source = this.Source.Clone() as Source,
|
||||
Machine = this.Machine?.Clone() as Machine,
|
||||
Source = this.Source?.Clone() as Source,
|
||||
Remove = this.Remove,
|
||||
|
||||
Name = this.Name,
|
||||
Value = this.Value,
|
||||
_sharedFeat = this._sharedFeat?.Clone() as Models.Internal.SharedFeat ?? new Models.Internal.SharedFeat(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -73,18 +86,14 @@ namespace SabreTools.DatItems.Formats
|
||||
#region Comparision Methods
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Equals(DatItem other)
|
||||
public override bool Equals(DatItem? other)
|
||||
{
|
||||
// If we don't have a sample, return false
|
||||
if (ItemType != other.ItemType)
|
||||
// If we don't have a SharedFeature, return false
|
||||
if (ItemType != other?.ItemType || other is not SharedFeature otherInternal)
|
||||
return false;
|
||||
|
||||
// Otherwise, treat it as a SharedFeature
|
||||
SharedFeature newOther = other as SharedFeature;
|
||||
|
||||
// If the archive information matches
|
||||
return (Name == newOther.Name
|
||||
&& Value == newOther.Value);
|
||||
// Compare the internal models
|
||||
return _sharedFeat.EqualTo(otherInternal._sharedFeat);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Xml.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
using SabreTools.Core;
|
||||
@@ -17,26 +18,40 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Name of the item
|
||||
/// </summary>
|
||||
[JsonProperty("name"), XmlElement("name")]
|
||||
public string Name { get; set; }
|
||||
public string? Name
|
||||
{
|
||||
get => _slot.ReadString(Models.Internal.Slot.NameKey);
|
||||
set => _slot[Models.Internal.Slot.NameKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Slot options associated with the slot
|
||||
/// </summary>
|
||||
[JsonProperty("slotoptions", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("slotoptions")]
|
||||
public List<SlotOption> SlotOptions { get; set; }
|
||||
public List<SlotOption>? SlotOptions
|
||||
{
|
||||
get => _slot.Read<SlotOption[]>(Models.Internal.Slot.SlotOptionKey)?.ToList();
|
||||
set => _slot[Models.Internal.Slot.SlotOptionKey] = value?.ToArray();
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool SlotOptionsSpecified { get { return SlotOptions != null && SlotOptions.Count > 0; } }
|
||||
|
||||
/// <summary>
|
||||
/// Internal Slot model
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
private Models.Internal.Slot _slot = new();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Accessors
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string GetName() => Name;
|
||||
public override string? GetName() => Name;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void SetName(string name) => Name = name;
|
||||
public override void SetName(string? name) => Name = name;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -63,12 +78,11 @@ namespace SabreTools.DatItems.Formats
|
||||
ItemType = this.ItemType,
|
||||
DupeType = this.DupeType,
|
||||
|
||||
Machine = this.Machine.Clone() as Machine,
|
||||
Source = this.Source.Clone() as Source,
|
||||
Machine = this.Machine?.Clone() as Machine,
|
||||
Source = this.Source?.Clone() as Source,
|
||||
Remove = this.Remove,
|
||||
|
||||
Name = this.Name,
|
||||
SlotOptions = this.SlotOptions,
|
||||
_slot = this._slot?.Clone() as Models.Internal.Slot ?? new Models.Internal.Slot(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -77,30 +91,14 @@ namespace SabreTools.DatItems.Formats
|
||||
#region Comparision Methods
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Equals(DatItem other)
|
||||
public override bool Equals(DatItem? other)
|
||||
{
|
||||
// If we don't have a Slot, return false
|
||||
if (ItemType != other.ItemType)
|
||||
if (ItemType != other?.ItemType || other is not Slot otherInternal)
|
||||
return false;
|
||||
|
||||
// Otherwise, treat it as a Slot
|
||||
Slot newOther = other as Slot;
|
||||
|
||||
// If the Slot information matches
|
||||
bool match = (Name == newOther.Name);
|
||||
if (!match)
|
||||
return match;
|
||||
|
||||
// If the slot options match
|
||||
if (SlotOptionsSpecified)
|
||||
{
|
||||
foreach (SlotOption slotOption in SlotOptions)
|
||||
{
|
||||
match &= newOther.SlotOptions.Contains(slotOption);
|
||||
}
|
||||
}
|
||||
|
||||
return match;
|
||||
// Compare the internal models
|
||||
return _slot.EqualTo(otherInternal._slot);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -16,32 +16,50 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Slot option name
|
||||
/// </summary>
|
||||
[JsonProperty("name"), XmlElement("name")]
|
||||
public string Name { get; set; }
|
||||
public string? Name
|
||||
{
|
||||
get => _slotOption.ReadString(Models.Internal.SlotOption.NameKey);
|
||||
set => _slotOption[Models.Internal.SlotOption.NameKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Referenced device name
|
||||
/// </summary>
|
||||
[JsonProperty("devname"), XmlElement("devname")]
|
||||
public string DeviceName { get; set; }
|
||||
public string? DeviceName
|
||||
{
|
||||
get => _slotOption.ReadString(Models.Internal.SlotOption.DevNameKey);
|
||||
set => _slotOption[Models.Internal.SlotOption.DevNameKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines if this slot option is default or not
|
||||
/// </summary>
|
||||
[JsonProperty("default", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("default")]
|
||||
public bool? Default { get; set; }
|
||||
public bool? Default
|
||||
{
|
||||
get => _slotOption.ReadBool(Models.Internal.SlotOption.DefaultKey);
|
||||
set => _slotOption[Models.Internal.SlotOption.DefaultKey] = value;
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool DefaultSpecified { get { return Default != null; } }
|
||||
|
||||
/// <summary>
|
||||
/// Internal SlotOption model
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
private Models.Internal.SlotOption _slotOption = new();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Accessors
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string GetName() => Name;
|
||||
public override string? GetName() => Name;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void SetName(string name) => Name = name;
|
||||
public override void SetName(string? name) => Name = name;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -68,13 +86,11 @@ namespace SabreTools.DatItems.Formats
|
||||
ItemType = this.ItemType,
|
||||
DupeType = this.DupeType,
|
||||
|
||||
Machine = this.Machine.Clone() as Machine,
|
||||
Source = this.Source.Clone() as Source,
|
||||
Machine = this.Machine?.Clone() as Machine,
|
||||
Source = this.Source?.Clone() as Source,
|
||||
Remove = this.Remove,
|
||||
|
||||
Name = this.Name,
|
||||
DeviceName = this.DeviceName,
|
||||
Default = this.Default,
|
||||
_slotOption = this._slotOption?.Clone() as Models.Internal.SlotOption ?? new Models.Internal.SlotOption(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -83,19 +99,14 @@ namespace SabreTools.DatItems.Formats
|
||||
#region Comparision Methods
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Equals(DatItem other)
|
||||
public override bool Equals(DatItem? other)
|
||||
{
|
||||
// If we don't have a SlotOption, return false
|
||||
if (ItemType != other.ItemType)
|
||||
// If we don't have a Adjuster, return false
|
||||
if (ItemType != other?.ItemType || other is not SlotOption otherInternal)
|
||||
return false;
|
||||
|
||||
// Otherwise, treat it as a SlotOption
|
||||
SlotOption newOther = other as SlotOption;
|
||||
|
||||
// If the SlotOption information matches
|
||||
return (Name == newOther.Name
|
||||
&& DeviceName == newOther.DeviceName
|
||||
&& Default == newOther.Default);
|
||||
// Compare the internal models
|
||||
return _slotOption.EqualTo(otherInternal._slotOption);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
using System.Xml.Serialization;
|
||||
|
||||
using SabreTools.Core;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using SabreTools.Core;
|
||||
using SabreTools.Core.Tools;
|
||||
|
||||
namespace SabreTools.DatItems.Formats
|
||||
{
|
||||
@@ -22,14 +22,22 @@ namespace SabreTools.DatItems.Formats
|
||||
/// </summary>
|
||||
[JsonProperty("tag", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
[XmlElement("tag")]
|
||||
public string Tag { get; set; }
|
||||
public string? Tag
|
||||
{
|
||||
get => _softwareList.ReadString(Models.Internal.SoftwareList.TagKey);
|
||||
set => _softwareList[Models.Internal.SoftwareList.TagKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Name of the item
|
||||
/// </summary>
|
||||
[JsonProperty("name")]
|
||||
[XmlElement("name")]
|
||||
public string Name { get; set; }
|
||||
public string? Name
|
||||
{
|
||||
get => _softwareList.ReadString(Models.Internal.SoftwareList.NameKey);
|
||||
set => _softwareList[Models.Internal.SoftwareList.NameKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Status of the softare list according to the machine
|
||||
@@ -37,7 +45,11 @@ namespace SabreTools.DatItems.Formats
|
||||
[JsonProperty("status", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
[XmlElement("status")]
|
||||
public SoftwareListStatus Status { get; set; }
|
||||
public SoftwareListStatus Status
|
||||
{
|
||||
get => _softwareList.ReadString(Models.Internal.SoftwareList.StatusKey).AsSoftwareListStatus();
|
||||
set => _softwareList[Models.Internal.SoftwareList.StatusKey] = value.FromSoftwareListStatus();
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool StatusSpecified { get { return Status != SoftwareListStatus.None; } }
|
||||
@@ -47,17 +59,27 @@ namespace SabreTools.DatItems.Formats
|
||||
/// </summary>
|
||||
[JsonProperty("filter", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
[XmlElement("filter")]
|
||||
public string Filter { get; set; }
|
||||
public string? Filter
|
||||
{
|
||||
get => _softwareList.ReadString(Models.Internal.SoftwareList.FilterKey);
|
||||
set => _softwareList[Models.Internal.SoftwareList.FilterKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Internal SoftwareList model
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
private Models.Internal.SoftwareList _softwareList = new();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Accessors
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string GetName() => Name;
|
||||
public override string? GetName() => Name;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void SetName(string name) => Name = name;
|
||||
public override void SetName(string? name) => Name = name;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -83,14 +105,11 @@ namespace SabreTools.DatItems.Formats
|
||||
ItemType = this.ItemType,
|
||||
DupeType = this.DupeType,
|
||||
|
||||
Machine = this.Machine.Clone() as Machine,
|
||||
Source = this.Source.Clone() as Source,
|
||||
Machine = this.Machine?.Clone() as Machine,
|
||||
Source = this.Source?.Clone() as Source,
|
||||
Remove = this.Remove,
|
||||
|
||||
Tag = this.Tag,
|
||||
Name = this.Name,
|
||||
Status = this.Status,
|
||||
Filter = this.Filter,
|
||||
_softwareList = this._softwareList?.Clone() as Models.Internal.SoftwareList ?? new Models.Internal.SoftwareList(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -98,20 +117,14 @@ namespace SabreTools.DatItems.Formats
|
||||
|
||||
#region Comparision Methods
|
||||
|
||||
public override bool Equals(DatItem other)
|
||||
public override bool Equals(DatItem? other)
|
||||
{
|
||||
// If we don't have a sample, return false
|
||||
if (ItemType != other.ItemType)
|
||||
// If we don't have a Adjuster, return false
|
||||
if (ItemType != other?.ItemType || other is not SoftwareList otherInternal)
|
||||
return false;
|
||||
|
||||
// Otherwise, treat it as a SoftwareList
|
||||
SoftwareList newOther = other as SoftwareList;
|
||||
|
||||
// If the SoftwareList information matches
|
||||
return (Tag == newOther.Tag
|
||||
&& Name == newOther.Name
|
||||
&& Status == newOther.Status
|
||||
&& Filter == newOther.Filter);
|
||||
// Compare the internal models
|
||||
return _softwareList.EqualTo(otherInternal._softwareList);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -16,11 +16,21 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Number of speakers or channels
|
||||
/// </summary>
|
||||
[JsonProperty("channels", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("channels")]
|
||||
public long? Channels { get; set; }
|
||||
public long? Channels
|
||||
{
|
||||
get => _sound.ReadLong(Models.Internal.Sound.ChannelsKey);
|
||||
set => _sound[Models.Internal.Sound.ChannelsKey] = value;
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool ChannelsSpecified { get { return Channels != null; } }
|
||||
|
||||
/// <summary>
|
||||
/// Internal Sound model
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
private Models.Internal.Sound _sound = new();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
@@ -45,11 +55,11 @@ namespace SabreTools.DatItems.Formats
|
||||
ItemType = this.ItemType,
|
||||
DupeType = this.DupeType,
|
||||
|
||||
Machine = this.Machine.Clone() as Machine,
|
||||
Source = this.Source.Clone() as Source,
|
||||
Machine = this.Machine?.Clone() as Machine,
|
||||
Source = this.Source?.Clone() as Source,
|
||||
Remove = this.Remove,
|
||||
|
||||
Channels = this.Channels,
|
||||
_sound = this._sound?.Clone() as Models.Internal.Sound ?? new Models.Internal.Sound(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -58,17 +68,14 @@ namespace SabreTools.DatItems.Formats
|
||||
#region Comparision Methods
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Equals(DatItem other)
|
||||
public override bool Equals(DatItem? other)
|
||||
{
|
||||
// If we don't have a Sound, return false
|
||||
if (ItemType != other.ItemType)
|
||||
if (ItemType != other?.ItemType || other is not Sound otherInternal)
|
||||
return false;
|
||||
|
||||
// Otherwise, treat it as a Sound
|
||||
Sound newOther = other as Sound;
|
||||
|
||||
// If the Sound information matches
|
||||
return (Channels == newOther.Channels);
|
||||
// Compare the internal models
|
||||
return _sound.EqualTo(otherInternal._sound);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -18,121 +18,121 @@ namespace SabreTools.DatItems.Formats
|
||||
/// </summary>
|
||||
/// <remarks>TODO: Is this required?</remarks>
|
||||
[JsonProperty("id", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("id")]
|
||||
public string Id { get; set; }
|
||||
public string? Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Section value
|
||||
/// </summary>
|
||||
[JsonProperty("section", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("section")]
|
||||
public string Section { get; set; }
|
||||
public string? Section { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Rom info value
|
||||
/// </summary>
|
||||
[JsonProperty("rominfo", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("rominfo")]
|
||||
public string RomInfo { get; set; }
|
||||
public string? RomInfo { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Dumping date value
|
||||
/// </summary>
|
||||
[JsonProperty("d_date", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("d_date")]
|
||||
public string DDate { get; set; }
|
||||
public string? DDate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Dumping date info value
|
||||
/// </summary>
|
||||
[JsonProperty("d_date_info", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("d_date_info")]
|
||||
public string DDateInfo { get; set; }
|
||||
public string? DDateInfo { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Release date value
|
||||
/// </summary>
|
||||
[JsonProperty("r_date", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("r_date")]
|
||||
public string RDate { get; set; }
|
||||
public string? RDate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Release date info value
|
||||
/// </summary>
|
||||
[JsonProperty("r_date_info", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("r_date_info")]
|
||||
public string RDateInfo { get; set; }
|
||||
public string? RDateInfo { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Origin value
|
||||
/// </summary>
|
||||
[JsonProperty("origin", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("origin")]
|
||||
public string Origin { get; set; }
|
||||
public string? Origin { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Region value
|
||||
/// </summary>
|
||||
[JsonProperty("region", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("region")]
|
||||
public string Region { get; set; }
|
||||
public string? Region { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Media title value
|
||||
/// </summary>
|
||||
[JsonProperty("media_title", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("media_title")]
|
||||
public string MediaTitle { get; set; }
|
||||
public string? MediaTitle { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Dumper value
|
||||
/// </summary>
|
||||
[JsonProperty("dumper", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("dumper")]
|
||||
public string Dumper { get; set; }
|
||||
public string? Dumper { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Project value
|
||||
/// </summary>
|
||||
[JsonProperty("project", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("project")]
|
||||
public string Project { get; set; }
|
||||
public string? Project { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Original format value
|
||||
/// </summary>
|
||||
[JsonProperty("originalformat", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("originalformat")]
|
||||
public string OriginalFormat { get; set; }
|
||||
public string? OriginalFormat { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Nodump value
|
||||
/// </summary>
|
||||
[JsonProperty("nodump", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("nodump")]
|
||||
public string Nodump { get; set; }
|
||||
public string? Nodump { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Tool value
|
||||
/// </summary>
|
||||
[JsonProperty("tool", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("tool")]
|
||||
public string Tool { get; set; }
|
||||
public string? Tool { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Comment 1 value
|
||||
/// </summary>
|
||||
[JsonProperty("comment1", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("comment1")]
|
||||
public string Comment1 { get; set; }
|
||||
public string? Comment1 { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Link 2 value
|
||||
/// </summary>
|
||||
[JsonProperty("comment2", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("comment2")]
|
||||
public string Comment2 { get; set; }
|
||||
public string? Comment2 { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Link 1 value
|
||||
/// </summary>
|
||||
[JsonProperty("link1", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("link1")]
|
||||
public string Link1 { get; set; }
|
||||
public string? Link1 { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Link 2 value
|
||||
/// </summary>
|
||||
[JsonProperty("link2", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("link2")]
|
||||
public string Link2 { get; set; }
|
||||
public string? Link2 { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Link 3 value
|
||||
/// </summary>
|
||||
[JsonProperty("link3", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("link3")]
|
||||
public string Link3 { get; set; }
|
||||
public string? Link3 { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -158,8 +158,8 @@ namespace SabreTools.DatItems.Formats
|
||||
ItemType = this.ItemType,
|
||||
DupeType = this.DupeType,
|
||||
|
||||
Machine = this.Machine.Clone() as Machine,
|
||||
Source = this.Source.Clone() as Source,
|
||||
Machine = this.Machine?.Clone() as Machine,
|
||||
Source = this.Source?.Clone() as Source,
|
||||
Remove = this.Remove,
|
||||
|
||||
Id = this.Id,
|
||||
@@ -190,17 +190,17 @@ namespace SabreTools.DatItems.Formats
|
||||
#region Comparision Methods
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Equals(DatItem other)
|
||||
public override bool Equals(DatItem? other)
|
||||
{
|
||||
// If we don't have a SourceDetails, return false
|
||||
if (ItemType != other.ItemType)
|
||||
if (ItemType != other?.ItemType)
|
||||
return false;
|
||||
|
||||
// Otherwise, treat it as a SourceDetails
|
||||
SourceDetails newOther = other as SourceDetails;
|
||||
SourceDetails? newOther = other as SourceDetails;
|
||||
|
||||
// If the Details information matches
|
||||
return (Id == newOther.Id
|
||||
return (Id == newOther!.Id
|
||||
&& Section == newOther.Section
|
||||
&& RomInfo == newOther.RomInfo
|
||||
&& DDate == newOther.DDate
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace SabreTools.DatItems
|
||||
/// </summary>
|
||||
[JsonProperty("name", DefaultValueHandling = DefaultValueHandling.Include)]
|
||||
[XmlElement("name")]
|
||||
public string Name { get; set; } = null;
|
||||
public string? Name { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Additional notes
|
||||
@@ -30,63 +30,63 @@ namespace SabreTools.DatItems
|
||||
/// <remarks>Known as "Extra" in AttractMode</remarks>
|
||||
[JsonProperty("comment", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
[XmlElement("comment")]
|
||||
public string Comment { get; set; } = null;
|
||||
public string? Comment { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Extended description
|
||||
/// </summary>
|
||||
[JsonProperty("description", DefaultValueHandling = DefaultValueHandling.Include)]
|
||||
[XmlElement("description")]
|
||||
public string Description { get; set; } = null;
|
||||
public string? Description { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Year(s) of release/manufacture
|
||||
/// </summary>
|
||||
[JsonProperty("year", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
[XmlElement("year")]
|
||||
public string Year { get; set; } = null;
|
||||
public string? Year { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Manufacturer, if available
|
||||
/// </summary>
|
||||
[JsonProperty("manufacturer", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
[XmlElement("manufacturer")]
|
||||
public string Manufacturer { get; set; } = null;
|
||||
public string? Manufacturer { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Publisher, if available
|
||||
/// </summary>
|
||||
[JsonProperty("publisher", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
[XmlElement("publisher")]
|
||||
public string Publisher { get; set; } = null;
|
||||
public string? Publisher { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Category, if available
|
||||
/// </summary>
|
||||
[JsonProperty("category", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
[XmlElement("category")]
|
||||
public string Category { get; set; } = null;
|
||||
public string? Category { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// fomof parent
|
||||
/// </summary>
|
||||
[JsonProperty("romof", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
[XmlElement("romof")]
|
||||
public string RomOf { get; set; } = null;
|
||||
public string? RomOf { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// cloneof parent
|
||||
/// </summary>
|
||||
[JsonProperty("cloneof", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
[XmlElement("cloneof")]
|
||||
public string CloneOf { get; set; } = null;
|
||||
public string? CloneOf { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// sampleof parent
|
||||
/// </summary>
|
||||
[JsonProperty("sampleof", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
[XmlElement("sampleof")]
|
||||
public string SampleOf { get; set; } = null;
|
||||
public string? SampleOf { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Type of the machine
|
||||
@@ -109,49 +109,49 @@ namespace SabreTools.DatItems
|
||||
/// <remarks>Also in Logiqx EmuArc</remarks>
|
||||
[JsonProperty("players", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
[XmlElement("players")]
|
||||
public string Players { get; set; } = null;
|
||||
public string? Players { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Screen rotation
|
||||
/// </summary>
|
||||
[JsonProperty("rotation", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
[XmlElement("rotation")]
|
||||
public string Rotation { get; set; } = null;
|
||||
public string? Rotation { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Control method
|
||||
/// </summary>
|
||||
[JsonProperty("control", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
[XmlElement("control")]
|
||||
public string Control { get; set; } = null;
|
||||
public string? Control { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Support status
|
||||
/// </summary>
|
||||
[JsonProperty("status", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
[XmlElement("status")]
|
||||
public string Status { get; set; } = null;
|
||||
public string? Status { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Display count
|
||||
/// </summary>
|
||||
[JsonProperty("displaycount", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
[XmlElement("displaycount")]
|
||||
public string DisplayCount { get; set; } = null;
|
||||
public string? DisplayCount { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Display type
|
||||
/// </summary>
|
||||
[JsonProperty("displaytype", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
[XmlElement("displaytype")]
|
||||
public string DisplayType { get; set; } = null;
|
||||
public string? DisplayType { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Number of input buttons
|
||||
/// </summary>
|
||||
[JsonProperty("buttons", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
[XmlElement("buttons")]
|
||||
public string Buttons { get; set; } = null;
|
||||
public string? Buttons { get; set; } = null;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -162,7 +162,7 @@ namespace SabreTools.DatItems
|
||||
/// </summary>
|
||||
[JsonProperty("history", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
[XmlElement("history")]
|
||||
public string History { get; set; } = null;
|
||||
public string? History { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Emulator source file related to the machine
|
||||
@@ -170,7 +170,7 @@ namespace SabreTools.DatItems
|
||||
/// <remarks>Also in Logiqx</remarks>
|
||||
[JsonProperty("sourcefile", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
[XmlElement("sourcefile")]
|
||||
public string SourceFile { get; set; } = null;
|
||||
public string? SourceFile { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Machine runnable status
|
||||
@@ -192,28 +192,28 @@ namespace SabreTools.DatItems
|
||||
/// </summary>
|
||||
[JsonProperty("board", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
[XmlElement("board")]
|
||||
public string Board { get; set; } = null;
|
||||
public string? Board { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Rebuild location if different than machine name
|
||||
/// </summary>
|
||||
[JsonProperty("rebuildto", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
[XmlElement("rebuildto")]
|
||||
public string RebuildTo { get; set; } = null;
|
||||
public string? RebuildTo { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// No-Intro ID for the game
|
||||
/// </summary>
|
||||
[JsonProperty("nointroid", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
[XmlElement("nointroid")]
|
||||
public string NoIntroId { get; set; } = null;
|
||||
public string? NoIntroId { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// No-Intro ID for the game
|
||||
/// </summary>
|
||||
[JsonProperty("nointrocloneofid", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
[XmlElement("nointrocloneofid")]
|
||||
public string NoIntroCloneOfId { get; set; } = null;
|
||||
public string? NoIntroCloneOfId { get; set; } = null;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -225,49 +225,49 @@ namespace SabreTools.DatItems
|
||||
/// </summary>
|
||||
[JsonProperty("titleid", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
[XmlElement("titleid")]
|
||||
public string TitleID { get; set; } = null;
|
||||
public string? TitleID { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Machine developer
|
||||
/// </summary>
|
||||
[JsonProperty("developer", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
[XmlElement("developer")]
|
||||
public string Developer { get; set; } = null;
|
||||
public string? Developer { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Game genre
|
||||
/// </summary>
|
||||
[JsonProperty("genre", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
[XmlElement("genre")]
|
||||
public string Genre { get; set; } = null;
|
||||
public string? Genre { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Game subgenre
|
||||
/// </summary>
|
||||
[JsonProperty("subgenre", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
[XmlElement("subgenre")]
|
||||
public string Subgenre { get; set; } = null;
|
||||
public string? Subgenre { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Game ratings
|
||||
/// </summary>
|
||||
[JsonProperty("ratings", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
[XmlElement("ratings")]
|
||||
public string Ratings { get; set; } = null;
|
||||
public string? Ratings { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Game score
|
||||
/// </summary>
|
||||
[JsonProperty("score", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
[XmlElement("score")]
|
||||
public string Score { get; set; } = null;
|
||||
public string? Score { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Is the machine enabled
|
||||
/// </summary>
|
||||
[JsonProperty("enabled", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
[XmlElement("enabled")]
|
||||
public string Enabled { get; set; } = null; // bool?
|
||||
public string? Enabled { get; set; } = null; // bool?
|
||||
|
||||
/// <summary>
|
||||
/// Does the game have a CRC check
|
||||
@@ -284,7 +284,7 @@ namespace SabreTools.DatItems
|
||||
/// </summary>
|
||||
[JsonProperty("relatedto", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
[XmlElement("relatedto")]
|
||||
public string RelatedTo { get; set; } = null;
|
||||
public string? RelatedTo { get; set; } = null;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -295,21 +295,21 @@ namespace SabreTools.DatItems
|
||||
/// </summary>
|
||||
[JsonProperty("genmsxid", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
[XmlElement("genmsxid")]
|
||||
public string GenMSXID { get; set; } = null;
|
||||
public string? GenMSXID { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// MSX System
|
||||
/// </summary>
|
||||
[JsonProperty("system", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
[XmlElement("system")]
|
||||
public string System { get; set; } = null;
|
||||
public string? System { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Machine country of origin
|
||||
/// </summary>
|
||||
[JsonProperty("country", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
[XmlElement("country")]
|
||||
public string Country { get; set; } = null;
|
||||
public string? Country { get; set; } = null;
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -2,12 +2,14 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\SabreTools.Core\SabreTools.Core.csproj" />
|
||||
<ProjectReference Include="..\SabreTools.FileTypes\SabreTools.FileTypes.csproj" />
|
||||
<ProjectReference Include="..\SabreTools.Logging\SabreTools.Logging.csproj" />
|
||||
<ProjectReference Include="..\SabreTools.Models\SabreTools.Models.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -15,14 +15,14 @@ namespace SabreTools.DatItems
|
||||
/// <summary>
|
||||
/// Source name
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
public string? Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <param name="id">Source ID, default 0</param>
|
||||
/// <param name="source">Source name, default null</param>
|
||||
public Source(int id = 0, string source = null)
|
||||
public Source(int id = 0, string? source = null)
|
||||
{
|
||||
Index = id;
|
||||
Name = source;
|
||||
|
||||
Reference in New Issue
Block a user