/// <include file='doc\PropertySheet.uex' path='docs/doc[@for="LanguagePreferences.Init"]/*' /> public virtual void Init() { ILocalRegistry3 localRegistry = site.GetService(typeof(SLocalRegistry)) as ILocalRegistry3; string root = null; if (localRegistry != null) { NativeMethods.ThrowOnFailure(localRegistry.GetLocalRegistryRoot(out root)); } if (root != null) { using (RegistryKey key = Registry.LocalMachine.OpenSubKey(root, false)) { if (key != null) { InitMachinePreferences(key, name); } } using (RegistryKey key = Registry.CurrentUser.OpenSubKey(root, false)) { if (key != null) { InitUserPreferences(key, name); } } } Connect(); localRegistry = null; }
public virtual void Init() { ILocalRegistry3 localRegistry = (ILocalRegistry3)site.GetService(typeof(SLocalRegistry)); string root = null; if (localRegistry != null) { localRegistry.GetLocalRegistryRoot(out root); } if (root != null) { using (RegistryKey key = Registry.LocalMachine.OpenSubKey(root, false)) { if (key != null) { InitMachinePreferences(key, editorName); } } using (RegistryKey key = Registry.CurrentUser.OpenSubKey(root, false)) { if (key != null) { InitUserPreferences(key, editorName); } } } localRegistry = null; }
public virtual void SetSite(Microsoft.VisualStudio.OLE.Interop.IServiceProvider psp) { this.site = new ServiceProvider(psp); extensions = new Hashtable(); ILocalRegistry3 localRegistry = (ILocalRegistry3)site.QueryService(VsConstants.SID_SLocalRegistry, typeof(ILocalRegistry3)); string root = null; if (localRegistry != null) { localRegistry.GetLocalRegistryRoot(out root); } using (RegistryKey rootKey = Registry.LocalMachine.OpenSubKey(root)) { if (rootKey != null) { string relpath = "Editors\\{" + this.GetType().GUID.ToString() + "}\\Extensions"; using (RegistryKey key = rootKey.OpenSubKey(relpath, false)) { if (key != null) { foreach (string ext in key.GetValueNames()) { extensions.Add(ext.ToLower(), ext); } } } } } }
public static string GetMsBuildPath(IServiceProvider serviceProvider) { string registryPath; if (serviceProvider == null) { return(String.Empty); } ILocalRegistry3 localRegistry = serviceProvider.GetService(typeof(SLocalRegistry)) as ILocalRegistry3; if (localRegistry == null) { return(String.Empty); } // first, we need the registry hive currently in use ErrorHandler.ThrowOnFailure(localRegistry.GetLocalRegistryRoot(out registryPath)); // now that we have it, append the subkey we are interested in to it if (!registryPath.EndsWith("\\")) { registryPath += '\\'; } registryPath += "MSBuild"; // finally, get the value from the registry Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(registryPath, false); string msBuildPath = (string)key.GetValue("MSBuildBinPath", null); if (msBuildPath == null || msBuildPath.Length <= 0) { string error = SR.GetString(SR.ErrorMsBuildRegistration); throw new FileLoadException(error); } return(msBuildPath); }
public RegistryKey OpenVSUserKey(string name) { ThreadHelper.ThrowIfNotOnUIThread(); RegistryKey rootKey = null; if (VSVersion.VS2005) { ILocalRegistry3 lr3 = GetService <ILocalRegistry3>(typeof(SLocalRegistry)); if (lr3 == null) { return(null); } string root; if (!VSErr.Succeeded(lr3.GetLocalRegistryRoot(out root))) { return(null); } rootKey = Registry.CurrentUser.OpenSubKey(root); } else { IMyLocalRegistry4 lr4 = GetService <IMyLocalRegistry4>(typeof(SLocalRegistry)); if (lr4 == null) { return(null); } uint type; const uint VsLocalRegistryRootHandle_CURRENT_USER = unchecked ((uint)-2147483647); string root; if (!VSErr.Succeeded(lr4.GetLocalRegistryRootEx(1 /* _VsLocalRegistryType.UserSettings */, out type, out root))) { return(null); } rootKey = ((type == VsLocalRegistryRootHandle_CURRENT_USER) ? Registry.CurrentUser : Registry.LocalMachine).OpenSubKey(root); } if (rootKey == null) { return(null); } else if (string.IsNullOrEmpty(name)) { return(rootKey); } using (rootKey) { return(rootKey.OpenSubKey(name)); } }
static Hashtable GetEditors(IServiceProvider site) { if (EditorFactory.editors != null) { return(EditorFactory.editors); } Hashtable editors = new Hashtable(); ILocalRegistry3 localRegistry = site.GetService(typeof(SLocalRegistry)) as ILocalRegistry3; string root = null; if (localRegistry == null) { return(editors); } NativeMethods.ThrowOnFailure(localRegistry.GetLocalRegistryRoot(out root)); using (RegistryKey rootKey = Registry.LocalMachine.OpenSubKey(root)) { if (rootKey != null) { RegistryKey editorsKey = rootKey.OpenSubKey("Editors", false); if (editorsKey != null) { using (editorsKey) { foreach (string editorGuid in editorsKey.GetSubKeyNames()) { Guid guid = GetGuid(editorGuid); using (RegistryKey editorKey = editorsKey.OpenSubKey(editorGuid, false)) { object value = editorKey.GetValue(null); string name = (value != null) ? value.ToString() : editorGuid.ToString(); RegistryKey extensions = editorKey.OpenSubKey("Extensions", false); if (extensions != null) { foreach (string s in extensions.GetValueNames()) { if (!string.IsNullOrEmpty(s)) { EditorInfo ei = new EditorInfo(); ei.name = name; ei.guid = guid; object obj = extensions.GetValue(s); if (obj is int) { ei.priority = (int)obj; } string ext = (s == "*") ? s : "." + s; AddEditorInfo(editors, ext.ToLowerInvariant(), ei); } } } } } } } } } return(EditorFactory.editors = editors); }
StringDictionary GetFileExtensionMappings() { ILocalRegistry3 localRegistry = site.GetService(typeof(SLocalRegistry)) as ILocalRegistry3; string root = null; if (localRegistry != null) { NativeMethods.ThrowOnFailure(localRegistry.GetLocalRegistryRoot(out root)); } StringDictionary map = new StringDictionary(); RegistryKey key = Registry.CurrentUser.OpenSubKey(root + "\\FileExtensionMapping", false); if (key != null) { using (key) { foreach (string name in key.GetSubKeyNames()) { using (RegistryKey extkey = key.OpenSubKey(name, false)) { if (extkey != null) { object obj = extkey.GetValue(null); if (obj is string) { string ext = "." + name; map[ext] = obj.ToString(); // extension -> editor. } } } } } } // Also pick up the "default editors" information key = Registry.CurrentUser.OpenSubKey(root + "\\Default Editors", false); if (key != null) { using (key) { foreach (string name in key.GetSubKeyNames()) { using (RegistryKey extkey = key.OpenSubKey(name, false)) { if (extkey != null) { object obj = extkey.GetValue("Custom"); if (obj is string) { string ext = "." + name; map[ext] = obj.ToString(); // extension -> editor. } } } } } } return(map); }
// ========================================================================================= // Constructors // ========================================================================================= /// <summary> /// Initializes a new instance of the <see cref="WixPackageSettings"/> class. /// </summary> /// <param name="serviceProvider">The <see cref="IServiceProvider"/> to use.</param> public WixPackageSettings(IServiceProvider serviceProvider) { WixHelperMethods.VerifyNonNullArgument(serviceProvider, "serviceProvider"); if (serviceProvider != null) { // get the Visual Studio registry root ILocalRegistry3 localRegistry = WixHelperMethods.GetService <ILocalRegistry3, SLocalRegistry>(serviceProvider); ErrorHandler.ThrowOnFailure(localRegistry.GetLocalRegistryRoot(out this.visualStudioRegistryRoot)); } }
// ========================================================================================= // Constructors // ========================================================================================= /// <summary> /// Initializes a new instance of the <see cref="XPackageSettings"/> class. /// </summary> /// <param name="serviceProvider">The <see cref="IServiceProvider"/> to use.</param> public XPackageSettings(IServiceProvider serviceProvider) { XHelperMethods.VerifyNonNullArgument(serviceProvider, "serviceProvider"); ThreadHelper.ThrowIfNotOnUIThread(); if (serviceProvider != null) { // get the Visual Studio registry root ILocalRegistry3 localRegistry = XHelperMethods.GetService <ILocalRegistry3, SLocalRegistry>(serviceProvider); ErrorHandler.ThrowOnFailure(localRegistry.GetLocalRegistryRoot(out this.visualStudioRegistryRoot)); } Instance = this; }
private bool GetValue(out object newValue) { string regRoot = "8.0"; ILocalRegistry3 registryService = GetService <SLocalRegistry>() as ILocalRegistry3; if (registryService != null) { registryService.GetLocalRegistryRoot(out regRoot); } newValue = regRoot; return(true); }
/// <summary> /// Search the registry fir the tool path for MSBuild. /// </summary> public static string GetMsBuildPath(IServiceProvider serviceProvider, string msbuildVersion) { string registryPath; if (serviceProvider == null) { return(String.Empty); } ILocalRegistry3 localRegistry = serviceProvider.GetService(typeof(SLocalRegistry)) as ILocalRegistry3; if (localRegistry == null) { return(String.Empty); } // first, we need the registry hive currently in use ErrorHandler.ThrowOnFailure(localRegistry.GetLocalRegistryRoot(out registryPath)); // now that we have it, append the subkey we are interested in to it if (!registryPath.EndsWith("\\")) { registryPath += '\\'; } registryPath += "MSBuild"; // finally, get the value from the registry string msBuildPath = null; using (Microsoft.Win32.RegistryKey vsKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(registryPath, false)) { msBuildPath = (string)vsKey.GetValue("MSBuildBinPath", null); } if (!string.IsNullOrEmpty(msBuildPath)) { return(msBuildPath); } // The path to MSBuild was not found in the VisualStudio's registry hive, so try to // find it in the new MSBuild hive. registryPath = string.Format(CultureInfo.InvariantCulture, "Software\\Microsoft\\MSBuild\\ToolsVersions\\{0}", msbuildVersion); using (Microsoft.Win32.RegistryKey msbuildKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(registryPath, false)) { msBuildPath = (string)msbuildKey.GetValue("MSBuildToolsPath", null); } if (string.IsNullOrEmpty(msBuildPath)) { string error = SR.GetString(SR.ErrorMsBuildRegistration); throw new FileLoadException(error); } return(msBuildPath); }
// ========================================================================================= // Constructors // ========================================================================================= /// <summary> /// Initializes a new instance of the <see cref="WixPackageSettings"/> class. /// </summary> /// <param name="serviceProvider">The <see cref="IServiceProvider"/> to use.</param> public WixPackageSettings(IServiceProvider serviceProvider) { WixHelperMethods.VerifyNonNullArgument(serviceProvider, "serviceProvider"); // get the Visual Studio registry root ILocalRegistry3 localRegistry = WixHelperMethods.GetService <ILocalRegistry3, SLocalRegistry>(serviceProvider); ErrorHandler.ThrowOnFailure(localRegistry.GetLocalRegistryRoot(out this.visualStudioRegistryRoot)); this.machineRootPath = WixHelperMethods.RegistryPathCombine(this.visualStudioRegistryRoot, @"InstalledProducts\WiX"); // initialize all of the machine settings this.toolsDirectory = new MachineSettingString(this.machineRootPath, KeyNames.ToolsDirectory, String.Empty); }
public static object CreateInstance(ServiceProvider provider, ref Guid clsid, ref Guid iid, Type t) { ILocalRegistry3 localRegistry = (ILocalRegistry3)provider.QueryService(VsConstants.SID_SLocalRegistry, typeof(ILocalRegistry3)); IntPtr pUnk; localRegistry.CreateInstance(clsid, null, ref iid, VsConstants.CLSCTX_INPROC_SERVER, out pUnk); localRegistry = null; object result = Marshal.GetTypedObjectForIUnknown(pUnk, t); Marshal.Release(pUnk); return(result); }
/// <summary> /// Return the current vs hive in where gax is executed. /// </summary> /// <returns></returns> public static string GetCurrentVsHive() { string regRoot = null; ILocalRegistry3 registry = Package.GetGlobalService(typeof(SLocalRegistry)) as ILocalRegistry3; // if we're at design-time try the VS service if (registry != null) { ErrorHandler.ThrowOnFailure(registry.GetLocalRegistryRoot(out regRoot)); regRoot = regRoot.Replace(VisualStudioRoot, string.Empty); return(regRoot.Split('\\')[0]); } return("14.0_Config"); }
public virtual ILanguageService CreateLanguageService(ref Guid guid) { ILocalRegistry3 localRegistry = (ILocalRegistry3)this.site.GetService(typeof(SLocalRegistry)); string root = null; if (localRegistry != null) { localRegistry.GetLocalRegistryRoot(out root); } string guidStr = guid.ToString("B"); using (RegistryKey rootKey = Registry.LocalMachine.OpenSubKey(root)){ Debug.Assert(rootKey != null); if (rootKey != null) { using (RegistryKey clsidKey = rootKey.OpenSubKey("CLSID")){ Debug.Assert(clsidKey != null); if (clsidKey != null) { foreach (string clsid in clsidKey.GetSubKeyNames()) { if (string.Compare(clsid, guidStr, true) == 0) { using (RegistryKey classKey = clsidKey.OpenSubKey(clsid)){ Debug.Assert(classKey != null); if (classKey != null) { RegistryKey inProcSvrKey = classKey.OpenSubKey("InprocServer32"); if (inProcSvrKey != null) { return(this.CreateLanguageService(localRegistry, inProcSvrKey)); } else { return(this.CreateLanguageService(localRegistry, classKey)); } } } } } } } } return(null); } }
static StringDictionary GetLanguageExtensions(IServiceProvider site) { if (EditorFactory.languageExtensions != null) { return(EditorFactory.languageExtensions); } StringDictionary extensions = new StringDictionary(); ILocalRegistry3 localRegistry = site.GetService(typeof(SLocalRegistry)) as ILocalRegistry3; string root = null; if (localRegistry != null) { NativeMethods.ThrowOnFailure(localRegistry.GetLocalRegistryRoot(out root)); } using (RegistryKey rootKey = Registry.LocalMachine.OpenSubKey(root)) { if (rootKey != null) { string relpath = "Languages\\File Extensions"; using (RegistryKey key = rootKey.OpenSubKey(relpath, false)) { if (key != null) { foreach (string ext in key.GetSubKeyNames()) { using (RegistryKey extkey = key.OpenSubKey(ext, false)) { if (extkey != null) { string fe = ext; string guid = extkey.GetValue(null) as string; // get default value if (!extensions.ContainsKey(fe)) { extensions.Add(fe, guid); } } } } } } } } return(EditorFactory.languageExtensions = extensions); }
public override void Execute() { string vsHive = @"SOFTWARE\Microsoft\VisualStudio\8.0"; ILocalRegistry3 localRegistry = GetService <SLocalRegistry>() as ILocalRegistry3; if (localRegistry != null) { localRegistry.GetLocalRegistryRoot(out vsHive); } using (RegistryKey vsdTemplates = Registry.LocalMachine.OpenSubKey(Path.Combine(vsHive, @"Projects\{54435603-DBB4-11D2-8724-00A0C9A8B90C}\AddItemTemplates\TemplateDirs\{66D6F801-B1EC-40A4-BB15-318617E96DAD}"))) { RegistryKey vsdTemplateDir = vsdTemplates.OpenSubKey("/1"); Template = ((string)vsdTemplateDir.GetValue("TemplatesDir")) + @"\Setup.vdproj"; ProjectName = PackageName + "Setup.vdproj"; EnvDTE.DTE dte = GetService <EnvDTE.DTE>(true); string slnFolder = (string)(dte.Solution.Properties.Item("Path").Value); slnFolder = slnFolder.Substring(0, slnFolder.LastIndexOf("\\")); ProjectFolder = slnFolder + @"\" + PackageName + "Setup"; } }
private ILanguageService CreateLanguageService(ILocalRegistry3 localRegistry, RegistryKey classInfo) { string typeName = classInfo.GetValue("Class") as String; Debug.Assert(typeName != null, "Registry value for 'Class' is missing or is not a string"); string assembly = classInfo.GetValue("Assembly") as String; Debug.Assert(assembly != null, "Registry value for 'Assembly' is missing or is not a string"); string codeBase = classInfo.GetValue("CodeBase") as String; Debug.Assert(codeBase != null, "Registry value for 'CodeBase' is missing or is not a string"); IntPtr pUnk; Guid iid = typeof(ILanguageService).GUID; localRegistry.CreateManagedInstance(codeBase, assembly, typeName, ref iid, out pUnk); ILanguageService result = null; try{ result = (ILanguageService)Marshal.GetTypedObjectForIUnknown(pUnk, typeof(ILanguageService)); }finally{ Marshal.Release(pUnk); } return(result); }
public virtual void SetSite(Microsoft.VisualStudio.OLE.Interop.IServiceProvider site) { this.site = new ServiceProvider(site); this.editorFactory = CreateEditorFactory(); if (this.editorFactory != null) { this.editorFactory.SetSite(site); Guid editorGuid = this.editorFactory.GetType().GUID; IVsRegisterEditors vre = (IVsRegisterEditors)this.site.QueryService(VsConstants.SID_SVsRegisterEditors, typeof(IVsRegisterEditors)); vre.RegisterEditor(ref editorGuid, editorFactory, out this.editorFactoryCookie); } this.projectFactory = CreateProjectFactory(); if (this.projectFactory != null) { this.projectFactory.SetSite(site); IVsRegisterProjectTypes rpt = (IVsRegisterProjectTypes)this.site.QueryService(VsConstants.SID_IVsRegisterProjectTypes, typeof(IVsRegisterProjectTypes)); if (rpt != null) { Guid projectType = this.projectFactory.GetType().GUID; rpt.RegisterProjectType(ref projectType, this.projectFactory, out this.projectFactoryCookie); } } uint lcid = VsShell.GetProviderLocale(this.site); languageServices = new Hashtable(); string thisPackage = "{" + this.GetType().GUID.ToString() + "}"; ServiceProvider thisSite = new ServiceProvider((Microsoft.VisualStudio.OLE.Interop.IServiceProvider) this); ILocalRegistry3 localRegistry = (ILocalRegistry3)this.site.QueryService(VsConstants.SID_SLocalRegistry, typeof(ILocalRegistry3)); string root = null; if (localRegistry != null) { localRegistry.GetLocalRegistryRoot(out root); } using (RegistryKey rootKey = Registry.LocalMachine.OpenSubKey(root)) { if (rootKey != null) { using (RegistryKey languages = rootKey.OpenSubKey("Languages\\Language Services")) { if (languages != null) { foreach (string languageName in languages.GetSubKeyNames()) { using (RegistryKey langKey = languages.OpenSubKey(languageName)) { object pkg = langKey.GetValue("Package"); if (pkg is string && string.Compare((string)pkg, thisPackage, false) == 0) { object guid = langKey.GetValue(null); if (guid is string) { Guid langGuid = new Guid((string)guid); if (!this.languageServices.Contains(langGuid.ToString())) { ILanguageService svc = CreateLanguageService(ref langGuid); if (svc != null) { svc.Init(thisSite, ref langGuid, lcid, GetFileExtensions(rootKey, (string)guid)); this.languageServices.Add(langGuid.ToString(), svc); } } } } } } } } } } //register with ComponentManager for Idle processing this.componentManager = (IOleComponentManager)this.site.QueryService(VsConstants.SID_SOleComponentManager, typeof(IOleComponentManager)); if (componentID == 0) { OLECRINFO[] crinfo = new OLECRINFO[1]; crinfo[0].cbSize = (uint)Marshal.SizeOf(typeof(OLECRINFO)); crinfo[0].grfcrf = (uint)OLECRF.olecrfNeedIdleTime | (uint)OLECRF.olecrfNeedPeriodicIdleTime; crinfo[0].grfcadvf = (uint)OLECADVF.olecadvfModal | (uint)OLECADVF.olecadvfRedrawOff | (uint)OLECADVF.olecadvfWarningsOff; crinfo[0].uIdleTimeInterval = 1000; this.componentManager.FRegisterComponent(this, crinfo, out componentID); } }
private ILanguageService CreateLanguageService(ILocalRegistry3 localRegistry, RegistryKey classInfo){ string typeName = classInfo.GetValue("Class") as String; Debug.Assert(typeName != null, "Registry value for 'Class' is missing or is not a string"); string assembly = classInfo.GetValue("Assembly") as String; Debug.Assert(assembly != null, "Registry value for 'Assembly' is missing or is not a string"); string codeBase = classInfo.GetValue("CodeBase") as String; Debug.Assert(codeBase != null, "Registry value for 'CodeBase' is missing or is not a string"); IntPtr pUnk; Guid iid = typeof(ILanguageService).GUID; localRegistry.CreateManagedInstance(codeBase, assembly, typeName, ref iid, out pUnk); ILanguageService result = null; try{ result = (ILanguageService)Marshal.GetTypedObjectForIUnknown(pUnk, typeof(ILanguageService)); }finally{ Marshal.Release(pUnk); } return result; }