Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(193)

Side by Side Diff: obsolete/Microsoft.VisualStudio.Project/SingleFileGeneratorFactory.cs

Issue 10928195: First round of dead file removal (Closed) Base URL: https://github.com/samclegg/nativeclient-sdk.git@master
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /// Copyright (c) Microsoft Corporation. All rights reserved.
2
3 using System;
4 using System.Collections.Generic;
5 using System.Runtime.InteropServices;
6 using Microsoft.VisualStudio;
7 using Microsoft.VisualStudio.OLE.Interop;
8 using Microsoft.VisualStudio.Shell.Interop;
9 using Microsoft.Win32;
10 using VSRegistry = Microsoft.VisualStudio.Shell.VSRegistry;
11
12 namespace Microsoft.VisualStudio.Project
13 {
14 /// <summary>
15 /// Provides implementation IVsSingleFileGeneratorFactory for
16 /// </summary>
17 public class SingleFileGeneratorFactory : IVsSingleFileGeneratorFactory
18 {
19 #region nested types
20 private class GeneratorMetaData
21 {
22 #region fields
23 private Guid generatorClsid = Guid.Empty;
24 private int generatesDesignTimeSource = -1;
25 private int generatesSharedDesignTimeSource = -1;
26 private int useDesignTimeCompilationFlag = -1;
27 object generator;
28 #endregion
29
30 #region ctor
31 /// <summary>
32 /// Constructor
33 /// </summary>
34 public GeneratorMetaData()
35 {
36 }
37 #endregion
38
39 #region Public Properties
40 /// <summary>
41 /// Generator instance
42 /// </summary>
43 public Object Generator
44 {
45 get
46 {
47 return generator;
48 }
49 set
50 {
51 generator = value;
52 }
53 }
54
55 /// <summary>
56 /// GeneratesDesignTimeSource reg value name under HKEY_ LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\[VsVer]\Generators\[ProjFacGuid]\[ GeneratorProgId]
57 /// </summary>
58 public int GeneratesDesignTimeSource
59 {
60 get
61 {
62 return generatesDesignTimeSource;
63 }
64 set
65 {
66 generatesDesignTimeSource = value;
67 }
68 }
69
70 /// <summary>
71 /// GeneratesSharedDesignTimeSource reg value name under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\[VsVer]\Generators\[ProjFacG uid]\[GeneratorProgId]
72 /// </summary>
73 public int GeneratesSharedDesignTimeSource
74 {
75 get
76 {
77 return generatesSharedDesignTimeSource;
78 }
79 set
80 {
81 generatesSharedDesignTimeSource = value;
82 }
83 }
84
85 /// <summary>
86 /// UseDesignTimeCompilationFlag reg value name under HK EY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\[VsVer]\Generators\[ProjFacGuid ]\[GeneratorProgId]
87 /// </summary>
88 public int UseDesignTimeCompilationFlag
89 {
90 get
91 {
92 return useDesignTimeCompilationFlag;
93 }
94 set
95 {
96 useDesignTimeCompilationFlag = value;
97 }
98 }
99
100 /// <summary>
101 /// Generator Class ID.
102 /// </summary>
103 public Guid GeneratorClsid
104 {
105 get
106 {
107 return generatorClsid;
108 }
109 set
110 {
111 generatorClsid = value;
112 }
113 }
114 #endregion
115 }
116 #endregion
117
118 #region fields
119 /// <summary>
120 /// Base generator registry key for MPF based project
121 /// </summary>
122 private RegistryKey baseGeneratorRegistryKey;
123
124 /// <summary>
125 /// CLSID reg value name under HKEY_LOCAL_MACHINE\SOFTWARE\Micro soft\VisualStudio\[VsVer]\Generators\[ProjFacGuid]\[GeneratorProgId]
126 /// </summary>
127 private string GeneratorClsid = "CLSID";
128
129 /// <summary>
130 /// GeneratesDesignTimeSource reg value name under HKEY_LOCAL_MA CHINE\SOFTWARE\Microsoft\VisualStudio\[VsVer]\Generators\[ProjFacGuid]\[Generato rProgId]
131 /// </summary>
132 private string GeneratesDesignTimeSource = "GeneratesDesignTimeS ource";
133
134 /// <summary>
135 /// GeneratesSharedDesignTimeSource reg value name under HKEY_LO CAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\[VsVer]\Generators\[ProjFacGuid]\[Ge neratorProgId]
136 /// </summary>
137 private string GeneratesSharedDesignTimeSource = "GeneratesShare dDesignTimeSource";
138
139 /// <summary>
140 /// UseDesignTimeCompilationFlag reg value name under HKEY_LOCAL _MACHINE\SOFTWARE\Microsoft\VisualStudio\[VsVer]\Generators\[ProjFacGuid]\[Gener atorProgId]
141 /// </summary>
142 private string UseDesignTimeCompilationFlag = "UseDesignTimeComp ilationFlag";
143
144 /// <summary>
145 /// Caches all the generators registered for the project type.
146 /// </summary>
147 private Dictionary<string, GeneratorMetaData> generatorsMap = ne w Dictionary<string, GeneratorMetaData>();
148
149 /// <summary>
150 /// The project type guid of the associated project.
151 /// </summary>
152 private Guid projectType;
153
154 /// <summary>
155 /// A service provider
156 /// </summary>
157 private System.IServiceProvider serviceProvider;
158 #endregion
159
160 #region ctors
161 /// <summary>
162 /// Constructor for SingleFileGeneratorFactory
163 /// </summary>
164 /// <param name="projectGuid">The project type guid of the assoc iated project.</param>
165 /// <param name="serviceProvider">A service provider.</param>
166 public SingleFileGeneratorFactory(Guid projectType, System.IServ iceProvider serviceProvider)
167 {
168 this.projectType = projectType;
169 this.serviceProvider = serviceProvider;
170 }
171 #endregion
172
173 #region properties
174 /// <summary>
175 /// Defines the project type guid of the associated project.
176 /// </summary>
177 public Guid ProjectGuid
178 {
179 get { return this.projectType; }
180 set { this.projectType = value; }
181 }
182
183 /// <summary>
184 /// Defines an associated service provider.
185 /// </summary>
186 public System.IServiceProvider ServiceProvider
187 {
188 get { return this.serviceProvider; }
189 set { this.serviceProvider = value; }
190 }
191 #endregion
192
193 #region IVsSingleFileGeneratorFactory Helpers
194 /// <summary>
195 /// Returns the project generator key under [VS-ConfigurationRoo t]]\Generators
196 /// </summary>
197 private RegistryKey BaseGeneratorsKey
198 {
199 get
200 {
201 if(this.baseGeneratorRegistryKey == null)
202 {
203 using(RegistryKey root = VSRegistry.Regi stryRoot(__VsLocalRegistryType.RegType_Configuration))
204 {
205 if(null != root)
206 {
207 string regPath = "Genera tors\\" + this.ProjectGuid.ToString("B");
208 baseGeneratorRegistryKey = root.OpenSubKey(regPath);
209 }
210 }
211 }
212
213 return this.baseGeneratorRegistryKey;
214 }
215 }
216
217 /// <summary>
218 /// Returns the local registry instance
219 /// </summary>
220 private ILocalRegistry LocalRegistry
221 {
222 get
223 {
224 return this.serviceProvider.GetService(typeof(SL ocalRegistry)) as ILocalRegistry;
225 }
226 }
227 #endregion
228
229 #region IVsSingleFileGeneratorFactory Members
230 /// <summary>
231 /// Creates an instance of the single file generator requested
232 /// </summary>
233 /// <param name="progId">prog id of the generator to be created. For e.g HKLM\SOFTWARE\Microsoft\VisualStudio\9.0Exp\Generators\[prjfacguid]\[ws zProgId]</param>
234 /// <param name="generatesDesignTimeSource">GeneratesDesignTimeS ource key value</param>
235 /// <param name="generatesSharedDesignTimeSource">GeneratesShare dDesignTimeSource key value</param>
236 /// <param name="useTempPEFlag">UseDesignTimeCompilationFlag key value</param>
237 /// <param name="generate">IVsSingleFileGenerator interface</par am>
238 /// <returns>S_OK if succesful</returns>
239 public virtual int CreateGeneratorInstance(string progId, out in t generatesDesignTimeSource, out int generatesSharedDesignTimeSource, out int us eTempPEFlag, out IVsSingleFileGenerator generate)
240 {
241 Guid genGuid;
242 ErrorHandler.ThrowOnFailure(this.GetGeneratorInformation (progId, out generatesDesignTimeSource, out generatesSharedDesignTimeSource, out useTempPEFlag, out genGuid));
243
244 //Create the single file generator and pass it out. Chec k to see if it is in the cache
245 if(!this.generatorsMap.ContainsKey(progId) || ((this.gen eratorsMap[progId]).Generator == null))
246 {
247 Guid riid = VSConstants.IID_IUnknown;
248 uint dwClsCtx = (uint)CLSCTX.CLSCTX_INPROC_SERVE R;
249 IntPtr genIUnknown = IntPtr.Zero;
250 //create a new one.
251 ErrorHandler.ThrowOnFailure(this.LocalRegistry.C reateInstance(genGuid, null, ref riid, dwClsCtx, out genIUnknown));
252 if(genIUnknown != IntPtr.Zero)
253 {
254 try
255 {
256 object generator = Marshal.GetOb jectForIUnknown(genIUnknown);
257 //Build the generator meta data object and cache it.
258 GeneratorMetaData genData = new GeneratorMetaData();
259 genData.GeneratesDesignTimeSourc e = generatesDesignTimeSource;
260 genData.GeneratesSharedDesignTim eSource = generatesSharedDesignTimeSource;
261 genData.UseDesignTimeCompilation Flag = useTempPEFlag;
262 genData.GeneratorClsid = genGuid ;
263 genData.Generator = generator;
264 this.generatorsMap[progId] = gen Data;
265 }
266 finally
267 {
268 Marshal.Release(genIUnknown);
269 }
270 }
271 }
272
273 generate = (this.generatorsMap[progId]).Generator as IVs SingleFileGenerator;
274
275 return VSConstants.S_OK;
276 }
277
278 /// <summary>
279 /// Gets the default generator based on the file extension. HKLM \Software\Microsoft\VS\9.0\Generators\[prjfacguid]\.extension
280 /// </summary>
281 /// <param name="filename">File name with extension</param>
282 /// <param name="progID">The generator prog ID</param>
283 /// <returns>S_OK if successful</returns>
284 public virtual int GetDefaultGenerator(string filename, out stri ng progID)
285 {
286 progID = "";
287 return VSConstants.E_NOTIMPL;
288 }
289
290 /// <summary>
291 /// Gets the generator information.
292 /// </summary>
293 /// <param name="progId">prog id of the generator to be created. For e.g HKLM\SOFTWARE\Microsoft\VisualStudio\9.0Exp\Generators\[prjfacguid]\[ws zProgId]</param>
294 /// <param name="generatesDesignTimeSource">GeneratesDesignTimeS ource key value</param>
295 /// <param name="generatesSharedDesignTimeSource">GeneratesShare dDesignTimeSource key value</param>
296 /// <param name="useTempPEFlag">UseDesignTimeCompilationFlag key value</param>
297 /// <param name="guiddGenerator">CLSID key value</param>
298 /// <returns>S_OK if succesful</returns>
299 public virtual int GetGeneratorInformation(string progId, out in t generatesDesignTimeSource, out int generatesSharedDesignTimeSource, out int us eTempPEFlag, out Guid guidGenerator)
300 {
301 RegistryKey genKey;
302 generatesDesignTimeSource = -1;
303 generatesSharedDesignTimeSource = -1;
304 useTempPEFlag = -1;
305 guidGenerator = Guid.Empty;
306 if(string.IsNullOrEmpty(progId))
307 return VSConstants.S_FALSE;
308
309 //Create the single file generator and pass it out.
310 if(!this.generatorsMap.ContainsKey(progId))
311 {
312 // We have to check whether the BaseGeneratorkey returns null.
313 RegistryKey tempBaseGeneratorKey = this.BaseGene ratorsKey;
314 if(tempBaseGeneratorKey == null || (genKey = tem pBaseGeneratorKey.OpenSubKey(progId)) == null)
315 {
316 return VSConstants.S_FALSE;
317 }
318
319 //Get the CLSID
320 string guid = (string)genKey.GetValue(GeneratorC lsid, "");
321 if(string.IsNullOrEmpty(guid))
322 return VSConstants.S_FALSE;
323
324 GeneratorMetaData genData = new GeneratorMetaDat a();
325
326 genData.GeneratorClsid = guidGenerator = new Gui d(guid);
327 //Get the GeneratesDesignTimeSource flag. Assume 0 if not present.
328 genData.GeneratesDesignTimeSource = generatesDes ignTimeSource = (int)genKey.GetValue(this.GeneratesDesignTimeSource, 0);
329 //Get the GeneratesSharedDesignTimeSource flag. Assume 0 if not present.
330 genData.GeneratesSharedDesignTimeSource = genera tesSharedDesignTimeSource = (int)genKey.GetValue(GeneratesSharedDesignTimeSource , 0);
331 //Get the UseDesignTimeCompilationFlag flag. Ass ume 0 if not present.
332 genData.UseDesignTimeCompilationFlag = useTempPE Flag = (int)genKey.GetValue(UseDesignTimeCompilationFlag, 0);
333 this.generatorsMap.Add(progId, genData);
334 }
335 else
336 {
337 GeneratorMetaData genData = this.generatorsMap[p rogId];
338 generatesDesignTimeSource = genData.GeneratesDes ignTimeSource;
339 //Get the GeneratesSharedDesignTimeSource flag. Assume 0 if not present.
340 generatesSharedDesignTimeSource = genData.Genera tesSharedDesignTimeSource;
341 //Get the UseDesignTimeCompilationFlag flag. Ass ume 0 if not present.
342 useTempPEFlag = genData.UseDesignTimeCompilation Flag;
343 //Get the CLSID
344 guidGenerator = genData.GeneratorClsid;
345 }
346
347 return VSConstants.S_OK;
348 }
349 #endregion
350
351 }
352 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698