mirror of
https://github.com/SabreTools/SabreTools.Serialization.git
synced 2026-05-06 20:43:36 +00:00
Libraries
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.
This commit is contained in:
32
SabreTools.Data.Extensions/XboxExecutableExtensions.cs
Normal file
32
SabreTools.Data.Extensions/XboxExecutableExtensions.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using SabreTools.IO.Extensions;
|
||||
|
||||
namespace SabreTools.Data.Extensions
|
||||
{
|
||||
public static class XboxExecutableExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Convert a UInt32 to a formatted XBE title ID
|
||||
/// </summary>
|
||||
public static string? ToFormattedXBETitleID(this uint value)
|
||||
{
|
||||
// Convert to a byte array
|
||||
byte[] data = BitConverter.GetBytes(value);
|
||||
|
||||
// Create the prefix
|
||||
string prefix1 = (0x41 <= data[3] && data[3] <= 0x5A) || (0x30 <= data[3] && data[3] <= 0x39)
|
||||
? $"{(char)data[3]}"
|
||||
: $"{data[3]:X2}";
|
||||
string prefix2 = (0x41 <= data[2] && data[2] <= 0x5A) || (0x30 <= data[2] && data[2] <= 0x39)
|
||||
? $"{(char)data[2]}"
|
||||
: $"{data[2]:X2}";
|
||||
|
||||
// Create the serial
|
||||
int offset = 0;
|
||||
ushort serial = data.ReadUInt16LittleEndian(ref offset);
|
||||
|
||||
// Assemble and return
|
||||
return $"{prefix1}{prefix2}-{serial:D3}";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user