Exemple #1
0
        public static async Task Reset()
        {
            if (_resetting)
            {
                Log.Warn("Reset already in progress.");
                return;
            }
            _resetting = true;
            var stoppedReader = await LogReaderManager.Stop();

            Game.Reset();
            if (DeckList.Instance.ActiveDeck != null)
            {
                Game.IsUsingPremade = true;
                MainWindow.UpdateMenuItemVisibility();
            }
            await Task.Delay(1000);

            if (stoppedReader)
            {
                LogReaderManager.Restart();
            }
            Overlay.HideSecrets();
            Overlay.Update(false);
            UpdatePlayerCards(true);
            _resetting = false;
        }
        private async void CheckMirrorStatus()
        {
            _checkedMirrorStatus = true;
            Status status;

            while ((status = Status.GetStatus()).MirrorStatus == MirrorStatus.ProcNotFound)
            {
                await Task.Delay(1000);
            }
            Log.Info($"Mirror status: {status.MirrorStatus}");
            if (status.MirrorStatus != MirrorStatus.Error)
            {
                return;
            }
            Log.Error(status.Exception);
            if (!(status.Exception is Win32Exception))
            {
                Log.Info("Not a Win32Exception - Process probably exited. Checking again later.");
                _checkedMirrorStatus = false;
                return;
            }
            Influx.OnUnevenPermissions();
            LogReaderManager.Stop(true).Forget();
            Core.MainWindow.ActivateWindow();
            while (Core.MainWindow.Visibility != Visibility.Visible || Core.MainWindow.WindowState == WindowState.Minimized)
            {
                await Task.Delay(100);
            }
            await Core.MainWindow.ShowMessage("Uneven permissions",
                                              "It appears that Hearthstone (Battle.net) and HDT do not have the same permissions.\n\nPlease run both as administrator or local user.\n\nIf you don't know what any of this means, just run HDT as administrator.");
        }
Exemple #3
0
        public async void UseDeck(Deck selected)
        {
            Core.Game.Reset();

            if (selected != null)
            {
                DeckList.Instance.ActiveDeck = selected;
                Core.Game.SetPremadeDeck((Deck)selected.Clone());
                UpdateMenuItemVisibility();
            }
            //needs to be true for automatic deck detection to work
            await LogReaderManager.Restart();

            Core.Overlay.Update(false);
            Core.Overlay.UpdatePlayerCards();
            Core.Windows.PlayerWindow.UpdatePlayerCards();
        }
Exemple #4
0
        private void SaveAndUpdateStats()
        {
            var statsControl = Config.Instance.StatsInWindow ? Helper.MainWindow.StatsWindow.StatsControl : Helper.MainWindow.DeckStatsFlyout;

            if (RecordCurrentGameMode)
            {
                if (Config.Instance.ShowNoteDialogAfterGame && Config.Instance.NoteDialogDelayed && !_showedNoteDialog)
                {
                    _showedNoteDialog = true;
                    new NoteDialog(_game.CurrentGameStats);
                }

                if (_game.CurrentGameStats != null)
                {
                    _game.CurrentGameStats.Turns = LogReaderManager.GetTurnNumber();
                    if (Config.Instance.DiscardZeroTurnGame && _game.CurrentGameStats.Turns < 1)
                    {
                        Logger.WriteLine("Game has 0 turns, discarded. (DiscardZeroTurnGame)", "GameEventHandler");
                        return;
                    }
                    _game.CurrentGameStats.GameMode = _game.CurrentGameMode;
                    Logger.WriteLine("Set CurrentGameStats.GameMode to " + _game.CurrentGameMode, "GameEventHandler");
                    _game.CurrentGameStats = null;
                }

                if (_assignedDeck == null)
                {
                    Logger.WriteLine("Saving DefaultDeckStats", "GameEventHandler");
                    DefaultDeckStats.Save();
                }
                else
                {
                    Logger.WriteLine("Saving DeckStats", "GameEventHandler");
                    DeckStatsList.Save();
                }

                Helper.MainWindow.DeckPickerList.UpdateDecks();
                statsControl.Refresh();
            }
            else if (_assignedDeck != null && _assignedDeck.DeckStats.Games.Contains(_game.CurrentGameStats))
            {
                //game was not supposed to be recorded, remove from deck again.
                _assignedDeck.DeckStats.Games.Remove(_game.CurrentGameStats);
                statsControl.Refresh();
            }
        }
