From 60818dba008edabf46cf6a4a25428240171bc95c Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Mon, 7 Sep 2020 22:00:02 -0700 Subject: [PATCH] Make items XML serializable --- SabreTools.Library/DatItems/Adjuster.cs | 11 +++ SabreTools.Library/DatItems/Analog.cs | 3 + SabreTools.Library/DatItems/Archive.cs | 3 + SabreTools.Library/DatItems/BiosSet.cs | 8 ++ SabreTools.Library/DatItems/Blank.cs | 5 +- SabreTools.Library/DatItems/Chip.cs | 14 ++- SabreTools.Library/DatItems/Condition.cs | 9 ++ SabreTools.Library/DatItems/Configuration.cs | 17 ++++ SabreTools.Library/DatItems/Control.cs | 42 +++++++++ SabreTools.Library/DatItems/DatItem.cs | 4 +- SabreTools.Library/DatItems/DataArea.cs | 15 ++++ SabreTools.Library/DatItems/Device.cs | 23 +++++ .../DatItems/DeviceReference.cs | 3 + SabreTools.Library/DatItems/DipSwitch.cs | 29 ++++++ SabreTools.Library/DatItems/Disk.cs | 43 +++++++++ SabreTools.Library/DatItems/DiskArea.cs | 3 + SabreTools.Library/DatItems/Display.cs | 55 ++++++++++++ SabreTools.Library/DatItems/Driver.cs | 18 ++++ SabreTools.Library/DatItems/Extension.cs | 3 + SabreTools.Library/DatItems/Feature.cs | 14 +++ SabreTools.Library/DatItems/Info.cs | 4 + SabreTools.Library/DatItems/Input.cs | 22 +++++ SabreTools.Library/DatItems/Instance.cs | 4 + SabreTools.Library/DatItems/Location.cs | 11 +++ SabreTools.Library/DatItems/Machine.cs | 72 ++++++--------- SabreTools.Library/DatItems/Media.cs | 7 ++ SabreTools.Library/DatItems/Part.cs | 8 ++ SabreTools.Library/DatItems/PartFeature.cs | 4 + SabreTools.Library/DatItems/Port.cs | 7 ++ SabreTools.Library/DatItems/RamOption.cs | 8 ++ SabreTools.Library/DatItems/Release.cs | 10 +++ SabreTools.Library/DatItems/Rom.cs | 90 ++++++++++--------- SabreTools.Library/DatItems/Sample.cs | 3 + SabreTools.Library/DatItems/Setting.cs | 12 +++ SabreTools.Library/DatItems/SharedFeature.cs | 4 + SabreTools.Library/DatItems/Slot.cs | 7 ++ SabreTools.Library/DatItems/SlotOption.cs | 8 ++ SabreTools.Library/DatItems/SoftwareList.cs | 8 ++ SabreTools.Library/DatItems/Sound.cs | 6 ++ 39 files changed, 523 insertions(+), 94 deletions(-) diff --git a/SabreTools.Library/DatItems/Adjuster.cs b/SabreTools.Library/DatItems/Adjuster.cs index 7e5977c4..ed8c65f5 100644 --- a/SabreTools.Library/DatItems/Adjuster.cs +++ b/SabreTools.Library/DatItems/Adjuster.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Xml.Serialization; using SabreTools.Library.Filtering; using SabreTools.Library.Tools; @@ -12,6 +13,7 @@ namespace SabreTools.Library.DatItems /// Represents which Adjuster(s) is associated with a set /// [JsonObject("adjuster")] + [XmlRoot("adjuster")] public class Adjuster : DatItem { #region Fields @@ -20,20 +22,29 @@ namespace SabreTools.Library.DatItems /// Name of the item /// [JsonProperty("name")] + [XmlElement("name")] public string Name { get; set; } /// /// Determine whether the value is default /// [JsonProperty("default", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("default")] public bool? Default { get; set; } + [JsonIgnore] + public bool DefaultSpecified { get { return Default != null; } } + /// /// Conditions associated with the adjustment /// [JsonProperty("conditions", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("conditions")] public List Conditions { get; set; } + [JsonIgnore] + public bool ConditionsSpecified { get { return Conditions != null && Conditions.Count > 0; } } + #endregion #region Accessors diff --git a/SabreTools.Library/DatItems/Analog.cs b/SabreTools.Library/DatItems/Analog.cs index 568ce31e..3ceae77e 100644 --- a/SabreTools.Library/DatItems/Analog.cs +++ b/SabreTools.Library/DatItems/Analog.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.Linq; +using System.Xml.Serialization; using SabreTools.Library.Filtering; using Newtonsoft.Json; @@ -10,6 +11,7 @@ namespace SabreTools.Library.DatItems /// Represents a single analog item /// [JsonObject("analog")] + [XmlRoot("analog")] public class Analog : DatItem { #region Fields @@ -18,6 +20,7 @@ namespace SabreTools.Library.DatItems /// Analog mask value /// [JsonProperty("mask", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("mask")] public string Mask { get; set; } #endregion diff --git a/SabreTools.Library/DatItems/Archive.cs b/SabreTools.Library/DatItems/Archive.cs index 4808ac0f..f8caf799 100644 --- a/SabreTools.Library/DatItems/Archive.cs +++ b/SabreTools.Library/DatItems/Archive.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Xml.Serialization; using SabreTools.Library.Filtering; using SabreTools.Library.Tools; @@ -12,6 +13,7 @@ namespace SabreTools.Library.DatItems /// Represents generic archive files to be included in a set /// [JsonObject("archive")] + [XmlRoot("archive")] public class Archive : DatItem { #region Fields @@ -20,6 +22,7 @@ namespace SabreTools.Library.DatItems /// Name of the item /// [JsonProperty("name")] + [XmlElement("name")] public string Name { get; set; } #endregion diff --git a/SabreTools.Library/DatItems/BiosSet.cs b/SabreTools.Library/DatItems/BiosSet.cs index a5dad455..65b93278 100644 --- a/SabreTools.Library/DatItems/BiosSet.cs +++ b/SabreTools.Library/DatItems/BiosSet.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Xml.Serialization; using SabreTools.Library.Filtering; using SabreTools.Library.Tools; @@ -12,6 +13,7 @@ namespace SabreTools.Library.DatItems /// Represents which BIOS(es) is associated with a set /// [JsonObject("biosset")] + [XmlRoot("biosset")] public class BiosSet : DatItem { #region Fields @@ -20,20 +22,26 @@ namespace SabreTools.Library.DatItems /// Name of the item /// [JsonProperty("name")] + [XmlElement("name")] public string Name { get; set; } /// /// Description of the BIOS /// [JsonProperty("description", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("description")] public string Description { get; set; } /// /// Determine whether the BIOS is default /// [JsonProperty("default", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("default")] public bool? Default { get; set; } + [JsonIgnore] + public bool DefaultSpecified { get { return Default != null; } } + #endregion #region Accessors diff --git a/SabreTools.Library/DatItems/Blank.cs b/SabreTools.Library/DatItems/Blank.cs index 0ef83ba0..b2cd3f08 100644 --- a/SabreTools.Library/DatItems/Blank.cs +++ b/SabreTools.Library/DatItems/Blank.cs @@ -1,4 +1,6 @@ -using Newtonsoft.Json; +using System.Xml.Serialization; + +using Newtonsoft.Json; namespace SabreTools.Library.DatItems { @@ -6,6 +8,7 @@ namespace SabreTools.Library.DatItems /// Represents a blank set from an input DAT /// [JsonObject("blank")] + [XmlRoot("blank")] public class Blank : DatItem { #region Constructors diff --git a/SabreTools.Library/DatItems/Chip.cs b/SabreTools.Library/DatItems/Chip.cs index 860c81cf..d40022f7 100644 --- a/SabreTools.Library/DatItems/Chip.cs +++ b/SabreTools.Library/DatItems/Chip.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Xml.Serialization; using SabreTools.Library.Filtering; using SabreTools.Library.Tools; @@ -14,6 +15,7 @@ namespace SabreTools.Library.DatItems /// Represents which Chip(s) is associated with a set /// [JsonObject("chip")] + [XmlRoot("chip")] public class Chip : DatItem { #region Fields @@ -22,27 +24,37 @@ namespace SabreTools.Library.DatItems /// Name of the item /// [JsonProperty("name")] + [XmlElement("name")] public string Name { get; set; } /// /// Internal tag /// [JsonProperty("tag", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("tag")] public string Tag { get; set; } /// /// Type of the chip /// - [JsonProperty("chiptype", DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonProperty("type", DefaultValueHandling = DefaultValueHandling.Ignore)] [JsonConverter(typeof(StringEnumConverter))] + [XmlElement("type")] public ChipType ChipType { get; set; } + [JsonIgnore] + public bool ChipTypeSpecified { get { return ChipType != ChipType.NULL; } } + /// /// Clock speed /// [JsonProperty("clock", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("clock")] public long? Clock { get; set; } + [JsonIgnore] + public bool ClockTypeSpecified { get { return Clock != null; } } + #endregion #region Accessors diff --git a/SabreTools.Library/DatItems/Condition.cs b/SabreTools.Library/DatItems/Condition.cs index 27024aae..ed1c6d95 100644 --- a/SabreTools.Library/DatItems/Condition.cs +++ b/SabreTools.Library/DatItems/Condition.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.Linq; +using System.Xml.Serialization; using SabreTools.Library.Filtering; using SabreTools.Library.Tools; @@ -12,6 +13,7 @@ namespace SabreTools.Library.DatItems /// Represents a condition on a machine or other item /// [JsonObject("condition")] + [XmlRoot("condition")] public class Condition : DatItem { #region Fields @@ -20,12 +22,14 @@ namespace SabreTools.Library.DatItems /// Condition tag value /// [JsonProperty("tag", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("tag")] public string Tag { get; set; } /// /// Condition mask /// [JsonProperty("mask", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("mask")] public string Mask { get; set; } /// @@ -33,12 +37,17 @@ namespace SabreTools.Library.DatItems /// [JsonProperty("relation", DefaultValueHandling = DefaultValueHandling.Ignore)] [JsonConverter(typeof(StringEnumConverter))] + [XmlElement("relation")] public Relation Relation { get; set; } + [JsonIgnore] + public bool RelationSpecified { get { return Relation != Relation.NULL; } } + /// /// Condition value /// [JsonProperty("value", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("value")] public string Value { get; set; } #endregion diff --git a/SabreTools.Library/DatItems/Configuration.cs b/SabreTools.Library/DatItems/Configuration.cs index 18fc3ab7..7c0c1c1a 100644 --- a/SabreTools.Library/DatItems/Configuration.cs +++ b/SabreTools.Library/DatItems/Configuration.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Xml.Serialization; using SabreTools.Library.Filtering; using SabreTools.Library.Tools; @@ -12,6 +13,7 @@ namespace SabreTools.Library.DatItems /// Represents which Configuration(s) is associated with a set /// [JsonObject("configuration")] + [XmlRoot("configuration")] public class Configuration : DatItem { #region Fields @@ -20,38 +22,53 @@ namespace SabreTools.Library.DatItems /// Name of the item /// [JsonProperty("name")] + [XmlElement("name")] public string Name { get; set; } /// /// Tag associated with the configuration /// [JsonProperty("tag", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("tag")] public string Tag { get; set; } /// /// Mask associated with the configuration /// [JsonProperty("mask", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("mask")] public string Mask { get; set; } /// /// Conditions associated with the configuration /// [JsonProperty("conditions", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("conditions")] public List Conditions { get; set; } + [JsonIgnore] + public bool ConditionsSpecified { get { return Conditions != null && Conditions.Count > 0; } } + /// /// Locations associated with the configuration /// [JsonProperty("locations", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("locations")] public List Locations { get; set; } + [JsonIgnore] + public bool LocationsSpecified { get { return Locations != null && Locations.Count > 0; } } + /// /// Settings associated with the configuration /// [JsonProperty("settings", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("settings")] public List Settings { get; set; } + [JsonIgnore] + public bool SettingsSpecified { get { return Settings != null && Settings.Count > 0; } } + #endregion #region Accessors diff --git a/SabreTools.Library/DatItems/Control.cs b/SabreTools.Library/DatItems/Control.cs index 4acdc252..6c597cde 100644 --- a/SabreTools.Library/DatItems/Control.cs +++ b/SabreTools.Library/DatItems/Control.cs @@ -1,10 +1,12 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Xml.Serialization; using SabreTools.Library.Filtering; using SabreTools.Library.Tools; using Newtonsoft.Json; +using Newtonsoft.Json.Converters; namespace SabreTools.Library.DatItems { @@ -12,6 +14,7 @@ namespace SabreTools.Library.DatItems /// Represents control for an input /// [JsonObject("control")] + [XmlRoot("control")] public class Control : DatItem { #region Fields @@ -20,56 +23,93 @@ namespace SabreTools.Library.DatItems /// General type of input /// [JsonProperty("type", DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonConverter(typeof(StringEnumConverter))] + [XmlElement("type")] public ControlType ControlType { get; set; } + [JsonIgnore] + public bool ControlTypeSpecified { get { return ControlType != ControlType.NULL; } } + /// /// Player which the input belongs to /// [JsonProperty("player", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("player")] public long? Player { get; set; } + [JsonIgnore] + public bool PlayerSpecified { get { return Player != null; } } + /// /// Total number of buttons /// [JsonProperty("buttons", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("buttons")] public long? Buttons { get; set; } + [JsonIgnore] + public bool ButtonsSpecified { get { return Buttons != null; } } + /// /// Total number of non-optional buttons /// [JsonProperty("reqbuttons", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("reqbuttons")] public long? RequiredButtons { get; set; } + [JsonIgnore] + public bool RequiredButtonsSpecified { get { return RequiredButtons != null; } } + /// /// Analog minimum value /// [JsonProperty("minimum", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("minimum")] public long? Minimum { get; set; } + [JsonIgnore] + public bool MinimumSpecified { get { return Minimum != null; } } + /// /// Analog maximum value /// [JsonProperty("maximum", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("maximum")] public long? Maximum { get; set; } + [JsonIgnore] + public bool MaximumSpecified { get { return Maximum != null; } } + /// /// Default analog sensitivity /// [JsonProperty("sensitivity", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("sensitivity")] public long? Sensitivity { get; set; } + [JsonIgnore] + public bool SensitivitySpecified { get { return Sensitivity != null; } } + /// /// Default analog keydelta /// [JsonProperty("keydelta", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("keydelta")] public long? KeyDelta { get; set; } + [JsonIgnore] + public bool KeyDeltaSpecified { get { return KeyDelta != null; } } + /// /// Default analog reverse setting /// [JsonProperty("reverse", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("type")] public bool? Reverse { get; set; } + [JsonIgnore] + public bool ReverseSpecified { get { return Reverse != null; } } + /// /// First set of ways /// @@ -80,12 +120,14 @@ namespace SabreTools.Library.DatItems /// Second set of ways /// [JsonProperty("ways2", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("type")] public string Ways2 { get; set; } /// /// Third set of ways /// [JsonProperty("ways3", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("type")] public string Ways3 { get; set; } #endregion diff --git a/SabreTools.Library/DatItems/DatItem.cs b/SabreTools.Library/DatItems/DatItem.cs index 0d8438bd..79ed15c4 100644 --- a/SabreTools.Library/DatItems/DatItem.cs +++ b/SabreTools.Library/DatItems/DatItem.cs @@ -65,9 +65,9 @@ namespace SabreTools.Library.DatItems /// /// Item type for outputting /// - [JsonProperty("type")] + [JsonProperty("itemtype")] [JsonConverter(typeof(StringEnumConverter))] - [XmlAttribute("type")] + [XmlElement("itemtype")] public ItemType ItemType { get; set; } /// diff --git a/SabreTools.Library/DatItems/DataArea.cs b/SabreTools.Library/DatItems/DataArea.cs index 1fd455b4..0be4d43d 100644 --- a/SabreTools.Library/DatItems/DataArea.cs +++ b/SabreTools.Library/DatItems/DataArea.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Xml.Serialization; using SabreTools.Library.Filtering; using SabreTools.Library.Tools; @@ -14,6 +15,7 @@ namespace SabreTools.Library.DatItems /// /// One DataArea can contain multiple Rom items [JsonObject("dataarea")] + [XmlRoot("dataarea")] public class DataArea : DatItem { #region Fields @@ -22,26 +24,39 @@ namespace SabreTools.Library.DatItems /// Name of the item /// [JsonProperty("name", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("name")] public string Name { get; set; } /// /// Total size of the area /// [JsonProperty("size", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("size")] public long? Size { get; set; } + [JsonIgnore] + public bool SizeSpecified { get { return Size != null; } } + /// /// Word width for the area /// [JsonProperty("width", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("width")] public long? Width { get; set; } + [JsonIgnore] + public bool WidthSpecified { get { return Width != null; } } + /// /// Byte endianness of the area /// [JsonProperty("endianness", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("endianness")] public Endianness Endianness { get; set; } + [JsonIgnore] + public bool EndiannessSpecified { get { return Endianness != Endianness.NULL; } } + #endregion #region Accessors diff --git a/SabreTools.Library/DatItems/Device.cs b/SabreTools.Library/DatItems/Device.cs index d214fbf9..02999ae7 100644 --- a/SabreTools.Library/DatItems/Device.cs +++ b/SabreTools.Library/DatItems/Device.cs @@ -1,9 +1,11 @@ using System.Collections.Generic; using System.Linq; +using System.Xml.Serialization; using SabreTools.Library.Filtering; using SabreTools.Library.Tools; using Newtonsoft.Json; +using Newtonsoft.Json.Converters; namespace SabreTools.Library.DatItems { @@ -11,6 +13,7 @@ namespace SabreTools.Library.DatItems /// Represents a single device on the machine /// [JsonObject("device")] + [XmlRoot("device")] public class Device : DatItem { #region Fields @@ -19,18 +22,25 @@ namespace SabreTools.Library.DatItems /// Device type /// [JsonProperty("type", DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonConverter(typeof(StringEnumConverter))] + [XmlElement("type")] public DeviceType DeviceType { get; set; } + [JsonIgnore] + public bool DeviceTypeSpecified { get { return DeviceType != DeviceType.NULL; } } + /// /// Device tag /// [JsonProperty("tag", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("tag")] public string Tag { get; set; } /// /// Fixed image format /// [JsonProperty("fixed_image", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("fixed_image")] public string FixedImage { get; set; } /// @@ -38,26 +48,39 @@ namespace SabreTools.Library.DatItems /// /// Only value used seems to be 1. Used like bool, but actually int [JsonProperty("mandatory", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("mandatory")] public long? Mandatory { get; set; } + [JsonIgnore] + public bool MandatorySpecified { get { return Mandatory != null; } } + /// /// Device interface /// [JsonProperty("interface", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("interface")] public string Interface { get; set; } /// /// Device instances /// [JsonProperty("instances", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("instances")] public List Instances { get; set; } + [JsonIgnore] + public bool InstancesSpecified { get { return Instances != null && Instances.Count > 0; } } + /// /// Device extensions /// [JsonProperty("extensions", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("extensions")] public List Extensions { get; set; } + [JsonIgnore] + public bool ExtensionsSpecified { get { return Extensions != null && Extensions.Count > 0; } } + #endregion #region Accessors diff --git a/SabreTools.Library/DatItems/DeviceReference.cs b/SabreTools.Library/DatItems/DeviceReference.cs index c7222cee..c0c2842b 100644 --- a/SabreTools.Library/DatItems/DeviceReference.cs +++ b/SabreTools.Library/DatItems/DeviceReference.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Xml.Serialization; using SabreTools.Library.Filtering; using SabreTools.Library.Tools; @@ -12,6 +13,7 @@ namespace SabreTools.Library.DatItems /// Represents which Device Reference(s) is associated with a set /// [JsonObject("device_ref")] + [XmlRoot("device_ref")] public class DeviceReference : DatItem { #region Fields @@ -20,6 +22,7 @@ namespace SabreTools.Library.DatItems /// Name of the item /// [JsonProperty("name")] + [XmlElement("name")] public string Name { get; set; } #endregion diff --git a/SabreTools.Library/DatItems/DipSwitch.cs b/SabreTools.Library/DatItems/DipSwitch.cs index 3b43d1b3..e39932dd 100644 --- a/SabreTools.Library/DatItems/DipSwitch.cs +++ b/SabreTools.Library/DatItems/DipSwitch.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Xml.Serialization; using SabreTools.Library.Filtering; using SabreTools.Library.Tools; @@ -12,6 +13,7 @@ namespace SabreTools.Library.DatItems /// Represents which DIP Switch(es) is associated with a set /// [JsonObject("dipswitch")] + [XmlRoot("dipswitch")] public class DipSwitch : DatItem { #region Fields @@ -22,38 +24,53 @@ namespace SabreTools.Library.DatItems /// Name of the item /// [JsonProperty("name")] + [XmlElement("name")] public string Name { get; set; } /// /// Tag associated with the dipswitch /// [JsonProperty("tag", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("tag")] public string Tag { get; set; } /// /// Mask associated with the dipswitch /// [JsonProperty("mask", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("mask")] public string Mask { get; set; } /// /// Conditions associated with the dipswitch /// [JsonProperty("conditions", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("conditions")] public List Conditions { get; set; } + [JsonIgnore] + public bool ConditionsSpecified { get { return Conditions != null && Conditions.Count > 0; } } + /// /// Locations associated with the dipswitch /// [JsonProperty("locations", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("locations")] public List Locations { get; set; } + [JsonIgnore] + public bool LocationsSpecified { get { return Locations != null && Locations.Count > 0; } } + /// /// Settings associated with the dipswitch /// [JsonProperty("values", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("values")] public List Values { get; set; } + [JsonIgnore] + public bool ValuesSpecified { get { return Values != null && Values.Count > 0; } } + #endregion #region SoftwareList @@ -62,8 +79,20 @@ namespace SabreTools.Library.DatItems /// Original hardware part associated with the item /// [JsonProperty("part", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("part")] public Part Part { get; set; } + [JsonIgnore] + public bool PartSpecified + { + get + { + return Part != null && Part != default + && ((Part.Name != null && Part.Name != default) + || (Part.Interface != null && Part.Interface != default)); + } + } + #endregion #endregion // Fields diff --git a/SabreTools.Library/DatItems/Disk.cs b/SabreTools.Library/DatItems/Disk.cs index d34bb75a..c8cc3e26 100644 --- a/SabreTools.Library/DatItems/Disk.cs +++ b/SabreTools.Library/DatItems/Disk.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Xml.Serialization; using SabreTools.Library.FileTypes; using SabreTools.Library.Filtering; @@ -14,6 +15,7 @@ namespace SabreTools.Library.DatItems /// Represents Compressed Hunks of Data (CHD) formatted disks which use internal hashes /// [JsonObject("disk")] + [XmlRoot("disk")] public class Disk : DatItem { #region Private instance variables @@ -31,12 +33,14 @@ namespace SabreTools.Library.DatItems /// Name of the item /// [JsonProperty("name")] + [XmlElement("name")] public string Name { get; set; } /// /// Data MD5 hash /// [JsonProperty("md5", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("md5")] public string MD5 { get { return _md5.IsNullOrEmpty() ? null : Utilities.ByteArrayToString(_md5); } @@ -47,6 +51,7 @@ namespace SabreTools.Library.DatItems /// Data SHA-1 hash /// [JsonProperty("sha1", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("sha1")] public string SHA1 { get { return _sha1.IsNullOrEmpty() ? null : Utilities.ByteArrayToString(_sha1); } @@ -57,39 +62,54 @@ namespace SabreTools.Library.DatItems /// Disk name to merge from parent /// [JsonProperty("merge", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("merge")] public string MergeTag { get; set; } /// /// Disk region /// [JsonProperty("region", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("region")] public string Region { get; set; } /// /// Disk index /// [JsonProperty("index", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("index")] public string Index { get; set; } /// /// Disk writable flag /// [JsonProperty("writable", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("writable")] public bool? Writable { get; set; } + [JsonIgnore] + public bool WritableSpecified { get { return Writable != null; } } + /// /// Disk dump status /// [JsonProperty("status", DefaultValueHandling = DefaultValueHandling.Ignore)] [JsonConverter(typeof(StringEnumConverter))] + [XmlElement("status")] public ItemStatus ItemStatus { get; set; } + [JsonIgnore] + public bool ItemStatusSpecified { get { return ItemStatus != ItemStatus.NULL; } } + /// /// Determine if the disk is optional in the set /// [JsonProperty("optional", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("optional")] public bool? Optional { get; set; } + [JsonIgnore] + public bool OptionalSpecified { get { return Optional != null; } } + #endregion #region SoftwareList @@ -98,14 +118,37 @@ namespace SabreTools.Library.DatItems /// Disk area information /// [JsonProperty("diskarea", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("diskarea")] public DiskArea DiskArea { get; set; } + [JsonIgnore] + public bool DiskAreaSpecified + { + get + { + return DiskArea != null && DiskArea != default + && DiskArea.Name != null && DiskArea.Name != default; + } + } + /// /// Original hardware part associated with the item /// [JsonProperty("part", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("part")] public Part Part { get; set; } + [JsonIgnore] + public bool PartSpecified + { + get + { + return Part != null && Part != default + && ((Part.Name != null && Part.Name != default) + || (Part.Interface != null && Part.Interface != default)); + } + } + #endregion #endregion // Fields diff --git a/SabreTools.Library/DatItems/DiskArea.cs b/SabreTools.Library/DatItems/DiskArea.cs index 57eb9c50..41983885 100644 --- a/SabreTools.Library/DatItems/DiskArea.cs +++ b/SabreTools.Library/DatItems/DiskArea.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Xml.Serialization; using SabreTools.Library.Filtering; using SabreTools.Library.Tools; @@ -14,6 +15,7 @@ namespace SabreTools.Library.DatItems /// /// One DiskArea can contain multiple Disk items [JsonObject("diskarea")] + [XmlRoot("diskarea")] public class DiskArea : DatItem { #region Fields @@ -22,6 +24,7 @@ namespace SabreTools.Library.DatItems /// Name of the item /// [JsonProperty("name", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("name")] public string Name { get; set; } #endregion diff --git a/SabreTools.Library/DatItems/Display.cs b/SabreTools.Library/DatItems/Display.cs index 905aa00a..a8142fde 100644 --- a/SabreTools.Library/DatItems/Display.cs +++ b/SabreTools.Library/DatItems/Display.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Xml.Serialization; using SabreTools.Library.Filtering; using SabreTools.Library.Tools; @@ -13,6 +14,7 @@ namespace SabreTools.Library.DatItems /// Represents one machine display /// [JsonObject("display")] + [XmlRoot("display")] public class Display : DatItem { #region Fields @@ -21,6 +23,7 @@ namespace SabreTools.Library.DatItems /// Display tag /// [JsonProperty("tag", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("tag")] public string Tag { get; set; } /// @@ -28,80 +31,132 @@ namespace SabreTools.Library.DatItems /// [JsonProperty("type", DefaultValueHandling = DefaultValueHandling.Ignore)] [JsonConverter(typeof(StringEnumConverter))] + [XmlElement("type")] public DisplayType DisplayType { get; set; } + [JsonIgnore] + public bool DisplayTypeSpecified { get { return DisplayType != DisplayType.NULL; } } + /// /// Display rotation /// [JsonProperty("rotate", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("rotate")] public long? Rotate { get; set; } + [JsonIgnore] + public bool RotateSpecified { get { return Rotate != null; } } + /// /// Determines if display is flipped in the X-coordinates /// [JsonProperty("flipx", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("flipx")] public bool? FlipX { get; set; } + [JsonIgnore] + public bool FlipXSpecified { get { return FlipX != null; } } + /// /// Display width /// [JsonProperty("width", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("width")] public long? Width { get; set; } + [JsonIgnore] + public bool WidthSpecified { get { return Width != null; } } + /// /// Display height /// [JsonProperty("height", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("height")] public long? Height { get; set; } + [JsonIgnore] + public bool HeightSpecified { get { return Height != null; } } + /// /// Refresh rate /// [JsonProperty("refresh", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("refresh")] public double? Refresh { get; set; } + [JsonIgnore] + public bool RefreshSpecified { get { return Refresh != null; } } + /// /// Pixel clock timer /// [JsonProperty("pixclock", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("pixclock")] public long? PixClock { get; set; } + [JsonIgnore] + public bool PixClockSpecified { get { return PixClock != null; } } + /// /// Total horizontal lines /// [JsonProperty("htotal", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("htotal")] public long? HTotal { get; set; } + [JsonIgnore] + public bool HTotalSpecified { get { return HTotal != null; } } + /// /// Horizontal blank end /// [JsonProperty("hbend", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("hbend")] public long? HBEnd { get; set; } + [JsonIgnore] + public bool HBEndSpecified { get { return HBEnd != null; } } + /// /// Horizontal blank start /// [JsonProperty("hbstart", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("hbstart")] public long? HBStart { get; set; } + [JsonIgnore] + public bool HBStartSpecified { get { return HBStart != null; } } + /// /// Total vertical lines /// [JsonProperty("vtotal", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("vtotal")] public long? VTotal { get; set; } + [JsonIgnore] + public bool VTotalSpecified { get { return VTotal != null; } } + /// /// Vertical blank end /// [JsonProperty("vbend", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("vbend")] public long? VBEnd { get; set; } + [JsonIgnore] + public bool VBEndSpecified { get { return VBEnd != null; } } + /// /// Vertical blank start /// [JsonProperty("vbstart", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("vbstart")] public long? VBStart { get; set; } + [JsonIgnore] + public bool VBStartSpecified { get { return VBStart != null; } } + #endregion #region Accessors diff --git a/SabreTools.Library/DatItems/Driver.cs b/SabreTools.Library/DatItems/Driver.cs index a873433b..89572862 100644 --- a/SabreTools.Library/DatItems/Driver.cs +++ b/SabreTools.Library/DatItems/Driver.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.Linq; +using System.Xml.Serialization; using SabreTools.Library.Filtering; using SabreTools.Library.Tools; @@ -12,6 +13,7 @@ namespace SabreTools.Library.DatItems /// Represents the a driver of the machine /// [JsonObject("driver")] + [XmlRoot("driver")] public class Driver : DatItem { #region Fields @@ -21,29 +23,45 @@ namespace SabreTools.Library.DatItems /// [JsonProperty("status", DefaultValueHandling = DefaultValueHandling.Ignore)] [JsonConverter(typeof(StringEnumConverter))] + [XmlElement("status")] public SupportStatus Status { get; set; } + [JsonIgnore] + public bool StatusSpecified { get { return Status != SupportStatus.NULL; } } + /// /// Driver emulation status /// [JsonProperty("emulation", DefaultValueHandling = DefaultValueHandling.Ignore)] [JsonConverter(typeof(StringEnumConverter))] + [XmlElement("emulation")] public SupportStatus Emulation { get; set; } + [JsonIgnore] + public bool EmulationSpecified { get { return Emulation != SupportStatus.NULL; ; } } + /// /// Cocktail orientation status /// [JsonProperty("cocktail", DefaultValueHandling = DefaultValueHandling.Ignore)] [JsonConverter(typeof(StringEnumConverter))] + [XmlElement("cocktail")] public SupportStatus Cocktail { get; set; } + [JsonIgnore] + public bool CocktailSpecified { get { return Cocktail != SupportStatus.NULL; ; } } + /// /// Save state support status /// [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 Accessors diff --git a/SabreTools.Library/DatItems/Extension.cs b/SabreTools.Library/DatItems/Extension.cs index ea4df034..6411109a 100644 --- a/SabreTools.Library/DatItems/Extension.cs +++ b/SabreTools.Library/DatItems/Extension.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Xml.Serialization; using SabreTools.Library.Filtering; using SabreTools.Library.Tools; @@ -12,6 +13,7 @@ namespace SabreTools.Library.DatItems /// Represents a matchable extension /// [JsonObject("extension")] + [XmlRoot("extension")] public class Extension : DatItem { #region Fields @@ -20,6 +22,7 @@ namespace SabreTools.Library.DatItems /// Name of the item /// [JsonProperty("name")] + [XmlElement("name")] public string Name { get; set; } #endregion diff --git a/SabreTools.Library/DatItems/Feature.cs b/SabreTools.Library/DatItems/Feature.cs index 3422b96b..c99968ce 100644 --- a/SabreTools.Library/DatItems/Feature.cs +++ b/SabreTools.Library/DatItems/Feature.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.Linq; +using System.Xml.Serialization; using SabreTools.Library.Filtering; using SabreTools.Library.Tools; @@ -12,6 +13,7 @@ namespace SabreTools.Library.DatItems /// Represents the a feature of the machine /// [JsonObject("feature")] + [XmlRoot("feature")] public class Feature : DatItem { #region Fields @@ -21,22 +23,34 @@ namespace SabreTools.Library.DatItems /// [JsonProperty("type", DefaultValueHandling = DefaultValueHandling.Ignore)] [JsonConverter(typeof(StringEnumConverter))] + [XmlElement("type")] public FeatureType Type { get; set; } + [JsonIgnore] + public bool TypeSpecified { get { return Type != FeatureType.NULL; } } + /// /// Emulation status /// [JsonProperty("status", DefaultValueHandling = DefaultValueHandling.Ignore)] [JsonConverter(typeof(StringEnumConverter))] + [XmlElement("status")] public FeatureStatus Status { get; set; } + [JsonIgnore] + public bool StatusSpecified { get { return Status != FeatureStatus.NULL; } } + /// /// Overall status /// [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 Accessors diff --git a/SabreTools.Library/DatItems/Info.cs b/SabreTools.Library/DatItems/Info.cs index ffd21dee..4ec9d643 100644 --- a/SabreTools.Library/DatItems/Info.cs +++ b/SabreTools.Library/DatItems/Info.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Xml.Serialization; using SabreTools.Library.Filtering; using SabreTools.Library.Tools; @@ -12,6 +13,7 @@ namespace SabreTools.Library.DatItems /// Represents special information about a machine /// [JsonObject("info")] + [XmlRoot("info")] public class Info : DatItem { #region Fields @@ -20,12 +22,14 @@ namespace SabreTools.Library.DatItems /// Name of the item /// [JsonProperty("name")] + [XmlElement("name")] public string Name { get; set; } /// /// Information value /// [JsonProperty("value")] + [XmlElement("value")] public string Value { get; set; } #endregion diff --git a/SabreTools.Library/DatItems/Input.cs b/SabreTools.Library/DatItems/Input.cs index 8615864d..5167405d 100644 --- a/SabreTools.Library/DatItems/Input.cs +++ b/SabreTools.Library/DatItems/Input.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Xml.Serialization; using SabreTools.Library.Filtering; using SabreTools.Library.Tools; @@ -12,6 +13,7 @@ namespace SabreTools.Library.DatItems /// Represents one ListXML input /// [JsonObject("input")] + [XmlRoot("input")] public class Input : DatItem { #region Fields @@ -20,32 +22,52 @@ namespace SabreTools.Library.DatItems /// Input service ID /// [JsonProperty("service", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("service")] public bool? Service { get; set; } + [JsonIgnore] + public bool ServiceSpecified { get { return Service != null; } } + /// /// Determins if this has a tilt sensor /// [JsonProperty("tilt", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("tilt")] public bool? Tilt { get; set; } + [JsonIgnore] + public bool TiltSpecified { get { return Tilt != null; } } + /// /// Number of players on the input /// [JsonProperty("players", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("players")] public long? Players { get; set; } + [JsonIgnore] + public bool PlayersSpecified { get { return Players != null; } } + /// /// Number of coins required /// [JsonProperty("coins", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("coins")] public long? Coins { get; set; } + [JsonIgnore] + public bool CoinsSpecified { get { return Coins != null; } } + /// /// Set of controls for the input /// [JsonProperty("controls", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("controls")] public List Controls { get; set; } + [JsonIgnore] + public bool ControlsSpecified { get { return Controls != null && Controls.Count > 0; } } + #endregion #region Accessors diff --git a/SabreTools.Library/DatItems/Instance.cs b/SabreTools.Library/DatItems/Instance.cs index 8881e152..be813141 100644 --- a/SabreTools.Library/DatItems/Instance.cs +++ b/SabreTools.Library/DatItems/Instance.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Xml.Serialization; using SabreTools.Library.Filtering; using SabreTools.Library.Tools; @@ -12,6 +13,7 @@ namespace SabreTools.Library.DatItems /// Represents a single instance of another item /// [JsonObject("instance")] + [XmlRoot("instance")] public class Instance : DatItem { #region Fields @@ -20,12 +22,14 @@ namespace SabreTools.Library.DatItems /// Name of the item /// [JsonProperty("name")] + [XmlElement("name")] public string Name { get; set; } /// /// Short name for the instance /// [JsonProperty("briefname", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("briefname")] public string BriefName { get; set; } #endregion diff --git a/SabreTools.Library/DatItems/Location.cs b/SabreTools.Library/DatItems/Location.cs index 246a540e..3910e73a 100644 --- a/SabreTools.Library/DatItems/Location.cs +++ b/SabreTools.Library/DatItems/Location.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Xml.Serialization; using SabreTools.Library.Filtering; using SabreTools.Library.Tools; @@ -12,6 +13,7 @@ namespace SabreTools.Library.DatItems /// Represents one conflocation or diplocation /// [JsonObject("location")] + [XmlRoot("location")] public class Location : DatItem { #region Fields @@ -20,20 +22,29 @@ namespace SabreTools.Library.DatItems /// Location name /// [JsonProperty("name")] + [XmlElement("name")] public string Name { get; set; } /// /// Location ID /// [JsonProperty("number", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("number")] public long? Number { get; set; } + [JsonIgnore] + public bool NumberSpecified { get { return Number != null; } } + /// /// Determines if location is inverted or not /// [JsonProperty("inverted", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("inverted")] public bool? Inverted { get; set; } + [JsonIgnore] + public bool InvertedSpecified { get { return Inverted != null; } } + #endregion #region Accessors diff --git a/SabreTools.Library/DatItems/Machine.cs b/SabreTools.Library/DatItems/Machine.cs index 9bc0da70..653a69bd 100644 --- a/SabreTools.Library/DatItems/Machine.cs +++ b/SabreTools.Library/DatItems/Machine.cs @@ -19,13 +19,13 @@ namespace SabreTools.Library.DatItems { #region Fields - #region Common Fields + #region Common /// /// Name of the machine /// [JsonProperty("name", DefaultValueHandling = DefaultValueHandling.Include)] - [XmlAttribute("name")] + [XmlElement("name")] public string Name { get; set; } = null; /// @@ -75,21 +75,21 @@ namespace SabreTools.Library.DatItems /// fomof parent /// [JsonProperty("romof", DefaultValueHandling = DefaultValueHandling.Ignore)] - [XmlAttribute("romof")] + [XmlElement("romof")] public string RomOf { get; set; } = null; /// /// cloneof parent /// [JsonProperty("cloneof", DefaultValueHandling = DefaultValueHandling.Ignore)] - [XmlAttribute("cloneof")] + [XmlElement("cloneof")] public string CloneOf { get; set; } = null; /// /// sampleof parent /// [JsonProperty("sampleof", DefaultValueHandling = DefaultValueHandling.Ignore)] - [XmlAttribute("sampleof")] + [XmlElement("sampleof")] public string SampleOf { get; set; } = null; /// @@ -97,12 +97,15 @@ namespace SabreTools.Library.DatItems /// [JsonProperty("type", DefaultValueHandling = DefaultValueHandling.Ignore)] [JsonConverter(typeof(StringEnumConverter))] - [XmlAttribute("type")] + [XmlElement("type")] public MachineType MachineType { get; set; } = 0x0; + [JsonIgnore] + public bool MachineTypeSpecified { get { return MachineType != 0x0 && MachineType != MachineType.NULL; } } + #endregion - #region AttractMode Fields + #region AttractMode /// /// Player count @@ -156,14 +159,14 @@ namespace SabreTools.Library.DatItems #endregion - #region ListXML Fields + #region ListXML /// /// Emulator source file related to the machine /// /// Also in Logiqx [JsonProperty("sourcefile", DefaultValueHandling = DefaultValueHandling.Ignore)] - [XmlAttribute("sourcefile")] + [XmlElement("sourcefile")] public string SourceFile { get; set; } = null; /// @@ -171,31 +174,34 @@ namespace SabreTools.Library.DatItems /// /// Also in Logiqx [JsonProperty("runnable", DefaultValueHandling = DefaultValueHandling.Ignore)] - [XmlAttribute("runnable")] + [XmlElement("runnable")] public Runnable Runnable { get; set; } = Runnable.NULL; + [JsonIgnore] + public bool RunnableSpecified { get { return Runnable != Runnable.NULL; } } + #endregion - #region Logiqx Fields + #region Logiqx /// /// Machine board name /// [JsonProperty("board", DefaultValueHandling = DefaultValueHandling.Ignore)] - [XmlAttribute("board")] + [XmlElement("board")] public string Board { get; set; } = null; /// /// Rebuild location if different than machine name /// [JsonProperty("rebuildto", DefaultValueHandling = DefaultValueHandling.Ignore)] - [XmlAttribute("rebuildto")] + [XmlElement("rebuildto")] public string RebuildTo { get; set; } = null; #endregion // TODO: Should this be a separate object for TruRip? - #region Logiqx EmuArc Fields + #region Logiqx EmuArc /// /// Title ID @@ -253,6 +259,9 @@ namespace SabreTools.Library.DatItems [XmlElement("hascrc")] public bool? Crc { get; set; } = null; + [JsonIgnore] + public bool CrcSpecified { get { return Crc != null; } } + /// /// Machine relations /// @@ -262,7 +271,7 @@ namespace SabreTools.Library.DatItems #endregion - #region OpenMSX Fields + #region OpenMSX /// /// Generation MSX ID @@ -287,7 +296,7 @@ namespace SabreTools.Library.DatItems #endregion - #region SoftwareList Fields + #region SoftwareList /// /// Support status @@ -296,41 +305,12 @@ namespace SabreTools.Library.DatItems [XmlElement("supported")] public Supported Supported { get; set; } = Supported.NULL; - #endregion - - #region XML Serialization Nullable Specifications - - #region Common - - [JsonIgnore] - public bool MachineTypeSpecified { get { return MachineType != 0x0 && MachineType != MachineType.NULL; } } - - #endregion - - #region ListXML - - [JsonIgnore] - public bool RunnableSpecified { get { return Runnable != Runnable.NULL; } } - - #endregion - - #region Logiqx EmuArc Fields - - [JsonIgnore] - public bool CrcSpecified { get { return Crc != null; } } - - #endregion - - #region SoftwareList - [JsonIgnore] public bool SupportedSpecified { get { return Supported != Supported.NULL; } } #endregion - #endregion // XML Serialization Nullable Specifications - - #endregion + #endregion // Fields #region Accessors diff --git a/SabreTools.Library/DatItems/Media.cs b/SabreTools.Library/DatItems/Media.cs index de5fdc0a..9be6b5ad 100644 --- a/SabreTools.Library/DatItems/Media.cs +++ b/SabreTools.Library/DatItems/Media.cs @@ -2,6 +2,7 @@ using System.IO; using System.Linq; using System.Text; +using System.Xml.Serialization; using SabreTools.Library.FileTypes; using SabreTools.Library.Filtering; @@ -14,6 +15,7 @@ namespace SabreTools.Library.DatItems /// Represents Aaruformat images which use internal hashes /// [JsonObject("media")] + [XmlRoot("media")] public class Media : DatItem { #region Private instance variables @@ -31,12 +33,14 @@ namespace SabreTools.Library.DatItems /// Name of the item /// [JsonProperty("name")] + [XmlElement("name")] public string Name { get; set; } /// /// Data MD5 hash /// [JsonProperty("md5", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("md5")] public string MD5 { get { return _md5.IsNullOrEmpty() ? null : Utilities.ByteArrayToString(_md5); } @@ -47,6 +51,7 @@ namespace SabreTools.Library.DatItems /// Data SHA-1 hash /// [JsonProperty("sha1", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("sha1")] public string SHA1 { get { return _sha1.IsNullOrEmpty() ? null : Utilities.ByteArrayToString(_sha1); } @@ -57,6 +62,7 @@ namespace SabreTools.Library.DatItems /// Data SHA-256 hash /// [JsonProperty("sha256", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("sha256")] public string SHA256 { get { return _sha256.IsNullOrEmpty() ? null : Utilities.ByteArrayToString(_sha256); } @@ -67,6 +73,7 @@ namespace SabreTools.Library.DatItems /// File SpamSum fuzzy hash /// [JsonProperty("spamsum", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("spamsum")] public string SpamSum { get { return _spamsum.IsNullOrEmpty() ? null : Encoding.UTF8.GetString(_spamsum); } diff --git a/SabreTools.Library/DatItems/Part.cs b/SabreTools.Library/DatItems/Part.cs index 2950c58f..4ce5cee8 100644 --- a/SabreTools.Library/DatItems/Part.cs +++ b/SabreTools.Library/DatItems/Part.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Xml.Serialization; using SabreTools.Library.Filtering; using SabreTools.Library.Tools; @@ -14,19 +15,26 @@ namespace SabreTools.Library.DatItems /// /// One Part can contain multiple PartFeature, DataArea, DiskArea, and DipSwitch items [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 Features { get; set; } + [JsonIgnore] + public bool FeaturesSpecified { get { return Features != null && Features.Count > 0; } } + #endregion #region Accessors diff --git a/SabreTools.Library/DatItems/PartFeature.cs b/SabreTools.Library/DatItems/PartFeature.cs index 83601180..a8810c90 100644 --- a/SabreTools.Library/DatItems/PartFeature.cs +++ b/SabreTools.Library/DatItems/PartFeature.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Xml.Serialization; using SabreTools.Library.Filtering; using SabreTools.Library.Tools; @@ -12,6 +13,7 @@ namespace SabreTools.Library.DatItems /// Represents one part feature object /// [JsonObject("part_feature")] + [XmlRoot("part_feature")] public class PartFeature : DatItem { #region Fields @@ -20,12 +22,14 @@ namespace SabreTools.Library.DatItems /// Name of the item /// [JsonProperty("name")] + [XmlElement("name")] public string Name { get; set; } /// /// PartFeature value /// [JsonProperty("value")] + [XmlElement("value")] public string Value { get; set; } #endregion diff --git a/SabreTools.Library/DatItems/Port.cs b/SabreTools.Library/DatItems/Port.cs index 29003d0e..bb319a22 100644 --- a/SabreTools.Library/DatItems/Port.cs +++ b/SabreTools.Library/DatItems/Port.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.Linq; +using System.Xml.Serialization; using SabreTools.Library.Filtering; using Newtonsoft.Json; @@ -10,6 +11,7 @@ namespace SabreTools.Library.DatItems /// Represents a single port on a machine /// [JsonObject("port")] + [XmlRoot("port")] public class Port : DatItem { #region Fields @@ -18,14 +20,19 @@ namespace SabreTools.Library.DatItems /// Tag for the port /// [JsonProperty("tag", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("tag")] public string Tag { get; set; } /// /// List of analogs on the port /// [JsonProperty("analogs", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("analogs")] public List Analogs { get; set; } + [JsonIgnore] + public bool AnalogsSpecified { get { return Analogs != null && Analogs.Count > 0; } } + #endregion #region Accessors diff --git a/SabreTools.Library/DatItems/RamOption.cs b/SabreTools.Library/DatItems/RamOption.cs index 83c0cd98..ec91d3d0 100644 --- a/SabreTools.Library/DatItems/RamOption.cs +++ b/SabreTools.Library/DatItems/RamOption.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Xml.Serialization; using SabreTools.Library.Filtering; using SabreTools.Library.Tools; @@ -12,6 +13,7 @@ namespace SabreTools.Library.DatItems /// Represents which RAM option(s) is associated with a set /// [JsonObject("ramoption")] + [XmlRoot("ramoption")] public class RamOption : DatItem { #region Fields @@ -20,18 +22,24 @@ namespace SabreTools.Library.DatItems /// Name of the item /// [JsonProperty("name")] + [XmlElement("name")] public string Name { get; set; } /// /// Determine whether the RamOption is default /// [JsonProperty("default", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("default")] public bool? Default { get; set; } + [JsonIgnore] + public bool DefaultSpecified { get { return Default != null; } } + /// /// Determines the content of the RamOption /// [JsonProperty("content", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("content")] public string Content { get; set; } #endregion diff --git a/SabreTools.Library/DatItems/Release.cs b/SabreTools.Library/DatItems/Release.cs index 5105f62f..0b80fa8d 100644 --- a/SabreTools.Library/DatItems/Release.cs +++ b/SabreTools.Library/DatItems/Release.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Xml.Serialization; using SabreTools.Library.Filtering; using SabreTools.Library.Tools; @@ -12,6 +13,7 @@ namespace SabreTools.Library.DatItems /// Represents release information about a set /// [JsonObject("release")] + [XmlRoot("release")] public class Release : DatItem { #region Fields @@ -20,32 +22,40 @@ namespace SabreTools.Library.DatItems /// Name of the item /// [JsonProperty("name")] + [XmlElement("name")] public string Name { get; set; } /// /// Release region(s) /// [JsonProperty("region", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("region")] public string Region { get; set; } /// /// Release language(s) /// [JsonProperty("language", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("language")] public string Language { get; set; } /// /// Date of release /// [JsonProperty("date", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("date")] public string Date { get; set; } /// /// Default release, if applicable /// [JsonProperty("default", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("default")] public bool? Default { get; set; } + [JsonIgnore] + public bool DefaultSpecified { get { return Default != null; } } + #endregion #region Accessors diff --git a/SabreTools.Library/DatItems/Rom.cs b/SabreTools.Library/DatItems/Rom.cs index af6645dc..acac3be6 100644 --- a/SabreTools.Library/DatItems/Rom.cs +++ b/SabreTools.Library/DatItems/Rom.cs @@ -44,7 +44,7 @@ namespace SabreTools.Library.DatItems /// Name of the item /// [JsonProperty("name")] - [XmlAttribute("name")] + [XmlElement("name")] public string Name { get; set; } /// @@ -61,6 +61,9 @@ namespace SabreTools.Library.DatItems [XmlElement("size")] public long? Size { get; set; } + [JsonIgnore] + public bool SizeSpecified { get { return Size != null; } } + /// /// File CRC32 hash /// @@ -187,6 +190,9 @@ namespace SabreTools.Library.DatItems [XmlElement("status")] public ItemStatus ItemStatus { get; set; } + [JsonIgnore] + public bool ItemStatusSpecified { get { return ItemStatus != ItemStatus.NULL && ItemStatus != ItemStatus.None; } } + /// /// Determine if the rom is optional in the set /// @@ -194,6 +200,9 @@ namespace SabreTools.Library.DatItems [XmlElement("optional")] public bool? Optional { get; set; } + [JsonIgnore] + public bool OptionalSpecified { get { return Optional != null; } } + /// /// Determine if the CRC32 hash is inverted /// @@ -201,6 +210,9 @@ namespace SabreTools.Library.DatItems [XmlElement("inverted")] public bool? Inverted { get; set; } + [JsonIgnore] + public bool InvertedSpecified { get { return Inverted != null; } } + #endregion #region AttractMode @@ -230,6 +242,9 @@ namespace SabreTools.Library.DatItems [XmlElement("original")] public Original Original { get; set; } + [JsonIgnore] + public bool OriginalSpecified { get { return Original != null && Original != default; } } + /// /// OpenMSX sub item type /// @@ -238,6 +253,9 @@ namespace SabreTools.Library.DatItems [JsonConverter(typeof(StringEnumConverter))] public OpenMSXSubType OpenMSXSubType { get; set; } + [JsonIgnore] + public bool OpenMSXSubTypeSpecified { get { return OpenMSXSubType != OpenMSXSubType.NULL; } } + /// /// OpenMSX sub item type /// @@ -271,6 +289,19 @@ namespace SabreTools.Library.DatItems [XmlElement("dataarea")] public DataArea DataArea { get; set; } + [JsonIgnore] + public bool DataAreaSpecified + { + get + { + return DataArea != null && DataArea != default + && ((DataArea.Name != null && DataArea.Name != default) + || (DataArea.Size != null && DataArea.Size != default) + || (DataArea.Width != null && DataArea.Width != default) + || (DataArea.Endianness != Endianness.NULL)); + } + } + /// /// Loading flag /// @@ -279,6 +310,9 @@ namespace SabreTools.Library.DatItems [JsonConverter(typeof(StringEnumConverter))] public LoadFlag LoadFlag { get; set; } + [JsonIgnore] + public bool LoadFlagSpecified { get { return LoadFlag != LoadFlag.NULL; } } + /// /// Original hardware part associated with the item /// @@ -286,6 +320,17 @@ namespace SabreTools.Library.DatItems [XmlElement("part")] public Part Part { get; set; } + [JsonIgnore] + public bool PartSpecified + { + get + { + return Part != null && Part != default + && ((Part.Name != null && Part.Name != default) + || (Part.Interface != null && Part.Interface != default)); + } + } + /// /// SoftwareList value associated with the item /// @@ -295,49 +340,6 @@ namespace SabreTools.Library.DatItems #endregion - #region XML Serialization Nullable Specifications - - #region Common - - [JsonIgnore] - public bool SizeSpecified { get { return Size != null; } } - - [JsonIgnore] - public bool ItemStatusSpecified { get { return ItemStatus != ItemStatus.NULL && ItemStatus != ItemStatus.None; } } - - [JsonIgnore] - public bool OptionalSpecified { get { return Optional != null; } } - - [JsonIgnore] - public bool InvertedSpecified { get { return Inverted != null; } } - - #endregion - - #region OpenMSX - - [JsonIgnore] - public bool OriginalSpecified { get { return Original != null && Original != default; } } - - [JsonIgnore] - public bool OpenMSXSubTypeSpecified { get { return OpenMSXSubType != OpenMSXSubType.NULL; } } - - #endregion - - #region SoftwareList - - [JsonIgnore] - public bool DataAreaSpecified { get { return DataArea != null && DataArea != default; } } - - [JsonIgnore] - public bool LoadFlagSpecified { get { return LoadFlag != LoadFlag.NULL; } } - - [JsonIgnore] - public bool PartSpecified { get { return Part != null && Part != default; } } - - #endregion - - #endregion // XML Serialization Nullable Specifications - #endregion // Fields #region Accessors diff --git a/SabreTools.Library/DatItems/Sample.cs b/SabreTools.Library/DatItems/Sample.cs index 5f083590..2ba74eb2 100644 --- a/SabreTools.Library/DatItems/Sample.cs +++ b/SabreTools.Library/DatItems/Sample.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Xml.Serialization; using SabreTools.Library.Filtering; using SabreTools.Library.Tools; @@ -12,6 +13,7 @@ namespace SabreTools.Library.DatItems /// Represents a (usually WAV-formatted) sample to be included for use in the set /// [JsonObject("sample")] + [XmlRoot("sample")] public class Sample : DatItem { #region Fields @@ -20,6 +22,7 @@ namespace SabreTools.Library.DatItems /// Name of the item /// [JsonProperty("name")] + [XmlElement("name")] public string Name { get; set; } #endregion diff --git a/SabreTools.Library/DatItems/Setting.cs b/SabreTools.Library/DatItems/Setting.cs index 7061387e..869b3c61 100644 --- a/SabreTools.Library/DatItems/Setting.cs +++ b/SabreTools.Library/DatItems/Setting.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Xml.Serialization; using SabreTools.Library.Filtering; using SabreTools.Library.Tools; @@ -12,6 +13,7 @@ namespace SabreTools.Library.DatItems /// Represents one ListXML confsetting or dipvalue /// [JsonObject("setting")] + [XmlRoot("setting")] public class Setting : DatItem { #region Fields @@ -20,26 +22,36 @@ namespace SabreTools.Library.DatItems /// Setting name /// [JsonProperty("name")] + [XmlElement("name")] public string Name { get; set; } /// /// Setting value /// [JsonProperty("value", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("value")] public string Value { get; set; } /// /// Determines if the setting is default or not /// [JsonProperty("default", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("default")] public bool? Default { get; set; } + [JsonIgnore] + public bool DefaultSpecified { get { return Default != null; } } + /// /// List of conditions on the setting /// [JsonProperty("conditions", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("conditions")] public List Conditions { get; set; } + [JsonIgnore] + public bool ConditionsSpecified { get { return Conditions != null && Conditions.Count > 0; } } + #endregion #region Accessors diff --git a/SabreTools.Library/DatItems/SharedFeature.cs b/SabreTools.Library/DatItems/SharedFeature.cs index ee6b1b21..2c1d2a9f 100644 --- a/SabreTools.Library/DatItems/SharedFeature.cs +++ b/SabreTools.Library/DatItems/SharedFeature.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Xml.Serialization; using SabreTools.Library.Filtering; using SabreTools.Library.Tools; @@ -12,6 +13,7 @@ namespace SabreTools.Library.DatItems /// Represents one shared feature object /// [JsonObject("sharedfeat")] + [XmlRoot("sharedfeat")] public class SharedFeature : DatItem { #region Fields @@ -20,12 +22,14 @@ namespace SabreTools.Library.DatItems /// Name of the item /// [JsonProperty("name")] + [XmlElement("name")] public string Name { get; set; } /// /// SharedFeature value /// [JsonProperty("value")] + [XmlElement("value")] public string Value { get; set; } #endregion diff --git a/SabreTools.Library/DatItems/Slot.cs b/SabreTools.Library/DatItems/Slot.cs index 25870414..22c9ac91 100644 --- a/SabreTools.Library/DatItems/Slot.cs +++ b/SabreTools.Library/DatItems/Slot.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Xml.Serialization; using SabreTools.Library.Filtering; using SabreTools.Library.Tools; @@ -12,6 +13,7 @@ namespace SabreTools.Library.DatItems /// Represents which Slot(s) is associated with a set /// [JsonObject("slot")] + [XmlRoot("slot")] public class Slot : DatItem { #region Fields @@ -20,14 +22,19 @@ namespace SabreTools.Library.DatItems /// Name of the item /// [JsonProperty("name")] + [XmlElement("name")] public string Name { get; set; } /// /// Slot options associated with the slot /// [JsonProperty("slotoptions", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("slotoptions")] public List SlotOptions { get; set; } + [JsonIgnore] + public bool SlotOptionsSpecified { get { return SlotOptions != null && SlotOptions.Count > 0; } } + #endregion #region Accessors diff --git a/SabreTools.Library/DatItems/SlotOption.cs b/SabreTools.Library/DatItems/SlotOption.cs index 515c4be5..280bc8fc 100644 --- a/SabreTools.Library/DatItems/SlotOption.cs +++ b/SabreTools.Library/DatItems/SlotOption.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Xml.Serialization; using SabreTools.Library.Filtering; using SabreTools.Library.Tools; @@ -12,6 +13,7 @@ namespace SabreTools.Library.DatItems /// Represents one ListXML slotoption /// [JsonObject("slotoption")] + [XmlRoot("slotoption")] public class SlotOption : DatItem { #region Fields @@ -20,20 +22,26 @@ namespace SabreTools.Library.DatItems /// Slot option name /// [JsonProperty("name")] + [XmlElement("name")] public string Name { get; set; } /// /// Referenced device name /// [JsonProperty("devname")] + [XmlElement("devname")] public string DeviceName { get; set; } /// /// Determines if this slot option is default or not /// [JsonProperty("default", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("default")] public bool? Default { get; set; } + [JsonIgnore] + public bool DefaultSpecified { get { return Default != null; } } + #endregion #region Accessors diff --git a/SabreTools.Library/DatItems/SoftwareList.cs b/SabreTools.Library/DatItems/SoftwareList.cs index 86cc2876..3db2d8f9 100644 --- a/SabreTools.Library/DatItems/SoftwareList.cs +++ b/SabreTools.Library/DatItems/SoftwareList.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Xml.Serialization; using SabreTools.Library.Filtering; using SabreTools.Library.Tools; @@ -13,6 +14,7 @@ namespace SabreTools.Library.DatItems /// Represents which SoftwareList(s) is associated with a set /// [JsonObject("softwarelist")] + [XmlRoot("softwarelist")] public class SoftwareList : DatItem { #region Fields @@ -21,6 +23,7 @@ namespace SabreTools.Library.DatItems /// Name of the item /// [JsonProperty("name")] + [XmlElement("name")] public string Name { get; set; } /// @@ -28,12 +31,17 @@ namespace SabreTools.Library.DatItems /// [JsonProperty("status", DefaultValueHandling = DefaultValueHandling.Ignore)] [JsonConverter(typeof(StringEnumConverter))] + [XmlElement("status")] public SoftwareListStatus Status { get; set; } + [JsonIgnore] + public bool StatusSpecified { get { return Status != SoftwareListStatus.NULL; } } + /// /// Filter to apply to the software list /// [JsonProperty("filter", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("filter")] public string Filter { get; set; } #endregion diff --git a/SabreTools.Library/DatItems/Sound.cs b/SabreTools.Library/DatItems/Sound.cs index fef12d88..6f70322f 100644 --- a/SabreTools.Library/DatItems/Sound.cs +++ b/SabreTools.Library/DatItems/Sound.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Xml.Serialization; using SabreTools.Library.Filtering; using SabreTools.Library.Tools; @@ -12,6 +13,7 @@ namespace SabreTools.Library.DatItems /// Represents the sound output for a machine /// [JsonObject("sound")] + [XmlRoot("sound")] public class Sound : DatItem { #region Fields @@ -20,8 +22,12 @@ namespace SabreTools.Library.DatItems /// Number of speakers or channels /// [JsonProperty("channels", DefaultValueHandling = DefaultValueHandling.Ignore)] + [XmlElement("channels")] public long? Channels { get; set; } + [JsonIgnore] + public bool ChannelsSpecified { get { return Channels != null; } } + #endregion #region Accessors