PKHeX/PKHeX.Core/Saves/Util/Recognition/SaveHandlerDeSmuME.cs
Kurt d47bb1d297
Update .NET Runtime to .NET 8.0 (#4082)
With the new version of Visual Studio bringing C# 12, we can revise our logic for better readability as well as use new methods/APIs introduced in the .NET 8.0 BCL.
2023-12-03 20:13:20 -08:00

28 lines
810 B
C#

using System;
namespace PKHeX.Core;
/// <summary>
/// Logic for recognizing .dsv save files from DeSmuME.
/// </summary>
public sealed class SaveHandlerDeSmuME : ISaveHandler
{
private const int sizeFooter = 0x7A;
private const int RealSize = SaveUtil.SIZE_G4RAW;
private const int ExpectedSize = RealSize + sizeFooter;
private static bool GetHasFooter(ReadOnlySpan<byte> input) => input.EndsWith("|-DESMUME SAVE-|"u8);
public bool IsRecognized(long size) => size is ExpectedSize;
public SaveHandlerSplitResult? TrySplit(ReadOnlySpan<byte> input)
{
if (!GetHasFooter(input))
return null;
var footer = input[RealSize..].ToArray();
var data = input[..RealSize].ToArray();
return new SaveHandlerSplitResult(data, [], footer);
}
}