private async void BtnStartHearthstone_Click(object sender, RoutedEventArgs e)
        {
            BtnStartHearthstone.IsEnabled = false;
            ButtonStartHearthstoneText    = LocUtil.Get(StartHearthstoneWaitingText, true);
            HearthstoneRunner.StartHearthstone().Forget();
            await Task.Delay(5000);

            BtnStartHearthstone.IsEnabled = true;
        }
        public TrayIcon()
        {
            NotifyIcon = new NotifyIcon
            {
                Visible     = true,
                ContextMenu = new ContextMenu(),
                Text        = "Hearthstone Deck Tracker"
            };

            var iconFile = new FileInfo("Images/HearthstoneDeckTracker16.ico");

            if (iconFile.Exists)
            {
                NotifyIcon.Icon = new Icon(iconFile.FullName);
            }
            else
            {
                Log.Error($"Cant find tray icon at \"{iconFile.FullName}\"");
            }

            MenuItemStartHearthstone = new MenuItem(LocUtil.Get("TrayIcon_MenuItemStartHearthstone"), (sender, args) => HearthstoneRunner.StartHearthstone().Forget());
            NotifyIcon.ContextMenu.MenuItems.Add(MenuItemStartHearthstone);
            HearthstoneRunner.StartingHearthstone += starting => MenuItemStartHearthstone.Enabled = !starting;

            MenuItemUseNoDeck = new MenuItem(LocUtil.Get("TrayIcon_MenuItemUseNoDeck"), (sender, args) => UseNoDeckContextMenu());
            NotifyIcon.ContextMenu.MenuItems.Add(MenuItemUseNoDeck);

            MenuItemAutoSelect = new MenuItem(LocUtil.Get("TrayIcon_MenuItemAutoSelect"), (sender, args) => AutoDeckDetectionContextMenu());
            NotifyIcon.ContextMenu.MenuItems.Add(MenuItemAutoSelect);

            MenuItemClassCardsFirst = new MenuItem(LocUtil.Get("TrayIcon_MenuItemClassCardsFirst"), (sender, args) => SortClassCardsFirstContextMenu());
            NotifyIcon.ContextMenu.MenuItems.Add(MenuItemClassCardsFirst);

            MenuItemShow = new MenuItem(LocUtil.Get("TrayIcon_MenuItemShow"), (sender, args) => Core.MainWindow.ActivateWindow());
            NotifyIcon.ContextMenu.MenuItems.Add(MenuItemShow);

            MenuItemExit = new MenuItem(LocUtil.Get("TrayIcon_MenuItemExit"), (sender, args) => Core.MainWindow.Close());
            NotifyIcon.ContextMenu.MenuItems.Add(MenuItemExit);

            NotifyIcon.MouseClick += (sender, args) =>
            {
                if (args.Button == MouseButtons.Left)
                {
                    Core.MainWindow.ActivateWindow();
                }
            };

            NotifyIcon.BalloonTipClicked += (sender1, e) => { Core.MainWindow.ActivateWindow(); };
        }
Example #3
0
#pragma warning disable 1998
        public static async void Initialize()
#pragma warning restore 1998
        {
            LocalizeDictionary.Instance.Culture = CultureInfo.GetCultureInfo("en-US");
            _startUpTime = DateTime.UtcNow;
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
            Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);
            Config.Load();
            Log.Info($"HDT: {Helper.GetCurrentVersion()}, Operating System: {Helper.GetWindowsVersion()}, .NET Framework: {Helper.GetInstalledDotNetVersion()}");
            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();
            Reflection.Exception += e => Log.Warn("HearthMirror Exception: " + e);
            ConfigManager.Run();
            LocUtil.UpdateCultureInfo();
            var newUser = ConfigManager.PreviousVersion == null;
            LogConfigUpdater.Run().Forget();
            LogConfigWatcher.Start();
            UITheme.InitializeTheme().Forget();
            ThemeManager.Run();
            ResourceMonitor.Run();
            Game = new GameV2();
            Game.SecretsManager.OnSecretsChanged += cards => Overlay.ShowSecrets(cards);
            MainWindow = new MainWindow();
            MainWindow.LoadConfigSettings();
            MainWindow.Show();
            splashScreenWindow.Close();

            if (Config.Instance.DisplayHsReplayNoteLive && ConfigManager.PreviousVersion != null && ConfigManager.PreviousVersion < new Version(1, 1, 0))
            {
                MainWindow.FlyoutHsReplayNote.IsOpen = true;
            }

            if (ConfigManager.UpdatedVersion != null)
            {
#if (!SQUIRREL)
                Updater.Cleanup();
#endif
                MainWindow.FlyoutUpdateNotes.IsOpen = true;
                MainWindow.UpdateNotesControl.SetHighlight(ConfigManager.PreviousVersion);
#if (SQUIRREL && !DEV)
                if (Config.Instance.CheckForDevUpdates && !Config.Instance.AllowDevUpdates.HasValue)
                {
                    MainWindow.ShowDevUpdatesMessage();
                }
#endif
            }
            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();
            }

            PluginManager.Instance.LoadPluginsFromDefaultPath();
            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.").Forget();
                Overlay.ShowRestartRequiredWarning();
            }
            LogWatcherManger.Start(Game).Forget();

            RemoteConfig.Instance.Load();
            HotKeyManager.Load();

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

            HSReplayNetHelper.UpdateAccount().Forget();

            Initialized = true;

            Influx.OnAppStart(
                Helper.GetCurrentVersion(),
                newUser,
                HSReplayNetOAuth.IsFullyAuthenticated,
                HSReplayNetOAuth.AccountData?.IsPremium?.Equals("true", StringComparison.InvariantCultureIgnoreCase) ?? false,
                (int)(DateTime.UtcNow - _startUpTime).TotalSeconds,
                PluginManager.Instance.Plugins.Count
                );
        }
 public static void StartHearthstone()
 {
     HearthstoneRunner.StartHearthstone().Forget();
 }
