Пример #1
0
        //private int renameObject( string objectId, string newName )
        //    {
        //    int err = 0;

        //        CComPtr<IPortableDeviceValues> properties, values, results;
        //        IPortableDeviceValues propertyValues;

        //    err = CoCreateInstance( CLSID_PortableDeviceValues, NULL, CLSCTX_INPROC_SERVER, IID_IPortableDeviceValues, (VOID**) &properties );
        //    err = CoCreateInstance( CLSID_PortableDeviceValues, NULL, CLSCTX_INPROC_SERVER, IID_IPortableDeviceValues, (VOID**) &values );

        //    // Mount the command.
        //    err = properties->SetGuidValue( WPD_PROPERTY_COMMON_COMMAND_CATEGORY , WPD_COMMAND_OBJECT_PROPERTIES_SET.fmtid );
        //    err = properties->SetUnsignedIntegerValue( WPD_PROPERTY_COMMON_COMMAND_ID, WPD_COMMAND_OBJECT_PROPERTIES_SET.pid );

        //    // Set the values
        //    err = properties->SetStringValue( WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID, objectId );
        //    err = values->SetStringValue( WPD_OBJECT_ORIGINAL_FILE_NAME, newName );
        //    err = properties->SetIPortableDeviceValuesValue( WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_VALUES, values );
        //    err = device->SendCommand( 0, properties, &results );

        //    return err;
        //}



        // file size
        private long GetFileSize(string objectId)
        {
            long objSize = 0;
            IPortableDeviceContent content;

            this._device.Content(out content);
            // Get the properties of the object
            IPortableDeviceProperties properties;

            content.Properties(out properties);
            PortableDeviceObject currentObject = WrapObject(properties, objectId);

            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
                _tagpropertykey property = new _tagpropertykey();
                property.fmtid = new Guid("EF6B490D-5CD8-437A-AFFC-DA8B60EE4A3C");
                property.pid   = 11; //WPD_OBJECT_SIZE;
                values.GetSignedLargeIntegerValue(property, out objSize);
            }
            return(objSize);
        }
Пример #2
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)
                {
                    PortableDeviceObject currentObject = WrapObject(properties, objectId);
                    parent.Files.Add(currentObject);
                    if (currentObject is PortableDeviceFolder)
                    {
                        EnumerateContents(ref content, (PortableDeviceFolder)currentObject);
                    }
                }
            } while (fetched > 0);
        }
Пример #3
0
 //----------------------------------------------------------------------------------------------
 public static void DisplayObject(PortableDevice device, PortableDeviceObject portableDeviceObject)
 {
     Console.WriteLine(portableDeviceObject.Name);
     if (portableDeviceObject is PortableDeviceFolder)
     {
         DisplayFolderContents(device, (PortableDeviceFolder) portableDeviceObject);
     }
 }
Пример #4
0
 public static void DisplayResourceContents(PortableDeviceObject portableDeviceObject)
 {
     Console.WriteLine(portableDeviceObject.Name);
     if (portableDeviceObject is PortableDeviceFolder)
     {
         DisplayFolderContents((PortableDeviceFolder)portableDeviceObject);
     }
 }
Пример #5
0
 public static void DisplayObject(PortableDevice device, PortableDeviceObject portableDeviceObject)
 {
     Console.WriteLine("device: " + device.FriendlyName + "   " + portableDeviceObject.Name);
     if (portableDeviceObject is PortableDeviceFolder)
     {
         DisplayFolderContents(device, (PortableDeviceFolder)portableDeviceObject);
     }
 }
Пример #6
0
 public static void DisplayResourceContents(PortableDeviceObject portableDeviceObject)
 {
     Console.WriteLine(portableDeviceObject.Name);
     if (portableDeviceObject is PortableDeviceFolder)
     {
         DisplayFolderContents((PortableDeviceFolder) portableDeviceObject);
     }
 }
Пример #7
0
        /**
         * Copy test file to device.
         */
        public static String copyFromDevice(PortableDevice device)
        {
            String error = "";

            try
            {
                PortableDeviceFolder root   = device.Root;
                PortableDeviceObject result = root.FindDir(@"Phone\Android\data\test");
                if (null == result)
                {
                    // Perhaps it was a tablet instead of a phone?
                    result = root.FindDir(@"Tablet\Android\data\test");
                }

                // Did we find a the desired folder on the device?
                if (null == result)
                {
                    error = @"Dir Android\data not found!";
                }
                else if (result is PortableDeviceFolder)
                {
                    if (COPY_FOLDER)
                    {
                        // Copy a whole folder
                        ((PortableDeviceFolder)result).CopyFolderToPC(device, @"C:\Test\CopiedBackfromPhone");
                    }
                    else
                    {
                        // Or Copy a file
                        PortableDeviceFile file = ((PortableDeviceFolder)result).FindFile("foo.txt");
                        device.TransferContentFromDevice(file, @"C:\Test\CopiedBackfromPhone", "Copyfoo.txt");
                    }
                }
            }
            catch (Exception ex)
            {
                error = ex.Message;
            }

            return(error);
        }
Пример #8
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);
            }
        }
Пример #9
0
        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);
        }