Exemple #5
0
        private async void CheckboxRemoveCards_Unchecked(object sender, RoutedEventArgs e)
        {
            if (!_initialized || !_game.IsUsingPremade)
            {
                return;
            }
            Config.Instance.RemoveCardsFromDeck = false;
            SaveConfig(false);
            _game.Reset();
            if (DeckList.Instance.ActiveDeck != null)
            {
                _game.SetPremadeDeck((Deck)DeckList.Instance.ActiveDeck.Clone());
            }
            await LogReaderManager.Restart();

            Helper.MainWindow.Overlay.Update(true);
        }
Exemple #6
0
        public static async Task Reset()
        {
            var stoppedReader = await LogReaderManager.Stop();

            Game.Reset();
            if (DeckList.Instance.ActiveDeck != null)
            {
                Game.SetPremadeDeck((Deck)DeckList.Instance.ActiveDeck.Clone());
                MainWindow.UpdateMenuItemVisibility();
            }
            if (stoppedReader)
            {
                LogReaderManager.Restart();
            }
            Overlay.Update(false);
            Overlay.UpdatePlayerCards();
            Windows.PlayerWindow.UpdatePlayerCards();
        }
Exemple #7
0
        public static async void Initialize()
        {
            Log.Info($"Operating System: {Helper.GetWindowsVersion()}, .NET Framework: {Helper.GetInstalledDotNetVersion()}");
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
            Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);
            Config.Load();
            var splashScreenWindow = new SplashScreenWindow();

#if (SQUIRREL)
            if (Config.Instance.CheckForUpdates)
            {
                var updateCheck = Updater.StartupUpdateCheck(splashScreenWindow);
                while (!updateCheck.IsCompleted)
                {
                    await Task.Delay(500);

                    if (splashScreenWindow.SkipUpdate)
                    {
                        break;
                    }
                }
            }
#endif
            splashScreenWindow.ShowConditional();
            Log.Initialize();
            ConfigManager.Run();
            var newUser = ConfigManager.PreviousVersion == null;
            LogConfigUpdater.Run().Forget();
            LogConfigWatcher.Start();
            Helper.UpdateAppTheme();
            ThemeManager.Run();
            ResourceMonitor.Run();
            Game = new GameV2();
            LoginType loginType;
            var       loggedIn = HearthStatsAPI.LoadCredentials();
            if (!loggedIn && Config.Instance.ShowLoginDialog)
            {
                var loginWindow = new LoginWindow();
                splashScreenWindow.Close();
                loginWindow.ShowDialog();
                if (loginWindow.LoginResult == LoginType.None)
                {
                    Application.Current.Shutdown();
                    return;
                }
                loginType          = loginWindow.LoginResult;
                splashScreenWindow = new SplashScreenWindow();
                splashScreenWindow.ShowConditional();
            }
            else
            {
                loginType = loggedIn ? LoginType.AutoLogin : LoginType.AutoGuest;
            }
            MainWindow = new MainWindow();
            MainWindow.LoadConfigSettings();
            if (Config.Instance.ReselectLastDeckUsed)
            {
                MainWindow.SelectLastUsedDeck();
                Config.Instance.ReselectLastDeckUsed = false;
                Config.Save();
            }
            MainWindow.Show();
            splashScreenWindow.Close();

            if (ConfigManager.UpdatedVersion != null)
            {
#if (!SQUIRREL)
                Updater.Cleanup();
#endif
                MainWindow.FlyoutUpdateNotes.IsOpen = true;
                MainWindow.UpdateNotesControl.SetHighlight(ConfigManager.PreviousVersion);
            }
            NetDeck.CheckForChromeExtention();
            DataIssueResolver.Run();

#if (!SQUIRREL)
            Helper.CopyReplayFiles();
