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); } foreach (PKM pkm in Results) { File.WriteAllBytes(Path.Combine(path, Util.CleanFileName(pkm.FileName)), pkm.DecryptedBoxData); } }
private void pbBoxSlot_MouseDown(object sender, MouseEventArgs e) { if (ModifierKeys == Keys.Control || ModifierKeys == Keys.Alt || ModifierKeys == Keys.Shift || ModifierKeys == (Keys.Control | Keys.Alt)) { switch (ModifierKeys) { case Keys.Control: clickView(sender, e); break; case Keys.Shift: clickSet(sender, e); break; case Keys.Alt: clickDelete(sender, e); break; } return; } PictureBox pb = (PictureBox)(sender); if (pb.Image == null) { return; } if (e.Button != MouseButtons.Left || e.Clicks != 1) { return; } int index = Array.FindIndex(pba, p => p.Name == (sender as PictureBox).Name); wc_slot = index; // Create Temp File to Drag Cursor.Current = Cursors.Hand; // Prepare Data byte[] dragdata = sav.Skip(Main.SAV.WondercardData + WC6.Size * index).Take(WC6.Size).ToArray(); WC6 card = new WC6(dragdata); string filename = Util.CleanFileName(card.CardID.ToString("0000") + " - " + card.CardTitle + ".wc6"); // Make File string newfile = Path.Combine(Path.GetTempPath(), Util.CleanFileName(filename)); try { File.WriteAllBytes(newfile, dragdata); DoDragDrop(new DataObject(DataFormats.FileDrop, new[] { newfile }), DragDropEffects.Move); } catch (ArgumentException x) { Util.Error("Drag & Drop Error:", x.ToString()); } File.Delete(newfile); wc_slot = -1; }
private void clickSet(object sender, EventArgs e) { // Don't care what slot was clicked, just add it to the database if (!m_parent.verifiedPKX()) { return; } PK6 pk = m_parent.preparepkx(); 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; } File.WriteAllBytes(path, pk.Data.Take(PK6.SIZE_STORED).ToArray()); pk.Identifier = path; int pre = RawDB.Count; RawDB.Add(pk); RawDB = new List <PK6>(RawDB.Distinct()); // just in case int post = RawDB.Count; if (pre == post) { Util.Alert("Pokémon already exists in database."); return; } Results.Add(pk); // Refresh database view. L_Count.Text = string.Format(Counter, Results.Count); slotSelected = Results.Count - 1; slotColor = Properties.Resources.slotSet; if ((SCR_Box.Maximum + 1) * 6 < Results.Count) { SCR_Box.Maximum += 1; } SCR_Box.Value = Math.Max(0, SCR_Box.Maximum - PKXBOXES.Length / 6 + 1); FillPKXBoxes(SCR_Box.Value); Util.Alert("Added Pokémon from tabs to database."); }
private void pbBoxSlot_MouseDown(object sender, MouseEventArgs e) { if (ModifierKeys == Keys.Control || ModifierKeys == Keys.Alt || ModifierKeys == Keys.Shift || ModifierKeys == (Keys.Control | Keys.Alt)) { switch (ModifierKeys) { case Keys.Control: clickView(sender, e); break; case Keys.Shift: clickSet(sender, e); break; case Keys.Alt: clickDelete(sender, e); break; } return; } PictureBox pb = (PictureBox)sender; if (pb.Image == null) { return; } if (e.Button != MouseButtons.Left || e.Clicks != 1) { return; } int index = Array.IndexOf(pba, sender); wc_slot = index; // Create Temp File to Drag Cursor.Current = Cursors.Hand; // Prepare Data WC6 card = SAV.getWC6(index); string filename = Util.CleanFileName($"{card.CardID.ToString("0000")} - {card.CardTitle}.wc6"); // Make File string newfile = Path.Combine(Path.GetTempPath(), Util.CleanFileName(filename)); try { File.WriteAllBytes(newfile, card.Data); DoDragDrop(new DataObject(DataFormats.FileDrop, new[] { newfile }), DragDropEffects.Move); } catch (ArgumentException x) { Util.Error("Drag & Drop Error:", x.ToString()); } File.Delete(newfile); wc_slot = -1; }
private void B_Output_Click(object sender, EventArgs e) { SaveFileDialog outputwc6 = new SaveFileDialog { Filter = getFilter(), FileName = Util.CleanFileName($"{mg.CardID} - {mg.CardTitle}{mg.Extension}") }; if (outputwc6.ShowDialog() != DialogResult.OK) return; string path = outputwc6.FileName; if (File.Exists(path)) // File already exists, save a .bak File.WriteAllBytes(path + ".bak", File.ReadAllBytes(path)); File.WriteAllBytes(path, mg.Data); }
private void pbBoxSlot_MouseDown(object sender, MouseEventArgs e) { switch (ModifierKeys) { case Keys.Control: clickView(sender, e); return; case Keys.Shift: clickSet(sender, e); return; case Keys.Alt: clickDelete(sender, e); return; } PictureBox pb = sender as PictureBox; if (pb?.Image == null) { return; } if (e.Button != MouseButtons.Left || e.Clicks != 1) { return; } int index = Array.IndexOf(pba, sender); wc_slot = index; // Create Temp File to Drag Cursor.Current = Cursors.Hand; // Prepare Data MysteryGift card = mga.Gifts[index]; string filename = Util.CleanFileName($"{card.CardID:0000} - {card.CardTitle}.wc6"); // Make File string newfile = Path.Combine(Path.GetTempPath(), Util.CleanFileName(filename)); try { File.WriteAllBytes(newfile, card.Data); DoDragDrop(new DataObject(DataFormats.FileDrop, new[] { newfile }), DragDropEffects.Move); } catch (Exception x) { Util.Error("Drag & Drop Error", x); } File.Delete(newfile); wc_slot = -1; }
private void B_Output_Click(object sender, EventArgs e) { SaveFileDialog outputwc6 = new SaveFileDialog(); int cardID = wc6.CardID; string cardname = wc6.CardTitle; outputwc6.FileName = Util.CleanFileName($"{cardID} - {cardname}.wc6"); outputwc6.Filter = "Wonder Card|*.wc6"; if (outputwc6.ShowDialog() != DialogResult.OK) { return; } string path = outputwc6.FileName; if (File.Exists(path)) // File already exists, save a .bak { File.WriteAllBytes(path + ".bak", File.ReadAllBytes(path)); } File.WriteAllBytes(path, wc6.Data); }
private void B_Output_Click(object sender, EventArgs e) { SaveFileDialog outputwc6 = new SaveFileDialog(); int cardID = BitConverter.ToUInt16(wondercard_data, 0); string cardname = Encoding.Unicode.GetString(wondercard_data, 0x2, 0x48); outputwc6.FileName = Util.CleanFileName($"{cardID} - {cardname}.wc6"); outputwc6.Filter = "Wonder Card|*.wc6"; if (outputwc6.ShowDialog() != DialogResult.OK) { return; } string path = outputwc6.FileName; if (File.Exists(path)) // File already exists, save a .bak { File.WriteAllBytes(path + ".bak", File.ReadAllBytes(path)); } File.WriteAllBytes(path, wondercard_data); }
private void pbBoxSlot_MouseMove(object sender, MouseEventArgs e) { if (DragInfo.slotDragDropInProgress) { return; } if (DragInfo.slotLeftMouseIsDown) { // The goal is to create a temporary PKX file for the underlying Pokemon // and use that file to perform a drag drop operation. // Abort if there is no Pokemon in the given slot. PictureBox pb = (PictureBox)sender; if (pb.Image == null) { return; } int slot = getSlot(pb); int box = slot >= 30 ? -1 : CB_BoxSelect.SelectedIndex; if (SAV.getIsSlotLocked(box, slot)) { return; } // Set flag to prevent re-entering. DragInfo.slotDragDropInProgress = true; DragInfo.slotSource = this; DragInfo.slotSourceSlotNumber = slot; DragInfo.slotSourceBoxNumber = box; DragInfo.slotSourceOffset = getPKXOffset(DragInfo.slotSourceSlotNumber); // Prepare Data DragInfo.slotPkmSource = SAV.getData(DragInfo.slotSourceOffset, SAV.SIZE_STORED); // Make a new file name based off the PID byte[] dragdata = SAV.decryptPKM(DragInfo.slotPkmSource); Array.Resize(ref dragdata, SAV.SIZE_STORED); PKM pkx = SAV.getPKM(dragdata); string filename = pkx.FileName; // Make File string newfile = Path.Combine(Path.GetTempPath(), Util.CleanFileName(filename)); try { File.WriteAllBytes(newfile, dragdata); var img = (Bitmap)pb.Image; DragInfo.Cursor = Cursor.Current = new Cursor(img.GetHicon()); pb.Image = null; pb.BackgroundImage = Properties.Resources.slotDrag; // Thread Blocks on DoDragDrop DragInfo.CurrentPath = newfile; DragDropEffects result = pb.DoDragDrop(new DataObject(DataFormats.FileDrop, new[] { newfile }), DragDropEffects.Move); if (!DragInfo.SourceValid || result != DragDropEffects.Link) // not dropped to another box slot, restore img { pb.Image = img; } else // refresh image { getQuickFiller(pb, SAV.getStoredSlot(DragInfo.slotSourceOffset)); } pb.BackgroundImage = null; if (DragInfo.SameBox && DragInfo.DestinationValid) { SlotPictureBoxes[DragInfo.slotDestinationSlotNumber].Image = img; } } catch (Exception x) { Util.Error("Drag & Drop Error", x); } parent.notifyBoxViewerRefresh(); DragInfo.Reset(); Cursor = DefaultCursor; // Browser apps need time to load data since the file isn't moved to a location on the user's local storage. // Tested 10ms -> too quick, 100ms was fine. 500ms should be safe? new Thread(() => { Thread.Sleep(500); if (File.Exists(newfile) && DragInfo.CurrentPath == null) { File.Delete(newfile); } }).Start(); } }