Minor clean

Magic number -> const usage
default(T) -> default (c#7.x feature)
remove some unused stuff
fix indentation in some spots
This commit is contained in:
Kurt 2019-09-10 22:07:50 -07:00
parent 62d08d7c30
commit c5ebbbbe15
24 changed files with 223 additions and 237 deletions

View file

@ -121,7 +121,7 @@ namespace PKHeX.Core
PersonalInfo = table?.GetFormeEntry(pkm.Species, pkm.AltForm) ?? pkm.PersonalInfo;
ParseLegality();
if (Parse.Count <= 0)
if (Parse.Count == 0)
return;
Valid = Parse.All(chk => chk.Valid)

View file

@ -69,11 +69,13 @@ namespace PKHeX.Core
// Process Conditions
if (PKX.GetUnownForm(pid) == form) // matches form, does it match nature?
{
switch (VerifyPIDCriteria(pid, info))
{
case LockInfo.Pass: // yes
yield break;
}
}
s1 = pidiv.RNG.Prev(s2);
s2 = pidiv.RNG.Prev(s1);

View file

@ -205,7 +205,7 @@ namespace PKHeX.Core
if (pk4.IV32 == 0)
{
uint iv1 = ((seed = RNG.LCRNG.Next(seed)) >> 16) & 0x7FFF;
uint iv2 = ((_ = RNG.LCRNG.Next(seed)) >> 16) & 0x7FFF;
uint iv2 = ((RNG.LCRNG.Next(seed)) >> 16) & 0x7FFF;
pk4.IV32 = iv1 | iv2 << 15;
}
}

View file

@ -36,8 +36,8 @@ namespace PKHeX.Core
Data = new byte[Data.Length]; // Invalidate
}
public int RestrictLanguage { get; set; } = 0; // None
public byte RestrictVersion { get; set; } = 0; // Permit All
public int RestrictLanguage { get; set; } // None
public byte RestrictVersion { get; set; } // Permit All
public bool CanBeReceivedByVersion(int v)
{

View file

@ -34,8 +34,8 @@ namespace PKHeX.Core
RawDate = SetDate((uint) now.Year, (uint) now.Month, (uint) now.Day);
}
public int RestrictLanguage { get; set; } = 0; // None
public byte RestrictVersion { get; set; } = 0; // Permit All
public int RestrictLanguage { get; set; } // None
public byte RestrictVersion { get; set; } // Permit All
public bool CanBeReceivedByVersion(int v)
{

View file

@ -660,7 +660,7 @@ namespace PKHeX.Core
byte[] ekm = ShuffleArray3(pkm, blockPositionInvert[PID%24]);
byte[] xorkey = BitConverter.GetBytes(seed);
for (int i = 32; i < 80; i++)
for (int i = 32; i < SIZE_3STORED; i++)
ekm[i] ^= xorkey[i & 3];
return ekm;
}

View file

