diff --git a/PKHeX.WinForms/Subforms/SAV_MysteryGiftDB.cs b/PKHeX.WinForms/Subforms/SAV_MysteryGiftDB.cs
index 6eb771e15..342a4261f 100644
--- a/PKHeX.WinForms/Subforms/SAV_MysteryGiftDB.cs
+++ b/PKHeX.WinForms/Subforms/SAV_MysteryGiftDB.cs
@@ -62,12 +62,16 @@ public SAV_MysteryGiftDB(Main f1)
ContextMenuStrip mnu = new ContextMenuStrip();
ToolStripMenuItem mnuView = new ToolStripMenuItem("View");
+ ToolStripMenuItem mnuSaveMG = new ToolStripMenuItem("Save Gift");
+ ToolStripMenuItem mnuSavePK = new ToolStripMenuItem("Save PKM");
// Assign event handlers
mnuView.Click += clickView;
+ mnuSaveMG.Click += clickSaveMG;
+ mnuSavePK.Click += clickSavePK;
// Add to main context menu
- mnu.Items.AddRange(new ToolStripItem[] { mnuView });
+ mnu.Items.AddRange(new ToolStripItem[] { mnuView, mnuSaveMG, mnuSavePK });
// Assign to datagridview
foreach (PictureBox p in PKXBOXES)
@@ -110,26 +114,44 @@ public SAV_MysteryGiftDB(Main f1)
// Important Events
private void clickView(object sender, EventArgs e)
{
- sender = ((sender as ToolStripItem)?.Owner as ContextMenuStrip)?.SourceControl ?? sender as PictureBox;
- int index = Array.IndexOf(PKXBOXES, sender);
- if (index >= RES_MAX)
- {
- System.Media.SystemSounds.Exclamation.Play();
- return;
- }
- index += SCR_Box.Value*RES_MIN;
- if (index >= Results.Count)
- {
- System.Media.SystemSounds.Exclamation.Play();
- return;
- }
-
+ int index = getSenderIndex(sender);
m_parent.populateFields(Results[index].convertToPKM(Main.SAV), false);
slotSelected = index;
slotColor = Properties.Resources.slotView;
FillPKXBoxes(SCR_Box.Value);
L_Viewed.Text = string.Format(Viewed, Results[index].FileName);
}
+ private void clickSavePK(object sender, EventArgs e)
+ {
+ int index = getSenderIndex(sender);
+ var gift = Results[index];
+ var pk = gift.convertToPKM(Main.SAV);
+ WinFormsUtil.SavePKMDialog(pk);
+ }
+ private void clickSaveMG(object sender, EventArgs e)
+ {
+ int index = getSenderIndex(sender);
+ var gift = Results[index];
+ WinFormsUtil.SaveMGDialog(gift);
+ }
+
+ private int getSenderIndex(object sender)
+ {
+ sender = ((sender as ToolStripItem)?.Owner as ContextMenuStrip)?.SourceControl ?? sender as PictureBox;
+ int index = Array.IndexOf(PKXBOXES, sender);
+ if (index >= RES_MAX)
+ {
+ System.Media.SystemSounds.Exclamation.Play();
+ return -1;
+ }
+ index += SCR_Box.Value*RES_MIN;
+ if (index >= Results.Count)
+ {
+ System.Media.SystemSounds.Exclamation.Play();
+ return -1;
+ }
+ return index;
+ }
private void populateComboBoxes()
{
// Set the Text
diff --git a/PKHeX.WinForms/Subforms/Save Editors/SAV_Wondercard.cs b/PKHeX.WinForms/Subforms/Save Editors/SAV_Wondercard.cs
index 900585d0b..69ef83790 100644
--- a/PKHeX.WinForms/Subforms/Save Editors/SAV_Wondercard.cs
+++ b/PKHeX.WinForms/Subforms/Save Editors/SAV_Wondercard.cs
@@ -115,25 +115,9 @@ private void setCardID(int cardID)
}
// Mystery Gift IO (.file<->window)
- private string getFilter()
- {
- switch (SAV.Generation)
- {
- case 4:
- return "Gen4 Mystery Gift|*.pgt;*.pcd|All Files|*.*";
- case 5:
- return "Gen5 Mystery Gift|*.pgf|All Files|*.*";
- case 6:
- return "Gen6 Mystery Gift|*.wc6;*.wc6full|All Files|*.*";
- case 7:
- return "Gen7 Mystery Gift|*.wc7;*.wc7full|All Files|*.*";
- default:
- return "";
- }
- }
private void B_Import_Click(object sender, EventArgs e)
{
- OpenFileDialog import = new OpenFileDialog {Filter = getFilter()};
+ OpenFileDialog import = new OpenFileDialog {Filter = WinFormsUtil.getMysterGiftFilter(SAV.Generation)};
if (import.ShowDialog() != DialogResult.OK) return;
string path = import.FileName;
@@ -147,27 +131,7 @@ private void B_Import_Click(object sender, EventArgs e)
}
private void B_Output_Click(object sender, EventArgs e)
{
- SaveFileDialog outputwc6 = new SaveFileDialog
- {
- Filter = getFilter(),
- FileName = Util.CleanFileName(mg.FileName)
- };
- if (outputwc6.ShowDialog() != DialogResult.OK) return;
-
- string path = outputwc6.FileName;
-
- if (File.Exists(path))
- {
- // File already exists, save a .bak
- string bakpath = path + ".bak";
- if (!File.Exists(bakpath))
- {
- byte[] backupfile = File.ReadAllBytes(path);
- File.WriteAllBytes(bakpath, backupfile);
- }
- }
-
- File.WriteAllBytes(path, mg.Data);
+ WinFormsUtil.SaveMGDialog(mg);
}
private int getLastUnfilledByType(MysteryGift Gift, MysteryGiftAlbum Album)
diff --git a/PKHeX.WinForms/Util/WinFormsUtil.cs b/PKHeX.WinForms/Util/WinFormsUtil.cs
index b36ddf487..457440e40 100644
--- a/PKHeX.WinForms/Util/WinFormsUtil.cs
+++ b/PKHeX.WinForms/Util/WinFormsUtil.cs
@@ -321,5 +321,53 @@ public static bool SaveSAVDialog(SaveFile SAV, int CurrentBox = 0)
}
return true;
}
+ ///
+ /// Opens a dialog to save a file.
+ ///
+ /// to be saved.
+ /// Result of whether or not the file was saved.
+ public static bool SaveMGDialog(MysteryGift gift)
+ {
+ SaveFileDialog output = new SaveFileDialog
+ {
+ Filter = getMysterGiftFilter(gift.Format),
+ FileName = Util.CleanFileName(gift.FileName)
+ };
+ if (output.ShowDialog() != DialogResult.OK)
+ return false;
+
+ string path = output.FileName;
+
+ if (File.Exists(path))
+ {
+ // File already exists, save a .bak
+ string bakpath = path + ".bak";
+ if (!File.Exists(bakpath))
+ {
+ byte[] backupfile = File.ReadAllBytes(path);
+ File.WriteAllBytes(bakpath, backupfile);
+ }
+ }
+
+ File.WriteAllBytes(path, gift.Data);
+ return true;
+ }
+
+ public static string getMysterGiftFilter(int Format)
+ {
+ switch (Format)
+ {
+ case 4:
+ return "Gen4 Mystery Gift|*.pgt;*.pcd|All Files|*.*";
+ case 5:
+ return "Gen5 Mystery Gift|*.pgf|All Files|*.*";
+ case 6:
+ return "Gen6 Mystery Gift|*.wc6;*.wc6full|All Files|*.*";
+ case 7:
+ return "Gen7 Mystery Gift|*.wc7;*.wc7full|All Files|*.*";
+ default:
+ return "";
+ }
+ }
}
}