/*************************************************************************** * __________ __ ___. * Open \______ \ ____ ____ | | _\_ |__ _______ ___ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ * \/ \/ \/ \/ \/ * Module: rbutil * File: autodetection.cpp * * Copyright (C) 2008 Dominik Wenger * * All files in this archive are subject to the GNU General Public License. * See the file COPYING in the source tree root for full license agreement. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * ****************************************************************************/ #include "autodetection.h" #include "bootloaders.h" /*************************************************** * General autodetection code ****************************************************/ bool ipodpatcherDetect(UsbDeviceInfo* tempdevice) { /* use ipodpatcher for ipod detecting */ struct ipod_t ipod; int n = ipod_scan(&ipod); if(n == 1) /* we found an ipod */ { wxString temp(ipod.targetname,wxConvUTF8); int index = gv->plat_bootloadername.Index(temp); // use the bootloader names.. tempdevice->device_index = index; tempdevice->status=DEVICEFOUND; /* find mount point if possible */ #if !(defined( __WXMSW__ ) || defined( __DARWIN__)) //linux code wxString tmp = resolve_mount_point(wxString(ipod.diskname,wxConvUTF8)+wxT("2")); if( tmp != wxT("") ) tempdevice->path = tmp; #endif return true; } else if (n > 1) /* to many ipods */ { tempdevice->status = TOMANYDEVICES; return true; } else /* no ipod */ { return false; } } bool sansapatcherDetect(UsbDeviceInfo* tempdevice) { /* scann for sansas */ struct sansa_t sansa; int n = sansa_scan(&sansa); if(n==1) { tempdevice->device_index = gv->plat_id.Index(wxT("sansae200")); tempdevice->status = DEVICEFOUND; /* find mount point if possible */ #if !(defined( __WXMSW__ ) || defined( __DARWIN__)) //linux code wxString tmp = resolve_mount_point(wxString(sansa.diskname,wxConvUTF8)+wxT("1")); if( tmp != wxT("") ) tempdevice->path = tmp; #endif return true; } else if (n > 1) { tempdevice->status = TOMANYDEVICES; return true; } else { return false; } } bool rockboxinfoDetect(wxString filename,UsbDeviceInfo* tempdevice) { wxTextFile rockboxinfo(filename); rockboxinfo.Open(); wxString line = rockboxinfo.GetFirstLine(); wxString targetstring; if(line.StartsWith(wxT("Target: "), &targetstring)) { int index = gv->plat_id.Index(targetstring); if(index < 0) return false; tempdevice->device_index = index; wxString myPath; if(filename.EndsWith(wxT(".rockbox" PATH_SEP "rockbox-info.txt"),&myPath)); tempdevice->path = myPath; tempdevice->status = DEVICEFOUND; return true; } else { return false; } } bool detectDevices(UsbDeviceInfo* tempdevice) { tempdevice->device_index= 0; tempdevice->path=wxT(""); tempdevice->status =NODEVICE; /* try ipodpatcher */ if(ipodpatcherDetect(tempdevice)) { return true; } /* try sansapatcher */ if(sansapatcherDetect(tempdevice)) { return true; } /*try via files on the devices */ wxArrayString mountpoints = getPossibleMountPoints(); for(unsigned int i=0;i