/// <summary> /// 获取总容量和可用容量 /// </summary> /// <param name="deviceContent"></param> /// <param name="storageId"></param> /// <param name="freeSpace"></param> /// <param name="storageCapacity"></param> private static void GetStorageCapacityAnFreeSpace(IPortableDeviceContent deviceContent, string storageId, out ulong freeSpace, out ulong storageCapacity) { try { IPortableDeviceProperties deviceProperties; deviceContent.Properties(out deviceProperties); IPortableDeviceKeyCollection keyCollection = (IPortableDeviceKeyCollection) new PortableDeviceTypesLib.PortableDeviceKeyCollectionClass(); _tagpropertykey freeSpaceKey = new _tagpropertykey(); freeSpaceKey.fmtid = new Guid("01a3057a-74d6-4e80-bea7-dc4c212ce50a"); freeSpaceKey.pid = 5; _tagpropertykey storageCapacityKey = new _tagpropertykey(); storageCapacityKey.fmtid = new Guid("01a3057a-74d6-4e80-bea7-dc4c212ce50a"); storageCapacityKey.pid = 4; keyCollection.Add(freeSpaceKey); keyCollection.Add(storageCapacityKey); IPortableDeviceValues deviceValues; deviceProperties.GetValues(storageId, keyCollection, out deviceValues); deviceValues.GetUnsignedLargeIntegerValue(ref freeSpaceKey, out freeSpace); deviceValues.GetUnsignedLargeIntegerValue(ref storageCapacityKey, out storageCapacity); } catch { freeSpace = 0; storageCapacity = 0; } }
/// <summary> /// 获取设备或设备下文件夹的所有对象(文件、文件夹)的ObjectId /// </summary> /// <param name="deviceId"></param> /// <param name="parentId"></param> /// <returns></returns> private static List <string> GetChildrenObjectIds(IPortableDeviceContent content, string parentId) { IEnumPortableDeviceObjectIDs objectIds; content.EnumObjects(0, parentId, null, out objectIds); List <string> childItems = new List <string>(); uint fetched = 0; do { string objectId; objectIds.Next(1, out objectId, ref fetched); // Check if anything was retrieved. if (fetched > 0) { childItems.Add(objectId); } } while (fetched > 0); return(childItems); }
internal void Enumerate(ref IPortableDeviceContent pContent, string parentID, PortableDeviceContainerObject node, IObjectEnumerateHelper helper, bool detectNewObjects = false) { IPortableDeviceProperties properties; pContent.Properties(out properties); foreach (var objectID in ExtractObjectIds(pContent, parentID)) { if (detectNewObjects && ParentContainsChildsId(node, objectID)) { continue; } PortableDeviceObject current = ExtractInformation(properties, objectID); if (!helper.IsObjectMatching(current)) { continue; } node.AddChild(current); if (!helper.IsLastNode && current is PortableDeviceContainerObject) { Enumerate(ref pContent, objectID, (PortableDeviceContainerObject)current, helper.Next(), detectNewObjects); } } }
private void CreateTree(MTPFileNode parentNode, IPortableDeviceContent content, IPortableDeviceProperties properties, IAsyncTaskProgress asyn) { List <string> objectsId = GetChildrenObjectIds(content, parentNode.Id); if (objectsId != null && objectsId.Count > 0) { foreach (string objectId in objectsId) { IPortableDeviceValues objectValues; properties.GetValues(objectId, null, out objectValues); MTPFileNode fileNode = new MTPFileNode() { Type = GetFileTypeProperty(objectValues), Name = GetFullNameProperty(objectValues), //FileSize = GetFileSizeProperty(objectValues), Id = objectId, Childrens = new List <MTPFileNode>(), Parent = parentNode, //Level = parentNode.Level + 1 }; parentNode.Childrens.Add(fileNode); //asyn.Advance(0, string.Format(LanguageHelper.Get("LANGKEY_HuoQuJieDian_00555"), fileNode.Name)); if (fileNode.Type != MTPFileNodeType.File) { CreateTree(fileNode, content, properties, asyn); } } } }
/// <summary> /// This method enumerates/cycles through sub objects within this current object. /// </summary> /// <param name="content"></param> protected void LoadDeviceItems(IPortableDeviceContent content) { // Enumerate the items contained by the current object IEnumPortableDeviceObjectIDs objectIds; content.EnumObjects(0, Id, null, out objectIds); // Cycle through each device item and add it to the device items list. uint fetched = 0; do { string objectId; objectIds.Next(1, out objectId, ref fetched); // Check if anything was retrieved. if (fetched > 0) { DeviceItems.Add(new Item(objectId, content)); } } while (fetched > 0); }
private void Enumerate(ref IPortableDeviceContent pContent, string parentID, string indent) { // // Output object ID // Console.WriteLine(indent + parentID); indent += " "; // // Enumerate children (if any) // IEnumPortableDeviceObjectIDs pEnum; pContent.EnumObjects(0, parentID, null, out pEnum); var cFetched = 0U; do { string objectID; pEnum.Next(1, out objectID, ref cFetched); if (cFetched > 0) { // // Recurse into children // this.Enumerate(ref pContent, objectID, indent); } } while (cFetched > 0); }
/** * 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(); }
// private static string GetObjectName(IPortableDeviceContent deviceContent, string objectId) // { // IPortableDeviceProperties deviceProperties; // deviceContent.Properties(out deviceProperties); // // var keyCollection = (IPortableDeviceKeyCollection)new PortableDeviceTypesLib.PortableDeviceKeyCollectionClass(); // keyCollection.Add(ref PortableDevicePropertyKeys.WPD_OBJECT_NAME); // // IPortableDeviceValues deviceValues; // deviceProperties.GetValues(objectId, keyCollection, out deviceValues); // // string name; // deviceValues.GetStringValue(ref PortableDevicePropertyKeys.WPD_OBJECT_NAME, out name); // // return name; // } private static IEnumerable <string> GetObjectProperties(IPortableDeviceContent deviceContent, string objectId) { IPortableDeviceProperties deviceProperties; deviceContent.Properties(out deviceProperties); IPortableDeviceValues deviceValues; deviceProperties.GetValues(objectId, null, out deviceValues); var properties = new List <string>(); uint valueCount = 0; deviceValues.GetCount(ref valueCount); for (uint i = 0; i < valueCount; i++) { var key = new _tagpropertykey(); var value = new tag_inner_PROPVARIANT(); deviceValues.GetAt(i, ref key, ref value); properties.Add( String.Format("[{0}, {1}] : {2}", key.fmtid, key.pid, PropVariant.FromValue(value).AsString())); } return(properties); }
private static void EnumerateContents(ref IPortableDeviceContent content, PortableDeviceFolder parent) { IPortableDeviceProperties portableDeviceProperty; IEnumPortableDeviceObjectIDs enumPortableDeviceObjectId; string str; content.Properties(out portableDeviceProperty); content.EnumObjects(0, parent.Id, null, out enumPortableDeviceObjectId); uint num = 0; do { enumPortableDeviceObjectId.Next(1, out str, ref num); if (num <= 0) { continue; } PortableDeviceObject portableDeviceObject = WrapObject(portableDeviceProperty, str); parent.Files.Add(portableDeviceObject); if (!(portableDeviceObject is PortableDeviceFolder)) { continue; } EnumerateContents(ref content, (PortableDeviceFolder)portableDeviceObject); }while (num > 0); }
private List <TransFileObject> GetObjects(string parentDirId, IPortableDeviceContent content, TransFileObject.ObjectKind kindFilter = TransFileObject.ObjectKind.ALL) { var retObjs = new List <TransFileObject>(); IPortableDeviceProperties properties; content.Properties(out properties); IEnumPortableDeviceObjectIDs objectIDs; content.EnumObjects(0, parentDirId, null, out objectIDs); // オブジェクトを取得 string objectID; uint fetched = 0; while (true) { objectIDs.Next(1, out objectID, ref fetched); if (fetched <= 0) { break; } TransFileObject currentObject = WrapObject(properties, objectID); if (kindFilter == TransFileObject.ObjectKind.ALL || currentObject.kind == kindFilter) { retObjs.Add(currentObject); } } return(retObjs); }
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); } } }
protected static void EnumerateContents(ref IPortableDeviceContent content, PortableDeviceFolder parent) { // Get the properties of the object IPortableDeviceProperties properties; content.Properties(out properties); // Enumerate the items contained by the current object IEnumPortableDeviceObjectIDs objectIds; content.EnumObjects(0, parent.Id, null, out objectIds); uint fetched = 0; do { string objectId; objectIds.Next(1, out objectId, ref fetched); if (fetched > 0) { var currentObject = WrapObject(properties, objectId); parent.Files.Add(currentObject); if (currentObject is PortableDeviceFolder) { EnumerateContents(ref content, (PortableDeviceFolder) currentObject); } } } while (fetched > 0); }
/// <summary> /// gets the create date time for the object /// </summary> /// <param name="deviceContent">unmanged device</param> /// <param name="objectId">object id</param> /// <returns>Try the creation date, fall back to modified date</returns> public DateTime GetObjectCreationTime(IPortableDeviceContent deviceContent, string objectId) { // Try the creation date, fall back to modified date var WPD_OBJECT_DATE_CREATED = new _tagpropertykey(); WPD_OBJECT_DATE_CREATED.fmtid = new Guid(0xEF6B490D, 0x5CD8, 0x437A, 0xAF, 0xFC, 0xDA, 0x8B, 0x60, 0xEE, 0x4A, 0x3C); WPD_OBJECT_DATE_CREATED.pid = 18; try { return(GetDateProperty( deviceContent, objectId, WPD_OBJECT_DATE_CREATED)); } catch (Exception) { //return GetDateProperty( // deviceContent, // objectId, // WPD_OBJECT_DATE_MODIFIED); } return(DateTime.Now); }
public void Update(ref IPortableDeviceContent pContent, PortableDeviceContainerObject parent) { lock (dispatcher) { Enumerate(ref pContent, parent.ID, parent, new AllObjectEnumerateHelper(), detectNewObjects: true); } }
private static void EnumerateContents(ref IPortableDeviceContent content, PortableDeviceFolder parent) { // Get the properties of the object IPortableDeviceProperties properties; content.Properties(out properties); // Enumerate the items contained by the current object IEnumPortableDeviceObjectIDs objectIds; content.EnumObjects(0, parent.Id, null, out objectIds); uint fetched = 0; do { string objectId; objectIds.Next(1, out objectId, ref fetched); if (fetched > 0) { var currentObject = WrapObject(properties, objectId); parent.Files.Add(currentObject); if (currentObject is PortableDeviceFolder) { EnumerateContents(ref content, (PortableDeviceFolder)currentObject); } } } while (fetched > 0); }
public DeviceObject( IPortableDeviceHelper portableDeviceHelper, IPortableDeviceContent portableDeviceContent, string id, string name) : this(portableDeviceHelper, portableDeviceContent, new FilenameMatcher(), id, name) { }
private static string TransferContentFromDevice(string saveToPath, IPortableDeviceContent content, string parentObjectID) { IPortableDeviceResources resources; content.Transfer(out resources); PortableDeviceApiLib.IStream wpdStream = null; uint optimalTransferSize = int.MaxValue; PortableDeviceApiLib._tagpropertykey property = new PortableDeviceApiLib._tagpropertykey(); property.fmtid = new Guid(0xE81E79BE, 0x34F0, 0x41BF, 0xB5, 0x3F, 0xF1, 0xA0, 0x6A, 0xE8, 0x78, 0x42); property.pid = 0; try { resources.GetStream(parentObjectID, ref property, 0, ref optimalTransferSize, out wpdStream); System.Runtime.InteropServices.ComTypes.IStream sourceStream = (System.Runtime.InteropServices.ComTypes.IStream)wpdStream; using (FileStream targetStream = new FileStream(saveToPath, FileMode.Create, FileAccess.Write)) { int filesize = int.Parse(optimalTransferSize.ToString()); var buffer = new byte[filesize]; int bytesRead = 0; IntPtr bytesReadIntPtr = new IntPtr(bytesRead); //设备建议读取长度optimalTransferSize长度一般为262144即256k, //注释掉的sourceStream.Read不能更新bytesRead值,do循环只能执行一次即写入256k数据。 //创建nextBufferSize变量,用于每次Read后计算下一次buffer长度 int nextBufferSize = 0; do { if (bytesReadIntPtr == IntPtr.Zero) { bytesReadIntPtr = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(int))); } sourceStream.Read(buffer, filesize, bytesReadIntPtr); nextBufferSize = Marshal.ReadInt32(bytesReadIntPtr); if (filesize > nextBufferSize) { filesize = nextBufferSize; } targetStream.Write(buffer, 0, filesize); } while (nextBufferSize > 0); Marshal.FreeCoTaskMem(bytesReadIntPtr); } } catch (Exception ex) { return(ex.Message); } finally { if (wpdStream != null) { Marshal.ReleaseComObject(wpdStream); } } return(string.Empty); }
/// <summary> /// lookup the given key and return the date property associated with the object /// </summary> /// <param name="deviceContent">unmanged device</param> /// <param name="objectId">object id</param> /// <param name="key">name of the property key</param> /// <returns>date value</returns> public DateTime GetDateProperty(IPortableDeviceContent deviceContent, string objectId, _tagpropertykey key) { var deviceValues = GetDeviceValues(deviceContent, key, objectId); PortableDeviceApiLib.tag_inner_PROPVARIANT value; deviceValues.GetValue(ref key, out value); return(PropVariant.FromValue(value).ToDate()); }
/// <summary> /// lookup the given key and return the string property associated with the object /// </summary> /// <param name="deviceContent">unmanged device</param> /// <param name="objectId">object id</param> /// <param name="key">name of the property key</param> /// <returns>string value</returns> public string GetStringProperty(IPortableDeviceContent deviceContent, string objectId, _tagpropertykey key) { var deviceValues = GetDeviceValues(deviceContent, key, objectId); string value; deviceValues.GetStringValue(ref key, out value); return(value); }
/// <summary> /// lookup the given key and return the guid property associated with the object /// </summary> /// <param name="deviceContent">unmanged device</param> /// <param name="objectId">object id</param> /// <param name="key">name of the property key</param> /// <returns>guid value</returns> public Guid GetGuidProperty(IPortableDeviceContent deviceContent, string objectId, _tagpropertykey key) { var deviceValues = GetDeviceValues(deviceContent, key, objectId); Guid value; deviceValues.GetGuidValue(ref key, out value); return(value); }
/** * The root folder on the device, also enumerate all files and folers on device. */ public PortableDeviceFolder Root() { PortableDeviceFolder root = new PortableDeviceFolder("DEVICE", "DEVICE"); IPortableDeviceContent content = getContents(); EnumerateContents(ref content, root); return(root); }
/// インスタンスを初期化します。 /// </summary> /// <param name="id">オブジェクトの識別子。</param> /// <param name="client">デバイスに接続しているクライアント情報。</param> /// <param name="content">デバイスのコンテンツ情報。</param> /// <param name="properties">プロパティ。</param> internal WpdObject( string id, WpdClient client, IPortableDeviceContent content, IPortableDeviceProperties properties ) { this.Id = id; this._client = client; this._content = content; this._properties = properties; // プロパティ更新 this.UpdateValues(); }
/// <summary> /// lookup the given key and return the long property associated with the object /// </summary> /// <param name="deviceContent">unmanged device</param> /// <param name="objectId">object id</param> /// <param name="key">name of the property key</param> /// <returns>long value</returns> public ulong GetUnsignedLargeIntegerProperty(IPortableDeviceContent deviceContent, string objectId, _tagpropertykey key) { var deviceValues = GetDeviceValues(deviceContent, key, objectId); ulong value; deviceValues.GetUnsignedLargeIntegerValue(ref key, out value); return(value); }
/// インスタンスを初期化します。 /// </summary> /// <param name="id">オブジェクトの識別子。</param> /// <param name="client">デバイスに接続しているクライアント情報。</param> /// <param name="content">デバイスのコンテンツ情報。</param> /// <param name="properties">プロパティ。</param> internal WpdObject(string id, WpdClient client, IPortableDeviceContent content, IPortableDeviceProperties properties) { this.Id = id; this._client = client; this._content = content; this._properties = properties; // プロパティ更新 this.UpdateValues(); }
private void DownloadFile(TransFileObject file, string destPath, IPortableDeviceContent content) { IPortableDeviceProperties properties; content.Properties(out properties); var downloadFileObj = WrapObject(properties, file.objId); IPortableDeviceResources resources; content.Transfer(out resources); PortableDeviceApiLib.IStream wpdStream; uint optimalTransferSize = 0; var property = new _tagpropertykey(); property.fmtid = new Guid(0xE81E79BE, 0x34F0, 0x41BF, 0xB5, 0x3F, 0xF1, 0xA0, 0x6A, 0xE8, 0x78, 0x42); property.pid = 0; resources.GetStream(file.objId, ref property, 0, ref optimalTransferSize, out wpdStream); System.Runtime.InteropServices.ComTypes.IStream sourceStream = (System.Runtime.InteropServices.ComTypes.IStream)wpdStream; FileStream targetStream = new FileStream(destPath, FileMode.Create, FileAccess.Write); unsafe { var buffer = new byte[10240]; int bytesRead; do { sourceStream.Read(buffer, 10240, new IntPtr(&bytesRead)); if (bytesRead <= 0) { break; } targetStream.Write(buffer, 0, bytesRead); } while (true /*bytesRead > 0*/); targetStream.Close(); } Marshal.ReleaseComObject(sourceStream); Marshal.ReleaseComObject(wpdStream); // ファイルの更新日時を更新 DateTime setDate = file.updateTime; if (setDate.CompareTo(DateTime.MinValue) == 0) { setDate = GetImgTakenDate(destPath); // Exifから撮影日時情報を取得 } File.SetLastWriteTime(destPath, setDate); }
private static void GetFiles(ref IPortableDeviceContent content, PortableDeviceFolder folder) { PortableDeviceFolder.EnumerateContents(ref content, folder); foreach (var fileItem in folder.Files) { Console.WriteLine($"\t{fileItem.Name}"); if (fileItem is PortableDeviceFolder childFolder) { GetFiles(ref content, childFolder); } } }
/// <summary> /// delete the specified object /// </summary> /// <param name="deviceContent">unmanged device</param> /// <param name="objectId">object to delete</param> public void DeleteObject(IPortableDeviceContent deviceContent, string objectId) { var objectIdCollection = (IPortableDevicePropVariantCollection) new PortableDeviceTypesLib.PortableDevicePropVariantCollectionClass(); var propVariantValue = PropVariant.StringToPropVariant(objectId); objectIdCollection.Add(ref propVariantValue); // TODO: get the results back and handle failures correctly deviceContent.Delete(PortableDeviceConstants.PORTABLE_DEVICE_DELETE_NO_RECURSION, objectIdCollection, null); }
public DeviceObject( IPortableDeviceHelper portableDeviceHelper, IPortableDeviceContent portableDeviceContent, IFilenameMatcher filenameMatcher, string id, string name) { _portableDeviceHelper = portableDeviceHelper; _portableDeviceContent = portableDeviceContent; _filenameMatcher = filenameMatcher; Id = id; Name = name; }
/// <summary> /// open a stream on the device for reading /// </summary> /// <param name="deviceContent">unmanged device</param> /// <param name="objectId">object to open</param> /// <param name="mode">mode to open the stream in</param> /// <returns></returns> public IStream OpenResourceStream(IPortableDeviceContent deviceContent, string objectId, uint mode) { IPortableDeviceResources resources; deviceContent.Transfer(out resources); IStream stream; uint optimalBufferSize = 0; resources.GetStream(objectId, PortableDevicePropertyKeys.WPD_RESOURCE_DEFAULT, mode, ref optimalBufferSize, out stream); return(stream); }
/// <summary> /// Tries to get the original filename property if it exists (ie. for real files/directories), falls /// back to object name for non-file objects (eg. device, Internal Storage, etc.) /// </summary> /// <param name="deviceContent">unmanaged device</param> /// <param name="objectId">the object id</param> /// <returns></returns> public string GetObjectFileName(IPortableDeviceContent deviceContent, string objectId) { try { return(GetStringProperty( deviceContent, objectId, PortableDevicePropertyKeys.WPD_OBJECT_ORIGINAL_FILE_NAME)); } catch (Exception) { return(GetObjectName(deviceContent, objectId)); } }
/// <summary> /// Tries to get the original filename property if it exists (ie. for real files/directories), falls /// back to object name for non-file objects (eg. device, Internal Storage, etc.) /// </summary> /// <param name="deviceContent">unmanaged device</param> /// <param name="objectId">the object id</param> /// <returns></returns> public string GetObjectFileName(IPortableDeviceContent deviceContent, string objectId) { try { return GetStringProperty( deviceContent, objectId, PortableDevicePropertyKeys.WPD_OBJECT_ORIGINAL_FILE_NAME); } catch (Exception) { return GetObjectName(deviceContent, objectId); } }
private static IPortableDeviceValues GetDeviceValues(IPortableDeviceContent deviceContent, _tagpropertykey key, string objectId) { IPortableDeviceProperties deviceProperties; deviceContent.Properties(out deviceProperties); var keyCollection = (IPortableDeviceKeyCollection) new PortableDeviceTypesLib.PortableDeviceKeyCollectionClass(); keyCollection.Add(key); IPortableDeviceValues deviceValues; deviceProperties.GetValues(objectId, keyCollection, out deviceValues); return(deviceValues); }
/// <summary> /// create a new resource stream in a parent object /// </summary> /// <param name="deviceContent">unmanged device</param> /// <param name="parentObjectId">the parent object</param> /// <param name="fileName">file to create</param> /// <param name="length">length of the file in bytes</param> /// <returns></returns> public IStream CreateResourceStream(IPortableDeviceContent deviceContent, string parentObjectId, string fileName, long length) { IPortableDeviceProperties deviceProperties; deviceContent.Properties(out deviceProperties); var deviceValues = GetRequiredPropertiesForFile(parentObjectId, fileName, length); IStream stream; uint optimalBufferSize = 0; deviceContent.CreateObjectWithPropertiesAndData(deviceValues, out stream, ref optimalBufferSize, null); return(stream); }
/// <summary> /// Tries to get the original filename property if it exists (ie. for real files/directories), falls /// back to object name for non-file objects (eg. device, Internal Storage, etc.) /// </summary> /// <param name="deviceContent">unmanaged device</param> /// <param name="objectId">the object id</param> /// <returns></returns> public ulong GetObjectFileSize(IPortableDeviceContent deviceContent, string objectId) { try { return GetUnsignedLargeIntegerProperty( deviceContent, objectId, PortableDevicePropertyKeys.WPD_OBJECT_SIZE); } catch (Exception exc) { Exception e = exc; return 0; //return GetObjectName(deviceContent, objectId); } }
public Item(string objectId, IPortableDeviceContent content) : base(objectId) { DeviceContent = content; IPortableDeviceProperties properties; content.Properties(out properties); IPortableDeviceKeyCollection keys; properties.GetSupportedProperties(objectId, out keys); IPortableDeviceValues values; properties.GetValues(objectId, keys, out values); ContentType = new ContentTypeProperty(values); Name = new NameProperty(values); // Only load the sub information if the current object is a folder or functional object. switch (ContentType.Type) { case WindowsPortableDeviceEnumerators.ContentType.FunctionalObject: { LoadDeviceItems(content); break; } case WindowsPortableDeviceEnumerators.ContentType.Folder: { OriginalFileName = new OriginalFileNameProperty(values); LoadDeviceItems(content); break; } case WindowsPortableDeviceEnumerators.ContentType.Image: { OriginalFileName = new OriginalFileNameProperty(values); break; } } }
private static IPortableDeviceValues GetDeviceValues(IPortableDeviceContent deviceContent, _tagpropertykey key, string objectId) { IPortableDeviceProperties deviceProperties; deviceContent.Properties(out deviceProperties); var keyCollection = (IPortableDeviceKeyCollection)new PortableDeviceTypesLib.PortableDeviceKeyCollectionClass(); keyCollection.Add(key); IPortableDeviceValues deviceValues; deviceProperties.GetValues(objectId, keyCollection, out deviceValues); return deviceValues; }
/// <summary> /// lookup the given key and return the guid property associated with the object /// </summary> /// <param name="deviceContent">unmanged device</param> /// <param name="objectId">object id</param> /// <param name="key">name of the property key</param> /// <returns>guid value</returns> public Guid GetGuidProperty(IPortableDeviceContent deviceContent, string objectId, _tagpropertykey key) { var deviceValues = GetDeviceValues(deviceContent, key, objectId); Guid value; deviceValues.GetGuidValue(ref key, out value); return value; }
public void Update(ref IPortableDeviceContent pContent, PortableDeviceContainerObject parent) { lock (dispatcher) { Enumerate(ref pContent, parent.ID, parent, enumerateHelper, detectNewObjects: true); } }
/// <summary> /// gets the name of an object /// </summary> /// <param name="deviceContent">unmanged device</param> /// <param name="objectId">object id</param> /// <returns>name</returns> public string GetObjectName(IPortableDeviceContent deviceContent, string objectId) { return GetStringProperty( deviceContent, objectId, PortableDevicePropertyKeys.WPD_OBJECT_NAME); }
/// <summary> /// lookup the given key and return the string property associated with the object /// </summary> /// <param name="deviceContent">unmanged device</param> /// <param name="objectId">object id</param> /// <param name="key">name of the property key</param> /// <returns>string value</returns> public string GetStringProperty(IPortableDeviceContent deviceContent, string objectId, _tagpropertykey key) { var deviceValues = GetDeviceValues(deviceContent, key, objectId); string value; deviceValues.GetStringValue(ref key, out value); return value; }
/// <summary> /// create a new resource stream in a parent object /// </summary> /// <param name="deviceContent">unmanged device</param> /// <param name="parentObjectId">the parent object</param> /// <param name="fileName">file to create</param> /// <param name="length">length of the file in bytes</param> /// <returns></returns> public IStream CreateResourceStream(IPortableDeviceContent deviceContent, string parentObjectId, string fileName, long length) { IPortableDeviceProperties deviceProperties; deviceContent.Properties(out deviceProperties); var deviceValues = GetRequiredPropertiesForFile(parentObjectId, fileName, length); IStream stream; uint optimalBufferSize = 0; deviceContent.CreateObjectWithPropertiesAndData(deviceValues, out stream, ref optimalBufferSize, null); return stream; }
/// <summary> /// lookup the given key and return the long property associated with the object /// </summary> /// <param name="deviceContent">unmanged device</param> /// <param name="objectId">object id</param> /// <param name="key">name of the property key</param> /// <returns>long value</returns> public ulong GetUnsignedLargeIntegerProperty(IPortableDeviceContent deviceContent, string objectId, _tagpropertykey key) { var deviceValues = GetDeviceValues(deviceContent, key, objectId); ulong value; deviceValues.GetUnsignedLargeIntegerValue(ref key, out value); return value; }
/// <summary> /// open a stream on the device for reading /// </summary> /// <param name="deviceContent">unmanged device</param> /// <param name="objectId">object to open</param> /// <param name="mode">mode to open the stream in</param> /// <returns></returns> public IStream OpenResourceStream(IPortableDeviceContent deviceContent, string objectId, uint mode) { IPortableDeviceResources resources; deviceContent.Transfer(out resources); IStream stream; uint optimalBufferSize = 0; resources.GetStream(objectId, PortableDevicePropertyKeys.WPD_RESOURCE_DEFAULT, mode, ref optimalBufferSize, out stream); //_ULARGE_INTEGER uli = new _ULARGE_INTEGER(); //uli.QuadPart = GetObjectFileSize(deviceContent, objectId); //stream.SetSize(uli); return stream; }
/// <summary> /// delete the specified object /// </summary> /// <param name="deviceContent">unmanged device</param> /// <param name="objectId">object to delete</param> public void DeleteObject(IPortableDeviceContent deviceContent, string objectId) { var objectIdCollection = (IPortableDevicePropVariantCollection)new PortableDeviceTypesLib.PortableDevicePropVariantCollectionClass(); var propVariantValue = PropVariant.StringToPropVariant(objectId); objectIdCollection.Add(ref propVariantValue); // TODO: get the results back and handle failures correctly deviceContent.Delete(PortableDeviceConstants.PORTABLE_DEVICE_DELETE_NO_RECURSION, objectIdCollection, null); }
/// <summary> /// create a folder storage object withing the specified parent /// </summary> /// <param name="deviceContent">unmanaged device</param> /// <param name="parentObjectId">parent object id</param> /// <param name="newFolder">name of the new folder</param> /// <returns>created object id</returns> public string CreateFolderObject(IPortableDeviceContent deviceContent, string parentObjectId, string newFolder) { IPortableDeviceProperties deviceProperties; deviceContent.Properties(out deviceProperties); IPortableDeviceValues deviceValues = (IPortableDeviceValues)new PortableDeviceTypesLib.PortableDeviceValues(); GetRequiredPropertiesForFolder(parentObjectId, newFolder, ref deviceValues); string objectId = string.Empty; deviceContent.CreateObjectWithPropertiesOnly(deviceValues,ref objectId); return objectId; }
private IEnumerable<string> ExtractObjectIds(IPortableDeviceContent pContent, string parentID) { IEnumPortableDeviceObjectIDs pEnum; pContent.EnumObjects(0, parentID, null, out pEnum); uint cFetched = 0; do { string objectID; pEnum.Next(1, out objectID, ref cFetched); if (cFetched <= 0) continue; yield return objectID; } while (cFetched > 0); }
/// <summary> /// identify the object type /// </summary> /// <param name="deviceContent">unmanged device</param> /// <param name="objectId">the object id</param> /// <returns>content type guid</returns> public Guid GetObjectContentType(IPortableDeviceContent deviceContent, string objectId) { return GetGuidProperty( deviceContent, objectId, PortableDevicePropertyKeys.WPD_OBJECT_CONTENT_TYPE); }
/// <summary> /// lookup the given key and return the date property associated with the object /// </summary> /// <param name="deviceContent">unmanged device</param> /// <param name="objectId">object id</param> /// <param name="key">name of the property key</param> /// <returns>date value</returns> public DateTime GetDateProperty(IPortableDeviceContent deviceContent, string objectId, _tagpropertykey key) { var deviceValues = GetDeviceValues(deviceContent, key, objectId); tag_inner_PROPVARIANT value; deviceValues.GetValue(ref key, out value); return PropVariant.FromValue(value).ToDate(); }
/// <summary> /// gets the create date time for the object /// </summary> /// <param name="deviceContent">unmanged device</param> /// <param name="objectId">object id</param> /// <returns>Try the creation date, fall back to modified date</returns> public DateTime GetObjectCreationTime(IPortableDeviceContent deviceContent, string objectId) { // Try the creation date, fall back to modified date try { return GetDateProperty( deviceContent, objectId, PortableDevicePropertyKeys.WPD_OBJECT_DATE_CREATED); } catch (Exception) { return GetDateProperty( deviceContent, objectId, PortableDevicePropertyKeys.WPD_OBJECT_DATE_MODIFIED); } }
/// <summary> /// get all the child object ids from a given parent /// </summary> /// <param name="deviceContent">unmanged device</param> /// <param name="parentId">parent object id</param> /// <returns>all child ids</returns> public IEnumerable<string> GetChildObjectIds(IPortableDeviceContent deviceContent, string parentId) { var childObjectIds = new List<string>(); IEnumPortableDeviceObjectIDs objectIdEnumerator; deviceContent.EnumObjects(0, parentId, null, out objectIdEnumerator); const int numberOfObjects = 1; uint numberReturned; do { numberReturned = 0; string childObjectId; objectIdEnumerator.Next(numberOfObjects, out childObjectId, ref numberReturned); if (numberReturned != 0) { childObjectIds.Add(childObjectId); } } while (numberReturned != 0); return childObjectIds; }
internal void Enumerate(ref IPortableDeviceContent pContent, string parentID, PortableDeviceContainerObject node, IObjectEnumerateHelper helper, bool detectNewObjects = false) { IPortableDeviceProperties properties; pContent.Properties(out properties); foreach (var objectID in ExtractObjectIds(pContent, parentID)) { if (detectNewObjects && ParentContainsChildsId(node, objectID)) continue; PortableDeviceObject current = ExtractInformation(properties, objectID); if(!helper.IsObjectMatching(current)) continue; node.AddChild(current); if (!helper.IsLastNode && current is PortableDeviceContainerObject) Enumerate(ref pContent, objectID, (PortableDeviceContainerObject)current, helper.Next(), detectNewObjects); } }