private void BtnClipboardText_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         if (NetDeck.CheckForClipboardImport())
         {
             if (!Config.Instance.NetDeckClipboardCheck.HasValue)
             {
                 Options.OptionsTrackerImporting.CheckboxImportNetDeck.IsChecked = true;
                 Config.Instance.NetDeckClipboardCheck = true;
                 Config.Save();
             }
             return;
         }
         if (Clipboard.ContainsText())
         {
             var deck = Helper.ParseCardString(Clipboard.GetText());
             if (deck != null)
             {
                 SetNewDeck(deck);
                 if (Config.Instance.AutoSaveOnImport)
                 {
                     SaveDeckWithOverwriteCheck();
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Logger.WriteLine("Error importing deck from clipboard(text): " + ex, "Import");
     }
 }
 private async void BtnClipboardText_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         if (NetDeck.CheckForClipboardImport())
         {
             if (!Config.Instance.NetDeckClipboardCheck.HasValue)
             {
                 Options.OptionsTrackerImporting.CheckboxImportNetDeck.IsChecked = true;
                 Config.Instance.NetDeckClipboardCheck = true;
                 Config.Save();
             }
             return;
         }
         if (Clipboard.ContainsText())
         {
             var english = true;
             if (Config.Instance.SelectedLanguage != "enUS")
             {
                 try
                 {
                     english = await this.ShowLanguageSelectionDialog();
                 }
                 catch (Exception ex)
                 {
                     Log.Error(ex);
                 }
             }
             var deck = Helper.ParseCardString(Clipboard.GetText(), !english);
             if (deck != null)
             {
                 SetNewDeck(deck);
                 if (Config.Instance.AutoSaveOnImport)
                 {
                     SaveDeckWithOverwriteCheck();
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Log.Error(ex);
     }
 }
示例#3
0
        private static async void UpdateOverlayAsync()
        {
#if (!SQUIRREL)
            if (Config.Instance.CheckForUpdates)
            {
                Updater.CheckForUpdates(true);
            }
#endif
            var hsForegroundChanged = false;
            var useNoDeckMenuItem   = TrayIcon.NotifyIcon.ContextMenu.MenuItems.IndexOfKey("startHearthstone");
            while (UpdateOverlay)
            {
                if (Config.Instance.CheckForUpdates)
                {
                    Updater.CheckForUpdates();
                }
                if (User32.GetHearthstoneWindow() != IntPtr.Zero)
                {
                    if (Game.CurrentRegion == Region.UNKNOWN)
                    {
                        //game started
                        Game.CurrentRegion = Helper.GetCurrentRegion();
                        if (Game.CurrentRegion != Region.UNKNOWN)
                        {
                            BackupManager.Run();
                            Game.MetaData.HearthstoneBuild = null;
                        }
                    }
                    Overlay.UpdatePosition();

                    if (!Game.IsRunning)
                    {
                        Overlay.Update(true);
                        Windows.CapturableOverlay?.UpdateContentVisibility();
                    }

                    MainWindow.BtnStartHearthstone.Visibility = Visibility.Collapsed;
                    TrayIcon.NotifyIcon.ContextMenu.MenuItems[useNoDeckMenuItem].Visible = false;

                    Game.IsRunning = true;

                    Helper.GameWindowState = User32.GetHearthstoneWindowState();
                    Windows.CapturableOverlay?.Update();
                    if (User32.IsHearthstoneInForeground() && Helper.GameWindowState != WindowState.Minimized)
                    {
                        if (hsForegroundChanged)
                        {
                            Overlay.Update(true);
                            if (Config.Instance.WindowsTopmostIfHsForeground && Config.Instance.WindowsTopmost)
                            {
                                //if player topmost is set to true before opponent:
                                //clicking on the playerwindow and back to hs causes the playerwindow to be behind hs.
                                //other way around it works for both windows... what?
                                Windows.OpponentWindow.Topmost = true;
                                Windows.PlayerWindow.Topmost   = true;
                                Windows.TimerWindow.Topmost    = true;
                            }
                            hsForegroundChanged = false;
                        }
                    }
                    else if (!hsForegroundChanged)
                    {
                        if (Config.Instance.WindowsTopmostIfHsForeground && Config.Instance.WindowsTopmost)
                        {
                            Windows.PlayerWindow.Topmost   = false;
                            Windows.OpponentWindow.Topmost = false;
                            Windows.TimerWindow.Topmost    = false;
                        }
                        hsForegroundChanged = true;
                    }
                }
                else if (Game.IsRunning)
                {
                    Game.IsRunning = false;
                    Overlay.ShowOverlay(false);
                    if (Windows.CapturableOverlay != null)
                    {
                        Windows.CapturableOverlay.UpdateContentVisibility();
                        await Task.Delay(100);

                        Windows.CapturableOverlay.ForcedWindowState = WindowState.Minimized;
                        Windows.CapturableOverlay.WindowState       = WindowState.Minimized;
                    }
                    Log.Info("Exited game");
                    Game.CurrentRegion = Region.UNKNOWN;
                    Log.Info("Reset region");
                    await Reset();

                    Game.IsInMenu = true;
                    Game.InvalidateMatchInfoCache();
                    Overlay.HideRestartRequiredWarning();
                    TurnTimer.Instance.Stop();

                    MainWindow.BtnStartHearthstone.Visibility = Visibility.Visible;
                    TrayIcon.NotifyIcon.ContextMenu.MenuItems[useNoDeckMenuItem].Visible = true;

                    if (Config.Instance.CloseWithHearthstone)
                    {
                        MainWindow.Close();
                    }
                }

                if (Config.Instance.NetDeckClipboardCheck.HasValue && Config.Instance.NetDeckClipboardCheck.Value && Initialized &&
                    !User32.IsHearthstoneInForeground())
                {
                    NetDeck.CheckForClipboardImport();
                }

                await Task.Delay(UpdateDelay);
            }
            CanShutdown = true;
        }
示例#4
0
        private static async void UpdateOverlayAsync()
        {
            if (Config.Instance.CheckForUpdates)
            {
                Updater.CheckForUpdates(true);
            }
            var hsForegroundChanged = false;
            var useNoDeckMenuItem   = TrayIcon.NotifyIcon.ContextMenu.MenuItems.IndexOfKey("startHearthstone");

            UpdateOverlay = Helper.HearthstoneDirExists;
            while (UpdateOverlay)
            {
                if (User32.GetHearthstoneWindow() != IntPtr.Zero)
                {
                    if (Game.CurrentRegion == Region.UNKNOWN)
                    {
                        //game started
                        Game.CurrentRegion = Helper.GetCurrentRegion();
                    }
                    Overlay.UpdatePosition();

                    if (Config.Instance.CheckForUpdates)
                    {
                        Updater.CheckForUpdates();
                    }

                    if (!Game.IsRunning)
                    {
                        Overlay.Update(true);
                    }

                    MainWindow.BtnStartHearthstone.Visibility = Visibility.Collapsed;
                    TrayIcon.NotifyIcon.ContextMenu.MenuItems[useNoDeckMenuItem].Visible = false;

                    Game.IsRunning = true;
                    if (User32.IsHearthstoneInForeground())
                    {
                        if (hsForegroundChanged)
                        {
                            Overlay.Update(true);
                            if (Config.Instance.WindowsTopmostIfHsForeground && Config.Instance.WindowsTopmost)
                            {
                                //if player topmost is set to true before opponent:
                                //clicking on the playerwindow and back to hs causes the playerwindow to be behind hs.
                                //other way around it works for both windows... what?
                                Windows.OpponentWindow.Topmost = true;
                                Windows.PlayerWindow.Topmost   = true;
                                Windows.TimerWindow.Topmost    = true;
                            }
                            hsForegroundChanged = false;
                        }
                    }
                    else if (!hsForegroundChanged)
                    {
                        if (Config.Instance.WindowsTopmostIfHsForeground && Config.Instance.WindowsTopmost)
                        {
                            Windows.PlayerWindow.Topmost   = false;
                            Windows.OpponentWindow.Topmost = false;
                            Windows.TimerWindow.Topmost    = false;
                        }
                        hsForegroundChanged = true;
                    }
                }
                else
                {
                    Overlay.ShowOverlay(false);
                    if (Game.IsRunning)
                    {
                        //game was closed
                        Logger.WriteLine("Exited game", "UpdateOverlayLoop");
                        Game.CurrentRegion = Region.UNKNOWN;
                        Logger.WriteLine("Reset region", "UpdateOverlayLoop");
                        //HsLogReaderV2.Instance.ClearLog();
                        Game.Reset();
                        if (DeckList.Instance.ActiveDeck != null)
                        {
                            Game.SetPremadeDeck((Deck)DeckList.Instance.ActiveDeck.Clone());
                        }
                        await LogReaderManager.Restart();

                        MainWindow.BtnStartHearthstone.Visibility = Visibility.Visible;
                        TrayIcon.NotifyIcon.ContextMenu.MenuItems[useNoDeckMenuItem].Visible = true;

                        if (Config.Instance.CloseWithHearthstone)
                        {
                            MainWindow.Close();
                        }
                    }
                    Game.IsRunning = false;
                }

                if (Config.Instance.NetDeckClipboardCheck.HasValue && Config.Instance.NetDeckClipboardCheck.Value &&
                    Initialized &&
                    !User32.IsHearthstoneInForeground())
                {
                    NetDeck.CheckForClipboardImport();
                }

                await Task.Delay(Config.Instance.UpdateDelay);
            }
            CanShutdown = true;
        }