private void StringToPropVariant(string objectId, out PortableDeviceApiLib.tag_inner_PROPVARIANT pv) { IPortableDeviceValues values = (PortableDeviceApiLib.IPortableDeviceValues) new PortableDeviceTypesLib.PortableDeviceValues(); values.SetStringValue(ref pKey.WPD_OBJECT_ID, objectId); values.GetValue(ref pKey.WPD_OBJECT_ID, out pv); }
private void ConvertObjectsIdToPropVariant(PortableDeviceObject obj, out tag_inner_PROPVARIANT propvarValue) { var pValues = (IPortableDeviceValues) new PortableDeviceValuesClass(); pValues.SetStringValue(PortableDevicePKeys.WPD_OBJECT_ID, obj.ID); pValues.GetValue(ref PortableDevicePKeys.WPD_OBJECT_ID, out propvarValue); }
public bool DeleteContentFromDevice(string objectId) { bool bRet = false; PortableDeviceApiLib.IPortableDevicePropVariantCollection toDelete = new PortableDeviceTypesLib.PortableDevicePropVariantCollection() as PortableDeviceApiLib.IPortableDevicePropVariantCollection; PortableDeviceApiLib.IPortableDevicePropVariantCollection result = new PortableDeviceTypesLib.PortableDevicePropVariantCollection() as PortableDeviceApiLib.IPortableDevicePropVariantCollection; var pv = new PortableDeviceApiLib.tag_inner_PROPVARIANT(); StringToPropVariant(objectId, out pv); toDelete.Add(ref pv); try { deviceContent.Delete((uint)DELETE_OBJECT_OPTIONS.NO_RECURSION, toDelete, ref result); } catch (Exception) { bRet = false; } return(bRet); }
/** * Delete a file. */ public void DeleteFile(PortableDeviceFile file) { try { // make sure that we are not holding on to a file. DisconnectConnect(); IPortableDeviceContent content = getContents(); var variant = new PortableDeviceApiLib.tag_inner_PROPVARIANT(); StringToPropVariant(file.Id, out variant); PortableDeviceApiLib.IPortableDevicePropVariantCollection objectIds = new PortableDeviceTypesLib.PortableDevicePropVariantCollection() as PortableDeviceApiLib.IPortableDevicePropVariantCollection; objectIds.Add(variant); content.Delete(0, objectIds, null); } catch (Exception ex) { Console.WriteLine(ex.Message); throw (ex); } Disconnect(); }
public void DeleteFile(PortableDeviceFile file) { var variant = new PortableDeviceApiLib.tag_inner_PROPVARIANT(); IPortableDeviceContent content = null; try { this._device.Content(out content); StringToPropVariant(file.Id, out variant, 2); PortableDeviceApiLib.IPortableDevicePropVariantCollection objectIds = new PortableDeviceTypesLib.PortableDevicePropVariantCollection() as PortableDeviceApiLib.IPortableDevicePropVariantCollection; objectIds.Add(variant); content.Delete(0, objectIds, null); } catch (Exception ex) { Logger.Basic.Error("Portable Device DeleteFile : " + ex.ToString(), ex); } finally { if (Marshal.IsComObject(variant)) { Marshal.ReleaseComObject(variant); } if (content != null && Marshal.IsComObject(content)) { Marshal.ReleaseComObject(content); } } }
// DELETE file private static void StringToPropVariant(string value, out PortableDeviceApiLib.tag_inner_PROPVARIANT propvarValue) { PortableDeviceApiLib.IPortableDeviceValues pValues = (PortableDeviceApiLib.IPortableDeviceValues) new PortableDeviceTypesLib.PortableDeviceValuesClass(); _tagpropertykey WPD_OBJECT_ID = new _tagpropertykey(); WPD_OBJECT_ID.fmtid = new Guid(0xEF6B490D, 0x5CD8, 0x437A, 0xAF, 0xFC, 0xDA, 0x8B, 0x60, 0xEE, 0x4A, 0x3C); WPD_OBJECT_ID.pid = 2; pValues.SetStringValue(ref WPD_OBJECT_ID, value); pValues.GetValue(ref WPD_OBJECT_ID, out propvarValue); }
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++) { PROPVARIANT val = new PROPVARIANT(); col.GetAt(i, ref val); yield return(GetEnumFromAttrGuid <TEnum>(PropVariant.FromValue(val))); } }
public static IEnumerable <string> ToStrings(this IPortableDevicePropVariantCollection col) { uint count = 0; col.GetCount(ref count); for (uint i = 0; i < count; i++) { PROPVARIANT val = new PROPVARIANT(); col.GetAt(i, ref val); yield return(PropVariant.FromValue(val)); } }
public static void WriteObject(IPortableDevicePropVariantCollection collection) { uint num = 0; collection.GetCount(ref num); for (uint index = 0; index < num; index++) { PROPVARIANT val = new PROPVARIANT(); collection.GetAt(index, ref val); Trace.WriteLine($"##### {((PropVariant)val).ToString()}"); } }
/// <summary> /// Extract device capabilities /// </summary> /// <param name="portableDeviceClass"></param> internal void ExtractDeviceCapabilities(PortableDeviceClass portableDeviceClass) { if (portableDeviceClass == null) { throw new ArgumentNullException("portableDeviceClass"); } try { IPortableDeviceCapabilities capabilities; portableDeviceClass.Capabilities(out capabilities); if (capabilities == null) { Trace.WriteLine("Cannot extract capabilities from device"); throw new PortableDeviceException("Cannot extract capabilities from device"); } IPortableDevicePropVariantCollection functionalCategories; capabilities.GetFunctionalCategories(out functionalCategories); if (functionalCategories == null) { throw new PortableDeviceException("Failed to extract functionnal categories"); } uint countCategories = 1; functionalCategories.GetCount(ref countCategories); var values = new tag_inner_PROPVARIANT(); string categoryName; Guid currentGuid; for (uint i = 0; i < countCategories; i++) { functionalCategories.GetAt(i, ref values); var pValues = (IPortableDeviceValues) new PortableDeviceValuesClass(); pValues.SetValue(ref PortableDevicePKeys.WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_FUNCTIONAL_CATEGORIES, ref values); pValues.GetStringValue(ref PortableDevicePKeys.WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_FUNCTIONAL_CATEGORIES, out categoryName); currentGuid = new Guid(categoryName); this.functionalCategories.Add(currentGuid, new FunctionalCategory( portableDeviceClass, currentGuid, PortableDeviceHelpers.GetKeyNameFromGuid(currentGuid))); } } catch (Exception ex) { throw new PortableDeviceException("Error on extract device capabilities", ex); } }
private static void StringToPropVariant( string value, out PortableDeviceApiLib.tag_inner_PROPVARIANT propvarValue) { var pValues = (IPortableDeviceValues) new PortableDeviceValuesClass(); var wpdObjectId = new _tagpropertykey { fmtid = CreateFmtidGuid(), pid = 2 }; pValues.SetStringValue(ref wpdObjectId, value); pValues.GetValue(ref wpdObjectId, out propvarValue); }
public static Guid[] ToGuid(this IPortableDevicePropVariantCollection col) { uint count = 0; col.GetCount(ref count); var result = new Guid[count]; for (uint i = 0; i < count; i++) { PROPVARIANT val = new PROPVARIANT(); col.GetAt(i, ref val); result[i] = PropVariant.FromValue(val); } return(result); }
public static TEnum[] ToArray <TEnum>(this IPortableDevicePropVariantCollection col) where TEnum : struct // enum { uint count = 0; col.GetCount(ref count); var result = new TEnum[count]; for (uint i = 0; i < count; i++) { PROPVARIANT val = new PROPVARIANT(); col.GetAt(i, ref val); result[i] = GetEnumFromAttrGuid <TEnum>(PropVariant.FromValue(val)); } return(result); }
public void DeleteFile(PortableDeviceFile file) { IPortableDeviceContent content; this._device.Content(out content); var variant = new PortableDeviceApiLib.tag_inner_PROPVARIANT(); StringToPropVariant(file.Id, out variant); PortableDeviceApiLib.IPortableDevicePropVariantCollection objectIds = new PortableDeviceTypesLib.PortableDevicePropVariantCollection() as PortableDeviceApiLib.IPortableDevicePropVariantCollection; objectIds.Add(variant); content.Delete(0, objectIds, null); }
private void uLongIntToPropVariant(ulong value, out PortableDeviceApiLib.tag_inner_PROPVARIANT propvarValue) { // We'll use an IPortableDeviceValues object to transform the // string into a PROPVARIANT PortableDeviceApiLib.IPortableDeviceValues pValues = (PortableDeviceApiLib.IPortableDeviceValues) new PortableDeviceTypesLib.PortableDeviceValuesClass(); // We insert the string value into the IPortableDeviceValues object // using the SetStringValue method pValues.SetUnsignedLargeIntegerValue(ref PortableDevicePKeys.WPD_OBJECT_ID, (ulong)value); // We then extract the string into a PROPVARIANT by using the // GetValue method pValues.GetValue(ref PortableDevicePKeys.WPD_OBJECT_ID, out propvarValue); }
public IEnumerable <PropVariant> GetPropVariants(PropertyKey key) { object obj = null; this.result.GetIUnknownValue(key, out obj); var col = obj as IPortableDevicePropVariantCollection; uint count = 0; col.GetCount(ref count); for (uint i = 0; i < count; i++) { PROPVARIANT val = new PROPVARIANT(); col.GetAt(i, ref val); yield return(PropVariant.FromValue(val)); } }
public bool Has(PropertyKey key) { uint count = 0; this.result.GetCount(ref count); for (uint i = 0; i < count; i++) { PropertyKey k = new PropertyKey(); PROPVARIANT v = new PROPVARIANT(); this.result.GetAt(i, ref k, ref v); if (key.fmtid == k.fmtid && key.pid == k.pid) { return(true); } } return(false); }
public void DeleteFolder(PortableDeviceFolder folder) { IPortableDeviceContent content; PortableDeviceClass.Content(out content); var variant = new PortableDeviceApiLib.tag_inner_PROPVARIANT(); StringToPropVariant(folder.Id, out variant); var objectIds = new PortableDevicePropVariantCollection() as PortableDeviceApiLib.IPortableDevicePropVariantCollection; objectIds.Add(variant); content.Delete(1, objectIds, null); }
private void ExtractContentType(PortableDeviceClass portableDeviceClass, Guid functionalCategory) { try { IPortableDeviceCapabilities capabilities; portableDeviceClass.Capabilities(out capabilities); if (capabilities == null) { Trace.WriteLine("Cannot extract capabilities from device"); throw new PortableDeviceException("Cannot extract capabilities from device"); } var pValues = (IPortableDeviceValues) new PortableDeviceValuesClass(); //Functional objects variables IPortableDevicePropVariantCollection contentTypes; uint countObjects = 1; var values = new tag_inner_PROPVARIANT(); string contentTypeName; Guid currentContentTypeGuid; capabilities.GetSupportedContentTypes(ref functionalCategory, out contentTypes); contentTypes.GetCount(ref countObjects); for (uint i = 0; i < countObjects; i++) { contentTypes.GetAt(i, ref values); pValues.SetValue(ref PortableDevicePKeys.WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_CONTENT_TYPES, ref values); pValues.GetStringValue(ref PortableDevicePKeys.WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_CONTENT_TYPES, out contentTypeName); currentContentTypeGuid = new Guid(contentTypeName); this.contentTypes.Add(currentContentTypeGuid, new ContentType( portableDeviceClass, currentContentTypeGuid, PortableDeviceHelpers.GetKeyNameFromGuid(currentContentTypeGuid))); } } catch (Exception ex) { throw new PortableDeviceException("Error on extract functional object", ex); } }
private void ExtractSupportedFormat(PortableDeviceClass portableDeviceClass, Guid contentType) { if (portableDeviceClass == null) { throw new PortableDeviceException(""); } IPortableDeviceCapabilities capabilities; portableDeviceClass.Capabilities(out capabilities); if (capabilities == null) { Trace.WriteLine("Cannot extract capabilities from device"); throw new PortableDeviceException("Cannot extract capabilities from device"); } var pValues = (IPortableDeviceValues) new PortableDeviceValuesClass(); //Functional objects variables IPortableDevicePropVariantCollection formats; uint countObjects = 1; var values = new tag_inner_PROPVARIANT(); string formatName; Guid currentFormat; capabilities.GetSupportedFormats(ref contentType, out formats); formats.GetCount(ref countObjects); for (uint i = 0; i < countObjects; i++) { formats.GetAt(i, ref values); pValues.SetValue(ref PortableDevicePKeys.WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_FORMATS, ref values); pValues.GetStringValue(ref PortableDevicePKeys.WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_FORMATS, out formatName); currentFormat = new Guid(formatName); this.formats[currentFormat] = PortableDeviceHelpers.GetKeyNameFromGuid(currentFormat); } }
public bool CopyInsideWPD(PortableDeviceFile file, string destinationFolderId) { bool success = false; PortableDeviceApiLib.tag_inner_PROPVARIANT variant = new PortableDeviceApiLib.tag_inner_PROPVARIANT(); StringToPropCopyVariant(file.Id, out variant); PortableDeviceApiLib.IPortableDevicePropVariantCollection objectIds = new PortableDeviceTypesLib.PortableDevicePropVariantCollection() as PortableDeviceApiLib.IPortableDevicePropVariantCollection; objectIds.Add(variant); IPortableDeviceContent content; this._device.Content(out content); try { PortableDeviceApiLib.IPortableDevicePropVariantCollection res = new PortableDeviceTypesLib.PortableDevicePropVariantCollection() as PortableDeviceApiLib.IPortableDevicePropVariantCollection; content.Copy(objectIds, destinationFolderId, ref res); success = true; } catch (Exception ex) { MessageBox.Show("CopyInsideWPD(..) - " + ex.Message); success = false; } return(success); }
public PropVariant[] GetPropVariants(PropertyKey key) { if (!this.result.TryGetIUnknownValue(key, out object obj)) { return(new PropVariant[0]); } var col = obj as IPortableDevicePropVariantCollection; uint count = 0; col.GetCount(ref count); var result = new PropVariant[count]; for (uint i = 0; i < count; i++) { PROPVARIANT val = new PROPVARIANT(); col.GetAt(i, ref val); result[i] = PropVariant.FromValue(val); } return(result); }
public void DeleteFolder(PortableDeviceFolder folder) { try { IPortableDeviceContent content; this._device.Content(out content); var variant = new PortableDeviceApiLib.tag_inner_PROPVARIANT(); StringToPropVariant(folder.Id, out variant); PortableDeviceApiLib.IPortableDevicePropVariantCollection objectIds = new PortableDeviceTypesLib.PortableDevicePropVariantCollection() as PortableDeviceApiLib.IPortableDevicePropVariantCollection; objectIds.Add(variant); content.Delete(0, objectIds, null); } catch (Exception ex) { throw new Exception(ex.Message); } }
public static void WriteObject(IPortableDeviceValues values) { uint num = 0; values.GetCount(ref num); for (uint i = 0; i < num; i++) { PropertyKey key = new PropertyKey(); PROPVARIANT val = new PROPVARIANT(); values.GetAt(i, ref key, ref val); Type twpd = typeof(WPD); var fields = twpd.GetFields().Where(f => f.FieldType == typeof(PropertyKey)).ToList(); foreach (var field in fields) { PropertyKey pk = (PropertyKey)field.GetValue(null); if (pk.pid == key.pid && pk.fmtid == key.fmtid) { Trace.WriteLine($"##### {field.Name} = {((PropVariant)val).ToString()}"); } } } }
public bool DeleteFile(PortableDeviceFile file) { bool success = false; // original // IPortableDeviceContent content; // this._device.Content(out content); PortableDeviceApiLib.tag_inner_PROPVARIANT variant = new PortableDeviceApiLib.tag_inner_PROPVARIANT(); StringToPropVariant(file.Id, out variant); PortableDeviceApiLib.IPortableDevicePropVariantCollection objectIds = new PortableDeviceTypesLib.PortableDevicePropVariantCollection() as PortableDeviceApiLib.IPortableDevicePropVariantCollection; objectIds.Add(variant); // the next 2 line need to appear AFTER "StringToPropVariant(file.Id, out variant);" - otherwise content is reset to null IPortableDeviceContent content; this._device.Content(out content); try { content.Delete(0, objectIds, null); success = true; } catch { success = false; } return(success); }
/// <summary> /// Extract device capabilities /// </summary> /// <param name="portableDeviceClass"></param> internal void ExtractDeviceCapabilities(PortableDeviceClass portableDeviceClass) { if (portableDeviceClass == null) throw new ArgumentNullException("portableDeviceClass"); try { IPortableDeviceCapabilities capabilities; portableDeviceClass.Capabilities(out capabilities); if (capabilities == null) { Trace.WriteLine("Cannot extract capabilities from device"); throw new PortableDeviceException("Cannot extract capabilities from device"); } IPortableDevicePropVariantCollection functionalCategories; capabilities.GetFunctionalCategories(out functionalCategories); if (functionalCategories == null) { throw new PortableDeviceException("Failed to extract functionnal categories"); } uint countCategories = 1; functionalCategories.GetCount(ref countCategories); var values = new tag_inner_PROPVARIANT(); string categoryName; Guid currentGuid; for (uint i = 0; i < countCategories; i++) { functionalCategories.GetAt(i, ref values); var pValues = (IPortableDeviceValues) new PortableDeviceValuesClass(); pValues.SetValue(ref PortableDevicePKeys.WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_FUNCTIONAL_CATEGORIES, ref values); pValues.GetStringValue(ref PortableDevicePKeys.WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_FUNCTIONAL_CATEGORIES, out categoryName); currentGuid = new Guid(categoryName); this.functionalCategories.Add(currentGuid, new FunctionalCategory( portableDeviceClass, currentGuid, PortableDeviceHelpers.GetKeyNameFromGuid(currentGuid))); } } catch (Exception ex) { throw new PortableDeviceException("Error on extract device capabilities", ex); } }
private void ExtractSupportedFormat(PortableDeviceClass portableDeviceClass, Guid contentType) { if (portableDeviceClass == null) throw new PortableDeviceException(""); IPortableDeviceCapabilities capabilities; portableDeviceClass.Capabilities(out capabilities); if (capabilities == null) { Trace.WriteLine("Cannot extract capabilities from device"); throw new PortableDeviceException("Cannot extract capabilities from device"); } var pValues = (IPortableDeviceValues) new PortableDeviceValuesClass(); //Functional objects variables IPortableDevicePropVariantCollection formats; uint countObjects = 1; var values = new tag_inner_PROPVARIANT(); string formatName; Guid currentFormat; capabilities.GetSupportedFormats(ref contentType, out formats); formats.GetCount(ref countObjects); for (uint i = 0; i < countObjects; i++) { formats.GetAt(i, ref values); pValues.SetValue(ref PortableDevicePKeys.WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_FORMATS, ref values); pValues.GetStringValue(ref PortableDevicePKeys.WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_FORMATS, out formatName); currentFormat = new Guid(formatName); this.formats[currentFormat] = PortableDeviceHelpers.GetKeyNameFromGuid(currentFormat); } }
/// <summary> /// Extract event supported by device /// </summary> /// <param name="portableDeviceClass"></param> internal void ExtractEvents(PortableDeviceClass portableDeviceClass) { IPortableDeviceCapabilities capabilities; portableDeviceClass.Capabilities(out capabilities); IPortableDevicePropVariantCollection events; capabilities.GetSupportedEvents(out events); uint countEvents = 0; events.GetCount(ref countEvents); var pValues = (IPortableDeviceValues) new PortableDeviceValuesClass(); var evt = new tag_inner_PROPVARIANT(); Guid eventName; IPortableDeviceValues eventOptions; PortableDeviceEventDescription eventDescription; for (uint i = 0; i < countEvents; i++) { events.GetAt(i, ref evt); pValues.SetValue(ref PortableDevicePKeys.WPD_EVENT_PARAMETER_EVENT_ID, ref evt); pValues.GetGuidValue(ref PortableDevicePKeys.WPD_EVENT_PARAMETER_EVENT_ID, out eventName); eventDescription = new PortableDeviceEventDescription(eventName, PortableDeviceHelpers.GetKeyNameFromGuid(eventName)); //Retrieve options try { // Event option isn't always present, so ... eventOptions = (IPortableDeviceValues) new PortableDeviceValuesClass(); capabilities.GetEventOptions(ref eventName, out eventOptions); //eventOptions.GetBoolValue(ref PortableDevicePKeys.WPD_EVENT_OPTION_IS_AUTOPLAY_EVENT, out isAutoPlayEvent); //eventOptions.GetBoolValue(ref PortableDevicePKeys.WPD_EVENT_OPTION_IS_BROADCAST_EVENT, out isBroadcastEvent); //eventDescription.AddOptions(new PortableDeviceEventOption() //{ // Guid = PortableDevicePKeys.WPD_EVENT_OPTION_IS_BROADCAST_EVENT.fmtid, // Name = PortableDeviceHelpers.GetKeyNameFromGuid(PortableDevicePKeys.WPD_EVENT_OPTION_IS_BROADCAST_EVENT.fmtid), // Value = isBroadcastEvent, // ValueType = TypeCode.Boolean //}); //eventDescription.AddOptions(new PortableDeviceEventOption() //{ // Guid = PortableDevicePKeys.WPD_EVENT_OPTION_IS_AUTOPLAY_EVENT.fmtid, // Name = PortableDeviceHelpers.GetKeyNameFromGuid(PortableDevicePKeys.WPD_EVENT_OPTION_IS_AUTOPLAY_EVENT.fmtid), // Value = isAutoPlayEvent, // ValueType = TypeCode.Boolean //}); } catch (Exception ex) { Debug.WriteLine(ex.Message); Debug.WriteLine(ex.StackTrace); } this.events.Add(eventDescription, PortableDevicePKeys.WPD_EVENT_PARAMETER_EVENT_ID); } }