OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 namespace NativeClientVSAddIn | 5 namespace NativeClientVSAddIn |
6 { | 6 { |
7 using System; | 7 using System; |
8 using System.Collections.Generic; | 8 using System.Collections.Generic; |
9 | 9 |
10 using EnvDTE; | 10 using EnvDTE; |
| 11 using EnvDTE80; |
11 using Microsoft.VisualStudio.VCProjectEngine; | 12 using Microsoft.VisualStudio.VCProjectEngine; |
12 | 13 |
13 /// <summary> | 14 /// <summary> |
14 /// Contains helper functions for this add-in. | 15 /// Contains helper functions for this add-in. |
15 /// </summary> | 16 /// </summary> |
16 public static class Utility | 17 public static class Utility |
17 { | 18 { |
18 /// <summary> | 19 /// <summary> |
19 /// Tells us if the given project is a Visual C/C++ project. | 20 /// Tells us if the given project is a Visual C/C++ project. |
20 /// </summary> | 21 /// </summary> |
21 /// <param name="proj">Project to check.</param> | 22 /// <param name="proj">Project to check.</param> |
22 /// <returns>True if project is a Visual C/C++ project.</returns> | 23 /// <returns>True if project is a Visual C/C++ project.</returns> |
23 public static bool IsVisualCProject(Project proj) | 24 public static bool IsVisualCProject(Project proj) |
24 { | 25 { |
25 string projectType = proj.Properties.Item("Kind").Value as string; | 26 foreach (Property prop in proj.Properties) |
26 return projectType == "VCProject"; | 27 { |
| 28 if (prop.Name == "Kind") |
| 29 { |
| 30 string projectType = prop.Value as string; |
| 31 return projectType == "VCProject"; |
| 32 } |
| 33 } |
| 34 |
| 35 return false; |
27 } | 36 } |
28 | 37 |
29 /// <summary> | 38 /// <summary> |
30 /// Given a generic project, checks that it is a Visual C project, and | 39 /// Given a generic project, checks that it is a Visual C project, and |
31 /// extracts the active VCConfiguration object. | 40 /// extracts the active VCConfiguration object. |
32 /// </summary> | 41 /// </summary> |
33 /// <param name="proj">Generic project object.</param> | 42 /// <param name="proj">Generic project object.</param> |
34 /// <returns>The active configuration, or null if failure.</returns> | 43 /// <returns>The active configuration, or null if failure.</returns> |
35 public static VCConfiguration GetActiveVCConfiguration(Project proj) | 44 public static VCConfiguration GetActiveVCConfiguration(Project proj) |
36 { | 45 { |
(...skipping 12 matching lines...) Expand all Loading... |
49 config.Platform.Name == active.PlatformName) | 58 config.Platform.Name == active.PlatformName) |
50 { | 59 { |
51 return config; | 60 return config; |
52 } | 61 } |
53 } | 62 } |
54 | 63 |
55 return null; | 64 return null; |
56 } | 65 } |
57 | 66 |
58 /// <summary> | 67 /// <summary> |
| 68 /// Returns all VCConfigurations from the open solution that have the specif
ied platform name. |
| 69 /// Note only VC++ projects are checked. |
| 70 /// </summary> |
| 71 /// <param name="dte">Visual studio main interface.</param> |
| 72 /// <param name="platformName">Name of the platform to get.</param> |
| 73 /// <returns>List of all matching VCConfigurations.</returns> |
| 74 public static List<VCConfiguration> GetPlatformVCConfigurations(DTE2 dte, st
ring platformName) |
| 75 { |
| 76 var platformConfigs = new List<VCConfiguration>(); |
| 77 foreach (Project proj in dte.Solution.Projects) |
| 78 { |
| 79 if (Utility.IsVisualCProject(proj)) |
| 80 { |
| 81 VCProject vcproj = (VCProject)proj.Object; |
| 82 IVCCollection configs = vcproj.Configurations; |
| 83 |
| 84 foreach (VCConfiguration config in configs) |
| 85 { |
| 86 if (platformName.Equals(config.Platform.Name)) |
| 87 { |
| 88 platformConfigs.Add(config); |
| 89 } |
| 90 } |
| 91 } |
| 92 } |
| 93 |
| 94 return platformConfigs; |
| 95 } |
| 96 |
| 97 /// <summary> |
59 /// Extends the string class to allow checking if a string contains another
string | 98 /// Extends the string class to allow checking if a string contains another
string |
60 /// allowing a comparison type (such as case-insensitivity). | 99 /// allowing a comparison type (such as case-insensitivity). |
61 /// </summary> | 100 /// </summary> |
62 /// <param name="source">Base string to search.</param> | 101 /// <param name="source">Base string to search.</param> |
63 /// <param name="toCheck">String to check if contained within base string.</
param> | 102 /// <param name="toCheck">String to check if contained within base string.</
param> |
64 /// <param name="comparison">Comparison type.</param> | 103 /// <param name="comparison">Comparison type.</param> |
65 /// <returns>True if toCheck is contained in source.</returns> | 104 /// <returns>True if toCheck is contained in source.</returns> |
66 public static bool Contains(this string source, string toCheck, StringCompar
ison comparison) | 105 public static bool Contains(this string source, string toCheck, StringCompar
ison comparison) |
67 { | 106 { |
68 return source.IndexOf(toCheck, comparison) != -1; | 107 return source.IndexOf(toCheck, comparison) != -1; |
(...skipping 13 matching lines...) Expand all Loading... |
82 uint ancestor) | 121 uint ancestor) |
83 { | 122 { |
84 return IsDescendantOfProcessHelper( | 123 return IsDescendantOfProcessHelper( |
85 processSearcher, | 124 processSearcher, |
86 descendant, | 125 descendant, |
87 ancestor, | 126 ancestor, |
88 DateTime.UtcNow); | 127 DateTime.UtcNow); |
89 } | 128 } |
90 | 129 |
91 /// <summary> | 130 /// <summary> |
| 131 /// Helper function to properly dispose of a process object and ensure it is
dead. The given |
| 132 /// reference is set to null afterwards. |
| 133 /// </summary> |
| 134 /// <param name="process">Process to kill. Reference is set to null afterwa
rds.</param> |
| 135 public static void EnsureProcessKill(ref System.Diagnostics.Process process) |
| 136 { |
| 137 if (process == null) |
| 138 { |
| 139 return; |
| 140 } |
| 141 |
| 142 try |
| 143 { |
| 144 process.Kill(); |
| 145 } |
| 146 catch (System.InvalidOperationException) |
| 147 { |
| 148 // This happens if the process has already exited. |
| 149 } |
| 150 |
| 151 process.Dispose(); |
| 152 process = null; |
| 153 } |
| 154 |
| 155 /// <summary> |
92 /// Helper function for IsDescendantOfProcessHelper(). | 156 /// Helper function for IsDescendantOfProcessHelper(). |
93 /// This function prevents an edge case where a process has a parent process
ID | 157 /// This function prevents an edge case where a process has a parent process
ID |
94 /// that refers to a descendant of itself. This can occur when the parent of
a process | 158 /// that refers to a descendant of itself. This can occur when the parent of
a process |
95 /// is destroyed and the parent's pid is recycled and reused on a descendant
. The | 159 /// is destroyed and the parent's pid is recycled and reused on a descendant
. The |
96 /// parent process ID value is never updated when the parent is destroyed. T
he solution | 160 /// parent process ID value is never updated when the parent is destroyed. T
he solution |
97 /// is to make sure that parents are created before children, otherwise it i
s a cycle. | 161 /// is to make sure that parents are created before children, otherwise it i
s a cycle. |
98 /// </summary> | 162 /// </summary> |
99 /// <param name="processSearcher">Process searcher object.</param> | 163 /// <param name="processSearcher">Process searcher object.</param> |
100 /// <param name="descendant">Process ID of the descendant.</param> | 164 /// <param name="descendant">Process ID of the descendant.</param> |
101 /// <param name="anscestor">Process ID of the ancestor.</param> | 165 /// <param name="anscestor">Process ID of the ancestor.</param> |
(...skipping 26 matching lines...) Expand all Loading... |
128 proc.ParentID, | 192 proc.ParentID, |
129 anscestor, | 193 anscestor, |
130 proc.CreationDate); | 194 proc.CreationDate); |
131 } | 195 } |
132 } | 196 } |
133 | 197 |
134 return false; | 198 return false; |
135 } | 199 } |
136 } | 200 } |
137 } | 201 } |
OLD | NEW |