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); } }