Improve file loaded transfer preference

use last char of file extension if available. edge case for pk[m]
considered:
pk[m] => 0x6D, -0x30 = 61d, &7 = 5, which prefers 6 instead of 7+ :)

adds a check for transferred pkm not having their CurrentHandler being
flagged as the save file (impossible for a transferred PKM to be still
handled by the OT).
This commit is contained in:
Kurt 2017-02-06 22:19:10 -08:00
parent 2b606dfc32
commit 2ecf1c1c7b
3 changed files with 6 additions and 3 deletions

View file

@ -741,7 +741,7 @@ namespace PKHeX.WinForms
{ {
openSAV(sav, path); openSAV(sav, path);
} }
else if ((temp = PKMConverter.getPKMfromBytes(input, prefer: SAV.Generation)) != null) else if ((temp = PKMConverter.getPKMfromBytes(input, prefer: ext.Length > 0 ? (ext.Last() - 0x30)&7 : SAV.Generation)) != null)
{ {
PKM pk = PKMConverter.convertToFormat(temp, SAV.PKMType, out c); PKM pk = PKMConverter.convertToFormat(temp, SAV.PKMType, out c);
if (pk == null) if (pk == null)
@ -4173,7 +4173,7 @@ namespace PKHeX.WinForms
byte[] data = File.ReadAllBytes(file); byte[] data = File.ReadAllBytes(file);
MysteryGift mg = MysteryGift.getMysteryGift(data, fi.Extension); MysteryGift mg = MysteryGift.getMysteryGift(data, fi.Extension);
PKM temp = mg?.convertToPKM(SAV) ?? PKMConverter.getPKMfromBytes(data, prefer: SAV.Generation); PKM temp = mg?.convertToPKM(SAV) ?? PKMConverter.getPKMfromBytes(data, prefer: fi.Extension.Length > 0 ? (fi.Extension.Last() - 0x30)&7 : SAV.Generation);
string c; string c;
PKM pk = PKMConverter.convertToFormat(temp, SAV.PKMType, out c); PKM pk = PKMConverter.convertToFormat(temp, SAV.PKMType, out c);

View file

@ -89,7 +89,7 @@ namespace PKHeX.WinForms
{ {
FileInfo fi = new FileInfo(file); FileInfo fi = new FileInfo(file);
if (!fi.Extension.Contains(".pk") || !PKX.getIsPKM(fi.Length)) return; if (!fi.Extension.Contains(".pk") || !PKX.getIsPKM(fi.Length)) return;
var pk = PKMConverter.getPKMfromBytes(File.ReadAllBytes(file), file, prefer: Main.SAV.Generation); var pk = PKMConverter.getPKMfromBytes(File.ReadAllBytes(file), file, prefer: (fi.Extension.Last() - 0x30)&7);
if (pk != null) if (pk != null)
dbTemp.Add(pk); dbTemp.Add(pk);
}); });

View file

@ -1170,6 +1170,9 @@ namespace PKHeX.Core
return new CheckResult(Severity.Invalid, "Should not have OT memories.", CheckIdentifier.History); return new CheckResult(Severity.Invalid, "Should not have OT memories.", CheckIdentifier.History);
} }
if (pkm.Format >= 6 && pkm.GenNumber != pkm.Format && pkm.CurrentHandler != 1)
return new CheckResult(Severity.Invalid, "Current handler cannot be past gen OT for transferred specimen.", CheckIdentifier.History);
if (pkm.HT_Gender > 1) if (pkm.HT_Gender > 1)
return new CheckResult(Severity.Invalid, $"HT Gender invalid {pkm.HT_Gender}.", CheckIdentifier.History); return new CheckResult(Severity.Invalid, $"HT Gender invalid {pkm.HT_Gender}.", CheckIdentifier.History);