private void setExtendedModeProcess_Exited(object sender, EventArgs e)
        {
            if (NativeHelpers.IsExtendedModeEnabled())
            {
                bool server_restart_prompt = true;

                try
                {
                    if (!NativeHelpers.IsDeviceRotationCorrect())
                    {
                        server_restart_prompt = false;  // device rotation will prompt restart
                        BeginInvoke(new MethodInvoker(PromptDeviceRotation));
                    }
                }
                catch
                {
                    server_restart_prompt = false;
                }

                if (server_restart_prompt)
                {
                    BeginInvoke(new MethodInvoker(PromptServerStartOrRestartDelegate));
                }
            }
        }
 private void PromptDeviceRotation()
 {
     if (Properties.Settings.Default.promptSetLandscapeDisplayOrientation)
     {
         m_displayOrientationPrompt.Show();
     }
     else if (Properties.Settings.Default.shouldSetLandscapeDisplayOrientation)
     {
         NativeHelpers.CorrectDeviceRotation();
     }
 }
        private void promptSetHDKDisplayRotationLabelYes_Click(object sender, EventArgs e)
        {
            NativeHelpers.CorrectDeviceRotation();

            if (promptHDKDisplayOrientationDontAskAgain.Checked)
            {
                Properties.Settings.Default.promptSetLandscapeDisplayOrientation = false;
                Properties.Settings.Default.shouldSetLandscapeDisplayOrientation = true;
                Properties.Settings.Default.Save();
            }

            Hide();

            m_contextMenu.PromptServerStartOrRestartDelegate();
        }
        /// <summary>
        /// Update enabled/disabled items based on server state
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OSVRContextMenuStrip_Opening(object sender, System.ComponentModel.CancelEventArgs e)
        {
            if (m_server.Running)
            {
                startServerToolStripMenuItem.Enabled   = false;
                restartServerToolStripMenuItem.Enabled = true;
                stopServerToolStripMenuItem.Enabled    = true;

                launchSampleSceneToolStripMenuItem.Enabled = true;
                launchTrackerViewToolStripMenuItem.Enabled = true;
            }
            else
            {
                startServerToolStripMenuItem.Enabled   = true;
                restartServerToolStripMenuItem.Enabled = false;
                stopServerToolStripMenuItem.Enabled    = false;

                launchSampleSceneToolStripMenuItem.Enabled = false;
                launchTrackerViewToolStripMenuItem.Enabled = false;
            }

            showServerConsoleToolStripMenuItem.Enabled  = !m_server.ConsoleVisible;
            enableExtendedModeToolStripMenuItem.Enabled = !NativeHelpers.IsExtendedModeEnabled();

            switch (SteamVRConfig.InversionState())
            {
            case SteamVRConfig.SteamVRInversion.Unknown:
                invertSteamVRToolStripMenuItem.Enabled = false;
                invertSteamVRToolStripMenuItem.Checked = false;
                break;

            case SteamVRConfig.SteamVRInversion.Inverted:
                invertSteamVRToolStripMenuItem.Enabled = true;
                invertSteamVRToolStripMenuItem.Checked = true;
                break;

            case SteamVRConfig.SteamVRInversion.NotSet:
            case SteamVRConfig.SteamVRInversion.Standard:
                invertSteamVRToolStripMenuItem.Enabled = true;
                invertSteamVRToolStripMenuItem.Checked = false;
                break;
            }
        }
        /// <summary>
        /// Start OSVR server
        /// </summary>
        public void StartServer(bool restart = false)
        {
            string configArgs = string.Empty;

            // is the "Use Custom Config" option checked
            if (m_contextMenu.CustomServerConfigChecked)
            {
                string targetCustomConfig = Properties.Settings.Default.targetCustomConfig;
                // has the user specified a custom config?
                if (!string.IsNullOrEmpty(targetCustomConfig) && File.Exists(targetCustomConfig))
                {
                    configArgs = targetCustomConfig;
                }
                else
                {
                    Common.ShowMessageBox(Common.MSG_MISSING_CUSTOM_CONFIG, MessageBoxButtons.OK, MessageBoxIcon.Error, true);
                    return;
                }
            }
            else
            {
                switch (m_contextMenu.DetectHDKType())
                {
                case ContextMenuWYSIWYG.HDKType.HDK1:
                    if (NativeHelpers.IsExtendedModeEnabled())
                    {
                        if (m_contextMenu.UseIRCameraChecked)
                        {
                            configArgs = Common.CFG_1X_EM_CAM;
                        }
                        else
                        {
                            configArgs = Common.CFG_1X_EM_NOCAM;
                        }
                    }
                    else
                    {
                        if (m_contextMenu.UseIRCameraChecked)
                        {
                            configArgs = Common.CFG_1X_DM_CAM;
                        }
                        else
                        {
                            configArgs = Common.CFG_1X_DM_NOCAM;
                        }
                    }
                    break;

                case ContextMenuWYSIWYG.HDKType.HDK2:
                    if (NativeHelpers.IsExtendedModeEnabled())
                    {
                        if (m_contextMenu.UseIRCameraChecked)
                        {
                            configArgs = Common.CFG_2_EM_CAM;
                        }
                        else
                        {
                            configArgs = Common.CFG_2_EM_NOCAM;
                        }
                    }
                    else
                    {
                        if (m_contextMenu.UseIRCameraChecked)
                        {
                            configArgs = Common.CFG_2_DM_CAM;
                        }
                        else
                        {
                            configArgs = Common.CFG_2_DM_NOCAM;
                        }
                    }
                    break;

                case ContextMenuWYSIWYG.HDKType.UNKNOWN:
                    Common.ShowMessageBox(Common.MSG_UNABLE_TO_DETECT_HDK_TYPE, MessageBoxButtons.OK, MessageBoxIcon.Error, true);
                    return;

                default:
                    // error case already shows error message
                    return;
                }
            }

            string  osvrPath         = OSVRRegistry.GetInstallDirectoryFromRegistry();
            string  completeFilePath = osvrPath + Common.SERVICE_PATH + Common.SERVICE_NAME;
            string  workingDirectory = osvrPath + Common.SERVICE_PATH;
            Process server           = OSVRProcessManager.LaunchExecutable(completeFilePath,
                                                                           workingDirectory,
                                                                           ProcessWindowStyle.Minimized, // Note: this is ignored
                                                                           configArgs,
                                                                           false);

            if (server == null)
            {
                Common.ShowMessageBox(Common.MSG_UNABLE_TO_START_SERVER, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (!m_console.Visible)
            {
                ShowServerConsole();
            }

            m_console.ServerStateChanged(restart ? ServerConsole.ServerState.Restart : ServerConsole.ServerState.Start);

            server.BeginOutputReadLine();
            server.BeginErrorReadLine();
            server.EnableRaisingEvents = true;
            server.OutputDataReceived += Server_OutputDataReceived;
            server.ErrorDataReceived  += Server_ErrorDataReceived;
        }