コード例 #1
0
        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);
        }
コード例 #2
0
        private bool IsInFolderList(string objectId, IPortableDeviceContent content)
        {
            bool result = false;

            DeviceContent = content;

            IPortableDeviceProperties properties;

            content.Properties(out properties);

            IPortableDeviceKeyCollection keys;

            properties.GetSupportedProperties(objectId, out keys);

            IPortableDeviceValues values;

            properties.GetValues(objectId, keys, out values);

            var theContentType = new ContentTypeProperty(values);
            var theName        = new NameProperty(values);

            if (LoadFolders.Count == 0 || LoadFolders.Contains(theName.Value.ToUpper()))
            {
                result = true;
            }

            return(result);
        }
コード例 #3
0
        /// <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;
            }
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: kaury/PodcastUtilities
//        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);
        }
コード例 #5
0
ファイル: CompatibleDevice.cs プロジェクト: notpod/Notpod2
        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);
        }
コード例 #6
0
        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);
                }
            }
        }
コード例 #7
0
        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);
        }
コード例 #8
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);
        }
コード例 #9
0
        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);
        }
コード例 #10
0
        /// <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);
        }
コード例 #11
0
        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);
        }
コード例 #12
0
        /// <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);
        }
コード例 #13
0
        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:
            {
                //TODO: Replace it back to LoadDeviceItems if not correct
                LoadDeviceItemsByThread(content);
                break;
            }

            case WindowsPortableDeviceEnumerators.ContentType.Folder:
            {
                OriginalFileName = new OriginalFileNameProperty(values);
                LoadDeviceItems(content);
                break;
            }

            case WindowsPortableDeviceEnumerators.ContentType.Image:
            case WindowsPortableDeviceEnumerators.ContentType.Video:
            case WindowsPortableDeviceEnumerators.ContentType.Audio:
            {
                OriginalFileName = new OriginalFileNameProperty(values);
                break;
            }
            }
        }
コード例 #14
0
        /// <summary>
        /// 连接设备
        /// </summary>
        /// <param name="DeviceId"></param>
        /// <param name="portableDevice"></param>
        /// <param name="deviceContent"></param>
        /// <returns></returns>
        private static IPortableDeviceValues Connect(string DeviceId, out PortableDevice portableDevice, out IPortableDeviceContent deviceContent)
        {
            IPortableDeviceValues clientInfo = (IPortableDeviceValues) new PortableDeviceTypesLib.PortableDeviceValuesClass();

            portableDevice = new PortableDeviceClass();
            portableDevice.Open(DeviceId, clientInfo);
            portableDevice.Content(out deviceContent);

            IPortableDeviceProperties deviceProperties;

            deviceContent.Properties(out deviceProperties);

            IPortableDeviceValues deviceValues;

            deviceProperties.GetValues("DEVICE", null, out deviceValues);
            return(deviceValues);
        }
コード例 #15
0
ファイル: Device.cs プロジェクト: brian-spanton/iTunesSync
        public Device(PortableDeviceManager devices, string id)
        {
            this.id = id;

            uint length = 0;

            devices.GetDeviceDescription(id, null, ref length);

            char[] bytes = new char[length];
            devices.GetDeviceDescription(id, bytes, ref length);
            description = new string(bytes, 0, (int)length - 1);

            foobalator.Log.WriteLine(string.Format("Discovered {0}", description));

            PortableDeviceValues values = new PortableDeviceValues();

            values.SetUnsignedIntegerValue(Constants.WPD_CLIENT_DESIRED_ACCESS, Constants.GENERIC_READ | Constants.GENERIC_WRITE);

            PortableDevice device = new PortableDevice();

            device.Open(id, values);
            device.Content(out content);
            content.Properties(out properties);

            DeviceObject root = new DeviceObject(this, "DEVICE");

            DeviceObject phoneFolder = root.GetChildByName("Phone");

            if (phoneFolder == null)
            {
                return;
            }

            musicFolder = phoneFolder.GetChildByName("Music");
            if (musicFolder == null)
            {
                return;
            }

            playlistFolder = musicFolder.GetChildByName("Playlist");
            if (playlistFolder == null)
            {
                return;
            }
        }
コード例 #16
0
        public void GetDate(MTPDevice device, MTPFileNode fileNode)
        {
            IPortableDeviceContent content = GetDeviceContent(device.DeviceId);

            IPortableDeviceProperties properties;

            content.Properties(out properties);

            IPortableDeviceValues objectValues;

            properties.GetValues(fileNode.Id, null, out objectValues);

            //暂时只获取文件的创建、修改、最后访问时间
            //由于不用手机设备对MTP协议的支持程度不同,导致不同设备可能获取到的多少不一致
            fileNode.DateCreated  = GetFileDateCreatedProperty(objectValues);
            fileNode.DateModified = GetFileDateModifiedProperty(objectValues);
            fileNode.DateAuthored = GetFileDateAuthoredProperty(objectValues);
        }
