OLD | NEW |
| (Empty) |
1 /// Copyright (c) Microsoft Corporation. All rights reserved. | |
2 | |
3 using System; | |
4 using Microsoft.VisualStudio.Shell.Interop; | |
5 using Microsoft.Win32; | |
6 using VSRegistry = Microsoft.VisualStudio.Shell.VSRegistry; | |
7 | |
8 namespace Microsoft.VisualStudio.Project | |
9 { | |
10 /// <summary> | |
11 /// Gets registry settings from for a project. | |
12 /// </summary> | |
13 internal class RegisteredProjectType | |
14 { | |
15 private string defaultProjectExtension; | |
16 | |
17 private string projectTemplatesDir; | |
18 | |
19 private string wizardTemplatesDir; | |
20 | |
21 private Guid packageGuid; | |
22 | |
23 internal const string DefaultProjectExtension = "DefaultProjectE
xtension"; | |
24 internal const string WizardsTemplatesDir = "WizardsTemplatesDir
"; | |
25 internal const string ProjectTemplatesDir = "ProjectTemplatesDir
"; | |
26 internal const string Package = "Package"; | |
27 | |
28 | |
29 | |
30 internal string DefaultProjectExtensionValue | |
31 { | |
32 get | |
33 { | |
34 return this.defaultProjectExtension; | |
35 } | |
36 set | |
37 { | |
38 this.defaultProjectExtension = value; | |
39 } | |
40 } | |
41 | |
42 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Perf
ormance", "CA1811:AvoidUncalledPrivateCode")] | |
43 internal string ProjectTemplatesDirValue | |
44 { | |
45 get | |
46 { | |
47 return this.projectTemplatesDir; | |
48 } | |
49 set | |
50 { | |
51 this.projectTemplatesDir = value; | |
52 } | |
53 } | |
54 | |
55 internal string WizardTemplatesDirValue | |
56 { | |
57 get | |
58 { | |
59 return this.wizardTemplatesDir; | |
60 } | |
61 set | |
62 { | |
63 this.wizardTemplatesDir = value; | |
64 } | |
65 } | |
66 | |
67 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Perf
ormance", "CA1811:AvoidUncalledPrivateCode")] | |
68 internal Guid PackageGuidValue | |
69 { | |
70 get | |
71 { | |
72 return this.packageGuid; | |
73 } | |
74 set | |
75 { | |
76 this.packageGuid = value; | |
77 } | |
78 } | |
79 | |
80 /// <summary> | |
81 /// If the project support VsTemplates, returns the path to | |
82 /// the vstemplate file corresponding to the requested template | |
83 /// | |
84 /// You can pass in a string such as: "Windows\Console Applicati
on" | |
85 /// </summary> | |
86 internal string GetVsTemplateFile(string templateFile) | |
87 { | |
88 // First see if this use the vstemplate model | |
89 if(!String.IsNullOrEmpty(DefaultProjectExtensionValue)) | |
90 { | |
91 EnvDTE80.DTE2 dte = Microsoft.VisualStudio.Shell
.Package.GetGlobalService(typeof(EnvDTE.DTE)) as EnvDTE80.DTE2; | |
92 if(dte != null) | |
93 { | |
94 EnvDTE80.Solution2 solution = dte.Soluti
on as EnvDTE80.Solution2; | |
95 if(solution != null) | |
96 { | |
97 string fullPath = solution.GetPr
ojectTemplate(templateFile, DefaultProjectExtensionValue); | |
98 // The path returned by GetProje
ctTemplate can be in the format "path|FrameworkVersion=x.y|Language=xxx" | |
99 // where the framework version a
nd language sections are optional. | |
100 // Here we are interested only i
n the full path, so we have to remove all the other sections. | |
101 int pipePos = fullPath.IndexOf('
|'); | |
102 if(0 == pipePos) | |
103 { | |
104 return null; | |
105 } | |
106 if(pipePos > 0) | |
107 { | |
108 fullPath = fullPath.Subs
tring(0, pipePos); | |
109 } | |
110 return fullPath; | |
111 } | |
112 } | |
113 | |
114 } | |
115 return null; | |
116 } | |
117 | |
118 internal static RegisteredProjectType CreateRegisteredProjectTyp
e(Guid projectTypeGuid) | |
119 { | |
120 RegisteredProjectType registederedProjectType = null; | |
121 | |
122 using(RegistryKey rootKey = VSRegistry.RegistryRoot(__Vs
LocalRegistryType.RegType_Configuration)) | |
123 { | |
124 if(rootKey == null) | |
125 { | |
126 return null; | |
127 } | |
128 | |
129 string projectPath = "Projects\\" + projectTypeG
uid.ToString("B"); | |
130 using(RegistryKey projectKey = rootKey.OpenSubKe
y(projectPath)) | |
131 { | |
132 if(projectKey == null) | |
133 { | |
134 return null; | |
135 } | |
136 | |
137 registederedProjectType = new Registered
ProjectType(); | |
138 registederedProjectType.DefaultProjectEx
tensionValue = projectKey.GetValue(DefaultProjectExtension) as string; | |
139 registederedProjectType.ProjectTemplates
DirValue = projectKey.GetValue(ProjectTemplatesDir) as string; | |
140 registederedProjectType.WizardTemplatesD
irValue = projectKey.GetValue(WizardsTemplatesDir) as string; | |
141 registederedProjectType.PackageGuidValue
= new Guid(projectKey.GetValue(Package) as string); | |
142 } | |
143 } | |
144 | |
145 return registederedProjectType; | |
146 } | |
147 } | |
148 } | |
OLD | NEW |