SabreDAT now JSON-equivalent

This commit is contained in:
Matt Nadareski
2020-09-07 22:21:02 -07:00
parent ccb73f9c39
commit d2ab6fdc05
3 changed files with 156 additions and 1450 deletions

View File

@@ -20,7 +20,7 @@ namespace SabreTools.Library.DatFiles
{ {
#region Fields #region Fields
#region Common Fields #region Common
/// <summary> /// <summary>
/// External name of the DAT /// External name of the DAT
@@ -127,6 +127,9 @@ namespace SabreTools.Library.DatFiles
[XmlElement("forcemerging")] [XmlElement("forcemerging")]
public MergingFlag ForceMerging { get; set; } public MergingFlag ForceMerging { get; set; }
[JsonIgnore]
public bool ForceMergingSpecified { get { return ForceMerging != MergingFlag.None; } }
/// <summary> /// <summary>
/// Force nodump handling when loaded /// Force nodump handling when loaded
/// </summary> /// </summary>
@@ -134,6 +137,9 @@ namespace SabreTools.Library.DatFiles
[XmlElement("forcenodump")] [XmlElement("forcenodump")]
public NodumpFlag ForceNodump { get; set; } public NodumpFlag ForceNodump { get; set; }
[JsonIgnore]
public bool ForceNodumpSpecified { get { return ForceNodump != NodumpFlag.None; } }
/// <summary> /// <summary>
/// Force output packing when loaded /// Force output packing when loaded
/// </summary> /// </summary>
@@ -141,6 +147,9 @@ namespace SabreTools.Library.DatFiles
[XmlElement("forcepacking")] [XmlElement("forcepacking")]
public PackingFlag ForcePacking { get; set; } public PackingFlag ForcePacking { get; set; }
[JsonIgnore]
public bool ForcePackingSpecified { get { return ForcePacking != PackingFlag.None; } }
/// <summary> /// <summary>
/// Read or write format /// Read or write format
/// </summary> /// </summary>
@@ -150,7 +159,7 @@ namespace SabreTools.Library.DatFiles
#endregion #endregion
#region ListXML Fields #region ListXML
/// <summary> /// <summary>
/// Debug build flag /// Debug build flag
@@ -160,6 +169,9 @@ namespace SabreTools.Library.DatFiles
[XmlElement("debug")] [XmlElement("debug")]
public bool? Debug { get; set; } = null; public bool? Debug { get; set; } = null;
[JsonIgnore]
public bool DebugSpecified { get { return Debug != null; } }
/// <summary> /// <summary>
/// MAME configuration name /// MAME configuration name
/// </summary> /// </summary>
@@ -193,6 +205,9 @@ namespace SabreTools.Library.DatFiles
[XmlElement("rommode")] [XmlElement("rommode")]
public MergingFlag RomMode { get; set; } public MergingFlag RomMode { get; set; }
[JsonIgnore]
public bool RomModeSpecified { get { return RomMode != MergingFlag.None; } }
/// <summary> /// <summary>
/// RomCenter bios mode /// RomCenter bios mode
/// </summary> /// </summary>
@@ -201,6 +216,9 @@ namespace SabreTools.Library.DatFiles
[XmlElement("biosmode")] [XmlElement("biosmode")]
public MergingFlag BiosMode { get; set; } public MergingFlag BiosMode { get; set; }
[JsonIgnore]
public bool BiosModeSpecified { get { return BiosMode != MergingFlag.None; } }
/// <summary> /// <summary>
/// RomCenter sample mode /// RomCenter sample mode
/// </summary> /// </summary>
@@ -209,6 +227,9 @@ namespace SabreTools.Library.DatFiles
[XmlElement("samplemode")] [XmlElement("samplemode")]
public MergingFlag SampleMode { get; set; } public MergingFlag SampleMode { get; set; }
[JsonIgnore]
public bool SampleModeSpecified { get { return SampleMode != MergingFlag.None; } }
/// <summary> /// <summary>
/// RomCenter lock rom mode /// RomCenter lock rom mode
/// </summary> /// </summary>
@@ -216,6 +237,9 @@ namespace SabreTools.Library.DatFiles
[XmlElement("lockrommode")] [XmlElement("lockrommode")]
public bool? LockRomMode { get; set; } public bool? LockRomMode { get; set; }
[JsonIgnore]
public bool LockRomModeSpecified { get { return LockRomMode != null; } }
/// <summary> /// <summary>
/// RomCenter lock bios mode /// RomCenter lock bios mode
/// </summary> /// </summary>
@@ -223,6 +247,9 @@ namespace SabreTools.Library.DatFiles
[XmlElement("lockbiosmode")] [XmlElement("lockbiosmode")]
public bool? LockBiosMode { get; set; } public bool? LockBiosMode { get; set; }
[JsonIgnore]
public bool LockBiosModeSpecified { get { return LockBiosMode != null; } }
/// <summary> /// <summary>
/// RomCenter lock sample mode /// RomCenter lock sample mode
/// </summary> /// </summary>
@@ -230,9 +257,12 @@ namespace SabreTools.Library.DatFiles
[XmlElement("locksamplemode")] [XmlElement("locksamplemode")]
public bool? LockSampleMode { get; set; } public bool? LockSampleMode { get; set; }
[JsonIgnore]
public bool LockSampleModeSpecified { get { return LockSampleMode != null; } }
#endregion #endregion
#region Missfile Fields #region Missfile
/// <summary> /// <summary>
/// Output the item name /// Output the item name
@@ -243,7 +273,7 @@ namespace SabreTools.Library.DatFiles
#endregion #endregion
#region OfflineList Fields #region OfflineList
/// <summary> /// <summary>
/// Screenshots width /// Screenshots width
@@ -266,6 +296,9 @@ namespace SabreTools.Library.DatFiles
[XmlElement("infos")] [XmlElement("infos")]
public List<OfflineListInfo> Infos { get; set; } public List<OfflineListInfo> Infos { get; set; }
[JsonIgnore]
public bool InfosSpecified { get { return Infos != null && Infos.Count > 0; } }
/// <summary> /// <summary>
/// OfflineList can-open extensions /// OfflineList can-open extensions
/// </summary> /// </summary>
@@ -273,6 +306,9 @@ namespace SabreTools.Library.DatFiles
[XmlElement("canopen")] [XmlElement("canopen")]
public List<string> CanOpen { get; set; } public List<string> CanOpen { get; set; }
[JsonIgnore]
public bool CanOpenSpecified { get { return CanOpen != null && CanOpen.Count > 0; } }
// TODO: Implement the following header values: // TODO: Implement the following header values:
// - newdat.datversionurl (currently reads and writes to Header.Url, not strictly correct) // - newdat.datversionurl (currently reads and writes to Header.Url, not strictly correct)
// - newdat.daturl (currently writes to Header.Url, not strictly correct) // - newdat.daturl (currently writes to Header.Url, not strictly correct)
@@ -354,62 +390,6 @@ namespace SabreTools.Library.DatFiles
#endregion #endregion
#region XML Serialization Nullable Specifications
#region Common
[JsonIgnore]
public bool ForceMergingSpecified { get { return ForceMerging != MergingFlag.None; } }
[JsonIgnore]
public bool ForceNodumpSpecified { get { return ForceNodump != NodumpFlag.None; } }
[JsonIgnore]
public bool ForcePackingSpecified { get { return ForcePacking != PackingFlag.None; } }
#endregion
#region ListXML
[JsonIgnore]
public bool DebugSpecified { get { return Debug != null; } }
#endregion
#region Logiqx
[JsonIgnore]
public bool RomModeSpecified { get { return RomMode != MergingFlag.None; } }
[JsonIgnore]
public bool BiosModeSpecified { get { return BiosMode != MergingFlag.None; } }
[JsonIgnore]
public bool SampleModeSpecified { get { return SampleMode != MergingFlag.None; } }
[JsonIgnore]
public bool LockRomModeSpecified { get { return LockRomMode != null; } }
[JsonIgnore]
public bool LockBiosModeSpecified { get { return LockBiosMode != null; } }
[JsonIgnore]
public bool LockSampleModeSpecified { get { return LockSampleMode != null; } }
#endregion
#region OfflineList
[JsonIgnore]
public bool InfosSpecified { get { return Infos != null; } }
[JsonIgnore]
public bool CanOpenSpecified { get { return CanOpen != null; } }
#endregion
#endregion // XML Serialization Nullable Specifications
#region Depot Information #region Depot Information
/// <summary> /// <summary>

View File

@@ -1,7 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq;
using System.Text; using System.Text;
using SabreTools.Library.Data; using SabreTools.Library.Data;
@@ -138,7 +137,6 @@ namespace SabreTools.Library.DatFiles
return; return;
// Prepare internal variables // Prepare internal variables
JsonSerializer js = new JsonSerializer();
Machine machine = null; Machine machine = null;
// Read the machine info, if possible // Read the machine info, if possible
@@ -454,7 +452,7 @@ namespace SabreTools.Library.DatFiles
try try
{ {
// No game should start with a path separator // No game should start with a path separator
datItem.Machine.Name = datItem.Machine.Name.TrimStart(Path.DirectorySeparatorChar); datItem.Machine.Name = datItem.Machine.Name.TrimStart(Path.DirectorySeparatorChar) ?? string.Empty;
// Build the state // Build the state
jtw.WriteStartObject(); jtw.WriteStartObject();

File diff suppressed because it is too large Load Diff