private string CreateDragDropPKM(PictureBox pb, bool encrypt, out bool external) { byte[] dragdata = SAV.DecryptPKM(DragInfo.Source.OriginalData); Array.Resize(ref dragdata, SAV.SIZE_STORED); PKM pkx = SAV.GetPKM(dragdata); string fn = pkx.FileName; fn = fn.Substring(0, fn.LastIndexOf('.')); string filename = fn + (encrypt ? $".ek{pkx.Format}" : $".{pkx.Extension}"); // Make File string newfile = Path.Combine(Path.GetTempPath(), Util.CleanFileName(filename)); try { TryMakeDragDropPKM(pb, encrypt, pkx, newfile, out external); } catch (Exception x) { WinFormsUtil.Error("Drag & Drop Error", x); external = false; } return(newfile); }
private static void ImportSelectBlock(SCBlock blockTarget) { var key = blockTarget.Key; var data = blockTarget.Data; using var ofd = new OpenFileDialog { FileName = $"{key:X8}.bin" }; if (ofd.ShowDialog() != DialogResult.OK) { return; } var path = ofd.FileName; var file = new FileInfo(path); if (file.Length != data.Length) { WinFormsUtil.Error(string.Format(MessageStrings.MsgFileSize, $"0x{file.Length:X8}")); return; } var bytes = File.ReadAllBytes(path); bytes.CopyTo(data, 0); }
public SAV_Database(PKMEditor f1, SAVEditor saveditor) { InitializeComponent(); WinFormsUtil.TranslateInterface(this, Main.CurrentLanguage); SAV = saveditor.SAV; BoxView = saveditor; PKME_Tabs = f1; // Preset Filters to only show PKM available for loaded save CB_FormatComparator.SelectedIndex = 3; // <= var grid = DatabasePokeGrid; var smallWidth = grid.Width; var smallHeight = grid.Height; grid.InitializeGrid(6, 11, SpriteUtil.Spriter); grid.SetBackground(Resources.box_wp_clean); var newWidth = grid.Width; var newHeight = grid.Height; var wdelta = newWidth - smallWidth; if (wdelta != 0) { Width += wdelta; } var hdelta = newHeight - smallHeight; if (hdelta != 0) { Height += hdelta; } PKXBOXES = grid.Entries.ToArray(); // Enable Scrolling when hovered over foreach (var slot in PKXBOXES) { // Enable Click slot.MouseClick += (sender, e) => { if (sender == null) { return; } switch (ModifierKeys) { case Keys.Control: ClickView(sender, e); break; case Keys.Alt: ClickDelete(sender, e); break; case Keys.Shift: ClickSet(sender, e); break; } }; slot.ContextMenuStrip = mnu; if (Main.Settings.Hover.HoverSlotShowText) { slot.MouseEnter += (o, args) => ShowHoverTextForSlot(slot, args); } } Counter = L_Count.Text; Viewed = L_Viewed.Text; L_Viewed.Text = string.Empty; // invisible for now PopulateComboBoxes(); // Load Data B_Search.Enabled = false; L_Count.Text = "Loading..."; var task = new Task(LoadDatabase); task.ContinueWith(z => { if (!z.IsFaulted) { return; } Invoke((MethodInvoker)(() => L_Count.Text = "Failed.")); if (z.Exception == null) { return; } WinFormsUtil.Error("Loading database failed.", z.Exception.InnerException ?? new Exception(z.Exception.Message)); }); task.Start(); Menu_SearchSettings.DropDown.Closing += (sender, e) => { if (e.CloseReason == ToolStripDropDownCloseReason.ItemClicked) { e.Cancel = true; } }; CB_Format.Items[0] = MsgAny; CenterToParent(); }