mirror of
https://github.com/SabreTools/SabreTools.Serialization.git
synced 2026-05-06 20:43:36 +00:00
64 lines
2.3 KiB
C#
64 lines
2.3 KiB
C#
using SabreTools.Serialization.Interfaces;
|
|
|
|
namespace SabreTools.Serialization.Strings
|
|
{
|
|
public partial class XeMID : IStringSerializer<Models.Xbox.XeMID>
|
|
{
|
|
/// <inheritdoc/>
|
|
public Models.Xbox.XeMID? Deserialize(string? str)
|
|
{
|
|
if (string.IsNullOrEmpty(str))
|
|
return null;
|
|
|
|
string xemid = str!.TrimEnd('\0');
|
|
if (string.IsNullOrEmpty(xemid))
|
|
return null;
|
|
|
|
return ParseXeMID(xemid);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Parse an XGD2/3 XeMID string
|
|
/// </summary>
|
|
/// <param name="xemidString">XeMID string to attempt to parse</param>
|
|
/// <returns>Filled XeMID on success, null on error</returns>
|
|
private static Models.Xbox.XeMID? ParseXeMID(string? xemidString)
|
|
{
|
|
if (xemidString == null)
|
|
return null;
|
|
if (!(xemidString.Length == 13 || xemidString.Length == 14 || xemidString.Length == 21 || xemidString.Length == 22))
|
|
return null;
|
|
|
|
var xemid = new Models.Xbox.XeMID();
|
|
|
|
xemid.PublisherIdentifier = xemidString.Substring(0, 2);
|
|
xemid.PlatformIdentifier = xemidString[2];
|
|
if (xemid.PlatformIdentifier != '2')
|
|
return null;
|
|
|
|
xemid.GameID = xemidString.Substring(3, 3);
|
|
xemid.SKU = xemidString.Substring(6, 2);
|
|
xemid.RegionIdentifier = xemidString[8];
|
|
|
|
if (xemidString.Length == 13 || xemidString.Length == 21)
|
|
{
|
|
xemid.BaseVersion = xemidString.Substring(9, 1);
|
|
xemid.MediaSubtypeIdentifier = xemidString[10];
|
|
xemid.DiscNumberIdentifier = xemidString.Substring(11, 2);
|
|
}
|
|
else if (xemidString.Length == 14 || xemidString.Length == 22)
|
|
{
|
|
xemid.BaseVersion = xemidString.Substring(9, 2);
|
|
xemid.MediaSubtypeIdentifier = xemidString[11];
|
|
xemid.DiscNumberIdentifier = xemidString.Substring(12, 2);
|
|
}
|
|
|
|
if (xemidString.Length == 21)
|
|
xemid.CertificationSubmissionIdentifier = xemidString.Substring(13);
|
|
else if (xemidString.Length == 22)
|
|
xemid.CertificationSubmissionIdentifier = xemidString.Substring(14);
|
|
|
|
return xemid;
|
|
}
|
|
}
|
|
} |