コード例 #1
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);
        }
コード例 #2
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);
        }
コード例 #3
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);
        }
コード例 #4
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);
        }
コード例 #5
0
ファイル: PortableDevice.cs プロジェクト: xuan2261/EMM
        private void EnumerateContents(ref IPortableDeviceContent content, ref IPortableDeviceProperties properties, PortableDeviceFolder parent, Queue <PortableDeviceObject> queue, int?depth, bool folderOnly = false)
        {
            content.EnumObjects(0, parent.Id, null, out IEnumPortableDeviceObjectIDs objectIDs);

            try
            {
                uint fetched = 0;
                do
                {
                    objectIDs.Next(1, out string nextObjectIDs, ref fetched);

                    if (fetched > 0)
                    {
                        var item = WrapObject(properties, nextObjectIDs);

                        if (!folderOnly || item.IsFolder)
                        {
                            parent.Files.Add(item);
                        }

                        if (depth == null || depth > 1)
                        {
                            queue.Enqueue(item);
                        }
                    }
                } while (fetched > 0);
            }
            finally
            {
                Marshal.ReleaseComObject(objectIDs);
            }
        }
コード例 #6
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);
        }
コード例 #7
0
        /// <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);
        }
コード例 #8
0
ファイル: WpdDevice.cs プロジェクト: jwelsch/MobileAccess
        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);
        }
コード例 #9
0
        public void FindChild(string parentId, int currentLevel)
        {
            EntryObject entry = new EntryObject();

            _hEntryManager.UpdateEntryProperties(parentId, ref entry);

            if (entry.Track >= 0 || (entry.Filename != null && entry.Filename.EndsWith(".")))
            {
                if (_sCurrentObjectId != parentId)
                {
                    _sCurrentObjectId = parentId;
                    _iCurrentLevel    = currentLevel;
                    _lEntryObjects.Add(entry);
                }
            }

            IEnumPortableDeviceObjectIDs deviceObjectIds;

            _hDeviceContent.EnumObjects(0, parentId, null, out deviceObjectIds);
            uint fetchedCount = 0;

            do
            {
                string objectId;
                deviceObjectIds.Next(1, out objectId, ref fetchedCount);

                if (fetchedCount > 0)
                {
                    FindChild(objectId, currentLevel + 1);
                }
            }while (fetchedCount > 0);
        }
コード例 #10
0
        /// <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);
        }
コード例 #11
0
        private void LoadDeviceItemsByThread(IPortableDeviceContent content)
        {
            UtilityHelper.Initial();

            // Enumerate the items contained by the current object
            IEnumPortableDeviceObjectIDs objectIds;

            content.EnumObjects(0, Id, null, out objectIds);

            //Get total item count, it is for progress.
            GetDeviceItemCount(Id, content);

            // Cycle through each device item and add it to the device items list.
            int  fCount  = 0;
            uint fetched = 9999;

            for (; fetched > 0;)
            {
                fetched = 0;
                string objectId;
                objectIds.Next(1, out objectId, ref fetched);

                // Check if anything was retrieved.

                if (fetched > 0)
                {
                    fCount++;
                    Console.WriteLine("Folder count: " + fCount);
                    if (IsInFolderList(objectId, content) == false)
                    {
                        UtilityHelper.LoadedItemCount++;
                        continue;
                    }

                    while (UtilityHelper.threadList.Count >= MAX_THREAD_COUNT)
                    {
                        Thread.Sleep(200);
                        Console.WriteLine("Sleep -- fCount is " + fCount);
                    }
                    Console.WriteLine("Start Task:" + fCount);
                    int  fNumber = fCount;
                    Task t       = new Task(() => GetItemsByThread(objectId, content, fNumber));
                    t.Start();
                    UtilityHelper.threadList.Add(t);
                }
            }
        }
コード例 #12
0
        private void GetDeviceItemCount(string parentID, IPortableDeviceContent content)
        {
            IEnumPortableDeviceObjectIDs objectIds;

            content.EnumObjects(0, parentID, null, out objectIds);
            uint   fe = 9999;
            string ob;

            UtilityHelper.RootItemCount = 0;
            for (; fe > 0;)
            {
                fe = 9999;
                objectIds.Next(1, out ob, ref fe);
                UtilityHelper.RootItemCount++;
            }
            UtilityHelper.RootItemCount--;
        }
