示例#1
0
        /// <summary>
        /// Checks if a mounted drive exists and the filesystem type is <see cref="DOKAN_FORMAT"/>.
        /// </summary>
        /// <param name="driveLetter">Letter of drive to check.</param>
        /// <returns><c>true</c>, if the drive with the given <paramref name="driveLetter"/> is a mounted Dokan drive, else <c>false</c>.</returns>
        public static bool IsDokanDrive(char driveLetter)
        {
            bool result = false;

            // Check if this drive was queried before
            if (_dokanDriveLetters.Contains(driveLetter))
            {
                return(true);
            }

            try
            {
                ThreadingUtils.CallWithTimeout(() =>
                {
                    // By checking the given drive's format, we'll find ALL Dokan drives, also those which are added by other MP2 instances (Client/Server), which is good, but we even
                    // find those which are not added to the system by MediaPortal at all, which is not so good.
                    // A better way would be to modify the drive format the DOKAN library uses for its drives. That way, we could use an own drive format type for MP2.
                    // But unfortunately, the drive format cannot be configured in the DOKAN library.
                    // It would be also possible to check the drive's volume label, but I think the check for the drive format is more elegant.
                    DriveInfo driveInfo = new DriveInfo(driveLetter + ":");
                    // Check the IsReady property to avoid DriveNotFoundException
                    result = driveInfo.IsReady && driveInfo.DriveFormat == DOKAN_FORMAT;
                }, DRIVE_TIMEOUT_MS);
            }
            catch (TimeoutException)
            {
                result = true;
            }
            // Cache information only for DOKAN drives, all other (also non-existing) needs to be checked again (i.e. for removable media)
            if (result)
            {
                _dokanDriveLetters.Add(driveLetter);
            }
            return(result);
        }