internal static string GetKeyNameFromPropkey(PortableDeviceApiLib._tagpropertykey propertyKey) { foreach (KeyValuePair<string, PortableDeviceApiLib._tagpropertykey> de in _values) { if ((propertyKey.pid == de.Value.pid) && (propertyKey.fmtid == de.Value.fmtid)) { return (string)de.Key; } } return (propertyKey.pid.ToString() + " " + propertyKey.fmtid.ToString()); }
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 static string GetNameFromGuid(PortableDeviceApiLib._tagpropertykey key, PortableDeviceApiLib.tag_inner_PROPVARIANT values) { PortableDeviceApiLib.IPortableDeviceValues pValues = (PortableDeviceApiLib.IPortableDeviceValues)new PortableDeviceTypesLib.PortableDeviceValuesClass(); string contentTypeName; pValues.SetValue(ref key, ref values); pValues.GetStringValue(ref key, out contentTypeName); return contentTypeName; }
private PortableDeviceObject ExtractInformation(PortableDeviceApiLib.IPortableDeviceProperties properties, string objectId) { PortableDeviceApiLib.IPortableDeviceKeyCollection keys; properties.GetSupportedProperties(objectId, out keys); PortableDeviceApiLib.IPortableDeviceValues values; properties.GetValues(objectId, keys, out values); string tmpVal; string name; values.GetStringValue(ref PortableDevicePKeys.WPD_OBJECT_NAME, out name); values.GetStringValue(ref PortableDevicePKeys.WPD_OBJECT_CONTENT_TYPE, out tmpVal); var guid = new Guid(tmpVal); string contentType = PortableDeviceHelpers.GetKeyNameFromGuid(guid); values.GetStringValue(ref PortableDevicePKeys.WPD_OBJECT_FORMAT, out tmpVal); string formatType = PortableDeviceHelpers.GetKeyNameFromGuid(new Guid(tmpVal)); return Factories.PortableDeviceObjectFactory.Instance.CreateInstance(guid, objectId, name, contentType, formatType); }
private void Enumerate(ref PortableDeviceApiLib.IPortableDeviceContent pContent, string parentID, PortableDeviceContainerObject node) { PortableDeviceApiLib.IPortableDeviceProperties properties; pContent.Properties(out properties); PortableDeviceApiLib.IEnumPortableDeviceObjectIDs pEnum; pContent.EnumObjects(0, parentID, null, out pEnum); uint cFetched = 0; PortableDeviceObject current; do { string objectID; pEnum.Next(1, out objectID, ref cFetched); if (cFetched > 0) { current = this.ExtractInformation(properties, objectID); node.AddChild(current); if (current is PortableDeviceContainerObject) Enumerate(ref pContent, objectID, (PortableDeviceContainerObject)current); } } while (cFetched > 0); }
//delete a file from device private static void StringToPropVariant(string value,out PortableDeviceApiLib.tag_inner_PROPVARIANT propvarValue) { PortableDeviceApiLib.IPortableDeviceValues pValues = (PortableDeviceApiLib.IPortableDeviceValues) new PortableDeviceTypesLib.PortableDeviceValuesClass(); var 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); }
static bool wpdEnumContent(string strObjectId, PortableDeviceApiLib.IPortableDeviceContent content) { if (null == strObjectId) { return false; } if (null == content) { return false; } //Console.WriteLine(strObjectId); bool result = true; PortableDeviceApiLib.IEnumPortableDeviceObjectIDs enumObj = null; const uint dwFlags = 0; const PortableDeviceApiLib.IPortableDeviceValues filter = null; try { content.EnumObjects(dwFlags, strObjectId, filter, out enumObj); } catch (System.Exception e) { if (e is System.Runtime.InteropServices.COMException) { System.Runtime.InteropServices.COMException ex = (System.Runtime.InteropServices.COMException)e; Console.WriteLine("EnumObjects, hr={0:X}", (uint)ex.ErrorCode); } else { Console.WriteLine(e.Message); } //Console.WriteLine(e.StackTrace); return false; } if (null == enumObj) { return false; } string[] strObjectIdArray = new string[MY_FETCH_COUNT]; //string strObjectIdArray = ""; uint nFetched = 0; do { // MY_FETCH_COUNT 1 is allowed. over 2, null reference occured and leak CoTaskMemFree at marshall System.Diagnostics.Debug.Assert(1 == MY_FETCH_COUNT); try { enumObj.Next(MY_FETCH_COUNT, out strObjectIdArray[0], ref nFetched); } catch (System.Exception e) { if (e is System.Runtime.InteropServices.COMException) { System.Runtime.InteropServices.COMException ex = (System.Runtime.InteropServices.COMException)e; Console.WriteLine("enumObj Next, hr={0:X}", (uint)ex.ErrorCode); } else { Console.WriteLine(e.Message); } //Console.WriteLine(e.StackTrace); result = false; nFetched = 0; break; } if (0 < nFetched) { countContent += nFetched; for (uint index = 0; index < nFetched; ++index) { result = wpdEnumContent(strObjectIdArray[index], content); if (false == result) { break; } } if (false == result) { nFetched = 0; break; } } } while (0 < nFetched); enumObj = null; return result; }
internal DeviceStream(PortableDeviceApiLib.IStream deviceStream) : this((IStream)deviceStream) // This is apparently safe for streams we get back from the portable device lib {}