private bool LaunchDebugTarget(string pidString)
{
Microsoft.VisualStudio.Shell.ServiceProvider sp =
new Microsoft.VisualStudio.Shell.ServiceProvider((Microsoft.VisualStudio.OLE.Interop.IServiceProvider)_dte);
IVsDebugger dbg = (IVsDebugger)sp.GetService(typeof(SVsShellDebugger));
VsDebugTargetInfo info = new VsDebugTargetInfo();
info.cbSize = (uint)System.Runtime.InteropServices.Marshal.SizeOf(info);
info.dlo = Microsoft.VisualStudio.Shell.Interop.DEBUG_LAUNCH_OPERATION.DLO_CreateProcess;
// Read debugger args from a file (it is set when the Deploy task is run)
System.IO.StreamReader argsFile = null;
try
{
string localAppData = Environment.GetEnvironmentVariable("AppData");
argsFile = new System.IO.StreamReader(localAppData + @"\BlackBerry\vsndk-args-file.txt");
}
catch (Exception e)
{
Debug.Fail("Unexpected exception in LaunchDebugTarget");
}
// Store all debugger arguments in a string
var nvc = new NameValueCollection();
nvc.Add("pid", pidString);
nvc.Add("targetIP", argsFile.ReadLine()); // The device (IP address)
info.bstrExe = argsFile.ReadLine(); // The executable path
nvc.Add("isSimulator", argsFile.ReadLine());
nvc.Add("ToolsPath", argsFile.ReadLine());
nvc.Add("PublicKeyPath", argsFile.ReadLine());
// Decrypt stored password.
byte[] data = Convert.FromBase64String(argsFile.ReadLine());
if (data.Length > 0)
{
byte[] decrypted = ProtectedData.Unprotect(data, null, DataProtectionScope.LocalMachine);
nvc.Add("Password", Encoding.Unicode.GetString(decrypted));
}
info.bstrArg = NameValueCollectionHelper.DumpToString(nvc);
argsFile.Close();
info.bstrRemoteMachine = null; // debug locally
info.fSendStdoutToOutputWindow = 0; // Let stdout stay with the application.
info.clsidCustom = new Guid("{E5A37609-2F43-4830-AA85-D94CFA035DD2}"); // Set the launching engine the VSNDK engine guid
info.grfLaunch = 0;
IntPtr pInfo = System.Runtime.InteropServices.Marshal.AllocCoTaskMem((int)info.cbSize);
System.Runtime.InteropServices.Marshal.StructureToPtr(info, pInfo, false);
try
{
int result = dbg.LaunchDebugTargets(1, pInfo);
if (result != VSConstants.S_OK)
{
string msg;
IVsUIShell sh = (IVsUIShell)sp.GetService(typeof(SVsUIShell));
sh.GetErrorInfo(out msg);
Debug.WriteLine("LaunchDebugTargets: " + msg);
return true;
}
}
finally
{
if (pInfo != IntPtr.Zero)
{
System.Runtime.InteropServices.Marshal.FreeCoTaskMem(pInfo);
}
}
return false;
}