#endif
            BackupManager.Run();

            if (Config.Instance.PlayerWindowOnStart)
            {
                Windows.PlayerWindow.Show();
            }
            if (Config.Instance.OpponentWindowOnStart)
            {
                Windows.OpponentWindow.Show();
            }
            if (Config.Instance.TimerWindowOnStartup)
            {
                Windows.TimerWindow.Show();
            }

            if (Config.Instance.HearthStatsSyncOnStart && HearthStatsAPI.IsLoggedIn)
            {
                HearthStatsManager.SyncAsync(background: true);
            }

            PluginManager.Instance.LoadPlugins();
            MainWindow.Options.OptionsTrackerPlugins.Load();
            PluginManager.Instance.StartUpdateAsync();

            UpdateOverlayAsync();

            if (Config.Instance.ShowCapturableOverlay)
            {
                Windows.CapturableOverlay = new CapturableOverlayWindow();
                Windows.CapturableOverlay.Show();
            }

            if (LogConfigUpdater.LogConfigUpdateFailed)
            {
                MainWindow.ShowLogConfigUpdateFailedMessage().Forget();
            }
            else if (LogConfigUpdater.LogConfigUpdated && Game.IsRunning)
            {
                MainWindow.ShowMessageAsync("Hearthstone restart required", "The log.config file has been updated. HDT may not work properly until Hearthstone has been restarted.");
                Overlay.ShowRestartRequiredWarning();
            }
            LogReaderManager.Start(Game).Forget();

            NewsUpdater.UpdateAsync();
            HotKeyManager.Load();

            if (Helper.HearthstoneDirExists && Config.Instance.StartHearthstoneWithHDT && !Game.IsRunning)
            {
                Helper.StartHearthstoneAsync().Forget();
            }

            Initialized = true;

            Influx.OnAppStart(Helper.GetCurrentVersion(), loginType, newUser);
        }
Exemple #8
0
        public static void Initialize()
        {
            Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);
            Config.Load();
            ConfigManager.Run();
            Logger.Initialzie();
            Helper.UpdateAppTheme();
            var splashScreenWindow = new SplashScreenWindow();

            splashScreenWindow.Show();
            Game = new GameV2();
            if (!HearthStatsAPI.LoadCredentials() && Config.Instance.ShowLoginDialog)
            {
                var loginWindow = new LoginWindow();
                splashScreenWindow.Close();
                loginWindow.ShowDialog();
                if (!loginWindow.LoginResult)
                {
                    Application.Current.Shutdown();
                    return;
                }
                splashScreenWindow = new SplashScreenWindow();
                splashScreenWindow.Show();
            }
            MainWindow = new MainWindow();
            MainWindow.LoadConfigSettings();
            MainWindow.Show();
            splashScreenWindow.Close();

            if (ConfigManager.UpdatedVersion != null)
            {
                Updater.Cleanup();
                MainWindow.FlyoutUpdateNotes.IsOpen = true;
                MainWindow.UpdateNotesControl.LoadUpdateNotes();
            }
            NetDeck.CheckForChromeExtention();
            DataIssueResolver.Run();

            if (Helper.HearthstoneDirExists)
            {
                if (Helper.UpdateLogConfig && Game.IsRunning)
                {
                    MainWindow.ShowMessageAsync("Restart Hearthstone",
                                                "This is either your first time starting HDT or the log.config file has been updated. Please restart Hearthstone, for HDT to work properly.");
                }
                LogReaderManager.Start(Game);
            }
            else
            {
                MainWindow.ShowHsNotInstalledMessage();
            }

            Helper.CopyReplayFiles();
            BackupManager.Run();

            if (Config.Instance.PlayerWindowOnStart)
            {
                Windows.PlayerWindow.Show();
            }
            if (Config.Instance.OpponentWindowOnStart)
            {
                Windows.OpponentWindow.Show();
            }
            if (Config.Instance.TimerWindowOnStartup)
            {
                Windows.TimerWindow.Show();
            }

            if (Config.Instance.HearthStatsSyncOnStart && HearthStatsAPI.IsLoggedIn)
            {
                HearthStatsManager.SyncAsync(background: true);
            }

            PluginManager.Instance.LoadPlugins();
            MainWindow.Options.OptionsTrackerPlugins.Load();
            PluginManager.Instance.StartUpdateAsync();

            UpdateOverlayAsync();
            NewsUpdater.UpdateAsync();
            Initialized = true;
        }
Exemple #9
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;
        }
Exemple #10
0
        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();
            }
        }
