2015-10-06 01:51:52 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Diagnostics;
|
2015-12-20 00:29:44 +00:00
|
|
|
|
using System.Drawing;
|
2015-10-06 01:51:52 +00:00
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
namespace PKHeX
|
|
|
|
|
{
|
|
|
|
|
public partial class SAV_Database : Form
|
|
|
|
|
{
|
|
|
|
|
public SAV_Database(Main f1)
|
|
|
|
|
{
|
|
|
|
|
m_parent = f1;
|
|
|
|
|
InitializeComponent();
|
2016-07-10 17:33:01 +00:00
|
|
|
|
|
|
|
|
|
// Preset Filters to only show PKM available for loaded save
|
|
|
|
|
CB_FormatComparator.SelectedIndex = 3; // <=
|
|
|
|
|
|
2015-10-08 03:19:34 +00:00
|
|
|
|
PKXBOXES = new[]
|
|
|
|
|
{
|
|
|
|
|
bpkx1, bpkx2, bpkx3, bpkx4, bpkx5, bpkx6,
|
|
|
|
|
bpkx7, bpkx8, bpkx9, bpkx10,bpkx11,bpkx12,
|
|
|
|
|
bpkx13,bpkx14,bpkx15,bpkx16,bpkx17,bpkx18,
|
|
|
|
|
bpkx19,bpkx20,bpkx21,bpkx22,bpkx23,bpkx24,
|
|
|
|
|
bpkx25,bpkx26,bpkx27,bpkx28,bpkx29,bpkx30,
|
|
|
|
|
|
|
|
|
|
bpkx31,bpkx32,bpkx33,bpkx34,bpkx35,bpkx36,
|
|
|
|
|
bpkx37,bpkx38,bpkx39,bpkx40,bpkx41,bpkx42,
|
|
|
|
|
bpkx43,bpkx44,bpkx45,bpkx46,bpkx47,bpkx48,
|
|
|
|
|
bpkx49,bpkx50,bpkx51,bpkx52,bpkx53,bpkx54,
|
|
|
|
|
bpkx55,bpkx56,bpkx57,bpkx58,bpkx59,bpkx60,
|
|
|
|
|
bpkx61,bpkx62,bpkx63,bpkx64,bpkx65,bpkx66,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Enable Scrolling when hovered over
|
2016-01-17 21:27:24 +00:00
|
|
|
|
PAN_Box.MouseHover += (sender, args) =>
|
2015-10-08 03:19:34 +00:00
|
|
|
|
{
|
2016-02-01 07:15:54 +00:00
|
|
|
|
if (ActiveForm == this)
|
2015-10-08 03:19:34 +00:00
|
|
|
|
SCR_Box.Focus();
|
|
|
|
|
};
|
|
|
|
|
foreach (var slot in PKXBOXES)
|
|
|
|
|
{
|
|
|
|
|
slot.MouseEnter += (sender, args) =>
|
|
|
|
|
{
|
2016-02-01 07:15:54 +00:00
|
|
|
|
if (ActiveForm == this)
|
2015-10-08 03:19:34 +00:00
|
|
|
|
SCR_Box.Focus();
|
|
|
|
|
};
|
|
|
|
|
// Enable Click
|
|
|
|
|
slot.MouseClick += (sender, args) =>
|
|
|
|
|
{
|
|
|
|
|
if (ModifierKeys == Keys.Control)
|
|
|
|
|
clickView(sender, args);
|
2015-11-15 03:41:39 +00:00
|
|
|
|
else if (ModifierKeys == Keys.Alt)
|
|
|
|
|
clickDelete(sender, args);
|
|
|
|
|
else if (ModifierKeys == Keys.Shift)
|
|
|
|
|
clickSet(sender, args);
|
2015-10-08 03:19:34 +00:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Counter = L_Count.Text;
|
2015-10-12 07:10:40 +00:00
|
|
|
|
Viewed = L_Viewed.Text;
|
|
|
|
|
L_Viewed.Text = ""; // invis for now
|
2015-10-08 03:19:34 +00:00
|
|
|
|
populateComboBoxes();
|
|
|
|
|
|
|
|
|
|
ContextMenuStrip mnu = new ContextMenuStrip();
|
|
|
|
|
ToolStripMenuItem mnuView = new ToolStripMenuItem("View");
|
2015-11-15 02:17:54 +00:00
|
|
|
|
ToolStripMenuItem mnuDelete = new ToolStripMenuItem("Delete");
|
2015-10-08 03:19:34 +00:00
|
|
|
|
|
|
|
|
|
// Assign event handlers
|
|
|
|
|
mnuView.Click += clickView;
|
2015-11-15 02:17:54 +00:00
|
|
|
|
mnuDelete.Click += clickDelete;
|
2015-10-08 03:19:34 +00:00
|
|
|
|
|
|
|
|
|
// Add to main context menu
|
2015-11-15 02:17:54 +00:00
|
|
|
|
mnu.Items.AddRange(new ToolStripItem[] { mnuView, mnuDelete });
|
2015-10-08 03:19:34 +00:00
|
|
|
|
|
|
|
|
|
// Assign to datagridview
|
|
|
|
|
foreach (PictureBox p in PKXBOXES)
|
|
|
|
|
p.ContextMenuStrip = mnu;
|
2015-10-06 01:51:52 +00:00
|
|
|
|
|
2016-08-03 00:40:20 +00:00
|
|
|
|
// Load Data
|
|
|
|
|
RawDB = new List<PKM>();
|
2015-10-10 17:02:32 +00:00
|
|
|
|
foreach (string file in Directory.GetFiles(DatabasePath, "*", SearchOption.AllDirectories))
|
2015-10-06 01:51:52 +00:00
|
|
|
|
{
|
2016-06-20 04:22:43 +00:00
|
|
|
|
FileInfo fi = new FileInfo(file);
|
|
|
|
|
if (fi.Extension.Contains(".pk") && PKX.getIsPKM(fi.Length))
|
2016-08-03 00:40:20 +00:00
|
|
|
|
RawDB.Add(PKMConverter.getPKMfromBytes(File.ReadAllBytes(file), file));
|
2015-10-06 01:51:52 +00:00
|
|
|
|
}
|
2015-10-10 17:02:32 +00:00
|
|
|
|
// Fetch from save file
|
2016-06-28 05:20:31 +00:00
|
|
|
|
foreach (var pkm in Main.SAV.BoxData.Where(pk => pk.Species != 0))
|
2016-08-03 00:40:20 +00:00
|
|
|
|
RawDB.Add(pkm);
|
2015-10-06 01:51:52 +00:00
|
|
|
|
|
2015-10-08 03:19:34 +00:00
|
|
|
|
// Prepare Database
|
2016-08-03 00:40:20 +00:00
|
|
|
|
RawDB = new List<PKM>(RawDB.Where(pk => pk.ChecksumValid && pk.Species != 0 && pk.Sanity == 0));
|
|
|
|
|
RawDB = new List<PKM>(RawDB.Distinct());
|
|
|
|
|
setResults(RawDB);
|
|
|
|
|
|
2016-03-23 03:30:48 +00:00
|
|
|
|
Menu_SearchSettings.DropDown.Closing += (sender, e) =>
|
2016-03-23 03:14:11 +00:00
|
|
|
|
{
|
|
|
|
|
if (e.CloseReason == ToolStripDropDownCloseReason.ItemClicked)
|
|
|
|
|
e.Cancel = true;
|
|
|
|
|
};
|
2016-04-15 23:11:46 +00:00
|
|
|
|
CenterToParent();
|
2015-10-06 01:51:52 +00:00
|
|
|
|
}
|
2016-01-17 21:27:24 +00:00
|
|
|
|
private readonly Main m_parent;
|
|
|
|
|
private readonly PictureBox[] PKXBOXES;
|
|
|
|
|
private readonly string DatabasePath = Main.DatabasePath;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
private List<PKM> Results;
|
|
|
|
|
private List<PKM> RawDB;
|
2015-10-10 17:28:24 +00:00
|
|
|
|
private int slotSelected = -1; // = null;
|
2015-12-20 00:29:44 +00:00
|
|
|
|
private Image slotColor;
|
2015-10-10 17:28:24 +00:00
|
|
|
|
private const int RES_MAX = 66;
|
|
|
|
|
private const int RES_MIN = 6;
|
2016-01-17 21:27:24 +00:00
|
|
|
|
private readonly string Counter;
|
|
|
|
|
private readonly string Viewed;
|
2016-06-28 04:16:46 +00:00
|
|
|
|
private const int MAXFORMAT = 6;
|
2015-10-06 01:51:52 +00:00
|
|
|
|
|
2015-10-10 17:28:24 +00:00
|
|
|
|
// Important Events
|
2015-10-08 03:19:34 +00:00
|
|
|
|
private void clickView(object sender, EventArgs e)
|
2015-10-06 01:51:52 +00:00
|
|
|
|
{
|
2016-02-01 07:15:54 +00:00
|
|
|
|
sender = ((sender as ToolStripItem)?.Owner as ContextMenuStrip)?.SourceControl ?? sender as PictureBox;
|
|
|
|
|
int index = Array.IndexOf(PKXBOXES, sender);
|
2015-10-06 01:51:52 +00:00
|
|
|
|
|
2015-10-08 03:19:34 +00:00
|
|
|
|
var dataArr = Results.Skip(SCR_Box.Value * RES_MIN).Take(RES_MAX).ToArray();
|
|
|
|
|
if (index >= dataArr.Length)
|
|
|
|
|
System.Media.SystemSounds.Exclamation.Play();
|
|
|
|
|
else
|
|
|
|
|
{
|
2016-06-20 04:22:43 +00:00
|
|
|
|
m_parent.populateFields(dataArr[index], false);
|
2015-10-08 03:19:34 +00:00
|
|
|
|
slotSelected = index + SCR_Box.Value * RES_MIN;
|
2015-12-20 00:29:44 +00:00
|
|
|
|
slotColor = Properties.Resources.slotView;
|
2015-10-08 03:19:34 +00:00
|
|
|
|
FillPKXBoxes(SCR_Box.Value);
|
2016-02-01 07:15:54 +00:00
|
|
|
|
L_Viewed.Text = string.Format(Viewed, dataArr[index].Identifier);
|
2015-10-08 03:19:34 +00:00
|
|
|
|
}
|
2015-10-06 01:51:52 +00:00
|
|
|
|
}
|
2015-11-15 02:17:54 +00:00
|
|
|
|
private void clickDelete(object sender, EventArgs e)
|
|
|
|
|
{
|
2016-02-01 07:15:54 +00:00
|
|
|
|
sender = ((sender as ToolStripItem)?.Owner as ContextMenuStrip)?.SourceControl ?? sender as PictureBox;
|
|
|
|
|
int index = Array.IndexOf(PKXBOXES, sender);
|
2015-11-15 02:17:54 +00:00
|
|
|
|
|
|
|
|
|
var dataArr = Results.Skip(SCR_Box.Value * RES_MIN).Take(RES_MAX).ToArray();
|
|
|
|
|
if (index >= dataArr.Length)
|
|
|
|
|
System.Media.SystemSounds.Exclamation.Play();
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var pk = dataArr[index];
|
|
|
|
|
string path = pk.Identifier;
|
|
|
|
|
|
|
|
|
|
if (path.Contains(Path.DirectorySeparatorChar))
|
|
|
|
|
{
|
|
|
|
|
// Data from Database: Delete file from disk
|
|
|
|
|
File.Delete(path);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Data from Box: Delete from save file
|
|
|
|
|
string[] split = pk.Identifier.Split(':');
|
|
|
|
|
int box = Convert.ToInt32(split[0].Substring(1)) - 1;
|
|
|
|
|
int slot = Convert.ToInt32(split[1]) - 1;
|
|
|
|
|
int spot = box*30 + slot;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
int offset = Main.SAV.getBoxOffset(0) + spot*Main.SAV.SIZE_STORED;
|
|
|
|
|
PKM pkSAV = Main.SAV.getStoredSlot(offset);
|
2015-11-15 02:17:54 +00:00
|
|
|
|
|
|
|
|
|
if (pkSAV.Data.SequenceEqual(pk.Data))
|
|
|
|
|
{
|
2016-06-20 04:22:43 +00:00
|
|
|
|
Main.SAV.setStoredSlot(Main.SAV.BlankPKM, offset);
|
2015-11-15 02:17:54 +00:00
|
|
|
|
m_parent.setPKXBoxes();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Util.Error("Database slot data does not match save data!", "Don't move Pokémon after initializing the Database, please re-open the Database viewer.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Remove from database.
|
|
|
|
|
RawDB.Remove(pk);
|
|
|
|
|
Results.Remove(pk);
|
|
|
|
|
// Refresh database view.
|
2016-02-01 07:15:54 +00:00
|
|
|
|
L_Count.Text = string.Format(Counter, Results.Count);
|
2015-12-20 00:29:44 +00:00
|
|
|
|
slotSelected = -1;
|
2015-11-15 02:17:54 +00:00
|
|
|
|
FillPKXBoxes(SCR_Box.Value);
|
2015-11-15 03:41:39 +00:00
|
|
|
|
System.Media.SystemSounds.Asterisk.Play();
|
2015-11-15 02:17:54 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2015-11-15 03:41:39 +00:00
|
|
|
|
private void clickSet(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
// Don't care what slot was clicked, just add it to the database
|
2016-06-21 06:02:26 +00:00
|
|
|
|
if (!m_parent.verifiedPKM())
|
2015-11-15 03:41:39 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2016-06-20 04:22:43 +00:00
|
|
|
|
PKM pk = m_parent.preparePKM();
|
2015-11-15 03:41:39 +00:00
|
|
|
|
if (!Directory.Exists(DatabasePath))
|
|
|
|
|
Directory.CreateDirectory(DatabasePath);
|
|
|
|
|
|
|
|
|
|
string path = Path.Combine(DatabasePath, Util.CleanFileName(pk.FileName));
|
|
|
|
|
|
|
|
|
|
if (RawDB.Any(p => p.Identifier == path))
|
|
|
|
|
{
|
|
|
|
|
Util.Alert("File already exists in database!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-20 04:22:43 +00:00
|
|
|
|
File.WriteAllBytes(path, pk.Data.Take(pk.SIZE_STORED).ToArray());
|
2015-11-15 03:41:39 +00:00
|
|
|
|
pk.Identifier = path;
|
|
|
|
|
|
2015-12-20 00:29:44 +00:00
|
|
|
|
int pre = RawDB.Count;
|
2015-11-15 03:41:39 +00:00
|
|
|
|
RawDB.Add(pk);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
RawDB = new List<PKM>(RawDB.Distinct()); // just in case
|
2015-12-20 00:29:44 +00:00
|
|
|
|
int post = RawDB.Count;
|
|
|
|
|
if (pre == post)
|
|
|
|
|
{ Util.Alert("Pokémon already exists in database."); return; }
|
2015-11-15 03:41:39 +00:00
|
|
|
|
Results.Add(pk);
|
2015-12-20 00:29:44 +00:00
|
|
|
|
|
2015-11-15 03:41:39 +00:00
|
|
|
|
// Refresh database view.
|
2016-02-01 07:15:54 +00:00
|
|
|
|
L_Count.Text = string.Format(Counter, Results.Count);
|
2015-12-20 00:29:44 +00:00
|
|
|
|
slotSelected = Results.Count - 1;
|
|
|
|
|
slotColor = Properties.Resources.slotSet;
|
|
|
|
|
if ((SCR_Box.Maximum+1)*6 < Results.Count)
|
|
|
|
|
SCR_Box.Maximum += 1;
|
2015-12-20 00:32:22 +00:00
|
|
|
|
SCR_Box.Value = Math.Max(0, SCR_Box.Maximum - PKXBOXES.Length/6 + 1);
|
2015-11-15 03:41:39 +00:00
|
|
|
|
FillPKXBoxes(SCR_Box.Value);
|
2015-12-20 00:29:44 +00:00
|
|
|
|
Util.Alert("Added Pokémon from tabs to database.");
|
2015-11-15 03:41:39 +00:00
|
|
|
|
}
|
2015-10-08 03:19:34 +00:00
|
|
|
|
private void populateComboBoxes()
|
|
|
|
|
{
|
|
|
|
|
// Set the Text
|
|
|
|
|
CB_HeldItem.DisplayMember =
|
|
|
|
|
CB_Species.DisplayMember =
|
|
|
|
|
CB_Ability.DisplayMember =
|
|
|
|
|
CB_Nature.DisplayMember =
|
|
|
|
|
CB_GameOrigin.DisplayMember =
|
|
|
|
|
CB_HPType.DisplayMember = "Text";
|
2015-10-06 01:51:52 +00:00
|
|
|
|
|
2015-10-08 03:19:34 +00:00
|
|
|
|
// Set the Value
|
|
|
|
|
CB_HeldItem.ValueMember =
|
|
|
|
|
CB_Species.ValueMember =
|
|
|
|
|
CB_Ability.ValueMember =
|
|
|
|
|
CB_Nature.ValueMember =
|
|
|
|
|
CB_GameOrigin.ValueMember =
|
|
|
|
|
CB_HPType.ValueMember = "Value";
|
|
|
|
|
|
2016-07-09 22:34:38 +00:00
|
|
|
|
var Any = new ComboItem {Text = "Any", Value = -1};
|
2015-10-08 03:19:34 +00:00
|
|
|
|
|
2016-07-09 22:34:38 +00:00
|
|
|
|
var DS_Species = new List<ComboItem>(Main.SpeciesDataSource);
|
2015-10-08 03:19:34 +00:00
|
|
|
|
DS_Species.RemoveAt(0); DS_Species.Insert(0, Any); CB_Species.DataSource = DS_Species;
|
|
|
|
|
|
2016-07-09 22:34:38 +00:00
|
|
|
|
var DS_Item = new List<ComboItem>(Main.ItemDataSource);
|
2015-10-08 03:19:34 +00:00
|
|
|
|
DS_Item.Insert(0, Any); CB_HeldItem.DataSource = DS_Item;
|
|
|
|
|
|
2016-07-09 22:34:38 +00:00
|
|
|
|
var DS_Nature = new List<ComboItem>(Main.NatureDataSource);
|
2015-10-08 03:19:34 +00:00
|
|
|
|
DS_Nature.Insert(0, Any); CB_Nature.DataSource = DS_Nature;
|
|
|
|
|
|
2016-07-09 22:34:38 +00:00
|
|
|
|
var DS_Ability = new List<ComboItem>(Main.AbilityDataSource);
|
2015-10-08 03:19:34 +00:00
|
|
|
|
DS_Ability.Insert(0, Any); CB_Ability.DataSource = DS_Ability;
|
|
|
|
|
|
2016-07-09 22:34:38 +00:00
|
|
|
|
var DS_Version = new List<ComboItem>(Main.VersionDataSource);
|
2015-10-08 03:19:34 +00:00
|
|
|
|
DS_Version.Insert(0, Any); CB_GameOrigin.DataSource = DS_Version;
|
|
|
|
|
|
|
|
|
|
string[] hptypes = new string[Main.types.Length - 2]; Array.Copy(Main.types, 1, hptypes, 0, hptypes.Length);
|
|
|
|
|
var DS_Type = Util.getCBList(hptypes, null);
|
|
|
|
|
DS_Type.Insert(0, Any); CB_HPType.DataSource = DS_Type;
|
|
|
|
|
|
|
|
|
|
// Set the Move ComboBoxes too..
|
2016-07-09 22:34:38 +00:00
|
|
|
|
var DS_Move = new List<ComboItem>(Main.MoveDataSource);
|
2015-10-08 03:19:34 +00:00
|
|
|
|
DS_Move.RemoveAt(0); DS_Move.Insert(0, Any);
|
|
|
|
|
{
|
|
|
|
|
foreach (ComboBox cb in new[] { CB_Move1, CB_Move2, CB_Move3, CB_Move4 })
|
|
|
|
|
{
|
|
|
|
|
cb.DisplayMember = "Text"; cb.ValueMember = "Value";
|
|
|
|
|
cb.DataSource = new BindingSource(DS_Move, null);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Trigger a Reset
|
|
|
|
|
resetFilters(null, null);
|
|
|
|
|
}
|
|
|
|
|
private void resetFilters(object sender, EventArgs e)
|
2015-10-06 01:51:52 +00:00
|
|
|
|
{
|
2015-10-08 03:19:34 +00:00
|
|
|
|
CHK_Shiny.Checked = CHK_IsEgg.Checked = true;
|
|
|
|
|
CHK_Shiny.CheckState = CHK_IsEgg.CheckState = CheckState.Indeterminate;
|
|
|
|
|
MT_ESV.Text = "";
|
|
|
|
|
CB_HeldItem.SelectedIndex = 0;
|
|
|
|
|
CB_Species.SelectedIndex = 0;
|
|
|
|
|
CB_Ability.SelectedIndex = 0;
|
|
|
|
|
CB_Nature.SelectedIndex = 0;
|
|
|
|
|
CB_HPType.SelectedIndex = 0;
|
2015-10-06 01:51:52 +00:00
|
|
|
|
|
2015-10-08 03:19:34 +00:00
|
|
|
|
CB_Level.SelectedIndex = 0;
|
|
|
|
|
TB_Level.Text = "";
|
|
|
|
|
CB_EVTrain.SelectedIndex = 0;
|
|
|
|
|
CB_IV.SelectedIndex = 0;
|
2015-10-06 01:51:52 +00:00
|
|
|
|
|
2015-10-08 03:19:34 +00:00
|
|
|
|
CB_Move1.SelectedIndex = CB_Move2.SelectedIndex = CB_Move3.SelectedIndex = CB_Move4.SelectedIndex = 0;
|
|
|
|
|
|
|
|
|
|
CB_GameOrigin.SelectedIndex = 0;
|
2015-10-10 17:28:24 +00:00
|
|
|
|
CB_Generation.SelectedIndex = 0;
|
2015-10-12 07:12:21 +00:00
|
|
|
|
|
|
|
|
|
MT_ESV.Visible = L_ESV.Visible = false;
|
2016-07-23 08:04:55 +00:00
|
|
|
|
RTB_Instructions.Clear();
|
2016-01-18 01:11:32 +00:00
|
|
|
|
|
|
|
|
|
if (sender != null)
|
|
|
|
|
System.Media.SystemSounds.Asterisk.Play();
|
2015-10-06 01:51:52 +00:00
|
|
|
|
}
|
2015-10-11 01:29:02 +00:00
|
|
|
|
private void generateDBReport(object sender, EventArgs e)
|
|
|
|
|
{
|
2016-02-09 23:35:56 +00:00
|
|
|
|
if (Util.Prompt(MessageBoxButtons.YesNo, "Generate a Report on all data?", "This may take a while...")
|
2015-10-11 01:29:02 +00:00
|
|
|
|
!= DialogResult.Yes)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
frmReport ReportForm = new frmReport();
|
|
|
|
|
ReportForm.Show();
|
|
|
|
|
ReportForm.PopulateData(Results.ToArray());
|
|
|
|
|
}
|
2015-10-08 03:19:34 +00:00
|
|
|
|
|
2015-10-10 17:28:24 +00:00
|
|
|
|
// IO Usage
|
2015-10-06 01:51:52 +00:00
|
|
|
|
private void openDB(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (Directory.Exists(DatabasePath))
|
2016-07-17 17:06:52 +00:00
|
|
|
|
Process.Start("explorer.exe", DatabasePath);
|
2015-10-06 01:51:52 +00:00
|
|
|
|
}
|
2015-10-13 00:12:20 +00:00
|
|
|
|
private void Menu_Export_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (Results == null || Results.Count == 0)
|
|
|
|
|
{ Util.Alert("No results to export."); return; }
|
|
|
|
|
|
|
|
|
|
if (DialogResult.Yes != Util.Prompt(MessageBoxButtons.YesNo, "Export to a folder?"))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
FolderBrowserDialog fbd = new FolderBrowserDialog();
|
|
|
|
|
if (DialogResult.OK != fbd.ShowDialog())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
string path = fbd.SelectedPath;
|
|
|
|
|
if (!Directory.Exists(path)) // just in case...
|
|
|
|
|
Directory.CreateDirectory(path);
|
|
|
|
|
|
2016-06-20 04:22:43 +00:00
|
|
|
|
foreach (PKM pkm in Results)
|
2016-08-03 00:40:20 +00:00
|
|
|
|
File.WriteAllBytes(Path.Combine(path, Util.CleanFileName(pkm.FileName)), pkm.DecryptedBoxData);
|
2015-10-13 00:12:20 +00:00
|
|
|
|
}
|
2015-10-08 03:19:34 +00:00
|
|
|
|
|
2015-10-10 17:28:24 +00:00
|
|
|
|
// View Updates
|
2015-10-08 03:19:34 +00:00
|
|
|
|
private void B_Search_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
// Populate Search Query Result
|
2016-06-20 04:22:43 +00:00
|
|
|
|
IEnumerable<PKM> res = RawDB;
|
2015-10-08 03:19:34 +00:00
|
|
|
|
|
2016-06-28 04:16:46 +00:00
|
|
|
|
int format = MAXFORMAT + 1 - CB_Format.SelectedIndex;
|
2016-07-10 17:33:01 +00:00
|
|
|
|
switch (CB_FormatComparator.SelectedIndex)
|
|
|
|
|
{
|
|
|
|
|
case 0: /* Do nothing */ break;
|
|
|
|
|
case 1: res = res.Where(pk => pk.Format >= format); break;
|
|
|
|
|
case 2: res = res.Where(pk => pk.Format == format); break;
|
|
|
|
|
case 3: res = res.Where(pk => pk.Format <= format); break;
|
|
|
|
|
}
|
2016-06-28 04:16:46 +00:00
|
|
|
|
|
|
|
|
|
switch (CB_Generation.SelectedIndex)
|
|
|
|
|
{
|
2016-07-10 17:33:01 +00:00
|
|
|
|
case 0: /* Do nothing */ break;
|
|
|
|
|
case 1: res = res.Where(pk => pk.Gen6); break;
|
|
|
|
|
case 2: res = res.Where(pk => pk.Gen5); break;
|
|
|
|
|
case 3: res = res.Where(pk => pk.Gen4); break;
|
|
|
|
|
case 4: res = res.Where(pk => pk.Gen3); break;
|
2016-06-28 04:16:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-10-08 03:19:34 +00:00
|
|
|
|
// Primary Searchables
|
|
|
|
|
int species = Util.getIndex(CB_Species);
|
|
|
|
|
int ability = Util.getIndex(CB_Ability);
|
|
|
|
|
int nature = Util.getIndex(CB_Nature);
|
|
|
|
|
int item = Util.getIndex(CB_HeldItem);
|
|
|
|
|
if (species != -1) res = res.Where(pk => pk.Species == species);
|
|
|
|
|
if (ability != -1) res = res.Where(pk => pk.Ability == ability);
|
|
|
|
|
if (nature != -1) res = res.Where(pk => pk.Nature == nature);
|
|
|
|
|
if (item != -1) res = res.Where(pk => pk.HeldItem == item);
|
|
|
|
|
|
|
|
|
|
// Secondary Searchables
|
|
|
|
|
int move1 = Util.getIndex(CB_Move1);
|
|
|
|
|
int move2 = Util.getIndex(CB_Move2);
|
|
|
|
|
int move3 = Util.getIndex(CB_Move3);
|
|
|
|
|
int move4 = Util.getIndex(CB_Move4);
|
|
|
|
|
if (move1 != -1) res = res.Where(pk => pk.Moves.Contains(move1));
|
|
|
|
|
if (move2 != -1) res = res.Where(pk => pk.Moves.Contains(move2));
|
|
|
|
|
if (move3 != -1) res = res.Where(pk => pk.Moves.Contains(move3));
|
|
|
|
|
if (move4 != -1) res = res.Where(pk => pk.Moves.Contains(move4));
|
|
|
|
|
int vers = Util.getIndex(CB_GameOrigin);
|
|
|
|
|
if (vers != -1) res = res.Where(pk => pk.Version == vers);
|
|
|
|
|
int hptype = Util.getIndex(CB_HPType);
|
|
|
|
|
if (hptype != -1) res = res.Where(pk => pk.HPType == hptype);
|
|
|
|
|
if (CHK_Shiny.CheckState == CheckState.Checked) res = res.Where(pk => pk.IsShiny);
|
|
|
|
|
if (CHK_Shiny.CheckState == CheckState.Unchecked) res = res.Where(pk => !pk.IsShiny);
|
|
|
|
|
if (CHK_IsEgg.CheckState == CheckState.Checked) res = res.Where(pk => pk.IsEgg);
|
|
|
|
|
if (CHK_IsEgg.CheckState == CheckState.Unchecked) res = res.Where(pk => !pk.IsEgg);
|
|
|
|
|
if (CHK_IsEgg.CheckState == CheckState.Checked && MT_ESV.Text != "")
|
|
|
|
|
res = res.Where(pk => pk.PSV == Convert.ToInt16(MT_ESV.Text));
|
|
|
|
|
|
|
|
|
|
// Tertiary Searchables
|
|
|
|
|
if (TB_Level.Text != "") // Level
|
|
|
|
|
{
|
|
|
|
|
int level = Convert.ToInt16(TB_Level.Text);
|
|
|
|
|
if (level <= 100)
|
|
|
|
|
switch (CB_Level.SelectedIndex)
|
|
|
|
|
{
|
|
|
|
|
case 0: break; // Any
|
|
|
|
|
case 1: // <=
|
|
|
|
|
res = res.Where(pk => pk.Stat_Level <= level);
|
|
|
|
|
break;
|
|
|
|
|
case 2: // ==
|
|
|
|
|
res = res.Where(pk => pk.Stat_Level == level);
|
|
|
|
|
break;
|
|
|
|
|
case 3: // >=
|
|
|
|
|
res = res.Where(pk => pk.Stat_Level >= level);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
switch (CB_IV.SelectedIndex)
|
|
|
|
|
{
|
|
|
|
|
case 0: break; // Do nothing
|
|
|
|
|
case 1: // <= 90
|
|
|
|
|
res = res.Where(pk => pk.IVs.Sum() <= 90);
|
|
|
|
|
break;
|
|
|
|
|
case 2: // 91-120
|
|
|
|
|
res = res.Where(pk => pk.IVs.Sum() > 90 && pk.IVs.Sum() <= 120);
|
|
|
|
|
break;
|
|
|
|
|
case 3: // 121-150
|
|
|
|
|
res = res.Where(pk => pk.IVs.Sum() > 120 && pk.IVs.Sum() <= 150);
|
|
|
|
|
break;
|
|
|
|
|
case 4: // 151-179
|
|
|
|
|
res = res.Where(pk => pk.IVs.Sum() > 150 && pk.IVs.Sum() < 180);
|
|
|
|
|
break;
|
|
|
|
|
case 5: // 180+
|
|
|
|
|
res = res.Where(pk => pk.IVs.Sum() >= 180);
|
|
|
|
|
break;
|
|
|
|
|
case 6: // == 186
|
|
|
|
|
res = res.Where(pk => pk.IVs.Sum() == 186);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
switch (CB_EVTrain.SelectedIndex)
|
|
|
|
|
{
|
|
|
|
|
case 0: break; // Do nothing
|
|
|
|
|
case 1: // None (0)
|
|
|
|
|
res = res.Where(pk => pk.EVs.Sum() == 0);
|
|
|
|
|
break;
|
|
|
|
|
case 2: // Some (127-0)
|
|
|
|
|
res = res.Where(pk => pk.EVs.Sum() < 128);
|
|
|
|
|
break;
|
|
|
|
|
case 3: // Half (128-507)
|
|
|
|
|
res = res.Where(pk => pk.EVs.Sum() >= 128 && pk.EVs.Sum() < 508);
|
|
|
|
|
break;
|
|
|
|
|
case 4: // Full (508+)
|
|
|
|
|
res = res.Where(pk => pk.EVs.Sum() >= 508);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-14 02:31:01 +00:00
|
|
|
|
// Filter for Selected Source
|
|
|
|
|
if (!Menu_SearchBoxes.Checked)
|
|
|
|
|
res = res.Where(pk => pk.Identifier.Contains("db\\"));
|
|
|
|
|
if (!Menu_SearchDatabase.Checked)
|
|
|
|
|
res = res.Where(pk => !pk.Identifier.Contains("db\\"));
|
|
|
|
|
|
2015-10-09 13:34:26 +00:00
|
|
|
|
slotSelected = -1; // reset the slot last viewed
|
2016-03-16 04:10:33 +00:00
|
|
|
|
|
|
|
|
|
if (Menu_SearchLegal.Checked && !Menu_SearchIllegal.Checked) // Legal Only
|
2016-07-17 17:06:52 +00:00
|
|
|
|
res = res.Where(pk => pk.Gen6 && pk is PK6 && new LegalityAnalysis((PK6) pk).Valid);
|
2016-03-16 04:10:33 +00:00
|
|
|
|
if (!Menu_SearchLegal.Checked && Menu_SearchIllegal.Checked) // Illegal Only
|
2016-07-17 17:06:52 +00:00
|
|
|
|
res = res.Where(pk => pk.Gen6 && pk is PK6 && !new LegalityAnalysis((PK6) pk).Valid);
|
2016-03-16 04:10:33 +00:00
|
|
|
|
|
2016-07-23 08:04:55 +00:00
|
|
|
|
if (RTB_Instructions.Lines.Any(line => line.Length > 0))
|
|
|
|
|
{
|
|
|
|
|
var raw =
|
|
|
|
|
RTB_Instructions.Lines
|
|
|
|
|
.Where(line => !string.IsNullOrWhiteSpace(line))
|
|
|
|
|
.Where(line => new[] { '!', '=' }.Contains(line[0]));
|
|
|
|
|
|
|
|
|
|
var filters = (from line in raw
|
|
|
|
|
let eval = line[0] == '='
|
|
|
|
|
let split = line.Substring(1).Split('=')
|
|
|
|
|
where split.Length == 2 && !string.IsNullOrWhiteSpace(split[0])
|
|
|
|
|
select new BatchEditor.StringInstruction { PropertyName = split[0], PropertyValue = split[1], Evaluator = eval }).ToArray();
|
|
|
|
|
|
|
|
|
|
if (filters.Any(z => string.IsNullOrWhiteSpace(z.PropertyValue)))
|
|
|
|
|
{ Util.Error("Empty Filter Value detected."); return; }
|
|
|
|
|
|
|
|
|
|
res = res.Where(pkm => // Compare across all filters
|
|
|
|
|
{
|
|
|
|
|
foreach (var cmd in filters)
|
|
|
|
|
{
|
|
|
|
|
if (!pkm.GetType().HasProperty(cmd.PropertyName))
|
|
|
|
|
return false;
|
|
|
|
|
try { if (ReflectUtil.GetValueEquals(pkm, cmd.PropertyName, cmd.PropertyValue) == cmd.Evaluator) continue; }
|
|
|
|
|
catch { Console.WriteLine($"Unable to compare {cmd.PropertyName} to {cmd.PropertyValue}."); }
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-08 03:19:34 +00:00
|
|
|
|
var results = res.ToArray();
|
|
|
|
|
if (results.Length == 0)
|
2015-11-14 02:31:01 +00:00
|
|
|
|
{
|
|
|
|
|
if (!Menu_SearchBoxes.Checked && !Menu_SearchDatabase.Checked)
|
|
|
|
|
Util.Alert("No data source to search!", "No results found!");
|
|
|
|
|
else
|
|
|
|
|
Util.Alert("No results found!");
|
|
|
|
|
}
|
2016-06-20 04:22:43 +00:00
|
|
|
|
setResults(new List<PKM>(results)); // updates Count Label as well.
|
2015-10-08 03:19:34 +00:00
|
|
|
|
System.Media.SystemSounds.Asterisk.Play();
|
|
|
|
|
}
|
|
|
|
|
private void updateScroll(object sender, ScrollEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.OldValue != e.NewValue)
|
|
|
|
|
FillPKXBoxes(e.NewValue);
|
|
|
|
|
}
|
2016-06-20 04:22:43 +00:00
|
|
|
|
private void setResults(List<PKM> res)
|
2015-10-10 17:28:24 +00:00
|
|
|
|
{
|
2016-06-20 04:22:43 +00:00
|
|
|
|
Results = new List<PKM>(res);
|
2015-10-08 03:19:34 +00:00
|
|
|
|
|
2015-10-10 17:28:24 +00:00
|
|
|
|
SCR_Box.Maximum = (int)Math.Ceiling((decimal)Results.Count / RES_MIN);
|
|
|
|
|
if (SCR_Box.Maximum > 0) SCR_Box.Maximum -= 1;
|
|
|
|
|
|
|
|
|
|
SCR_Box.Value = 0;
|
|
|
|
|
FillPKXBoxes(0);
|
|
|
|
|
|
2016-02-01 07:15:54 +00:00
|
|
|
|
L_Count.Text = string.Format(Counter, Results.Count);
|
2015-10-10 17:28:24 +00:00
|
|
|
|
}
|
2015-10-08 03:19:34 +00:00
|
|
|
|
private void FillPKXBoxes(int start)
|
|
|
|
|
{
|
|
|
|
|
if (Results == null)
|
|
|
|
|
for (int i = 0; i < RES_MAX; i++)
|
|
|
|
|
PKXBOXES[i].Image = null;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
PKM[] data = Results.Skip(start * RES_MIN).Take(RES_MAX).ToArray();
|
2015-10-08 03:19:34 +00:00
|
|
|
|
for (int i = 0; i < data.Length; i++)
|
|
|
|
|
PKXBOXES[i].Image = data[i].Sprite;
|
|
|
|
|
for (int i = data.Length; i < RES_MAX; i++)
|
|
|
|
|
PKXBOXES[i].Image = null;
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < RES_MAX; i++)
|
2015-12-20 00:29:44 +00:00
|
|
|
|
PKXBOXES[i].BackgroundImage = Properties.Resources.slotTrans;
|
2015-10-08 03:19:34 +00:00
|
|
|
|
if (slotSelected != -1 && slotSelected >= RES_MIN * start && slotSelected < RES_MIN * start + RES_MAX)
|
2015-12-20 00:29:44 +00:00
|
|
|
|
PKXBOXES[slotSelected - start * RES_MIN].BackgroundImage = slotColor ?? Properties.Resources.slotView;
|
2015-10-08 03:19:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Misc Update Methods
|
|
|
|
|
private void toggleESV(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
L_ESV.Visible = MT_ESV.Visible = CHK_IsEgg.CheckState == CheckState.Checked;
|
|
|
|
|
}
|
|
|
|
|
private void changeLevel(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (CB_Level.SelectedIndex == 0)
|
|
|
|
|
TB_Level.Text = "";
|
|
|
|
|
}
|
2015-10-10 17:18:55 +00:00
|
|
|
|
private void changeGame(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (CB_GameOrigin.SelectedIndex != 0)
|
|
|
|
|
CB_Generation.SelectedIndex = 0;
|
|
|
|
|
}
|
|
|
|
|
private void changeGeneration(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (CB_Generation.SelectedIndex != 0)
|
|
|
|
|
CB_GameOrigin.SelectedIndex = 0;
|
|
|
|
|
}
|
2015-10-08 03:19:34 +00:00
|
|
|
|
|
2016-07-23 08:04:55 +00:00
|
|
|
|
private void Menu_SearchAdvanced_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (!Menu_SearchAdvanced.Checked)
|
|
|
|
|
{ Size = MinimumSize; RTB_Instructions.Clear(); }
|
|
|
|
|
else Size = MaximumSize;
|
|
|
|
|
}
|
2015-11-14 03:04:42 +00:00
|
|
|
|
|
|
|
|
|
private void Menu_Exit_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Close();
|
|
|
|
|
}
|
2016-03-19 02:33:09 +00:00
|
|
|
|
protected override void OnMouseWheel(MouseEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (!PAN_Box.RectangleToScreen(PAN_Box.ClientRectangle).Contains(MousePosition))
|
|
|
|
|
return;
|
|
|
|
|
int oldval = SCR_Box.Value;
|
|
|
|
|
int newval = oldval + (e.Delta < 0 ? 1 : -1);
|
|
|
|
|
if (newval >= SCR_Box.Minimum && SCR_Box.Maximum >= newval)
|
|
|
|
|
FillPKXBoxes(SCR_Box.Value = newval);
|
|
|
|
|
}
|
2016-07-10 17:33:01 +00:00
|
|
|
|
|
|
|
|
|
private void changeFormatFilter(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (CB_FormatComparator.SelectedIndex == 0)
|
|
|
|
|
{
|
|
|
|
|
CB_Format.Visible = false; // !any
|
|
|
|
|
CB_Format.SelectedIndex = 0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
CB_Format.Visible = true;
|
|
|
|
|
CB_Format.SelectedIndex = MAXFORMAT - Main.SAV.Generation + 1; // SAV generation (offset by 1 for "Any")
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-10-06 01:51:52 +00:00
|
|
|
|
}
|
|
|
|
|
}
|