From 69241529ffa4b45b3ebf408e4ed81b6a4142728f Mon Sep 17 00:00:00 2001 From: Dominik Wenger Date: Fri, 22 Jun 2007 18:53:27 +0000 Subject: rbutil: reworked device detection, now uses rockbox-info.txt and the patchers to detect the device. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@13687 a1c6a512-1295-4272-9138-f99709370657 --- rbutil/autodetection.cpp | 299 +++++++++++++++++++++++++++-------------------- rbutil/autodetection.h | 86 +++----------- rbutil/rbutil.cbp | 2 + rbutil/rbutilCtrls.cpp | 40 +++---- 4 files changed, 208 insertions(+), 219 deletions(-) (limited to 'rbutil') diff --git a/rbutil/autodetection.cpp b/rbutil/autodetection.cpp index 1d85d961b9..53469ff91b 100644 --- a/rbutil/autodetection.cpp +++ b/rbutil/autodetection.cpp @@ -24,178 +24,177 @@ * General autodetection code ****************************************************/ - -UsbDeviceInfo detectDevicesViaPatchers() +bool ipodpatcherDetect(UsbDeviceInfo* tempdevice) { - UsbDeviceInfo tempdevice; - tempdevice.device_index= 0; - tempdevice.path=wxT(""); - tempdevice.status =0; - - /* scann for ipods */ - + /* use ipodpatcher for ipod detecting */ struct ipod_t ipod; int n = ipod_scan(&ipod); - if(n == 1) + if(n == 1) /* we found an ipod */ { wxString temp(ipod.targetname,wxConvUTF8); int index = gv->plat_bootloadername.Index(temp); // use the bootloader names.. - tempdevice.device_index = index; + tempdevice->device_index = index; + tempdevice->status=DEVICEFOUND; + /* find mount point if possible */ #if !(defined( __WXMSW__ ) || defined( __DARWIN__)) //linux code wxString tmp = resolve_mount_point(wxString(ipod.diskname,wxConvUTF8)+wxT("2")); if( tmp != wxT("") ) - tempdevice.path = tmp; -#endif -#if defined( __WXMSW__ ) //Windows code - wxString tmp = guess_mount_point(); - if( tmp != wxT("") ) - tempdevice.path = tmp; + tempdevice->path = tmp; #endif - return tempdevice; + return true; + } - else if (n > 1) + else if (n > 1) /* to many ipods */ + { + tempdevice->status = TOMANYDEVICES; + return true; + } + else /* no ipod */ { - tempdevice.status = TOMANYDEVICES; - return tempdevice; + return false; } - /* scann for sansas */ +} + +bool sansapatcherDetect(UsbDeviceInfo* tempdevice) +{ + /* scann for sansas */ struct sansa_t sansa; - int n2 = sansa_scan(&sansa); - if(n2==1) + int n = sansa_scan(&sansa); + if(n==1) { - tempdevice.device_index = gv->plat_id.Index(wxT("sansae200")); + tempdevice->device_index = gv->plat_id.Index(wxT("sansae200")); + tempdevice->status = DEVICEFOUND; /* find mount point if possible */ #if !(defined( __WXMSW__ ) || defined( __DARWIN__)) //linux code wxString tmp = resolve_mount_point(wxString(ipod.diskname,wxConvUTF8)+wxT("1")); if( tmp != wxT("") ) - tempdevice.path = tmp; -#endif -#if defined( __WXMSW__ ) // windows code - wxString tmp = guess_mount_point(); - if( tmp != wxT("") ) - tempdevice.path = tmp; + tempdevice->path = tmp; #endif - return tempdevice; + return true; } else if (n > 1) { - tempdevice.status = TOMANYDEVICES; - return tempdevice; + tempdevice->status = TOMANYDEVICES; + return true; } + else + { + return false; + } +} - tempdevice.status = NODEVICE; - return tempdevice; +bool rockboxinfoDetect(wxString filename,UsbDeviceInfo* tempdevice) +{ + wxTextFile rockboxinfo(filename); + rockboxinfo.Open(); + wxString line = rockboxinfo.GetFirstLine(); + wxString targetstring; + if(line.StartsWith(wxT("Target: "), &targetstring)) + { + int index = gv->plat_id.Index(targetstring); + if(index < 0) return false; -} + tempdevice->device_index = index; + wxString myPath; + if(filename.EndsWith(wxT(".rockbox" PATH_SEP "rockbox-info.txt"),&myPath)); + tempdevice->path = myPath; + tempdevice->status = DEVICEFOUND; + return true; + } + else + { + return false; + } -/*************************************************** -* Windows code for autodetection -****************************************************/ -#if defined( __WXMSW__ ) +} + -wxString guess_mount_point() +bool detectDevices(UsbDeviceInfo* tempdevice) { - wxString mountpoint = wxT(""); - TCHAR szDrvName[33]; - DWORD maxDriveSet, curDriveSet; - DWORD drive; - TCHAR szBuf[300]; - HANDLE hDevice; - PSTORAGE_DEVICE_DESCRIPTOR pDevDesc; - - maxDriveSet = GetLogicalDrives(); - curDriveSet = maxDriveSet; - for ( drive = 0; drive < 32; ++drive ) - { - if ( maxDriveSet & (1 << drive) ) - { - DWORD temp = 1<Size = sizeof(STORAGE_DEVICE_DESCRIPTOR) + 512 - 1; - - if(GetDisksProperty(hDevice, pDevDesc)) - { - if(pDevDesc->BusType == BusTypeUsb) - { - mountpoint.Printf(wxT("%c:\\"), chFirstDriveFromMask(temp)); - } - } - delete pDevDesc; - CloseHandle(hDevice); - } - break; - } - } - } - return mountpoint; + tempdevice->device_index= 0; + tempdevice->path=wxT(""); + tempdevice->status =NODEVICE; + + /* try ipodpatcher */ + if(ipodpatcherDetect(tempdevice)) + { + return true; + } + + /* try sansapatcher */ + if(sansapatcherDetect(tempdevice)) + { + return true; + } + + /*try via files on the devices */ + wxArrayString mountpoints = getPossibleMountPoints(); + + for(unsigned int i=0;iSize, // output data buffer - &dwOutBytes, // out's length - (LPOVERLAPPED)NULL); - - return bResult; + wxArrayString tempList; + tempList.Add(wxT("D:\\")); + tempList.Add(wxT("E:\\")); + tempList.Add(wxT("F:\\")); + tempList.Add(wxT("G:\\")); + tempList.Add(wxT("H:\\")); + tempList.Add(wxT("I:\\")); + tempList.Add(wxT("J:\\")); + tempList.Add(wxT("K:\\")); + tempList.Add(wxT("L:\\")); + tempList.Add(wxT("M:\\")); + tempList.Add(wxT("N:\\")); + tempList.Add(wxT("O:\\")); + tempList.Add(wxT("P:\\")); + tempList.Add(wxT("Q:\\")); + tempList.Add(wxT("R:\\")); + tempList.Add(wxT("S:\\")); + tempList.Add(wxT("T:\\")); + tempList.Add(wxT("U:\\")); + tempList.Add(wxT("V:\\")); + tempList.Add(wxT("W:\\")); + tempList.Add(wxT("X:\\")); + tempList.Add(wxT("Y:\\")); + tempList.Add(wxT("Z:\\")); + + return tempList; } -/********************************************* -* Converts the driveMask to a drive letter -*******************************************/ -char chFirstDriveFromMask (ULONG unitmask) -{ - char i; - for (i = 0; i < 26; ++i) - { - if (unitmask & 0x1) - break; - unitmask = unitmask >> 1; - } - return (i + 'A'); -} #endif /* windows code */ /********************************************************** @@ -203,7 +202,22 @@ char chFirstDriveFromMask (ULONG unitmask) *******************************************************/ #if !(defined( __WXMSW__ ) || defined( __DARWIN__)) +wxArrayString getPossibleMountPoints() +{ + wxArrayString tempList; + FILE *fp = fopen( "/proc/mounts", "r" ); + if( !fp ) return wxT(""); + char *dev, *dir; + while( fscanf( fp, "%as %as %*s %*s %*s %*s", &dev, &dir ) != EOF ) + { + wxString directory = wxString( dir, wxConvUTF8 ); + tempList.Add(directory); + free( dev ); + free( dir ); + } + fclose( fp ); +} wxString resolve_mount_point( const wxString device ) { @@ -228,4 +242,31 @@ wxString resolve_mount_point( const wxString device ) -#endif +#endif /* linux code */ + +/********************************************************** +* MAC code for autodetection +*******************************************************/ +#if defined( __DARWIN__) + +wxArrayString getPossibleMountPoints() +{ + wxArrayString tempList; + + wxDir volumes; + + if(volumes.Open(wxT("/Volumes"))) + { + wxString filename; + bool cont = volumes.GetFirst(&filename, wxEmptyString, wxDIR_DIRS); + while ( cont ) + { + tempList.Add(filename); + cont = dir.GetNext(&filename); + } + } + return tempList; + +} + +#endif /* Mac Code */ diff --git a/rbutil/autodetection.h b/rbutil/autodetection.h index dc2d7d2490..a69b9e4bca 100644 --- a/rbutil/autodetection.h +++ b/rbutil/autodetection.h @@ -29,6 +29,7 @@ #define TOMANYDEVICES 2 #define NODEVICE 1 +#define DEVICEFOUND 0 struct UsbDeviceInfo { @@ -37,87 +38,24 @@ struct UsbDeviceInfo int status; }; -UsbDeviceInfo detectDevicesViaPatchers(); + +bool detectDevices(UsbDeviceInfo* tempdevice); + +wxArrayString getPossibleMountPoints(); /* this funktion has to be implemented for every OS /******************************** -* Windows code for USB Device detection and information +* Windows header for USB Device detection and information **************************************/ #if defined( __WXMSW__ ) -#include // For DeviceChange. -#include // For DeviceIOCtl. - -// IOCTL control code -#define IOCTL_STORAGE_QUERY_PROPERTY CTL_CODE(IOCTL_STORAGE_BASE, 0x0500, METHOD_BUFFERED, FILE_ANY_ACCESS) - -//// The following structures all can find at MSDN. -// enumeration type specifies the various types of storage buses -typedef enum _STORAGE_BUS_TYPE { - BusTypeUnknown = 0x00, - BusTypeScsi, - BusTypeAtapi, - BusTypeAta, - BusType1394, - BusTypeSsa, - BusTypeFibre, - BusTypeUsb, - BusTypeRAID, - BusTypeMaxReserved = 0x7F -} STORAGE_BUS_TYPE, *PSTORAGE_BUS_TYPE; -// retrieve the storage device descriptor data for a device. -typedef struct _STORAGE_DEVICE_DESCRIPTOR { - ULONG Version; - ULONG Size; - UCHAR DeviceType; - UCHAR DeviceTypeModifier; - BOOLEAN RemovableMedia; - BOOLEAN CommandQueueing; - ULONG VendorIdOffset; - ULONG ProductIdOffset; - ULONG ProductRevisionOffset; - ULONG SerialNumberOffset; - STORAGE_BUS_TYPE BusType; - ULONG RawPropertiesLength; - UCHAR RawDeviceProperties[1]; - -} STORAGE_DEVICE_DESCRIPTOR, *PSTORAGE_DEVICE_DESCRIPTOR; -// retrieve the properties of a storage device or adapter. -typedef enum _STORAGE_QUERY_TYPE { - PropertyStandardQuery = 0, - PropertyExistsQuery, - PropertyMaskQuery, - PropertyQueryMaxDefined - -} STORAGE_QUERY_TYPE, *PSTORAGE_QUERY_TYPE; - -// retrieve the properties of a storage device or adapter. -typedef enum _STORAGE_PROPERTY_ID { - StorageDeviceProperty = 0, - StorageAdapterProperty, - StorageDeviceIdProperty - -} STORAGE_PROPERTY_ID, *PSTORAGE_PROPERTY_ID; -// retrieve the properties of a storage device or adapter. -typedef struct _STORAGE_PROPERTY_QUERY { - STORAGE_PROPERTY_ID PropertyId; - STORAGE_QUERY_TYPE QueryType; - UCHAR AdditionalParameters[1]; - -} STORAGE_PROPERTY_QUERY, *PSTORAGE_PROPERTY_QUERY; - - -wxString guess_mount_point(); - -BOOL GetDisksProperty(HANDLE hDevice, PSTORAGE_DEVICE_DESCRIPTOR pDevDesc); -char chFirstDriveFromMask (ULONG unitmask); #endif /*__WXMSW__ */ /************************************************************************+ -*Linux code for autodetection +*Linux header for autodetection **************************************************************************/ @@ -131,6 +69,16 @@ wxString resolve_mount_point( const wxString device ); +/************************************************************************+ +*MAc header for autodetection +**************************************************************************/ + + +#if defined( __DARWIN__) + + + +#endif /* MAc Code */ diff --git a/rbutil/rbutil.cbp b/rbutil/rbutil.cbp index 55e4ea72b1..9351795977 100644 --- a/rbutil/rbutil.cbp +++ b/rbutil/rbutil.cbp @@ -93,6 +93,8 @@ + + diff --git a/rbutil/rbutilCtrls.cpp b/rbutil/rbutilCtrls.cpp index 887f2e7fb1..441d046ca8 100644 --- a/rbutil/rbutilCtrls.cpp +++ b/rbutil/rbutilCtrls.cpp @@ -439,35 +439,33 @@ void DeviceSelectorCtrl::OnAutoDetect(wxCommandEvent& event) void DeviceSelectorCtrl::AutoDetect() { + UsbDeviceInfo device; + if(detectDevices(&device)) + { - UsbDeviceInfo device = detectDevicesViaPatchers(); + if(device.status == DEVICEFOUND) + { + m_deviceCbx->SetValue(gv->plat_name[device.device_index]); + gv->curplat=gv->plat_id[device.device_index]; - if( device.status == NODEVICE) - { - WARN_DIALOG(wxT("No Device detected. (This function currently only works for Ipods and Sansas)."), + if(device.path != wxT("")) + { + gv->curdestdir = device.path; + } + } + else if(device.status == TOMANYDEVICES) + { + WARN_DIALOG(wxT("More then one device detected, please connect only One"), wxT("Detecting a Device")); - return; + return; + } } - - if( device.status == TOMANYDEVICES) + else { - WARN_DIALOG(wxT("More then one device detected, please connect only One"), + WARN_DIALOG(wxT("No Device detected. (This function only works if you have already installed rockbox or if you use a ipod or a sansa)."), wxT("Detecting a Device")); return; - - } - - if (device.status == 0 ) /* everything is ok */ - { - m_deviceCbx->SetValue(gv->plat_name[device.device_index]); - gv->curplat=gv->plat_id[device.device_index]; - - if(device.path != wxT("")) - { - gv->curdestdir = device.path; - } - } } -- cgit v1.2.3