Example #5
0
        public async Task StartArenaImporting()
        {
            ProgressDialogController controller = null;

            if (!Core.Game.IsRunning)
            {
                Log.Info("Waiting for game...");
                var result = await this.ShowMessageAsync("Importing arena deck", "Start Hearthstone and enter the 'Arena' screen.",
                                                         MessageDialogStyle.AffirmativeAndNegative,
                                                         new MessageDialogs.Settings()
                {
                    AffirmativeButtonText = "Start Hearthstone", NegativeButtonText = "Cancel"
                });

                if (result == MessageDialogResult.Negative)
                {
                    return;
                }
                HearthstoneRunner.StartHearthstone().Forget();
                controller = await this.ShowProgressAsync("Importing arena deck", "Waiting for Hearthstone...", true);

                while (!Core.Game.IsRunning)
                {
                    if (controller.IsCanceled)
                    {
                        await controller.CloseAsync();

                        return;
                    }
                    await Task.Delay(500);
                }
            }
            if (Core.Game.CurrentMode != Mode.DRAFT)
            {
                if (controller == null)
                {
                    controller = await this.ShowProgressAsync("Importing arena deck", "", true);
                }
                controller.SetMessage("Enter the 'Arena' screen.");
                Log.Info("Waiting for DRAFT screen...");
                while (Core.Game.CurrentMode != Mode.DRAFT)
                {
                    if (controller.IsCanceled)
                    {
                        await controller.CloseAsync();

                        return;
                    }
                    await Task.Delay(500);
                }
            }
            var deck = DeckImporter.FromArena()?.Deck;

            while (deck == null || deck.Cards.Sum(x => x.Count) < 30)
            {
                if (controller == null)
                {
                    controller = await this.ShowProgressAsync("Importing arena deck", "", true);
                }
                if (controller.IsCanceled)
                {
                    await controller.CloseAsync();

                    return;
                }
                controller.SetMessage($"Waiting for complete deck ({deck?.Cards.Sum(x => x.Count) ?? 0}/30 cards)...");
                await Task.Delay(1000);

                deck = DeckImporter.FromArena(false)?.Deck;
            }
            if (controller != null)
            {
                await controller.CloseAsync();
            }
            var recentArenaDecks = DeckList.Instance.Decks.Where(d => d.IsArenaDeck && d.Cards.Sum(x => x.Count) == 30).OrderByDescending(d => d.LastPlayedNewFirst).Take(15);
            var existing         = recentArenaDecks.FirstOrDefault(d => d.Cards.All(c => deck.Cards.Any(c2 => c.Id == c2.Id && c.Count == c2.Count)));

            if (existing != null)
            {
                var result = await this.ShowMessageAsync("Deck already exists", "You seem to already have this deck.",
                                                         MessageDialogStyle.AffirmativeAndNegative,
                                                         new MessageDialogs.Settings()
                {
                    AffirmativeButtonText = "Use existing", NegativeButtonText = "Import anyway"
                });

                if (result == MessageDialogResult.Affirmative)
                {
                    SelectDeck(existing, true);
                    return;
                }
            }
            ImportArenaDeck(deck);
        }