From 8a1691eb912b9b377aa5eafbc53e9736f1832349 Mon Sep 17 00:00:00 2001 From: Kurt Date: Fri, 9 Jun 2017 23:13:41 -0700 Subject: [PATCH] Let pkmdb fetch from save backups Only if compiled in debug; bumps my searchables to 6 figures lol bulk legality scan yielded one exception (bad CXD pidiv for starters) bullk sav fetch yielded one exception (unknown type didn't define SeenFlagOffsets) --- PKHeX.Core/Legality/Checks.cs | 3 +++ PKHeX.Core/Saves/SAV3.cs | 2 +- PKHeX.WinForms/Subforms/SAV_Database.cs | 31 ++++++++++++++++++++++++- 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/PKHeX.Core/Legality/Checks.cs b/PKHeX.Core/Legality/Checks.cs index 402030533..eca198e74 100644 --- a/PKHeX.Core/Legality/Checks.cs +++ b/PKHeX.Core/Legality/Checks.cs @@ -824,6 +824,9 @@ private void verifyCXD() } private void verifyCXDStarterCorrelation(PIDIV pidiv) { + if (pidiv.Type != PIDType.CXD) + return; + var spec = EncounterMatch.Species; int rev; // pidiv reversed 2x yields SID, 3x yields TID. shift by 7 if another PKM is generated prior switch (spec) diff --git a/PKHeX.Core/Saves/SAV3.cs b/PKHeX.Core/Saves/SAV3.cs index 284777b58..095e0af2a 100644 --- a/PKHeX.Core/Saves/SAV3.cs +++ b/PKHeX.Core/Saves/SAV3.cs @@ -148,7 +148,7 @@ public SAV3(byte[] data = null, GameVersion versionOverride = GameVersion.Any) HeldItems = Legal.HeldItems_RS; // Sanity Check SeenFlagOffsets -- early saves may not have block 4 initialized yet - SeenFlagOffsets = SeenFlagOffsets.Where(z => z >= 0).ToArray(); + SeenFlagOffsets = SeenFlagOffsets?.Where(z => z >= 0).ToArray(); if (!Exportable) resetBoxes(); diff --git a/PKHeX.WinForms/Subforms/SAV_Database.cs b/PKHeX.WinForms/Subforms/SAV_Database.cs index f824ddb93..ce16d5979 100644 --- a/PKHeX.WinForms/Subforms/SAV_Database.cs +++ b/PKHeX.WinForms/Subforms/SAV_Database.cs @@ -100,6 +100,26 @@ public SAV_Database(PKMEditor f1, SAVEditor saveditor) dbTemp.Add(pk); }); +#if DEBUG + if (SaveUtil.getSavesFromFolder(Main.BackupPath, false, out IEnumerable result)) + { + Parallel.ForEach(result, file => + { + var sav = SaveUtil.getVariantSAV(File.ReadAllBytes(file)); + var path = EXTERNAL_SAV + new FileInfo(file).Name; + if (sav.HasBox) + foreach (var pk in sav.BoxData) + addPKM(pk); + + void addPKM(PKM pk) + { + pk.Identifier = Path.Combine(path, pk.Identifier); + dbTemp.Add(pk); + } + }); + } +#endif + // Prepare Database RawDB = new List(dbTemp.OrderBy(pk => pk.Identifier) .Concat(SAV.BoxData.Where(pk => pk.Species != 0)) // Fetch from save file @@ -126,6 +146,7 @@ public SAV_Database(PKMEditor f1, SAVEditor saveditor) private readonly string Counter; private readonly string Viewed; private const int MAXFORMAT = 7; + private readonly string EXTERNAL_SAV = new DirectoryInfo(Main.BackupPath).Name + Path.DirectorySeparatorChar; private static string hash(PKM pk) { switch (pk.Format) @@ -178,10 +199,18 @@ private void clickDelete(object sender, EventArgs e) var pk = Results[index]; string path = pk.Identifier; +#if DEBUG + if (path.StartsWith(EXTERNAL_SAV)) + { + WinFormsUtil.Alert("Can't delete from a backup save."); + return; + } +#endif if (path.Contains(Path.DirectorySeparatorChar)) { // Data from Database: Delete file from disk - File.Delete(path); + if (File.Exists(path)) + File.Delete(path); } else {