private void StartMainApp()
		{
			IsEnabled = false;
			var mainWindow = new MainWindow();
			try
			{
				mainWindow.Show();
			}
			catch(Exception ex)
			{
				Logger.WriteLine("Error showing main window: " + ex, "LoginWindow");
			}
			Close();
		}
		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();
			}
		}
        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();
            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.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" : ""), "");
        }
        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();
            }
        }
        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);
        }
Exemple #6
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" : "")}", "");
        }
#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)
            {
                ShowRestartRequiredMessageAsync().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
                );
        }