public MainWindow() { // Set working directory to path of executable Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory); InitializeComponent(); EnableMenuItems(false); try { if (File.Exists("Updater_new.exe")) { if (File.Exists("Updater.exe")) { File.Delete("Updater.exe"); } File.Move("Updater_new.exe", "Updater.exe"); } } catch { Logger.WriteLine("Error updating updater"); } Helper.MainWindow = this; /*_configPath =*/ Config.Load(); HsLogReader.Create(); var configVersion = string.IsNullOrEmpty(Config.Instance.CreatedByVersion) ? null : new Version(Config.Instance.CreatedByVersion); Version currentVersion; if (Config.Instance.CheckForUpdates) { currentVersion = Helper.CheckForUpdates(out NewVersion); _lastUpdateCheck = DateTime.Now; } else { currentVersion = Helper.GetCurrentVersion(); } var versionString = string.Empty; if (currentVersion != null) { versionString = string.Format("{0}.{1}.{2}", currentVersion.Major, currentVersion.Minor, currentVersion.Build); Help.TxtblockVersion.Text = "Version: " + versionString; // Assign current version to the config instance so that it will be saved when the config // is rewritten to disk, thereby telling us what version of the application created it Config.Instance.CreatedByVersion = currentVersion.ToString(); } ConvertLegacyConfig(currentVersion, configVersion); if (Config.Instance.SelectedTags.Count == 0) { Config.Instance.SelectedTags.Add("All"); } if (Config.Instance.GenerateLog) { Directory.CreateDirectory("Logs"); var listener = new TextWriterTraceListener(Config.Instance.LogFilePath); Trace.Listeners.Add(listener); Trace.AutoFlush = true; } _foundHsDirectory = FindHearthstoneDir(); if (_foundHsDirectory) { _updatedLogConfig = UpdateLogConfigFile(); } //hearthstone, loads db etc - needs to be loaded before playerdecks, since cards are only saved as ids now Game.Reset(); _decksPath = Config.Instance.DataDir + "PlayerDecks.xml"; SetupDeckListFile(); try { DeckList = XmlManager <Decks> .Load(_decksPath); } catch (Exception e) { MessageBox.Show( e.Message + "\n\n" + e.InnerException + "\n\n If you don't know how to fix this, please delete " + _decksPath + " (this will cause you to lose your decks).", "Error loading PlayerDecks.xml"); Application.Current.Shutdown(); } foreach (var deck in DeckList.DecksList) { DeckPickerList.AddDeck(deck); } SetupDeckStatsFile(); DeckStatsList.Load(); _notifyIcon = new NotifyIcon { Icon = new Icon(@"Images/HearthstoneDeckTracker16.ico"), Visible = true, ContextMenu = new ContextMenu(), Text = "Hearthstone Deck Tracker v" + versionString }; _notifyIcon.ContextMenu.MenuItems.Add("Show", (sender, args) => ActivateWindow()); _notifyIcon.ContextMenu.MenuItems.Add("Exit", (sender, args) => Close()); _notifyIcon.MouseClick += (sender, args) => { if (args.Button == MouseButtons.Left) { ActivateWindow(); } }; //create overlay Overlay = new OverlayWindow { Topmost = true }; PlayerWindow = new PlayerWindow(Config.Instance, Game.IsUsingPremade ? Game.PlayerDeck : Game.PlayerDrawn); OpponentWindow = new OpponentWindow(Config.Instance, Game.OpponentCards); TimerWindow = new TimerWindow(Config.Instance); StatsWindow = new StatsWindow(); if (Config.Instance.PlayerWindowOnStart) { PlayerWindow.Show(); } if (Config.Instance.OpponentWindowOnStart) { OpponentWindow.Show(); } if (Config.Instance.TimerWindowOnStartup) { TimerWindow.Show(); } if (!DeckList.AllTags.Contains("All")) { DeckList.AllTags.Add("All"); WriteDecks(); } if (!DeckList.AllTags.Contains("Arena")) { DeckList.AllTags.Add("Arena"); WriteDecks(); } if (!DeckList.AllTags.Contains("Constructed")) { DeckList.AllTags.Add("Constructed"); WriteDecks(); } Options.ComboboxAccent.ItemsSource = ThemeManager.Accents; Options.ComboboxTheme.ItemsSource = ThemeManager.AppThemes; Options.ComboboxLanguages.ItemsSource = Helper.LanguageDict.Keys; Options.ComboboxKeyPressGameStart.ItemsSource = EventKeys; Options.ComboboxKeyPressGameEnd.ItemsSource = EventKeys; LoadConfig(); FillElementSorters(); //this has to happen before reader starts var lastDeck = DeckList.DecksList.FirstOrDefault(d => d.Name == Config.Instance.LastDeck); DeckPickerList.SelectDeck(lastDeck); TurnTimer.Create(90); SortFilterDecksFlyout.HideStuffToCreateNewTag(); TagControlEdit.OperationSwitch.Visibility = Visibility.Collapsed; TagControlEdit.PnlSortDecks.Visibility = Visibility.Collapsed; UpdateDbListView(); _doUpdate = _foundHsDirectory; UpdateOverlayAsync(); _initialized = true; Options.MainWindowInitialized(); DeckPickerList.UpdateList(); if (lastDeck != null) { DeckPickerList.SelectDeck(lastDeck); UpdateDeckList(lastDeck); UseDeck(lastDeck); } if (_foundHsDirectory) { HsLogReader.Instance.Start(); } Helper.SortCardCollection(ListViewDeck.Items, Config.Instance.CardSortingClassFirst); DeckPickerList.SortDecks(); }
public static async void Initialize() { LocalizeDictionary.Instance.Culture = CultureInfo.GetCultureInfo("en-US"); _startUpTime = DateTime.UtcNow; Log.Info($"HDT: {Helper.GetCurrentVersion()}, 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(); LocUtil.UpdateCultureInfo(); var newUser = ConfigManager.PreviousVersion == null; LogConfigUpdater.Run().Forget(); LogConfigWatcher.Start(); Helper.UpdateAppTheme(); ThemeManager.Run(); ResourceMonitor.Run(); Game = new GameV2(); 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); } 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(); } 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."); Overlay.ShowRestartRequiredWarning(); } LogWatcherManger.Start(Game).Forget(); NewsManager.LoadNews(); HotKeyManager.Load(); if (Helper.HearthstoneDirExists && Config.Instance.StartHearthstoneWithHDT && !Game.IsRunning) { Helper.StartHearthstoneAsync().Forget(); } ApiWrapper.UpdateAccountStatus().Forget(); Initialized = true; Influx.OnAppStart(Helper.GetCurrentVersion(), newUser, (int)(DateTime.UtcNow - _startUpTime).TotalSeconds); }
#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 CheckForHearthstoneUpdate(); } 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) { ShowRestartRequiredMessageAsync().Forget(); Overlay.ShowRestartRequiredWarning(); } LogWatcherManger.Start(Game).Forget(); RemoteConfig.Instance.Loaded += CheckForCardImageUpdate; RemoteConfig.Instance.Load(); HotKeyManager.Load(); if (Helper.HearthstoneDirExists && Config.Instance.StartHearthstoneWithHDT && !Game.IsRunning) { HearthstoneRunner.StartHearthstone().Forget(); } HSReplayNetHelper.UpdateAccount().Forget(); AssetDownloaders.SetupAssetDownloaders(); 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 async void Initialize() { ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls; Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory); var newUser = !Directory.Exists(Config.AppDataPath); Config.Load(); var splashScreenWindow = new SplashScreenWindow(); splashScreenWindow.ShowConditional(); #if (SQUIRREL) if (Config.Instance.CheckForUpdates) { var updateCheck = Updater.StartupUpdateCheck(splashScreenWindow); while (!updateCheck.IsCompleted) { await Task.Delay(500); if (splashScreenWindow.SkipWasPressed) { break; } } } #endif Log.Initialize(); ConfigManager.Run(); LogConfigUpdater.Run().Forget(); LogConfigWatcher.Start(); Helper.UpdateAppTheme(); ThemeManager.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); MainWindow.UpdateNotesControl.LoadUpdateNotes(); } 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); }
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" : "")}", ""); }
public static void Initialize() { Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory); var newUser = !Directory.Exists(Config.AppDataPath); Config.Load(); ConfigManager.Run(); Logger.Initialzie(); 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" : ""), ""); }