Files
SabreTools/SabreTools.DatItems/Formats/SoftwareList.cs

133 lines
3.9 KiB
C#
Raw Normal View History

using System.Xml.Serialization;
2020-08-31 23:26:07 -07:00
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using SabreTools.Core;
using SabreTools.Core.Tools;
2020-08-31 23:26:07 -07:00
2021-02-02 10:23:43 -08:00
namespace SabreTools.DatItems.Formats
2020-08-31 23:26:07 -07:00
{
/// <summary>
/// Represents which SoftwareList(s) is associated with a set
/// </summary>
2022-11-03 12:22:17 -07:00
/// <remarks>
/// TODO: Add new fields to documentation
/// </remarks>
2020-09-08 10:12:41 -07:00
[JsonObject("softwarelist"), XmlRoot("softwarelist")]
2020-08-31 23:26:07 -07:00
public class SoftwareList : DatItem
{
#region Fields
2022-11-03 11:44:29 -07:00
/// <summary>
/// Tag for the software list
/// </summary>
[JsonProperty("tag", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("tag")]
public string? Tag
{
get => _softwareList.ReadString(Models.Internal.SoftwareList.TagKey);
set => _softwareList[Models.Internal.SoftwareList.TagKey] = value;
}
2022-11-03 11:44:29 -07:00
2020-09-02 12:19:12 -07:00
/// <summary>
/// Name of the item
/// </summary>
[JsonProperty("name")]
2020-09-07 22:00:02 -07:00
[XmlElement("name")]
public string? Name
{
get => _softwareList.ReadString(Models.Internal.SoftwareList.NameKey);
set => _softwareList[Models.Internal.SoftwareList.NameKey] = value;
}
2020-09-02 12:19:12 -07:00
/// <summary>
/// Status of the softare list according to the machine
/// </summary>
2020-08-31 23:26:07 -07:00
[JsonProperty("status", DefaultValueHandling = DefaultValueHandling.Ignore)]
[JsonConverter(typeof(StringEnumConverter))]
2020-09-07 22:00:02 -07:00
[XmlElement("status")]
public SoftwareListStatus Status
{
get => _softwareList.ReadString(Models.Internal.SoftwareList.StatusKey).AsSoftwareListStatus();
set => _softwareList[Models.Internal.SoftwareList.StatusKey] = value.FromSoftwareListStatus();
}
2020-08-31 23:26:07 -07:00
2020-09-07 22:00:02 -07:00
[JsonIgnore]
2023-04-20 10:34:37 -04:00
public bool StatusSpecified { get { return Status != SoftwareListStatus.None; } }
2020-09-07 22:00:02 -07:00
2020-09-02 12:19:12 -07:00
/// <summary>
/// Filter to apply to the software list
/// </summary>
2020-08-31 23:26:07 -07:00
[JsonProperty("filter", DefaultValueHandling = DefaultValueHandling.Ignore)]
2020-09-07 22:00:02 -07:00
[XmlElement("filter")]
public string? Filter
{
get => _softwareList.ReadString(Models.Internal.SoftwareList.FilterKey);
set => _softwareList[Models.Internal.SoftwareList.FilterKey] = value;
}
/// <summary>
/// Internal SoftwareList model
/// </summary>
[JsonIgnore]
private Models.Internal.SoftwareList _softwareList = new();
2020-08-31 23:26:07 -07:00
#endregion
#region Accessors
/// <inheritdoc/>
public override string? GetName() => Name;
2020-09-02 12:19:12 -07:00
/// <inheritdoc/>
public override void SetName(string? name) => Name = name;
2020-08-31 23:26:07 -07:00
#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,
2020-08-31 23:26:07 -07:00
Remove = this.Remove,
_softwareList = this._softwareList?.Clone() as Models.Internal.SoftwareList ?? new Models.Internal.SoftwareList(),
2020-08-31 23:26:07 -07:00
};
}
#endregion
#region Comparision Methods
public override bool Equals(DatItem? other)
2020-08-31 23:26:07 -07:00
{
// If we don't have a Adjuster, return false
if (ItemType != other?.ItemType || other is not SoftwareList otherInternal)
2020-08-31 23:26:07 -07:00
return false;
// Compare the internal models
return _softwareList.EqualTo(otherInternal._softwareList);
2020-08-31 23:26:07 -07:00
}
2020-09-02 12:19:12 -07:00
2020-08-31 23:26:07 -07:00
#endregion
}
}