add a "help" entry to the about menu. For now this opens the system browser with...
[Rockbox.git] / rbutil / autodetection.cpp
blob85bfc21b114a672b2c297b6b202ab79da535b2e6
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * Module: rbutil
9 * File: autodetection.cpp
11 * Copyright (C) 2008 Dominik Wenger
13 * All files in this archive are subject to the GNU General Public License.
14 * See the file COPYING in the source tree root for full license agreement.
16 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
17 * KIND, either express or implied.
19 ****************************************************************************/
21 #include "autodetection.h"
22 #include "bootloaders.h"
23 /***************************************************
24 * General autodetection code
25 ****************************************************/
27 bool ipodpatcherDetect(UsbDeviceInfo* tempdevice)
29 /* use ipodpatcher for ipod detecting */
30 struct ipod_t ipod;
31 int n = ipod_scan(&ipod);
32 if(n == 1) /* we found an ipod */
34 wxString temp(ipod.targetname,wxConvUTF8);
35 int index = gv->plat_bootloadername.Index(temp); // use the bootloader names..
36 tempdevice->device_index = index;
37 tempdevice->status=DEVICEFOUND;
39 /* find mount point if possible */
40 #if !(defined( __WXMSW__ ) || defined( __DARWIN__)) //linux code
41 wxString tmp = resolve_mount_point(wxString(ipod.diskname,wxConvUTF8)+wxT("2"));
42 if( tmp != wxT("") )
43 tempdevice->path = tmp;
44 #endif
45 return true;
48 else if (n > 1) /* to many ipods */
50 tempdevice->status = TOMANYDEVICES;
51 return true;
53 else /* no ipod */
55 return false;
60 bool sansapatcherDetect(UsbDeviceInfo* tempdevice)
62 /* scann for sansas */
63 struct sansa_t sansa;
64 int n = sansa_scan(&sansa);
65 if(n==1)
67 tempdevice->device_index = gv->plat_id.Index(wxT("sansae200"));
68 tempdevice->status = DEVICEFOUND;
69 /* find mount point if possible */
70 #if !(defined( __WXMSW__ ) || defined( __DARWIN__)) //linux code
71 wxString tmp = resolve_mount_point(wxString(sansa.diskname,wxConvUTF8)+wxT("1"));
72 if( tmp != wxT("") )
73 tempdevice->path = tmp;
74 #endif
75 return true;
77 else if (n > 1)
79 tempdevice->status = TOMANYDEVICES;
80 return true;
82 else
84 return false;
89 bool rockboxinfoDetect(wxString filename,UsbDeviceInfo* tempdevice)
91 wxTextFile rockboxinfo(filename);
92 rockboxinfo.Open();
93 wxString line = rockboxinfo.GetFirstLine();
94 wxString targetstring;
95 if(line.StartsWith(wxT("Target: "), &targetstring))
97 int index = gv->plat_id.Index(targetstring);
98 if(index < 0) return false;
100 tempdevice->device_index = index;
101 wxString myPath;
102 if(filename.EndsWith(wxT(".rockbox" PATH_SEP "rockbox-info.txt"),&myPath));
103 tempdevice->path = myPath;
105 tempdevice->status = DEVICEFOUND;
107 return true;
109 else
111 return false;
118 bool detectDevices(UsbDeviceInfo* tempdevice)
120 tempdevice->device_index= 0;
121 tempdevice->path=wxT("");
122 tempdevice->status =NODEVICE;
124 /* try ipodpatcher */
125 if(ipodpatcherDetect(tempdevice))
127 return true;
130 /* try sansapatcher */
131 if(sansapatcherDetect(tempdevice))
133 return true;
136 /*try via files on the devices */
137 wxArrayString mountpoints = getPossibleMountPoints();
139 for(unsigned int i=0;i<mountpoints.GetCount();i++)
141 if(wxDir::Exists(mountpoints[i]))
143 /*check for rockbox-info.txt */
144 wxString filename;
145 filename.Printf("%s" PATH_SEP ".rockbox" PATH_SEP "rockbox-info.txt",mountpoints[i].c_str());
146 if(wxFile::Exists(filename))
148 if(rockboxinfoDetect(filename,tempdevice))
149 return true;
155 return false;
162 /***************************************************
163 * Windows code for autodetection
164 ****************************************************/
165 #if defined( __WXMSW__ )
167 wxArrayString getPossibleMountPoints()
169 wxArrayString tempList;
170 tempList.Add(wxT("D:\\"));
171 tempList.Add(wxT("E:\\"));
172 tempList.Add(wxT("F:\\"));
173 tempList.Add(wxT("G:\\"));
174 tempList.Add(wxT("H:\\"));
175 tempList.Add(wxT("I:\\"));
176 tempList.Add(wxT("J:\\"));
177 tempList.Add(wxT("K:\\"));
178 tempList.Add(wxT("L:\\"));
179 tempList.Add(wxT("M:\\"));
180 tempList.Add(wxT("N:\\"));
181 tempList.Add(wxT("O:\\"));
182 tempList.Add(wxT("P:\\"));
183 tempList.Add(wxT("Q:\\"));
184 tempList.Add(wxT("R:\\"));
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:\\"));
194 return tempList;
198 #endif /* windows code */
200 /**********************************************************
201 * Linux code for autodetection
202 *******************************************************/
203 #if !(defined( __WXMSW__ ) || defined( __DARWIN__))
205 wxArrayString getPossibleMountPoints()
207 wxArrayString tempList;
209 FILE *fp = fopen( "/proc/mounts", "r" );
210 if( !fp ) return tempList;
211 char *dev, *dir;
212 while( fscanf( fp, "%as %as %*s %*s %*s %*s", &dev, &dir ) != EOF )
214 wxString directory = wxString( dir, wxConvUTF8 );
215 tempList.Add(directory);
216 free( dev );
217 free( dir );
219 fclose( fp );
221 return tempList;
224 wxString resolve_mount_point( const wxString device )
226 FILE *fp = fopen( "/proc/mounts", "r" );
227 if( !fp ) return wxT("");
228 char *dev, *dir;
229 while( fscanf( fp, "%as %as %*s %*s %*s %*s", &dev, &dir ) != EOF )
231 if( wxString( dev, wxConvUTF8 ) == device )
233 wxString directory = wxString( dir, wxConvUTF8 );
234 free( dev );
235 free( dir );
236 return directory;
238 free( dev );
239 free( dir );
241 fclose( fp );
242 return wxT("");
247 #endif /* linux code */
249 /**********************************************************
250 * MAC code for autodetection
251 *******************************************************/
252 #if defined( __DARWIN__)
254 wxArrayString getPossibleMountPoints()
256 wxArrayString tempList;
258 wxDir volumes;
260 if(volumes.Open(wxT("/Volumes")))
262 wxString filename;
263 bool cont = volumes.GetFirst(&filename, wxEmptyString, wxDIR_DIRS);
264 while ( cont )
266 tempList.Add(filename);
267 cont = dir.GetNext(&filename);
270 return tempList;
274 #endif /* Mac Code */