コード例 #13
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);
        }
コード例 #14
0
        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);
        }
コード例 #15
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);
            }
        }
コード例 #16
0
        public void EnumerateFetchContent(string parentId, int currentLevel)
        {
            EntryObject entryObject = new EntryObject();

            UpdateEntryProperties(parentId, ref entryObject);

            if (entryObject.Track >= 0 || (entryObject.Filename != null && entryObject.Filename.EndsWith(".")))
            {
                FoundNewMusicEntryEvent(entryObject);
            }

            try
            {
                IEnumPortableDeviceObjectIDs deviceObjectIds;
                _hDeviceContent.EnumObjects(0, parentId, null, out deviceObjectIds);

                uint fetchedCount = 0;
                do
                {
                    string objectId;
                    deviceObjectIds.Next(1, out objectId, ref fetchedCount);

                    if (fetchedCount > 0)
                    {
                        EnumerateFetchContent(objectId, currentLevel + 1);

                        if (objectId == "RenderingInformation" || objectId == _hDevice.FriendlyName)
                        {
                            Console.WriteLine("Song fetching successfully completed.");
                            MessageBox.Show("Song fetching successfully completed.", "ZenseMe");
                            return;
                        }
                    }
                }while (fetchedCount > 0);
            }
            catch
            {
                Console.WriteLine("Your device is no longer connected?");
            }
        }
コード例 #17
0
        /// <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 = 9999;
            for(;fetched > 0;)
            {
                fetched = 0;
                string objectId;
                objectIds.Next(1, out objectId, ref fetched);

                // Check if anything was retrieved.

                if (fetched > 0)
                {
                    Item i = new Item(objectId, content);
                    if (i.ContentType.Type == WindowsPortableDeviceEnumerators.ContentType.FunctionalObject ||
                        i.ContentType.Type == WindowsPortableDeviceEnumerators.ContentType.Folder ||
                        i.ContentType.Type == WindowsPortableDeviceEnumerators.ContentType.Audio ||
                        i.ContentType.Type == WindowsPortableDeviceEnumerators.ContentType.Video ||
                        i.ContentType.Type == WindowsPortableDeviceEnumerators.ContentType.Image)
                    {
                        DeviceItems.Add(i);
                    }

                    if (i.ContentType.Type == WindowsPortableDeviceEnumerators.ContentType.Audio ||
                        i.ContentType.Type == WindowsPortableDeviceEnumerators.ContentType.Video ||
                        i.ContentType.Type == WindowsPortableDeviceEnumerators.ContentType.Image)
                    {
                        UtilityHelper.LoadedFileCount++;
                    }
                }
            } 
        }
コード例 #18
0
        /// <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);
        }
コード例 #19
0
ファイル: Program.cs プロジェクト: kaury/PodcastUtilities
        private static void EnumerateContent(string objectId, IPortableDeviceContent deviceContent, string indent)
        {
            const int numberOfObjects = 1;

            //var name = GetObjectName(deviceContent, objectId);
            //Console.WriteLine("{0}{1} : {2}", indent, objectId, name);

            Console.WriteLine("{0}{1}", indent, objectId);

            var properties = GetObjectProperties(deviceContent, objectId);

            foreach (var property in properties)
            {
                Console.WriteLine("{0}- {1}", indent, property);
            }

            indent += "  ";

            IEnumPortableDeviceObjectIDs objectIdEnumerator;

            deviceContent.EnumObjects(0, objectId, null, out objectIdEnumerator);

            uint numberReturned;

            do
            {
                numberReturned = 0;
                string childObjectId;
                objectIdEnumerator.Next(numberOfObjects, out childObjectId, ref numberReturned);

                if (numberReturned != 0)
                {
                    EnumerateContent(childObjectId, deviceContent, indent);
                }
            } while (numberReturned != 0);
        }
コード例 #20
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);
        }
コード例 #21
0
        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);
        }
コード例 #22
0
        /// <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;
        }