protected override void OnClosing(System.ComponentModel.CancelEventArgs e) { bool loaded = ActiveProfile != null; if (loaded) { if (ActiveProfile.IsStarted) { ConfigManager.LogManager.LogInfo("Stopping profile on exit."); ActiveProfile.Stop(); } ConfigManager.LogManager.LogInfo("Unloading profile on exit."); ActiveProfile = null; } ConfigManager.LogManager.LogInfo("Saving control center window position."); // Persist window placement details to application settings WINDOWPLACEMENT wp = new WINDOWPLACEMENT(); IntPtr hwnd = new WindowInteropHelper(this).Handle; NativeMethods.GetWindowPlacement(hwnd, out wp); //Properties.PreferencesFile.Default.ControlCenterPlacement = wp; PreferencesFile.SaveSetting("ControlCenter", "WindowLocation", wp.normalPosition); if (loaded && _profileIndex >= 0 && _profileIndex < _profiles.Count) { PreferencesFile.SaveSetting("ControlCenter", "LastProfile", _profiles[_profileIndex]); } Properties.Settings.Default.Save(); base.OnClosing(e); }
private void Profile_ProfileHintReceived(object sender, ProfileHint e) { string oldValue = _lastProfileHint; _lastProfileHint = e.Tag; if (oldValue != _lastProfileHint) { UpdateStatusMessage(); // send only a simple status message to status viewer instead of whole status via ReportStatusToStatusViewer ReportStatus($"Simulator is '{_lastProfileHint}'"); } if (!Preferences.ProfileAutoStart) { return; } ConfigManager.LogManager.LogDebug($"received profile hint with tag '{e.Tag}'"); string mostRecent = PreferencesFile.LoadSetting("RecentByTag", e.Tag, null); if (mostRecent == null) { ConfigManager.LogManager.LogInfo($"received profile hint with tag '{e.Tag}' but no matching profile has been loaded; cannot auto load"); return; } if ((ActiveProfile != null) && (ActiveProfile.Path == mostRecent)) { ConfigManager.LogManager.LogDebug($"most recent profile for profile hint with tag '{e.Tag}' is already active"); // ask simulator to use the one we are running, if possible ActiveProfile.RequestProfileSupport(); return; } // execute auto load ConfigManager.LogManager.LogDebug($"trying to start most recent matching profile '{mostRecent}'"); ControlCenterCommands.RunProfile.Execute(mostRecent, Application.Current.MainWindow); }
private void Window_Opened(object sender, EventArgs e) { if (Environment.OSVersion.Version.Major > 5 && PreferencesFile.LoadSetting("ControlCenter", "AeroWarning", true)) { bool aeroEnabled; NativeMethods.DwmIsCompositionEnabled(out aeroEnabled); if (!aeroEnabled) { AeroWarning warningDialog = new AeroWarning(); warningDialog.Owner = this; warningDialog.ShowDialog(); if (warningDialog.DisplayAgainCheckbox.IsChecked == true) { PreferencesFile.SaveSetting("ControlCenter", "AeroWarning", false); } } } App app = Application.Current as App; if (app != null && app.StartupProfile != null && File.Exists(app.StartupProfile)) { LoadProfileList(app.StartupProfile); LoadProfile(app.StartupProfile); StartProfile(); } VersionChecker.Check versionCheck = ConfigManager.VersionChecker.CheckAvailableVersion(false); if (!ConfigManager.VersionChecker.ShouldOfferNewVersion(versionCheck)) { return; } // can't use the interactive dialog, because this would require writing settings StatusMessage = StatusValue.UpgradeAvailable; StatusReportItem item = new StatusReportItem { Status = $"new version {versionCheck.AvailableVersion} is available", Flags = StatusReportItem.StatusFlags.ConfigurationUpToDate }; if (versionCheck.DownloadUrl != null) { item.Link = new Uri(versionCheck.DownloadUrl); item.Recommendation = $"Use Profile Editor to check for new version or download directly from {versionCheck.DownloadUrl}"; } else { item.Link = StatusReportItem.ProfileEditor; item.Recommendation = "check for new version and download it"; } StatusViewer.AddItem(item); }
protected override void OnSourceInitialized(EventArgs e) { base.OnSourceInitialized(e); try { // Load window placement details for previous application session from application settings // Note - if window was closed on a monitor that is now disconnected from the computer, // SetWindowPlacement will place the window onto a visible monitor. if (PreferencesFile.IsSettingAvailable("ControlCenter", "WindowLocation")) { WINDOWPLACEMENT wp = new WINDOWPLACEMENT(); wp.normalPosition = PreferencesFile.LoadSetting("ControlCenter", "WindowLocation", new RECT(0, 0, (int)Width, (int)Height)); wp.length = Marshal.SizeOf(typeof(WINDOWPLACEMENT)); wp.flags = 0; wp.showCmd = (wp.showCmd == NativeMethods.SW_SHOWMINIMIZED ? NativeMethods.SW_SHOWNORMAL : wp.showCmd); IntPtr hwnd = new WindowInteropHelper(this).Handle; NativeMethods.SetWindowPlacement(hwnd, ref wp); } if (!Enum.TryParse(Preferences.HotKeyModifiers, out ModifierKeys mods)) { HotKeyDescription = "None"; return; } if (!Enum.TryParse(Preferences.HotKey, out Keys hotKey)) { HotKeyDescription = "None"; return; } if (hotKey != Keys.None) { _hotkey = new HotKey(mods, hotKey, this); _hotkey.HotKeyPressed += new Action <HotKey>(HotKeyPressed); HotKeyDescription = KeyboardEmulator.ModifierKeysToString(_hotkey.KeyModifier) + _hotkey.Key.ToString(); } else { HotKeyDescription = "None"; } } catch (System.Exception ex) { ConfigManager.LogManager.LogError("exception thrown during hotkey initialization", ex); RemoveHotkey(); } }
private void StartProfile() { if (ActiveProfile == null || ActiveProfile.IsStarted) { return; } ActiveProfile.Dispatcher = Dispatcher; if (Preferences.PreflightCheck) { if (!PerformReadyCheck()) { // this is already logged as an error because we set the StatusMessage to an error type ConfigManager.LogManager.LogDebug("Aborted start up of Profile due to failed preflight check."); return; } } else { ReportStatus("Preflight check is disabled. Helios will not be able to ensure configuration is correct."); } ActiveProfile.ControlCenterShown += Profile_ShowControlCenter; ActiveProfile.ControlCenterHidden += Profile_HideControlCenter; ActiveProfile.ProfileStopped += Profile_ProfileStopped; ActiveProfile.ProfileHintReceived += Profile_ProfileHintReceived; ActiveProfile.DriverStatusReceived += Profile_DriverStatusReceived; ActiveProfile.ClientChanged += Profile_ClientChanged; ActiveProfile.Start(); if (_dispatcherTimer != null) { _dispatcherTimer.Stop(); } _dispatcherTimer = new DispatcherTimer(); _dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, 33); _dispatcherTimer.Tick += new EventHandler(DispatcherTimer_Tick); _dispatcherTimer.Start(); foreach (Monitor monitor in ActiveProfile.Monitors) { try { if (monitor.Children.Count > 0 || monitor.FillBackground || !String.IsNullOrWhiteSpace(monitor.BackgroundImage)) { monitor.SuppressMouseAfterTouchDuration = Preferences.SuppressMouseAfterTouchDuration; ConfigManager.LogManager.LogDebug("Creating window (Monitor=\"" + monitor.Name + "\")" + " with touchscreen mouse event suppression delay set to " + Convert.ToString(monitor.SuppressMouseAfterTouchDuration) + " msec."); MonitorWindow window = new MonitorWindow(monitor, Preferences.HighQualityBitmapScaling, true); window.Show(); _windows.Add(window); } } catch (Exception ex) { ConfigManager.LogManager.LogError("Error creating monitor window (Monitor=\"" + monitor.Name + "\")", ex); } } // success, consider this the most recently run profile for its tags (usually just the aircraft types supported) foreach (string tag in ActiveProfile.Tags) { PreferencesFile.SaveSetting("RecentByTag", tag, ActiveProfile.Path); } StatusMessage = StatusValue.Running; if (Preferences.AutoHide) { MinimizeWindow(); } else { NativeMethods.BringWindowToTop(_helper.Handle); } }