@ -23,19 +23,19 @@ namespace PKHeX.Core
// Constructor
public MemeKey(MemeKeyIndex key)
{
GetMemeData(key, out byte[] d, out byte[] der);
DER = der;
DER = GetMemeData(key);
var _N = new byte[0x61];
var _E = new byte[0x3];
Array.Copy(der, 0x18, _N, 0, 0x61);
Array.Copy(der, 0x7B, _E, 0, 3);
Array.Copy(DER, 0x18, _N, 0, 0x61);
Array.Copy(DER, 0x7B, _E, 0, 3);
Array.Reverse(_N);
N = new BigInteger(_N);
Array.Reverse(_E);
E = new BigInteger(_E);
if (d != null)
if (key == MemeKeyIndex.PokedexAndSaveFile)
{
var _D = (byte[])d.Clone();
var _D = (byte[])D_3.Clone();
Array.Reverse(_D);
D = new BigInteger(_D);
}
@ -59,6 +59,7 @@ namespace PKHeX.Core
{
if (data.Length < 0x60)
throw new ArgumentException("Memebuffers must be atleast 0x60 bytes long!");
var key = new byte[0x10];
var buffer = new byte[DER.Length + data.Length - 0x60];
Array.Copy(DER, 0, buffer, 0, DER.Length);
@ -232,59 +233,26 @@ namespace PKHeX.Core
Array.Copy(rawSig, outSig, 0x60);
return outSig;
}
// Helper Method to retrieve data for loading
private static void GetMemeData(MemeKeyIndex key, out byte[] d, out byte[] der)
{
d = null;
private static byte[] GetMemeData(MemeKeyIndex key)
{
switch (key)
{
case MemeKeyIndex.LocalWireless:
der = DER_LW;
break;
case MemeKeyIndex.FriendlyCompetition:
der = DER_0;
break;
case MemeKeyIndex.LiveCompetition:
der = DER_1;
break;
case MemeKeyIndex.RentalTeam:
der = DER_2;
break;
case MemeKeyIndex.PokedexAndSaveFile:
der = DER_3;
d = D_3;
break;
case MemeKeyIndex.GaOle:
der = DER_4;
break;
case MemeKeyIndex.MagearnaEvent:
der = DER_5;
break;
case MemeKeyIndex.MoncolleGet:
der = DER_6;
break;
case MemeKeyIndex.IslandScanEventSpecial:
der = DER_7;
break;
case MemeKeyIndex.TvTokyoDataBroadcasting:
der = DER_8;
break;
case MemeKeyIndex.CapPikachuEvent:
der = DER_9;
break;
case MemeKeyIndex.Unknown10:
der = DER_A;
break;
case MemeKeyIndex.Unknown11:
der = DER_B;
break;
case MemeKeyIndex.Unknown12:
der = DER_C;
break;
case MemeKeyIndex.Unknown13:
der = DER_D;
break;
case MemeKeyIndex.LocalWireless: return DER_LW;
case MemeKeyIndex.FriendlyCompetition: return DER_0;
case MemeKeyIndex.LiveCompetition: return DER_1;
case MemeKeyIndex.RentalTeam: return DER_2;
case MemeKeyIndex.PokedexAndSaveFile: return DER_3;
case MemeKeyIndex.GaOle: return DER_4;
case MemeKeyIndex.MagearnaEvent: return DER_5;
case MemeKeyIndex.MoncolleGet: return DER_6;
case MemeKeyIndex.IslandScanEventSpecial: return DER_7;
case MemeKeyIndex.TvTokyoDataBroadcasting: return DER_8;
case MemeKeyIndex.CapPikachuEvent: return DER_9;
case MemeKeyIndex.Unknown10: return DER_A;
case MemeKeyIndex.Unknown11: return DER_B;
case MemeKeyIndex.Unknown12: return DER_C;
case MemeKeyIndex.Unknown13: return DER_D;
default:
throw new ArgumentOutOfRangeException(nameof(key), key, null);
}

View file

@ -10,7 +10,7 @@ namespace PKHeX.Core
val |= data[offset + 0] << 24;
val |= data[offset + 1] << 16;
val |= data[offset + 2] << 8;
val |= data[offset + 3] << 0;
val |= data[offset + 3];
return (uint)val;
}
@ -18,7 +18,7 @@ namespace PKHeX.Core
{
int val = 0;
val |= data[offset + 0] << 8;
val |= data[offset + 1] << 0;
val |= data[offset + 1];
return (ushort)val;
}
@ -28,7 +28,7 @@ namespace PKHeX.Core
val |= data[offset + 0] << 24;
val |= data[offset + 1] << 16;
val |= data[offset + 2] << 8;
val |= data[offset + 3] << 0;
val |= data[offset + 3];
return val;
}
@ -36,7 +36,7 @@ namespace PKHeX.Core
{
int val = 0;
val |= data[offset + 0] << 8;
val |= data[offset + 1] << 0;
val |= data[offset + 1];
return (short)val;
}

View file

@ -116,17 +116,16 @@ namespace PKHeX.Core
public static string GetStringResource(string name)
{
if (!resourceNameMap.ContainsKey(name))
if (!resourceNameMap.TryGetValue(name, out var resname))
{
bool Match(string x) => x.StartsWith("PKHeX.Core.Resources.text.") && x.EndsWith($"{name}.txt", StringComparison.OrdinalIgnoreCase);
var resname = Array.Find(manifestResourceNames, Match);
resname = Array.Find(manifestResourceNames, Match);
if (resname == null)
return null;
resourceNameMap.Add(name, resname);
}
if (resourceNameMap[name] == null)
return null;
using (var resource = thisAssembly.GetManifestResourceStream(resourceNameMap[name]))
using (var resource = thisAssembly.GetManifestResourceStream(resname))
using (var reader = new StreamReader(resource))
return reader.ReadToEnd();
}
@ -318,9 +317,8 @@ namespace PKHeX.Core
public static void AddCBWithOffset(List<ComboItem> cbList, IReadOnlyList<string> inStrings, int offset, params int[] allowed)
{
int beginCount = cbList.Count;
for (int i = 0; i < allowed.Length; i++)
foreach (var index in allowed)
{
int index = allowed[i];
var item = new ComboItem(inStrings[index - offset], index);
cbList.Add(item);
}
@ -330,9 +328,8 @@ namespace PKHeX.Core
public static void AddCB(List<ComboItem> cbList, IReadOnlyList<string> inStrings, int[] allowed)
{
int beginCount = cbList.Count;
for (int i = 0; i < allowed.Length; i++)
foreach (var index in allowed)
{
int index = allowed[i];
var item = new ComboItem(inStrings[index], index);
cbList.Add(item);
}

View file

@ -134,7 +134,7 @@ namespace PKHeX.Core
{
if (ext == ".pgt") // size collision with pk6
{
pk = default(PKM);
pk = default;
return false;
}
var format = PKX.GetPKMFormatFromExtension(ext, sav?.Generation ?? 6);

View file

@ -55,12 +55,15 @@ namespace PKHeX.WinForms.Controls
imgWidth = baseImage.Width;
imgHeight = baseImage.Height;
GlowData = glowData;
pb = pbox;
GlowCounter = 0;
OriginalBackground = original;
GlowCache = new Image[GlowFps];
GlowInterval = 1000 / GlowFps;
Interval = GlowInterval;
lock (Lock)
{
pb = pbox;
OriginalBackground = original;
}
Enabled = true;
}

View file

@ -1,7 +1,4 @@
using System;
using PKHeX.Core;
namespace PKHeX.WinForms.Controls
namespace PKHeX.WinForms.Controls
{
internal enum SlotIndex
{
@ -9,29 +6,4 @@ namespace PKHeX.WinForms.Controls
BattleBox = 6,
Daycare = 12,
}
public static partial class Extensions
{
internal static bool IsEditable(this SlotIndex type) => type == SlotIndex.Party;
internal static bool IsParty(this SlotIndex type, int format) => type < SlotIndex.BattleBox || (format == 5 && type == SlotIndex.BattleBox);
internal static SlotIndex GetMiscSlotType(int slot)
{
if (slot < (int)SlotIndex.BattleBox) return SlotIndex.Party;
if (slot < (int)SlotIndex.Daycare) return SlotIndex.BattleBox;
return SlotIndex.Daycare;
}
internal static StorageSlotType GetMiscSlotType(this SlotIndex type)
{
switch (type)
{
case SlotIndex.Party: return StorageSlotType.Party;
case SlotIndex.Daycare: return StorageSlotType.Daycare;
case SlotIndex.BattleBox: return StorageSlotType.BattleBox;
default:
throw new ArgumentOutOfRangeException(nameof(type), type, null);
}
}
}
}

View file

@ -1105,10 +1105,8 @@ namespace PKHeX.WinForms
return;
OpenQuick(files[0]);
e.Effect = DragDropEffects.Copy;
Cursor = DefaultCursor;
}
// Decrypted Export
private void Dragout_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left && (ModifierKeys == Keys.Alt || ModifierKeys == Keys.Shift))

View file

@ -32,6 +32,7 @@
this.RB_Boxes = new System.Windows.Forms.RadioButton();
this.RB_Path = new System.Windows.Forms.RadioButton();
this.FLP_RB = new System.Windows.Forms.FlowLayoutPanel();
this.RB_Party = new System.Windows.Forms.RadioButton();
this.TB_Folder = new System.Windows.Forms.TextBox();
this.RTB_Instructions = new System.Windows.Forms.RichTextBox();
this.B_Go = new System.Windows.Forms.Button();
@ -42,7 +43,7 @@
this.B_Add = new System.Windows.Forms.Button();
this.L_PropType = new System.Windows.Forms.Label();
this.L_PropValue = new System.Windows.Forms.Label();
this.RB_Party = new System.Windows.Forms.RadioButton();
this.b = new System.ComponentModel.BackgroundWorker();
this.FLP_RB.SuspendLayout();
this.SuspendLayout();
//
@ -89,6 +90,19 @@
this.FLP_RB.Size = new System.Drawing.Size(370, 24);
this.FLP_RB.TabIndex = 2;
//
// RB_Party
//
this.RB_Party.Anchor = System.Windows.Forms.AnchorStyles.Left;
this.RB_Party.Appearance = System.Windows.Forms.Appearance.Button;
this.RB_Party.AutoSize = true;
this.RB_Party.Location = new System.Drawing.Point(46, 0);
this.RB_Party.Margin = new System.Windows.Forms.Padding(0);
this.RB_Party.Name = "RB_Party";
this.RB_Party.Size = new System.Drawing.Size(41, 23);
this.RB_Party.TabIndex = 5;
this.RB_Party.Text = "Party";
this.RB_Party.UseVisualStyleBackColor = true;
//
// TB_Folder
//
this.TB_Folder.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
@ -199,18 +213,9 @@
this.L_PropValue.TabIndex = 13;
this.L_PropValue.Text = "PropertyValue";
//
// RB_Party
// b
//
this.RB_Party.Anchor = System.Windows.Forms.AnchorStyles.Left;
this.RB_Party.Appearance = System.Windows.Forms.Appearance.Button;
this.RB_Party.AutoSize = true;
this.RB_Party.Location = new System.Drawing.Point(46, 0);
this.RB_Party.Margin = new System.Windows.Forms.Padding(0);
this.RB_Party.Name = "RB_Party";
this.RB_Party.Size = new System.Drawing.Size(41, 23);
this.RB_Party.TabIndex = 5;
this.RB_Party.Text = "Party";
this.RB_Party.UseVisualStyleBackColor = true;
this.b.WorkerReportsProgress = true;
//
// BatchEditor
//
@ -258,5 +263,6 @@
private System.Windows.Forms.Label L_PropType;
private System.Windows.Forms.Label L_PropValue;
private System.Windows.Forms.RadioButton RB_Party;
private System.ComponentModel.BackgroundWorker b;
}
}

