diff options
Diffstat (limited to 'rbutil/autodetection.cpp')
-rw-r--r-- | rbutil/autodetection.cpp | 299 |
1 files changed, 170 insertions, 129 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 | 27 | bool ipodpatcherDetect(UsbDeviceInfo* tempdevice) | |
28 | UsbDeviceInfo 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 | |||
60 | bool 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; | 89 | bool 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 | ||
102 | wxString guess_mount_point() | 118 | bool 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 |
163 | BOOL GetDisksProperty(HANDLE hDevice, PSTORAGE_DEVICE_DESCRIPTOR pDevDesc) | 164 | ****************************************************/ |
165 | #if defined( __WXMSW__ ) | ||
166 | |||
167 | wxArrayString 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 | *******************************************/ | ||
187 | char 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 | ||
205 | wxArrayString 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 | ||
208 | wxString resolve_mount_point( const wxString device ) | 222 | wxString 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 | |||
252 | wxArrayString 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 */ | ||