예제 #1
0
        /// <summary>
        /// Find and return device by description. Only return device which connected as MTP / PTP.
        /// </summary>
        /// <param name="deviceDescription">Device description</param>
        /// <returns></returns>
        public MediaDevice GetDevice(string deviceDescription)
        {
            MediaDevice ptrDevice = GetDevices().FirstOrDefault(x => x.Description == deviceDescription);

            if (ptrDevice == null)
            {
                return(null);
            }

            //Enumerate Directory to ensure Media Device in MTP or PTP Mode.
            //By default, Android device is connected as USB Charging only with no file access.
            ptrDevice.Connect();
            MediaDirectoryInfo rootInfo = ptrDevice.GetRootDirectory();

            try
            {
                var dirs = rootInfo.EnumerateDirectories();
                if (rootInfo.EnumerateDirectories().Count() > 0)
                {
                    return(ptrDevice);
                }
            }
            catch { ptrDevice.Dispose(); ptrDevice = null; }
            return(null);
        }
예제 #2
0
        /// <summary>
        /// Refreshes the state of the object.
        /// </summary>
        public virtual void Refresh()
        {
            ObjectProperties prop = this.device.GetProperties(this.id);

            Guid contentType = prop.ContentType;
            MediaFileAttributes attributes;
            string name;

            if (this.id == Item.RootId)
            {
                name       = this.device.DirectorySeparatorChar.ToString();
                attributes = MediaFileAttributes.Object;
            }
            else if (contentType == WPD.CONTENT_TYPE_FUNCTIONAL_OBJECT)
            {
                name       = prop.Name;
                attributes = MediaFileAttributes.Object;
            }
            else if (contentType == WPD.CONTENT_TYPE_FOLDER)
            {
                name       = prop.OriginalFileName;
                attributes = MediaFileAttributes.Directory;
            }
            else
            {
                name       = prop.OriginalFileName;
                attributes = MediaFileAttributes.Normal;
            }

            attributes |= prop.CanDelete ? MediaFileAttributes.CanDelete : 0;
            attributes |= prop.IsSystem ? MediaFileAttributes.System : 0;
            attributes |= prop.IsHidden ? MediaFileAttributes.Hidden : 0;
            attributes |= prop.IsDRMProtected ? MediaFileAttributes.DRMProtected : 0;

            this.Name          = name;
            this.Length        = prop.Size;
            this.CreationTime  = prop.DateCreated;
            this.LastWriteTime = prop.DateModified;
            this.DateAuthored  = prop.DateAuthored;
            this.Attributes    = attributes;
            this.parentId      = prop.ParentId;
            this.parent        = null; // create once if needed
            this.fullName      = null; // create once if needed
        }
예제 #3
0
 /// <summary>
 /// Gets the parent directory of a specified subdirectory.
 /// </summary>
 protected MediaDirectoryInfo GetParent()
 {
     return(this.parent ?? (string.IsNullOrEmpty(this.parentId) ? null : (this.parent = new MediaDirectoryInfo(this.device, this.parentId))));
 }