public static async Task Export(Deck deck)
        {
            if (deck == null)
            {
                return;
            }
            string Current_Clipboard = "";

            try
            {
                if (Config.Instance.ExportPasteClipboard && Clipboard.ContainsText())
                {
                    Current_Clipboard = Clipboard.GetText();
                }
                Logger.WriteLine(string.Format("Exporting " + deck.GetDeckInfo()), "DeckExporter");
                var hsHandle = User32.GetHearthstoneWindow();

                if (!User32.IsHearthstoneInForeground())
                {
                    //restore window and bring to foreground
                    User32.ShowWindow(hsHandle, User32.SwRestore);
                    User32.SetForegroundWindow(hsHandle);
                    //wait it to actually be in foreground, else the rect might be wrong
                    await Task.Delay(500);
                }
                if (!User32.IsHearthstoneInForeground())
                {
                    MessageBox.Show("Can't find Heartstone window.");
                    Logger.WriteLine("Can't find Hearthstone window.", "DeckExporter");
                    return;
                }

                Logger.WriteLine("Waiting for " + Config.Instance.ExportStartDelay + " seconds before starting the export process", "DeckExporter");
                await Task.Delay(Config.Instance.ExportStartDelay * 1000);

                var hsRect = User32.GetHearthstoneRect(false);
                var ratio  = (4.0 / 3.0) / ((double)hsRect.Width / hsRect.Height);

                var searchBoxPos = new Point((int)(GetXPos(Config.Instance.ExportSearchBoxX, hsRect.Width, ratio)),
                                             (int)(Config.Instance.ExportSearchBoxY * hsRect.Height));
                var cardPosX  = GetXPos(Config.Instance.ExportCard1X, hsRect.Width, ratio);
                var card2PosX = GetXPos(Config.Instance.ExportCard2X, hsRect.Width, ratio);
                var cardPosY  = Config.Instance.ExportCardsY * hsRect.Height;


                Helper.MainWindow.Overlay.ForceHidden = true;
                Helper.MainWindow.Overlay.UpdatePosition();

                if (Config.Instance.AutoClearDeck)
                {
                    await ClearDeck(hsRect.Width, hsRect.Height, hsHandle, ratio);
                }

                if (Config.Instance.ExportSetDeckName)
                {
                    await SetDeckName(deck.Name, ratio, hsRect.Width, hsRect.Height, hsHandle);
                }

                await ClickAllCrystal(ratio, hsRect.Width, hsRect.Height, hsHandle);

                Logger.WriteLine("Creating deck...", "DeckExporter");
                deck.MissingCards.Clear();
                foreach (var card in deck.Cards)
                {
                    var missingCardsCount =
                        await AddCardToDeck(card, searchBoxPos, cardPosX, card2PosX, cardPosY, hsRect.Height, hsRect.Width, hsHandle);

                    if (missingCardsCount < 0)
                    {
                        return;
                    }
                    if (missingCardsCount > 0)
                    {
                        var missingCard = (Card)card.Clone();
                        missingCard.Count = missingCardsCount;
                        deck.MissingCards.Add(missingCard);
                    }
                }

                if (deck.MissingCards.Any())
                {
                    DeckList.Save();
                }

                // Clear search field now all cards have been entered

                await ClickOnPoint(hsHandle, searchBoxPos);

                SendKeys.SendWait("{DELETE}");
                SendKeys.SendWait("{ENTER}");

                if (Config.Instance.ExportPasteClipboard)
                {
                    Clipboard.Clear();
                }

                Logger.WriteLine("Done creating deck.", "DeckExporter");
            }
            catch (Exception e)
            {
                Logger.WriteLine("Error exporting deck: " + e, "DeckExporter");
            }
            finally
            {
                Helper.MainWindow.Overlay.ForceHidden = false;
                Helper.MainWindow.Overlay.UpdatePosition();
                if (Config.Instance.ExportPasteClipboard && Current_Clipboard != "")
                {
                    Clipboard.SetText(Current_Clipboard);
                }
            }
        }
Beispiel #2
0
        public static async Task Export(Deck deck)
        {
            if (deck == null)
            {
                return;
            }
            try
            {
                Logger.WriteLine(string.Format("Exporting " + deck.GetDeckInfo(), "DeckExporter"));
                var hsHandle = User32.GetHearthstoneWindow();

                if (!User32.IsHearthstoneInForeground())
                {
                    //restore window and bring to foreground
                    User32.ShowWindow(hsHandle, User32.SwRestore);
                    User32.SetForegroundWindow(hsHandle);
                    //wait it to actually be in foreground, else the rect might be wrong
                    await Task.Delay(500);
                }
                if (!User32.IsHearthstoneInForeground())
                {
                    MessageBox.Show("Can't find Heartstone window.");
                    Logger.WriteLine("Can't find Hearthstone window.", "DeckExporter");
                    return;
                }

                var hsRect = User32.GetHearthstoneRect(false);
                var ratio  = (4.0 / 3.0) / ((double)hsRect.Width / hsRect.Height);

                string oldClipboardContent = null;
                try
                {
                    oldClipboardContent = Clipboard.GetText();
                }
                catch
                {
                }

                var searchBoxPos = new Point((int)(GetXPos(Config.Instance.ExportSearchBoxX, hsRect.Width, ratio)),
                                             (int)(Config.Instance.ExportSearchBoxY * hsRect.Height));
                var cardPosX  = GetXPos(Config.Instance.ExportCard1X, hsRect.Width, ratio);
                var card2PosX = GetXPos(Config.Instance.ExportCard2X, hsRect.Width, ratio);
                var cardPosY  = Config.Instance.ExportCardsY * hsRect.Height;


                Helper.MainWindow.Overlay.ForceHidden = true;
                Helper.MainWindow.Overlay.UpdatePosition();

                if (Config.Instance.AutoClearDeck)
                {
                    await ClearDeck(hsRect.Width, hsRect.Height, hsHandle, ratio);
                }

                if (Config.Instance.ExportSetDeckName)
                {
                    await SetDeckName(deck.Name, ratio, hsRect.Width, hsRect.Height, hsHandle);
                }

                await ClickAllCrystal(ratio, hsRect.Width, hsRect.Height, hsHandle);

                Logger.WriteLine("Creating deck...", "DeckExporter");
                foreach (var card in deck.Cards)
                {
                    await AddCardToDeck(card, searchBoxPos, cardPosX, card2PosX, cardPosY, hsRect.Height, hsHandle);
                }


                // Clear search field now all cards have been entered

                await ClickOnPoint(hsHandle, searchBoxPos);

                SendKeys.SendWait("{DELETE}");
                SendKeys.SendWait("{ENTER}");
                try
                {
                    if (oldClipboardContent != null)
                    {
                        Clipboard.SetText(oldClipboardContent);
                    }
                }
                catch
                {
                }
                Logger.WriteLine("Done creating deck.", "DeckExporter");
            }
            catch (Exception e)
            {
                Logger.WriteLine("Error exporting deck: " + e.Message, "DeckExporter");
            }
            finally
            {
                Helper.MainWindow.Overlay.ForceHidden = false;
                Helper.MainWindow.Overlay.UpdatePosition();
            }
        }