View file

@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Linq;
@ -119,8 +118,6 @@ namespace PKHeX.WinForms
RB_Path.Checked = true;
}
private BackgroundWorker b;
private void RunBackgroundWorker()
{
if (RTB_Instructions.Lines.Any(line => line.Length == 0))
@ -167,7 +164,6 @@ namespace PKHeX.WinForms
private void RunBatchEdit(StringInstructionSet[] sets, string source, string destination)
{
editor = new Core.BatchEditor();
b = new BackgroundWorker { WorkerReportsProgress = true };
b.DoWork += (sender, e) =>
{
if (RB_Boxes.Checked)

View file

@ -117,6 +117,9 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="b.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>

View file

@ -28,6 +28,7 @@
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(SAV_Database));
this.SCR_Box = new System.Windows.Forms.VScrollBar();
this.bpkx30 = new System.Windows.Forms.PictureBox();
@ -159,6 +160,10 @@
this.L_Format = new System.Windows.Forms.Label();
this.FLP_Level = new System.Windows.Forms.FlowLayoutPanel();
this.RTB_Instructions = new System.Windows.Forms.RichTextBox();
this.mnu = new System.Windows.Forms.ContextMenuStrip(this.components);
this.mnuView = new System.Windows.Forms.ToolStripMenuItem();
this.mnuDelete = new System.Windows.Forms.ToolStripMenuItem();
this.hover = new System.Windows.Forms.ToolTip(this.components);
((System.ComponentModel.ISupportInitialize)(this.bpkx30)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.bpkx29)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.bpkx28)).BeginInit();
@ -232,6 +237,7 @@
this.TLP_Filters.SuspendLayout();
this.FLP_Format.SuspendLayout();
this.FLP_Level.SuspendLayout();
this.mnu.SuspendLayout();
this.SuspendLayout();
//
// SCR_Box
@ -1625,6 +1631,7 @@
this.L_Viewed.TabIndex = 117;
this.L_Viewed.Text = "Last Viewed: {0}";
this.L_Viewed.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.L_Viewed.MouseEnter += new System.EventHandler(this.L_Viewed_MouseEnter);
//
// FLP_Egg
//
@ -1845,6 +1852,28 @@
this.RTB_Instructions.TabIndex = 119;
this.RTB_Instructions.Text = "";
//
// mnu
//
this.mnu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.mnuView,
this.mnuDelete});
this.mnu.Name = "mnu";
this.mnu.Size = new System.Drawing.Size(108, 48);
this.mnu.Click += new System.EventHandler(this.ClickView);
//
// mnuView
//
this.mnuView.Name = "mnuView";
this.mnuView.Size = new System.Drawing.Size(107, 22);
this.mnuView.Text = "View";
//
// mnuDelete
//
this.mnuDelete.Name = "mnuDelete";
this.mnuDelete.Size = new System.Drawing.Size(107, 22);
this.mnuDelete.Text = "Delete";
this.mnuDelete.Click += new System.EventHandler(this.ClickDelete);
//
// SAV_Database
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -1944,6 +1973,7 @@
this.FLP_Format.ResumeLayout(false);
this.FLP_Level.ResumeLayout(false);
this.FLP_Level.PerformLayout();
this.mnu.ResumeLayout(false);
this.ResumeLayout(false);
this.PerformLayout();
@ -2081,5 +2111,9 @@
private System.Windows.Forms.ToolStripMenuItem Menu_SearchClones;
private System.Windows.Forms.ToolStripMenuItem Menu_DeleteClones;
private System.Windows.Forms.ToolStripMenuItem Menu_Import;
private System.Windows.Forms.ContextMenuStrip mnu;
private System.Windows.Forms.ToolStripMenuItem mnuView;
private System.Windows.Forms.ToolStripMenuItem mnuDelete;
private System.Windows.Forms.ToolTip hover;
}
}

