/// <summary> /// Loads the Visual Studio private registry, which is implicitly done when creating /// a new ExternalSettingsManager. The private registry contains the search paths to the /// extensions which is required for the Check-In Policies to work. /// /// Calling this method on a 64bit process will not work, as a BadImageException is thrown. /// </summary> /// <param name="devenvPath">Path to the Visual Studio installation for which the private registry shall be loaded</param> private void LoadAssemblySearchPathFromVisualStudioPrivateRegistry(string devenvPath) { Trace.WriteLine($"Loading VS private registry for '{devenvPath}"); myExternalSettingsManager = ExternalSettingsManager.CreateForApplication(devenvPath); Trace.WriteLine("ApplicationExtensions:" + myExternalSettingsManager.GetApplicationDataFolder(ApplicationDataFolder.ApplicationExtensions)); Trace.WriteLine(myExternalSettingsManager.GetApplicationDataFolder(ApplicationDataFolder.Configuration)); Trace.WriteLine(myExternalSettingsManager.GetApplicationDataFolder(ApplicationDataFolder.Documents)); Trace.WriteLine(myExternalSettingsManager.GetApplicationDataFolder(ApplicationDataFolder.LocalSettings)); Trace.WriteLine(myExternalSettingsManager.GetApplicationDataFolder(ApplicationDataFolder.RoamingSettings)); Trace.WriteLine("UserExtensions :" + myExternalSettingsManager.GetApplicationDataFolder(ApplicationDataFolder.UserExtensions)); foreach (string searchPath in myExternalSettingsManager.GetCommonExtensionsSearchPaths()) { Trace.WriteLine("CommonExtensionsPath :" + searchPath); } SettingsStore store = myExternalSettingsManager.GetReadOnlySettingsStore(SettingsScope.UserSettings); var propNames = store.GetPropertyNames(@"ExtensionManager\EnabledExtensions"); myAssemblySearchPaths.AddRange(myExternalSettingsManager.GetCommonExtensionsSearchPaths()); string userExtensions = myExternalSettingsManager.GetApplicationDataFolder(ApplicationDataFolder.UserExtensions); if (!userExtensions.IsNullOrEmpty()) { myAssemblySearchPaths.Add(Path.Combine(myVisualStudioInstallationPath, userExtensions)); } myAssemblySearchPaths.Add(Path.Combine(myVisualStudioInstallationPath, myTeamExplorerFolder)); }
/// <summary> /// Initialization of the package; this method is called right after the package is sited, so this is the place /// where you can put all the initialization code that rely on services provided by VisualStudio. /// </summary> protected override void Initialize() { CompareDirectoriesCommand.Initialize(this); base.Initialize(); using (ServiceProvider serviceProvider = new ServiceProvider((IServiceProvider)(Package.GetGlobalService(typeof(IServiceProvider))))) { SettingsManager settingsManager = new ShellSettingsManager(serviceProvider); SettingsStore settingsStore = settingsManager.GetReadOnlySettingsStore(SettingsScope.UserSettings); if (settingsStore.CollectionExists(FilterSettings)) { IEnumerable <string> propertyNames = settingsStore.GetPropertyNames(FilterSettings); foreach (string propertyName in propertyNames) { var filter = settingsStore.GetString(FilterSettings, propertyName, null); if (filter != null) { CommonFilters.Add(filter); } } } } if (CommonFilters.Count == 0) { CommonFilters.Add("-*.dll;-*.pdb;-*.obj;-*.exe;-*.vsix;-.vs\\*;-*obj\\*;-*bin\\*;-.git\\*;-packages\\*"); CommonFilters.Add("*.cs;*.vb;*.c;*.cpp;*.h"); CommonFilters.Add(string.Empty); } }
private static bool?GetOutOfProcessSettingFromSessionStore(AcuminatorVSPackage package) { const bool defaultOutOfProcessValue = true; const string settingsStoreOutOfProcessValuePath = @"Roslyn\Internal\OnOff\Features"; const string OutOfProcessPropertyName = "OOP64Bit"; var shellSettingsManager = new ShellSettingsManager(package); SettingsStore settingsStore = shellSettingsManager.GetReadOnlySettingsStore(SettingsScope.UserSettings); if (settingsStore == null) { return(null); } else if (!settingsStore.CollectionExists(settingsStoreOutOfProcessValuePath)) { return(defaultOutOfProcessValue); } var propertyNames = settingsStore.GetPropertyNames(settingsStoreOutOfProcessValuePath); if (!propertyNames.Contains(OutOfProcessPropertyName)) { return(defaultOutOfProcessValue); } int?outOfProcessValue = settingsStore.GetInt32(settingsStoreOutOfProcessValuePath, OutOfProcessPropertyName) as int?; return(outOfProcessValue.HasValue ? outOfProcessValue == 1 : defaultOutOfProcessValue); }
public IEnumerable <AutoLoadPackage> GetAutoLoadPackages() { foreach (string autoLoadContextGuidString in _configurationStore.GetSubCollectionNames(_autoLoadPackagesPath)) { //Each path here is a context GUID Guid contextGuid = Guid.Empty; if (!Guid.TryParse(autoLoadContextGuidString, out contextGuid)) { continue; } string packagesPath = Path.Combine(_autoLoadPackagesPath, autoLoadContextGuidString); string contextName = GetUIContextName(autoLoadContextGuidString); bool isRuleBasedUIContext = IsRuleBasedUIContext(autoLoadContextGuidString); string uiContextExpression = string.Empty; if (isRuleBasedUIContext) { string rulePath = Path.Combine(_uIContextRulesPath, autoLoadContextGuidString); var expression = new StringBuilder(); foreach (string expressionName in _configurationStore.GetPropertyNames(rulePath)) { if (expressionName != "" && expressionName != "Expression" && expressionName != "Delay") { expression.Append(_configurationStore.GetString(rulePath, expressionName) + "|"); } } uiContextExpression = expression.ToString(); } foreach (string packageGuidString in _configurationStore.GetPropertyNames(packagesPath)) { Guid packageGuid = Guid.Empty; if (Guid.TryParse(packageGuidString, out packageGuid)) { yield return(new AutoLoadPackage(packageGuid, contextGuid, contextName, isRuleBasedUIContext, uiContextExpression, _configurationStore)); } } } }
public MRUHelper(string path) { ExternalSettingsManager externalSettingsManager = ExternalSettingsManager.CreateForApplication(path); settingsStore = externalSettingsManager.GetReadOnlySettingsStore(SettingsScope.UserSettings); foreach (string name in settingsStore.GetPropertyNames(@"MRUItems\{a9c4a31f-f9cb-47a9-abc0-49ce82d0b3ac}\Items")) { string value = settingsStore.GetString(@"MRUItems\{a9c4a31f-f9cb-47a9-abc0-49ce82d0b3ac}\Items", name); Console.WriteLine("Property name: {0}, value: {1}", name, value.Split('|')[0]); recentProjectsPaths.Add(value.Split('|')[0]); } }
/// <summary> /// Hydrates the properties from the registry asyncronously. /// </summary> public virtual async Task LoadAsync() { ShellSettingsManager manager = await _settingsManager.GetValueAsync().ConfigureAwait(true); SettingsStore settingsStore = manager.GetReadOnlySettingsStore(SettingsScope.UserSettings); if (!settingsStore.CollectionExists(CollectionName)) { return; } #if DEBUG_OPTION_VALUES_LOAD_SAVE Debug.WriteLine($"LoadAsync<{typeof(T).Name}>()"); Debug.WriteLine($"GetPropertyCount = {settingsStore.GetPropertyCount(CollectionName)}"); Debug.WriteLine($"GetPropertyCount = {settingsStore.GetPropertyCount(CollectionName)}"); //var pnv = settingsStore.GetPropertyNamesAndValues(CollectionName); var pn = settingsStore.GetPropertyNames(CollectionName); foreach (var n in pn) { Debug.WriteLine($"Property: Name={n} Type = {settingsStore.GetPropertyType(CollectionName, n).ToString()}"); } #endif var propertiesToSerialize = GetOptionProperties(); foreach (PropertyInfo property in propertiesToSerialize) { if (!settingsStore.PropertyExists(CollectionName, property.Name)) { #if DEBUG_OPTION_VALUES_LOAD_SAVE Debug.WriteLine($"Skipping property {property.Name}. Not found in settings store"); #endif property.SetValue(this, property.GetValue(this)); continue; } try { string serializedProp = settingsStore.GetString(CollectionName, property.Name); object value = DeserializeValue(serializedProp, property.PropertyType); property.SetValue(this, value); #if DEBUG_OPTION_VALUES_LOAD_SAVE Debug.WriteLine($"{property.Name} = {property.GetValue(this)} | value = {value}"); #endif } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); } } #if DEBUG_OPTION_VALUES_LOAD_SAVE Debug.WriteLine($"LoadAsync<{typeof(T).Name}>() finished ==================================="); #endif }
private string GetSettingsPath() { var settingName = "VisualStudioProjectsLocation"; SettingsManager sm = new ShellSettingsManager(ServiceProvider.GlobalProvider); SettingsStore ss = sm.GetReadOnlySettingsStore(SettingsScope.UserSettings); string setting = ""; try { setting = ss.GetString("", settingName); } catch (Exception ex) { string collection = ""; foreach (string s in ss.GetPropertyNames("")) { collection += s + "\r\n"; } MessageBox.Show($"Cannot find {settingName} in {collection}"); } return(Environment.ExpandEnvironmentVariables(setting)); }
public int GetPropertyName([ComAliasName("OLE.LPCOLESTR")] string collectionPath, [ComAliasName("OLE.DWORD")] uint index, out string propertyName) { propertyName = inner.GetPropertyNames(collectionPath).ElementAt((int)index); return(0); }