Exemple #11
0
        public static void Initialize()
        {
            Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);
            var newUser = !Directory.Exists(Config.AppDataPath);

            Config.Load();
            ConfigManager.Run();
            Logger.Initialize();
            Helper.UpdateAppTheme();
            var splashScreenWindow = new SplashScreenWindow();

            splashScreenWindow.ShowConditional();
            Game = new GameV2();
            LoginType loginType;
            var       loggedIn = HearthStatsAPI.LoadCredentials();

            if (!loggedIn && Config.Instance.ShowLoginDialog)
            {
                var loginWindow = new LoginWindow();
                splashScreenWindow.Close();
                loginWindow.ShowDialog();
                if (loginWindow.LoginResult == LoginType.None)
                {
                    Application.Current.Shutdown();
                    return;
                }
                loginType          = loginWindow.LoginResult;
                splashScreenWindow = new SplashScreenWindow();
                splashScreenWindow.ShowConditional();
            }
            else
            {
                loginType = loggedIn ? LoginType.AutoLogin : LoginType.AutoGuest;
            }
            MainWindow = new MainWindow();
            MainWindow.LoadConfigSettings();
            MainWindow.Show();
            splashScreenWindow.Close();

            if (ConfigManager.UpdatedVersion != null)
            {
                Updater.Cleanup();
                MainWindow.FlyoutUpdateNotes.IsOpen = true;
                MainWindow.UpdateNotesControl.LoadUpdateNotes();
            }
            NetDeck.CheckForChromeExtention();
            DataIssueResolver.Run();

            if (Helper.HearthstoneDirExists)
            {
                if (Helper.UpdateLogConfig && Game.IsRunning)
                {
                    MainWindow.ShowMessageAsync("Restart Hearthstone",
                                                "This is either your first time starting HDT or the log.config file has been updated. Please restart Hearthstone, for HDT to work properly.");
                }
                LogReaderManager.Start(Game);
            }
            else
            {
                MainWindow.ShowHsNotInstalledMessage();
            }

            Helper.CopyReplayFiles();
            BackupManager.Run();

            if (Config.Instance.PlayerWindowOnStart)
            {
                Windows.PlayerWindow.Show();
            }
            if (Config.Instance.OpponentWindowOnStart)
            {
                Windows.OpponentWindow.Show();
            }
            if (Config.Instance.TimerWindowOnStartup)
            {
                Windows.TimerWindow.Show();
            }

            if (Config.Instance.HearthStatsSyncOnStart && HearthStatsAPI.IsLoggedIn)
            {
                HearthStatsManager.SyncAsync(background: true);
            }

            PluginManager.Instance.LoadPlugins();
            MainWindow.Options.OptionsTrackerPlugins.Load();
            PluginManager.Instance.StartUpdateAsync();

            UpdateOverlayAsync();
            NewsUpdater.UpdateAsync();
            HotKeyManager.Load();
            Initialized = true;

            Analytics.Analytics.TrackPageView(
                string.Format("/app/v{0}/{1}{2}", Helper.GetCurrentVersion().ToVersionString(),
                              loginType.ToString().ToLower(), newUser ? "/new" : ""), "");
        }
