private void StartMainApp() { IsEnabled = false; var mainWindow = new MainWindow(); try { mainWindow.Show(); } catch(Exception ex) { Logger.WriteLine("Error showing main window: " + ex, "LoginWindow"); } Close(); }
#pragma warning disable 1998 public static async void Initialize() #pragma warning restore 1998 { 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.").Forget(); 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); }
private async void BtnRegister_Click(object sender, RoutedEventArgs e) { if(!CheckBoxPrivacyPolicy.IsChecked == true) return; var email = TextBoxRegisterEmail.Text; if(string.IsNullOrEmpty(email) || !Regex.IsMatch(email, @".*@.*\..*")) { DisplayLoginError("Please enter an valid email address"); return; } if(string.IsNullOrEmpty(TextBoxRegisterPassword.Password)) { DisplayLoginError("Please enter a password"); return; } if(TextBoxRegisterPassword.Password.Length < 6) { DisplayLoginError("Your password needs to be at least 6 characters"); return; } if(string.IsNullOrEmpty(TextBoxRegisterPasswordConfirm.Password)) { DisplayLoginError("Please confirm your password"); return; } if(!TextBoxRegisterPassword.Password.Equals(TextBoxRegisterPasswordConfirm.Password)) { DisplayLoginError("Entered passwords do not match"); return; } IsEnabled = false; _controller = await this.ShowProgressAsync("Registering account...", ""); var result = await HearthStatsAPI.RegisterAsync(email, TextBoxRegisterPassword.Password); if(result.Success) { _controller.SetTitle("Logging in..."); result = await HearthStatsAPI.LoginAsync(email, TextBoxRegisterPassword.Password); } else if(result.Message.Contains("422")) DisplayLoginError("Email already registered"); else DisplayLoginError(result.Message); TextBoxRegisterPassword.Clear(); TextBoxRegisterPasswordConfirm.Clear(); if(result.Success) { var mw = new MainWindow(); mw.Show(); Close(); } }
private static async void UpdateOverlayAsync() { #if (!SQUIRREL) if (Config.Instance.CheckForUpdates) { Updater.CheckForUpdates(true); } #endif var hsForegroundChanged = false; var useNoDeckMenuItem = TrayIcon.NotifyIcon.ContextMenu.MenuItems.IndexOfKey("startHearthstone"); while (UpdateOverlay) { if (Config.Instance.CheckForUpdates) { Updater.CheckForUpdates(); } if (User32.GetHearthstoneWindow() != IntPtr.Zero) { if (Game.CurrentRegion == Region.UNKNOWN) { //game started Helper.VerifyHearthstonePath(); Game.CurrentRegion = await Helper.GetCurrentRegion(); if (Game.CurrentRegion != Region.UNKNOWN) { BackupManager.Run(); Game.MetaData.HearthstoneBuild = null; } } Overlay.UpdatePosition(); if (!Game.IsRunning) { Overlay.Update(true); Windows.CapturableOverlay?.UpdateContentVisibility(); } MainWindow.BtnStartHearthstone.Visibility = Visibility.Collapsed; TrayIcon.NotifyIcon.ContextMenu.MenuItems[useNoDeckMenuItem].Visible = false; Game.IsRunning = true; Helper.GameWindowState = User32.GetHearthstoneWindowState(); Windows.CapturableOverlay?.Update(); if (User32.IsHearthstoneInForeground() && Helper.GameWindowState != WindowState.Minimized) { 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 if (Game.IsRunning) { Game.IsRunning = false; Overlay.ShowOverlay(false); if (Windows.CapturableOverlay != null) { Windows.CapturableOverlay.UpdateContentVisibility(); await Task.Delay(100); Windows.CapturableOverlay.ForcedWindowState = WindowState.Minimized; Windows.CapturableOverlay.WindowState = WindowState.Minimized; } Log.Info("Exited game"); Game.CurrentRegion = Region.UNKNOWN; Log.Info("Reset region"); await Reset(); Game.IsInMenu = true; Game.InvalidateMatchInfoCache(); Overlay.HideRestartRequiredWarning(); Helper.ClearCachedHearthstoneBuild(); TurnTimer.Instance.Stop(); MainWindow.BtnStartHearthstone.Visibility = Visibility.Visible; TrayIcon.NotifyIcon.ContextMenu.MenuItems[useNoDeckMenuItem].Visible = true; if (Config.Instance.CloseWithHearthstone) { MainWindow.Close(); } } if (Config.Instance.NetDeckClipboardCheck.HasValue && Config.Instance.NetDeckClipboardCheck.Value && Initialized && !User32.IsHearthstoneInForeground()) { NetDeck.CheckForClipboardImport(); } await Task.Delay(UpdateDelay); } CanShutdown = true; }