mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Add doctype writing to serializers
This commit is contained in:
@@ -130,7 +130,6 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Check required fields
|
|
||||||
return missingFields;
|
return missingFields;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,38 @@
|
|||||||
|
using System.IO;
|
||||||
|
|
||||||
namespace SabreTools.Serialization
|
namespace SabreTools.Serialization
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// XML deserializer for Logiqx-derived metadata files
|
/// XML deserializer for Logiqx-derived metadata files
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Logiqx : XmlSerializer<Models.Logiqx.Datafile> { }
|
public class Logiqx : XmlSerializer<Models.Logiqx.Datafile>
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// name field for DOCTYPE
|
||||||
|
/// </summary>
|
||||||
|
public const string? DocTypeName = "datafile";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// pubid field for DOCTYPE
|
||||||
|
/// </summary>
|
||||||
|
public const string? DocTypePubId = "-//Logiqx//DTD ROM Management Datafile//EN";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// sysid field for DOCTYPE
|
||||||
|
/// </summary>
|
||||||
|
public const string? DocTypeSysId = "http://www.logiqx.com/Dats/datafile.dtd";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// subset field for DOCTYPE
|
||||||
|
/// </summary>
|
||||||
|
public const string? DocTypeSubset = null;
|
||||||
|
|
||||||
|
/// <inheritdoc cref="SerializeToFile(Models.Logiqx.Datafile, string, string?, string?, string?, string?)" />
|
||||||
|
public static bool SerializeToFileWithDocType(Models.Logiqx.Datafile obj, string path)
|
||||||
|
=> SerializeToFile(obj, path, DocTypeName, DocTypePubId, DocTypeSysId, DocTypeSysId);
|
||||||
|
|
||||||
|
/// <inheritdoc cref="SerializeToStream(Models.Logiqx.Datafile, string?, string?, string?, string?)" />
|
||||||
|
public static Stream? SerializeToStreamWithDocType(Models.Logiqx.Datafile obj, string path)
|
||||||
|
=> SerializeToStream(obj, DocTypeName, DocTypePubId, DocTypeSysId, DocTypeSysId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,38 @@
|
|||||||
|
using System.IO;
|
||||||
|
|
||||||
namespace SabreTools.Serialization
|
namespace SabreTools.Serialization
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// XML deserializer for OpenMSX software database files
|
/// XML deserializer for OpenMSX software database files
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class OpenMSX : XmlSerializer<Models.OpenMSX.SoftwareDb> { }
|
public class OpenMSX : XmlSerializer<Models.OpenMSX.SoftwareDb>
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// name field for DOCTYPE
|
||||||
|
/// </summary>
|
||||||
|
public const string? DocTypeName = "softwaredb";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// pubid field for DOCTYPE
|
||||||
|
/// </summary>
|
||||||
|
public const string? DocTypePubId = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// sysid field for DOCTYPE
|
||||||
|
/// </summary>
|
||||||
|
public const string? DocTypeSysId = "softwaredb1.dtd";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// subset field for DOCTYPE
|
||||||
|
/// </summary>
|
||||||
|
public const string? DocTypeSubset = null;
|
||||||
|
|
||||||
|
/// <inheritdoc cref="SerializeToFile(Models.OpenMSX.SoftwareDb, string, string?, string?, string?, string?)" />
|
||||||
|
public static bool SerializeToFileWithDocType(Models.OpenMSX.SoftwareDb obj, string path)
|
||||||
|
=> SerializeToFile(obj, path, DocTypeName, DocTypePubId, DocTypeSysId, DocTypeSysId);
|
||||||
|
|
||||||
|
/// <inheritdoc cref="SerializeToStream(Models.OpenMSX.SoftwareDb, string?, string?, string?, string?)" />
|
||||||
|
public static Stream? SerializeToStreamWithDocType(Models.OpenMSX.SoftwareDb obj, string path)
|
||||||
|
=> SerializeToStream(obj, DocTypeName, DocTypePubId, DocTypeSysId, DocTypeSysId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,38 @@
|
|||||||
|
using System.IO;
|
||||||
|
|
||||||
namespace SabreTools.Serialization
|
namespace SabreTools.Serialization
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// XML deserializer for MAME softwarelist files
|
/// XML deserializer for MAME softwarelist files
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class SoftawreList : XmlSerializer<Models.SoftwareList.SoftwareList> { }
|
public class SoftawreList : XmlSerializer<Models.SoftwareList.SoftwareList>
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// name field for DOCTYPE
|
||||||
|
/// </summary>
|
||||||
|
public const string? DocTypeName = "softwarelist";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// pubid field for DOCTYPE
|
||||||
|
/// </summary>
|
||||||
|
public const string? DocTypePubId = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// sysid field for DOCTYPE
|
||||||
|
/// </summary>
|
||||||
|
public const string? DocTypeSysId = "softwarelist.dtd";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// subset field for DOCTYPE
|
||||||
|
/// </summary>
|
||||||
|
public const string? DocTypeSubset = null;
|
||||||
|
|
||||||
|
/// <inheritdoc cref="SerializeToFile(Models.SoftwareList.SoftwareList, string, string?, string?, string?, string?)" />
|
||||||
|
public static bool SerializeToFileWithDocType(Models.SoftwareList.SoftwareList obj, string path)
|
||||||
|
=> SerializeToFile(obj, path, DocTypeName, DocTypePubId, DocTypeSysId, DocTypeSysId);
|
||||||
|
|
||||||
|
/// <inheritdoc cref="SerializeToStream(Models.SoftwareList.SoftwareList, string?, string?, string?, string?)" />
|
||||||
|
public static Stream? SerializeToStreamWithDocType(Models.SoftwareList.SoftwareList obj, string path)
|
||||||
|
=> SerializeToStream(obj, DocTypeName, DocTypePubId, DocTypeSysId, DocTypeSysId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -10,6 +10,16 @@ namespace SabreTools.Serialization
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract partial class XmlSerializer<T>
|
public abstract partial class XmlSerializer<T>
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Serializes the defined type to an XML file
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="obj">Data to serialize</param>
|
||||||
|
/// <param name="path">Path to the file to serialize to</param>
|
||||||
|
/// <param name="obj">Data to serialize</param>
|
||||||
|
/// <returns>True on successful serialization, false otherwise</returns>
|
||||||
|
public static bool SerializeToFile(T? obj, string path)
|
||||||
|
=> SerializeToFile(obj, path, null, null, null, null);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Serializes the defined type to an XML file
|
/// Serializes the defined type to an XML file
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -21,9 +31,9 @@ namespace SabreTools.Serialization
|
|||||||
/// <param name="sysid">Optional DOCTYPE sysid</param>
|
/// <param name="sysid">Optional DOCTYPE sysid</param>
|
||||||
/// <param name="subset">Optional DOCTYPE name</param>
|
/// <param name="subset">Optional DOCTYPE name</param>
|
||||||
/// <returns>True on successful serialization, false otherwise</returns>
|
/// <returns>True on successful serialization, false otherwise</returns>
|
||||||
public static bool SerializeToFile(T? obj, string path, string? name = null, string? pubid = null, string? sysid = null, string? subset = null)
|
protected static bool SerializeToFile(T? obj, string path, string? name = null, string? pubid = null, string? sysid = null, string? subset = null)
|
||||||
{
|
{
|
||||||
using var stream = SerializeToStream(obj);
|
using var stream = SerializeToStream(obj, name, pubid, sysid, subset);
|
||||||
if (stream == null)
|
if (stream == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@@ -32,6 +42,14 @@ namespace SabreTools.Serialization
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Serializes the defined type to a stream
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="obj">Data to serialize</param>
|
||||||
|
/// <returns>Stream containing serialized data on success, null otherwise</returns>
|
||||||
|
public static Stream? SerializeToStream(T? obj)
|
||||||
|
=> SerializeToStream(obj, null, null, null, null);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Serializes the defined type to a stream
|
/// Serializes the defined type to a stream
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -41,7 +59,7 @@ namespace SabreTools.Serialization
|
|||||||
/// <param name="sysid">Optional DOCTYPE sysid</param>
|
/// <param name="sysid">Optional DOCTYPE sysid</param>
|
||||||
/// <param name="subset">Optional DOCTYPE name</param>
|
/// <param name="subset">Optional DOCTYPE name</param>
|
||||||
/// <returns>Stream containing serialized data on success, null otherwise</returns>
|
/// <returns>Stream containing serialized data on success, null otherwise</returns>
|
||||||
public static Stream? SerializeToStream(T? obj, string? name = null, string? pubid = null, string? sysid = null, string? subset = null)
|
protected static Stream? SerializeToStream(T? obj, string? name = null, string? pubid = null, string? sysid = null, string? subset = null)
|
||||||
{
|
{
|
||||||
// If the object is null
|
// If the object is null
|
||||||
if (obj == null)
|
if (obj == null)
|
||||||
@@ -70,5 +88,6 @@ namespace SabreTools.Serialization
|
|||||||
stream.Seek(0, SeekOrigin.Begin);
|
stream.Seek(0, SeekOrigin.Begin);
|
||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user