Make dragdrop work with exporting to discord

Hold shift when dropping into discord to have discord auto-send it; bump time delay to 20s for file deletes

Seems like it just wanted Effects.Copy instead of Effects.Move, nice. Used to work for a while until it didn't.
This commit is contained in:
Kurt 2022-03-22 23:02:46 -07:00
parent 2cbdd5dbe6
commit d02537f16e
3 changed files with 37 additions and 12 deletions

View file

@ -163,8 +163,8 @@ namespace PKHeX.WinForms.Controls
// 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?
// Keep it to 10 seconds; Discord upload only stores the file path until you click Upload.
int delay = external ? 10_000 : 0;
// Keep it to 20 seconds; Discord upload only stores the file path until you click Upload.
int delay = external ? 20_000 : 0;
DeleteAsync(newfile, delay);
if (Drag.Info.DragIsParty)
SE.SetParty();
@ -173,8 +173,11 @@ namespace PKHeX.WinForms.Controls
private async void DeleteAsync(string path, int delay)
{
await Task.Delay(delay).ConfigureAwait(true);
if (File.Exists(path) && Drag.Info.CurrentPath == null)
File.Delete(path);
if (!File.Exists(path) || Drag.Info.CurrentPath == path)
return;
try { File.Delete(path); }
catch (Exception ex) { Debug.WriteLine(ex.Message); }
}
private string CreateDragDropPKM(PictureBox pb, bool encrypt, out bool external)
@ -208,7 +211,7 @@ namespace PKHeX.WinForms.Controls
// Thread Blocks on DoDragDrop
Drag.Info.CurrentPath = newfile;
var result = pb.DoDragDrop(new DataObject(DataFormats.FileDrop, new[] { newfile }), DragDropEffects.Move);
var result = pb.DoDragDrop(new DataObject(DataFormats.FileDrop, new[] { newfile }), DragDropEffects.Copy);
var external = Drag.Info.Destination == null || result != DragDropEffects.Link;
if (external || Drag.Info.SameLocation) // not dropped to another box slot, restore img
{

View file

@ -1096,7 +1096,7 @@ namespace PKHeX.WinForms
e.Effect = DragDropEffects.Copy;
}
private void Dragout_MouseDown(object sender, MouseEventArgs e)
private async void Dragout_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button != MouseButtons.Left)
return;
@ -1123,13 +1123,23 @@ namespace PKHeX.WinForms
var pb = (PictureBox)sender;
if (pb.Image != null)
C_SAV.M.Drag.Info.Cursor = Cursor = new Cursor(((Bitmap)pb.Image).GetHicon());
DoDragDrop(new DataObject(DataFormats.FileDrop, new[] { newfile }), DragDropEffects.Move);
DoDragDrop(new DataObject(DataFormats.FileDrop, new[] { newfile }), DragDropEffects.Copy);
C_SAV.M.Drag.ResetCursor(this);
await DeleteAsync(newfile, 20_000).ConfigureAwait(false);
}
// Tons of things can happen with drag & drop; don't try to handle things, just indicate failure.
catch (Exception x)
{ WinFormsUtil.Error("Drag && Drop Error", x); }
C_SAV.M.Drag.ResetCursor(this);
File.Delete(newfile);
}
private static async Task DeleteAsync(string path, int delay)
{
await Task.Delay(delay).ConfigureAwait(true);
if (!File.Exists(path))
return;
try { File.Delete(path); }
catch (Exception ex) { Debug.WriteLine(ex.Message); }
}
private void Dragout_DragOver(object sender, DragEventArgs e) => e.Effect = DragDropEffects.Move;

View file

@ -1,9 +1,11 @@
using PKHeX.Core;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using PKHeX.Drawing.Misc;
using PKHeX.WinForms.Controls;
@ -390,7 +392,7 @@ namespace PKHeX.WinForms
ViewGiftData(gift);
}
private void BoxSlot_MouseDown(object? sender, MouseEventArgs e)
private async void BoxSlot_MouseDown(object? sender, MouseEventArgs e)
{
if (sender == null)
return;
@ -417,13 +419,23 @@ namespace PKHeX.WinForms
try
{
File.WriteAllBytes(newfile, gift.Write());
DoDragDrop(new DataObject(DataFormats.FileDrop, new[] { newfile }), DragDropEffects.Move);
DoDragDrop(new DataObject(DataFormats.FileDrop, new[] { newfile }), DragDropEffects.Copy);
}
// Sometimes the drag-drop is canceled or ends up at a bad location. Don't bother recovering from an exception; just display a safe error message.
catch (Exception x)
{ WinFormsUtil.Error("Drag & Drop Error", x); }
File.Delete(newfile);
wc_slot = -1;
await DeleteAsync(newfile, 20_000).ConfigureAwait(false);
}
private static async Task DeleteAsync(string path, int delay)
{
await Task.Delay(delay).ConfigureAwait(true);
if (!File.Exists(path))
return;
try { File.Delete(path); }
catch (Exception ex) { Debug.WriteLine(ex.Message); }
}
private void BoxSlot_DragDrop(object? sender, DragEventArgs? e)