private void PopulatePropertyList(List <PropertyConfig> propertyList, PropertySystemNativeMethods.PropDescEnumFilter filter) { propertyList.Clear(); IPropertyDescriptionList propertyDescriptionList = null; IPropertyDescription propertyDescription = null; Guid guid = new Guid(ShellIIDGuid.IPropertyDescriptionList); try { var hr = PropertySystemNativeMethods.PSEnumeratePropertyDescriptions( filter, ref guid, out propertyDescriptionList); if (hr >= 0) { propertyDescriptionList.GetCount(out uint count); guid = new Guid(ShellIIDGuid.IPropertyDescription); for (uint i = 0; i < count; i++) { propertyDescriptionList.GetAt(i, ref guid, out propertyDescription); if (propertyDescription != null) { var shellProperty = new ShellPropertyDescription(propertyDescription); var pc = new PropertyConfig(shellProperty); shellProperty.Dispose(); // Releases propertyDescription propertyDescription = null; GetInstalledProperty(pc, true); // Add search and alias info propertyList.Add(pc); DictInstalledProperties.Add(pc.CanonicalName, pc); } } } } finally { if (propertyDescriptionList != null) { Marshal.ReleaseComObject(propertyDescriptionList); } if (propertyDescription != null) { Marshal.ReleaseComObject(propertyDescription); } } }
private PropertyConfig GetInstalledProperty(PropertyConfig pc, bool skipBasics = false) { try { PropertyConfig installed = null; var key = new PropertyKey(pc.FormatId, (int)pc.PropertyId); var guidDescription = new Guid(ShellIIDGuid.IPropertyDescription); if (!skipBasics) { var hr = PropertySystemNativeMethods.PSGetPropertyDescription( ref key, ref guidDescription, out IPropertyDescription propertyDescription); if (hr >= 0) { var shellProperty = new ShellPropertyDescription(propertyDescription); installed = new PropertyConfig(shellProperty); shellProperty.Dispose(); // Releases propertyDescription } } else { installed = pc; // Continue populating existing config } if (installed != null) { var guidSearch = new Guid(ShellIIDGuid.IPropertyDescriptionSearchInfo); var hr = PropertySystemNativeMethods.PSGetPropertyDescription( ref key, ref guidSearch, out IPropertyDescriptionSearchInfo propSearchInfo); if (hr >= 0) { hr = propSearchInfo.GetSearchInfoFlags(out PropertySearchInfoFlags searchOptions); if (hr >= 0) { installed.InInvertedIndex = searchOptions.HasFlag(PropertySearchInfoFlags.InInvertedIndex); installed.IsColumn = searchOptions.HasFlag(PropertySearchInfoFlags.IsColumn); installed.IsColumnSparse = searchOptions.HasFlag(PropertySearchInfoFlags.IsColumnSparse); installed.AlwaysInclude = searchOptions.HasFlag(PropertySearchInfoFlags.AlwaysInclude); installed.UseForTypeAhead = searchOptions.HasFlag(PropertySearchInfoFlags.UseForTypeAhead); } hr = propSearchInfo.GetColumnIndexType(out ColumnIndexType ppType); if (hr >= 0) { installed.ColumnIndexType = ppType; } // Just the canonical name again //hr = propSearchInfo.GetProjectionString(out IntPtr namePtr); //if (CoreErrorHelper.Succeeded(hr) && namePtr != IntPtr.Zero) //{ // string displayName = Marshal.PtrToStringUni(namePtr); // Marshal.FreeCoTaskMem(namePtr); //} hr = propSearchInfo.GetMaxSize(out uint maxSize); if (hr >= 0) { installed.MaxSize = maxSize; } Marshal.ReleaseComObject(propSearchInfo); } var guidAlias = new Guid(ShellIIDGuid.IPropertyDescriptionAliasInfo); hr = PropertySystemNativeMethods.PSGetPropertyDescription( ref key, ref guidAlias, out IPropertyDescriptionAliasInfo propAliasInfo); if (hr >= 0) { hr = propAliasInfo.GetSortByAlias(guidDescription, out IPropertyDescription alias); if (hr >= 0 && alias != null) { alias.GetCanonicalName(out string canonicalName); pc.SortByAlias = canonicalName; // To do Consider adding additional aliases Marshal.ReleaseComObject(alias); } Marshal.ReleaseComObject(propAliasInfo); } } return(installed); } #pragma warning disable CS0168 // Variable is declared but never used #pragma warning disable IDE0059 // Unnecessary assignment of a value catch (Exception ex) #pragma warning restore IDE0059 // Unnecessary assignment of a value #pragma warning restore CS0168 // Variable is declared but never used { return(null); } }
internal PropertyConfig(ShellPropertyDescription propertyDescription) { // Basics CanonicalName = propertyDescription.CanonicalName; FormatId = propertyDescription.PropertyKey.FormatId; PropertyId = propertyDescription.PropertyKey.PropertyId; // Search information // Not held in property description, so set the defaults InInvertedIndex = false; IsColumn = false; IsColumnSparse = true; ColumnIndexType = ColumnIndexType.OnDemand; MaxSize = 512; Mnemonics = null; // Label information DisplayName = propertyDescription.DisplayName; EditInvitation = propertyDescription.EditInvitation; SortDescription = propertyDescription.SortDescription; HideLabel = propertyDescription.ViewFlags.HasFlag(PropertyViewOptions.HideLabel); // Type information Type = PropertyUtils.VarEnumToPropertyType(propertyDescription.VarEnumType); GroupingRange = propertyDescription.GroupingRange; MultipleValues = propertyDescription.TypeFlags.HasFlag(PropertyTypeOptions.MultipleValues); IsInnate = propertyDescription.TypeFlags.HasFlag(PropertyTypeOptions.IsInnate); CanBePurged = propertyDescription.TypeFlags.HasFlag(PropertyTypeOptions.CanBePurged); IsGroup = propertyDescription.TypeFlags.HasFlag(PropertyTypeOptions.IsGroup); AggregationType = propertyDescription.AggregationTypes; // Pre-Windows 7 //CanGroupBy = propertyDescription.TypeFlags.HasFlag(PropertyTypeOptions.CanGroupBy); //CanStackBy = propertyDescription.TypeFlags.HasFlag(PropertyTypeOptions.CanStackBy); IsTreeProperty = propertyDescription.TypeFlags.HasFlag(PropertyTypeOptions.IsTreeProperty); IsViewable = propertyDescription.TypeFlags.HasFlag(PropertyTypeOptions.IsViewable); IsSystemProperty = propertyDescription.TypeFlags.HasFlag(PropertyTypeOptions.IsSystemProperty); ConditionType = propertyDescription.ConditionType; ConditionOperationInstalled = propertyDescription.ConditionOperation; // Display information DisplayType = propertyDescription.DisplayType; DefaultColumnWidth = propertyDescription.DefaultColumnWidth; if (propertyDescription.ViewFlags.HasFlag(PropertyViewOptions.CenterAlign)) { Alignment = PropertyAlignmentType.Center; } else if (propertyDescription.ViewFlags.HasFlag(PropertyViewOptions.RightAlign)) { Alignment = PropertyAlignmentType.Right; } else { Alignment = PropertyAlignmentType.Left; } RelativeDescriptionType = propertyDescription.RelativeDescriptionType; if (propertyDescription.ViewFlags.HasFlag(PropertyViewOptions.SortDescending)) { DefaultSortDirection = SortDirection.Descending; } else { DefaultSortDirection = SortDirection.Ascending; } // Pre-Windows 7 displayInfo //ColumnState = propertyDescription.ColumnState; // To do elements controlling editing the property // They do not seem to be readable: we have EditControl so far // To do. See if these have any more juice in them ViewFlags = propertyDescription.ViewFlags; }