2020-09-02 17:09:19 -07:00
|
|
|
|
using System.Collections.Generic;
|
2020-09-07 22:00:02 -07:00
|
|
|
|
using System.Xml.Serialization;
|
2020-09-02 17:09:19 -07:00
|
|
|
|
using Newtonsoft.Json;
|
2020-09-07 22:00:02 -07:00
|
|
|
|
using Newtonsoft.Json.Converters;
|
2022-11-03 12:22:17 -07:00
|
|
|
|
using SabreTools.Core;
|
2020-09-02 17:09:19 -07:00
|
|
|
|
|
2021-02-02 10:23:43 -08:00
|
|
|
|
namespace SabreTools.DatItems.Formats
|
2020-09-02 17:09:19 -07:00
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Represents a single device on the machine
|
|
|
|
|
|
/// </summary>
|
2020-09-08 10:12:41 -07:00
|
|
|
|
[JsonObject("device"), XmlRoot("device")]
|
2020-09-02 17:09:19 -07:00
|
|
|
|
public class Device : DatItem
|
|
|
|
|
|
{
|
|
|
|
|
|
#region Fields
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Device type
|
|
|
|
|
|
/// </summary>
|
2022-11-03 12:22:17 -07:00
|
|
|
|
[JsonProperty("type", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("type")]
|
2020-09-07 22:00:02 -07:00
|
|
|
|
[JsonConverter(typeof(StringEnumConverter))]
|
2020-09-07 00:39:59 -07:00
|
|
|
|
public DeviceType DeviceType { get; set; }
|
2020-09-02 17:09:19 -07:00
|
|
|
|
|
2020-09-07 22:00:02 -07:00
|
|
|
|
[JsonIgnore]
|
|
|
|
|
|
public bool DeviceTypeSpecified { get { return DeviceType != DeviceType.NULL; } }
|
|
|
|
|
|
|
2020-09-02 17:09:19 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Device tag
|
|
|
|
|
|
/// </summary>
|
2022-11-03 12:22:17 -07:00
|
|
|
|
[JsonProperty("tag", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("tag")]
|
2020-09-02 17:09:19 -07:00
|
|
|
|
public string Tag { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Fixed image format
|
|
|
|
|
|
/// </summary>
|
2022-11-03 12:22:17 -07:00
|
|
|
|
[JsonProperty("fixed_image", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("fixed_image")]
|
2020-09-02 17:09:19 -07:00
|
|
|
|
public string FixedImage { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Determines if the devices is mandatory
|
|
|
|
|
|
/// </summary>
|
2020-09-04 10:28:25 -07:00
|
|
|
|
/// <remarks>Only value used seems to be 1. Used like bool, but actually int</remarks>
|
2022-11-03 12:22:17 -07:00
|
|
|
|
[JsonProperty("mandatory", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("mandatory")]
|
2020-09-07 12:34:18 -07:00
|
|
|
|
public long? Mandatory { get; set; }
|
2020-09-02 17:09:19 -07:00
|
|
|
|
|
2020-09-07 22:00:02 -07:00
|
|
|
|
[JsonIgnore]
|
|
|
|
|
|
public bool MandatorySpecified { get { return Mandatory != null; } }
|
|
|
|
|
|
|
2020-09-02 17:09:19 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Device interface
|
|
|
|
|
|
/// </summary>
|
2022-11-03 12:22:17 -07:00
|
|
|
|
[JsonProperty("interface", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("interface")]
|
2020-09-02 17:09:19 -07:00
|
|
|
|
public string Interface { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Device instances
|
|
|
|
|
|
/// </summary>
|
2022-11-03 12:22:17 -07:00
|
|
|
|
[JsonProperty("instances", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("instances")]
|
2020-09-02 17:09:19 -07:00
|
|
|
|
public List<Instance> Instances { get; set; }
|
|
|
|
|
|
|
2020-09-07 22:00:02 -07:00
|
|
|
|
[JsonIgnore]
|
|
|
|
|
|
public bool InstancesSpecified { get { return Instances != null && Instances.Count > 0; } }
|
|
|
|
|
|
|
2020-09-02 17:09:19 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Device extensions
|
|
|
|
|
|
/// </summary>
|
2022-11-03 12:22:17 -07:00
|
|
|
|
[JsonProperty("extensions", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("extensions")]
|
2020-09-02 17:09:19 -07:00
|
|
|
|
public List<Extension> Extensions { get; set; }
|
|
|
|
|
|
|
2020-09-07 22:00:02 -07:00
|
|
|
|
[JsonIgnore]
|
|
|
|
|
|
public bool ExtensionsSpecified { get { return Extensions != null && Extensions.Count > 0; } }
|
|
|
|
|
|
|
2020-09-02 17:09:19 -07:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region Constructors
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Create a default, empty Device object
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public Device()
|
|
|
|
|
|
{
|
|
|
|
|
|
ItemType = ItemType.Device;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region Cloning Methods
|
|
|
|
|
|
|
2022-11-03 12:22:17 -07:00
|
|
|
|
/// <inheritdoc/>
|
2020-09-02 17:09:19 -07:00
|
|
|
|
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
|
|
|
|
|
|
|
2022-11-03 12:22:17 -07:00
|
|
|
|
/// <inheritdoc/>
|
2020-09-02 17:09:19 -07:00
|
|
|
|
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
|
2020-09-03 15:02:59 -07:00
|
|
|
|
bool match = (DeviceType == newOther.DeviceType
|
2020-09-02 17:09:19 -07:00
|
|
|
|
&& Tag == newOther.Tag
|
|
|
|
|
|
&& FixedImage == newOther.FixedImage
|
|
|
|
|
|
&& Mandatory == newOther.Mandatory
|
|
|
|
|
|
&& Interface == newOther.Interface);
|
2020-09-03 15:02:59 -07:00
|
|
|
|
if (!match)
|
|
|
|
|
|
return match;
|
|
|
|
|
|
|
|
|
|
|
|
// If the instances match
|
2020-09-30 13:25:40 -07:00
|
|
|
|
if (InstancesSpecified)
|
2020-09-03 15:02:59 -07:00
|
|
|
|
{
|
|
|
|
|
|
foreach (Instance instance in Instances)
|
|
|
|
|
|
{
|
|
|
|
|
|
match &= newOther.Instances.Contains(instance);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// If the extensions match
|
2020-09-30 13:25:40 -07:00
|
|
|
|
if (ExtensionsSpecified)
|
2020-09-03 15:02:59 -07:00
|
|
|
|
{
|
|
|
|
|
|
foreach (Extension extension in Extensions)
|
|
|
|
|
|
{
|
|
|
|
|
|
match &= newOther.Extensions.Contains(extension);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2020-09-02 17:09:19 -07:00
|
|
|
|
|
2020-09-03 15:02:59 -07:00
|
|
|
|
return match;
|
2020-09-02 17:09:19 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|