コード例 #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 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);
        }