/// <summary>
 /// Handler for launching Unity campfire sample app
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void launchSampleSceneToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (!OSVRProcessManager.ProcessInstanceIsRunning(Common.TEST_APP_NAME))
     {
         StartTestApp();
     }
 }
 /// <summary>
 /// Handler for launching HDK Firmware Utility
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void launchFWUToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (!OSVRProcessManager.ProcessInstanceIsRunning(Common.FW_UTIL_NAME))
     {
         StartFWUtil();
     }
 }
        private void Server_ErrorDataReceived(object sender, DataReceivedEventArgs e)
        {
            m_console.DataReceived(e.Data, true);

            /// There is probably a better way to handle this...
            if (e.Data != null && e.Data.Contains("WARNING - Your HDK infrared tracking camera was detected to have outdated firmware in need of updating, and may not function properly."))
            {
                string  osvrPath          = OSVRRegistry.GetInstallDirectoryFromRegistry();
                string  workingDirectory  = osvrPath + Common.FW_UTIL_PATH;
                string  completeFilePath  = workingDirectory + Common.IR_CAM_FW_UPDATER_NAME;
                Process ir_cam_fw_updater = OSVRProcessManager.LaunchExecutable(completeFilePath,
                                                                                workingDirectory,
                                                                                ProcessWindowStyle.Normal,
                                                                                string.Empty);

                if (ir_cam_fw_updater == null)
                {
                    Common.ShowMessageBox(Common.MSG_MISSING_OR_CANCELLED_IR_CAM_FW_UPDATER, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    m_console.DataReceived(
                        "\n---\n" +
                        "Because your HDK IR Camera has outdated firmware, the firmware update tool will be launched.\n" +
                        "Please restart the server after updating your camera's firmware.\n\n" +
                        "NOTE: If the update utility reports that the update \"is not suitable for your device\"\n" +
                        "please plug your HDK IR Camera directly into a USB port on your computer rather than a hub\n" +
                        "such as those found on monitors, then restart the server to try again." +
                        "\n---\n", false);
                }
            }
        }
 /// <summary>
 /// Handler for launching tracker viewer
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void launchTrackerViewToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (!OSVRProcessManager.ProcessInstanceIsRunning(Common.TRACKER_VIEW_NAME))
     {
         StartTrackerView();
     }
 }
        public void Recenter()
        {
            string osvrPath         = OSVRRegistry.GetInstallDirectoryFromRegistry();
            string workingDirectory = osvrPath + Common.FW_UTIL_PATH;
            string completeFilePath = workingDirectory + Common.RECENTER_NAME;

            OSVRProcessManager.LaunchExecutable(completeFilePath,
                                                workingDirectory,
                                                ProcessWindowStyle.Minimized,
                                                string.Empty);
        }
        /// <summary>
        /// Launch tracker viewer
        /// </summary>
        private void StartTrackerView()
        {
            string  osvrPath         = OSVRRegistry.GetInstallDirectoryFromRegistry();
            string  workingDirectory = osvrPath + Common.TRACKER_VIEW_PATH;
            string  completeFilePath = workingDirectory + Common.TRACKER_VIEW_NAME;
            Process tv = OSVRProcessManager.LaunchExecutable(completeFilePath, workingDirectory, ProcessWindowStyle.Normal, string.Empty);

            if (tv == null)
            {
                Common.ShowMessageBox(Common.MSG_MISSING_TRACKER_VIEW, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        /// <summary>
        /// Event fired when the exit option is clicked. Perform any
        /// shutdown logic here.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (m_server.Running)
            {
                m_server.StopServer();
            }

            OSVRProcessManager.KillProcessByName(Common.TRACKER_VIEW_NAME);
            OSVRProcessManager.KillProcessByName(Common.FW_UTIL_NAME);
            OSVRProcessManager.KillProcessByName(Common.TEST_APP_NAME);

            Application.Exit();
        }
        /// <summary>
        /// Stop OSVR server
        /// </summary>
        public bool StopServer()
        {
            if (serverRunning())
            {
                if (OSVRProcessManager.KillProcessByName(Common.SERVICE_NAME) > 0)
                {
                    m_console.ServerStateChanged(ServerConsole.ServerState.Stop);
                    return(true);
                }
                else
                {
                    Common.ShowMessageBox(Common.MSG_UNABLE_TO_STOP_SERVER, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

            return(false);
        }
        /// <summary>
        /// Set extended display mode
        /// </summary>
        private void SetExtendedMode()
        {
            string extended_mode_name = null;

            GPUDetection.GraphicsCardType gct = GPUDetection.GraphicsCardType.UNKNOWN;
            try
            {
                gct = (GPUDetection.GraphicsCardType)Enum.Parse(typeof(GPUDetection.GraphicsCardType), Properties.Settings.Default.graphicsCardType);
            }
            catch (ArgumentException) { }

            switch (gct)
            {
            case GPUDetection.GraphicsCardType.NVIDIA:
                extended_mode_name = Common.EXTENDED_MODE_NAME_NVIDIA;
                break;

            case GPUDetection.GraphicsCardType.AMD:
                extended_mode_name = Common.EXTENDED_MODE_NAME_AMD;
                break;

            case GPUDetection.GraphicsCardType.UNKNOWN:
                ShowSelectGPUTypeDialog();
                return;
            }

            string  osvrPath         = OSVRRegistry.GetInstallDirectoryFromRegistry();
            string  workingDirectory = osvrPath + Common.SERVICE_PATH;
            string  completeFilePath = workingDirectory + extended_mode_name;
            Process em_exe           = OSVRProcessManager.LaunchExecutable(completeFilePath,
                                                                           workingDirectory,
                                                                           ProcessWindowStyle.Normal,
                                                                           string.Empty);

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

            em_exe.EnableRaisingEvents = true;
            em_exe.Exited += setExtendedModeProcess_Exited;
        }
        /// <summary>
        /// Launch Unity campfire sample application
        /// </summary>
        private void StartTestApp()
        {
            string osvrPath         = OSVRRegistry.GetInstallDirectoryFromRegistry();
            string workingDirectory = osvrPath + Common.TEST_APP_PATH;
            string completeFilePath = workingDirectory + Common.TEST_APP_NAME;

            Process proc = OSVRProcessManager.LaunchExecutable(completeFilePath,
                                                               workingDirectory,
                                                               ProcessWindowStyle.Normal,
                                                               ""); // "-show-screen-selector"); // NativeHelpers.IsExtendedModeEnabled() ? "-show-screen-selector" : "");

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

            proc.EnableRaisingEvents = true;
            proc.Exited += Testapp_Exited;
        }
        /// <summary>
        /// Launch CPI
        /// </summary>
        public HDKType StartFWUtil(bool detect_hw_type = false)
        {
            string  osvrPath         = OSVRRegistry.GetInstallDirectoryFromRegistry();
            string  workingDirectory = osvrPath + Common.FW_UTIL_PATH;
            string  completeFilePath = workingDirectory + Common.FW_UTIL_NAME;
            Process fw_util          = OSVRProcessManager.LaunchExecutable(completeFilePath,
                                                                           workingDirectory,
                                                                           ProcessWindowStyle.Normal,
                                                                           detect_hw_type ? "-detecthw" : string.Empty);

            if (fw_util == null)
            {
                Common.ShowMessageBox(Common.MSG_MISSING_FWU, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(HDKType.ERROR);
            }

            if (detect_hw_type)
            {
                fw_util.WaitForExit();
                return((HDKType)fw_util.ExitCode);
            }
            return(HDKType.NOT_REQUESTED);
        }
Beispiel #12
0
        static void Main(string[] args)
        {
            // Visual setup
            try
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
            }
            catch (InvalidOperationException e)
            {
                Debug.WriteLine("Unable to set text compatible text rendering default: " + e.Message + "\n" + e.StackTrace);
            }

            // If run with -startserver flag, try to start the server; if the server is already running, ignore this flag
            bool start_server_arg = args.Length == 1 && args[0] == "-startserver";

            // Check whether the OSVR Server is already running
            bool server_running = OSVRProcessManager.ProcessInstanceIsRunning(Common.SERVICE_NAME);

            // Check whether another instance of the TrayApp is already running
            Process existing_trayapp_instance = OSVRProcessManager.ExistingTrayAppProcess();

            bool trayapp_running = existing_trayapp_instance != null;

            // On Win7x64 Pro and potentially other operating systems, two instances of this application are for some reason
            // being launched on startup, despite only one entry existing in msconfig's startups tab.  See OSVI-201 for details.
            //
            // When this situation occurs, this block will detect it and terminate the instance with the higher process ID.
            // This could also be solved with the sort of global system lock that used to be present here, but that had other issues.
            if (trayapp_running &&
                DateTime.Now - existing_trayapp_instance.StartTime < TimeSpan.FromSeconds(1d))
            {
                if (existing_trayapp_instance.Id < Process.GetCurrentProcess().Id)
                {
                    Debug.WriteLine("Two instances launched at nearly the same time; terminating this one because it has a higher process ID.");
                    return;
                }
                else
                {
                    Debug.WriteLine("Two instances launched at nearly the same time; terminating other one because it has a higher process ID.");
                    trayapp_running = false;
                }
            }

            /*
             * trayapp_running, start_server_arg, server_running:
             * no, yes, yes -> show message saying unmanaged server already running
             * no, no, yes -> show message saying unmanaged server already running
             * no, no, no -> vanilla
             * yes, yes, no -> terminate existing instance, launch server
             * no, yes, no -> launch server
             * yes, yes, yes -> terminate this instance, show message saying both server and trayapp are already running
             * yes, no, yes -> terminate this instance, show message saying trayapp already running
             * yes, no, no ->  terminate this instance, show message saying trayapp already running
             */

            bool terminate_this_instance     = trayapp_running && (!start_server_arg || server_running);
            bool terminate_existing_instance = trayapp_running && start_server_arg && !server_running;
            bool launch_server = start_server_arg && !server_running;
            bool msg_unmanaged_server_already_running = !trayapp_running && server_running;
            bool msg_trayapp_already_running          = trayapp_running && !start_server_arg;
            bool msg_both_already_running             = trayapp_running && start_server_arg && server_running;

            if (msg_unmanaged_server_already_running)
            {
                Common.ShowMessageBox(Common.MSG_SERVER_ALREADY_RUNNING_UMANAGED, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            if (msg_trayapp_already_running)
            {
                Common.ShowMessageBox(Common.MSG_TRAYAPP_ALREADY_RUNNING, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            if (msg_both_already_running)
            {
                Common.ShowMessageBox(Common.MSG_TRAYAPP_AND_SERVER_ALREADY_RUNNING, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            if (terminate_existing_instance)
            {
                try
                {
                    existing_trayapp_instance.Kill();
                }
                catch
                {
                    Debug.WriteLine("Unable to kill existing TrayApp process with PID " + existing_trayapp_instance.Id + "!");
                }
            }

            if (terminate_this_instance)
            {
                return;
            }

#if (RUN_TESTRAIL)
            CommonTests.Run();
#endif

            using (OSVRIcon osvrIcon = new OSVRIcon())
            {
                osvrIcon.Display(launch_server);
                Application.Run();
            }
        }
        /// <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;
        }
 public bool serverRunning()
 {
     ServerLastState = OSVRProcessManager.ProcessInstanceIsRunning(Common.SERVICE_NAME);
     return(ServerLastState);
 }