diff --git a/lib/driver/MSWindows/win32.c b/lib/driver/MSWindows/win32.c index bb30f502..db1ed25f 100644 --- a/lib/driver/MSWindows/win32.c +++ b/lib/driver/MSWindows/win32.c @@ -1,5 +1,5 @@ /* - $Id: win32.c,v 1.25 2005/03/07 00:55:31 rocky Exp $ + $Id: win32.c,v 1.26 2005/03/08 03:11:19 rocky Exp $ Copyright (C) 2003, 2004, 2005 Rocky Bernstein @@ -26,7 +26,7 @@ # include "config.h" #endif -static const char _rcsid[] = "$Id: win32.c,v 1.25 2005/03/07 00:55:31 rocky Exp $"; +static const char _rcsid[] = "$Id: win32.c,v 1.26 2005/03/08 03:11:19 rocky Exp $"; #include #include @@ -173,16 +173,6 @@ audio_stop_win32 ( void *p_user_data) } } -static driver_return_code_t -close_tray_win32 ( void *p_user_data) -{ - if ( WIN_NT ) { - return close_tray_win32ioctl (p_user_data); - } else { - return DRIVER_OP_UNSUPPORTED; /* not yet, but soon I hope */ - } -} - /* General ioctl() CD-ROM command function */ static bool _cdio_mciSendCommand(int id, UINT msg, DWORD flags, void *arg) @@ -552,6 +542,16 @@ read_toc_win32 (void *p_user_data) return ret; } +driver_return_code_t +close_tray_win32 ( const char *psz_win32_drive) +{ + if ( WIN_NT ) { + return close_tray_win32ioctl (psz_win32_drive); + } else { + return DRIVER_OP_UNSUPPORTED; /* not yet, but soon I hope */ + } +} + /*! Eject media. Return 1 if successful, 0 otherwise. */ @@ -856,7 +856,6 @@ cdio_open_am_win32 (const char *psz_orig_source, const char *psz_access_mode) _funcs.audio_resume = audio_resume_win32; _funcs.audio_set_volume = audio_set_volume_win32; _funcs.audio_stop = audio_stop_win32; - _funcs.close_tray = close_tray_win32; _funcs.eject_media = eject_media_win32; _funcs.free = free_win32; _funcs.get_arg = get_arg_win32; diff --git a/lib/driver/MSWindows/win32.h b/lib/driver/MSWindows/win32.h index bc47b2e4..0f7058c2 100644 --- a/lib/driver/MSWindows/win32.h +++ b/lib/driver/MSWindows/win32.h @@ -1,5 +1,5 @@ /* - $Id: win32.h,v 1.7 2005/03/07 00:55:31 rocky Exp $ + $Id: win32.h,v 1.8 2005/03/08 03:11:19 rocky Exp $ Copyright (C) 2004, 2005 Rocky Bernstein @@ -120,7 +120,7 @@ audio_set_volume_win32ioctl ( void *p_user_data, @param p_user_data the CD object to be acted upon. */ -driver_return_code_t close_tray_win32ioctl (void *p_user_data); +driver_return_code_t close_tray_win32ioctl (const char *psz_win32_drive); /*! Reads an audio device using the DeviceIoControl method into data diff --git a/lib/driver/MSWindows/win32_ioctl.c b/lib/driver/MSWindows/win32_ioctl.c index 850a8cdd..20b542e7 100644 --- a/lib/driver/MSWindows/win32_ioctl.c +++ b/lib/driver/MSWindows/win32_ioctl.c @@ -1,5 +1,5 @@ /* - $Id: win32_ioctl.c,v 1.20 2005/03/07 00:55:31 rocky Exp $ + $Id: win32_ioctl.c,v 1.21 2005/03/08 03:11:19 rocky Exp $ Copyright (C) 2004, 2005 Rocky Bernstein @@ -26,7 +26,7 @@ # include "config.h" #endif -static const char _rcsid[] = "$Id: win32_ioctl.c,v 1.20 2005/03/07 00:55:31 rocky Exp $"; +static const char _rcsid[] = "$Id: win32_ioctl.c,v 1.21 2005/03/08 03:11:19 rocky Exp $"; #ifdef HAVE_WIN32_CDROM @@ -360,15 +360,39 @@ audio_stop_win32ioctl (void *p_user_data) */ driver_return_code_t -close_tray_win32ioctl (void *p_user_data) +close_tray_win32ioctl (const char *psz_win32_drive) { - const _img_private_t *p_env = p_user_data; +#ifdef WIN32 DWORD dw_bytes_returned; + DWORD dw_access_flags; - bool b_success = - DeviceIoControl(p_env->h_device_handle, IOCTL_STORAGE_LOAD_MEDIA2, - NULL, (DWORD) 0, NULL, 0, &dw_bytes_returned, NULL); + OSVERSIONINFO ov; + HANDLE h_device_handle; + bool b_success; + + memset(&ov,0,sizeof(OSVERSIONINFO)); + ov.dwOSVersionInfoSize=sizeof(OSVERSIONINFO); + GetVersionEx(&ov); + + if((ov.dwPlatformId==VER_PLATFORM_WIN32_NT) && + (ov.dwMajorVersion>4)) + dw_access_flags = GENERIC_READ|GENERIC_WRITE; /* add gen write on W2k/XP */ + else dw_access_flags = GENERIC_READ; + h_device_handle = CreateFile( psz_win32_drive, + dw_access_flags, + FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, + OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, + NULL ); + b_success = + DeviceIoControl(h_device_handle, IOCTL_STORAGE_LOAD_MEDIA, + NULL, (DWORD) 0, NULL, 0, &dw_bytes_returned, NULL); + + + CloseHandle(h_device_handle); + if ( ! b_success ) { char *psz_msg = NULL; long int i_err = GetLastError(); @@ -381,6 +405,9 @@ close_tray_win32ioctl (void *p_user_data) return DRIVER_OP_ERROR; } return DRIVER_OP_SUCCESS; +#else + return DRIVER_OP_UNSUPPORTED; +#endif } /*! diff --git a/lib/driver/cdio_private.h b/lib/driver/cdio_private.h index 88c6cb8d..0d0e224b 100644 --- a/lib/driver/cdio_private.h +++ b/lib/driver/cdio_private.h @@ -1,5 +1,5 @@ /* - $Id: cdio_private.h,v 1.23 2005/03/07 07:23:52 rocky Exp $ + $Id: cdio_private.h,v 1.24 2005/03/08 03:11:19 rocky Exp $ Copyright (C) 2003, 2004, 2005 Rocky Bernstein @@ -474,6 +474,7 @@ extern "C" { unsigned int *i_drives); driver_return_code_t close_tray_linux (const char *psz_device); + driver_return_code_t close_tray_win32 (const char *psz_win32_drive); #ifdef __cplusplus diff --git a/lib/driver/device.c b/lib/driver/device.c index d76234ca..dbff8dd4 100644 --- a/lib/driver/device.c +++ b/lib/driver/device.c @@ -1,5 +1,5 @@ /* - $Id: device.c,v 1.15 2005/03/07 07:23:52 rocky Exp $ + $Id: device.c,v 1.16 2005/03/08 03:11:19 rocky Exp $ Copyright (C) 2005 Rocky Bernstein @@ -186,7 +186,7 @@ CdIo_driver_t CdIo_all_drivers[CDIO_MAX_DRIVER+1] = { &cdio_get_default_device_win32, &cdio_is_device_win32, &cdio_get_devices_win32, - NULL + &close_tray_win32 }, {DRIVER_CDRDAO, @@ -312,7 +312,7 @@ cdio_close_tray (const char *psz_device, /*in/out*/ driver_id_t *p_driver_id = CDIO_MIN_DEVICE_DRIVER; /* Scan for driver */ - for ( ; *p_driver_id<=CDIO_MAX_DRIVER; *p_driver_id++) { + for ( ; *p_driver_id<=CDIO_MAX_DRIVER; (*p_driver_id)++) { if ( (*CdIo_all_drivers[*p_driver_id].have_driver)() && *CdIo_all_drivers[*p_driver_id].close_tray ) { return (*CdIo_all_drivers[*p_driver_id].close_tray)(psz_device); diff --git a/src/cdda-player.c b/src/cdda-player.c index 52ef4fd2..e12f4c11 100644 --- a/src/cdda-player.c +++ b/src/cdda-player.c @@ -1,5 +1,5 @@ /* - $Id: cdda-player.c,v 1.1 2005/03/07 12:55:12 rocky Exp $ + $Id: cdda-player.c,v 1.2 2005/03/08 03:11:19 rocky Exp $ Copyright (C) 2005 Rocky Bernstein @@ -103,12 +103,15 @@ bool b_db = false; /* we have a database at all */ bool b_record = false; /* we have a record for the inserted CD */ -#define PLAY_CD 1 -#define PLAY_TRACK 2 -#define STOP_PLAYING 3 -#define EJECT_CD 4 -#define LIST_TRACKS 5 -#define PS_LIST_TRACKS 6 +typedef enum { + PLAY_CD=1, + PLAY_TRACK=2, + STOP_PLAYING=3, + EJECT_CD=4, + CLOSE_CD=5, + LIST_TRACKS=6, + PS_LIST_TRACKS=7 +} cd_operation_t; char *psz_device=NULL; char *psz_program; @@ -299,7 +302,7 @@ cd_eject(CdIo_t *p_cdio) } static void -cd_close(CdIo_t *p_cdio) +cd_close(const char *psz_device) { if (!b_cd) { action("close..."); @@ -388,7 +391,7 @@ play_track(track_t i_start_track, track_t i_end_track) char line[80]; if (!b_cd) { - cd_close(p_cdio); + cd_close(psz_device); read_toc(p_cdio); } @@ -1050,7 +1053,7 @@ main(int argc, char *argv[]) /* parse options */ while ( 1 ) { - if (-1 == (c = getopt(argc, argv, "xdhkvcpset:la"))) + if (-1 == (c = getopt(argc, argv, "xdhkvcCpset:la"))) break; switch (c) { case 'v': @@ -1085,6 +1088,10 @@ main(int argc, char *argv[]) interactive = 0; todo = LIST_TRACKS; break; + case 'C': + interactive = 0; + todo = CLOSE_CD; + break; case 'c': interactive = 0; todo = PS_LIST_TRACKS; @@ -1134,6 +1141,14 @@ main(int argc, char *argv[]) if (b_verbose) fprintf(stderr,"open %s... ", psz_device); + if (!interactive) { + b_sig = true; + nostop=1; + if (!b_cd && todo != EJECT_CD) { + cd_close(psz_device); + } + } + p_cdio = cdio_open (psz_device, driver_id); if (!p_cdio) { @@ -1157,7 +1172,7 @@ main(int argc, char *argv[]) nostop=1; read_toc(p_cdio); if (!b_cd && todo != EJECT_CD) { - cd_close(p_cdio); + cd_close(psz_device); read_toc(p_cdio); } if (b_cd || todo == EJECT_CD) { @@ -1225,7 +1240,7 @@ main(int argc, char *argv[]) break; case 'C': case 'c': - cd_close(p_cdio); + cd_close(psz_device); break; case ' ': case 'P':