Example #1
0
 private void Window_Closing_1(object sender, CancelEventArgs e)
 {
     try
     {
         _overlay.Close();
         _logReader.Stop();
         _updateThread.Abort();
         _playerWindow.Shutdown();
         _opponentWindow.Shutdown();
         _xmlManagerConfig.Save("config.xml", _config);
     }
     catch (Exception)
     {
         //doesnt matter
     }
 }
        private async void Window_Closing(object sender, CancelEventArgs e)
        {
            try
            {
                _doUpdate = false;

                //wait for update to finish, might otherwise crash when overlay gets disposed
                for (var i = 0; i < 100; i++)
                {
                    if (_canShowDown)
                    {
                        break;
                    }
                    await Task.Delay(50);
                }

                Config.Instance.SelectedTags = Config.Instance.SelectedTags.Distinct().ToList();
                Config.Instance.ShowAllDecks = DeckPickerList.ShowAll;

                Config.Instance.WindowWidth       = (int)(Width - (GridNewDeck.Visibility == Visibility.Visible ? GridNewDeck.ActualWidth : 0));
                Config.Instance.WindowHeight      = (int)Height;
                Config.Instance.TrackerWindowTop  = (int)Top;
                Config.Instance.TrackerWindowLeft = (int)Left;

                //position of add. windows is NaN if they were never opened.
                if (!double.IsNaN(PlayerWindow.Left))
                {
                    Config.Instance.PlayerWindowLeft = (int)PlayerWindow.Left;
                }
                if (!double.IsNaN(PlayerWindow.Top))
                {
                    Config.Instance.PlayerWindowTop = (int)PlayerWindow.Top;
                }
                Config.Instance.PlayerWindowHeight = (int)PlayerWindow.Height;

                if (!double.IsNaN(OpponentWindow.Left))
                {
                    Config.Instance.OpponentWindowLeft = (int)OpponentWindow.Left;
                }
                if (!double.IsNaN(OpponentWindow.Top))
                {
                    Config.Instance.OpponentWindowTop = (int)OpponentWindow.Top;
                }
                Config.Instance.OpponentWindowHeight = (int)OpponentWindow.Height;

                if (!double.IsNaN(TimerWindow.Left))
                {
                    Config.Instance.TimerWindowLeft = (int)TimerWindow.Left;
                }
                if (!double.IsNaN(TimerWindow.Top))
                {
                    Config.Instance.TimerWindowTop = (int)TimerWindow.Top;
                }
                Config.Instance.TimerWindowHeight = (int)TimerWindow.Height;
                Config.Instance.TimerWindowWidth  = (int)TimerWindow.Width;

                if (!double.IsNaN(StatsWindow.Left))
                {
                    Config.Instance.StatsWindowLeft = (int)StatsWindow.Left;
                }
                if (!double.IsNaN(StatsWindow.Top))
                {
                    Config.Instance.StatsWindowTop = (int)StatsWindow.Top;
                }
                Config.Instance.StatsWindowHeight = (int)StatsWindow.Height;
                Config.Instance.StatsWindowWidth  = (int)StatsWindow.Width;

                _notifyIcon.Visible = false;
                Overlay.Close();
                HsLogReader.Instance.Stop();
                TimerWindow.Shutdown();
                PlayerWindow.Shutdown();
                OpponentWindow.Shutdown();
                StatsWindow.Shutdown();
                Config.Save();
                WriteDecks();
            }
            catch (Exception)
            {
                //doesnt matter
            }
        }