コード例 #1
0
        public Property(PropertySystem propSys, PropertyStore ps, int index)
        {
            var pk = ps.GetAt(index);

            PropertyKey = pk;

            var propDef = propSys.GetPropertyDescription(pk);

            if (propDef != null)
            {
                // Names
                DisplayName   = propDef.DisplayName;
                CanonicalName = propDef.CanonicalName;
                if (string.IsNullOrEmpty(DisplayName))
                {
                    DisplayName = CanonicalName;
                    if (string.IsNullOrEmpty(DisplayName))
                    {
                        DisplayName = pk.ToString();
                    }
                }
                if (string.IsNullOrEmpty(CanonicalName))
                {
                    CanonicalName = DisplayName;
                }

                // Flags
                {
                    var    f  = propDef.TypeFlags;
                    char[] cf = new char[4];
                    cf[0] = (f & PROPDESC_TYPE_FLAGS.PDTF_ISSYSTEMPROPERTY) == 0 ? '-' : 'S';
                    cf[1] = (f & PROPDESC_TYPE_FLAGS.PDTF_ISINNATE) == 0 ? '-' : 'I';
                    cf[2] = (f & PROPDESC_TYPE_FLAGS.PDTF_CANBEPURGED) == 0 ? '-' : 'P';
                    cf[3] = (f & PROPDESC_TYPE_FLAGS.PDTF_ISVIEWABLE) == 0 ? '-' : 'V';
                    Flags = new string(cf);
                }
            }
            else
            {
                CanonicalName = DisplayName = pk.ToString();
                Flags         = "????";
            }

            Value = ValueToString(ps.GetValue(pk), pk);
        }
コード例 #2
0
        public void RetrieveAll(string path)
        {
            try
            {
                Console.WriteLine(path);
                foreach (string filePath in Directory.GetFiles(path))
                {
                    PropertyStore propStore = null;
                    try
                    {
                        bool hasError = false;
                        try
                        {
                            propStore = PropertyStore.Open(filePath);
                        }
                        catch (Exception err)
                        {
                            Console.WriteLine("Failed to open property store on: {0}\r\n{1}\r\n", filePath, err.ToString());
                            // m_log.WriteLine("Failed to open property store on: {0}\r\n{1}\r\n", filePath, err.ToString());
                            hasError = true;
                        }

                        if (!hasError)
                        {
                            int count = propStore.Count;
                            for (int i = 0; i < propStore.Count; ++i)
                            {
                                PropertyKey propKey;
                                try
                                {
                                    // Get the key for the enumerated property
                                    propKey = propStore.GetAt(i);
                                }
                                catch (Exception err)
                                {
                                    Console.WriteLine("Failed to retrieve property key on '{0}' index='{1}'\r\n{2}\r\n", filePath, i, err.ToString());
                                    m_log.WriteLine("Failed to retrieve property key on '{0}' index='{1}'\r\n{2}\r\n", filePath, i, err.ToString());
                                    continue;
                                }

                                object value = null;
                                try
                                {
                                    // Get the value
                                    value = propStore.GetValue(propKey);
                                }
                                catch (Exception err)
                                {
                                    if (m_errorKeys.Add(propKey))
                                    {
                                        string message = (err.InnerException != null) ? err.InnerException.Message : err.Message;

                                        // Attempt to get the canonical name
                                        string name = string.Empty;
                                        try
                                        {
                                            name = m_ps.GetPropertyDescription(propKey).CanonicalName;
                                        }
                                        catch
                                        {
                                            name = string.Empty;
                                        }

                                        Console.WriteLine("Failed to retrieve value. file='{0}' propkey='{1}' canonicalName='{2}'\r\n{3}\r\n", filePath, propKey, name, message);
                                        m_log.WriteLine("Failed to retrieve value. file='{0}' propkey='{1}' canonicalName='{2}'\r\n{3}\r\n", filePath, propKey, name, message);
                                    }
                                }

                                if (m_foundKeys.Add(propKey))
                                {
                                    PropertyDescription desc = null;
                                    try
                                    {
                                        // Get the description from the property store (if available)
                                        desc = m_ps.GetPropertyDescription(propKey);
                                    }
                                    catch (Exception err)
                                    {
                                        Console.WriteLine("Error retrieving property description. propkey='{0}'\r\n{1}\r\n", propKey, err.ToString());
                                        m_log.WriteLine("Error retrieving property description. propkey='{0}'\r\n{1}\r\n", propKey, err.ToString());
                                    }
                                    if (desc != null)
                                    {
                                        if (string.IsNullOrEmpty(desc.CanonicalName))
                                        {
                                            Console.WriteLine("No canonical name provided. propkey='{0}'\r\n", propKey);
                                            m_log.WriteLine("No canonical name provided. propkey='{0}'\r\n", propKey);
                                        }
                                        else if (string.IsNullOrEmpty(desc.DisplayName))
                                        {
                                            Console.WriteLine("No display name provided. propkey='{0}' canonical='{1}'\r\n", propKey, desc.CanonicalName);
                                            m_log.WriteLine("No display name provided. propkey='{0}' canonical='{1}'\r\n", propKey, desc.CanonicalName);
                                        }
                                    }
                                } // if not in foundkeys

                                if (value != null && !m_typematchKeys.Contains(propKey))
                                {
                                    m_typematchKeys.Add(propKey);

                                    PropertyDescription desc = null;
                                    try
                                    {
                                        // Get the description from the property store (if available)
                                        desc = m_ps.GetPropertyDescription(propKey);
                                    }
                                    catch (Exception)
                                    {
                                        // Suppress errors here
                                    }
                                    if (desc != null)
                                    {
                                        // See if type matches
                                        Type expectedType = desc.ValueType;
                                        Type valueType    = (value != null) ? value.GetType() : null;

                                        if (expectedType == null)
                                        {
                                            Console.WriteLine($"For '{desc.CanonicalName}' expected type is null but value type is '{valueType}'.");
                                            m_log.WriteLine($"For '{desc.CanonicalName}' expected type is null but value type is '{valueType}'.");
                                        }
                                        else if (expectedType != valueType)
                                        {
                                            Console.WriteLine($"For '{desc.CanonicalName}' expected type is '{expectedType}' but value type is '{valueType}'.");
                                            m_log.WriteLine($"For '{desc.CanonicalName}' expected type is '{expectedType}' but value type is '{valueType}'.");
                                        }
                                    }
                                }
                            }
                        }
                    }
                    finally
                    {
                        if (propStore != null)
                        {
                            propStore.Dispose();
                            propStore = null;
                        }
                    }
                } // foreach file

                // Recursively enumerate directories
                foreach (string dirPath in Directory.GetDirectories(path))
                {
                    RetrieveAll(dirPath);
                }
            }
            catch (UnauthorizedAccessException err)
            {
                Console.WriteLine("Error: " + err.ToString() + "\r\n");
            }
            catch (Exception err)
            {
                Console.WriteLine("Error: " + err.ToString() + "\r\n");
                m_log.WriteLine("Error: " + err.ToString() + "\r\n");
            }
        }