예제 #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);
        }
        public List <DataGridViewGenericRowAndValue> Read(string fullFileName)
        {
            List <DataGridViewGenericRowAndValue> dataGridViewGenericRowsAndValueList = new List <DataGridViewGenericRowAndValue>();
            string fileExtension = Path.GetExtension(fullFileName);
            Dictionary <PropertyKey, PropVariant> filePropertiesAndVariant = new Dictionary <WinProps.PropertyKey, PropVariant>();
            Dictionary <PropertyKey, bool>        filePropertiesReadOnly   = new Dictionary <WinProps.PropertyKey, bool>();

            try
            {
                using (PropertyStore propertyStoreExtension = new PropertyStore())
                {
                    propertyStoreExtension.AddDefaultsByExtension(fileExtension);

                    foreach (PropertyKey propertyKey in propertyStoreExtension)
                    {
                        try
                        {
                            using (PropertyDescription propertyDescription = new PropertyDescription(propertyKey))
                            {
                                PropVariant propVariant = propertyStoreExtension.GetValue(propertyKey);
                                filePropertiesAndVariant[propertyKey] = propVariant;
                            }
                        }
                        catch { }
                    }
                }
            }
            catch { }

            try
            {
                using (PropertyStore propertyStoreFile = new PropertyStore(fullFileName, PropertyStore.GetFlags.Default))
                {
                    foreach (PropertyKey propertyKey in propertyStoreFile)
                    {
                        try
                        {
                            using (PropertyDescription propertyDescription = new PropertyDescription(propertyKey))
                            {
                                PropVariant propVariant = propertyStoreFile.GetValue(propertyKey);
                                filePropertiesAndVariant[propertyKey] = propVariant;
                                filePropertiesReadOnly[propertyKey]   = !propertyStoreFile.IsEditable(propertyKey);
                            }
                        }
                        catch { }
                    }
                }
            }
            catch
            {
            }

            PropertyDescriptionList propertyDescriptionList = null;

            try
            {
                propertyDescriptionList = new PropertyDescriptionList(fileExtension, PropertyKey.Keys["System.PropList.FullDetails"]);
            }
            catch
            {
            }

            if (propertyDescriptionList != null)
            {
                string groupName       = "Unknown";
                bool   isReadOnlyGroup = false;
                for (int i = 0; i < propertyDescriptionList.Count; ++i)
                {
                    using (PropertyDescription propertyDescription = propertyDescriptionList[i])
                    {
                        using (PropertyKey key = propertyDescription.PropertyKey)
                        {
                            if (propertyDescription.TypeFlags.IsGroup)
                            {
                                isReadOnlyGroup = true;
                                if (key.Equals(PropertyKey.Keys["System.PropGroup.Origin"]))
                                {
                                    isReadOnlyGroup = false;
                                }
                                if (key.Equals(PropertyKey.Keys["System.PropGroup.Description"]))
                                {
                                    isReadOnlyGroup = false;
                                }
                                //isReadOnlyGroup = key.Equals(PropertyKey.Keys["System.PropGroup.FileSystem"]);

                                groupName = propertyDescription.DisplayName;
                                dataGridViewGenericRowsAndValueList.Add(new DataGridViewGenericRowAndValue(propertyDescription.DisplayName, key, isReadOnlyGroup));
                            }
                            else
                            {
                                bool readOnly = isReadOnlyGroup;


                                bool isIsMultiValued = propertyDescription.TypeFlags.IsMultiValued;

                                string textValue = "";
                                if (filePropertiesAndVariant.ContainsKey(key)) // && !isFileGroup)
                                {
                                    if (propertyDescription.TypeFlags.IsMultiValued)
                                    {
                                        if (filePropertiesAndVariant[key].IsVector)
                                        {
                                            textValue = string.Join(Environment.NewLine, filePropertiesAndVariant[key].ToType <string>().Split(new[] { "; ", ";" }, StringSplitOptions.RemoveEmptyEntries));
                                        }
                                        else
                                        {
                                            textValue = propertyDescription.FormatForDisplay(filePropertiesAndVariant[key], PropertyDescription.FormatFlags.Default);
                                        }
                                    }
                                    else
                                    {
                                        textValue = propertyDescription.FormatForDisplay(filePropertiesAndVariant[key], PropertyDescription.FormatFlags.Default);
                                    }

                                    string test = "";
                                    if (!filePropertiesReadOnly.ContainsKey(key) || filePropertiesReadOnly[key])
                                    {
                                        readOnly = true;
                                        test     = "*";
                                    }
                                    else
                                    {
                                        //		propertyDescription.CanonicalName	"System.Image.ImageID"	string

                                        /*File/Properties	C:\Users\nordl\OneDrive\Pictures JTNs OneDrive\TestTags\IMG_1267.jpg
                                         * Metering mode	Pattern
                                         * Flash mode	No flash, compulsory */
                                    }
                                    if (key.Equals(PropertyKey.Keys["System.Image.ImageID"]))
                                    {
                                        readOnly = true;
                                    }
                                    if (key.Equals(PropertyKey.Keys["System.Photo.ISOSpeed"]))
                                    {
                                        readOnly = true;
                                    }
                                    if (key.Equals(PropertyKey.Keys["System.Photo.MeteringMode"]))
                                    {
                                        readOnly = true;
                                    }
                                    if (key.Equals(PropertyKey.Keys["System.Photo.Flash"]))
                                    {
                                        readOnly = true;
                                    }

                                    dataGridViewGenericRowsAndValueList.Add(
                                        new DataGridViewGenericRowAndValue(
                                            groupName,
                                            propertyDescription.DisplayName + test, key,
                                            readOnly ? ReadWriteAccess.ForceCellToReadOnly : ReadWriteAccess.DefaultReadOnly,
                                            isIsMultiValued, readOnly, textValue));
                                }
                            }
                        }
                    }
                }
            }

            return(dataGridViewGenericRowsAndValueList);
        }
예제 #3
0
 protected T Get <T>([CallerMemberName] string propertyName = null)
 {
     return(properties.GetValue <T>(propertyName));
 }
예제 #4
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");
            }
        }