ref: 13b4e10ccb98348e3e4b170373d74fbc062d2a6d
parent: 0c4fd16c0e19b66ed0f3138fb2ceb8e063c8e8ad
author: Sam Hocevar <[email protected]>
date: Mon Aug 29 18:02:55 EDT 2005
* src/device.c: if the target is the empty string, attempt to autodetect the DVD drive instead of giving up.
--- a/src/device.c
+++ b/src/device.c
@@ -136,6 +136,69 @@
#endif
}
+void _dvdcss_check ( dvdcss_t dvdcss )
+{
+#if defined( WIN32 )
+ DWORD drives;
+ int i;
+#else
+ char *ppsz_devices[] = { "/dev/dvd", "/dev/cdrom", "/dev/hdc", NULL };
+ int i, i_fd;
+#endif
+
+ /* If the device name is non-null, return */
+ if( dvdcss->psz_device[0] )
+ {
+ return;
+ }
+
+#if defined( WIN32 )
+ drives = GetLogicalDrives();
+
+ for( i = 0; drives; i++ )
+ {
+ char psz_device[5];
+ DWORD cur = 1 << i;
+ UINT i_ret;
+
+ if( (drives & cur) == 0 )
+ {
+ continue;
+ }
+ drives &= ~cur;
+
+ sprintf( psz_device, "%c:\\", 'A' + i );
+ i_ret = GetDriveType( psz_device );
+ if( i_ret != DRIVE_CDROM )
+ {
+ continue;
+ }
+
+ /* FIXME: we want to differenciate between CD and DVD drives
+ * using DeviceIoControl() */
+ print_debug( dvdcss, "defaulting to drive `%s'", psz_device );
+ free( dvdcss->psz_device );
+ dvdcss->psz_device = strdup( psz_device );
+ return;
+ }
+#else
+ for( i = 0; ppsz_devices[i]; i++ )
+ {
+ i_fd = open( ppsz_devices[i], 0 );
+ if( i_fd != -1 )
+ {
+ print_debug( dvdcss, "defaulting to drive `%s'", ppsz_devices[i] );
+ close( i_fd );
+ free( dvdcss->psz_device );
+ dvdcss->psz_device = strdup( ppsz_devices[i] );
+ return;
+ }
+ }
+#endif
+
+ print_error( dvdcss, "could not find a suitable default drive" );
+}
+
int _dvdcss_open ( dvdcss_t dvdcss )
{
char const *psz_device = dvdcss->psz_device;
--- a/src/device.h
+++ b/src/device.h
@@ -2,7 +2,7 @@
* device.h: DVD device access
*****************************************************************************
* Copyright (C) 1998-2002 VideoLAN
- * $Id: device.h,v 1.7 2002/12/19 12:37:30 sam Exp $
+ * $Id$
*
* Authors: St�phane Borel <[email protected]>
* Samuel Hocevar <[email protected]>
@@ -44,9 +44,10 @@
/*****************************************************************************
* Device reading prototypes
*****************************************************************************/
-int _dvdcss_use_ioctls ( dvdcss_t );
-int _dvdcss_open ( dvdcss_t );
-int _dvdcss_close ( dvdcss_t );
+int _dvdcss_use_ioctls ( dvdcss_t );
+void _dvdcss_check ( dvdcss_t );
+int _dvdcss_open ( dvdcss_t );
+int _dvdcss_close ( dvdcss_t );
/*****************************************************************************
* Device reading prototypes, raw-device specific
--- a/src/libdvdcss.c
+++ b/src/libdvdcss.c
@@ -330,6 +330,7 @@
/*
* Open device
*/
+ _dvdcss_check( dvdcss );
i_ret = _dvdcss_open( dvdcss );
if( i_ret < 0 )
{