コード例 #17
0
        private static void EnumerateContents(PortableDevice parentDevice, 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
            {
                fetched = 0;

                string objectId;

                objectIds.Next(1, out objectId, ref fetched);
                if (fetched > 0)
                {
                    var currentObject = WrapObject(properties, objectId);
                    currentObject.content      = content;
                    currentObject.parentDevice = parentDevice;

                    parent.Files.Add(currentObject);

                    if (currentObject is PortableDeviceFolder)
                    {
                        System.Diagnostics.Debugger.Log(0, "cat", "Opening: " + currentObject.Name + "\r\n");

                        //EnumerateContents(ref content, (PortableDeviceFolder) currentObject);
                    }
                    else
                    {
                        System.Diagnostics.Debugger.Log(0, "cat", "Adding: " + currentObject.Name + "\r\n");
                    }
                }
            } while (fetched > 0);
        }
コード例 #18
0
ファイル: Item.cs プロジェクト: tiemuer/WPD-.NET-Wrapper
        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;
                }
            }
        }
コード例 #19
0
        public void EnumerateContents(ref IPortableDeviceContent content, PortableDeviceFolder parent, int level)
        {
            if (level < 2)
            {
                // 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)
                        {
                            if (!currentObject.Name.Equals("ServicePlatform"))
                            {
                                EnumerateContents(ref content, (PortableDeviceFolder)currentObject, level + 1);
                            }
                            else
                            {
                                ServicePlatformFolder = currentObject;
                                EnumerateContents(ref content, (PortableDeviceFolder)currentObject, 0);
                            }
                        }
                    }
                } while (fetched > 0);
            }
        }
コード例 #20
0
        /**
         * Device must be connected!
         *
         * Returns the id of the new folder.
         */
        public PortableDeviceFolder CreateDir(PortableDevice device, string folderName)
        {
            PortableDeviceFolder result = null;

            try
            {
                String newFolderId = "";

                // Already got folderName?
                result = FindDir(folderName);
                if (null == result)
                {
                    IPortableDeviceContent content = device.getContents();

                    // Get the properties of the object
                    IPortableDeviceProperties properties;
                    content.Properties(out properties);

                    IPortableDeviceValues createFolderValues = GetRequiredCreateDirPropertiesForContentType(Id, folderName);

                    content.CreateObjectWithPropertiesOnly(createFolderValues, ref newFolderId);

                    // Last, add to list of files.
                    result = new PortableDeviceFolder(newFolderId, folderName);

                    this.Files.Add(result);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                result = null;
            }

            return(result);
        }
コード例 #21
0
ファイル: PortableDevice.cs プロジェクト: grzwolf/cfw
        private static void EnumerateFolderContent(ref IPortableDeviceContent content, PortableDeviceFolder parent, string currentFolder, string targetFolder, ref List <wpdFileInfo> retlist, ref string targetFolderID)
        {
            // save ID of the parent when target folder is reached
            if (targetFolder == currentFolder)
            {
                targetFolderID = parent.Id;
            }
            // 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)
                {
                    PortableDeviceObject currentObject = WrapObject(properties, objectId);
                    // only collect objects within the targetFolder, ignore all other object
                    if (targetFolder == currentFolder)
                    {
                        // build item
                        string name = currentObject.Name;
                        if (currentObject is PortableDeviceFolder)
                        {
                            // get file modified date
                            IPortableDeviceKeyCollection keys;
                            properties.GetSupportedProperties(currentObject.Id, out keys);
                            IPortableDeviceValues values;
                            properties.GetValues(currentObject.Id, keys, out values);
                            string          objDateStr = "";
                            _tagpropertykey property   = new _tagpropertykey();
                            property.fmtid = new Guid("EF6B490D-5CD8-437A-AFFC-DA8B60EE4A3C");
                            property.pid   = 19;                                 //WPD_OBJECT_DATE_MODIFIED
                            try {
                                values.GetStringValue(property, out objDateStr); // 2016/10/19:18:52:52.000
                            } catch {; }
                            retlist.Add(new wpdFileInfo("p:" + name, "wpd_" + currentObject.Id, 0, objDateStr));
                        }
                        if (currentObject is PortableDeviceFile)
                        {
                            // get file properties
                            IPortableDeviceKeyCollection keys;
                            properties.GetSupportedProperties(currentObject.Id, out keys);
                            IPortableDeviceValues values;
                            properties.GetValues(currentObject.Id, keys, out values);

                            // get file size
                            long            objSize;
                            _tagpropertykey property = new _tagpropertykey();
                            property.fmtid = new Guid("EF6B490D-5CD8-437A-AFFC-DA8B60EE4A3C");
                            property.pid   = 11; //WPD_OBJECT_SIZE;
                            values.GetSignedLargeIntegerValue(property, out objSize);

                            // get file modified date
                            string objDateStr;
                            property.pid = 19;                               //WPD_OBJECT_DATE_MODIFIED
                            values.GetStringValue(property, out objDateStr); // 2016/10/19:18:52:52.000
                            //DateTime objDateUTC = (DateTime.ParseExact(objDateStr, "dd.MM.yyyy HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.AssumeLocal)).ToUniversalTime();  // 2016/10/19:18:52:52.000

                            // transfer file to return list
                            retlist.Add(new wpdFileInfo("f:" + name, "wpd_" + currentObject.Id, objSize, objDateStr));
                        }
                    }

                    // a path sequence along the targetFolder is needed; as long as currentFolder is the beginning of the targetFolder, we are on the right track
                    string latestFolder = Path.Combine(currentFolder, currentObject.Name);
                    if ((targetFolder.StartsWith(latestFolder)))
                    {
                        // next level starts with a new currentFolder
                        currentFolder = latestFolder;
                        EnumerateFolderContent(ref content, (PortableDeviceFolder)currentObject, currentFolder, targetFolder, ref retlist, ref targetFolderID);
                        // after returning from a deeper level, currentFolder needs to reset to the next higher level
                        currentFolder = Path.GetDirectoryName(currentFolder);
                    }
                }
            } while (fetched > 0);
        }