Exemple #12
0
#pragma warning disable 4014
        public async void HandleGameEnd()
        {
            Helper.MainWindow.Overlay.HideTimers();
            if (_game.CurrentGameStats == null || _handledGameEnd)
            {
                return;
            }
            if (_game.CurrentGameMode == GameMode.Spectator && !Config.Instance.RecordSpectator)
            {
                Logger.WriteLine("Game is in Spectator mode, discarded. (Record Spectator disabled)", "GameEventHandler");
                _assignedDeck = null;
                return;
            }
            var player   = _game.Entities.FirstOrDefault(e => e.Value.IsPlayer);
            var opponent = _game.Entities.FirstOrDefault(e => e.Value.HasTag(GAME_TAG.PLAYER_ID) && !e.Value.IsPlayer);

            if (player.Value != null)
            {
                _game.CurrentGameStats.PlayerName = player.Value.Name;
            }
            if (opponent.Value != null && CardIds.HeroIdDict.ContainsValue(_game.CurrentGameStats.OpponentHero))
            {
                _game.CurrentGameStats.OpponentName = opponent.Value.Name;
            }
            else
            {
                _game.CurrentGameStats.OpponentName = _game.CurrentGameStats.OpponentHero;
            }

            _game.CurrentGameStats.Turns = LogReaderManager.GetTurnNumber();
            if (Config.Instance.DiscardZeroTurnGame && _game.CurrentGameStats.Turns < 1)
            {
                Logger.WriteLine("Game has 0 turns, discarded. (DiscardZeroTurnGame)", "GameEventHandler");
                _assignedDeck = null;
                GameEvents.OnGameEnd.Execute();
                return;
            }
            _game.CurrentGameStats.GameEnd();
            GameEvents.OnGameEnd.Execute();
            var selectedDeck = DeckList.Instance.ActiveDeck;

            if (selectedDeck != null)
            {
                if (Config.Instance.DiscardGameIfIncorrectDeck &&
                    !_game.Player.DrawnCards.All(
                        c =>
                        c.IsCreated ||
                        selectedDeck.GetSelectedDeckVersion().Cards.Any(c2 => c.Id == c2.Id && c.Count <= c2.Count)))
                {
                    if (Config.Instance.AskBeforeDiscardingGame)
                    {
                        var discardDialog = new DiscardGameDialog(_game.CurrentGameStats);
                        discardDialog.Topmost = true;
                        discardDialog.ShowDialog();
                        if (discardDialog.Result == DiscardGameDialogResult.Discard)
                        {
                            Logger.WriteLine("Assigned current game to NO deck - selected deck does not match cards played (dialogresult: discard)",
                                             "GameEventHandler");
                            _game.CurrentGameStats.DeleteGameFile();
                            _assignedDeck = null;
                            return;
                        }
                        if (discardDialog.Result == DiscardGameDialogResult.MoveToOther)
                        {
                            var moveDialog = new MoveGameDialog(DeckList.Instance.Decks.Where(d => d.Class == _game.CurrentGameStats.PlayerHero));
                            moveDialog.Topmost = true;
                            moveDialog.ShowDialog();
                            var targetDeck = moveDialog.SelectedDeck;
                            if (targetDeck != null)
                            {
                                selectedDeck = targetDeck;
                                _game.CurrentGameStats.PlayerDeckVersion        = moveDialog.SelectedVersion;
                                _game.CurrentGameStats.HearthStatsDeckVersionId = targetDeck.GetVersion(moveDialog.SelectedVersion).HearthStatsDeckVersionId;
                                //...continue as normal
                            }
                            else
                            {
                                Logger.WriteLine("No deck selected in move game dialog after discard dialog, discarding game", "GameEventHandler");
                                _game.CurrentGameStats.DeleteGameFile();
                                _assignedDeck = null;
                                return;
                            }
                        }
                    }
                    else
                    {
                        Logger.WriteLine("Assigned current game to NO deck - selected deck does not match cards played (no dialog)", "GameEventHandler");
                        _game.CurrentGameStats.DeleteGameFile();
                        _assignedDeck = null;
                        return;
                    }
                }
                else
                {
                    _game.CurrentGameStats.PlayerDeckVersion        = DeckList.Instance.ActiveDeckVersion.Version;
                    _game.CurrentGameStats.HearthStatsDeckVersionId = DeckList.Instance.ActiveDeckVersion.HearthStatsDeckVersionId;
                }

                _lastGame = _game.CurrentGameStats;
                selectedDeck.DeckStats.AddGameResult(_lastGame);
                selectedDeck.StatsUpdated();
                if (Config.Instance.ShowNoteDialogAfterGame && !Config.Instance.NoteDialogDelayed && !_showedNoteDialog)
                {
                    _showedNoteDialog = true;
                    new NoteDialog(_game.CurrentGameStats);
                }
                Logger.WriteLine("Assigned current game to deck: " + selectedDeck.Name, "GameStats");
                _assignedDeck = selectedDeck;

                // Unarchive the active deck after we have played a game with it
                if (_assignedDeck.Archived)
                {
                    Logger.WriteLine("Automatically unarchiving deck " + selectedDeck.Name + " after assigning current game", "GameEventHandler");
                    Helper.MainWindow.ArchiveDeck(_assignedDeck, false);
                }

                if (HearthStatsAPI.IsLoggedIn && Config.Instance.HearthStatsAutoUploadNewGames)
                {
                    if (_game.CurrentGameMode == GameMode.None)
                    {
                        await GameModeDetection(300); //give the user 5 minutes to get out of the victory/defeat screen
                    }
                    if (_game.CurrentGameMode == GameMode.Casual)
                    {
                        await LogReaderManager.RankedDetection();
                    }
                    if (_game.CurrentGameMode == GameMode.Ranked && !_lastGame.HasRank)
                    {
                        await RankDetection(5);
                    }
                    await GameModeSaved(15);

                    if (_game.CurrentGameMode == GameMode.Arena)
                    {
                        HearthStatsManager.UploadArenaMatchAsync(_lastGame, selectedDeck, background: true);
                    }
                    else if (_game.CurrentGameMode == GameMode.Brawl)
                    { /* do nothing */
                    }
                    else
                    {
                        HearthStatsManager.UploadMatchAsync(_lastGame, selectedDeck, background: true);
                    }
                }
                _lastGame = null;
            }
            else
            {
                DefaultDeckStats.Instance.GetDeckStats(_game.Player.Class).AddGameResult(_game.CurrentGameStats);
                Logger.WriteLine(string.Format("Assigned current deck to default {0} deck.", _game.Player.Class), "GameStats");
                _assignedDeck = null;
            }
        }
