From e95b5d3268ac46c73c82436354503542546309df Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Mon, 15 Jun 2020 21:00:09 -0700 Subject: [PATCH] Make dat items serializable --- SabreTools.Library/DatItems/BiosSet.cs | 3 ++ SabreTools.Library/DatItems/DatItem.cs | 34 +++++++++++++++++++- SabreTools.Library/DatItems/Disk.cs | 13 ++++++++ SabreTools.Library/DatItems/Machine.cs | 19 +++++++++++ SabreTools.Library/DatItems/Release.cs | 5 +++ SabreTools.Library/DatItems/Rom.cs | 16 +++++++++ SabreTools.Library/SabreTools.Library.csproj | 1 + 7 files changed, 90 insertions(+), 1 deletion(-) diff --git a/SabreTools.Library/DatItems/BiosSet.cs b/SabreTools.Library/DatItems/BiosSet.cs index 2a102c03..1f1aa5f1 100644 --- a/SabreTools.Library/DatItems/BiosSet.cs +++ b/SabreTools.Library/DatItems/BiosSet.cs @@ -1,4 +1,5 @@ using SabreTools.Library.Data; +using Newtonsoft.Json; namespace SabreTools.Library.DatItems { @@ -12,11 +13,13 @@ namespace SabreTools.Library.DatItems /// /// Description of the BIOS /// + [JsonProperty("description")] public string Description { get; set; } /// /// Determine whether the BIOS is default /// + [JsonProperty("default")] public bool? Default { get; set; } #endregion diff --git a/SabreTools.Library/DatItems/DatItem.cs b/SabreTools.Library/DatItems/DatItem.cs index 363deae6..5ac50432 100644 --- a/SabreTools.Library/DatItems/DatItem.cs +++ b/SabreTools.Library/DatItems/DatItem.cs @@ -7,6 +7,7 @@ using SabreTools.Library.Data; using SabreTools.Library.DatFiles; using SabreTools.Library.Tools; using NaturalSort; +using Newtonsoft.Json; namespace SabreTools.Library.DatItems { @@ -17,7 +18,7 @@ namespace SabreTools.Library.DatItems { #region Protected instance variables - // Machine information + [JsonIgnore] protected Machine _machine = new Machine(); #endregion @@ -29,16 +30,19 @@ namespace SabreTools.Library.DatItems /// /// Name of the item /// + [JsonProperty("name")] public string Name { get; set; } /// /// Item type for outputting /// + [JsonIgnore] public ItemType ItemType { get; set; } /// /// Duplicate type when compared to another item /// + [JsonIgnore] public DupeType DupeType { get; set; } #endregion @@ -48,6 +52,7 @@ namespace SabreTools.Library.DatItems /// /// Name of the machine associated with the item /// + [JsonIgnore] public string MachineName { get @@ -73,6 +78,7 @@ namespace SabreTools.Library.DatItems /// /// Additional notes on the machine /// + [JsonIgnore] public string Comment { get @@ -98,6 +104,7 @@ namespace SabreTools.Library.DatItems /// /// Extended description of the machine /// + [JsonIgnore] public string MachineDescription { get @@ -123,6 +130,7 @@ namespace SabreTools.Library.DatItems /// /// Machine year(s) of release/manufacture /// + [JsonIgnore] public string Year { get @@ -148,6 +156,7 @@ namespace SabreTools.Library.DatItems /// /// Machine manufacturer, if available /// + [JsonIgnore] public string Manufacturer { get @@ -173,6 +182,7 @@ namespace SabreTools.Library.DatItems /// /// Machine publisher, if available /// + [JsonIgnore] public string Publisher { get @@ -198,6 +208,7 @@ namespace SabreTools.Library.DatItems /// /// Machine romof parent /// + [JsonIgnore] public string RomOf { get @@ -223,6 +234,7 @@ namespace SabreTools.Library.DatItems /// /// Machine cloneof parent /// + [JsonIgnore] public string CloneOf { get @@ -248,6 +260,7 @@ namespace SabreTools.Library.DatItems /// /// Machine sampleof parent /// + [JsonIgnore] public string SampleOf { get @@ -274,6 +287,7 @@ namespace SabreTools.Library.DatItems /// Machine support status /// /// yes = true, partial = null, no = false + [JsonIgnore] public bool? Supported { get @@ -299,6 +313,7 @@ namespace SabreTools.Library.DatItems /// /// Emulator source file related to the machine /// + [JsonIgnore] public string SourceFile { get @@ -325,6 +340,7 @@ namespace SabreTools.Library.DatItems /// Machine runnable status /// /// yes = true, partial = null, no = false + [JsonIgnore] public bool? Runnable { get @@ -350,6 +366,7 @@ namespace SabreTools.Library.DatItems /// /// Machine board name /// + [JsonIgnore] public string Board { get @@ -375,6 +392,7 @@ namespace SabreTools.Library.DatItems /// /// Rebuild location if different than machine name /// + [JsonIgnore] public string RebuildTo { get @@ -400,6 +418,7 @@ namespace SabreTools.Library.DatItems /// /// List of associated device names /// + [JsonIgnore] public List Devices { get @@ -425,6 +444,7 @@ namespace SabreTools.Library.DatItems /// /// List of slot options /// + [JsonIgnore] public List SlotOptions { get @@ -450,6 +470,7 @@ namespace SabreTools.Library.DatItems /// /// List of info items /// + [JsonIgnore] public List> Infos { get @@ -475,6 +496,7 @@ namespace SabreTools.Library.DatItems /// /// Type of the associated machine /// + [JsonIgnore] public MachineType MachineType { get @@ -504,26 +526,31 @@ namespace SabreTools.Library.DatItems /// /// Original hardware part associated with the item /// + [JsonProperty("partname")] public string PartName { get; set; } /// /// Original hardware interface associated with the item /// + [JsonProperty("partinterface")] public string PartInterface { get; set; } /// /// Features provided to/by the item /// + [JsonProperty("features")] public List> Features { get; set; } /// /// Original hardware part name within an item /// + [JsonProperty("areaname")] public string AreaName { get; set; } /// /// Original hardware size within the part /// + [JsonProperty("areasize")] public long? AreaSize { get; set; } #endregion @@ -533,26 +560,31 @@ namespace SabreTools.Library.DatItems /// /// Internal system ID for organization /// + [JsonIgnore] public int SystemID { get; set; } /// /// Internal system name for organization /// + [JsonIgnore] public string System { get; set; } /// /// Internal source ID for organization /// + [JsonIgnore] public int SourceID { get; set; } /// /// Internal source name for organization /// + [JsonIgnore] public string Source { get; set; } /// /// Flag if item should be removed /// + [JsonIgnore] public bool Remove { get; set; } #endregion diff --git a/SabreTools.Library/DatItems/Disk.cs b/SabreTools.Library/DatItems/Disk.cs index ee95c759..50b3fd52 100644 --- a/SabreTools.Library/DatItems/Disk.cs +++ b/SabreTools.Library/DatItems/Disk.cs @@ -3,6 +3,7 @@ using SabreTools.Library.Data; using SabreTools.Library.FileTypes; using SabreTools.Library.Tools; +using Newtonsoft.Json; namespace SabreTools.Library.DatItems { @@ -27,6 +28,7 @@ namespace SabreTools.Library.DatItems /// /// Data MD5 hash /// + [JsonProperty("md5")] public string MD5 { get { return _md5.IsNullOrWhiteSpace() ? null : Utilities.ByteArrayToString(_md5); } @@ -36,6 +38,7 @@ namespace SabreTools.Library.DatItems /// /// Data RIPEMD160 hash /// + [JsonProperty("ripemd160")] public string RIPEMD160 { get { return _ripemd160.IsNullOrWhiteSpace() ? null : Utilities.ByteArrayToString(_ripemd160); } @@ -45,6 +48,7 @@ namespace SabreTools.Library.DatItems /// /// Data SHA-1 hash /// + [JsonProperty("sha1")] public string SHA1 { get { return _sha1.IsNullOrWhiteSpace() ? null : Utilities.ByteArrayToString(_sha1); } @@ -54,6 +58,7 @@ namespace SabreTools.Library.DatItems /// /// Data SHA-256 hash /// + [JsonProperty("sha256")] public string SHA256 { get { return _sha256.IsNullOrWhiteSpace() ? null : Utilities.ByteArrayToString(_sha256); } @@ -63,6 +68,7 @@ namespace SabreTools.Library.DatItems /// /// Data SHA-384 hash /// + [JsonProperty("sha384")] public string SHA384 { get { return _sha384.IsNullOrWhiteSpace() ? null : Utilities.ByteArrayToString(_sha384); } @@ -72,6 +78,7 @@ namespace SabreTools.Library.DatItems /// /// Data SHA-512 hash /// + [JsonProperty("sha512")] public string SHA512 { get { return _sha512.IsNullOrWhiteSpace() ? null : Utilities.ByteArrayToString(_sha512); } @@ -81,31 +88,37 @@ namespace SabreTools.Library.DatItems /// /// Disk name to merge from parent /// + [JsonProperty("merge")] public string MergeTag { get; set; } /// /// Disk region /// + [JsonProperty("region")] public string Region { get; set; } /// /// Disk index /// + [JsonProperty("index")] public string Index { get; set; } /// /// Disk writable flag /// + [JsonProperty("writable")] public bool? Writable { get; set; } /// /// Disk dump status /// + [JsonProperty("status")] public ItemStatus ItemStatus { get; set; } /// /// Determine if the disk is optional in the set /// + [JsonProperty("optional")] public bool? Optional { get; set; } #endregion diff --git a/SabreTools.Library/DatItems/Machine.cs b/SabreTools.Library/DatItems/Machine.cs index 79028323..89ab533b 100644 --- a/SabreTools.Library/DatItems/Machine.cs +++ b/SabreTools.Library/DatItems/Machine.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using SabreTools.Library.Data; +using Newtonsoft.Json; namespace SabreTools.Library.DatItems { @@ -15,93 +16,111 @@ namespace SabreTools.Library.DatItems /// /// Name of the machine /// + [JsonProperty("name")] public string Name { get; set; } /// /// Additional notes /// + [JsonProperty("comment")] public string Comment { get; set; } /// /// Extended description /// + [JsonProperty("description")] public string Description { get; set; } /// /// Year(s) of release/manufacture /// + [JsonProperty("year")] public string Year { get; set; } /// /// Manufacturer, if available /// + [JsonProperty("manufacturer")] public string Manufacturer { get; set; } /// /// Publisher, if available /// + [JsonProperty("publisher")] public string Publisher { get; set; } /// /// fomof parent /// + [JsonProperty("romof")] public string RomOf { get; set; } /// /// cloneof parent /// + [JsonProperty("cloneof")] public string CloneOf { get; set; } /// /// sampleof parent /// + [JsonProperty("sampleof")] public string SampleOf { get; set; } /// /// Support status /// /// yes = true, partial = null, no = false + [JsonProperty("supported")] public bool? Supported { get; set; } /// /// Emulator source file related to the machine /// + [JsonProperty("sourcefile")] public string SourceFile { get; set; } /// /// Machine runnable status /// /// yes = true, partial = null, no = false + [JsonProperty("runnable")] public bool? Runnable { get; set; } /// /// Machine board name /// + [JsonProperty("board")] public string Board { get; set; } /// /// Rebuild location if different than machine name /// + [JsonProperty("rebuildto")] public string RebuildTo { get; set; } /// /// List of associated device names /// + [JsonProperty("devices")] public List Devices { get; set; } /// /// List of slot options /// + [JsonProperty("slotoptions")] public List SlotOptions { get; set; } /// /// List of info items /// + [JsonProperty("infos")] public List> Infos { get; set; } /// /// Type of the machine /// + [JsonProperty("type")] public MachineType MachineType { get; set; } #endregion diff --git a/SabreTools.Library/DatItems/Release.cs b/SabreTools.Library/DatItems/Release.cs index a3b6349b..b73602e5 100644 --- a/SabreTools.Library/DatItems/Release.cs +++ b/SabreTools.Library/DatItems/Release.cs @@ -1,4 +1,5 @@ using SabreTools.Library.Data; +using Newtonsoft.Json; namespace SabreTools.Library.DatItems { @@ -12,21 +13,25 @@ namespace SabreTools.Library.DatItems /// /// 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 diff --git a/SabreTools.Library/DatItems/Rom.cs b/SabreTools.Library/DatItems/Rom.cs index 7d9996fe..ef477ed7 100644 --- a/SabreTools.Library/DatItems/Rom.cs +++ b/SabreTools.Library/DatItems/Rom.cs @@ -3,6 +3,7 @@ using SabreTools.Library.Data; using SabreTools.Library.FileTypes; using SabreTools.Library.Tools; +using Newtonsoft.Json; namespace SabreTools.Library.DatItems { @@ -28,16 +29,19 @@ namespace SabreTools.Library.DatItems /// /// What BIOS is required for this rom /// + [JsonProperty("bios")] public string Bios { get; set; } /// /// Byte size of the rom /// + [JsonProperty("size")] public long Size { get; set; } /// /// File CRC32 hash /// + [JsonProperty("crc")] public string CRC { get { return _crc.IsNullOrWhiteSpace() ? null : Utilities.ByteArrayToString(_crc); } @@ -47,6 +51,7 @@ namespace SabreTools.Library.DatItems /// /// File MD5 hash /// + [JsonProperty("md5")] public string MD5 { get { return _md5.IsNullOrWhiteSpace() ? null : Utilities.ByteArrayToString(_md5); } @@ -56,6 +61,7 @@ namespace SabreTools.Library.DatItems /// /// File RIPEMD160 hash /// + [JsonProperty("ripemd160")] public string RIPEMD160 { get { return _ripemd160.IsNullOrWhiteSpace() ? null : Utilities.ByteArrayToString(_ripemd160); } @@ -65,6 +71,7 @@ namespace SabreTools.Library.DatItems /// /// File SHA-1 hash /// + [JsonProperty("sha1")] public string SHA1 { get { return _sha1.IsNullOrWhiteSpace() ? null : Utilities.ByteArrayToString(_sha1); } @@ -74,6 +81,7 @@ namespace SabreTools.Library.DatItems /// /// File SHA-256 hash /// + [JsonProperty("sha256")] public string SHA256 { get { return _sha256.IsNullOrWhiteSpace() ? null : Utilities.ByteArrayToString(_sha256); } @@ -83,6 +91,7 @@ namespace SabreTools.Library.DatItems /// /// File SHA-384 hash /// + [JsonProperty("sha384")] public string SHA384 { get { return _sha384.IsNullOrWhiteSpace() ? null : Utilities.ByteArrayToString(_sha384); } @@ -92,6 +101,7 @@ namespace SabreTools.Library.DatItems /// /// File SHA-512 hash /// + [JsonProperty("sha512")] public string SHA512 { get { return _sha512.IsNullOrWhiteSpace() ? null : Utilities.ByteArrayToString(_sha512); } @@ -101,31 +111,37 @@ namespace SabreTools.Library.DatItems /// /// Rom name to merge from parent /// + [JsonProperty("merge")] public string MergeTag { get; set; } /// /// Rom region /// + [JsonProperty("region")] public string Region { get; set; } /// /// Data offset within rom /// + [JsonProperty("offset")] public string Offset { get; set; } /// /// File created date /// + [JsonProperty("date")] public string Date { get; set; } /// /// Rom dump status /// + [JsonProperty("status")] public ItemStatus ItemStatus { get; set; } /// /// Determine if the rom is optional in the set /// + [JsonProperty("optional")] public bool? Optional { get; set; } #endregion diff --git a/SabreTools.Library/SabreTools.Library.csproj b/SabreTools.Library/SabreTools.Library.csproj index 0e231743..569ddcb5 100644 --- a/SabreTools.Library/SabreTools.Library.csproj +++ b/SabreTools.Library/SabreTools.Library.csproj @@ -59,6 +59,7 @@ +