Пример #1
0
        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);
        }
Пример #2
0
        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);
        }
Пример #3
0
        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);
            }
        }