From f25adad21147ec1ca9796c4e7b97d4ee244a09f0 Mon Sep 17 00:00:00 2001 From: Kurt Date: Sat, 4 Feb 2017 23:11:48 -0800 Subject: [PATCH] Misc tweaks allow qr for gens 1-3, change draginfo cursor type to object. need to figure out how I can get it out of main --- PKHeX.WinForms/MainWindow/Main.cs | 23 ++++++++----------- PKHeX.WinForms/Misc/QR.cs | 3 ++- .../Subforms/Save Editors/SAV_BoxViewer.cs | 2 +- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/PKHeX.WinForms/MainWindow/Main.cs b/PKHeX.WinForms/MainWindow/Main.cs index f1b08adab..a52fbf692 100644 --- a/PKHeX.WinForms/MainWindow/Main.cs +++ b/PKHeX.WinForms/MainWindow/Main.cs @@ -1232,11 +1232,11 @@ private void openSAV(SaveFile sav, string path) { // Check location write protection bool locked = true; - try { locked = (new DirectoryInfo(path).Attributes & FileAttributes.ReadOnly) != 0; } + try { locked = File.GetAttributes(path).HasFlag(FileAttributes.ReadOnly); } catch { } if (locked) - WinFormsUtil.Alert("Save file's location is write protected:\n" + path, + WinFormsUtil.Alert("File's location is write protected:\n" + path, "If the path is a removable disk (SD card), please ensure the write protection switch is not set."); } @@ -1502,7 +1502,7 @@ public void populateFields(PKM pk, bool focus = true) pkm = pk.Clone(); if (fieldsInitialized & !pkm.ChecksumValid) - WinFormsUtil.Alert("PKX File has an invalid checksum."); + WinFormsUtil.Alert("PKM File has an invalid checksum."); if (pkm.Format != SAV.Generation) // past gen format { @@ -1663,11 +1663,6 @@ private void setMarkings() // Clicked Label Shortcuts // private void clickQR(object sender, EventArgs e) { - if (SAV.Generation <= 3) - { - WinFormsUtil.Alert("QR feature not available for loaded game."); - return; - } if (ModifierKeys == Keys.Alt) { // Fetch data from QR code... @@ -1693,7 +1688,6 @@ private void clickQR(object sender, EventArgs e) { if (!verifiedPKM()) return; PKM pkx = preparePKM(); - byte[] ekx = pkx.EncryptedBoxData; Image qr; switch (pkx.Format) @@ -1702,7 +1696,8 @@ private void clickQR(object sender, EventArgs e) qr = QR.GenerateQRCode7((PK7) pkx); break; default: - qr = QR.getQRImage(ekx, pkx.Format == 6 ? QR6Path : "null/#"); + bool qr6 = pkx.Format == 6; + qr = QR.getQRImage(pkx.EncryptedBoxData, qr6 ? QR6Path : QR.BadQRUrl); break; } @@ -3074,12 +3069,12 @@ private void dragout_MouseDown(object sender, MouseEventArgs e) { File.WriteAllBytes(newfile, dragdata); PictureBox pb = (PictureBox)sender; - Cursor = DragInfo.Cursor = new Cursor(((Bitmap)pb.Image).GetHicon()); + DragInfo.Cursor = Cursor = new Cursor(((Bitmap)pb.Image).GetHicon()); DoDragDrop(new DataObject(DataFormats.FileDrop, new[] { newfile }), DragDropEffects.Move); } catch (Exception x) { WinFormsUtil.Error("Drag & Drop Error", x); } - Cursor = DragInfo.Cursor = DefaultCursor; + DragInfo.Cursor = Cursor = DefaultCursor; File.Delete(newfile); } private void dragout_DragOver(object sender, DragEventArgs e) @@ -4233,7 +4228,7 @@ private void pbBoxSlot_DragEnter(object sender, DragEventArgs e) e.Effect = DragDropEffects.Move; if (DragInfo.slotDragDropInProgress) - Cursor = DragInfo.Cursor; + Cursor = (Cursor)DragInfo.Cursor; } private void pbBoxSlot_QueryContinueDrag(object sender, QueryContinueDragEventArgs e) { @@ -4264,7 +4259,7 @@ public static class DragInfo public static int slotDestinationSlotNumber = -1; public static int slotDestinationBoxNumber = -1; - public static Cursor Cursor; + public static object Cursor; public static string CurrentPath; public static bool SameBox => slotSourceBoxNumber > -1 && slotSourceBoxNumber == slotDestinationBoxNumber; diff --git a/PKHeX.WinForms/Misc/QR.cs b/PKHeX.WinForms/Misc/QR.cs index a6abc9225..4b9983f1c 100644 --- a/PKHeX.WinForms/Misc/QR.cs +++ b/PKHeX.WinForms/Misc/QR.cs @@ -81,6 +81,7 @@ private void PB_QR_Click(object sender, EventArgs e) } // QR Utility + public const string BadQRUrl = "null/#"; // prefix to prevent URL from loading internal static byte[] getQRData() { // Fetch data from QR code... @@ -107,7 +108,7 @@ internal static byte[] getQRData() pkstr = pkstr.Substring(0, pkstr.IndexOf(cap, StringComparison.Ordinal)); // Trim outro try { - if (!pkstr.StartsWith("http")) // G7 + if (!pkstr.StartsWith("http") && pkstr.StartsWith(BadQRUrl)) // G7 { string fstr = Regex.Unescape(pkstr); byte[] raw = Encoding.Unicode.GetBytes(fstr); diff --git a/PKHeX.WinForms/Subforms/Save Editors/SAV_BoxViewer.cs b/PKHeX.WinForms/Subforms/Save Editors/SAV_BoxViewer.cs index 2e6a68dd0..e8549ffa1 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/SAV_BoxViewer.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/SAV_BoxViewer.cs @@ -320,7 +320,7 @@ private void pbBoxSlot_DragEnter(object sender, DragEventArgs e) e.Effect = DragDropEffects.Move; if (DragInfo.slotDragDropInProgress) - Cursor = DragInfo.Cursor; + Cursor = (Cursor)DragInfo.Cursor; } private void pbBoxSlot_QueryContinueDrag(object sender, QueryContinueDragEventArgs e) {