summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rbutil/autodetection.cpp299
-rw-r--r--rbutil/autodetection.h86
-rw-r--r--rbutil/rbutil.cbp2
-rw-r--r--rbutil/rbutilCtrls.cpp40
4 files changed, 208 insertions, 219 deletions
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 @@
24* General autodetection code 24* General autodetection code
25****************************************************/ 25****************************************************/
26 26
27 27bool ipodpatcherDetect(UsbDeviceInfo* tempdevice)
28UsbDeviceInfo detectDevicesViaPatchers()
29{ 28{
30 UsbDeviceInfo tempdevice; 29 /* use ipodpatcher for ipod detecting */
31 tempdevice.device_index= 0;
32 tempdevice.path=wxT("");
33 tempdevice.status =0;
34
35 /* scann for ipods */
36
37 struct ipod_t ipod; 30 struct ipod_t ipod;
38 int n = ipod_scan(&ipod); 31 int n = ipod_scan(&ipod);
39 if(n == 1) 32 if(n == 1) /* we found an ipod */
40 { 33 {
41 wxString temp(ipod.targetname,wxConvUTF8); 34 wxString temp(ipod.targetname,wxConvUTF8);
42 int index = gv->plat_bootloadername.Index(temp); // use the bootloader names.. 35 int index = gv->plat_bootloadername.Index(temp); // use the bootloader names..
43 tempdevice.device_index = index; 36 tempdevice->device_index = index;
37 tempdevice->status=DEVICEFOUND;
38
44 /* find mount point if possible */ 39 /* find mount point if possible */
45#if !(defined( __WXMSW__ ) || defined( __DARWIN__)) //linux code 40#if !(defined( __WXMSW__ ) || defined( __DARWIN__)) //linux code
46 wxString tmp = resolve_mount_point(wxString(ipod.diskname,wxConvUTF8)+wxT("2")); 41 wxString tmp = resolve_mount_point(wxString(ipod.diskname,wxConvUTF8)+wxT("2"));
47 if( tmp != wxT("") ) 42 if( tmp != wxT("") )
48 tempdevice.path = tmp; 43 tempdevice->path = tmp;
49#endif
50#if defined( __WXMSW__ ) //Windows code
51 wxString tmp = guess_mount_point();
52 if( tmp != wxT("") )
53 tempdevice.path = tmp;
54#endif 44#endif
55 return tempdevice; 45 return true;
46
56 } 47 }
57 else if (n > 1) 48 else if (n > 1) /* to many ipods */
49 {
50 tempdevice->status = TOMANYDEVICES;
51 return true;
52 }
53 else /* no ipod */
58 { 54 {
59 tempdevice.status = TOMANYDEVICES; 55 return false;
60 return tempdevice;
61 } 56 }
62 57
63 /* scann for sansas */ 58}
59
60bool sansapatcherDetect(UsbDeviceInfo* tempdevice)
61{
62 /* scann for sansas */
64 struct sansa_t sansa; 63 struct sansa_t sansa;
65 int n2 = sansa_scan(&sansa); 64 int n = sansa_scan(&sansa);
66 if(n2==1) 65 if(n==1)
67 { 66 {
68 tempdevice.device_index = gv->plat_id.Index(wxT("sansae200")); 67 tempdevice->device_index = gv->plat_id.Index(wxT("sansae200"));
68 tempdevice->status = DEVICEFOUND;
69 /* find mount point if possible */ 69 /* find mount point if possible */
70#if !(defined( __WXMSW__ ) || defined( __DARWIN__)) //linux code 70#if !(defined( __WXMSW__ ) || defined( __DARWIN__)) //linux code
71 wxString tmp = resolve_mount_point(wxString(ipod.diskname,wxConvUTF8)+wxT("1")); 71 wxString tmp = resolve_mount_point(wxString(ipod.diskname,wxConvUTF8)+wxT("1"));
72 if( tmp != wxT("") ) 72 if( tmp != wxT("") )
73 tempdevice.path = tmp; 73 tempdevice->path = tmp;
74#endif
75#if defined( __WXMSW__ ) // windows code
76 wxString tmp = guess_mount_point();
77 if( tmp != wxT("") )
78 tempdevice.path = tmp;
79#endif 74#endif
80 return tempdevice; 75 return true;
81 } 76 }
82 else if (n > 1) 77 else if (n > 1)
83 { 78 {
84 tempdevice.status = TOMANYDEVICES; 79 tempdevice->status = TOMANYDEVICES;
85 return tempdevice; 80 return true;
86 } 81 }
82 else
83 {
84 return false;
85 }
86}
87 87
88 88
89 tempdevice.status = NODEVICE; 89bool rockboxinfoDetect(wxString filename,UsbDeviceInfo* tempdevice)
90 return tempdevice; 90{
91 wxTextFile rockboxinfo(filename);
92 rockboxinfo.Open();
93 wxString line = rockboxinfo.GetFirstLine();
94 wxString targetstring;
95 if(line.StartsWith(wxT("Target: "), &targetstring))
96 {
97 int index = gv->plat_id.Index(targetstring);
98 if(index < 0) return false;
91 99
92} 100 tempdevice->device_index = index;
101 wxString myPath;
102 if(filename.EndsWith(wxT(".rockbox" PATH_SEP "rockbox-info.txt"),&myPath));
103 tempdevice->path = myPath;
93 104
105 tempdevice->status = DEVICEFOUND;
94 106
107 return true;
108 }
109 else
110 {
111 return false;
112 }
95 113
96 114
97/*************************************************** 115}
98* Windows code for autodetection 116
99****************************************************/
100#if defined( __WXMSW__ )
101 117
102wxString guess_mount_point() 118bool detectDevices(UsbDeviceInfo* tempdevice)
103{ 119{
104 wxString mountpoint = wxT(""); 120 tempdevice->device_index= 0;
105 TCHAR szDrvName[33]; 121 tempdevice->path=wxT("");
106 DWORD maxDriveSet, curDriveSet; 122 tempdevice->status =NODEVICE;
107 DWORD drive; 123
108 TCHAR szBuf[300]; 124 /* try ipodpatcher */
109 HANDLE hDevice; 125 if(ipodpatcherDetect(tempdevice))
110 PSTORAGE_DEVICE_DESCRIPTOR pDevDesc; 126 {
111 127 return true;
112 maxDriveSet = GetLogicalDrives(); 128 }
113 curDriveSet = maxDriveSet; 129
114 for ( drive = 0; drive < 32; ++drive ) 130 /* try sansapatcher */
115 { 131 if(sansapatcherDetect(tempdevice))
116 if ( maxDriveSet & (1 << drive) ) 132 {
117 { 133 return true;
118 DWORD temp = 1<<drive; 134 }
119 _stprintf( szDrvName, _T("%c:\\"), 'A'+drive ); 135
120 switch ( GetDriveType( szDrvName ) ) 136 /*try via files on the devices */
121 { 137 wxArrayString mountpoints = getPossibleMountPoints();
122 case 0: // The drive type cannot be determined. 138
123 case 1: // The root directory does not exist. 139 for(unsigned int i=0;i<mountpoints.GetCount();i++)
124 case DRIVE_CDROM: // The drive is a CD-ROM drive. 140 {
125 case DRIVE_REMOTE: // The drive is a remote (network) drive. 141 if(wxDir::Exists(mountpoints[i]))
126 case DRIVE_RAMDISK: // The drive is a RAM disk. 142 {
127 case DRIVE_REMOVABLE: // The drive can be removed from the drive. 143 /*check for rockbox-info.txt */
128 break; 144 wxString filename;
129 case DRIVE_FIXED: // The disk cannot be removed from the drive. 145 filename.Printf("%s" PATH_SEP ".rockbox" PATH_SEP "rockbox-info.txt",mountpoints[i].c_str());
130 sprintf(szBuf, "\\\\?\\%c:", 'A'+drive); 146 if(wxFile::Exists(filename))
131 hDevice = CreateFile(szBuf, GENERIC_READ, 147 {
132 FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, NULL, NULL); 148 if(rockboxinfoDetect(filename,tempdevice))
133 149 return true;
134 if (hDevice != INVALID_HANDLE_VALUE) 150 }
135 {
136 pDevDesc = (PSTORAGE_DEVICE_DESCRIPTOR)new BYTE[sizeof(STORAGE_DEVICE_DESCRIPTOR) + 512 - 1];
137 pDevDesc->Size = sizeof(STORAGE_DEVICE_DESCRIPTOR) + 512 - 1;
138
139 if(GetDisksProperty(hDevice, pDevDesc))
140 {
141 if(pDevDesc->BusType == BusTypeUsb)
142 {
143 mountpoint.Printf(wxT("%c:\\"), chFirstDriveFromMask(temp));
144 }
145 }
146 delete pDevDesc;
147 CloseHandle(hDevice);
148 }
149 break;
150 }
151 }
152 }
153 return mountpoint;
154 151
152 }
153 }
154
155 return false;
155} 156}
156 157
157 158
158 159
159/**************************************************************************** 160
160* FUNCTION: GetDisksProperty(HANDLE hDevice, PSTORAGE_DEVICE_DESCRIPTOR pDevDesc) 161
161* PURPOSE: get the info of specified device 162/***************************************************
162*****************************************************************************/ 163* Windows code for autodetection
163BOOL GetDisksProperty(HANDLE hDevice, PSTORAGE_DEVICE_DESCRIPTOR pDevDesc) 164****************************************************/
165#if defined( __WXMSW__ )
166
167wxArrayString getPossibleMountPoints()
164{ 168{
165 STORAGE_PROPERTY_QUERY Query; // input param for query 169 wxArrayString tempList;
166 DWORD dwOutBytes; // IOCTL output length 170 tempList.Add(wxT("D:\\"));
167 BOOL bResult; // IOCTL return val 171 tempList.Add(wxT("E:\\"));
168 172 tempList.Add(wxT("F:\\"));
169 // specify the query type 173 tempList.Add(wxT("G:\\"));
170 Query.PropertyId = StorageDeviceProperty; 174 tempList.Add(wxT("H:\\"));
171 Query.QueryType = PropertyStandardQuery; 175 tempList.Add(wxT("I:\\"));
172 176 tempList.Add(wxT("J:\\"));
173 // Query using IOCTL_STORAGE_QUERY_PROPERTY 177 tempList.Add(wxT("K:\\"));
174 bResult = ::DeviceIoControl(hDevice, // device handle 178 tempList.Add(wxT("L:\\"));
175 IOCTL_STORAGE_QUERY_PROPERTY, // info of device property 179 tempList.Add(wxT("M:\\"));
176 &Query, sizeof(STORAGE_PROPERTY_QUERY), // input data buffer 180 tempList.Add(wxT("N:\\"));
177 pDevDesc, pDevDesc->Size, // output data buffer 181 tempList.Add(wxT("O:\\"));
178 &dwOutBytes, // out's length 182 tempList.Add(wxT("P:\\"));
179 (LPOVERLAPPED)NULL); 183 tempList.Add(wxT("Q:\\"));
180 184 tempList.Add(wxT("R:\\"));
181 return bResult; 185 tempList.Add(wxT("S:\\"));
186 tempList.Add(wxT("T:\\"));
187 tempList.Add(wxT("U:\\"));
188 tempList.Add(wxT("V:\\"));
189 tempList.Add(wxT("W:\\"));
190 tempList.Add(wxT("X:\\"));
191 tempList.Add(wxT("Y:\\"));
192 tempList.Add(wxT("Z:\\"));
193
194 return tempList;
182} 195}
183 196
184/*********************************************
185* Converts the driveMask to a drive letter
186*******************************************/
187char chFirstDriveFromMask (ULONG unitmask)
188{
189 197
190 char i;
191 for (i = 0; i < 26; ++i)
192 {
193 if (unitmask & 0x1)
194 break;
195 unitmask = unitmask >> 1;
196 }
197 return (i + 'A');
198}
199#endif /* windows code */ 198#endif /* windows code */
200 199
201/********************************************************** 200/**********************************************************
@@ -203,7 +202,22 @@ char chFirstDriveFromMask (ULONG unitmask)
203*******************************************************/ 202*******************************************************/
204#if !(defined( __WXMSW__ ) || defined( __DARWIN__)) 203#if !(defined( __WXMSW__ ) || defined( __DARWIN__))
205 204
205wxArrayString getPossibleMountPoints()
206{
207 wxArrayString tempList;
206 208
209 FILE *fp = fopen( "/proc/mounts", "r" );
210 if( !fp ) return wxT("");
211 char *dev, *dir;
212 while( fscanf( fp, "%as %as %*s %*s %*s %*s", &dev, &dir ) != EOF )
213 {
214 wxString directory = wxString( dir, wxConvUTF8 );
215 tempList.Add(directory);
216 free( dev );
217 free( dir );
218 }
219 fclose( fp );
220}
207 221
208wxString resolve_mount_point( const wxString device ) 222wxString resolve_mount_point( const wxString device )
209{ 223{
@@ -228,4 +242,31 @@ wxString resolve_mount_point( const wxString device )
228 242
229 243
230 244
231#endif 245#endif /* linux code */
246
247/**********************************************************
248* MAC code for autodetection
249*******************************************************/
250#if defined( __DARWIN__)
251
252wxArrayString getPossibleMountPoints()
253{
254 wxArrayString tempList;
255
256 wxDir volumes;
257
258 if(volumes.Open(wxT("/Volumes")))
259 {
260 wxString filename;
261 bool cont = volumes.GetFirst(&filename, wxEmptyString, wxDIR_DIRS);
262 while ( cont )
263 {
264 tempList.Add(filename);
265 cont = dir.GetNext(&filename);
266 }
267 }
268 return tempList;
269
270}
271
272#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 @@
29 29
30#define TOMANYDEVICES 2 30#define TOMANYDEVICES 2
31#define NODEVICE 1 31#define NODEVICE 1
32#define DEVICEFOUND 0
32 33
33struct UsbDeviceInfo 34struct UsbDeviceInfo
34{ 35{
@@ -37,87 +38,24 @@ struct UsbDeviceInfo
37 int status; 38 int status;
38}; 39};
39 40
40UsbDeviceInfo detectDevicesViaPatchers(); 41
42bool detectDevices(UsbDeviceInfo* tempdevice);
43
44wxArrayString getPossibleMountPoints(); /* this funktion has to be implemented for every OS
41 45
42 46
43/******************************** 47/********************************
44* Windows code for USB Device detection and information 48* Windows header for USB Device detection and information
45**************************************/ 49**************************************/
46 50
47#if defined( __WXMSW__ ) 51#if defined( __WXMSW__ )
48 52
49#include <dbt.h> // For DeviceChange.
50#include <winioctl.h> // For DeviceIOCtl.
51
52// IOCTL control code
53#define IOCTL_STORAGE_QUERY_PROPERTY CTL_CODE(IOCTL_STORAGE_BASE, 0x0500, METHOD_BUFFERED, FILE_ANY_ACCESS)
54
55//// The following structures all can find at MSDN.
56// enumeration type specifies the various types of storage buses
57typedef enum _STORAGE_BUS_TYPE {
58 BusTypeUnknown = 0x00,
59 BusTypeScsi,
60 BusTypeAtapi,
61 BusTypeAta,
62 BusType1394,
63 BusTypeSsa,
64 BusTypeFibre,
65 BusTypeUsb,
66 BusTypeRAID,
67 BusTypeMaxReserved = 0x7F
68} STORAGE_BUS_TYPE, *PSTORAGE_BUS_TYPE;
69// retrieve the storage device descriptor data for a device.
70typedef struct _STORAGE_DEVICE_DESCRIPTOR {
71 ULONG Version;
72 ULONG Size;
73 UCHAR DeviceType;
74 UCHAR DeviceTypeModifier;
75 BOOLEAN RemovableMedia;
76 BOOLEAN CommandQueueing;
77 ULONG VendorIdOffset;
78 ULONG ProductIdOffset;
79 ULONG ProductRevisionOffset;
80 ULONG SerialNumberOffset;
81 STORAGE_BUS_TYPE BusType;
82 ULONG RawPropertiesLength;
83 UCHAR RawDeviceProperties[1];
84
85} STORAGE_DEVICE_DESCRIPTOR, *PSTORAGE_DEVICE_DESCRIPTOR;
86// retrieve the properties of a storage device or adapter.
87typedef enum _STORAGE_QUERY_TYPE {
88 PropertyStandardQuery = 0,
89 PropertyExistsQuery,
90 PropertyMaskQuery,
91 PropertyQueryMaxDefined
92
93} STORAGE_QUERY_TYPE, *PSTORAGE_QUERY_TYPE;
94
95// retrieve the properties of a storage device or adapter.
96typedef enum _STORAGE_PROPERTY_ID {
97 StorageDeviceProperty = 0,
98 StorageAdapterProperty,
99 StorageDeviceIdProperty
100
101} STORAGE_PROPERTY_ID, *PSTORAGE_PROPERTY_ID;
102// retrieve the properties of a storage device or adapter.
103typedef struct _STORAGE_PROPERTY_QUERY {
104 STORAGE_PROPERTY_ID PropertyId;
105 STORAGE_QUERY_TYPE QueryType;
106 UCHAR AdditionalParameters[1];
107
108} STORAGE_PROPERTY_QUERY, *PSTORAGE_PROPERTY_QUERY;
109
110
111wxString guess_mount_point();
112
113BOOL GetDisksProperty(HANDLE hDevice, PSTORAGE_DEVICE_DESCRIPTOR pDevDesc);
114char chFirstDriveFromMask (ULONG unitmask);
115 53
116#endif /*__WXMSW__ */ 54#endif /*__WXMSW__ */
117 55
118 56
119/************************************************************************+ 57/************************************************************************+
120*Linux code for autodetection 58*Linux header for autodetection
121**************************************************************************/ 59**************************************************************************/
122 60
123 61
@@ -131,6 +69,16 @@ wxString resolve_mount_point( const wxString device );
131 69
132 70
133 71
72/************************************************************************+
73*MAc header for autodetection
74**************************************************************************/
75
76
77#if defined( __DARWIN__)
78
79
80
81#endif /* MAc Code */
134 82
135 83
136 84
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 @@
93 </Linker> 93 </Linker>
94 <Unit filename="Makefile" /> 94 <Unit filename="Makefile" />
95 <Unit filename="archos.ico" /> 95 <Unit filename="archos.ico" />
96 <Unit filename="autodetection.cpp" />
97 <Unit filename="autodetection.h" />
96 <Unit filename="bootloaders.cpp" /> 98 <Unit filename="bootloaders.cpp" />
97 <Unit filename="bootloaders.h" /> 99 <Unit filename="bootloaders.h" />
98 <Unit filename="copying.txt" /> 100 <Unit filename="copying.txt" />
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)
439 439
440void DeviceSelectorCtrl::AutoDetect() 440void DeviceSelectorCtrl::AutoDetect()
441{ 441{
442 UsbDeviceInfo device;
442 443
444 if(detectDevices(&device))
445 {
443 446
444 UsbDeviceInfo device = detectDevicesViaPatchers(); 447 if(device.status == DEVICEFOUND)
448 {
449 m_deviceCbx->SetValue(gv->plat_name[device.device_index]);
450 gv->curplat=gv->plat_id[device.device_index];
445 451
446 if( device.status == NODEVICE) 452 if(device.path != wxT(""))
447 { 453 {
448 WARN_DIALOG(wxT("No Device detected. (This function currently only works for Ipods and Sansas)."), 454 gv->curdestdir = device.path;
455 }
456 }
457 else if(device.status == TOMANYDEVICES)
458 {
459 WARN_DIALOG(wxT("More then one device detected, please connect only One"),
449 wxT("Detecting a Device")); 460 wxT("Detecting a Device"));
450 return; 461 return;
462 }
451 } 463 }
452 464 else
453 if( device.status == TOMANYDEVICES)
454 { 465 {
455 WARN_DIALOG(wxT("More then one device detected, please connect only One"), 466 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)."),
456 wxT("Detecting a Device")); 467 wxT("Detecting a Device"));
457 return; 468 return;
458
459 }
460
461 if (device.status == 0 ) /* everything is ok */
462 {
463 m_deviceCbx->SetValue(gv->plat_name[device.device_index]);
464 gv->curplat=gv->plat_id[device.device_index];
465
466 if(device.path != wxT(""))
467 {
468 gv->curdestdir = device.path;
469 }
470
471 } 469 }
472 470
473} 471}