private bool getProcessInfo(DTE2 dte, ref string pidString, ref string toolsPath, ref string publicKeyPath, ref string targetIP, ref string password, ref string executablePath)
{
string currentPath = "";
foreach (string[] paths in _targetDir)
{
if (paths[0] == processName)
{
currentPath = paths[1];
break;
}
}
executablePath = currentPath + processName; // The executable path
executablePath = executablePath.Replace('\\', '/');
publicKeyPath = Environment.GetEnvironmentVariable("AppData") + @"\BlackBerry\bbt_id_rsa.pub";
publicKeyPath = publicKeyPath.Replace('\\', '/');
try
{
RegistryKey rkHKCU = Registry.CurrentUser;
RegistryKey rkPluginRegKey = rkHKCU.OpenSubKey("Software\\BlackBerry\\BlackBerryVSPlugin");
toolsPath = rkPluginRegKey.GetValue("NDKHostPath").ToString() + "/usr/bin";
toolsPath = toolsPath.Replace('\\', '/');
if (_isSimulator)
{
targetIP = rkPluginRegKey.GetValue("simulator_IP").ToString();
password = rkPluginRegKey.GetValue("simulator_password").ToString();
}
else
{
targetIP = rkPluginRegKey.GetValue("device_IP").ToString();
password = rkPluginRegKey.GetValue("device_password").ToString();
}
// Decrypt stored password.
byte[] data = Convert.FromBase64String(password);
if (data.Length > 0)
{
byte[] decrypted = ProtectedData.Unprotect(data, null, DataProtectionScope.LocalMachine);
password = Encoding.Unicode.GetString(decrypted);
}
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message, "Microsoft Visual Studio", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
}
pidString = getPIDfromGDB(processName, targetIP, password, _isSimulator, toolsPath, publicKeyPath);
if (pidString == "")
{
// Select all of the text
_owP.TextDocument.Selection.SelectAll();
string outputText = _owP.TextDocument.Selection.Text;
// Check for successful deployment
if (System.Text.RegularExpressions.Regex.IsMatch(outputText, "Info: done"))
{
string pattern = @"\s+result::(\d+)\r\n.+|\s+result::(\d+) \(TaskId:";
Regex r = new Regex(pattern, RegexOptions.IgnoreCase);
// Match the regular expression pattern against a text string.
Match m = r.Match(outputText);
// Take first match
if (m.Success)
{
Group g = m.Groups[1];
CaptureCollection cc = g.Captures;
if (cc.Count == 0)
{ // Diagnostic verbosity mode
g = m.Groups[2];
cc = g.Captures;
}
if (cc.Count != 0)
{
Capture c = cc[0];
pidString = c.ToString();
}
}
}
}
if (pidString != "")
{
// Store proccess name and file location into ProcessesPath.txt, so "Attach To Process" would be able to find the
// source code for a running process.
// First read the file.
processName += "_" + _isSimulator.ToString();
string processesPaths = "";
System.IO.StreamReader readProcessesPathsFile = null;
try
{
readProcessesPathsFile = new System.IO.StreamReader(System.Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\Research In Motion\ProcessesPath.txt");
processesPaths = readProcessesPathsFile.ReadToEnd();
readProcessesPathsFile.Close();
}
catch (Exception e)
{
processesPaths = "";
}
// Updating the contents.
int begin = processesPaths.IndexOf(processName + ":>");
if (begin != -1)
{
begin += processName.Length + 2;
int end = processesPaths.IndexOf("\r\n", begin);
processesPaths = processesPaths.Substring(0, begin) + currentPath + processesPaths.Substring(end);
}
else
{
processesPaths = processesPaths + processName + ":>" + currentPath + "\r\n";
}
// Writing contents to file.
System.IO.StreamWriter writeProcessesPathsFile = null;
try
{
writeProcessesPathsFile = new System.IO.StreamWriter(System.Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\Research In Motion\ProcessesPath.txt", false);
writeProcessesPathsFile.Write(processesPaths);
writeProcessesPathsFile.Close();
}
catch (Exception e)
{
}
return true;
}
return false;
}