public static async Task<bool> Export(Deck deck, Func<Task<bool>> onInterrupt) { if(deck == null) return false; var currentClipboard = ""; try { Log.Info("Exporting " + deck.GetDeckInfo()); if(Config.Instance.ExportPasteClipboard && Clipboard.ContainsText()) currentClipboard = Clipboard.GetText(); var info = new ExportingInfo(); LogDebugInfo(info); info = await ExportingHelper.EnsureHearthstoneInForeground(info); if(info == null) return false; LogDebugInfo(info); Log.Info($"Waiting for {Config.Instance.ExportStartDelay} seconds before starting the export process"); await Task.Delay(Config.Instance.ExportStartDelay*1000); var exporter = new ExportingActions(info, deck, onInterrupt); await exporter.ClearDeck(); await exporter.SetDeckName(); await exporter.ClearFilters(); await exporter.CreateDeck(); await exporter.ClearSearchBox(); if(Config.Instance.ExportPasteClipboard) Clipboard.Clear(); Log.Info("Success exporting deck."); return true; } catch(ExportingInterruptedException e) { Log.Warn(e.Message); return false; } catch(Exception e) { Log.Error("Error exporting deck: " + e); return false; } finally { try { if(Config.Instance.ExportPasteClipboard && currentClipboard != "") Clipboard.SetText(currentClipboard); } catch(Exception ex) { Log.Error("Could not restore clipboard content after export: " + ex); } } }
public static async Task <bool> Export(Deck deck, Func <Task <bool> > onInterrupt) { if (deck == null) { return(false); } var currentClipboard = ""; try { Log.Info("Exporting " + deck.GetDeckInfo()); if (Config.Instance.ExportPasteClipboard && Clipboard.ContainsText()) { currentClipboard = Clipboard.GetText(); } var info = new ExportingInfo(); LogDebugInfo(info); info = await ExportingHelper.EnsureHearthstoneInForeground(info); if (info == null) { return(false); } LogDebugInfo(info); Log.Info($"Waiting for {Config.Instance.ExportStartDelay} seconds before starting the export process"); await Task.Delay(Config.Instance.ExportStartDelay *1000); var exporter = new ExportingActions(info, deck, onInterrupt); await exporter.ClearDeck(); await exporter.SetDeckName(); await exporter.ClearFilters(); await exporter.CreateDeck(); await exporter.ClearSearchBox(); if (Config.Instance.ExportPasteClipboard) { Clipboard.Clear(); } Log.Info("Success exporting deck."); return(true); } catch (ExportingInterruptedException e) { Log.Warn(e.Message); return(false); } catch (Exception e) { Log.Error("Error exporting deck: " + e); return(false); } finally { try { if (Config.Instance.ExportPasteClipboard && currentClipboard != "") { Clipboard.SetText(currentClipboard); } } catch (Exception ex) { Log.Error("Could not restore clipboard content after export: " + ex); } } }
public static async Task Export(Deck deck) { if (deck == null) { return; } var currentClipboard = ""; try { Logger.WriteLine("Exporting " + deck.GetDeckInfo(), "DeckExporter"); if (Config.Instance.ExportPasteClipboard && Clipboard.ContainsText()) { currentClipboard = Clipboard.GetText(); } var info = new ExportingInfo(); LogDebugInfo(info); var inForeground = await ExportingHelper.EnsureHearthstoneInForeground(info.HsHandle); if (!inForeground) { return; } Logger.WriteLine("Waiting for " + Config.Instance.ExportStartDelay + " seconds before starting the export process", "DeckExporter"); await Task.Delay(Config.Instance.ExportStartDelay * 1000); Core.Overlay.ForceHide(true); await ExportingActions.ClearDeck(info); await ExportingActions.SetDeckName(deck, info); await ExportingActions.ClearFilters(info); var lostFocus = await ExportingActions.CreateDeck(deck, info); if (lostFocus) { return; } await ExportingActions.ClearSearchBox(info.HsHandle, info.SearchBoxPos); if (Config.Instance.ExportPasteClipboard) { Clipboard.Clear(); } Logger.WriteLine("Success exporting deck.", "DeckExporter"); } catch (Exception e) { Logger.WriteLine("Error exporting deck: " + e, "DeckExporter"); } finally { Core.Overlay.ForceHide(false); if (Config.Instance.ExportPasteClipboard && currentClipboard != "") { Clipboard.SetText(currentClipboard); } } }