2007-06-17 20:15:18 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* 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
|
|
|
|
****************************************************/
|
|
|
|
|
2007-06-22 18:53:27 +00:00
|
|
|
bool ipodpatcherDetect(UsbDeviceInfo* tempdevice)
|
2007-06-17 20:15:18 +00:00
|
|
|
{
|
2007-06-22 18:53:27 +00:00
|
|
|
/* use ipodpatcher for ipod detecting */
|
2007-06-17 20:15:18 +00:00
|
|
|
struct ipod_t ipod;
|
|
|
|
int n = ipod_scan(&ipod);
|
2007-06-22 18:53:27 +00:00
|
|
|
if(n == 1) /* we found an ipod */
|
2007-06-17 20:15:18 +00:00
|
|
|
{
|
|
|
|
wxString temp(ipod.targetname,wxConvUTF8);
|
|
|
|
int index = gv->plat_bootloadername.Index(temp); // use the bootloader names..
|
2007-06-22 18:53:27 +00:00
|
|
|
tempdevice->device_index = index;
|
|
|
|
tempdevice->status=DEVICEFOUND;
|
|
|
|
|
2007-06-17 20:15:18 +00:00
|
|
|
/* 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("") )
|
2007-06-22 18:53:27 +00:00
|
|
|
tempdevice->path = tmp;
|
2007-06-17 20:15:18 +00:00
|
|
|
#endif
|
2007-06-22 18:53:27 +00:00
|
|
|
return true;
|
|
|
|
|
2007-06-17 20:15:18 +00:00
|
|
|
}
|
2007-06-22 18:53:27 +00:00
|
|
|
else if (n > 1) /* to many ipods */
|
|
|
|
{
|
|
|
|
tempdevice->status = TOMANYDEVICES;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else /* no ipod */
|
2007-06-17 20:15:18 +00:00
|
|
|
{
|
2007-06-22 18:53:27 +00:00
|
|
|
return false;
|
2007-06-17 20:15:18 +00:00
|
|
|
}
|
|
|
|
|
2007-06-22 18:53:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool sansapatcherDetect(UsbDeviceInfo* tempdevice)
|
|
|
|
{
|
|
|
|
/* scann for sansas */
|
2007-06-17 20:15:18 +00:00
|
|
|
struct sansa_t sansa;
|
2007-06-22 18:53:27 +00:00
|
|
|
int n = sansa_scan(&sansa);
|
|
|
|
if(n==1)
|
2007-06-17 20:15:18 +00:00
|
|
|
{
|
2007-06-22 18:53:27 +00:00
|
|
|
tempdevice->device_index = gv->plat_id.Index(wxT("sansae200"));
|
|
|
|
tempdevice->status = DEVICEFOUND;
|
2007-06-17 20:15:18 +00:00
|
|
|
/* find mount point if possible */
|
|
|
|
#if !(defined( __WXMSW__ ) || defined( __DARWIN__)) //linux code
|
2007-06-22 19:05:09 +00:00
|
|
|
wxString tmp = resolve_mount_point(wxString(sansa.diskname,wxConvUTF8)+wxT("1"));
|
2007-06-17 20:15:18 +00:00
|
|
|
if( tmp != wxT("") )
|
2007-06-22 18:53:27 +00:00
|
|
|
tempdevice->path = tmp;
|
2007-06-17 20:15:18 +00:00
|
|
|
#endif
|
2007-06-22 18:53:27 +00:00
|
|
|
return true;
|
2007-06-17 20:15:18 +00:00
|
|
|
}
|
|
|
|
else if (n > 1)
|
|
|
|
{
|
2007-06-22 18:53:27 +00:00
|
|
|
tempdevice->status = TOMANYDEVICES;
|
|
|
|
return true;
|
2007-06-17 20:15:18 +00:00
|
|
|
}
|
2007-06-22 18:53:27 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2007-06-17 20:15:18 +00:00
|
|
|
|
|
|
|
|
2007-06-22 18:53:27 +00:00
|
|
|
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;
|
2007-06-17 20:15:18 +00:00
|
|
|
|
2007-06-22 18:53:27 +00:00
|
|
|
tempdevice->device_index = index;
|
|
|
|
wxString myPath;
|
|
|
|
if(filename.EndsWith(wxT(".rockbox" PATH_SEP "rockbox-info.txt"),&myPath));
|
|
|
|
tempdevice->path = myPath;
|
2007-06-17 20:15:18 +00:00
|
|
|
|
2007-06-22 18:53:27 +00:00
|
|
|
tempdevice->status = DEVICEFOUND;
|
2007-06-17 20:15:18 +00:00
|
|
|
|
2007-06-22 18:53:27 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2007-06-17 20:15:18 +00:00
|
|
|
|
|
|
|
|
2007-06-22 18:53:27 +00:00
|
|
|
}
|
|
|
|
|
2007-06-17 20:15:18 +00:00
|
|
|
|
2007-06-22 18:53:27 +00:00
|
|
|
bool detectDevices(UsbDeviceInfo* tempdevice)
|
2007-06-17 20:15:18 +00:00
|
|
|
{
|
2007-06-22 18:53:27 +00:00
|
|
|
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<mountpoints.GetCount();i++)
|
|
|
|
{
|
|
|
|
if(wxDir::Exists(mountpoints[i]))
|
|
|
|
{
|
|
|
|
/*check for rockbox-info.txt */
|
|
|
|
wxString filename;
|
|
|
|
filename.Printf("%s" PATH_SEP ".rockbox" PATH_SEP "rockbox-info.txt",mountpoints[i].c_str());
|
|
|
|
if(wxFile::Exists(filename))
|
|
|
|
{
|
|
|
|
if(rockboxinfoDetect(filename,tempdevice))
|
|
|
|
return true;
|
|
|
|
}
|
2007-06-17 20:15:18 +00:00
|
|
|
|
2007-06-22 18:53:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2007-06-17 20:15:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2007-06-22 18:53:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
/***************************************************
|
|
|
|
* Windows code for autodetection
|
|
|
|
****************************************************/
|
|
|
|
#if defined( __WXMSW__ )
|
|
|
|
|
|
|
|
wxArrayString getPossibleMountPoints()
|
2007-06-17 20:15:18 +00:00
|
|
|
{
|
2007-06-22 18:53:27 +00:00
|
|
|
wxArrayString tempList;
|
|
|
|
tempList.Add(wxT("D:\\"));
|
|
|
|
tempList.Add(wxT("E:\\"));
|
|
|
|
tempList.Add(wxT("F:\\"));
|
|
|
|
tempList.Add(wxT("G:\\"));
|
|
|
|
tempList.Add(wxT("H:\\"));
|
|
|
|
tempList.Add(wxT("I:\\"));
|
|
|
|
tempList.Add(wxT("J:\\"));
|
|
|
|
tempList.Add(wxT("K:\\"));
|
|
|
|
tempList.Add(wxT("L:\\"));
|
|
|
|
tempList.Add(wxT("M:\\"));
|
|
|
|
tempList.Add(wxT("N:\\"));
|
|
|
|
tempList.Add(wxT("O:\\"));
|
|
|
|
tempList.Add(wxT("P:\\"));
|
|
|
|
tempList.Add(wxT("Q:\\"));
|
|
|
|
tempList.Add(wxT("R:\\"));
|
|
|
|
tempList.Add(wxT("S:\\"));
|
|
|
|
tempList.Add(wxT("T:\\"));
|
|
|
|
tempList.Add(wxT("U:\\"));
|
|
|
|
tempList.Add(wxT("V:\\"));
|
|
|
|
tempList.Add(wxT("W:\\"));
|
|
|
|
tempList.Add(wxT("X:\\"));
|
|
|
|
tempList.Add(wxT("Y:\\"));
|
|
|
|
tempList.Add(wxT("Z:\\"));
|
|
|
|
|
|
|
|
return tempList;
|
2007-06-17 20:15:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* windows code */
|
|
|
|
|
|
|
|
/**********************************************************
|
|
|
|
* Linux code for autodetection
|
|
|
|
*******************************************************/
|
|
|
|
#if !(defined( __WXMSW__ ) || defined( __DARWIN__))
|
|
|
|
|
2007-06-22 18:53:27 +00:00
|
|
|
wxArrayString getPossibleMountPoints()
|
|
|
|
{
|
|
|
|
wxArrayString tempList;
|
2007-06-17 20:15:18 +00:00
|
|
|
|
2007-06-22 18:53:27 +00:00
|
|
|
FILE *fp = fopen( "/proc/mounts", "r" );
|
2007-06-22 19:09:00 +00:00
|
|
|
if( !fp ) return tempList;
|
2007-06-22 18:53:27 +00:00
|
|
|
char *dev, *dir;
|
|
|
|
while( fscanf( fp, "%as %as %*s %*s %*s %*s", &dev, &dir ) != EOF )
|
|
|
|
{
|
|
|
|
wxString directory = wxString( dir, wxConvUTF8 );
|
|
|
|
tempList.Add(directory);
|
|
|
|
free( dev );
|
|
|
|
free( dir );
|
|
|
|
}
|
|
|
|
fclose( fp );
|
2007-06-22 19:09:00 +00:00
|
|
|
|
|
|
|
return tempList;
|
2007-06-22 18:53:27 +00:00
|
|
|
}
|
2007-06-17 20:15:18 +00:00
|
|
|
|
|
|
|
wxString resolve_mount_point( const wxString device )
|
|
|
|
{
|
|
|
|
FILE *fp = fopen( "/proc/mounts", "r" );
|
|
|
|
if( !fp ) return wxT("");
|
|
|
|
char *dev, *dir;
|
|
|
|
while( fscanf( fp, "%as %as %*s %*s %*s %*s", &dev, &dir ) != EOF )
|
|
|
|
{
|
|
|
|
if( wxString( dev, wxConvUTF8 ) == device )
|
|
|
|
{
|
|
|
|
wxString directory = wxString( dir, wxConvUTF8 );
|
|
|
|
free( dev );
|
|
|
|
free( dir );
|
|
|
|
return directory;
|
|
|
|
}
|
|
|
|
free( dev );
|
|
|
|
free( dir );
|
|
|
|
}
|
|
|
|
fclose( fp );
|
|
|
|
return wxT("");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2007-06-22 18:53:27 +00:00
|
|
|
#endif /* linux code */
|
|
|
|
|
|
|
|
/**********************************************************
|
|
|
|
* MAC code for autodetection
|
|
|
|
*******************************************************/
|
|
|
|
#if defined( __DARWIN__)
|
|
|
|
|
|
|
|
wxArrayString getPossibleMountPoints()
|
|
|
|
{
|
|
|
|
wxArrayString tempList;
|
|
|
|
|
|
|
|
wxDir volumes;
|
|
|
|
|
|
|
|
if(volumes.Open(wxT("/Volumes")))
|
|
|
|
{
|
|
|
|
wxString filename;
|
|
|
|
bool cont = volumes.GetFirst(&filename, wxEmptyString, wxDIR_DIRS);
|
|
|
|
while ( cont )
|
|
|
|
{
|
|
|
|
tempList.Add(filename);
|
|
|
|
cont = dir.GetNext(&filename);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return tempList;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* Mac Code */
|