using System.Collections.Generic; using Newtonsoft.Json; namespace SabreTools.Library.DatItems { /// /// Represents release information about a set /// public class Release : DatItem { #region Publicly facing variables /// /// Release region(s) /// [JsonProperty("region")] public string Region { get; set; } /// /// Release language(s) /// [JsonProperty("language")] public string Language { get; set; } /// /// Date of release /// [JsonProperty("date")] public string Date { get; set; } /// /// Default release, if applicable /// [JsonProperty("default")] public bool? Default { get; set; } #endregion #region Accessors /// /// Get the value of that field as a string, if possible /// public override string GetField(Field field, List excludeFields) { // If the field is to be excluded, return empty string if (excludeFields.Contains(field)) return string.Empty; // Handle Release-specific fields string fieldValue; switch (field) { case Field.Region: fieldValue = Region; break; case Field.Language: fieldValue = Language; break; case Field.Date: fieldValue = Date; break; case Field.Default: fieldValue = Default?.ToString(); break; // For everything else, use the base method default: return base.GetField(field, excludeFields); } // Make sure we don't return null if (string.IsNullOrEmpty(fieldValue)) fieldValue = string.Empty; return fieldValue; } #endregion #region Constructors /// /// Create a default, empty Release object /// public Release() { this.Name = string.Empty; this.ItemType = ItemType.Release; this.Region = string.Empty; this.Language = string.Empty; this.Date = string.Empty; this.Default = null; } #endregion #region Cloning Methods public override object Clone() { return new Release() { Name = this.Name, ItemType = this.ItemType, DupeType = this.DupeType, Supported = this.Supported, Publisher = this.Publisher, Category = this.Category, Infos = this.Infos, PartName = this.PartName, PartInterface = this.PartInterface, Features = this.Features, AreaName = this.AreaName, AreaSize = this.AreaSize, MachineName = this.MachineName, Comment = this.Comment, MachineDescription = this.MachineDescription, Year = this.Year, Manufacturer = this.Manufacturer, RomOf = this.RomOf, CloneOf = this.CloneOf, SampleOf = this.SampleOf, SourceFile = this.SourceFile, Runnable = this.Runnable, Board = this.Board, RebuildTo = this.RebuildTo, Devices = this.Devices, MachineType = this.MachineType, IndexId = this.IndexId, IndexSource = this.IndexSource, 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 (this.ItemType != other.ItemType) return false; // Otherwise, treat it as a Release Release newOther = other as Release; // If the archive information matches return (this.Name == newOther.Name && this.Region == newOther.Region && this.Language == newOther.Language && this.Date == newOther.Date && this.Default == newOther.Default); } #endregion } }