View file

@ -1,5 +1,4 @@
#define LOADALL
using System;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
@ -26,11 +25,7 @@ namespace PKHeX.WinForms
{
InitializeComponent();
ToolStripMenuItem mnuView = new ToolStripMenuItem {Name = "mnuView", Text = "View"};
ToolStripMenuItem mnuDelete = new ToolStripMenuItem {Name = "mnuDelete", Text = "Delete" };
WinFormsUtil.TranslateInterface(this, Main.CurrentLanguage);
ContextMenuStrip mnu = new ContextMenuStrip();
mnu.Items.AddRange(new ToolStripItem[] { mnuView, mnuDelete });
SAV = saveditor.SAV;
@ -62,48 +57,23 @@ namespace PKHeX.WinForms
// Enable Click
slot.MouseClick += (sender, e) =>
{
if (ModifierKeys == Keys.Control)
ClickView(sender, e);
else if (ModifierKeys == Keys.Alt)
ClickDelete(sender, e);
else if (ModifierKeys == Keys.Shift)
ClickSet(sender, e);
switch (ModifierKeys)
{
case Keys.Control: ClickView(sender, e); break;
case Keys.Alt: ClickDelete(sender, e); break;
case Keys.Shift: ClickSet(sender, e); break;
}
};
if (Settings.Default.HoverSlotShowText)
{
slot.MouseEnter += (sender, e) =>
{
int index = Array.IndexOf(PKXBOXES, slot);
if (!GetShiftedIndex(ref index))
return;
var pk = Results[index];
if (pk.Species == 0)
{
ShowSet.RemoveAll();
return;
}
var text = ShowdownSet.GetLocalizedPreviewText(pk, Settings.Default.Language);
ShowSet.SetToolTip(slot, text);
};
}
slot.MouseEnter += ShowHoverTextForSlot;
}
Counter = L_Count.Text;
Viewed = L_Viewed.Text;
L_Viewed.Text = string.Empty; // invis for now
var hover = new ToolTip();
L_Viewed.MouseEnter += (sender, e) => hover.SetToolTip(L_Viewed, L_Viewed.Text);
L_Viewed.Text = string.Empty; // invisible for now
PopulateComboBoxes();
// Assign event handlers
mnuView.Click += ClickView;
mnuDelete.Click += ClickDelete;
// Add to main context menu
// Assign to datagridview
foreach (PictureBox p in PKXBOXES)
p.ContextMenuStrip = mnu;
@ -134,7 +104,7 @@ namespace PKHeX.WinForms
private readonly string Viewed;
private const int MAXFORMAT = PKX.Generation;
private readonly string EXTERNAL_SAV = new DirectoryInfo(Main.BackupPath).Name + Path.DirectorySeparatorChar;
private readonly ToolTip ShowSet = new ToolTip {InitialDelay = 200, IsBalloon = false};
private readonly SummaryPreviewer ShowSet = new SummaryPreviewer();
// Important Events
private void ClickView(object sender, EventArgs e)
@ -149,7 +119,7 @@ namespace PKHeX.WinForms
PKME_Tabs.PopulateFields(Results[index], false);
slotSelected = index;
slotColor = Properties.Resources.slotView;
slotColor = Resources.slotView;
FillPKXBoxes(SCR_Box.Value);
L_Viewed.Text = string.Format(Viewed, Results[index].Identifier);
}
@ -236,7 +206,7 @@ namespace PKHeX.WinForms
// Refresh database view.
L_Count.Text = string.Format(Counter, Results.Count);
slotSelected = Results.Count - 1;
slotColor = Properties.Resources.slotSet;
slotColor = Resources.slotSet;
if ((SCR_Box.Maximum+1)*6 < Results.Count)
SCR_Box.Maximum++;
SCR_Box.Value = Math.Max(0, SCR_Box.Maximum - (PKXBOXES.Length/6) + 1);
@ -331,6 +301,14 @@ namespace PKHeX.WinForms
if (WinFormsUtil.Prompt(MessageBoxButtons.YesNo, MsgDBCreateReportPrompt, MsgDBCreateReportWarning) != DialogResult.Yes)
return;
var form = WinFormsUtil.FirstFormOfType<ReportGrid>();
if (form != null)
{
form.BringToFront();
form.CenterToForm(this);
}
ReportGrid reportGrid = new ReportGrid();
reportGrid.Show();
reportGrid.PopulateData(Results.ToArray());
@ -357,34 +335,51 @@ namespace PKHeX.WinForms
private static List<PKM> LoadPKMSaves(string pkmdb, string savdb, string EXTERNAL_SAV, SaveFile SAV)
{
var dbTemp = new ConcurrentBag<PKM>();
var files = Directory.EnumerateFiles(pkmdb, "*", SearchOption.AllDirectories);
var extensions = new HashSet<string>(PKM.Extensions.Select(z => $".{z}"));
Parallel.ForEach(files, file =>
var files = Directory.EnumerateFiles(pkmdb, "*", SearchOption.AllDirectories);
Parallel.ForEach(files, file => TryAddPKMsFromFolder(dbTemp, file, SAV, extensions));
if (SaveUtil.GetSavesFromFolder(savdb, false, out IEnumerable<string> result))
Parallel.ForEach(result, file => TryAddPKMsFromSaveFilePath(dbTemp, file, EXTERNAL_SAV));
// Fetch from save file
var savpkm = SAV.BoxData.Where(pk => pk.Species != 0);
var bakpkm = dbTemp.Where(pk => pk.Species != 0).OrderBy(pk => pk.Identifier);
var db = bakpkm.Concat(savpkm).Where(pk => pk.ChecksumValid && pk.Sanity == 0);
// Finalize the Database
return new List<PKM>(db);
}
private static void TryAddPKMsFromFolder(ConcurrentBag<PKM> dbTemp, string file, ITrainerInfo dest, ICollection<string> validExtensions)
{
var fi = new FileInfo(file);
if (!extensions.Contains(fi.Extension) || !PKX.IsPKM(fi.Length)) return;
if (!validExtensions.Contains(fi.Extension) || !PKX.IsPKM(fi.Length))
return;
var data = File.ReadAllBytes(file);
var prefer = PKX.GetPKMFormatFromExtension(fi.Extension, SAV.Generation);
var prefer = PKX.GetPKMFormatFromExtension(fi.Extension, dest.Generation);
var pk = PKMConverter.GetPKMfromBytes(data, prefer);
if (!(pk?.Species > 0))
return;
pk.Identifier = file;
dbTemp.Add(pk);
});
}
#if LOADALL
if (SaveUtil.GetSavesFromFolder(savdb, false, out IEnumerable<string> result))
private static void TryAddPKMsFromSaveFilePath(ConcurrentBag<PKM> dbTemp, string file, string externalFilePrefix)
{
Parallel.ForEach(result, file =>
try
{
try {
var sav = SaveUtil.GetVariantSAV(file);
if (sav == null)
{
Console.WriteLine("Unable to load SaveFile: " + file);
return; // bad backup
return;
}
var path = EXTERNAL_SAV + Path.GetFileName(file);
var path = externalFilePrefix + Path.GetFileName(file);
if (sav.HasBox)
{
foreach (var pk in sav.BoxData)
@ -402,17 +397,6 @@ namespace PKHeX.WinForms
Console.WriteLine("ERROR: Unable to load SaveFile: " + file);
Console.WriteLine(ex.Message);
}
});
}
#endif
// Fetch from save file
var savpkm = SAV.BoxData.Where(pk => pk.Species != 0);
var bakpkm = dbTemp.Where(pk => pk.Species != 0).OrderBy(pk => pk.Identifier);
var db = bakpkm.Concat(savpkm).Where(pk => pk.ChecksumValid && pk.Sanity == 0);
// Prepare Database
return new List<PKM>(db);
}
// IO Usage
@ -596,9 +580,9 @@ namespace PKHeX.WinForms
PKXBOXES[i].Image = null;
for (int i = 0; i < RES_MAX; i++)
PKXBOXES[i].BackgroundImage = Properties.Resources.slotTrans;
PKXBOXES[i].BackgroundImage = Resources.slotTrans;
if (slotSelected != -1 && slotSelected >= begin && slotSelected < begin + RES_MAX)
PKXBOXES[slotSelected - begin].BackgroundImage = slotColor ?? Properties.Resources.slotView;
PKXBOXES[slotSelected - begin].BackgroundImage = slotColor ?? Resources.slotView;
}
// Misc Update Methods
@ -691,5 +675,17 @@ namespace PKHeX.WinForms
WinFormsUtil.Alert(string.Format(MsgFileDeleteCount, deleted), MsgWindowClose);
Close();
}
private void L_Viewed_MouseEnter(object sender, EventArgs e) => hover.SetToolTip(L_Viewed, L_Viewed.Text);
private void ShowHoverTextForSlot(object sender, EventArgs e)
{
var pb = (PictureBox)sender;
int index = Array.IndexOf(PKXBOXES, pb);
if (!GetShiftedIndex(ref index))
return;
ShowSet.Show(pb, Results[index]);
}
}
}

