private void Update()
 {
     while (true)
     {
         _overlay.Dispatcher.BeginInvoke(new Action(() =>
         {
             _overlay.UpdatePosition();
         }));
         Thread.Sleep(100);
     }
 }
Пример #2
0
        private void Update()
        {
            while (true)
            {
                if (Process.GetProcessesByName("Hearthstone").Length == 1)
                {
                    _overlay.Dispatcher.BeginInvoke(new Action(() =>
                    {
                        _overlay.UpdatePosition();
                    }));
                }
                else
                {
                    _overlay.Dispatcher.BeginInvoke(new Action(() => _overlay.EnableCanvas(false)));
                }

                Thread.Sleep(_config.UpdateDelay);
            }
        }
        private async void UpdateOverlayAsync()
        {
            var hsForegroundChanged = false;

            while (_doUpdate)
            {
                if (User32.GetHearthstoneWindow() != IntPtr.Zero)
                {
                    Overlay.UpdatePosition();

                    if (!_tempUpdateCheckDisabled && Config.Instance.CheckForUpdates)
                    {
                        if (!Game.IsRunning && (DateTime.Now - _lastUpdateCheck) > new TimeSpan(0, 10, 0))
                        {
                            Version newVersion;
                            var     currentVersion = Helper.CheckForUpdates(out newVersion);
                            if (currentVersion != null && newVersion != null)
                            {
                                ShowNewUpdateMessage(newVersion);
                            }
                            _lastUpdateCheck = DateTime.Now;
                        }
                    }

                    Game.IsRunning = true;
                    if (!User32.IsHearthstoneInForeground() && !hsForegroundChanged)
                    {
                        if (Config.Instance.WindowsTopmostIfHsForeground && Config.Instance.WindowsTopmost)
                        {
                            PlayerWindow.Topmost   = false;
                            OpponentWindow.Topmost = false;
                            TimerWindow.Topmost    = false;
                        }
                        hsForegroundChanged = true;
                    }
                    else if (hsForegroundChanged && User32.IsHearthstoneInForeground())
                    {
                        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?
                            OpponentWindow.Topmost = true;
                            PlayerWindow.Topmost   = true;
                            TimerWindow.Topmost    = true;
                        }
                        hsForegroundChanged = false;
                    }
                }
                else
                {
                    Overlay.ShowOverlay(false);
                    if (Game.IsRunning)
                    {
                        //game was closed
                        Logger.WriteLine("Exited game");
                        HsLogReader.Instance.ClearLog();
                        Game.Reset();
                        if (DeckPickerList.SelectedDeck != null)
                        {
                            Game.SetPremadeDeck((Deck)DeckPickerList.SelectedDeck.Clone());
                        }
                        HsLogReader.Instance.Reset(true);

                        if (Config.Instance.CloseWithHearthstone)
                        {
                            Close();
                        }
                    }
                    Game.IsRunning = false;
                }
                await Task.Delay(Config.Instance.UpdateDelay);
            }
            _canShowDown = true;
        }