Beispiel #1
0
        public static bool IsDriveAudioCd(char driveLetter)
        {
            if (UnsafeCalls.GetDriveType(driveLetter.ToString() + ":") != UnsafeCalls.CdromDriveType)
            {
                return(false);
            }

            try
            {
                bool hasTracks = Directory.GetFiles(driveLetter.ToString() + ":\\", TrackCdaFiles).Length > 0;

                return(hasTracks);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
                return(false);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Creates instance if the reader for assigned CD drive.
        /// </summary>
        /// <param name="driveLetter">CD drive letter</param>
        public CdromReader(char driveLetter)
        {
            if (!Char.IsUpper(driveLetter))
            {
                throw new ArgumentException("Invalid drive letter");
            }
            uint driveType = UnsafeCalls.GetDriveType(driveLetter.ToString() + ":");

            if (driveType != UnsafeCalls.CdromDriveType)
            {
                throw new CdromUtilsException("Drive is not a CDROM");
            }

            this.driveLetter = driveLetter;

            hCd = UnsafeCalls.CreateFile(@"\\.\" + driveLetter.ToString() + ":",
                                         UnsafeCalls.GenericRead, UnsafeCalls.FileShareRead,
                                         IntPtr.Zero, UnsafeCalls.OpenExisting, 0, IntPtr.Zero);

            if (hCd.IsInvalid)
            {
                throw new Win32Exception(UnsafeCalls.GetLastError());
            }
        }