View file

@ -321,6 +321,12 @@
<metadata name="bpkx61.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="mnu.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>132, 17</value>
</metadata>
<metadata name="hover.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>208, 17</value>
</metadata>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>

View file

@ -24,7 +24,6 @@ namespace PKHeX.WinForms
}
private readonly string[] pfa = GameInfo.Strings.puffs;
private int PuffCount { get; set; }
private void Setup(int rowCount)
{
@ -58,7 +57,6 @@ namespace PKHeX.WinForms
private void LoadPuffs(byte[] Puffs)
{
PuffCount = Puffs.Length;
for (int i = 0; i < Puffs.Length; i++)
{
dgv.Rows[i].Cells[0].Value = (i + 1).ToString();

View file

@ -297,9 +297,16 @@ namespace PKHeX.WinForms
}
catch (Exception x)
{
if (x is UnauthorizedAccessException || x is FileNotFoundException || x is IOException)
switch (x)
{
case UnauthorizedAccessException _:
case FileNotFoundException _:
case IOException _:
Error(MsgFileWriteFail + Environment.NewLine + x.Message, MsgFileWriteProtectedAdvice);
else throw;
break;
default:
throw;
}
}
}

View file

@ -46,15 +46,15 @@ namespace PKHeX.Tests.PKM
CheckStringGetSet(nameof(pkm.Nickname), name_nidoran, pkm.Nickname, byte_nidoran, pkm.Nickname_Trash);
}
private static void CheckStringGetSet(string check, string instr, string outstr, byte[] indata, byte[] outdata)
private static void CheckStringGetSet(string check, string instr, string outstr, byte[] indata,
byte[] outdata)
{
Assert.Equal(instr, outstr);
instr.Should().BeEquivalentTo(outstr);
outdata = outdata.Take(indata.Length).ToArray();
Assert.True(indata.SequenceEqual(outdata),
$"{check} did not set properly."
+ Environment.NewLine + string.Join(", ", outdata.Select(z => $"{z:X2}")));
indata.SequenceEqual(outdata).Should()
.BeTrue($"expected {check} to set properly, instead got {string.Join(", ", outdata.Select(z => $"{z:X2}"))}");
}
}