Exemple #13
0
        public static void Initialize()
        {
            Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);
            var newUser = !Directory.Exists(Config.AppDataPath);

            Config.Load();
            Log.Initialize();
            ConfigManager.Run();
            LogConfigUpdater.Run().Forget();
            LogConfigWatcher.Start();
            Helper.UpdateAppTheme();
            ThemeManager.Run();
            var splashScreenWindow = new SplashScreenWindow();

            splashScreenWindow.ShowConditional();
            Game = new GameV2();
            LoginType loginType;
            var       loggedIn = HearthStatsAPI.LoadCredentials();

            if (!loggedIn && Config.Instance.ShowLoginDialog)
            {
                var loginWindow = new LoginWindow();
                splashScreenWindow.Close();
                loginWindow.ShowDialog();
                if (loginWindow.LoginResult == LoginType.None)
                {
                    Application.Current.Shutdown();
                    return;
                }
                loginType          = loginWindow.LoginResult;
                splashScreenWindow = new SplashScreenWindow();
                splashScreenWindow.ShowConditional();
            }
            else
            {
                loginType = loggedIn ? LoginType.AutoLogin : LoginType.AutoGuest;
            }
            MainWindow = new MainWindow();
            MainWindow.LoadConfigSettings();
            if (Config.Instance.ReselectLastDeckUsed)
            {
                MainWindow.SelectLastUsedDeck();
                Config.Instance.ReselectLastDeckUsed = false;
                Config.Save();
            }
            MainWindow.Show();
            splashScreenWindow.Close();

            if (ConfigManager.UpdatedVersion != null)
            {
                Updater.Cleanup();
                MainWindow.FlyoutUpdateNotes.IsOpen = true;
                MainWindow.UpdateNotesControl.SetHighlight(ConfigManager.PreviousVersion);
                MainWindow.UpdateNotesControl.LoadUpdateNotes();
            }
            NetDeck.CheckForChromeExtention();
            DataIssueResolver.Run();

            Helper.CopyReplayFiles();
            BackupManager.Run();

            if (Config.Instance.PlayerWindowOnStart)
            {
                Windows.PlayerWindow.Show();
            }
            if (Config.Instance.OpponentWindowOnStart)
            {
                Windows.OpponentWindow.Show();
            }
            if (Config.Instance.TimerWindowOnStartup)
            {
                Windows.TimerWindow.Show();
            }

            if (Config.Instance.HearthStatsSyncOnStart && HearthStatsAPI.IsLoggedIn)
            {
                HearthStatsManager.SyncAsync(background: true);
            }

            PluginManager.Instance.LoadPlugins();
            MainWindow.Options.OptionsTrackerPlugins.Load();
            PluginManager.Instance.StartUpdateAsync();

            UpdateOverlayAsync();

            if (Config.Instance.ShowCapturableOverlay)
            {
                Windows.CapturableOverlay = new CapturableOverlayWindow();
                Windows.CapturableOverlay.Show();
            }

            if (LogConfigUpdater.LogConfigUpdateFailed)
            {
                MainWindow.ShowLogConfigUpdateFailedMessage().Forget();
            }
            else if (LogConfigUpdater.LogConfigUpdated && Game.IsRunning)
            {
                MainWindow.ShowMessageAsync("Hearthstone restart required", "The log.config file has been updated. HDT may not work properly until Hearthstone has been restarted.");
                Overlay.ShowRestartRequiredWarning();
            }
            LogReaderManager.Start(Game).Forget();

            NewsUpdater.UpdateAsync();
            HotKeyManager.Load();

            if (Helper.HearthstoneDirExists && Config.Instance.StartHearthstoneWithHDT && !Game.IsRunning)
            {
                Helper.StartHearthstoneAsync();
            }

            Initialized = true;

            Analytics.Analytics.TrackPageView($"/app/v{Helper.GetCurrentVersion().ToVersionString()}/{loginType.ToString().ToLower()}{(newUser ? "/new" : "")}", "");
        }