Esempio n. 1
0
        internal void SetDateAuthored(DateTime value)
        {
            IPortableDeviceValues portableDeviceValues = new PortableDeviceValues() as IPortableDeviceValues;
            IPortableDeviceValues result;

            using (PropVariantFacade val = PropVariantFacade.DateTimeToPropVariant(value))
            {
                portableDeviceValues.SetValue(ref WPD.OBJECT_DATE_AUTHORED, ref val.Value);
                this.device.deviceProperties.SetValues(this.Id, portableDeviceValues, out result);
                ComTrace.WriteObject(result);
            }

            Refresh();
        }
Esempio n. 2
0
        public void Delete(bool recursive = false)
        {
            var objectIdCollection = (IPortableDevicePropVariantCollection) new PortableDeviceTypesLib.PortableDevicePropVariantCollection();

            var propVariantValue = PropVariant.StringToPropVariant(this.Id);

            objectIdCollection.Add(ref propVariantValue);

            IPortableDevicePropVariantCollection results = (PortableDeviceApiLib.IPortableDevicePropVariantCollection) new PortableDevicePropVariantCollection();

            // TODO: get the results back and handle failures correctly
            this.device.deviceContent.Delete(recursive ? PORTABLE_DEVICE_DELETE_WITH_RECURSION : PORTABLE_DEVICE_DELETE_NO_RECURSION, objectIdCollection, null);

            ComTrace.WriteObject(objectIdCollection);
        }
Esempio n. 3
0
        public static IEnumerable <KeyValuePair <string, string> > ToKeyValuePair(this IPortableDeviceValues values)
        {
            uint num = 0;

            values?.GetCount(ref num);
            for (uint i = 0; i < num; i++)
            {
                PropertyKey key = new PropertyKey();
                using (PropVariantFacade val = new PropVariantFacade())
                {
                    values.GetAt(i, ref key, ref val.Value);


                    string    fieldName = string.Empty;
                    FieldInfo propField = ComTrace.FindPropertyKeyField(key);
                    if (propField != null)
                    {
                        fieldName = propField.Name;
                    }
                    else
                    {
                        FieldInfo guidField = ComTrace.FindGuidField(key.fmtid);
                        if (guidField != null)
                        {
                            fieldName = $"{guidField.Name}, {key.pid}";
                        }
                        else
                        {
                            fieldName = $"{key.fmtid}, {key.pid}";
                        }
                    }
                    string fieldValue = string.Empty;
                    switch (val.VariantType)
                    {
                    case PropVariantType.VT_CLSID:
                        fieldValue = ComTrace.FindGuidField(val.ToGuid())?.Name ?? val.ToString();
                        break;

                    default:
                        fieldValue = val.ToDebugString();
                        break;
                    }

                    yield return(new KeyValuePair <string, string>(fieldName, fieldValue));
                }
            }
        }
Esempio n. 4
0
        internal bool Rename(string newName)
        {
            IPortableDeviceValues portableDeviceValues = new PortableDeviceValues() as IPortableDeviceValues;
            IPortableDeviceValues result;

            // with OBJECT_NAME does not work for Amazon Kindle Paperwhite
            portableDeviceValues.SetStringValue(ref WPD.OBJECT_ORIGINAL_FILE_NAME, newName);
            this.device.deviceProperties.SetValues(this.Id, portableDeviceValues, out result);
            ComTrace.WriteObject(result);

            if (result.TryGetStringValue(WPD.OBJECT_ORIGINAL_FILE_NAME, out string check))
            {
                if (check == "Error: S_OK")
                {
                    // id can change on rename (e.g. Amazon Kindle Paperwhite) so find new one
                    var newItem = this.parent.GetChildren().FirstOrDefault(i => device.EqualsName(i.Name, newName));
                    this.Id = newItem.Id;

                    Refresh();
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 5
0
 public void WriteResults()
 {
     ComTrace.WriteObject(this.result);
 }