private async void Window_Closing(object sender, CancelEventArgs e) { try { if (HearthStatsManager.SyncInProgress && !_closeAnyway) { e.Cancel = true; var result = await this.ShowMessageAsync("WARNING! Sync with HearthStats in progress!", "Closing Hearthstone Deck Tracker now can cause data inconsistencies. Are you sure?", MessageDialogStyle.AffirmativeAndNegative, new MessageDialogs.Settings { AffirmativeButtonText = "close anyway", NegativeButtonText = "wait" }); if (result == MessageDialogResult.Negative) { while (HearthStatsManager.SyncInProgress) { await Task.Delay(100); } await this.ShowMessage("Sync is complete.", "You can close Hearthstone Deck Tracker now."); } else { _closeAnyway = true; Close(); } } Core.UpdateOverlay = false; Core.Update = false; //wait for update to finish, might otherwise crash when overlay gets disposed for (var i = 0; i < 100; i++) { if (Core.CanShutdown) { break; } await Task.Delay(50); } ReplayReader.CloseViewers(); Config.Instance.SelectedTags = Config.Instance.SelectedTags.Distinct().ToList(); //Config.Instance.ShowAllDecks = DeckPickerList.ShowAll; Config.Instance.SelectedDeckPickerClasses = DeckPickerList.SelectedClasses.ToArray(); Config.Instance.WindowWidth = (int)(Width - (GridNewDeck.Visibility == Visible ? GridNewDeck.ActualWidth : 0)); Config.Instance.WindowHeight = (int)(Height - _heightChangeDueToSearchBox); Config.Instance.TrackerWindowTop = (int)Top; Config.Instance.TrackerWindowLeft = (int)(Left + (MovedLeft ?? 0)); //position of add. windows is NaN if they were never opened. if (!double.IsNaN(Core.Windows.PlayerWindow.Left)) { Config.Instance.PlayerWindowLeft = (int)Core.Windows.PlayerWindow.Left; } if (!double.IsNaN(Core.Windows.PlayerWindow.Top)) { Config.Instance.PlayerWindowTop = (int)Core.Windows.PlayerWindow.Top; } Config.Instance.PlayerWindowHeight = (int)Core.Windows.PlayerWindow.Height; if (!double.IsNaN(Core.Windows.OpponentWindow.Left)) { Config.Instance.OpponentWindowLeft = (int)Core.Windows.OpponentWindow.Left; } if (!double.IsNaN(Core.Windows.OpponentWindow.Top)) { Config.Instance.OpponentWindowTop = (int)Core.Windows.OpponentWindow.Top; } Config.Instance.OpponentWindowHeight = (int)Core.Windows.OpponentWindow.Height; if (!double.IsNaN(Core.Windows.TimerWindow.Left)) { Config.Instance.TimerWindowLeft = (int)Core.Windows.TimerWindow.Left; } if (!double.IsNaN(Core.Windows.TimerWindow.Top)) { Config.Instance.TimerWindowTop = (int)Core.Windows.TimerWindow.Top; } Config.Instance.TimerWindowHeight = (int)Core.Windows.TimerWindow.Height; Config.Instance.TimerWindowWidth = (int)Core.Windows.TimerWindow.Width; Core.TrayIcon.NotifyIcon.Visible = false; Core.Overlay.Close(); await LogReaderManager.Stop(true); Core.Windows.TimerWindow.Shutdown(); Core.Windows.PlayerWindow.Shutdown(); Core.Windows.OpponentWindow.Shutdown(); Config.Save(); DeckList.Save(); DeckStatsList.Save(); PluginManager.SavePluginsSettings(); PluginManager.Instance.UnloadPlugins(); } catch (Exception) { //doesnt matter } finally { Application.Current.Shutdown(); } }
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); } ReplayReader.CloseViewers(); 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 } }