Exemplo n.º 1
0
        private void PopulateSystemProperties()
        {
            IPropertyDescriptionList propertyDescriptionList = null;
            IPropertyDescription     propertyDescription     = null;
            Guid guid = new Guid(ShellIIDGuid.IPropertyDescriptionList);

            try
            {
                int hr = PropertySystemNativeMethods.PSEnumeratePropertyDescriptions(PropertySystemNativeMethods.PropDescEnumFilter.PDEF_ALL, ref guid, out propertyDescriptionList);
                if (hr >= 0)
                {
                    uint count;
                    propertyDescriptionList.GetCount(out count);
                    guid = new Guid(ShellIIDGuid.IPropertyDescription);
                    Dictionary <string, List <string> > dict = new Dictionary <string, List <string> >();

                    for (uint i = 0; i < count; i++)
                    {
                        propertyDescriptionList.GetAt(i, ref guid, out propertyDescription);
                        var spd = new ShellPropertyDescription(propertyDescription);

                        propDescs.Add(spd);
                        propDescDict.Add(spd.CanonicalName, spd);
                    }
                }
            }
            finally
            {
                if (propertyDescriptionList != null)
                {
                    Marshal.ReleaseComObject(propertyDescriptionList);
                }
            }
        }
Exemplo n.º 2
0
        public void GetTextAssociation_QuickTip()
        {
            string value = ShellMethods.AssocQueryString(AssociationFlags.None, AssociationString.QuickTip, ".txt", null);

            value.Should().Be("prop:System.ItemTypeText;System.Size;System.DateModified");

            IPropertyDescriptionList list = ShellMethods.GetPropertyDescriptionListFromString(value);

            list.GetCount().Should().Be(3);
            IPropertyDescription desc = list.GetAt(0, new Guid(InterfaceIds.IID_IPropertyDescription));

            desc.GetCanonicalName().Should().Be("System.ItemTypeText");
            desc = list.GetAt(1, new Guid(InterfaceIds.IID_IPropertyDescription));
            desc.GetCanonicalName().Should().Be("System.Size");
            desc = list.GetAt(2, new Guid(InterfaceIds.IID_IPropertyDescription));
            desc.GetCanonicalName().Should().Be("System.DateModified");
        }
Exemplo n.º 3
0
        public static DataTable GetPropertyDefinitions()
        {
            DataTable dt = CreateTable();
            Guid      riid;
            IPropertyDescriptionList propList = null;
            IPropertyDescription     propDesc = null;

            try
            {
                riid = new Guid(IIDStrings.IPropertyDescriptionList);
                int hr = PSEnumeratePropertyDescriptions(0,                 // PDEF_ALL,
                                                         ref riid,
                                                         out propList);

                if (hr < 0)
                {
                    throw (new ApplicationException(string.Format("PSEnumeratePropertyDescriptions returned: {0}", hr)));
                }

                uint numProps = propList.GetCount();
                riid = new Guid(IIDStrings.IPropertyDescription);

                for (int i = 0; i < numProps; i++)
                {
                    // Iterates through each item in the description list
                    propDesc = propList.GetAt((uint)i, ref riid);

                    string propName = propDesc.GetCanonicalName();

                    DataRow dr = dt.Rows.Add(propName);
                    InitRow(dr, propDesc);
                    Marshal.ReleaseComObject(propDesc);
                }
            }
            finally
            {
                Marshal.ReleaseComObject(propList);
                Marshal.ReleaseComObject(propDesc);
            }

            return(dt);
        }
Exemplo n.º 4
0
        public static IEnumerable <string> GetPropertyDefinitions()
        {
            Guid riid;

            IPropertyDescriptionList propList = null;
            IPropertyDescription     propDesc = null;

            try
            {
                riid = new Guid(IIDStrings.IPropertyDescriptionList);
                int hr = PSEnumeratePropertyDescriptions(0, // PDEF_ALL,
                                                         ref riid,
                                                         out propList);

                if (hr < 0)
                {
                    throw (new ApplicationException(string.Format("PSEnumeratePropertyDescriptions returned: {0}", hr)));
                }

                uint numProps = propList.GetCount();
                riid = new Guid(IIDStrings.IPropertyDescription);

                for (int i = 0; i < numProps; i++)
                {
                    // Iterates through each item in the description list
                    propDesc = propList.GetAt((uint)i, ref riid);

                    yield return(propDesc.GetCanonicalName());
                }
            }
            finally
            {
                Marshal.ReleaseComObject(propList);
                Marshal.ReleaseComObject(propDesc);
            }
        }
