internal void CheckEmacsVskSelected() { try { if (!IsEmacsVskInstalled) { return; } ILocalRegistry2 service = ServiceProvider.GetService <SLocalRegistry, ILocalRegistry2>(); var pbstrRoot = (string)null; service.GetLocalRegistryRoot(out pbstrRoot); using (RegistryKey registryKey1 = Registry.CurrentUser.OpenSubKey(pbstrRoot)) { if (registryKey1 == null) { return; } using (RegistryKey registryKey2 = registryKey1.OpenSubKey("Keyboard")) { if (registryKey2 == null) { return; } var path = registryKey2.GetValue("SchemeName") as string; IsEnabled = !string.IsNullOrEmpty(path) && string.Equals("VsEmacs.vsk", Path.GetFileName(path), StringComparison.InvariantCultureIgnoreCase); } } } catch { IsEnabled = false; } }
/// <summary> /// Returns a RegistryKey object for the root of a given storage type. /// It is up to the caller to dispose the returned object. /// </summary> /// <param name="provider">The service provider to use to access the Visual Studio's services.</param> /// <param name="registryType">The type of registry storage to open.</param> /// <param name="writable">Flag to indicate is the key should be writable.</param> public static RegistryKey RegistryRoot(IServiceProvider provider, __VsLocalRegistryType registryType, bool writable) { if (null == provider) { throw new ArgumentNullException("provider"); } // The current implementation of the shell supports only RegType_UserSettings and // RegType_Configuration, so for any other values we have to return not implemented. if ((__VsLocalRegistryType.RegType_UserSettings != registryType) && (__VsLocalRegistryType.RegType_Configuration != registryType)) { throw new NotSupportedException(); } // Try to get the new ILocalRegistry4 interface that is able to handle the new // registry paths. ILocalRegistry4 localRegistry = provider.GetService(typeof(SLocalRegistry)) as ILocalRegistry4; if (null != localRegistry) { uint rootHandle; string rootPath; if (ErrorHandler.Succeeded(localRegistry.GetLocalRegistryRootEx((uint)registryType, out rootHandle, out rootPath))) { // Check if we have valid data. __VsLocalRegistryRootHandle handle = (__VsLocalRegistryRootHandle)rootHandle; if (!string.IsNullOrEmpty(rootPath) && (__VsLocalRegistryRootHandle.RegHandle_Invalid != handle)) { // Check if the root is inside HKLM or HKCU. Note that this does not depends only from // the registry type, but also from instance-specific data like the RANU flag. RegistryKey root = (__VsLocalRegistryRootHandle.RegHandle_LocalMachine == handle) ? Registry.LocalMachine : Registry.CurrentUser; return(root.OpenSubKey(rootPath, writable)); } } } // We are here if the usage of the new interface failed for same reason, so we have to fall back to // the ond way to access the registry. ILocalRegistry2 oldRegistry = provider.GetService(typeof(SLocalRegistry)) as ILocalRegistry2; if (null == oldRegistry) { // There is something wrong with this installation or this service provider. return(null); } string registryPath; NativeMethods.ThrowOnFailure(oldRegistry.GetLocalRegistryRoot(out registryPath)); if (string.IsNullOrEmpty(registryPath)) { return(null); } RegistryKey regRoot = (__VsLocalRegistryType.RegType_Configuration == registryType) ? Registry.LocalMachine : Registry.CurrentUser; return(regRoot.OpenSubKey(registryPath, writable)); }
private void EnsureContexts() { ThreadHelper.ThrowIfNotOnUIThread(); if (_otherSccProviderContexts == null) { List <SccData> sccs = new List <SccData>(); ILocalRegistry2 lr = GetService <ILocalRegistry2>(typeof(SLocalRegistry)); string root; List <string> names = new List <string>(); if (VSErr.Succeeded(lr.GetLocalRegistryRoot(out root))) { RegistryKey baseKey = Registry.LocalMachine; // TODO: Find some way to use the VS2008 RANU api if (root.EndsWith("\\UserSettings")) { root = root.Substring(0, root.Length - 13) + "\\Configuration"; baseKey = Registry.CurrentUser; } using (RegistryKey rk = baseKey.OpenSubKey(root + "\\SourceControlProviders", RegistryKeyPermissionCheck.ReadSubTree)) { if (rk != null) { string myId = AnkhId.SccProviderGuid.ToString("B"); foreach (string name in rk.GetSubKeyNames()) { if (name.Length == 38 && !myId.Equals(name, StringComparison.OrdinalIgnoreCase)) { try { using (RegistryKey rks = rk.OpenSubKey(name, RegistryKeyPermissionCheck.ReadSubTree)) { string service = rks.GetValue("Service") as string; if (!string.IsNullOrEmpty(service)) { Guid sccGuid = new Guid(name); CmdStateCacheItem cache = GetCache(new Guid(name)); sccs.Add(new SccData(cache, service)); } } } catch { } } } } } } _otherSccProviderContexts = sccs.ToArray(); } }
private string GetVsInstallPath() { ILocalRegistry2 service = ServiceProvider.GetService <SLocalRegistry, ILocalRegistry2>(); var pbstrRoot = (string)null; service.GetLocalRegistryRoot(out pbstrRoot); using (RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(pbstrRoot)) return(Path.GetDirectoryName(registryKey.GetValue("InstallDir") as string)); }
protected override void SetOutputLogger(IVsOutputWindowPane output) { if (BuildLogger == null) { // Need to get the outer IVsHierarchy because may be aggregated. System.IntPtr unknown = System.IntPtr.Zero; IVsHierarchy hierarchy = null; try { unknown = Marshal.GetIUnknownForObject(this); hierarchy = Marshal.GetTypedObjectForIUnknown(unknown, typeof(IVsHierarchy)) as IVsHierarchy; } finally { if (unknown != System.IntPtr.Zero) { Marshal.Release(unknown); } } // Create the logger. BuildLogger = new VsLogger(output, TaskProvider, hierarchy); // To retrive the verbosity level the logger depends on the registry root. ILocalRegistry2 registry = GetService(typeof(SLocalRegistry)) as ILocalRegistry2; if (registry != null) { string registryRoot; registry.GetLocalRegistryRoot(out registryRoot); VsLogger logger = BuildLogger as VsLogger; if (!string.IsNullOrEmpty(registryRoot) && logger != null) { logger.VerbosityRegistryRoot = registryRoot; logger.ErrorString = ErrorString; logger.WarningString = WarningString; } } } else { ((VsLogger)BuildLogger).OutputWindowPane = output; } if (BuildEngine != null) { BuildEngine.UnregisterAllLoggers(); BuildEngine.RegisterLogger(BuildLogger); } }
static public String GetLocalRegistryRoot() { // Get the visual studio root key if (VsRoot == null) { ILocalRegistry2 localReg = GetService(typeof(ILocalRegistry)) as ILocalRegistry2; if (localReg != null) { localReg.GetLocalRegistryRoot(out VsRoot); } if (VsRoot == null) { VsRoot = @"Software\Microsoft\VisualStudio\10.0"; // Guess on failure } } return(VsRoot); }
static public String GetLocalRegistryRoot() { // Get the visual studio root key string vsRoot = null; ILocalRegistry2 localReg = GetService(typeof(ILocalRegistry)) as ILocalRegistry2; if (localReg != null) { localReg.GetLocalRegistryRoot(out vsRoot); if (vsRoot != null) { return(vsRoot); } } #if DEV10 return(@"Software\Microsoft\VisualStudio\10.0"); // Guess on failure #else return(@"Software\Microsoft\VisualStudio\9.0"); // Guess on failure #endif }