2007-08-05 19:48:04 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007 by 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.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2008-10-12 19:21:58 +00:00
|
|
|
#include <QtCore>
|
2007-08-05 19:48:04 +00:00
|
|
|
#include "autodetection.h"
|
2009-05-09 16:59:14 +00:00
|
|
|
#include "rbsettings.h"
|
2010-01-24 21:12:11 +00:00
|
|
|
#include "systeminfo.h"
|
2007-08-05 19:48:04 +00:00
|
|
|
|
2008-10-15 18:37:26 +00:00
|
|
|
#include "../ipodpatcher/ipodpatcher.h"
|
|
|
|
#include "../sansapatcher/sansapatcher.h"
|
|
|
|
|
2008-12-13 10:09:13 +00:00
|
|
|
|
2009-08-10 19:46:51 +00:00
|
|
|
#include "system.h"
|
2008-06-29 09:50:20 +00:00
|
|
|
#include "utils.h"
|
2010-04-02 21:24:19 +00:00
|
|
|
#include "rockboxinfo.h"
|
2007-09-02 08:49:08 +00:00
|
|
|
|
2007-08-05 19:48:04 +00:00
|
|
|
Autodetection::Autodetection(QObject* parent): QObject(parent)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Autodetection::detect()
|
|
|
|
{
|
|
|
|
m_device = "";
|
|
|
|
m_mountpoint = "";
|
2007-09-14 20:52:38 +00:00
|
|
|
m_errdev = "";
|
|
|
|
|
|
|
|
detectUsb();
|
2007-08-30 19:08:25 +00:00
|
|
|
|
|
|
|
// Try detection via rockbox.info / rbutil.log
|
2011-07-17 08:08:58 +00:00
|
|
|
QStringList mounts = Utils::mountpoints();
|
2012-10-06 08:44:56 +00:00
|
|
|
qDebug() << "[Autodetect] paths to check:" << mounts;
|
2007-08-23 15:24:28 +00:00
|
|
|
|
2008-12-13 19:45:11 +00:00
|
|
|
for(int i=0; i< mounts.size();i++)
|
2007-08-05 19:48:04 +00:00
|
|
|
{
|
2007-08-30 19:08:25 +00:00
|
|
|
// do the file checking
|
2008-12-13 19:45:11 +00:00
|
|
|
QDir dir(mounts.at(i));
|
2007-08-05 19:48:04 +00:00
|
|
|
if(dir.exists())
|
|
|
|
{
|
2007-08-30 19:08:25 +00:00
|
|
|
// check logfile first.
|
2008-12-13 19:45:11 +00:00
|
|
|
if(QFile(mounts.at(i) + "/.rockbox/rbutil.log").exists()) {
|
|
|
|
QSettings log(mounts.at(i) + "/.rockbox/rbutil.log",
|
2007-08-30 19:08:25 +00:00
|
|
|
QSettings::IniFormat, this);
|
|
|
|
if(!log.value("platform").toString().isEmpty()) {
|
2007-09-14 20:52:38 +00:00
|
|
|
if(m_device.isEmpty())
|
|
|
|
m_device = log.value("platform").toString();
|
2008-12-13 19:45:11 +00:00
|
|
|
m_mountpoint = mounts.at(i);
|
2009-08-08 12:12:49 +00:00
|
|
|
qDebug() << "[Autodetect] rbutil.log detected:" << m_device << m_mountpoint;
|
2007-08-30 19:08:25 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// check rockbox-info.txt afterwards.
|
2009-03-21 16:30:40 +00:00
|
|
|
RockboxInfo info(mounts.at(i));
|
2009-08-10 19:20:53 +00:00
|
|
|
if(info.success())
|
2007-08-05 19:48:04 +00:00
|
|
|
{
|
2009-03-21 16:30:40 +00:00
|
|
|
if(m_device.isEmpty())
|
2007-08-05 19:48:04 +00:00
|
|
|
{
|
2009-03-21 16:30:40 +00:00
|
|
|
m_device = info.target();
|
2009-08-08 12:12:49 +00:00
|
|
|
}
|
2009-03-21 16:30:40 +00:00
|
|
|
m_mountpoint = mounts.at(i);
|
2009-08-08 12:12:49 +00:00
|
|
|
qDebug() << "[Autodetect] rockbox-info.txt detected:"
|
|
|
|
<< m_device << m_mountpoint;
|
2009-03-21 16:30:40 +00:00
|
|
|
return true;
|
2007-08-05 19:48:04 +00:00
|
|
|
}
|
2009-08-08 12:12:49 +00:00
|
|
|
|
2007-09-02 10:50:13 +00:00
|
|
|
// check for some specific files in root folder
|
2008-12-13 19:45:11 +00:00
|
|
|
QDir root(mounts.at(i));
|
2007-09-02 10:50:13 +00:00
|
|
|
QStringList rootentries = root.entryList(QDir::Files);
|
2007-09-02 12:20:44 +00:00
|
|
|
if(rootentries.contains("archos.mod", Qt::CaseInsensitive))
|
2007-09-02 10:50:13 +00:00
|
|
|
{
|
|
|
|
// archos.mod in root folder -> Archos Player
|
|
|
|
m_device = "player";
|
2008-12-13 19:45:11 +00:00
|
|
|
m_mountpoint = mounts.at(i);
|
2007-09-02 10:50:13 +00:00
|
|
|
return true;
|
|
|
|
}
|
2007-09-27 08:50:47 +00:00
|
|
|
if(rootentries.contains("ONDIOST.BIN", Qt::CaseInsensitive))
|
2007-09-02 10:50:13 +00:00
|
|
|
{
|
|
|
|
// ONDIOST.BIN in root -> Ondio FM
|
|
|
|
m_device = "ondiofm";
|
2008-12-13 19:45:11 +00:00
|
|
|
m_mountpoint = mounts.at(i);
|
2007-09-02 10:50:13 +00:00
|
|
|
return true;
|
|
|
|
}
|
2007-09-27 08:50:47 +00:00
|
|
|
if(rootentries.contains("ONDIOSP.BIN", Qt::CaseInsensitive))
|
2007-09-02 10:50:13 +00:00
|
|
|
{
|
|
|
|
// ONDIOSP.BIN in root -> Ondio SP
|
|
|
|
m_device = "ondiosp";
|
2008-12-13 19:45:11 +00:00
|
|
|
m_mountpoint = mounts.at(i);
|
2007-09-02 10:50:13 +00:00
|
|
|
return true;
|
|
|
|
}
|
2007-09-27 08:50:47 +00:00
|
|
|
if(rootentries.contains("ajbrec.ajz", Qt::CaseInsensitive))
|
2007-09-02 10:50:13 +00:00
|
|
|
{
|
2009-08-08 12:12:49 +00:00
|
|
|
qDebug() << "[Autodetect] ajbrec.ajz found. Trying detectAjbrec()";
|
2008-12-13 19:45:11 +00:00
|
|
|
if(detectAjbrec(mounts.at(i))) {
|
|
|
|
m_mountpoint = mounts.at(i);
|
2009-08-08 12:12:49 +00:00
|
|
|
qDebug() << "[Autodetect]" << m_device;
|
2007-09-27 08:50:47 +00:00
|
|
|
return true;
|
|
|
|
}
|
2007-09-02 10:50:13 +00:00
|
|
|
}
|
|
|
|
// detection based on player specific folders
|
2008-04-05 18:59:54 +00:00
|
|
|
QStringList rootfolders = root.entryList(QDir::Dirs
|
|
|
|
| QDir::NoDotAndDotDot | QDir::Hidden | QDir::System);
|
|
|
|
if(rootfolders.contains("GBSYSTEM", Qt::CaseInsensitive))
|
2007-09-02 10:50:13 +00:00
|
|
|
{
|
|
|
|
// GBSYSTEM folder -> Gigabeat
|
|
|
|
m_device = "gigabeatf";
|
2008-12-13 19:45:11 +00:00
|
|
|
m_mountpoint = mounts.at(i);
|
2007-09-02 10:50:13 +00:00
|
|
|
return true;
|
|
|
|
}
|
2008-03-20 20:29:17 +00:00
|
|
|
#if defined(Q_OS_WIN32)
|
|
|
|
// on windows, try to detect the drive letter of an Ipod
|
2008-04-05 18:59:54 +00:00
|
|
|
if(rootfolders.contains("iPod_Control", Qt::CaseInsensitive))
|
2008-03-20 20:29:17 +00:00
|
|
|
{
|
|
|
|
// iPod_Control folder -> Ipod found
|
|
|
|
// detecting of the Ipod type is done below using ipodpatcher
|
2008-12-13 19:45:11 +00:00
|
|
|
m_mountpoint = mounts.at(i);
|
2008-03-20 20:29:17 +00:00
|
|
|
}
|
|
|
|
#endif
|
2007-08-05 19:48:04 +00:00
|
|
|
}
|
2007-08-30 19:08:25 +00:00
|
|
|
|
2007-08-05 19:48:04 +00:00
|
|
|
}
|
2007-09-02 12:20:44 +00:00
|
|
|
|
2007-09-02 10:50:13 +00:00
|
|
|
int n;
|
2008-09-28 17:02:36 +00:00
|
|
|
// try ipodpatcher
|
|
|
|
// initialize sector buffer. Needed.
|
2007-08-23 15:24:28 +00:00
|
|
|
struct ipod_t ipod;
|
2012-12-23 22:30:57 +00:00
|
|
|
ipod.sectorbuf = NULL;
|
|
|
|
ipod_alloc_buffer(&ipod, BUFFER_SIZE);
|
2007-08-23 22:07:21 +00:00
|
|
|
n = ipod_scan(&ipod);
|
2007-08-23 15:24:28 +00:00
|
|
|
if(n == 1) {
|
2009-08-08 12:12:49 +00:00
|
|
|
qDebug() << "[Autodetect] Ipod found:" << ipod.modelstr << "at" << ipod.diskname;
|
2010-02-20 22:11:11 +00:00
|
|
|
// if the found ipod is a macpod also notice it as device with problem.
|
|
|
|
if(ipod.macpod)
|
|
|
|
m_errdev = ipod.targetname;
|
2007-08-23 15:24:28 +00:00
|
|
|
m_device = ipod.targetname;
|
2010-02-27 11:27:13 +00:00
|
|
|
// since resolveMountPoint is doing exact matches we need to select
|
|
|
|
// the correct partition.
|
|
|
|
QString mp(ipod.diskname);
|
|
|
|
#ifdef Q_OS_LINUX
|
|
|
|
mp.append("2");
|
|
|
|
#endif
|
|
|
|
#ifdef Q_OS_MACX
|
|
|
|
mp.append("s2");
|
|
|
|
#endif
|
2011-07-17 08:08:58 +00:00
|
|
|
m_mountpoint = Utils::resolveMountPoint(mp);
|
2007-08-23 15:24:28 +00:00
|
|
|
return true;
|
|
|
|
}
|
2008-06-29 09:50:20 +00:00
|
|
|
else {
|
2009-08-08 12:12:49 +00:00
|
|
|
qDebug() << "[Autodetect] ipodpatcher: no Ipod found." << n;
|
2008-06-29 09:50:20 +00:00
|
|
|
}
|
2013-01-01 10:04:21 +00:00
|
|
|
ipod_dealloc_buffer(&ipod);
|
2007-09-02 10:50:13 +00:00
|
|
|
|
2008-09-28 17:02:36 +00:00
|
|
|
// try sansapatcher
|
|
|
|
// initialize sector buffer. Needed.
|
2007-08-23 22:07:21 +00:00
|
|
|
struct sansa_t sansa;
|
2012-12-23 22:36:00 +00:00
|
|
|
sansa_alloc_buffer(&sansa, BUFFER_SIZE);
|
2007-08-23 22:07:21 +00:00
|
|
|
n = sansa_scan(&sansa);
|
|
|
|
if(n == 1) {
|
2009-08-08 12:12:49 +00:00
|
|
|
qDebug() << "[Autodetect] Sansa found:" << sansa.targetname << "at" << sansa.diskname;
|
2007-09-19 22:02:34 +00:00
|
|
|
m_device = QString("sansa%1").arg(sansa.targetname);
|
2010-02-27 11:27:13 +00:00
|
|
|
QString mp(sansa.diskname);
|
|
|
|
#ifdef Q_OS_LINUX
|
|
|
|
mp.append("1");
|
|
|
|
#endif
|
|
|
|
#ifdef Q_OS_MACX
|
|
|
|
mp.append("s1");
|
|
|
|
#endif
|
2011-07-17 08:08:58 +00:00
|
|
|
m_mountpoint = Utils::resolveMountPoint(mp);
|
2007-08-23 22:07:21 +00:00
|
|
|
return true;
|
|
|
|
}
|
2008-06-29 09:50:20 +00:00
|
|
|
else {
|
2009-08-08 12:12:49 +00:00
|
|
|
qDebug() << "[Autodetect] sansapatcher: no Sansa found." << n;
|
2008-06-29 09:50:20 +00:00
|
|
|
}
|
2013-01-01 12:23:47 +00:00
|
|
|
sansa_dealloc_buffer(&sansa);
|
2007-09-02 10:50:13 +00:00
|
|
|
|
2008-10-15 18:37:26 +00:00
|
|
|
if(m_mountpoint.isEmpty() && m_device.isEmpty()
|
|
|
|
&& m_errdev.isEmpty() && m_incompat.isEmpty())
|
2007-09-14 20:52:38 +00:00
|
|
|
return false;
|
|
|
|
return true;
|
2007-08-05 19:48:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-14 20:52:38 +00:00
|
|
|
/** @brief detect devices based on usb pid / vid.
|
|
|
|
* @return true upon success, false otherwise.
|
|
|
|
*/
|
|
|
|
bool Autodetection::detectUsb()
|
|
|
|
{
|
|
|
|
// usbids holds the mapping in the form
|
|
|
|
// ((VID<<16)|(PID)), targetname
|
|
|
|
// the ini file needs to hold the IDs as hex values.
|
2012-10-06 08:44:56 +00:00
|
|
|
QMap<int, QStringList> usbids = SystemInfo::usbIdMap(SystemInfo::MapDevice);
|
|
|
|
QMap<int, QStringList> usberror = SystemInfo::usbIdMap(SystemInfo::MapError);
|
|
|
|
QMap<int, QStringList> usbincompat = SystemInfo::usbIdMap(SystemInfo::MapIncompatible);
|
2007-09-14 20:52:38 +00:00
|
|
|
|
|
|
|
// usb pid detection
|
2008-06-21 10:28:10 +00:00
|
|
|
QList<uint32_t> attached;
|
2009-08-10 19:46:51 +00:00
|
|
|
attached = System::listUsbIds();
|
2008-06-21 10:28:10 +00:00
|
|
|
|
|
|
|
int i = attached.size();
|
|
|
|
while(i--) {
|
|
|
|
if(usbids.contains(attached.at(i))) {
|
2012-10-06 08:44:56 +00:00
|
|
|
m_device = usbids.value(attached.at(i)).at(0);
|
2008-06-21 10:28:10 +00:00
|
|
|
qDebug() << "[USB] detected supported player" << m_device;
|
|
|
|
return true;
|
2007-09-14 20:52:38 +00:00
|
|
|
}
|
2008-06-21 10:28:10 +00:00
|
|
|
if(usberror.contains(attached.at(i))) {
|
2012-10-06 08:44:56 +00:00
|
|
|
m_errdev = usberror.value(attached.at(i)).at(0);
|
2008-06-21 10:28:10 +00:00
|
|
|
qDebug() << "[USB] detected problem with player" << m_errdev;
|
|
|
|
return true;
|
2007-09-23 10:34:28 +00:00
|
|
|
}
|
2009-08-15 21:29:31 +00:00
|
|
|
QString idstring = QString("%1").arg(attached.at(i), 8, 16, QChar('0'));
|
2010-01-24 21:12:11 +00:00
|
|
|
if(!SystemInfo::platformValue(idstring, SystemInfo::CurName).toString().isEmpty()) {
|
2009-08-15 21:29:31 +00:00
|
|
|
m_incompat = idstring;
|
2008-06-21 10:28:10 +00:00
|
|
|
qDebug() << "[USB] detected incompatible player" << m_incompat;
|
|
|
|
return true;
|
2007-09-23 10:34:28 +00:00
|
|
|
}
|
|
|
|
}
|
2007-09-14 20:52:38 +00:00
|
|
|
return false;
|
|
|
|
}
|
2007-09-27 08:50:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
bool Autodetection::detectAjbrec(QString root)
|
|
|
|
{
|
|
|
|
QFile f(root + "/ajbrec.ajz");
|
|
|
|
char header[24];
|
|
|
|
f.open(QIODevice::ReadOnly);
|
|
|
|
if(!f.read(header, 24)) return false;
|
|
|
|
|
|
|
|
// check the header of the file.
|
|
|
|
// recorder v1 had a 6 bytes sized header
|
|
|
|
// recorder v2, FM, Ondio SP and FM have a 24 bytes header.
|
|
|
|
|
|
|
|
// recorder v1 has the binary length in the first 4 bytes, so check
|
|
|
|
// for them first.
|
|
|
|
int len = (header[0]<<24) | (header[1]<<16) | (header[2]<<8) | header[3];
|
2009-08-08 12:12:49 +00:00
|
|
|
qDebug() << "[Autodetect] ABJREC possible bin length:" << len
|
|
|
|
<< "file len:" << f.size();
|
2007-09-27 08:50:47 +00:00
|
|
|
if((f.size() - 6) == len)
|
|
|
|
m_device = "recorder";
|
2008-10-15 18:37:26 +00:00
|
|
|
|
2007-09-27 08:50:47 +00:00
|
|
|
// size didn't match, now we need to assume we have a headerlength of 24.
|
|
|
|
switch(header[11]) {
|
|
|
|
case 2:
|
|
|
|
m_device = "recorderv2";
|
|
|
|
break;
|
2008-10-15 18:37:26 +00:00
|
|
|
|
2007-09-27 08:50:47 +00:00
|
|
|
case 4:
|
|
|
|
m_device = "fmrecorder";
|
|
|
|
break;
|
2008-10-15 18:37:26 +00:00
|
|
|
|
2007-09-27 08:50:47 +00:00
|
|
|
case 8:
|
2007-09-27 18:01:12 +00:00
|
|
|
m_device = "ondiofm";
|
2007-09-27 08:50:47 +00:00
|
|
|
break;
|
2007-09-27 18:01:12 +00:00
|
|
|
|
2007-09-27 08:50:47 +00:00
|
|
|
case 16:
|
|
|
|
m_device = "ondiosp";
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
f.close();
|
2008-10-15 18:37:26 +00:00
|
|
|
|
2007-09-27 08:50:47 +00:00
|
|
|
if(m_device.isEmpty()) return false;
|
|
|
|
return true;
|
|
|
|
}
|
2008-10-15 18:37:26 +00:00
|
|
|
|