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 using System.Linq; | 9 using System.Linq; |
10 using System.Windows.Forms; | 10 using System.Windows.Forms; |
(...skipping 16 matching lines...) Expand all Loading... |
27 /// The target configuration and platform to read from. | 27 /// The target configuration and platform to read from. |
28 /// </summary> | 28 /// </summary> |
29 private VCConfiguration configuration_; | 29 private VCConfiguration configuration_; |
30 | 30 |
31 /// <summary> | 31 /// <summary> |
32 /// Constructs the property manager. Sets the platform type to Other which i
nvalidates use | 32 /// Constructs the property manager. Sets the platform type to Other which i
nvalidates use |
33 /// of the property manager until SetTarget is called with a valid target. | 33 /// of the property manager until SetTarget is called with a valid target. |
34 /// </summary> | 34 /// </summary> |
35 public PropertyManager() | 35 public PropertyManager() |
36 { | 36 { |
37 ProjectPlatform = ProjectPlatformType.Other; | 37 PlatformType = ProjectPlatformType.Other; |
38 } | 38 } |
39 | 39 |
40 /// <summary> | 40 /// <summary> |
41 /// Specifies the type of plug-in being run in this debug session. | 41 /// Specifies the type of plug-in being run in this debug session. |
42 /// </summary> | 42 /// </summary> |
43 public enum ProjectPlatformType | 43 public enum ProjectPlatformType |
44 { | 44 { |
45 /// <summary> | 45 /// <summary> |
46 /// Represents all non-pepper/non-nacl platform types. | 46 /// Represents all non-pepper/non-nacl platform types. |
47 /// </summary> | 47 /// </summary> |
48 Other, | 48 Other, |
49 | 49 |
50 /// <summary> | 50 /// <summary> |
51 /// Indicates project platform is a trusted plug-in (nexe). | 51 /// Indicates project platform is a trusted plug-in (nexe). |
52 /// </summary> | 52 /// </summary> |
53 NaCl, | 53 NaCl, |
54 | 54 |
55 /// <summary> | 55 /// <summary> |
56 /// Indicates project platform is an untrusted plug-in. | 56 /// Indicates project platform is an untrusted plug-in. |
57 /// </summary> | 57 /// </summary> |
58 Pepper | 58 Pepper |
59 } | 59 } |
60 | 60 |
61 /// <summary> | 61 /// <summary> |
62 /// Gets or sets the current project platform type. This indicates Pepper, N
aCl, or Other type | 62 /// Gets or sets the current project platform type. This indicates Pepper, N
aCl, or Other type |
63 /// of project. If this is set to Other then it is invalid to read the prope
rties. | 63 /// of project. If this is set to Other then it is invalid to read the prope
rties. |
64 /// </summary> | 64 /// </summary> |
65 public ProjectPlatformType ProjectPlatform { get; protected set; } | 65 public ProjectPlatformType PlatformType { get; protected set; } |
| 66 |
| 67 /// <summary> |
| 68 /// Gets or sets the current project platform name. |
| 69 /// </summary> |
| 70 public string PlatformName { get; protected set; } |
66 | 71 |
67 /// <summary> | 72 /// <summary> |
68 /// Gets or sets the full path to the output assembly. | 73 /// Gets or sets the full path to the output assembly. |
69 /// </summary> | 74 /// </summary> |
70 public virtual string PluginAssembly | 75 public virtual string PluginAssembly |
71 { | 76 { |
72 get | 77 get |
73 { | 78 { |
74 AssertValidPlatform(); | 79 AssertValidPlatform(); |
75 VCLinkerTool linker = configuration_.Tools.Item("VCLinkerTool"); | 80 VCLinkerTool linker = configuration_.Tools.Item("VCLinkerTool"); |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 { | 237 { |
233 } | 238 } |
234 } | 239 } |
235 | 240 |
236 /// <summary> | 241 /// <summary> |
237 /// Return true if the given platform is a NaCl platform. | 242 /// Return true if the given platform is a NaCl platform. |
238 /// </summary> | 243 /// </summary> |
239 public static bool IsNaClPlatform(string platformName) | 244 public static bool IsNaClPlatform(string platformName) |
240 { | 245 { |
241 return platformName.Equals(Strings.NaCl32PlatformName, StringComparison.
OrdinalIgnoreCase) || | 246 return platformName.Equals(Strings.NaCl32PlatformName, StringComparison.
OrdinalIgnoreCase) || |
242 platformName.Equals(Strings.NaCl64PlatformName, StringComparison.
OrdinalIgnoreCase); | 247 platformName.Equals(Strings.NaCl64PlatformName, StringComparison.
OrdinalIgnoreCase) || |
| 248 platformName.Equals(Strings.PNaClPlatformName, StringComparison.O
rdinalIgnoreCase); |
243 } | 249 } |
244 | 250 |
245 /// <summary> | 251 /// <summary> |
| 252 /// Return true if the given platform is the PNaCl platform. |
| 253 /// </summary> |
| 254 public bool IsPNaCl() |
| 255 { |
| 256 return PlatformName.Equals(Strings.PNaClPlatformName, StringComparison.O
rdinalIgnoreCase); |
| 257 } |
| 258 |
| 259 /// <summary> |
246 /// Return true if the given platform is a PPAPI platform. | 260 /// Return true if the given platform is a PPAPI platform. |
247 /// </summary> | 261 /// </summary> |
248 public static bool IsPepperPlatform(string platformName) | 262 public static bool IsPepperPlatform(string platformName) |
249 { | 263 { |
250 return platformName.Equals(Strings.PepperPlatformName, StringComparison.
OrdinalIgnoreCase); | 264 return platformName.Equals(Strings.PepperPlatformName, StringComparison.
OrdinalIgnoreCase); |
251 } | 265 } |
252 | 266 |
253 /// <summary> | 267 /// <summary> |
254 /// Sets the target project, platform, and configuration to get settings fro
m. | 268 /// Sets the target project, platform, and configuration to get settings fro
m. |
255 /// </summary> | 269 /// </summary> |
256 /// <param name="proj">Project to read settings from.</param> | 270 /// <param name="proj">Project to read settings from.</param> |
257 /// <param name="targetPlatformName">Platform type to read settings from.</p
aram> | 271 /// <param name="targetPlatformName">Platform type to read settings from.</p
aram> |
258 /// <param name="targetConfigName">Configuration to read from (Debug or Rele
ase).</param> | 272 /// <param name="targetConfigName">Configuration to read from (Debug or Rele
ase).</param> |
259 public void SetTarget(Project proj, string targetPlatformName, string target
ConfigName) | 273 public void SetTarget(Project proj, string targetPlatformName, string target
ConfigName) |
260 { | 274 { |
261 // Set the project platform. If it is set to Other then no settings are v
alid to be read. | 275 // Set the project platform. If it is set to Other then no settings are v
alid to be read. |
262 if (IsPepperPlatform(targetPlatformName)) | 276 SetPlatform(targetPlatformName); |
263 { | 277 if (!IsPepperPlatform(targetPlatformName) && !IsNaClPlatform(targetPlatfor
mName)) |
264 ProjectPlatform = ProjectPlatformType.Pepper; | |
265 } | |
266 else if (IsNaClPlatform(targetPlatformName)) | |
267 { | |
268 ProjectPlatform = ProjectPlatformType.NaCl; | |
269 } | |
270 else | |
271 { | |
272 ProjectPlatform = ProjectPlatformType.Other; | |
273 return; | 278 return; |
274 } | |
275 | 279 |
276 // We don't support non-visual C/C++ projects. | 280 // We don't support non-visual C/C++ projects. |
277 if (!Utility.IsVisualCProject(proj)) | 281 if (!Utility.IsVisualCProject(proj)) |
278 { | 282 { |
279 ProjectPlatform = ProjectPlatformType.Other; | 283 PlatformType = ProjectPlatformType.Other; |
280 return; | 284 return; |
281 } | 285 } |
282 | 286 |
283 // Set the member variables for configuration and project to the target. | 287 // Set the member variables for configuration and project to the target. |
284 project_ = (VCProject)proj.Object; | 288 project_ = (VCProject)proj.Object; |
285 foreach (VCConfiguration config in project_.Configurations) | 289 foreach (VCConfiguration config in project_.Configurations) |
286 { | 290 { |
287 if (config.ConfigurationName == targetConfigName && | 291 if (config.ConfigurationName == targetConfigName && |
288 config.Platform.Name == targetPlatformName) | 292 config.Platform.Name == targetPlatformName) |
289 { | 293 { |
(...skipping 10 matching lines...) Expand all Loading... |
300 public void SetTarget(VCConfiguration config) | 304 public void SetTarget(VCConfiguration config) |
301 { | 305 { |
302 if (config == null) | 306 if (config == null) |
303 { | 307 { |
304 throw new ArgumentNullException("Config"); | 308 throw new ArgumentNullException("Config"); |
305 } | 309 } |
306 | 310 |
307 configuration_ = config; | 311 configuration_ = config; |
308 project_ = config.project; | 312 project_ = config.project; |
309 | 313 |
310 if (IsPepperPlatform(config.Platform.Name)) | 314 SetPlatform(config.Platform.Name); |
| 315 } |
| 316 |
| 317 private void SetPlatform(string platform) |
| 318 { |
| 319 PlatformName = platform; |
| 320 |
| 321 if (IsPepperPlatform(PlatformName)) |
311 { | 322 { |
312 ProjectPlatform = ProjectPlatformType.Pepper; | 323 PlatformType = ProjectPlatformType.Pepper; |
313 } | 324 } |
314 else if (IsNaClPlatform(config.Platform.Name)) | 325 else if (IsNaClPlatform(PlatformName)) |
315 { | 326 { |
316 ProjectPlatform = ProjectPlatformType.NaCl; | 327 PlatformType = ProjectPlatformType.NaCl; |
317 } | 328 } |
318 else | 329 else |
319 { | 330 { |
320 ProjectPlatform = ProjectPlatformType.Other; | 331 PlatformType = ProjectPlatformType.Other; |
321 } | 332 } |
322 } | 333 } |
323 | 334 |
324 /// <summary> | 335 /// <summary> |
325 /// Sets the target project, platform, and configuration to the active start
-up project and | 336 /// Sets the target project, platform, and configuration to the active start
-up project and |
326 /// selected platform and configuration so that settings are read from them. | 337 /// selected platform and configuration so that settings are read from them. |
327 /// </summary> | 338 /// </summary> |
328 /// <param name="dte">The main Visual Studio object.</param> | 339 /// <param name="dte">The main Visual Studio object.</param> |
329 public void SetTargetToActive(DTE2 dte) | 340 public void SetTargetToActive(DTE2 dte) |
330 { | 341 { |
(...skipping 21 matching lines...) Expand all Loading... |
352 // Get the first start-up project object. | 363 // Get the first start-up project object. |
353 List<Project> projList = dte.Solution.Projects.OfType<Project>().ToList(); | 364 List<Project> projList = dte.Solution.Projects.OfType<Project>().ToList(); |
354 string startProjectName = startupProjects.GetValue(0) as string; | 365 string startProjectName = startupProjects.GetValue(0) as string; |
355 Project startProject = projList.Find(proj => proj.UniqueName == startProje
ctName); | 366 Project startProject = projList.Find(proj => proj.UniqueName == startProje
ctName); |
356 | 367 |
357 VCConfiguration activeConfig = Utility.GetActiveVCConfiguration(startProje
ct); | 368 VCConfiguration activeConfig = Utility.GetActiveVCConfiguration(startProje
ct); |
358 | 369 |
359 // GetActiveVCConfiguration will return null if not a VC project. | 370 // GetActiveVCConfiguration will return null if not a VC project. |
360 if (activeConfig == null) | 371 if (activeConfig == null) |
361 { | 372 { |
362 ProjectPlatform = ProjectPlatformType.Other; | 373 PlatformType = ProjectPlatformType.Other; |
363 return; | 374 return; |
364 } | 375 } |
365 | 376 |
366 SetTarget(activeConfig); | 377 SetTarget(activeConfig); |
367 } | 378 } |
368 | 379 |
369 /// <summary> | 380 /// <summary> |
370 /// Reads any generic property from the current target properties. | 381 /// Reads any generic property from the current target properties. |
371 /// </summary> | 382 /// </summary> |
372 /// <param name="page">Name of the page where the property is located.</para
m> | 383 /// <param name="page">Name of the page where the property is located.</para
m> |
(...skipping 15 matching lines...) Expand all Loading... |
388 { | 399 { |
389 IVCRulePropertyStorage pageStorage = configuration_.Rules.Item(page); | 400 IVCRulePropertyStorage pageStorage = configuration_.Rules.Item(page); |
390 pageStorage.SetPropertyValue(name, value); | 401 pageStorage.SetPropertyValue(name, value); |
391 } | 402 } |
392 | 403 |
393 /// <summary> | 404 /// <summary> |
394 /// Ensures that the current target has the NaCl platform and throws if not. | 405 /// Ensures that the current target has the NaCl platform and throws if not. |
395 /// </summary> | 406 /// </summary> |
396 private void AssertNaCl() | 407 private void AssertNaCl() |
397 { | 408 { |
398 if (ProjectPlatform != ProjectPlatformType.NaCl) | 409 if (PlatformType != ProjectPlatformType.NaCl) |
399 { | 410 { |
400 throw new Exception(string.Format( | 411 throw new Exception(string.Format( |
401 "Cannot read NaCl only property on {0} platform", configuration_.Platf
orm.Name)); | 412 "Cannot read NaCl only property on {0} platform", configuration_.Platf
orm.Name)); |
402 } | 413 } |
403 } | 414 } |
404 | 415 |
405 /// <summary> | 416 /// <summary> |
406 /// Ensures that the current target has the Pepper platform and throws if no
t. | 417 /// Ensures that the current target has the Pepper platform and throws if no
t. |
407 /// </summary> | 418 /// </summary> |
408 private void AssertPepper() | 419 private void AssertPepper() |
409 { | 420 { |
410 if (ProjectPlatform != ProjectPlatformType.Pepper) | 421 if (PlatformType != ProjectPlatformType.Pepper) |
411 { | 422 { |
412 throw new Exception(string.Format( | 423 throw new Exception(string.Format( |
413 "Cannot read Pepper only property on {0} platform", configuration_.Pla
tform.Name)); | 424 "Cannot read Pepper only property on {0} platform", configuration_.Pla
tform.Name)); |
414 } | 425 } |
415 } | 426 } |
416 | 427 |
417 /// <summary> | 428 /// <summary> |
418 /// Ensures the current target is either the NaCl or Pepper platform. Throws
if not. | 429 /// Ensures the current target is either the NaCl or Pepper platform. Throws
if not. |
419 /// </summary> | 430 /// </summary> |
420 private void AssertValidPlatform() | 431 private void AssertValidPlatform() |
421 { | 432 { |
422 if (ProjectPlatform == ProjectPlatformType.Other) | 433 if (PlatformType == ProjectPlatformType.Other) |
423 { | 434 { |
424 throw new Exception(string.Format( | 435 throw new Exception(string.Format( |
425 "Unsupported platform type: {0} platform", configuration_.Platform.Nam
e)); | 436 "Unsupported platform type: {0} platform", configuration_.Platform.Nam
e)); |
426 } | 437 } |
427 } | 438 } |
428 } | 439 } |
429 } | 440 } |
OLD | NEW |