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

View File

@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using SabreTools.Library.Data;
@@ -138,7 +137,6 @@ namespace SabreTools.Library.DatFiles
return;
// Prepare internal variables
JsonSerializer js = new JsonSerializer();
Machine machine = null;
// Read the machine info, if possible
@@ -454,7 +452,7 @@ namespace SabreTools.Library.DatFiles
try
{
// 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
jtw.WriteStartObject();

File diff suppressed because it is too large Load Diff