diff options
Diffstat (limited to 'rbutil/autodetection.cpp')
-rw-r--r-- | rbutil/autodetection.cpp | 274 |
1 files changed, 0 insertions, 274 deletions
diff --git a/rbutil/autodetection.cpp b/rbutil/autodetection.cpp deleted file mode 100644 index 85bfc21b11..0000000000 --- a/rbutil/autodetection.cpp +++ /dev/null | |||
@@ -1,274 +0,0 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * Module: rbutil | ||
9 | * File: autodetection.cpp | ||
10 | * | ||
11 | * Copyright (C) 2008 Dominik Wenger | ||
12 | * | ||
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. | ||
15 | * | ||
16 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
17 | * KIND, either express or implied. | ||
18 | * | ||
19 | ****************************************************************************/ | ||
20 | |||
21 | #include "autodetection.h" | ||
22 | #include "bootloaders.h" | ||
23 | /*************************************************** | ||
24 | * General autodetection code | ||
25 | ****************************************************/ | ||
26 | |||
27 | bool ipodpatcherDetect(UsbDeviceInfo* tempdevice) | ||
28 | { | ||
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 */ | ||
33 | { | ||
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; | ||
38 | |||
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; | ||
46 | |||
47 | } | ||
48 | else if (n > 1) /* to many ipods */ | ||
49 | { | ||
50 | tempdevice->status = TOMANYDEVICES; | ||
51 | return true; | ||
52 | } | ||
53 | else /* no ipod */ | ||
54 | { | ||
55 | return false; | ||
56 | } | ||
57 | |||
58 | } | ||
59 | |||
60 | bool sansapatcherDetect(UsbDeviceInfo* tempdevice) | ||
61 | { | ||
62 | /* scann for sansas */ | ||
63 | struct sansa_t sansa; | ||
64 | int n = sansa_scan(&sansa); | ||
65 | if(n==1) | ||
66 | { | ||
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; | ||
76 | } | ||
77 | else if (n > 1) | ||
78 | { | ||
79 | tempdevice->status = TOMANYDEVICES; | ||
80 | return true; | ||
81 | } | ||
82 | else | ||
83 | { | ||
84 | return false; | ||
85 | } | ||
86 | } | ||
87 | |||
88 | |||
89 | bool rockboxinfoDetect(wxString filename,UsbDeviceInfo* 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; | ||
99 | |||
100 | tempdevice->device_index = index; | ||
101 | wxString myPath; | ||
102 | if(filename.EndsWith(wxT(".rockbox" PATH_SEP "rockbox-info.txt"),&myPath)); | ||
103 | tempdevice->path = myPath; | ||
104 | |||
105 | tempdevice->status = DEVICEFOUND; | ||
106 | |||
107 | return true; | ||
108 | } | ||
109 | else | ||
110 | { | ||
111 | return false; | ||
112 | } | ||
113 | |||
114 | |||
115 | } | ||
116 | |||
117 | |||
118 | bool detectDevices(UsbDeviceInfo* tempdevice) | ||
119 | { | ||
120 | tempdevice->device_index= 0; | ||
121 | tempdevice->path=wxT(""); | ||
122 | tempdevice->status =NODEVICE; | ||
123 | |||
124 | /* try ipodpatcher */ | ||
125 | if(ipodpatcherDetect(tempdevice)) | ||
126 | { | ||
127 | return true; | ||
128 | } | ||
129 | |||
130 | /* try sansapatcher */ | ||
131 | if(sansapatcherDetect(tempdevice)) | ||
132 | { | ||
133 | return true; | ||
134 | } | ||
135 | |||
136 | /*try via files on the devices */ | ||
137 | wxArrayString mountpoints = getPossibleMountPoints(); | ||
138 | |||
139 | for(unsigned int i=0;i<mountpoints.GetCount();i++) | ||
140 | { | ||
141 | if(wxDir::Exists(mountpoints[i])) | ||
142 | { | ||
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)) | ||
147 | { | ||
148 | if(rockboxinfoDetect(filename,tempdevice)) | ||
149 | return true; | ||
150 | } | ||
151 | |||
152 | } | ||
153 | } | ||
154 | |||
155 | return false; | ||
156 | } | ||
157 | |||
158 | |||
159 | |||
160 | |||
161 | |||
162 | /*************************************************** | ||
163 | * Windows code for autodetection | ||
164 | ****************************************************/ | ||
165 | #if defined( __WXMSW__ ) | ||
166 | |||
167 | wxArrayString getPossibleMountPoints() | ||
168 | { | ||
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:\\")); | ||
193 | |||
194 | return tempList; | ||
195 | } | ||
196 | |||
197 | |||
198 | #endif /* windows code */ | ||
199 | |||
200 | /********************************************************** | ||
201 | * Linux code for autodetection | ||
202 | *******************************************************/ | ||
203 | #if !(defined( __WXMSW__ ) || defined( __DARWIN__)) | ||
204 | |||
205 | wxArrayString getPossibleMountPoints() | ||
206 | { | ||
207 | wxArrayString tempList; | ||
208 | |||
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 ) | ||
213 | { | ||
214 | wxString directory = wxString( dir, wxConvUTF8 ); | ||
215 | tempList.Add(directory); | ||
216 | free( dev ); | ||
217 | free( dir ); | ||
218 | } | ||
219 | fclose( fp ); | ||
220 | |||
221 | return tempList; | ||
222 | } | ||
223 | |||
224 | wxString resolve_mount_point( const wxString device ) | ||
225 | { | ||
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 ) | ||
230 | { | ||
231 | if( wxString( dev, wxConvUTF8 ) == device ) | ||
232 | { | ||
233 | wxString directory = wxString( dir, wxConvUTF8 ); | ||
234 | free( dev ); | ||
235 | free( dir ); | ||
236 | return directory; | ||
237 | } | ||
238 | free( dev ); | ||
239 | free( dir ); | ||
240 | } | ||
241 | fclose( fp ); | ||
242 | return wxT(""); | ||
243 | } | ||
244 | |||
245 | |||
246 | |||
247 | #endif /* linux code */ | ||
248 | |||
249 | /********************************************************** | ||
250 | * MAC code for autodetection | ||
251 | *******************************************************/ | ||
252 | #if defined( __DARWIN__) | ||
253 | |||
254 | wxArrayString getPossibleMountPoints() | ||
255 | { | ||
256 | wxArrayString tempList; | ||
257 | |||
258 | wxDir volumes; | ||
259 | |||
260 | if(volumes.Open(wxT("/Volumes"))) | ||
261 | { | ||
262 | wxString filename; | ||
263 | bool cont = volumes.GetFirst(&filename, wxEmptyString, wxDIR_DIRS); | ||
264 | while ( cont ) | ||
265 | { | ||
266 | tempList.Add(filename); | ||
267 | cont = dir.GetNext(&filename); | ||
268 | } | ||
269 | } | ||
270 | return tempList; | ||
271 | |||
272 | } | ||
273 | |||
274 | #endif /* Mac Code */ | ||