private void SetupHeadlines() { try { _bannerChangeTimer?.Stop(); _headlines = Headlines.Get(_game); _bannerBitmaps = new BitmapImage[_headlines.Banner.Length]; for (var i = 0; i < _headlines.Banner.Length; i++) { var imageBytes = _game.DownloadAsLauncher(_headlines.Banner[i].LsbBanner.ToString()); using (var stream = new MemoryStream(imageBytes)) { var bitmapImage = new BitmapImage(); bitmapImage.BeginInit(); bitmapImage.StreamSource = stream; bitmapImage.CacheOption = BitmapCacheOption.OnLoad; bitmapImage.EndInit(); bitmapImage.Freeze(); _bannerBitmaps[i] = bitmapImage; } } this.Dispatcher.BeginInvoke(new Action(() => { BannerImage.Source = _bannerBitmaps[0]; })); _bannerChangeTimer = new System.Timers.Timer { Interval = 5000 }; _bannerChangeTimer.Elapsed += (o, args) => { if (_currentBannerIndex + 1 > _headlines.Banner.Length - 1) { _currentBannerIndex = 0; } else { _currentBannerIndex++; } this.Dispatcher.BeginInvoke(new Action(() => { BannerImage.Source = _bannerBitmaps[_currentBannerIndex]; })); }; _bannerChangeTimer.AutoReset = true; _bannerChangeTimer.Start(); this.Dispatcher.BeginInvoke(new Action(() => { NewsListView.ItemsSource = _headlines.News; })); } catch (Exception) { this.Dispatcher.BeginInvoke(new Action(() => { NewsListView.Items.Add(new News() { Title = "Could not download news data.", Tag = "DlError" }); })); } }
private void InitializeWindow() { var gateStatus = XIVGame.GetGateStatus(); if (!gateStatus) { WorldStatusPackIcon.Foreground = new SolidColorBrush(Color.FromRgb(242, 24, 24)); } var savedCredentials = CredentialManager.GetCredentials(AppName); if (savedCredentials != null) { LoginUsername.Text = savedCredentials.UserName; LoginPassword.Password = savedCredentials.Password; OtpCheckBox.IsChecked = Settings.NeedsOtp(); AutoLoginCheckBox.IsChecked = Settings.IsAutologin(); SaveLoginCheckBox.IsChecked = true; } if (Settings.IsAutologin() && !Settings.IsAdministrator() && savedCredentials != null) { try { if (!gateStatus) { MessageBox.Show( "Square Enix seems to be running maintenance work right now. The game shouldn't be launched."); Settings.SetAutologin(false); } else { HandleLogin(true); } } catch (Exception exc) { Util.ShowError("Logging in failed, check your login information or try again.\n\n" + exc, "Login failed"); Settings.SetAutologin(false); } Settings.Save(); } if (Settings.GetGamePath() == string.Empty) { var setup = new FirstTimeSetup(); setup.ShowDialog(); } try { _headlines = Headlines.Get(); _bannerBitmaps = new BitmapImage[_headlines.Banner.Length]; for (int i = 0; i < _headlines.Banner.Length; i++) { var bitmap = new BitmapImage(); bitmap.BeginInit(); bitmap.UriSource = _headlines.Banner[i].LsbBanner; bitmap.EndInit(); _bannerBitmaps[i] = bitmap; } _bannerChangeTimer = new System.Timers.Timer { Interval = 5000 }; _bannerChangeTimer.Elapsed += (o, args) => { if (_currentBannerIndex + 1 > _headlines.Banner.Length - 1) { _currentBannerIndex = 0; } else { _currentBannerIndex++; } this.Dispatcher.BeginInvoke(new Action(() => { BannerImage.Source = _bannerBitmaps[_currentBannerIndex]; })); _bannerChangeTimer.Start(); }; _bannerChangeTimer.Start(); NewsListView.ItemsSource = _headlines.News; } catch (Exception) { NewsListView.Items.Add(new News() { Title = "Could not download news data.", Tag = "DlError" }); } this.Visibility = Visibility.Visible; }
private void InitializeWindow() { // Upgrade the stored settings if needed if (Properties.Settings.Default.UpgradeRequired) { Properties.Settings.Default.Upgrade(); Properties.Settings.Default.UpgradeRequired = false; Properties.Settings.Default.Save(); } // Check if dark mode is enabled on windows, if yes, load the dark theme var themeUri = new Uri("pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml", UriKind.RelativeOrAbsolute); if (Util.IsWindowsDarkModeEnabled()) { themeUri = new Uri("pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Dark.xaml", UriKind.RelativeOrAbsolute); } Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary() { Source = themeUri }); var gateStatus = false; try { gateStatus = _game.GetGateStatus(); } catch { // ignored } if (!gateStatus) { WorldStatusPackIcon.Foreground = new SolidColorBrush(Color.FromRgb(242, 24, 24)); } var savedCredentials = CredentialManager.GetCredentials(AppName); if (savedCredentials != null) { LoginUsername.Text = savedCredentials.UserName; LoginPassword.Password = savedCredentials.Password; OtpCheckBox.IsChecked = Settings.NeedsOtp(); AutoLoginCheckBox.IsChecked = Settings.IsAutologin(); SaveLoginCheckBox.IsChecked = true; } if (Settings.IsAutologin() && !Settings.IsAdministrator() && savedCredentials != null) { try { if (!gateStatus) { MessageBox.Show( "Square Enix seems to be running maintenance work right now. The game shouldn't be launched."); Settings.SetAutologin(false); } else { HandleLogin(true); } } catch (Exception exc) { Util.ShowError("Logging in failed, check your login information or try again.\n\n" + exc, "Login failed"); Settings.SetAutologin(false); } Settings.Save(); } if (Settings.GetGamePath() == string.Empty) { var setup = new FirstTimeSetup(); setup.ShowDialog(); } try { _headlines = Headlines.Get(); _bannerBitmaps = new BitmapImage[_headlines.Banner.Length]; for (int i = 0; i < _headlines.Banner.Length; i++) { var bitmap = new BitmapImage(); bitmap.BeginInit(); bitmap.UriSource = _headlines.Banner[i].LsbBanner; bitmap.EndInit(); _bannerBitmaps[i] = bitmap; } BannerImage.Source = _bannerBitmaps[0]; _bannerChangeTimer = new System.Timers.Timer { Interval = 5000 }; _bannerChangeTimer.Elapsed += (o, args) => { if (_currentBannerIndex + 1 > _headlines.Banner.Length - 1) { _currentBannerIndex = 0; } else { _currentBannerIndex++; } this.Dispatcher.BeginInvoke(new Action(() => { BannerImage.Source = _bannerBitmaps[_currentBannerIndex]; })); _bannerChangeTimer.Start(); }; _bannerChangeTimer.Start(); NewsListView.ItemsSource = _headlines.News; } catch (Exception) { NewsListView.Items.Add(new News() { Title = "Could not download news data.", Tag = "DlError" }); } this.Visibility = Visibility.Visible; }