DatItem formats to own sub-namespace

This commit is contained in:
Matt Nadareski
2021-02-02 10:23:43 -08:00
parent 11fd354a47
commit c54b35db92
76 changed files with 79 additions and 42 deletions

View File

@@ -0,0 +1,120 @@
using System.Collections.Generic;
using System.Xml.Serialization;
using SabreTools.Core;
using Newtonsoft.Json;
namespace SabreTools.DatItems.Formats
{
/// <summary>
/// Represents which Adjuster(s) is associated with a set
/// </summary>
[JsonObject("adjuster"), XmlRoot("adjuster")]
public class Adjuster : DatItem
{
#region Fields
/// <summary>
/// Name of the item
/// </summary>
[JsonProperty("name")]
[XmlElement("name")]
public string Name { get; set; }
/// <summary>
/// Determine whether the value is default
/// </summary>
[JsonProperty("default", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("default")]
public bool? Default { get; set; }
[JsonIgnore]
public bool DefaultSpecified { get { return Default != null; } }
/// <summary>
/// Conditions associated with the adjustment
/// </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 Adjuster object
/// </summary>
public Adjuster()
{
Name = string.Empty;
ItemType = ItemType.Adjuster;
}
#endregion
#region Cloning Methods
public override object Clone()
{
return new Adjuster()
{
ItemType = this.ItemType,
DupeType = this.DupeType,
Machine = this.Machine.Clone() as Machine,
Source = this.Source.Clone() as Source,
Remove = this.Remove,
Name = this.Name,
Default = this.Default,
Conditions = this.Conditions,
};
}
#endregion
#region Comparision Methods
public override bool Equals(DatItem other)
{
// If we don't have a Adjuster, return false
if (ItemType != other.ItemType)
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;
}
#endregion
}
}

View File

@@ -0,0 +1,73 @@
using System.Xml.Serialization;
using SabreTools.Core;
using Newtonsoft.Json;
namespace SabreTools.DatItems.Formats
{
/// <summary>
/// Represents a single analog item
/// </summary>
[JsonObject("analog"), XmlRoot("analog")]
public class Analog : DatItem
{
#region Fields
/// <summary>
/// Analog mask value
/// </summary>
[JsonProperty("mask", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("mask")]
public string Mask { get; set; }
#endregion
#region Constructors
/// <summary>
/// Create a default, empty Analog object
/// </summary>
public Analog()
{
ItemType = ItemType.Analog;
}
#endregion
#region Cloning Methods
public override object Clone()
{
return new Analog()
{
ItemType = this.ItemType,
DupeType = this.DupeType,
Machine = this.Machine.Clone() as Machine,
Source = this.Source.Clone() as Source,
Remove = this.Remove,
Mask = this.Mask,
};
}
#endregion
#region Comparision Methods
public override bool Equals(DatItem other)
{
// If we don't have a Analog, return false
if (ItemType != other.ItemType)
return false;
// Otherwise, treat it as a Analog
Analog newOther = other as Analog;
// If the Feature information matches
return (Mask == newOther.Mask);
}
#endregion
}
}

View File

@@ -0,0 +1,83 @@
using System.Xml.Serialization;
using SabreTools.Core;
using Newtonsoft.Json;
namespace SabreTools.DatItems.Formats
{
/// <summary>
/// Represents generic archive files to be included in a set
/// </summary>
[JsonObject("archive"), XmlRoot("archive")]
public class Archive : DatItem
{
#region Fields
/// <summary>
/// Name of the item
/// </summary>
[JsonProperty("name")]
[XmlElement("name")]
public string Name { get; set; }
#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 Archive object
/// </summary>
public Archive()
{
Name = string.Empty;
ItemType = ItemType.Archive;
}
#endregion
#region Cloning Methods
public override object Clone()
{
return new Archive()
{
ItemType = this.ItemType,
DupeType = this.DupeType,
Machine = this.Machine.Clone() as Machine,
Source = this.Source.Clone() as Source,
Remove = this.Remove,
Name = this.Name,
};
}
#endregion
#region Comparision Methods
public override bool Equals(DatItem other)
{
// If we don't have an archive, return false
if (ItemType != other.ItemType)
return false;
// Otherwise, treat it as an archive
Archive newOther = other as Archive;
// If the archive information matches
return (Name == newOther.Name);
}
#endregion
}
}

View File

@@ -0,0 +1,30 @@
using System.Xml.Serialization;
using Newtonsoft.Json;
/// <summary>
/// This holds all of the auxiliary types needed for proper parsing
/// </summary>
namespace SabreTools.DatItems.Formats
{
#region DatItem
#region OpenMSX
/// <summary>
/// Represents the OpenMSX original value
/// </summary>
[JsonObject("original"), XmlRoot("original")]
public class Original
{
[JsonProperty("value")]
public bool? Value { get; set; }
[JsonProperty("content")]
public string Content { get; set; }
}
#endregion
#endregion //DatItem
}

View File

@@ -0,0 +1,105 @@
using System.Xml.Serialization;
using SabreTools.Core;
using Newtonsoft.Json;
namespace SabreTools.DatItems.Formats
{
/// <summary>
/// Represents which BIOS(es) is associated with a set
/// </summary>
[JsonObject("biosset"), XmlRoot("biosset")]
public class BiosSet : DatItem
{
#region Fields
/// <summary>
/// Name of the item
/// </summary>
[JsonProperty("name")]
[XmlElement("name")]
public string Name { get; set; }
/// <summary>
/// Description of the BIOS
/// </summary>
[JsonProperty("description", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("description")]
public string Description { get; set; }
/// <summary>
/// Determine whether the BIOS is default
/// </summary>
[JsonProperty("default", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("default")]
public bool? Default { get; set; }
[JsonIgnore]
public bool DefaultSpecified { get { return Default != 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 BiosSet object
/// </summary>
public BiosSet()
{
Name = string.Empty;
ItemType = ItemType.BiosSet;
}
#endregion
#region Cloning Methods
public override object Clone()
{
return new BiosSet()
{
ItemType = this.ItemType,
DupeType = this.DupeType,
Machine = this.Machine.Clone() as Machine,
Source = this.Source.Clone() as Source,
Remove = this.Remove,
Name = this.Name,
Description = this.Description,
Default = this.Default,
};
}
#endregion
#region Comparision Methods
public override bool Equals(DatItem other)
{
// If we don't have a BiosSet, return false
if (ItemType != other.ItemType)
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);
}
#endregion
}
}

View File

@@ -0,0 +1,60 @@
using System.Xml.Serialization;
using SabreTools.Core;
using Newtonsoft.Json;
namespace SabreTools.DatItems.Formats
{
/// <summary>
/// Represents a blank set from an input DAT
/// </summary>
[JsonObject("blank"), XmlRoot("blank")]
public class Blank : DatItem
{
#region Constructors
/// <summary>
/// Create a default, empty Archive object
/// </summary>
public Blank()
{
ItemType = ItemType.Blank;
}
#endregion
#region Cloning Methods
public override object Clone()
{
return new Blank()
{
ItemType = this.ItemType,
DupeType = this.DupeType,
Machine = this.Machine.Clone() as Machine,
Source = this.Source.Clone() as Source,
Remove = this.Remove,
};
}
#endregion
#region Comparision Methods
public override bool Equals(DatItem other)
{
// If we don't have a blank, return false
if (ItemType != other.ItemType)
return false;
// Otherwise, treat it as a Blank
Blank newOther = other as Blank;
// If the archive information matches
return (Machine == newOther.Machine);
}
#endregion
}
}

View File

@@ -0,0 +1,119 @@
using System.Xml.Serialization;
using SabreTools.Core;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
namespace SabreTools.DatItems.Formats
{
/// <summary>
/// Represents which Chip(s) is associated with a set
/// </summary>
[JsonObject("chip"), XmlRoot("chip")]
public class Chip : DatItem
{
#region Fields
/// <summary>
/// Name of the item
/// </summary>
[JsonProperty("name")]
[XmlElement("name")]
public string Name { get; set; }
/// <summary>
/// Internal tag
/// </summary>
[JsonProperty("tag", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("tag")]
public string Tag { get; set; }
/// <summary>
/// Type of the chip
/// </summary>
[JsonProperty("type", DefaultValueHandling = DefaultValueHandling.Ignore)]
[JsonConverter(typeof(StringEnumConverter))]
[XmlElement("type")]
public ChipType ChipType { get; set; }
[JsonIgnore]
public bool ChipTypeSpecified { get { return ChipType != ChipType.NULL; } }
/// <summary>
/// Clock speed
/// </summary>
[JsonProperty("clock", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("clock")]
public long? Clock { get; set; }
[JsonIgnore]
public bool ClockTypeSpecified { get { return Clock != 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 Chip object
/// </summary>
public Chip()
{
Name = string.Empty;
ItemType = ItemType.Chip;
}
#endregion
#region Cloning Methods
public override object Clone()
{
return new Chip()
{
ItemType = this.ItemType,
DupeType = this.DupeType,
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,
};
}
#endregion
#region Comparision Methods
public override bool Equals(DatItem other)
{
// If we don't have a chip, return false
if (ItemType != other.ItemType)
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);
}
#endregion
}
}

View File

@@ -0,0 +1,105 @@
using System.Xml.Serialization;
using SabreTools.Core;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
namespace SabreTools.DatItems.Formats
{
/// <summary>
/// Represents a condition on a machine or other item
/// </summary>
[JsonObject("condition"), XmlRoot("condition")]
public class Condition : DatItem
{
#region Fields
/// <summary>
/// Condition tag value
/// </summary>
[JsonProperty("tag", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("tag")]
public string Tag { get; set; }
/// <summary>
/// Condition mask
/// </summary>
[JsonProperty("mask", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("mask")]
public string Mask { get; set; }
/// <summary>
/// Condition relationship
/// </summary>
[JsonProperty("relation", DefaultValueHandling = DefaultValueHandling.Ignore)]
[JsonConverter(typeof(StringEnumConverter))]
[XmlElement("relation")]
public Relation Relation { get; set; }
[JsonIgnore]
public bool RelationSpecified { get { return Relation != Relation.NULL; } }
/// <summary>
/// Condition value
/// </summary>
[JsonProperty("value", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("value")]
public string Value { get; set; }
#endregion
#region Constructors
/// <summary>
/// Create a default, empty Condition object
/// </summary>
public Condition()
{
ItemType = ItemType.Condition;
}
#endregion
#region Cloning Methods
public override object Clone()
{
return new Condition()
{
ItemType = this.ItemType,
DupeType = this.DupeType,
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,
};
}
#endregion
#region Comparision Methods
public override bool Equals(DatItem other)
{
// If we don't have a Condition, return false
if (ItemType != other.ItemType)
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);
}
#endregion
}
}

View File

@@ -0,0 +1,167 @@
using System.Collections.Generic;
using System.Xml.Serialization;
using SabreTools.Core;
using Newtonsoft.Json;
namespace SabreTools.DatItems.Formats
{
/// <summary>
/// Represents which Configuration(s) is associated with a set
/// </summary>
[JsonObject("configuration"), XmlRoot("configuration")]
public class Configuration : DatItem
{
#region Fields
/// <summary>
/// Name of the item
/// </summary>
[JsonProperty("name")]
[XmlElement("name")]
public string Name { get; set; }
/// <summary>
/// Tag associated with the configuration
/// </summary>
[JsonProperty("tag", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("tag")]
public string Tag { get; set; }
/// <summary>
/// Mask associated with the configuration
/// </summary>
[JsonProperty("mask", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("mask")]
public string Mask { get; set; }
/// <summary>
/// Conditions associated with the configuration
/// </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; } }
/// <summary>
/// Locations associated with the configuration
/// </summary>
[JsonProperty("locations", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("locations")]
public List<Location> Locations { get; set; }
[JsonIgnore]
public bool LocationsSpecified { get { return Locations != null && Locations.Count > 0; } }
/// <summary>
/// Settings associated with the configuration
/// </summary>
[JsonProperty("settings", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("settings")]
public List<Setting> Settings { get; set; }
[JsonIgnore]
public bool SettingsSpecified { get { return Settings != null && Settings.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 Configuration object
/// </summary>
public Configuration()
{
Name = string.Empty;
ItemType = ItemType.Configuration;
}
#endregion
#region Cloning Methods
public override object Clone()
{
return new Configuration()
{
ItemType = this.ItemType,
DupeType = this.DupeType,
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,
};
}
#endregion
#region Comparision Methods
public override bool Equals(DatItem other)
{
// If we don't have a Configuration, return false
if (ItemType != other.ItemType)
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;
}
#endregion
}
}

View File

@@ -0,0 +1,201 @@
using System.Xml.Serialization;
using SabreTools.Core;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
namespace SabreTools.DatItems.Formats
{
/// <summary>
/// Represents control for an input
/// </summary>
[JsonObject("control"), XmlRoot("control")]
public class Control : DatItem
{
#region Fields
/// <summary>
/// General type of input
/// </summary>
[JsonProperty("type", DefaultValueHandling = DefaultValueHandling.Ignore)]
[JsonConverter(typeof(StringEnumConverter))]
[XmlElement("type")]
public ControlType ControlType { get; set; }
[JsonIgnore]
public bool ControlTypeSpecified { get { return ControlType != ControlType.NULL; } }
/// <summary>
/// Player which the input belongs to
/// </summary>
[JsonProperty("player", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("player")]
public long? Player { get; set; }
[JsonIgnore]
public bool PlayerSpecified { get { return Player != null; } }
/// <summary>
/// Total number of buttons
/// </summary>
[JsonProperty("buttons", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("buttons")]
public long? Buttons { get; set; }
[JsonIgnore]
public bool ButtonsSpecified { get { return Buttons != null; } }
/// <summary>
/// Total number of non-optional buttons
/// </summary>
[JsonProperty("reqbuttons", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("reqbuttons")]
public long? RequiredButtons { get; set; }
[JsonIgnore]
public bool RequiredButtonsSpecified { get { return RequiredButtons != null; } }
/// <summary>
/// Analog minimum value
/// </summary>
[JsonProperty("minimum", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("minimum")]
public long? Minimum { get; set; }
[JsonIgnore]
public bool MinimumSpecified { get { return Minimum != null; } }
/// <summary>
/// Analog maximum value
/// </summary>
[JsonProperty("maximum", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("maximum")]
public long? Maximum { get; set; }
[JsonIgnore]
public bool MaximumSpecified { get { return Maximum != null; } }
/// <summary>
/// Default analog sensitivity
/// </summary>
[JsonProperty("sensitivity", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("sensitivity")]
public long? Sensitivity { get; set; }
[JsonIgnore]
public bool SensitivitySpecified { get { return Sensitivity != null; } }
/// <summary>
/// Default analog keydelta
/// </summary>
[JsonProperty("keydelta", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("keydelta")]
public long? KeyDelta { get; set; }
[JsonIgnore]
public bool KeyDeltaSpecified { get { return KeyDelta != null; } }
/// <summary>
/// Default analog reverse setting
/// </summary>
[JsonProperty("reverse", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("reverse")]
public bool? Reverse { get; set; }
[JsonIgnore]
public bool ReverseSpecified { get { return Reverse != null; } }
/// <summary>
/// First set of ways
/// </summary>
[JsonProperty("ways", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("ways")]
public string Ways { get; set; }
/// <summary>
/// Second set of ways
/// </summary>
[JsonProperty("ways2", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("ways2")]
public string Ways2 { get; set; }
/// <summary>
/// Third set of ways
/// </summary>
[JsonProperty("ways3", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("ways3")]
public string Ways3 { get; set; }
#endregion
#region Constructors
/// <summary>
/// Create a default, empty Control object
/// </summary>
public Control()
{
ItemType = ItemType.Control;
}
#endregion
#region Cloning Methods
public override object Clone()
{
return new Control()
{
ItemType = this.ItemType,
DupeType = this.DupeType,
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,
};
}
#endregion
#region Comparision Methods
public override bool Equals(DatItem other)
{
// If we don't have a Control, return false
if (ItemType != other.ItemType)
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);
}
#endregion
}
}

View File

@@ -0,0 +1,121 @@
using System.Xml.Serialization;
using SabreTools.Core;
using Newtonsoft.Json;
namespace SabreTools.DatItems.Formats
{
/// <summary>
/// SoftwareList dataarea information
/// </summary>
/// <remarks>One DataArea can contain multiple Rom items</remarks>
[JsonObject("dataarea"), XmlRoot("dataarea")]
public class DataArea : DatItem
{
#region Fields
/// <summary>
/// Name of the item
/// </summary>
[JsonProperty("name", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("name")]
public string Name { get; set; }
/// <summary>
/// Total size of the area
/// </summary>
[JsonProperty("size", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("size")]
public long? Size { get; set; }
[JsonIgnore]
public bool SizeSpecified { get { return Size != null; } }
/// <summary>
/// Word width for the area
/// </summary>
[JsonProperty("width", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("width")]
public long? Width { get; set; }
[JsonIgnore]
public bool WidthSpecified { get { return Width != null; } }
/// <summary>
/// Byte endianness of the area
/// </summary>
[JsonProperty("endianness", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("endianness")]
public Endianness Endianness { get; set; }
[JsonIgnore]
public bool EndiannessSpecified { get { return Endianness != Endianness.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 DataArea object
/// </summary>
public DataArea()
{
Name = string.Empty;
ItemType = ItemType.DataArea;
}
#endregion
#region Cloning Methods
public override object Clone()
{
return new DataArea()
{
ItemType = this.ItemType,
DupeType = this.DupeType,
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,
};
}
#endregion
#region Comparision Methods
public override bool Equals(DatItem other)
{
// If we don't have a DataArea, return false
if (ItemType != other.ItemType)
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);
}
#endregion
}
}

View File

@@ -0,0 +1,163 @@
using System.Collections.Generic;
using System.Xml.Serialization;
using SabreTools.Core;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
namespace SabreTools.DatItems.Formats
{
/// <summary>
/// Represents a single device on the machine
/// </summary>
[JsonObject("device"), XmlRoot("device")]
public class Device : DatItem
{
#region Fields
/// <summary>
/// Device type
/// </summary>
[JsonProperty("type", DefaultValueHandling = DefaultValueHandling.Ignore)]
[JsonConverter(typeof(StringEnumConverter))]
[XmlElement("type")]
public DeviceType DeviceType { get; set; }
[JsonIgnore]
public bool DeviceTypeSpecified { get { return DeviceType != DeviceType.NULL; } }
/// <summary>
/// Device tag
/// </summary>
[JsonProperty("tag", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("tag")]
public string Tag { get; set; }
/// <summary>
/// Fixed image format
/// </summary>
[JsonProperty("fixed_image", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("fixed_image")]
public string FixedImage { get; set; }
/// <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; }
[JsonIgnore]
public bool MandatorySpecified { get { return Mandatory != null; } }
/// <summary>
/// Device interface
/// </summary>
[JsonProperty("interface", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("interface")]
public string Interface { get; set; }
/// <summary>
/// Device instances
/// </summary>
[JsonProperty("instances", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("instances")]
public List<Instance> Instances { get; set; }
[JsonIgnore]
public bool InstancesSpecified { get { return Instances != null && Instances.Count > 0; } }
/// <summary>
/// Device extensions
/// </summary>
[JsonProperty("extensions", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("extensions")]
public List<Extension> Extensions { get; set; }
[JsonIgnore]
public bool ExtensionsSpecified { get { return Extensions != null && Extensions.Count > 0; } }
#endregion
#region Constructors
/// <summary>
/// Create a default, empty Device object
/// </summary>
public Device()
{
ItemType = ItemType.Device;
}
#endregion
#region Cloning Methods
public override object Clone()
{
return new Device()
{
ItemType = this.ItemType,
DupeType = this.DupeType,
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,
};
}
#endregion
#region Comparision Methods
public override bool Equals(DatItem other)
{
// If we don't have a Device, return false
if (ItemType != other.ItemType)
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;
}
#endregion
}
}

View File

@@ -0,0 +1,84 @@
using System.Xml.Serialization;
using SabreTools.Core;
using Newtonsoft.Json;
namespace SabreTools.DatItems.Formats
{
/// <summary>
/// Represents which Device Reference(s) is associated with a set
/// </summary>
[JsonObject("device_ref"), XmlRoot("device_ref")]
public class DeviceReference : DatItem
{
#region Fields
/// <summary>
/// Name of the item
/// </summary>
[JsonProperty("name")]
[XmlElement("name")]
public string Name { get; set; }
#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 DeviceReference object
/// </summary>
public DeviceReference()
{
Name = string.Empty;
ItemType = ItemType.DeviceReference;
}
#endregion
#region Cloning Methods
public override object Clone()
{
return new DeviceReference()
{
ItemType = this.ItemType,
DupeType = this.DupeType,
Machine = this.Machine.Clone() as Machine,
Source = this.Source.Clone() as Source,
Remove = this.Remove,
Name = this.Name,
};
}
#endregion
#region Comparision Methods
public override bool Equals(DatItem other)
{
// If we don't have a device reference, return false
if (ItemType != other.ItemType)
return false;
// Otherwise, treat it as a device reference
DeviceReference newOther = other as DeviceReference;
// If the device reference information matches
return (Name == newOther.Name);
}
#endregion
}
}

View File

@@ -0,0 +1,199 @@
using System.Collections.Generic;
using System.Xml.Serialization;
using SabreTools.Core;
using Newtonsoft.Json;
namespace SabreTools.DatItems.Formats
{
/// <summary>
/// Represents which DIP Switch(es) is associated with a set
/// </summary>
[JsonObject("dipswitch"), XmlRoot("dipswitch")]
public class DipSwitch : DatItem
{
#region Fields
#region Common
/// <summary>
/// Name of the item
/// </summary>
[JsonProperty("name")]
[XmlElement("name")]
public string Name { get; set; }
/// <summary>
/// Tag associated with the dipswitch
/// </summary>
[JsonProperty("tag", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("tag")]
public string Tag { get; set; }
/// <summary>
/// Mask associated with the dipswitch
/// </summary>
[JsonProperty("mask", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("mask")]
public string Mask { get; set; }
/// <summary>
/// Conditions associated with the dipswitch
/// </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; } }
/// <summary>
/// Locations associated with the dipswitch
/// </summary>
[JsonProperty("locations", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("locations")]
public List<Location> Locations { get; set; }
[JsonIgnore]
public bool LocationsSpecified { get { return Locations != null && Locations.Count > 0; } }
/// <summary>
/// Settings associated with the dipswitch
/// </summary>
[JsonProperty("values", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("values")]
public List<Setting> Values { get; set; }
[JsonIgnore]
public bool ValuesSpecified { get { return Values != null && Values.Count > 0; } }
#endregion
#region SoftwareList
/// <summary>
/// Original hardware part associated with the item
/// </summary>
[JsonProperty("part", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("part")]
public Part Part { get; set; } = null;
[JsonIgnore]
public bool PartSpecified
{
get
{
return Part != null
&& (!string.IsNullOrEmpty(Part.Name)
|| !string.IsNullOrEmpty(Part.Interface));
}
}
#endregion
#endregion // Fields
#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 DipSwitch object
/// </summary>
public DipSwitch()
{
Name = string.Empty;
ItemType = ItemType.DipSwitch;
}
#endregion
#region Cloning Methods
public override object Clone()
{
return new DipSwitch()
{
ItemType = this.ItemType,
DupeType = this.DupeType,
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,
Part = this.Part,
};
}
#endregion
#region Comparision Methods
public override bool Equals(DatItem other)
{
// If we don't have a DipSwitch, return false
if (ItemType != other.ItemType)
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;
}
#endregion
}
}

View File

@@ -0,0 +1,400 @@
using System.Xml.Serialization;
using SabreTools.Core;
using SabreTools.Core.Tools;
using SabreTools.FileTypes;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
namespace SabreTools.DatItems.Formats
{
/// <summary>
/// Represents Compressed Hunks of Data (CHD) formatted disks which use internal hashes
/// </summary>
[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
/// <summary>
/// Name of the item
/// </summary>
[JsonProperty("name")]
[XmlElement("name")]
public string Name { get; set; }
/// <summary>
/// Data MD5 hash
/// </summary>
[JsonProperty("md5", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("md5")]
public string MD5
{
get { return _md5.IsNullOrEmpty() ? null : Utilities.ByteArrayToString(_md5); }
set { _md5 = Utilities.StringToByteArray(CleanMD5(value)); }
}
/// <summary>
/// Data SHA-1 hash
/// </summary>
[JsonProperty("sha1", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("sha1")]
public string SHA1
{
get { return _sha1.IsNullOrEmpty() ? null : Utilities.ByteArrayToString(_sha1); }
set { _sha1 = Utilities.StringToByteArray(CleanSHA1(value)); }
}
/// <summary>
/// Disk name to merge from parent
/// </summary>
[JsonProperty("merge", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("merge")]
public string MergeTag { get; set; }
/// <summary>
/// Disk region
/// </summary>
[JsonProperty("region", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("region")]
public string Region { get; set; }
/// <summary>
/// Disk index
/// </summary>
[JsonProperty("index", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("index")]
public string Index { get; set; }
/// <summary>
/// Disk writable flag
/// </summary>
[JsonProperty("writable", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("writable")]
public bool? Writable { get; set; } = null;
[JsonIgnore]
public bool WritableSpecified { get { return Writable != null; } }
/// <summary>
/// Disk dump status
/// </summary>
[JsonProperty("status", DefaultValueHandling = DefaultValueHandling.Ignore)]
[JsonConverter(typeof(StringEnumConverter))]
[XmlElement("status")]
public ItemStatus ItemStatus { get; set; }
[JsonIgnore]
public bool ItemStatusSpecified { get { return ItemStatus != ItemStatus.NULL; } }
/// <summary>
/// Determine if the disk is optional in the set
/// </summary>
[JsonProperty("optional", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("optional")]
public bool? Optional { get; set; } = null;
[JsonIgnore]
public bool OptionalSpecified { get { return Optional != null; } }
#endregion
#region SoftwareList
/// <summary>
/// Disk area information
/// </summary>
[JsonProperty("diskarea", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("diskarea")]
public DiskArea DiskArea { get; set; } = null;
[JsonIgnore]
public bool DiskAreaSpecified
{
get
{
return DiskArea != null
&& !string.IsNullOrEmpty(DiskArea.Name);
}
}
/// <summary>
/// Original hardware part associated with the item
/// </summary>
[JsonProperty("part", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("part")]
public Part Part { get; set; } = null;
[JsonIgnore]
public bool PartSpecified
{
get
{
return Part != null
&& (!string.IsNullOrEmpty(Part.Name)
|| !string.IsNullOrEmpty(Part.Interface));
}
}
#endregion
#endregion // Fields
#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 Disk object
/// </summary>
public Disk()
{
Name = string.Empty;
ItemType = ItemType.Disk;
DupeType = 0x00;
ItemStatus = ItemStatus.None;
}
/// <summary>
/// Create a Disk object from a BaseFile
/// </summary>
/// <param name="baseFile"></param>
public Disk(BaseFile baseFile)
{
Name = baseFile.Filename;
_md5 = baseFile.MD5;
_sha1 = baseFile.SHA1;
ItemType = ItemType.Disk;
DupeType = 0x00;
ItemStatus = ItemStatus.None;
}
#endregion
#region Cloning Methods
public override object Clone()
{
return new Disk()
{
Name = this.Name,
ItemType = this.ItemType,
DupeType = this.DupeType,
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,
DiskArea = this.DiskArea,
Part = this.Part,
};
}
/// <summary>
/// Convert Disk object to a BaseFile
/// </summary>
public BaseFile ConvertToBaseFile()
{
return new BaseFile()
{
Filename = this.Name,
Parent = this.Machine?.Name,
MD5 = this._md5,
SHA1 = this._sha1,
};
}
/// <summary>
/// Convert a disk to the closest Rom approximation
/// </summary>
/// <returns></returns>
public Rom ConvertToRom()
{
var rom = new Rom()
{
Name = this.Name + ".chd",
ItemType = ItemType.Rom,
DupeType = this.DupeType,
Machine = this.Machine.Clone() as Machine,
Source = this.Source.Clone() as Source,
Remove = this.Remove,
MergeTag = this.MergeTag,
Region = this.Region,
ItemStatus = this.ItemStatus,
Optional = this.Optional,
MD5 = this.MD5,
SHA1 = this.SHA1,
DataArea = new DataArea { Name = this.DiskArea.Name },
Part = this.Part,
};
return rom;
}
#endregion
#region Comparision Methods
public override bool Equals(DatItem other)
{
bool dupefound = 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;
}
/// <summary>
/// Fill any missing size and hash information from another Disk
/// </summary>
/// <param name="other">Disk to fill information from</param>
public void FillMissingInformation(Disk other)
{
if (_md5.IsNullOrEmpty() && !other._md5.IsNullOrEmpty())
_md5 = other._md5;
if (_sha1.IsNullOrEmpty() && !other._sha1.IsNullOrEmpty())
_sha1 = other._sha1;
}
/// <summary>
/// Get unique duplicate suffix on name collision
/// </summary>
/// <returns>String representing the suffix</returns>
public string GetDuplicateSuffix()
{
if (!_md5.IsNullOrEmpty())
return $"_{MD5}";
else if (!_sha1.IsNullOrEmpty())
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
/// <inheritdoc/>
public override string GetKey(ItemKey bucketedBy, bool lower = true, bool norename = true)
{
// Set the output key as the default blank string
string key;
// Now determine what the key should be based on the bucketedBy value
switch (bucketedBy)
{
case ItemKey.MD5:
key = MD5;
break;
case ItemKey.SHA1:
key = SHA1;
break;
// Let the base handle generic stuff
default:
return base.GetKey(bucketedBy, lower, norename);
}
// Double and triple check the key for corner cases
if (key == null)
key = string.Empty;
return key;
}
#endregion
}
}

View File

@@ -0,0 +1,85 @@
using System.Xml.Serialization;
using SabreTools.Core;
using Newtonsoft.Json;
namespace SabreTools.DatItems.Formats
{
/// <summary>
/// SoftwareList diskarea information
/// </summary>
/// <remarks>One DiskArea can contain multiple Disk items</remarks>
[JsonObject("diskarea"), XmlRoot("diskarea")]
public class DiskArea : DatItem
{
#region Fields
/// <summary>
/// Name of the item
/// </summary>
[JsonProperty("name", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("name")]
public string Name { get; set; }
#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 DiskArea object
/// </summary>
public DiskArea()
{
Name = string.Empty;
ItemType = ItemType.DiskArea;
}
#endregion
#region Cloning Methods
public override object Clone()
{
return new DiskArea()
{
ItemType = this.ItemType,
DupeType = this.DupeType,
Machine = this.Machine.Clone() as Machine,
Source = this.Source.Clone() as Source,
Remove = this.Remove,
Name = this.Name,
};
}
#endregion
#region Comparision Methods
public override bool Equals(DatItem other)
{
// If we don't have a DiskArea, return false
if (ItemType != other.ItemType)
return false;
// Otherwise, treat it as a DiskArea
DiskArea newOther = other as DiskArea;
// If the DiskArea information matches
return (Name == newOther.Name);
}
#endregion
}
}

View File

@@ -0,0 +1,231 @@
using System.Xml.Serialization;
using SabreTools.Core;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
namespace SabreTools.DatItems.Formats
{
/// <summary>
/// Represents one machine display
/// </summary>
[JsonObject("display"), XmlRoot("display")]
public class Display : DatItem
{
#region Fields
/// <summary>
/// Display tag
/// </summary>
[JsonProperty("tag", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("tag")]
public string Tag { get; set; }
/// <summary>
/// Display type
/// </summary>
[JsonProperty("type", DefaultValueHandling = DefaultValueHandling.Ignore)]
[JsonConverter(typeof(StringEnumConverter))]
[XmlElement("type")]
public DisplayType DisplayType { get; set; }
[JsonIgnore]
public bool DisplayTypeSpecified { get { return DisplayType != DisplayType.NULL; } }
/// <summary>
/// Display rotation
/// </summary>
[JsonProperty("rotate", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("rotate")]
public long? Rotate { get; set; }
[JsonIgnore]
public bool RotateSpecified { get { return Rotate != null; } }
/// <summary>
/// Determines if display is flipped in the X-coordinates
/// </summary>
[JsonProperty("flipx", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("flipx")]
public bool? FlipX { get; set; }
[JsonIgnore]
public bool FlipXSpecified { get { return FlipX != null; } }
/// <summary>
/// Display width
/// </summary>
[JsonProperty("width", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("width")]
public long? Width { get; set; }
[JsonIgnore]
public bool WidthSpecified { get { return Width != null; } }
/// <summary>
/// Display height
/// </summary>
[JsonProperty("height", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("height")]
public long? Height { get; set; }
[JsonIgnore]
public bool HeightSpecified { get { return Height != null; } }
/// <summary>
/// Refresh rate
/// </summary>
[JsonProperty("refresh", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("refresh")]
public double? Refresh { get; set; }
[JsonIgnore]
public bool RefreshSpecified { get { return Refresh != null; } }
/// <summary>
/// Pixel clock timer
/// </summary>
[JsonProperty("pixclock", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("pixclock")]
public long? PixClock { get; set; }
[JsonIgnore]
public bool PixClockSpecified { get { return PixClock != null; } }
/// <summary>
/// Total horizontal lines
/// </summary>
[JsonProperty("htotal", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("htotal")]
public long? HTotal { get; set; }
[JsonIgnore]
public bool HTotalSpecified { get { return HTotal != null; } }
/// <summary>
/// Horizontal blank end
/// </summary>
[JsonProperty("hbend", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("hbend")]
public long? HBEnd { get; set; }
[JsonIgnore]
public bool HBEndSpecified { get { return HBEnd != null; } }
/// <summary>
/// Horizontal blank start
/// </summary>
[JsonProperty("hbstart", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("hbstart")]
public long? HBStart { get; set; }
[JsonIgnore]
public bool HBStartSpecified { get { return HBStart != null; } }
/// <summary>
/// Total vertical lines
/// </summary>
[JsonProperty("vtotal", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("vtotal")]
public long? VTotal { get; set; }
[JsonIgnore]
public bool VTotalSpecified { get { return VTotal != null; } }
/// <summary>
/// Vertical blank end
/// </summary>
[JsonProperty("vbend", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("vbend")]
public long? VBEnd { get; set; }
[JsonIgnore]
public bool VBEndSpecified { get { return VBEnd != null; } }
/// <summary>
/// Vertical blank start
/// </summary>
[JsonProperty("vbstart", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("vbstart")]
public long? VBStart { get; set; }
[JsonIgnore]
public bool VBStartSpecified { get { return VBStart != null; } }
#endregion
#region Constructors
/// <summary>
/// Create a default, empty Display object
/// </summary>
public Display()
{
ItemType = ItemType.Display;
}
#endregion
#region Cloning Methods
public override object Clone()
{
return new Display()
{
ItemType = this.ItemType,
DupeType = this.DupeType,
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,
};
}
#endregion
#region Comparision Methods
public override bool Equals(DatItem other)
{
// If we don't have a Display, return false
if (ItemType != other.ItemType)
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);
}
#endregion
}
}

View File

@@ -0,0 +1,117 @@
using System.Xml.Serialization;
using SabreTools.Core;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
namespace SabreTools.DatItems.Formats
{
/// <summary>
/// Represents the a driver of the machine
/// </summary>
[JsonObject("driver"), XmlRoot("driver")]
public class Driver : DatItem
{
#region Fields
/// <summary>
/// Overall driver status
/// </summary>
[JsonProperty("status", DefaultValueHandling = DefaultValueHandling.Ignore)]
[JsonConverter(typeof(StringEnumConverter))]
[XmlElement("status")]
public SupportStatus Status { get; set; }
[JsonIgnore]
public bool StatusSpecified { get { return Status != SupportStatus.NULL; } }
/// <summary>
/// Driver emulation status
/// </summary>
[JsonProperty("emulation", DefaultValueHandling = DefaultValueHandling.Ignore)]
[JsonConverter(typeof(StringEnumConverter))]
[XmlElement("emulation")]
public SupportStatus Emulation { get; set; }
[JsonIgnore]
public bool EmulationSpecified { get { return Emulation != SupportStatus.NULL; ; } }
/// <summary>
/// Cocktail orientation status
/// </summary>
[JsonProperty("cocktail", DefaultValueHandling = DefaultValueHandling.Ignore)]
[JsonConverter(typeof(StringEnumConverter))]
[XmlElement("cocktail")]
public SupportStatus Cocktail { get; set; }
[JsonIgnore]
public bool CocktailSpecified { get { return Cocktail != SupportStatus.NULL; ; } }
/// <summary>
/// Save state support status
/// </summary>
[JsonProperty("savestate", DefaultValueHandling = DefaultValueHandling.Ignore)]
[JsonConverter(typeof(StringEnumConverter))]
[XmlElement("savestate")]
public Supported SaveState { get; set; }
[JsonIgnore]
public bool SaveStateSpecified { get { return SaveState != Supported.NULL; } }
#endregion
#region Constructors
/// <summary>
/// Create a default, empty Driver object
/// </summary>
public Driver()
{
ItemType = ItemType.Driver;
}
#endregion
#region Cloning Methods
public override object Clone()
{
return new Driver()
{
ItemType = this.ItemType,
DupeType = this.DupeType,
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,
};
}
#endregion
#region Comparision Methods
public override bool Equals(DatItem other)
{
// If we don't have a Driver, return false
if (ItemType != other.ItemType)
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);
}
#endregion
}
}

View File

@@ -0,0 +1,84 @@
using System.Xml.Serialization;
using SabreTools.Core;
using Newtonsoft.Json;
namespace SabreTools.DatItems.Formats
{
/// <summary>
/// Represents a matchable extension
/// </summary>
[JsonObject("extension"), XmlRoot("extension")]
public class Extension : DatItem
{
#region Fields
/// <summary>
/// Name of the item
/// </summary>
[JsonProperty("name")]
[XmlElement("name")]
public string Name { get; set; }
#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 Extension object
/// </summary>
public Extension()
{
Name = string.Empty;
ItemType = ItemType.Extension;
}
#endregion
#region Cloning Methods
public override object Clone()
{
return new Extension()
{
ItemType = this.ItemType,
DupeType = this.DupeType,
Machine = this.Machine.Clone() as Machine,
Source = this.Source.Clone() as Source,
Remove = this.Remove,
Name = this.Name,
};
}
#endregion
#region Comparision Methods
public override bool Equals(DatItem other)
{
// If we don't have a Extension, return false
if (ItemType != other.ItemType)
return false;
// Otherwise, treat it as a Extension
Extension newOther = other as Extension;
// If the Extension information matches
return (Name == newOther.Name);
}
#endregion
}
}

View File

@@ -0,0 +1,102 @@
using System.Xml.Serialization;
using SabreTools.Core;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
namespace SabreTools.DatItems.Formats
{
/// <summary>
/// Represents the a feature of the machine
/// </summary>
[JsonObject("feature"), XmlRoot("feature")]
public class Feature : DatItem
{
#region Fields
/// <summary>
/// Type of feature
/// </summary>
[JsonProperty("type", DefaultValueHandling = DefaultValueHandling.Ignore)]
[JsonConverter(typeof(StringEnumConverter))]
[XmlElement("type")]
public FeatureType Type { get; set; }
[JsonIgnore]
public bool TypeSpecified { get { return Type != FeatureType.NULL; } }
/// <summary>
/// Emulation status
/// </summary>
[JsonProperty("status", DefaultValueHandling = DefaultValueHandling.Ignore)]
[JsonConverter(typeof(StringEnumConverter))]
[XmlElement("status")]
public FeatureStatus Status { get; set; }
[JsonIgnore]
public bool StatusSpecified { get { return Status != FeatureStatus.NULL; } }
/// <summary>
/// Overall status
/// </summary>
[JsonProperty("overall", DefaultValueHandling = DefaultValueHandling.Ignore)]
[JsonConverter(typeof(StringEnumConverter))]
[XmlElement("overall")]
public FeatureStatus Overall { get; set; }
[JsonIgnore]
public bool OverallSpecified { get { return Overall != FeatureStatus.NULL; } }
#endregion
#region Constructors
/// <summary>
/// Create a default, empty Feature object
/// </summary>
public Feature()
{
ItemType = ItemType.Feature;
}
#endregion
#region Cloning Methods
public override object Clone()
{
return new Feature()
{
ItemType = this.ItemType,
DupeType = this.DupeType,
Machine = this.Machine.Clone() as Machine,
Source = this.Source.Clone() as Source,
Remove = this.Remove,
Type = this.Type,
Status = this.Status,
Overall = this.Overall,
};
}
#endregion
#region Comparision Methods
public override bool Equals(DatItem other)
{
// If we don't have a Feature, return false
if (ItemType != other.ItemType)
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);
}
#endregion
}
}

View File

@@ -0,0 +1,92 @@
using System.Xml.Serialization;
using SabreTools.Core;
using Newtonsoft.Json;
namespace SabreTools.DatItems.Formats
{
/// <summary>
/// Represents special information about a machine
/// </summary>
[JsonObject("info"), XmlRoot("info")]
public class Info : DatItem
{
#region Fields
/// <summary>
/// Name of the item
/// </summary>
[JsonProperty("name")]
[XmlElement("name")]
public string Name { get; set; }
/// <summary>
/// Information value
/// </summary>
[JsonProperty("value")]
[XmlElement("value")]
public string Value { get; set; }
#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 Info object
/// </summary>
public Info()
{
Name = string.Empty;
ItemType = ItemType.Info;
}
#endregion
#region Cloning Methods
public override object Clone()
{
return new Info()
{
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,
};
}
#endregion
#region Comparision Methods
public override bool Equals(DatItem other)
{
// If we don't have a sample, return false
if (ItemType != other.ItemType)
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);
}
#endregion
}
}

View File

@@ -0,0 +1,137 @@
using System.Collections.Generic;
using System.Xml.Serialization;
using SabreTools.Core;
using Newtonsoft.Json;
namespace SabreTools.DatItems.Formats
{
/// <summary>
/// Represents one ListXML input
/// </summary>
[JsonObject("input"), XmlRoot("input")]
public class Input : DatItem
{
#region Fields
/// <summary>
/// Input service ID
/// </summary>
[JsonProperty("service", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("service")]
public bool? Service { get; set; }
[JsonIgnore]
public bool ServiceSpecified { get { return Service != null; } }
/// <summary>
/// Determins if this has a tilt sensor
/// </summary>
[JsonProperty("tilt", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("tilt")]
public bool? Tilt { get; set; }
[JsonIgnore]
public bool TiltSpecified { get { return Tilt != null; } }
/// <summary>
/// Number of players on the input
/// </summary>
[JsonProperty("players", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("players")]
public long? Players { get; set; }
[JsonIgnore]
public bool PlayersSpecified { get { return Players != null; } }
/// <summary>
/// Number of coins required
/// </summary>
[JsonProperty("coins", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("coins")]
public long? Coins { get; set; }
[JsonIgnore]
public bool CoinsSpecified { get { return Coins != null; } }
/// <summary>
/// Set of controls for the input
/// </summary>
[JsonProperty("controls", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("controls")]
public List<Control> Controls { get; set; }
[JsonIgnore]
public bool ControlsSpecified { get { return Controls != null && Controls.Count > 0; } }
#endregion
#region Constructors
/// <summary>
/// Create a default, empty Input object
/// </summary>
public Input()
{
ItemType = ItemType.Input;
}
#endregion
#region Cloning Methods
public override object Clone()
{
return new Input()
{
ItemType = this.ItemType,
DupeType = this.DupeType,
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,
};
}
#endregion
#region Comparision Methods
public override bool Equals(DatItem other)
{
// If we don't have a Input, return false
if (ItemType != other.ItemType)
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;
}
#endregion
}
}

View File

@@ -0,0 +1,92 @@
using System.Xml.Serialization;
using SabreTools.Core;
using Newtonsoft.Json;
namespace SabreTools.DatItems.Formats
{
/// <summary>
/// Represents a single instance of another item
/// </summary>
[JsonObject("instance"), XmlRoot("instance")]
public class Instance : DatItem
{
#region Fields
/// <summary>
/// Name of the item
/// </summary>
[JsonProperty("name")]
[XmlElement("name")]
public string Name { get; set; }
/// <summary>
/// Short name for the instance
/// </summary>
[JsonProperty("briefname", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("briefname")]
public string BriefName { get; set; }
#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 Instance object
/// </summary>
public Instance()
{
Name = string.Empty;
ItemType = ItemType.Instance;
}
#endregion
#region Cloning Methods
public override object Clone()
{
return new Instance()
{
ItemType = this.ItemType,
DupeType = this.DupeType,
Machine = this.Machine.Clone() as Machine,
Source = this.Source.Clone() as Source,
Remove = this.Remove,
Name = this.Name,
BriefName = this.BriefName,
};
}
#endregion
#region Comparision Methods
public override bool Equals(DatItem other)
{
// If we don't have a Instance, return false
if (ItemType != other.ItemType)
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);
}
#endregion
}
}

View File

@@ -0,0 +1,108 @@
using System.Xml.Serialization;
using SabreTools.Core;
using Newtonsoft.Json;
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
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
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
}
}

View File

@@ -0,0 +1,331 @@
using System.Text;
using System.Xml.Serialization;
using SabreTools.Core;
using SabreTools.Core.Tools;
using SabreTools.FileTypes;
using Newtonsoft.Json;
namespace SabreTools.DatItems.Formats
{
/// <summary>
/// Represents Aaruformat images which use internal hashes
/// </summary>
[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; }
/// <summary>
/// Data MD5 hash
/// </summary>
[JsonProperty("md5", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("md5")]
public string MD5
{
get { return _md5.IsNullOrEmpty() ? null : Utilities.ByteArrayToString(_md5); }
set { _md5 = Utilities.StringToByteArray(CleanMD5(value)); }
}
/// <summary>
/// Data SHA-1 hash
/// </summary>
[JsonProperty("sha1", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("sha1")]
public string SHA1
{
get { return _sha1.IsNullOrEmpty() ? null : Utilities.ByteArrayToString(_sha1); }
set { _sha1 = Utilities.StringToByteArray(CleanSHA1(value)); }
}
/// <summary>
/// Data SHA-256 hash
/// </summary>
[JsonProperty("sha256", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("sha256")]
public string SHA256
{
get { return _sha256.IsNullOrEmpty() ? null : Utilities.ByteArrayToString(_sha256); }
set { _sha256 = Utilities.StringToByteArray(CleanSHA256(value)); }
}
/// <summary>
/// File SpamSum fuzzy hash
/// </summary>
[JsonProperty("spamsum", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("spamsum")]
public string SpamSum
{
get { return _spamsum.IsNullOrEmpty() ? null : Encoding.UTF8.GetString(_spamsum); }
set { _spamsum = Encoding.UTF8.GetBytes(value ?? string.Empty); }
}
#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 Media object
/// </summary>
public Media()
{
Name = string.Empty;
ItemType = ItemType.Media;
DupeType = 0x00;
}
/// <summary>
/// Create a Media object from a BaseFile
/// </summary>
/// <param name="baseFile"></param>
public Media(BaseFile baseFile)
{
Name = baseFile.Filename;
_md5 = baseFile.MD5;
_sha1 = baseFile.SHA1;
_sha256 = baseFile.SHA256;
_spamsum = baseFile.SpamSum;
ItemType = ItemType.Media;
DupeType = 0x00;
}
#endregion
#region Cloning Methods
public override object Clone()
{
return new Media()
{
ItemType = this.ItemType,
DupeType = this.DupeType,
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,
};
}
/// <summary>
/// Convert Media object to a BaseFile
/// </summary>
public BaseFile ConvertToBaseFile()
{
return new BaseFile()
{
Filename = this.Name,
Parent = this.Machine?.Name,
MD5 = this._md5,
SHA1 = this._sha1,
SHA256 = this._sha256,
SpamSum = this._spamsum,
};
}
/// <summary>
/// Convert a media to the closest Rom approximation
/// </summary>
/// <returns></returns>
public Rom ConvertToRom()
{
var rom = new Rom()
{
ItemType = ItemType.Rom,
DupeType = this.DupeType,
Machine = this.Machine.Clone() as Machine,
Source = this.Source.Clone() as Source,
Remove = this.Remove,
Name = this.Name + ".aif",
MD5 = this.MD5,
SHA1 = this.SHA1,
SHA256 = this.SHA256,
SpamSum = this.SpamSum,
};
return rom;
}
#endregion
#region Comparision Methods
public override bool Equals(DatItem other)
{
bool dupefound = false;
// If we don't have a Media, return false
if (ItemType != other.ItemType)
return dupefound;
// Otherwise, treat it as a Media
Media newOther = other as Media;
// If we get a partial match
if (HashMatch(newOther))
dupefound = true;
return dupefound;
}
/// <summary>
/// Fill any missing size and hash information from another Media
/// </summary>
/// <param name="other">Media to fill information from</param>
public void FillMissingInformation(Media other)
{
if (_md5.IsNullOrEmpty() && !other._md5.IsNullOrEmpty())
_md5 = other._md5;
if (_sha1.IsNullOrEmpty() && !other._sha1.IsNullOrEmpty())
_sha1 = other._sha1;
if (_sha256.IsNullOrEmpty() && !other._sha256.IsNullOrEmpty())
_sha256 = other._sha256;
if (_spamsum.IsNullOrEmpty() && !other._spamsum.IsNullOrEmpty())
_spamsum = other._spamsum;
}
/// <summary>
/// Get unique duplicate suffix on name collision
/// </summary>
/// <returns>String representing the suffix</returns>
public string GetDuplicateSuffix()
{
if (!_md5.IsNullOrEmpty())
return $"_{MD5}";
else if (!_sha1.IsNullOrEmpty())
return $"_{SHA1}";
else if (!_sha256.IsNullOrEmpty())
return $"_{SHA256}";
else if (!_spamsum.IsNullOrEmpty())
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
/// <inheritdoc/>
public override string GetKey(ItemKey bucketedBy, bool lower = true, bool norename = true)
{
// Set the output key as the default blank string
string key;
// Now determine what the key should be based on the bucketedBy value
switch (bucketedBy)
{
case ItemKey.MD5:
key = MD5;
break;
case ItemKey.SHA1:
key = SHA1;
break;
case ItemKey.SHA256:
key = SHA256;
break;
case ItemKey.SpamSum:
key = SpamSum;
break;
// Let the base handle generic stuff
default:
return base.GetKey(bucketedBy, lower, norename);
}
// Double and triple check the key for corner cases
if (key == null)
key = string.Empty;
return key;
}
#endregion
}
}

View File

@@ -0,0 +1,110 @@
using System.Collections.Generic;
using System.Xml.Serialization;
using SabreTools.Core;
using Newtonsoft.Json;
namespace SabreTools.DatItems.Formats
{
/// <summary>
/// SoftwareList part information
/// </summary>
/// <remarks>One Part can contain multiple PartFeature, DataArea, DiskArea, and DipSwitch items</remarks>
[JsonObject("part"), XmlRoot("part")]
public class Part : DatItem
{
#region Fields
[JsonProperty("name")]
[XmlElement("name")]
public string Name { get; set; }
[JsonProperty("interface")]
[XmlElement("interface")]
public string Interface { get; set; }
[JsonProperty("features", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("features")]
public List<PartFeature> Features { get; set; }
[JsonIgnore]
public bool FeaturesSpecified { get { return Features != null && Features.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 Part object
/// </summary>
public Part()
{
Name = string.Empty;
ItemType = ItemType.Part;
}
#endregion
#region Cloning Methods
public override object Clone()
{
return new Part()
{
ItemType = this.ItemType,
DupeType = this.DupeType,
Machine = this.Machine.Clone() as Machine,
Source = this.Source.Clone() as Source,
Remove = this.Remove,
Name = this.Name,
Interface = this.Interface,
Features = this.Features,
};
}
#endregion
#region Comparision Methods
public override bool Equals(DatItem other)
{
// If we don't have a Part, return false
if (ItemType != other.ItemType)
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;
}
#endregion
}
}

View File

@@ -0,0 +1,92 @@
using System.Xml.Serialization;
using SabreTools.Core;
using Newtonsoft.Json;
namespace SabreTools.DatItems.Formats
{
/// <summary>
/// Represents one part feature object
/// </summary>
[JsonObject("part_feature"), XmlRoot("part_feature")]
public class PartFeature : DatItem
{
#region Fields
/// <summary>
/// Name of the item
/// </summary>
[JsonProperty("name")]
[XmlElement("name")]
public string Name { get; set; }
/// <summary>
/// PartFeature value
/// </summary>
[JsonProperty("value")]
[XmlElement("value")]
public string Value { get; set; }
#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 PartFeature object
/// </summary>
public PartFeature()
{
Name = string.Empty;
ItemType = ItemType.PartFeature;
}
#endregion
#region Cloning Methods
public override object Clone()
{
return new PartFeature()
{
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,
};
}
#endregion
#region Comparision Methods
public override bool Equals(DatItem other)
{
// If we don't have a sample, return false
if (ItemType != other.ItemType)
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);
}
#endregion
}
}

View File

@@ -0,0 +1,98 @@
using System.Collections.Generic;
using System.Xml.Serialization;
using SabreTools.Core;
using Newtonsoft.Json;
namespace SabreTools.DatItems.Formats
{
/// <summary>
/// Represents a single port on a machine
/// </summary>
[JsonObject("port"), XmlRoot("port")]
public class Port : DatItem
{
#region Fields
/// <summary>
/// Tag for the port
/// </summary>
[JsonProperty("tag", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("tag")]
public string Tag { get; set; }
/// <summary>
/// List of analogs on the port
/// </summary>
[JsonProperty("analogs", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("analogs")]
public List<Analog> Analogs { get; set; }
[JsonIgnore]
public bool AnalogsSpecified { get { return Analogs != null && Analogs.Count > 0; } }
#endregion
#region Constructors
/// <summary>
/// Create a default, empty Port object
/// </summary>
public Port()
{
ItemType = ItemType.Port;
}
#endregion
#region Cloning Methods
public override object Clone()
{
return new Port()
{
ItemType = this.ItemType,
DupeType = this.DupeType,
Machine = this.Machine.Clone() as Machine,
Source = this.Source.Clone() as Source,
Remove = this.Remove,
Tag = this.Tag,
Analogs = this.Analogs,
};
}
#endregion
#region Comparision Methods
public override bool Equals(DatItem other)
{
// If we don't have a Port, return false
if (ItemType != other.ItemType)
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;
}
#endregion
}
}

View File

@@ -0,0 +1,103 @@
using System.Xml.Serialization;
using SabreTools.Core;
using Newtonsoft.Json;
namespace SabreTools.DatItems.Formats
{
/// <summary>
/// Represents which RAM option(s) is associated with a set
/// </summary>
[JsonObject("ramoption"), XmlRoot("ramoption")]
public class RamOption : DatItem
{
#region Fields
/// <summary>
/// Name of the item
/// </summary>
[JsonProperty("name")]
[XmlElement("name")]
public string Name { get; set; }
/// <summary>
/// Determine whether the RamOption is default
/// </summary>
[JsonProperty("default", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("default")]
public bool? Default { get; set; }
[JsonIgnore]
public bool DefaultSpecified { get { return Default != null; } }
/// <summary>
/// Determines the content of the RamOption
/// </summary>
[JsonProperty("content", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("content")]
public string Content { get; set; }
#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 RamOption object
/// </summary>
public RamOption()
{
Name = string.Empty;
ItemType = ItemType.RamOption;
}
#endregion
#region Cloning Methods
public override object Clone()
{
return new RamOption()
{
ItemType = this.ItemType,
DupeType = this.DupeType,
Machine = this.Machine.Clone() as Machine,
Source = this.Source.Clone() as Source,
Remove = this.Remove,
Name = this.Name,
Default = this.Default,
Content = this.Content,
};
}
#endregion
#region Comparision Methods
public override bool Equals(DatItem other)
{
// If we don't have a RamOption, return false
if (ItemType != other.ItemType)
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);
}
#endregion
}
}

View File

@@ -0,0 +1,127 @@
using System.Xml.Serialization;
using SabreTools.Core;
using Newtonsoft.Json;
namespace SabreTools.DatItems.Formats
{
/// <summary>
/// Represents release information about a set
/// </summary>
[JsonObject("release"), XmlRoot("release")]
public class Release : DatItem
{
#region Fields
/// <summary>
/// Name of the item
/// </summary>
[JsonProperty("name")]
[XmlElement("name")]
public string Name { get; set; }
/// <summary>
/// Release region(s)
/// </summary>
[JsonProperty("region", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("region")]
public string Region { get; set; }
/// <summary>
/// Release language(s)
/// </summary>
[JsonProperty("language", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("language")]
public string Language { get; set; }
/// <summary>
/// Date of release
/// </summary>
[JsonProperty("date", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("date")]
public string Date { get; set; }
/// <summary>
/// Default release, if applicable
/// </summary>
[JsonProperty("default", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("default")]
public bool? Default { get; set; }
[JsonIgnore]
public bool DefaultSpecified { get { return Default != 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 Release object
/// </summary>
public Release()
{
Name = string.Empty;
ItemType = ItemType.Release;
Region = string.Empty;
Language = string.Empty;
Date = string.Empty;
Default = null;
}
#endregion
#region Cloning Methods
public override object Clone()
{
return new Release()
{
ItemType = this.ItemType,
DupeType = this.DupeType,
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,
};
}
#endregion
#region Comparision Methods
public override bool Equals(DatItem other)
{
// If we don't have a release return false
if (ItemType != other.ItemType)
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);
}
#endregion
}
}

View File

@@ -0,0 +1,679 @@
using System;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using SabreTools.Core;
using SabreTools.Core.Tools;
using SabreTools.FileTypes;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
namespace SabreTools.DatItems.Formats
{
/// <summary>
/// Represents a generic file within a set
/// </summary>
[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
/// <summary>
/// Name of the item
/// </summary>
[JsonProperty("name")]
[XmlElement("name")]
public string Name { get; set; }
/// <summary>
/// What BIOS is required for this rom
/// </summary>
[JsonProperty("bios", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("bios")]
public string Bios { get; set; }
/// <summary>
/// Byte size of the rom
/// </summary>
[JsonProperty("size", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("size")]
public long? Size { get; set; } = null;
[JsonIgnore]
public bool SizeSpecified { get { return Size != null; } }
/// <summary>
/// File CRC32 hash
/// </summary>
[JsonProperty("crc", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("crc")]
public string CRC
{
get { return _crc.IsNullOrEmpty() ? null : Utilities.ByteArrayToString(_crc); }
set { _crc = (value == "null" ? Constants.CRCZeroBytes : Utilities.StringToByteArray(CleanCRC32(value))); }
}
/// <summary>
/// File MD5 hash
/// </summary>
[JsonProperty("md5", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("md5")]
public string MD5
{
get { return _md5.IsNullOrEmpty() ? null : Utilities.ByteArrayToString(_md5); }
set { _md5 = Utilities.StringToByteArray(CleanMD5(value)); }
}
/// <summary>
/// File SHA-1 hash
/// </summary>
[JsonProperty("sha1", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("sha1")]
public string SHA1
{
get { return _sha1.IsNullOrEmpty() ? null : Utilities.ByteArrayToString(_sha1); }
set { _sha1 = Utilities.StringToByteArray(CleanSHA1(value)); }
}
/// <summary>
/// File SHA-256 hash
/// </summary>
[JsonProperty("sha256", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("sha256")]
public string SHA256
{
get { return _sha256.IsNullOrEmpty() ? null : Utilities.ByteArrayToString(_sha256); }
set { _sha256 = Utilities.StringToByteArray(CleanSHA256(value)); }
}
/// <summary>
/// File SHA-384 hash
/// </summary>
[JsonProperty("sha384", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("sha384")]
public string SHA384
{
get { return _sha384.IsNullOrEmpty() ? null : Utilities.ByteArrayToString(_sha384); }
set { _sha384 = Utilities.StringToByteArray(CleanSHA384(value)); }
}
/// <summary>
/// File SHA-512 hash
/// </summary>
[JsonProperty("sha512", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("sha512")]
public string SHA512
{
get { return _sha512.IsNullOrEmpty() ? null : Utilities.ByteArrayToString(_sha512); }
set { _sha512 = Utilities.StringToByteArray(CleanSHA512(value)); }
}
/// <summary>
/// File SpamSum fuzzy hash
/// </summary>
[JsonProperty("spamsum", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("spamsum")]
public string SpamSum
{
get { return _spamsum.IsNullOrEmpty() ? null : Encoding.UTF8.GetString(_spamsum); }
set { _spamsum = Encoding.UTF8.GetBytes(value ?? string.Empty); }
}
/// <summary>
/// Rom name to merge from parent
/// </summary>
[JsonProperty("merge", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("merge")]
public string MergeTag { get; set; }
/// <summary>
/// Rom region
/// </summary>
[JsonProperty("region", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("biregionos")]
public string Region { get; set; }
/// <summary>
/// Data offset within rom
/// </summary>
[JsonProperty("offset", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("offset")]
public string Offset { get; set; }
/// <summary>
/// File created date
/// </summary>
[JsonProperty("date", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("date")]
public string Date { get; set; }
/// <summary>
/// Rom dump status
/// </summary>
[JsonProperty("status", DefaultValueHandling = DefaultValueHandling.Ignore)]
[JsonConverter(typeof(StringEnumConverter))]
[XmlElement("status")]
public ItemStatus ItemStatus { get; set; }
[JsonIgnore]
public bool ItemStatusSpecified { get { return ItemStatus != ItemStatus.NULL && ItemStatus != ItemStatus.None; } }
/// <summary>
/// Determine if the rom is optional in the set
/// </summary>
[JsonProperty("optional", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("optional")]
public bool? Optional { get; set; } = null;
[JsonIgnore]
public bool OptionalSpecified { get { return Optional != null; } }
/// <summary>
/// Determine if the CRC32 hash is inverted
/// </summary>
[JsonProperty("inverted", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("inverted")]
public bool? Inverted { get; set; } = null;
[JsonIgnore]
public bool InvertedSpecified { get { return Inverted != null; } }
#endregion
#region AttractMode
/// <summary>
/// Alternate name for the item
/// </summary>
[JsonProperty("alt_romname", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("alt_romname")]
public string AltName { get; set; }
/// <summary>
/// Alternate title for the item
/// </summary>
[JsonProperty("alt_title", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("alt_title")]
public string AltTitle { get; set; }
#endregion
#region OpenMSX
/// <summary>
/// OpenMSX sub item type
/// </summary>
[JsonProperty("original", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("original")]
public Original Original { get; set; } = null;
[JsonIgnore]
public bool OriginalSpecified { get { return Original != null && Original != default; } }
/// <summary>
/// OpenMSX sub item type
/// </summary>
[JsonProperty("openmsx_subtype", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("openmsx_subtype")]
[JsonConverter(typeof(StringEnumConverter))]
public OpenMSXSubType OpenMSXSubType { get; set; }
[JsonIgnore]
public bool OpenMSXSubTypeSpecified { get { return OpenMSXSubType != OpenMSXSubType.NULL; } }
/// <summary>
/// OpenMSX sub item type
/// </summary>
/// <remarks>Not related to the subtype above</remarks>
[JsonProperty("openmsx_type", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("openmsx_type")]
public string OpenMSXType { get; set; }
/// <summary>
/// Item remark (like a comment)
/// </summary>
[JsonProperty("remark", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("remark")]
public string Remark { get; set; }
/// <summary>
/// Boot state
/// </summary>
[JsonProperty("boot", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("boot")]
public string Boot { get; set; }
#endregion
#region SoftwareList
/// <summary>
/// Data area information
/// </summary>
[JsonProperty("dataarea", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("dataarea")]
public DataArea DataArea { get; set; } = null;
[JsonIgnore]
public bool DataAreaSpecified
{
get
{
return DataArea != null
&& (!string.IsNullOrEmpty(DataArea.Name)
|| DataArea.SizeSpecified
|| DataArea.WidthSpecified
|| DataArea.EndiannessSpecified);
}
}
/// <summary>
/// Loading flag
/// </summary>
[JsonProperty("loadflag", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("loadflag")]
[JsonConverter(typeof(StringEnumConverter))]
public LoadFlag LoadFlag { get; set; }
[JsonIgnore]
public bool LoadFlagSpecified { get { return LoadFlag != LoadFlag.NULL; } }
/// <summary>
/// Original hardware part associated with the item
/// </summary>
[JsonProperty("part", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("part")]
public Part Part { get; set; } = null;
[JsonIgnore]
public bool PartSpecified
{
get
{
return Part != null
&& (!string.IsNullOrEmpty(Part.Name)
|| !string.IsNullOrEmpty(Part.Interface));
}
}
/// <summary>
/// SoftwareList value associated with the item
/// </summary>
[JsonProperty("value", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("value")]
public string Value { get; set; }
#endregion
#endregion // Fields
#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 Rom object
/// </summary>
public Rom()
{
Name = null;
ItemType = ItemType.Rom;
DupeType = 0x00;
ItemStatus = ItemStatus.None;
}
/// <summary>
/// Create a "blank" Rom object
/// </summary>
/// <param name="name"></param>
/// <param name="machineName"></param>
/// <param name="omitFromScan"></param>
public Rom(string name, string machineName)
{
Name = name;
ItemType = ItemType.Rom;
Size = null;
ItemStatus = ItemStatus.None;
Machine = new Machine
{
Name = machineName,
Description = machineName,
};
}
/// <summary>
/// Create a Rom object from a BaseFile
/// </summary>
/// <param name="baseFile"></param>
public Rom(BaseFile baseFile)
{
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;
ItemType = ItemType.Rom;
DupeType = 0x00;
ItemStatus = ItemStatus.None;
Date = baseFile.Date;
}
#endregion
#region Cloning Methods
public override object Clone()
{
return new Rom()
{
Name = this.Name,
ItemType = this.ItemType,
DupeType = this.DupeType,
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,
Original = this.Original,
OpenMSXSubType = this.OpenMSXSubType,
OpenMSXType = this.OpenMSXType,
Remark = this.Remark,
Boot = this.Boot,
DataArea = this.DataArea,
LoadFlag = this.LoadFlag,
Part = this.Part,
Value = this.Value,
};
}
/// <summary>
/// Convert Rom object to a BaseFile
/// </summary>
public BaseFile ConvertToBaseFile()
{
return new BaseFile()
{
Filename = this.Name,
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,
};
}
#endregion
#region Comparision Methods
public override bool Equals(DatItem other)
{
bool dupefound = 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;
}
/// <summary>
/// Fill any missing size and hash information from another Rom
/// </summary>
/// <param name="other">Rom to fill information from</param>
public void FillMissingInformation(Rom other)
{
if (Size == null && other.Size != null)
Size = other.Size;
if (_crc.IsNullOrEmpty() && !other._crc.IsNullOrEmpty())
_crc = other._crc;
if (_md5.IsNullOrEmpty() && !other._md5.IsNullOrEmpty())
_md5 = other._md5;
if (_sha1.IsNullOrEmpty() && !other._sha1.IsNullOrEmpty())
_sha1 = other._sha1;
if (_sha256.IsNullOrEmpty() && !other._sha256.IsNullOrEmpty())
_sha256 = other._sha256;
if (_sha384.IsNullOrEmpty() && !other._sha384.IsNullOrEmpty())
_sha384 = other._sha384;
if (_sha512.IsNullOrEmpty() && !other._sha512.IsNullOrEmpty())
_sha512 = other._sha512;
if (_spamsum.IsNullOrEmpty() && !other._spamsum.IsNullOrEmpty())
_spamsum = other._spamsum;
}
/// <summary>
/// Get unique duplicate suffix on name collision
/// </summary>
/// <returns>String representing the suffix</returns>
public string GetDuplicateSuffix()
{
if (!_crc.IsNullOrEmpty())
return $"_{CRC}";
else if (!_md5.IsNullOrEmpty())
return $"_{MD5}";
else if (!_sha1.IsNullOrEmpty())
return $"_{SHA1}";
else if (!_sha256.IsNullOrEmpty())
return $"_{SHA256}";
else if (!_sha384.IsNullOrEmpty())
return $"_{SHA384}";
else if (!_sha512.IsNullOrEmpty())
return $"_{SHA512}";
else if (!_spamsum.IsNullOrEmpty())
return $"_{SpamSum}";
else
return "_1";
}
/// <summary>
/// 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();
}
/// <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);
}
#endregion
#region Sorting and Merging
/// <inheritdoc/>
public override string GetKey(ItemKey bucketedBy, bool lower = true, bool norename = true)
{
// Set the output key as the default blank string
string key;
// Now determine what the key should be based on the bucketedBy value
switch (bucketedBy)
{
case ItemKey.CRC:
key = CRC;
break;
case ItemKey.MD5:
key = MD5;
break;
case ItemKey.SHA1:
key = SHA1;
break;
case ItemKey.SHA256:
key = SHA256;
break;
case ItemKey.SHA384:
key = SHA384;
break;
case ItemKey.SHA512:
key = SHA512;
break;
case ItemKey.SpamSum:
key = SpamSum;
break;
// Let the base handle generic stuff
default:
return base.GetKey(bucketedBy, lower, norename);
}
// Double and triple check the key for corner cases
if (key == null)
key = string.Empty;
return key;
}
#endregion
}
}

View File

@@ -0,0 +1,84 @@
using System.Xml.Serialization;
using SabreTools.Core;
using Newtonsoft.Json;
namespace SabreTools.DatItems.Formats
{
/// <summary>
/// Represents a (usually WAV-formatted) sample to be included for use in the set
/// </summary>
[JsonObject("sample"), XmlRoot("sample")]
public class Sample : DatItem
{
#region Fields
/// <summary>
/// Name of the item
/// </summary>
[JsonProperty("name")]
[XmlElement("name")]
public string Name { get; set; }
#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 Sample object
/// </summary>
public Sample()
{
Name = string.Empty;
ItemType = ItemType.Sample;
}
#endregion
#region Cloning Methods
public override object Clone()
{
return new Sample()
{
ItemType = this.ItemType,
DupeType = this.DupeType,
Machine = this.Machine.Clone() as Machine,
Source = this.Source.Clone() as Source,
Remove = this.Remove,
Name = this.Name,
};
}
#endregion
#region Comparision Methods
public override bool Equals(DatItem other)
{
// If we don't have a sample, return false
if (ItemType != other.ItemType)
return false;
// Otherwise, treat it as a Sample
Sample newOther = other as Sample;
// If the archive information matches
return (Name == newOther.Name);
}
#endregion
}
}

View File

@@ -0,0 +1,130 @@
using System.Collections.Generic;
using System.Xml.Serialization;
using SabreTools.Core;
using Newtonsoft.Json;
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
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
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
}
}

View File

@@ -0,0 +1,92 @@
using System.Xml.Serialization;
using SabreTools.Core;
using Newtonsoft.Json;
namespace SabreTools.DatItems.Formats
{
/// <summary>
/// Represents one shared feature object
/// </summary>
[JsonObject("sharedfeat"), XmlRoot("sharedfeat")]
public class SharedFeature : DatItem
{
#region Fields
/// <summary>
/// Name of the item
/// </summary>
[JsonProperty("name")]
[XmlElement("name")]
public string Name { get; set; }
/// <summary>
/// SharedFeature value
/// </summary>
[JsonProperty("value")]
[XmlElement("value")]
public string Value { get; set; }
#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 SharedFeature object
/// </summary>
public SharedFeature()
{
Name = string.Empty;
ItemType = ItemType.SharedFeature;
}
#endregion
#region Cloning Methods
public override object Clone()
{
return new SharedFeature()
{
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,
};
}
#endregion
#region Comparision Methods
public override bool Equals(DatItem other)
{
// If we don't have a sample, return false
if (ItemType != other.ItemType)
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);
}
#endregion
}
}

View File

@@ -0,0 +1,109 @@
using System.Collections.Generic;
using System.Xml.Serialization;
using SabreTools.Core;
using Newtonsoft.Json;
namespace SabreTools.DatItems.Formats
{
/// <summary>
/// Represents which Slot(s) is associated with a set
/// </summary>
[JsonObject("slot"), XmlRoot("slot")]
public class Slot : DatItem
{
#region Fields
/// <summary>
/// Name of the item
/// </summary>
[JsonProperty("name")]
[XmlElement("name")]
public string Name { get; set; }
/// <summary>
/// Slot options associated with the slot
/// </summary>
[JsonProperty("slotoptions", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("slotoptions")]
public List<SlotOption> SlotOptions { get; set; }
[JsonIgnore]
public bool SlotOptionsSpecified { get { return SlotOptions != null && SlotOptions.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 Slot object
/// </summary>
public Slot()
{
Name = string.Empty;
ItemType = ItemType.Slot;
}
#endregion
#region Cloning Methods
public override object Clone()
{
return new Slot()
{
ItemType = this.ItemType,
DupeType = this.DupeType,
Machine = this.Machine.Clone() as Machine,
Source = this.Source.Clone() as Source,
Remove = this.Remove,
Name = this.Name,
SlotOptions = this.SlotOptions,
};
}
#endregion
#region Comparision Methods
public override bool Equals(DatItem other)
{
// If we don't have a Slot, return false
if (ItemType != other.ItemType)
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;
}
#endregion
}
}

View File

@@ -0,0 +1,105 @@
using System.Xml.Serialization;
using SabreTools.Core;
using Newtonsoft.Json;
namespace SabreTools.DatItems.Formats
{
/// <summary>
/// Represents one ListXML slotoption
/// </summary>
[JsonObject("slotoption"), XmlRoot("slotoption")]
public class SlotOption : DatItem
{
#region Fields
/// <summary>
/// Slot option name
/// </summary>
[JsonProperty("name")]
[XmlElement("name")]
public string Name { get; set; }
/// <summary>
/// Referenced device name
/// </summary>
[JsonProperty("devname")]
[XmlElement("devname")]
public string DeviceName { get; set; }
/// <summary>
/// Determines if this slot option 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; } }
#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 SlotOption object
/// </summary>
public SlotOption()
{
Name = string.Empty;
ItemType = ItemType.SlotOption;
}
#endregion
#region Cloning Methods
public override object Clone()
{
return new SlotOption()
{
ItemType = this.ItemType,
DupeType = this.DupeType,
Machine = this.Machine.Clone() as Machine,
Source = this.Source.Clone() as Source,
Remove = this.Remove,
Name = this.Name,
DeviceName = this.DeviceName,
Default = this.Default,
};
}
#endregion
#region Comparision Methods
public override bool Equals(DatItem other)
{
// If we don't have a SlotOption, return false
if (ItemType != other.ItemType)
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);
}
#endregion
}
}

View File

@@ -0,0 +1,107 @@
using System.Xml.Serialization;
using SabreTools.Core;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
namespace SabreTools.DatItems.Formats
{
/// <summary>
/// Represents which SoftwareList(s) is associated with a set
/// </summary>
[JsonObject("softwarelist"), XmlRoot("softwarelist")]
public class SoftwareList : DatItem
{
#region Fields
/// <summary>
/// Name of the item
/// </summary>
[JsonProperty("name")]
[XmlElement("name")]
public string Name { get; set; }
/// <summary>
/// Status of the softare list according to the machine
/// </summary>
[JsonProperty("status", DefaultValueHandling = DefaultValueHandling.Ignore)]
[JsonConverter(typeof(StringEnumConverter))]
[XmlElement("status")]
public SoftwareListStatus Status { get; set; }
[JsonIgnore]
public bool StatusSpecified { get { return Status != SoftwareListStatus.NULL; } }
/// <summary>
/// Filter to apply to the software list
/// </summary>
[JsonProperty("filter", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("filter")]
public string Filter { get; set; }
#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 SoftwareList object
/// </summary>
public SoftwareList()
{
Name = string.Empty;
ItemType = ItemType.SoftwareList;
}
#endregion
#region Cloning Methods
public override object Clone()
{
return new SoftwareList()
{
ItemType = this.ItemType,
DupeType = this.DupeType,
Machine = this.Machine.Clone() as Machine,
Source = this.Source.Clone() as Source,
Remove = this.Remove,
Name = this.Name,
Status = this.Status,
Filter = this.Filter,
};
}
#endregion
#region Comparision Methods
public override bool Equals(DatItem other)
{
// If we don't have a sample, return false
if (ItemType != other.ItemType)
return false;
// Otherwise, treat it as a SoftwareList
SoftwareList newOther = other as SoftwareList;
// If the SoftwareList information matches
return (Name == newOther.Name
&& Status == newOther.Status
&& Filter == newOther.Filter);
}
#endregion
}
}

View File

@@ -0,0 +1,76 @@
using System.Xml.Serialization;
using SabreTools.Core;
using Newtonsoft.Json;
namespace SabreTools.DatItems.Formats
{
/// <summary>
/// Represents the sound output for a machine
/// </summary>
[JsonObject("sound"), XmlRoot("sound")]
public class Sound : DatItem
{
#region Fields
/// <summary>
/// Number of speakers or channels
/// </summary>
[JsonProperty("channels", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("channels")]
public long? Channels { get; set; }
[JsonIgnore]
public bool ChannelsSpecified { get { return Channels != null; } }
#endregion
#region Constructors
/// <summary>
/// Create a default, empty Sound object
/// </summary>
public Sound()
{
ItemType = ItemType.Sound;
}
#endregion
#region Cloning Methods
public override object Clone()
{
return new Sound()
{
ItemType = this.ItemType,
DupeType = this.DupeType,
Machine = this.Machine.Clone() as Machine,
Source = this.Source.Clone() as Source,
Remove = this.Remove,
Channels = this.Channels,
};
}
#endregion
#region Comparision Methods
public override bool Equals(DatItem other)
{
// If we don't have a Sound, return false
if (ItemType != other.ItemType)
return false;
// Otherwise, treat it as a Sound
Sound newOther = other as Sound;
// If the Sound information matches
return (Channels == newOther.Channels);
}
#endregion
}
}