Example #1
0
        // Open CD Drive with Win32Functions
        public bool Open(char Drive)
        {
            Close();
            if (Win32Functions.GetDriveType(Drive + ":\\") == Win32Functions.DriveTypes.DRIVE_CDROM)
            {
                cdHandle = Win32Functions.CreateFile("\\\\.\\" + Drive + ':', Win32Functions.GENERIC_READ, Win32Functions.FILE_SHARE_READ | Win32Functions.FILE_SHARE_WRITE, IntPtr.Zero, Win32Functions.OPEN_EXISTING, 0, IntPtr.Zero);
                if ((int)cdHandle == -1)
                {
                    int errCode = Marshal.GetLastWin32Error();
                }
                if (((int)cdHandle != -1) && ((int)cdHandle != 0))
                {
                    /*Win32Functions.CDROM_SET_SPEED setSpeed = new Win32Functions.CDROM_SET_SPEED();
                     * setSpeed.RequestType = Win32Functions.CDROM_SPEED_REQUEST.CdromSetSpeed;
                     * setSpeed.RotationControl = Win32Functions.WRITE_ROTATION.CdromDefaultRotation;
                     * setSpeed.ReadSpeed = 0xffff;*/

                    Win32Functions.CDROM_SET_STREAMING setSpeed = new Win32Functions.CDROM_SET_STREAMING();
                    setSpeed.RequestType = Win32Functions.CDROM_SPEED_REQUEST.CdromSetStreaming;
                    if (Settings.Current.RecordSpeed == 0)
                    {
                        setSpeed.ReadSize = 0xffff;
                    }
                    else
                    {
                        setSpeed.ReadSize = (uint)((double)Settings.Current.RecordSpeed * 176400.0 / 1024.0);
                    }
                    setSpeed.ReadTime        = 1000; // in ms
                    setSpeed.WriteSize       = 0xffff;
                    setSpeed.WriteTime       = 1000;
                    setSpeed.StartLba        = 0xffffffff;
                    setSpeed.EndLba          = 0xffffffff;
                    setSpeed.RotationControl = Win32Functions.WRITE_ROTATION.CdromDefaultRotation;
                    setSpeed.RestoreDefaults = 0; //(byte)false;
                    setSpeed.SetExact        = 0; //false;
                    setSpeed.RandomAccess    = 0; //false;
                    setSpeed.Persistent      = 1; //true;

                    uint BytesRead = 0;
                    int  result    = Win32Functions.DeviceIoControl(cdHandle, Win32Functions.IOCTL_CDROM_SET_SPEED, setSpeed, (uint)Marshal.SizeOf(setSpeed), null, 0, ref BytesRead, IntPtr.Zero);

                    m_Drive              = Drive;
                    NotWnd               = new DeviceChangeNotificationWindow();
                    NotWnd.DeviceChange += new DeviceChangeEventHandler(NotWnd_DeviceChange);
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
Example #2
0
        public static char[] GetCDDriveLetters()
        {
            string res = "";

            for (char c = 'C'; c <= 'Z'; c++)
            {
                if (Win32Functions.GetDriveType(c + ":") == Win32Functions.DriveTypes.DRIVE_CDROM)
                {
                    res += c;
                }
            }
            return(res.ToCharArray());
        }
Example #3
0
 /// <summary>
 /// Open the CD drive door
 /// </summary>
 /// <returns>True on success</returns>
 public bool EjectCD()
 {
     TocValid = false;
     if (((int)cdHandle != -1) && ((int)cdHandle != 0))
     {
         uint Dummy = 0;
         return(Win32Functions.DeviceIoControl(cdHandle, Win32Functions.IOCTL_STORAGE_EJECT_MEDIA, IntPtr.Zero, 0, IntPtr.Zero, 0, ref Dummy, IntPtr.Zero) != 0);
     }
     else
     {
         return(false);
     }
 }
Example #4
0
 protected bool ReadTOC()
 {
     if (((int)cdHandle != -1) && ((int)cdHandle != 0))
     {
         uint BytesRead = 0;
         TocValid = Win32Functions.DeviceIoControl(cdHandle, Win32Functions.IOCTL_CDROM_READ_TOC, IntPtr.Zero, 0, Toc, (uint)Marshal.SizeOf(Toc), ref BytesRead, IntPtr.Zero) != 0;
     }
     else
     {
         TocValid = false;
     }
     return(TocValid);
 }
Example #5
0
 /// <summary>
 /// Unlock CD drive
 /// </summary>
 /// <returns>True on success</returns>
 public bool UnLockCD()
 {
     if (((int)cdHandle != -1) && ((int)cdHandle != 0))
     {
         uint Dummy = 0;
         Win32Functions.PREVENT_MEDIA_REMOVAL pmr = new Win32Functions.PREVENT_MEDIA_REMOVAL();
         pmr.PreventMediaRemoval = 0;
         return(Win32Functions.DeviceIoControl(cdHandle, Win32Functions.IOCTL_STORAGE_MEDIA_REMOVAL, pmr, (uint)Marshal.SizeOf(pmr), IntPtr.Zero, 0, ref Dummy, IntPtr.Zero) != 0);
     }
     else
     {
         return(false);
     }
 }
Example #6
0
 public void Close()
 {
     UnLockCD();
     if (NotWnd != null)
     {
         NotWnd.DestroyHandle();
         NotWnd = null;
     }
     if (((int)cdHandle != -1) && ((int)cdHandle != 0))
     {
         Win32Functions.CloseHandle(cdHandle);
     }
     cdHandle = IntPtr.Zero;
     m_Drive  = '\0';
     TocValid = false;
 }
Example #7
0
 /// <summary>
 /// Check if there is CD in the drive
 /// </summary>
 /// <returns>True on success</returns>
 public bool IsCDReady()
 {
     if (((int)cdHandle != -1) && ((int)cdHandle != 0))
     {
         uint Dummy = 0;
         if (Win32Functions.DeviceIoControl(cdHandle, Win32Functions.IOCTL_STORAGE_CHECK_VERIFY, IntPtr.Zero, 0, IntPtr.Zero, 0, ref Dummy, IntPtr.Zero) != 0)
         {
             return(true);
         }
         else
         {
             TocValid = false;
             return(false);
         }
     }
     else
     {
         TocValid = false;
         return(false);
     }
 }
Example #8
0
        /// <summary>
        /// Read Audio Sectors
        /// </summary>
        /// <param name="sector">The sector where to start to read</param>
        /// <param name="Buffer">The length must be at least CB_CDDASECTOR*Sectors bytes</param>
        /// <param name="NumSectors">Number of sectors to read</param>
        /// <returns>True on success</returns>
        protected bool ReadSector(int sector, byte[] Buffer, int NumSectors)
        {
            if (TocValid && ((sector + NumSectors) <= GetEndSector(Toc.LastTrack)) && (Buffer.Length >= CB_AUDIO * NumSectors))
            {
                Win32Functions.RAW_READ_INFO rri = new Win32Functions.RAW_READ_INFO();
                rri.TrackMode   = Win32Functions.TRACK_MODE_TYPE.CDDA;
                rri.SectorCount = (uint)NumSectors;
                rri.DiskOffset  = sector * CB_CDROMSECTOR;

                uint BytesRead = 0;
                if (Win32Functions.DeviceIoControl(cdHandle, Win32Functions.IOCTL_CDROM_RAW_READ, rri, (uint)Marshal.SizeOf(rri), Buffer, (uint)NumSectors * CB_AUDIO, ref BytesRead, IntPtr.Zero) != 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }