mirror of
https://github.com/SabreTools/SabreTools.Serialization.git
synced 2026-04-05 22:01:33 +00:00
This change looks dramatic, but it's just separating out the already-split namespaces into separate top-level folders. In theory, every single one could be built into their own Nuget package. `SabreTools.Serialization` still builds the normal Nuget package that is used by all other projects and includes all namespaces.
54 lines
1.7 KiB
C#
54 lines
1.7 KiB
C#
#pragma warning disable IDE0017 // Simplify object initialization
|
|
namespace SabreTools.Serialization.Readers
|
|
{
|
|
public partial class XMID : IStringReader<Data.Models.Xbox.XMID>
|
|
{
|
|
/// <inheritdoc/>
|
|
public bool Debug { get; set; } = false;
|
|
|
|
/// <inheritdoc cref="IStringReader.Deserialize(string?)"/>
|
|
public static Data.Models.Xbox.XMID? DeserializeString(string? str)
|
|
{
|
|
var deserializer = new XMID();
|
|
return deserializer.Deserialize(str);
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
public Data.Models.Xbox.XMID? Deserialize(string? str)
|
|
{
|
|
if (string.IsNullOrEmpty(str))
|
|
return null;
|
|
|
|
string xmid = str!.TrimEnd('\0');
|
|
if (string.IsNullOrEmpty(xmid))
|
|
return null;
|
|
|
|
return ParseXMID(xmid);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Parse an XGD2/3 XMID string
|
|
/// </summary>
|
|
/// <param name="xmidString">XMID string to attempt to parse</param>
|
|
/// <returns>Filled XMID on success, null on error</returns>
|
|
private static Data.Models.Xbox.XMID? ParseXMID(string? xmidString)
|
|
{
|
|
if (xmidString is null || xmidString.Length != 8)
|
|
return null;
|
|
|
|
var xmid = new Data.Models.Xbox.XMID();
|
|
|
|
#if NETCOREAPP || NETSTANDARD2_1_OR_GREATER
|
|
xmid.PublisherIdentifier = xmidString[..2];
|
|
#else
|
|
xmid.PublisherIdentifier = xmidString.Substring(0, 2);
|
|
#endif
|
|
xmid.GameID = xmidString.Substring(2, 3);
|
|
xmid.VersionNumber = xmidString.Substring(5, 2);
|
|
xmid.RegionIdentifier = xmidString[7];
|
|
|
|
return xmid;
|
|
}
|
|
}
|
|
}
|