private void SetButtonText() { if (bwConnecter.IsBusy || m_state == ProfilingState.Connecting) { buttonConnect.Text = c_Cancel; checkReboot.Enabled = false; } else if (m_state == ProfilingState.Connected) { buttonConnect.Text = c_Disconnect; } else { _DBG.PortDefinition port = comboBoxDevice.PortDefinition; _DBG.PortDefinition_Emulator emuPort = port as _DBG.PortDefinition_Emulator; if (emuPort != null && emuPort.Pid == 0) { buttonConnect.Text = c_Launch; checkReboot.Enabled = false; } else { buttonConnect.Text = c_Connect; checkReboot.Enabled = true; } } }
public void Start(ProcessStartInfo psi) { psi.FileName = m_exe; psi.Arguments = m_args; m_proc = new Process(); m_proc.StartInfo = psi; if (psi.RedirectStandardOutput) { m_proc.OutputDataReceived += new DataReceivedEventHandler(StandardOutputHandler); } if (psi.RedirectStandardError) { m_proc.ErrorDataReceived += new DataReceivedEventHandler(StandardErrorHandler); } m_proc.Start(); if (psi.RedirectStandardOutput) { m_proc.BeginOutputReadLine(); } if (psi.RedirectStandardError) { m_proc.BeginErrorReadLine(); } m_pipe = PortDefinition_Emulator.PipeNameFromPid(m_proc.Id); }
public static Process LaunchEmulator(_DBG.PortDefinition_Emulator pd, bool fWaitForDebugger, string program) { _DBG.PlatformInfo pi = new _DBG.PlatformInfo(null); _DBG.PlatformInfo.Emulator emu = pi.FindEmulator(pd.Port); _DBG.CommandLineBuilder cb = new _DBG.CommandLineBuilder(); if (emu == null) { throw new ArgumentException(); } if (emu.legacyCommandLine) { throw new NotSupportedException("Legacy emulators not supported."); } if (!string.IsNullOrEmpty(emu.additionalOptions)) { _DBG.CommandLineBuilder cbT = new _DBG.CommandLineBuilder(emu.additionalOptions); cb.AddArguments(cbT.Arguments); } if (!string.IsNullOrEmpty(emu.config)) { cb.AddArguments("/config:" + emu.config); } if (fWaitForDebugger) { cb.AddArguments("/waitfordebugger"); } string[] files = EmulatorLauncher.GetFilesToLoad(program); foreach (string pe in files) { cb.AddArguments("/load:" + pe); } string args = ""; args = args.Trim(); if (args.Length > 0) { cb.AddArguments("/commandlinearguments:" + args); } string commandLine = cb.ToString(); commandLine = Environment.ExpandEnvironmentVariables(commandLine); Process p = new System.Diagnostics.Process(); p.StartInfo.FileName = emu.application; p.StartInfo.Arguments = commandLine; p.StartInfo.UseShellExecute = false; p.StartInfo.WorkingDirectory = Path.GetDirectoryName(emu.application); try { p.Start(); } catch (System.ComponentModel.Win32Exception we) { MessageBox.Show(string.Format("Failed to launch emulator: {0}", we.NativeErrorCode), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(null); } return(p); }
public void SelectLaunchedEmulator(PortDefinition_Emulator port) { ArrayList al = (ArrayList)DataSource as ArrayList; if (al == null) { al = new ArrayList(); } al.Add(port); DataSource = null; //Set to null to force list refresh DataSource = al; DisplayMember = "DisplayName"; SelectedItem = port; //Select newly-launched emulator. }
private void Connect() { _DBG.PortDefinition port = comboBoxDevice.PortDefinition; if (port == null) { SetInvalidDevice(); return; } try { comboBoxTransport.Enabled = false; comboBoxDevice.Enabled = false; buttonConnect.Enabled = false; groupBoxOutput.Enabled = false; groupBoxOptions.Enabled = false; m_state = ProfilingState.Connecting; if (port is _DBG.PortDefinition_Emulator) { _DBG.PortDefinition_Emulator emuport = port as _DBG.PortDefinition_Emulator; if (emuport.Pid == 0) { OpenFileDialog fd = new OpenFileDialog(); fd.DefaultExt = "exe"; fd.Filter = ".NET MF Exe files (*.exe)|*.exe"; fd.Title = "Choose an application to emulate"; if (fd.ShowDialog(this) == DialogResult.OK) { m_emuProcess = EmulatorLauncher.LaunchEmulator(emuport, true, fd.FileName); if (m_emuProcess == null) { LogText("Could not launch emulator."); Disconnect(); return; } else { m_emuLaunched = true; LogText(string.Format("Started emulator process {0}", m_emuProcess.Id)); _DBG.PlatformInfo pi = new _DBG.PlatformInfo(null); port = new _DBG.PortDefinition_Emulator("Emulator - pid " + m_emuProcess.Id, m_emuProcess.Id); comboBoxDevice.SelectLaunchedEmulator((_DBG.PortDefinition_Emulator)port); } } else { Disconnect(); return; } } else { try { m_emuProcess = Process.GetProcessById(emuport.Pid); } catch { m_state = ProfilingState.Disconnected; EnableUI(); SetInvalidDevice(); return; } } } buttonConnect.Text = c_Cancel; buttonConnect.Enabled = true; BackgroundConnectorArguments bca = new BackgroundConnectorArguments(); bca.connectPort = port; bca.outputFileName = textLogFile.Text; #if DEBUG if (radioOffProf.Checked) { bca.exporter = BackgroundConnectorArguments.ExporterType.OffProf; } else { bca.exporter = BackgroundConnectorArguments.ExporterType.CLRProfiler; } #else bca.exporter = BackgroundConnectorArguments.ExporterType.CLRProfiler; #endif //Rebooting the emulator just makes it quit. bca.reboot = checkReboot.Checked && !(port is _DBG.PortDefinition_Emulator); bwConnecter.RunWorkerAsync(bca); } catch (ApplicationException e) { comboBoxTransport.Enabled = true; comboBoxDevice.Enabled = true; buttonConnect.Enabled = true; groupBoxOutput.Enabled = true; groupBoxOptions.Enabled = true; m_state = ProfilingState.Disconnected; MessageBox.Show(this, e.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } }