Invert export flags, fix footer inclusion gen1-3

Closes #4307
This commit is contained in:
Kurt 2024-06-29 12:55:13 -05:00
parent dc5f1a0b17
commit baac00c130
2 changed files with 16 additions and 9 deletions

View file

@ -55,11 +55,11 @@ public sealed record SaveFileMetadata(SaveFile SAV)
/// <returns>Final save file data.</returns>
public byte[] Finalize(byte[] data, BinaryExportSetting setting)
{
if (Footer.Length != 0 && setting.HasFlag(BinaryExportSetting.IncludeFooter))
if (HasFooter && !setting.HasFlag(BinaryExportSetting.ExcludeFooter))
data = [..data, ..Footer];
if (Header.Length != 0 && setting.HasFlag(BinaryExportSetting.IncludeHeader))
if (HasHeader && !setting.HasFlag(BinaryExportSetting.ExcludeHeader))
data = [..Header, ..data];
if (setting != BinaryExportSetting.None)
if (!setting.HasFlag(BinaryExportSetting.ExcludeFinalize))
Handler?.Finalize(data);
return data;
}
@ -189,11 +189,17 @@ public sealed record SaveFileMetadata(SaveFile SAV)
/// <param name="ext">Selected export extension</param>
public BinaryExportSetting GetSuggestedFlags(string? ext = null)
{
// Do everything as default
var flags = BinaryExportSetting.None;
if (ext == ".dsv")
flags |= BinaryExportSetting.IncludeFooter;
if (ext == ".gci" || SAV is IGCSaveFile {MemoryCard: null} || ext == ".sram")
flags |= BinaryExportSetting.IncludeHeader;
if (FileName is not null)
{
// Try to support a couple formats changes that the user wants to remove from the file
if (FileName.EndsWith(".dsv") && ext is not ".dsv")
flags |= BinaryExportSetting.ExcludeFooter;
else if (FileName.EndsWith(".gci") && ext is not ".gci")
flags |= BinaryExportSetting.ExcludeHeader;
}
return flags;
}
}

View file

@ -6,6 +6,7 @@ namespace PKHeX.Core;
public enum BinaryExportSetting
{
None,
IncludeFooter = 1 << 0,
IncludeHeader = 1 << 1,
ExcludeFooter = 1 << 0,
ExcludeHeader = 1 << 1,
ExcludeFinalize = 1 << 2,
}