Exemplo n.º 1
0
 public void SaveFile(PortableDevice device, PortableDeviceFile item)
 {
     if (ContainsCondition(item.Name))
     {
         device.DownloadFile((PortableDeviceFile)item, CPath);
     }
 }
Exemplo n.º 2
0
        public void DownloadFile(PortableDeviceFile file, string saveToPath)
        {
            IPortableDeviceContent content;

            this._device.Content(out content);

            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;

            try
            {
                resources.GetStream(file.Id, ref property, 0, ref optimalTransferSize, out wpdStream);

                System.Runtime.InteropServices.ComTypes.IStream sourceStream = (System.Runtime.InteropServices.ComTypes.IStream)wpdStream;

                var        filename     = Path.GetFileName(file.Name);
                FileStream targetStream = new FileStream(Path.Combine(saveToPath, filename), FileMode.Create, FileAccess.Write);

                unsafe
                {
                    var buffer = new byte[1024];
                    int bytesRead;
                    do
                    {
                        sourceStream.Read(buffer, 1024, new IntPtr(&bytesRead));
                        targetStream.Write(buffer, 0, 1024);
                    } while (bytesRead > 0);
                    targetStream.Close();
                }

                Marshal.ReleaseComObject(sourceStream);
                Marshal.ReleaseComObject(wpdStream);
            }
            catch
            {
                return;
            }
        }
Exemplo n.º 3
0
        public void DeleteFile(PortableDeviceFile file)
        {
            IPortableDeviceContent content;

            this._device.Content(out content);

            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);
        }