internal void UploadFile(string fileName, Stream stream) { IPortableDeviceValues portableDeviceValues = new PortableDeviceValues() as IPortableDeviceValues; portableDeviceValues.SetStringValue(ref WPD.OBJECT_PARENT_ID, this.Id); portableDeviceValues.SetUnsignedLargeIntegerValue(ref WPD.OBJECT_SIZE, (ulong)stream.Length); portableDeviceValues.SetStringValue(ref WPD.OBJECT_ORIGINAL_FILE_NAME, fileName); portableDeviceValues.SetStringValue(ref WPD.OBJECT_NAME, fileName); // test using (PropVariantFacade now = PropVariantFacade.DateTimeToPropVariant(DateTime.Now)) { portableDeviceValues.SetValue(ref WPD.OBJECT_DATE_CREATED, ref now.Value); portableDeviceValues.SetValue(ref WPD.OBJECT_DATE_MODIFIED, ref now.Value); uint num = 0u; string text = null; this.device.deviceContent.CreateObjectWithPropertiesAndData(portableDeviceValues, out IStream wpdStream, ref num, ref text); using (StreamWrapper destinationStream = new StreamWrapper(wpdStream)) { stream.CopyTo(destinationStream); destinationStream.Flush(); } } }
//public static PropVariantFacade UIntToPropVariant(uint value) //{ // PropVariantFacade pv = new PropVariantFacade(); // pv.Value.vt = PropVariantType.VT_UI4; // pv.Value.inner.ulVal = value; // return pv; //} public static PropVariantFacade IntToPropVariant(int value) { PropVariantFacade pv = new PropVariantFacade(); pv.Value.vt = PropVariantType.VT_INT; pv.Value.intVal = value; return(pv); }
public static PropVariantFacade DateTimeToPropVariant(DateTime value) { PropVariantFacade pv = new PropVariantFacade(); pv.Value.vt = PropVariantType.VT_DATE; pv.Value.dateVal = value.ToOADate(); return(pv); }
public static PropVariantType GetVarType(this IPortableDeviceValues values, PropertyKey key) { using (PropVariantFacade val = new PropVariantFacade()) { values.GetValue(ref key, out val.Value); return(val.VariantType); } }
public static PropVariantFacade StringToPropVariant(string value) { PropVariantFacade pv = new PropVariantFacade(); pv.Value.vt = PropVariantType.VT_LPWSTR; // Hack, see GetString pv.Value.ptrVal = Marshal.StringToCoTaskMemUni(value); return(pv); }
public void Add(PropertyKey key, IEnumerable <int> values) { IPortableDevicePropVariantCollection col = (IPortableDevicePropVariantCollection) new PortableDevicePropVariantCollection(); foreach (var value in values) { var var = PropVariantFacade.IntToPropVariant(value); col.Add(ref var.Value); } this.values.SetIPortableDevicePropVariantCollectionValue(ref key, col); }
internal static bool TryGetValue(this IPortableDeviceValues values, PropertyKey key, out PropVariantFacade value) { if (values.HasKeyValue(key)) { PropVariantFacade val = new PropVariantFacade(); values.GetValue(ref key, out val.Value); value = val; return(true); } value = null; return(false); }
public static IEnumerable <TEnum> ToEnum <TEnum>(this IPortableDevicePropVariantCollection col) where TEnum : struct // enum { uint count = 0; col.GetCount(ref count); for (uint i = 0; i < count; i++) { PropVariantFacade val = new PropVariantFacade(); col.GetAt(i, ref val.Value); yield return(GetEnumFromAttrGuid <TEnum>(val.ToGuid())); } }
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(); }
public static bool TryGetDateTimeValue(this IPortableDeviceValues values, PropertyKey key, out DateTime?value) { if (values.HasKeyValue(key)) { using (PropVariantFacade val = new PropVariantFacade()) { values.GetValue(ref key, out val.Value); value = val.ToDate(); } return(true); } value = null; return(false); }
public static IEnumerable <string> ToStrings(this IPortableDevicePropVariantCollection col) { uint count = 0; col.GetCount(ref count); for (uint i = 0; i < count; i++) { using (PropVariantFacade val = new PropVariantFacade()) { col.GetAt(i, ref val.Value); yield return(val.ToString()); } } }
public static void WriteObject(IPortableDevicePropVariantCollection collection) { Trace.WriteLine("###############################"); uint num = 0; collection.GetCount(ref num); for (uint index = 0; index < num; index++) { using (PropVariantFacade val = new PropVariantFacade()) { collection.GetAt(index, ref val.Value); Trace.WriteLine($"##### {val.ToString()}"); } } }
public static Item GetFromPersistentUniqueId(MediaDevice device, string persistentUniqueId) { // fill collection with id to request var collection = (IPortableDevicePropVariantCollection) new PortableDevicePropVariantCollection(); using (var propVariantPUID = PropVariantFacade.StringToPropVariant(persistentUniqueId)) { collection.Add(ref propVariantPUID.Value); } // request id collection device.deviceContent.GetObjectIDsFromPersistentUniqueIDs(collection, out IPortableDevicePropVariantCollection results); string mediaObjectId = results.ToStrings().FirstOrDefault(); // return result item return(mediaObjectId == null ? null : Item.Create(device, mediaObjectId)); }
public void Delete(bool recursive = false) { var objectIdCollection = (IPortableDevicePropVariantCollection) new PortableDevicePropVariantCollection(); var propVariantValue = PropVariantFacade.StringToPropVariant(this.Id); objectIdCollection.Add(ref propVariantValue.Value); IPortableDevicePropVariantCollection results = (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, ref results); ComTrace.WriteObject(objectIdCollection); }
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)); } } }
public IEnumerable <PropVariantFacade> GetPropVariants(PropertyKey key) { object obj = null; this.result.GetIUnknownValue(ref key, out obj); var col = obj as IPortableDevicePropVariantCollection; uint count = 0; col.GetCount(ref count); for (uint i = 0; i < count; i++) { PropVariantFacade val = new PropVariantFacade(); col.GetAt(i, ref val.Value); yield return(val); } }
private static void InternalWriteObject(IPortableDeviceValues values) { string func = new StackTrace().GetFrame(2).GetMethod().Name; Trace.WriteLine($"############################### {func}"); uint num = 0; values.GetCount(ref num); for (uint i = 0; i < num; i++) { PropertyKey key = new PropertyKey(); PropVariantFacade val = new PropVariantFacade(); values.GetAt(i, ref key, ref val.Value); string fieldName = string.Empty; FieldInfo propField = FindPropertyKeyField(key); if (propField != null) { fieldName = propField.Name; } else { FieldInfo guidField = FindGuidField(key.fmtid); if (guidField != null) { fieldName = $"{guidField.Name}, {key.pid}"; } else { fieldName = $"{key.fmtid}, {key.pid}"; } } switch (val.VariantType) { case PropVariantType.VT_CLSID: Trace.WriteLine($"##### {fieldName} = {FindGuidField(val.ToGuid())?.Name ?? val.ToString()}"); break; default: Trace.WriteLine($"##### {fieldName} = {val.ToDebugString()}"); break; } } }
public static bool HasKeyValue(this IPortableDeviceValues values, PropertyKey findKey) { 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); if (key == findKey) { return(val.VariantType != PropVariantType.VT_ERROR); } } } return(false); }
private void GetProperties() { IPortableDeviceValues values = null; try { // get all predefined values this.device.deviceProperties.GetValues(this.Id, keyCollection, out values); } catch (Exception ex) { Trace.TraceError($"{ex.Message} for {this.Id}"); return; } // read all properties // use a loop to prevent exceptions during calling GetValue for non existing 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); if (key.fmtid == WPD.OBJECT_PROPERTIES_V1) { switch ((ObjectProperties)key.pid) { case ObjectProperties.ContentType: this.ContentType = val; break; case ObjectProperties.Name: this.name = val; break; case ObjectProperties.OriginalFileName: this.OriginalFileName = val; break; case ObjectProperties.HintLocationDisplayName: this.HintLocationName = val; break; case ObjectProperties.ContainerFunctionalObjectId: this.ParentContainerId = val; break; case ObjectProperties.Size: this.Size = val; break; case ObjectProperties.DateCreated: this.DateCreated = val; break; case ObjectProperties.DateModified: this.DateModified = val; break; case ObjectProperties.DateAuthored: this.DateAuthored = val; break; case ObjectProperties.CanDelete: this.CanDelete = val; break; case ObjectProperties.IsSystem: this.IsSystem = val.ToBool(); break; case ObjectProperties.IsHidden: this.IsHidden = val; break; case ObjectProperties.IsDrmProtected: this.IsDRMProtected = val; break; case ObjectProperties.ParentId: this.ParentId = val; break; case ObjectProperties.PersistentUniqueId: this.PersistentUniqueId = val; break; } } } } }