コード例 #22
0
        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;
        }
コード例 #23
0
        /// <summary>
        /// 获取MTP设备文件系统树
        /// </summary>
        /// <param name="device"></param>
        /// <param name="asyn"></param>
        /// <returns>根节点</returns>
        public MTPFileNode GetRootFileNode(MTPDevice device, IAsyncTaskProgress asyn)
        {
            MTPFileNode root = new MTPFileNode()
            {
                Type = MTPFileNodeType.Root, Name = "Root", Childrens = new List <MTPFileNode>(), Level = -1
            };

            IPortableDeviceContent content = GetDeviceContent(device.DeviceId);

            IPortableDeviceProperties properties;

            content.Properties(out properties);

            IPortableDeviceValues deviceValues;

            properties.GetValues("DEVICE", null, out deviceValues);

            List <string> storagesId = GetChildrenObjectIds(content, "DEVICE"); //获取存储卡设备

            foreach (string storageId in storagesId)
            {
                MTPFileNode deviceNode = new MTPFileNode()
                {
                    Type      = MTPFileNodeType.Device,
                    Name      = GetNameById(storageId, properties),
                    Id        = storageId,
                    Childrens = new List <MTPFileNode>(),
                    Parent    = root,
                    //Level = 0
                };
                root.Childrens.Add(deviceNode);
            }

            foreach (var parentNode in root.Childrens)
            {
                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);

                        if (fileNode.Type != MTPFileNodeType.File)
                        {
                            CreateTree(fileNode, content, properties, asyn);
                        }
                    }
                }
            }

            return(root);
        }
コード例 #24
0
        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);
            }
        }
コード例 #25
0
        /// <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;
        }
コード例 #26
0
        /// <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;
        }
コード例 #27
0
        public MTPFileNode GetRootFileNode(MTPDevice device, IAsyncProgress asyn)
        {
            MTPFileNode root = new MTPFileNode()
            {
                Type = MTPFileNodeType.Root, Name = "Root", Childrens = new List <MTPFileNode>(), Level = -1
            };

            IPortableDeviceContent content = GetDeviceContent(device.DeviceId);

            IPortableDeviceProperties properties;

            content.Properties(out properties);

            IPortableDeviceValues deviceValues;

            properties.GetValues("DEVICE", null, out deviceValues);

            List <string> storagesId = GetChildrenObjectIds(content, "DEVICE"); //获取存储卡设备

            //asyn.Advance(0, string.Format("获取到{0}个存储设备", storagesId.Count));

            foreach (string storageId in storagesId)
            {
                MTPFileNode deviceNode = new MTPFileNode()
                {
                    Type      = MTPFileNodeType.Device,
                    Name      = GetNameById(storageId, properties),
                    Id        = storageId,
                    Childrens = new List <MTPFileNode>(),
                    Parent    = root,
                    //Level = 0
                };
                root.Childrens.Add(deviceNode);
            }

            foreach (var parentNode in root.Childrens)
            {
                //asyn.Advance(0, string.Format(LanguageHelper.Get("LANGKEY_KaiShiHuoQuDeWenJianXiTong_00553"), parentNode.Name));

                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(10.0 / root.Childrens.Count / objectsId.Count, string.Format(LanguageHelper.Get("LANGKEY_HuoQuJieDian_00554"), fileNode.Name));

                        if (fileNode.Type != MTPFileNodeType.File)
                        {
                            CreateTree(fileNode, content, properties, asyn);
                        }
                    }
                }
            }

            return(root);
        }