1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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 */
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"));
43 tempdevice
->path
= tmp
;
48 else if (n
> 1) /* to many ipods */
50 tempdevice
->status
= TOMANYDEVICES
;
60 bool sansapatcherDetect(UsbDeviceInfo
* tempdevice
)
62 /* scann for sansas */
64 int n
= sansa_scan(&sansa
);
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"));
73 tempdevice
->path
= tmp
;
79 tempdevice
->status
= TOMANYDEVICES
;
89 bool rockboxinfoDetect(wxString filename
,UsbDeviceInfo
* tempdevice
)
91 wxTextFile
rockboxinfo(filename
);
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
;
102 if(filename
.EndsWith(wxT(".rockbox" PATH_SEP
"rockbox-info.txt"),&myPath
));
103 tempdevice
->path
= myPath
;
105 tempdevice
->status
= DEVICEFOUND
;
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
))
130 /* try sansapatcher */
131 if(sansapatcherDetect(tempdevice
))
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 */
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
))
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:\\"));
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
;
212 while( fscanf( fp
, "%as %as %*s %*s %*s %*s", &dev
, &dir
) != EOF
)
214 wxString directory
= wxString( dir
, wxConvUTF8
);
215 tempList
.Add(directory
);
224 wxString
resolve_mount_point( const wxString device
)
226 FILE *fp
= fopen( "/proc/mounts", "r" );
227 if( !fp
) return wxT("");
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
);
247 #endif /* linux code */
249 /**********************************************************
250 * MAC code for autodetection
251 *******************************************************/
252 #if defined( __DARWIN__)
254 wxArrayString
getPossibleMountPoints()
256 wxArrayString tempList
;
260 if(volumes
.Open(wxT("/Volumes")))
263 bool cont
= volumes
.GetFirst(&filename
, wxEmptyString
, wxDIR_DIRS
);
266 tempList
.Add(filename
);
267 cont
= dir
.GetNext(&filename
);
274 #endif /* Mac Code */