internal static async void UpdateAsync() { const string url = "https://raw.githubusercontent.com/Epix37/HDT-Data/master/news"; _update = true; _lastNewsCheck = DateTime.MinValue; _lastNewsUpdate = DateTime.MinValue; CurrentNewsId = Config.Instance.IgnoreNewsId; _lastHearthStatsSync = DateTime.Now; while (_update) { if ((DateTime.Now - _lastNewsCheck) > TimeSpan.FromSeconds(NewsCheckInterval)) { try { var oldNewsId = CurrentNewsId; using (var client = new WebClient()) { var raw = await client.DownloadStringTaskAsync(url); var content = raw.Split(new[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim()).ToArray(); try { CurrentNewsId = int.Parse(content[0].Split(':')[1].Trim()); } catch (Exception) { CurrentNewsId = 0; } _news = content.Skip(1).ToArray(); } if (CurrentNewsId > oldNewsId || Core.MainWindow.StatusBarNews.Visibility == Visibility.Collapsed && CurrentNewsId > Config.Instance.IgnoreNewsId) { Core.MainWindow.TopRow.Height = new GridLength(26); Core.MainWindow.StatusBarNews.Visibility = Visibility.Visible; Core.MainWindow.MinHeight += Core.MainWindow.StatusBarNewsHeight; UpdateNews(0); } } catch (Exception e) { Logger.WriteLine("Error loading news: " + e, "UpdateNews"); } _lastNewsCheck = DateTime.Now; } if ((DateTime.Now - _lastNewsUpdate) > TimeSpan.FromSeconds(NewsTickerUpdateInterval)) { UpdateNews(); } if (HearthStatsAPI.IsLoggedIn && Config.Instance.HearthStatsAutoSyncInBackground && (DateTime.Now - _lastHearthStatsSync) > TimeSpan.FromSeconds(HearthStatsAutoSyncInterval)) { _lastHearthStatsSync = DateTime.Now; HearthStatsManager.SyncAsync(background: true); } await Task.Delay(1000); } }
private static async void StartGeneralServer() { Log.Info("Started server"); var exceptionCount = 0; while (exceptionCount < 10) { try { using (var pipe = new NamedPipeServerStream("hdtgeneral", PipeDirection.In, 1, PipeTransmissionMode.Message)) { Log.Info("Waiting for connecetion..."); await Task.Run(() => pipe.WaitForConnection()); using (var sr = new StreamReader(pipe)) { var line = sr.ReadLine(); switch (line) { case "sync": HearthStatsManager.SyncAsync(false, true); break; } Log.Info(line); } } } catch (Exception ex) { Log.Error(ex); exceptionCount++; } } Log.Info("Closed server. ExceptionCount=" + exceptionCount); }
private async void MetroWindow_Loaded(object sender, RoutedEventArgs e) { var presentationsource = PresentationSource.FromVisual(this); if(presentationsource != null) // make sure it's connected { Helper.DpiScalingX = presentationsource.CompositionTarget.TransformToDevice.M11; Helper.DpiScalingY = presentationsource.CompositionTarget.TransformToDevice.M22; } ManaCurveMyDecks.UpdateValues(); if(_updatedVersion != null) await this.ShowUpdateNotesMessage(); if(!_foundHsDirectory) await this.ShowHsNotInstalledMessage(); else if(_updatedLogConfig) { await this.ShowMessage("Restart Hearthstone", "This is either your first time starting the tracker or the log.config file has been updated. Please restart Heartstone once, for the tracker to work properly."); } if(!Config.Instance.ResolvedDeckStatsIds) { if(ResolveDeckStatsIds()) await Restart(); } if(Config.Instance.HearthStatsSyncOnStart && HearthStatsAPI.IsLoggedIn) HearthStatsManager.SyncAsync(background: true); }
private async void MenuItemHearthStatsForceFullSync_OnClick(object sender, RoutedEventArgs e) { var result = await this.ShowMessageAsync("Full sync", "This may take a while, are you sure?", MessageDialogStyle.AffirmativeAndNegative, new MetroDialogSettings { AffirmativeButtonText = "start full sync", NegativeButtonText = "cancel" }); if (result == MessageDialogResult.Affirmative) { HearthStatsManager.SyncAsync(true); } }
private async void MetroWindow_Loaded(object sender, RoutedEventArgs e) { var presentationsource = PresentationSource.FromVisual(this); if (presentationsource != null) // make sure it's connected { Helper.DpiScalingX = presentationsource.CompositionTarget.TransformToDevice.M11; Helper.DpiScalingY = presentationsource.CompositionTarget.TransformToDevice.M22; } ManaCurveMyDecks.UpdateValues(); if (_updatedVersion != null) { FlyoutUpdateNotes.IsOpen = true; UpdateNotesControl.LoadUpdateNotes(); //await this.ShowUpdateNotesMessage(); } if (!_foundHsDirectory) { await this.ShowHsNotInstalledMessage(); } else if (_updatedLogConfig && _game.IsRunning) { await this.ShowMessage("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."); } if (!Config.Instance.FixedDuplicateMatches) { RemoveDuplicateMatches(false); } if (!Config.Instance.ResolvedOpponentNames) { ResolveOpponentNames(); } if (!Config.Instance.ResolvedDeckStatsIds) { ResolveDeckStatsIds(); //Restart(); } if (Config.Instance.HearthStatsSyncOnStart && HearthStatsAPI.IsLoggedIn) { HearthStatsManager.SyncAsync(background: true); } //SetupProtocol(); turn on later }
private async void BtnLogin_Click(object sender, RoutedEventArgs e) { var email = TextBoxEmail.Text; if (string.IsNullOrEmpty(email) || !Regex.IsMatch(email, @".*@.*\..*")) { DisplayLoginError("Please enter an valid email address"); return; } if (string.IsNullOrEmpty(TextBoxPassword.Password)) { DisplayLoginError("Please enter a password"); return; } IsEnabled = false; var result = await HearthStatsAPI.LoginAsync(TextBoxEmail.Text, TextBoxPassword.Password); TextBoxPassword.Clear(); if (result.Success) { Core.MainWindow.EnableHearthStatsMenu(true); Core.MainWindow.FlyoutHearthStatsLogin.IsOpen = false; Core.MainWindow.MenuItemLogin.Visibility = Visibility.Collapsed; Core.MainWindow.MenuItemLogout.Visibility = Visibility.Visible; Core.MainWindow.SeparatorLogout.Visibility = Visibility.Visible; Core.MainWindow.MenuItemLogout.Header = $"LOGOUT ({HearthStatsAPI.LoggedInAs})"; var dialogResult = await Core.MainWindow.ShowMessageAsync("Sync now?", "Do you want to sync with HearthStats now?", MessageDialogStyle.AffirmativeAndNegative, new MessageDialogs.Settings { AffirmativeButtonText = "sync now", NegativeButtonText = "later" }); if (dialogResult == MessageDialogResult.Affirmative) { HearthStatsManager.SyncAsync(); } } else { DisplayLoginError(result.Message); } }
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); }
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; }
private void MenuItemHearthStatsSync_OnClick(object sender, RoutedEventArgs e) => HearthStatsManager.SyncAsync();
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" : ""), ""); }
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" : "")}", ""); }