mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Add nullable context to SabreTools.DatItems
This change also starts migrating the internals of the DatItem formats to the new internal models. Right now, it's basically just acting like a wrapper around those models.
This commit is contained in:
@@ -16,44 +16,70 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Name of the item
|
||||
/// </summary>
|
||||
[JsonProperty("name"), XmlElement("name")]
|
||||
public string Name { get; set; }
|
||||
public string? Name
|
||||
{
|
||||
get => _release.ReadString(Models.Internal.Release.NameKey);
|
||||
set => _release[Models.Internal.Release.NameKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Release region(s)
|
||||
/// </summary>
|
||||
[JsonProperty("region", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("region")]
|
||||
public string Region { get; set; }
|
||||
public string? Region
|
||||
{
|
||||
get => _release.ReadString(Models.Internal.Release.RegionKey);
|
||||
set => _release[Models.Internal.Release.RegionKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Release language(s)
|
||||
/// </summary>
|
||||
[JsonProperty("language", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("language")]
|
||||
public string Language { get; set; }
|
||||
public string? Language
|
||||
{
|
||||
get => _release.ReadString(Models.Internal.Release.LanguageKey);
|
||||
set => _release[Models.Internal.Release.LanguageKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Date of release
|
||||
/// </summary>
|
||||
[JsonProperty("date", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("date")]
|
||||
public string Date { get; set; }
|
||||
public string? Date
|
||||
{
|
||||
get => _release.ReadString(Models.Internal.Release.DateKey);
|
||||
set => _release[Models.Internal.Release.DateKey] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Default release, if applicable
|
||||
/// </summary>
|
||||
[JsonProperty("default", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("default")]
|
||||
public bool? Default { get; set; }
|
||||
public bool? Default
|
||||
{
|
||||
get => _release.ReadBool(Models.Internal.Release.DefaultKey);
|
||||
set => _release[Models.Internal.Release.DefaultKey] = value;
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool DefaultSpecified { get { return Default != null; } }
|
||||
|
||||
/// <summary>
|
||||
/// Internal Release model
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
private Models.Internal.Release _release = new();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Accessors
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string GetName() => Name;
|
||||
public override string? GetName() => Name;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void SetName(string name) => Name = name;
|
||||
public override void SetName(string? name) => Name = name;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -84,15 +110,11 @@ namespace SabreTools.DatItems.Formats
|
||||
ItemType = this.ItemType,
|
||||
DupeType = this.DupeType,
|
||||
|
||||
Machine = this.Machine.Clone() as Machine,
|
||||
Source = this.Source.Clone() as Source,
|
||||
Machine = this.Machine?.Clone() as Machine,
|
||||
Source = this.Source?.Clone() as Source,
|
||||
Remove = this.Remove,
|
||||
|
||||
Name = this.Name,
|
||||
Region = this.Region,
|
||||
Language = this.Language,
|
||||
Date = this.Date,
|
||||
Default = this.Default,
|
||||
_release = this._release?.Clone() as Models.Internal.Release ?? new Models.Internal.Release(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -101,21 +123,14 @@ namespace SabreTools.DatItems.Formats
|
||||
#region Comparision Methods
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Equals(DatItem other)
|
||||
public override bool Equals(DatItem? other)
|
||||
{
|
||||
// If we don't have a release return false
|
||||
if (ItemType != other.ItemType)
|
||||
// If we don't have a Release, return false
|
||||
if (ItemType != other?.ItemType || other is not Release otherInternal)
|
||||
return false;
|
||||
|
||||
// Otherwise, treat it as a Release
|
||||
Release newOther = other as Release;
|
||||
|
||||
// If the archive information matches
|
||||
return (Name == newOther.Name
|
||||
&& Region == newOther.Region
|
||||
&& Language == newOther.Language
|
||||
&& Date == newOther.Date
|
||||
&& Default == newOther.Default);
|
||||
// Compare the internal models
|
||||
return _release.EqualTo(otherInternal._release);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
Reference in New Issue
Block a user