Exemplo n.º 5
0
        public void PopulateSystemProperties()
        {
            IPropertyDescriptionList propertyDescriptionList = null;
            IPropertyDescription     propertyDescription     = null;
            Guid guid = new Guid(ShellIIDGuid.IPropertyDescriptionList);

            try
            {
                int hr = PropertySystemNativeMethods.PSEnumeratePropertyDescriptions(PropertySystemNativeMethods.PropDescEnumFilter.PDEF_ALL, ref guid, out propertyDescriptionList);
                if (hr >= 0)
                {
                    uint count;
                    propertyDescriptionList.GetCount(out count);
                    guid = new Guid(ShellIIDGuid.IPropertyDescription);
                    Dictionary <string, List <string> > dict = new Dictionary <string, List <string> >();

                    for (uint i = 0; i < count; i++)
                    {
                        propertyDescriptionList.GetAt(i, ref guid, out propertyDescription);

                        string propName;
                        propertyDescription.GetCanonicalName(out propName);

                        List <string> names = null;
                        string[]      parts = propName.Split('.');
                        if (parts.Count() == 2)
                        {
                            // System.Foo
                            if (!dict.TryGetValue(parts[0], out names))
                            {
                                names = new List <string>();
                                dict.Add(parts[0], names);
                            }
                            names.Add(parts[1]);
                        }
                        else if (parts.Count() == 3)
                        {
                            // System.Bar.Baz
                            if (!dict.TryGetValue(parts[1], out names))
                            {
                                names = new List <string>();
                                dict.Add(parts[1], names);
                            }
                            names.Add(parts[2]);
                        }

                        // If we ever need it:
                        // ShellPropertyDescription desc = new ShellPropertyDescription(propertyDescription);

                        if (propertyDescription != null)
                        {
                            Marshal.ReleaseComObject(propertyDescription);
                            propertyDescription = null;
                        }
                    }

                    // build tree
                    foreach (string cat in dict.Keys)
                    {
                        TreeItem main = new TreeItem(cat, PropType.Group);
                        foreach (string name in dict[cat])
                        {
                            main.AddChild(new TreeItem(name, PropType.Normal));
                        }

                        if (cat == "System")
                        {
                            AllProperties.Insert(0, main);
                        }
                        else if (cat == "PropGroup")
                        {
                            foreach (TreeItem ti in main.Children)
                            {
                                GroupProperties.Add(ti.Name);
                            }
                        }
                        else
                        {
                            AllProperties.Add(main);
                        }
                    }
                }
            }
            finally
            {
                if (propertyDescriptionList != null)
                {
                    Marshal.ReleaseComObject(propertyDescriptionList);
                }
                if (propertyDescription != null)
                {
                    Marshal.ReleaseComObject(propertyDescription);
                }
            }
        }
Exemplo n.º 6
0
        public void PopulateSystemProperties()
        {
            List <SystemProperty>    systemProperties        = new List <SystemProperty>();
            IPropertyDescriptionList propertyDescriptionList = null;
            IPropertyDescription     propertyDescription     = null;
            Guid guid = new Guid(ShellIIDGuid.IPropertyDescriptionList);

            try
            {
                int hr = PropertySystemNativeMethods.PSEnumeratePropertyDescriptions(PropertySystemNativeMethods.PropDescEnumFilter.PDEF_ALL, ref guid, out propertyDescriptionList);
                if (hr >= 0)
                {
                    uint count;
                    propertyDescriptionList.GetCount(out count);
                    guid = new Guid(ShellIIDGuid.IPropertyDescription);

                    for (uint i = 0; i < count; i++)
                    {
                        propertyDescriptionList.GetAt(i, ref guid, out propertyDescription);

                        string propName;
                        propertyDescription.GetCanonicalName(out propName);
                        IntPtr displayNamePtr;
                        string displayName = null;
                        propertyDescription.GetDisplayName(out displayNamePtr);
                        if (displayNamePtr != IntPtr.Zero)
                        {
                            displayName = Marshal.PtrToStringAuto(displayNamePtr);
                        }
                        SystemProperty sp = new SystemProperty {
                            FullName = propName, DisplayName = displayName
                        };

                        systemProperties.Add(sp);

                        // If we ever need it:
                        // ShellPropertyDescription desc = new ShellPropertyDescription(propertyDescription);

                        if (propertyDescription != null)
                        {
                            Marshal.ReleaseComObject(propertyDescription);
                            propertyDescription = null;
                        }
                    }

                    Dictionary <string, TreeItem> dict = new Dictionary <string, TreeItem>();
                    List <TreeItem> roots = new List <TreeItem>();

                    // Build tree based on property names
                    foreach (SystemProperty sp in systemProperties)
                    {
                        AddTreeItem(dict, roots, sp);
                    }

                    // Wire trees to tree controls, tweaking the structure as we go
                    TreeItem propGroup = null;
                    foreach (TreeItem root in roots)
                    {
                        if (root.Name == "System")
                        {
                            AllProperties.Insert(0, root);

                            // Move property groups from root to their own list
                            propGroup = root.Children.Where(x => x.Name == "PropGroup").FirstOrDefault();
                            if (propGroup != null)
                            {
                                foreach (TreeItem ti in propGroup.Children)
                                {
                                    GroupProperties.Add(ti.Name);
                                }
                                root.RemoveChild(propGroup);
                            }

                            // Make remaining children of System that are parents into roots
                            List <TreeItem> movers = new List <TreeItem>(root.Children.Where(x => x.Children.Count() > 0));
                            foreach (TreeItem ti in movers)
                            {
                                root.RemoveChild(ti);
                                AllProperties.Add(ti);
                            }
                        }
                        else
                        {
                            AllProperties.Add(root);
                        }
                    }
                }
            }
            finally
            {
                if (propertyDescriptionList != null)
                {
                    Marshal.ReleaseComObject(propertyDescriptionList);
                }
                if (propertyDescription != null)
                {
                    Marshal.ReleaseComObject(propertyDescription);
                }
            }
        }