2007-08-05 19:48:04 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007 by Dominik Wenger
|
2007-08-23 22:11:50 +00:00
|
|
|
* $Id$
|
2007-08-05 19:48:04 +00:00
|
|
|
*
|
|
|
|
* 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"
|
|
|
|
|
2007-09-14 20:52:38 +00:00
|
|
|
#if defined(Q_OS_LINUX) || defined(Q_OS_MACX)
|
2007-09-02 08:49:08 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#endif
|
2007-09-29 12:15:31 +00:00
|
|
|
#if defined(Q_OS_LINUX)
|
|
|
|
#include <mntent.h>
|
|
|
|
#endif
|
2007-10-13 16:26:38 +00:00
|
|
|
#if defined(Q_OS_MACX)
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/ucred.h>
|
|
|
|
#include <sys/mount.h>
|
|
|
|
#endif
|
2007-09-23 10:34:28 +00:00
|
|
|
#if defined(Q_OS_WIN32)
|
|
|
|
#if defined(UNICODE)
|
|
|
|
#define _UNICODE
|
|
|
|
#endif
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <tchar.h>
|
|
|
|
#include <windows.h>
|
|
|
|
#include <setupapi.h>
|
2008-06-29 09:50:20 +00:00
|
|
|
#include <winioctl.h>
|
2007-09-23 10:34:28 +00:00
|
|
|
#endif
|
2008-12-13 10:09:13 +00:00
|
|
|
|
|
|
|
#if defined(Q_OS_OPENBSD)
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/mount.h>
|
|
|
|
#endif
|
|
|
|
|
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
|
2008-12-13 19:45:11 +00:00
|
|
|
QStringList mounts = mountpoints();
|
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));
|
2009-08-08 12:12:49 +00:00
|
|
|
qDebug() << "[Autodetect] paths to check:" << mounts;
|
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.
|
|
|
|
ipod_sectorbuf = NULL;
|
|
|
|
ipod_alloc_buffer(&ipod_sectorbuf, BUFFER_SIZE);
|
2007-08-23 15:24:28 +00:00
|
|
|
struct ipod_t ipod;
|
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
|
|
|
|
m_mountpoint = 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
|
|
|
}
|
2008-09-28 17:02:36 +00:00
|
|
|
free(ipod_sectorbuf);
|
|
|
|
ipod_sectorbuf = NULL;
|
2007-09-02 10:50:13 +00:00
|
|
|
|
2008-09-28 17:02:36 +00:00
|
|
|
// try sansapatcher
|
|
|
|
// initialize sector buffer. Needed.
|
|
|
|
sansa_sectorbuf = NULL;
|
|
|
|
sansa_alloc_buffer(&sansa_sectorbuf, BUFFER_SIZE);
|
2007-08-23 22:07:21 +00:00
|
|
|
struct sansa_t sansa;
|
|
|
|
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
|
|
|
|
m_mountpoint = 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
|
|
|
}
|
2008-09-28 17:02:36 +00:00
|
|
|
free(sansa_sectorbuf);
|
|
|
|
sansa_sectorbuf = NULL;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-12-13 19:45:11 +00:00
|
|
|
QStringList Autodetection::mountpoints()
|
2007-08-05 19:48:04 +00:00
|
|
|
{
|
|
|
|
QStringList tempList;
|
2007-10-13 16:26:38 +00:00
|
|
|
#if defined(Q_OS_WIN32)
|
2007-08-05 19:48:04 +00:00
|
|
|
QFileInfoList list = QDir::drives();
|
|
|
|
for(int i=0; i<list.size();i++)
|
|
|
|
{
|
|
|
|
tempList << list.at(i).absolutePath();
|
2010-04-25 21:22:36 +00:00
|
|
|
qDebug() << "[Autodetection] Mounted on" << list.at(i).absolutePath();
|
2007-08-05 19:48:04 +00:00
|
|
|
}
|
2007-09-15 22:57:07 +00:00
|
|
|
|
2008-12-13 10:09:13 +00:00
|
|
|
#elif defined(Q_OS_MACX) || defined(Q_OS_OPENBSD)
|
2007-10-13 16:26:38 +00:00
|
|
|
int num;
|
|
|
|
struct statfs *mntinf;
|
|
|
|
|
|
|
|
num = getmntinfo(&mntinf, MNT_WAIT);
|
|
|
|
while(num--) {
|
|
|
|
tempList << QString(mntinf->f_mntonname);
|
2010-04-25 21:22:36 +00:00
|
|
|
qDebug() << "[Autodetection] Mounted on" << mntinf->f_mntonname
|
|
|
|
<< "is" << mntinf->f_mntfromname << "type" << mntinf->f_fstypename;
|
2007-10-13 16:26:38 +00:00
|
|
|
mntinf++;
|
|
|
|
}
|
2007-08-05 22:13:40 +00:00
|
|
|
#elif defined(Q_OS_LINUX)
|
2007-08-05 19:48:04 +00:00
|
|
|
|
2007-09-02 09:36:28 +00:00
|
|
|
FILE *mn = setmntent("/etc/mtab", "r");
|
|
|
|
if(!mn)
|
|
|
|
return QStringList("");
|
2007-09-15 22:57:07 +00:00
|
|
|
|
2007-09-02 09:36:28 +00:00
|
|
|
struct mntent *ent;
|
2010-04-25 21:22:36 +00:00
|
|
|
while((ent = getmntent(mn))) {
|
2007-09-02 09:36:28 +00:00
|
|
|
tempList << QString(ent->mnt_dir);
|
2010-04-25 21:22:36 +00:00
|
|
|
qDebug() << "[Autodetection] Mounted on" << ent->mnt_dir
|
|
|
|
<< "is" << ent->mnt_fsname << "type" << ent->mnt_type;
|
|
|
|
}
|
2007-09-02 09:36:28 +00:00
|
|
|
endmntent(mn);
|
2007-09-15 22:57:07 +00:00
|
|
|
|
2007-08-05 19:48:04 +00:00
|
|
|
#else
|
2010-09-01 17:47:33 +00:00
|
|
|
#error Unknown Platform
|
2007-08-05 19:48:04 +00:00
|
|
|
#endif
|
2007-10-13 16:26:38 +00:00
|
|
|
return tempList;
|
2007-08-05 19:48:04 +00:00
|
|
|
}
|
|
|
|
|
2009-04-30 19:14:24 +00:00
|
|
|
|
|
|
|
/** resolve device name to mount point / drive letter
|
|
|
|
* @param device device name / disk number
|
|
|
|
* @return mount point / drive letter
|
|
|
|
*/
|
2007-08-23 15:24:28 +00:00
|
|
|
QString Autodetection::resolveMountPoint(QString device)
|
|
|
|
{
|
2009-08-08 12:12:49 +00:00
|
|
|
qDebug() << "[Autodetect] resolving mountpoint:" << device;
|
2007-09-02 08:49:08 +00:00
|
|
|
|
2007-08-23 15:24:28 +00:00
|
|
|
#if defined(Q_OS_LINUX)
|
2007-09-02 08:49:08 +00:00
|
|
|
FILE *mn = setmntent("/etc/mtab", "r");
|
|
|
|
if(!mn)
|
|
|
|
return QString("");
|
2007-09-15 22:57:07 +00:00
|
|
|
|
2007-09-02 08:49:08 +00:00
|
|
|
struct mntent *ent;
|
|
|
|
while((ent = getmntent(mn))) {
|
2010-02-20 22:46:58 +00:00
|
|
|
// Check for valid filesystem. Allow hfs too, as an Ipod might be a
|
|
|
|
// MacPod.
|
2010-04-25 21:22:36 +00:00
|
|
|
if(QString(ent->mnt_fsname) == device) {
|
|
|
|
QString result;
|
|
|
|
if(QString(ent->mnt_type).contains("vfat", Qt::CaseInsensitive)
|
|
|
|
|| QString(ent->mnt_type).contains("hfs", Qt::CaseInsensitive)) {
|
|
|
|
qDebug() << "[Autodetect] resolved mountpoint is:" << ent->mnt_dir;
|
|
|
|
result = QString(ent->mnt_dir);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
qDebug() << "[Autodetect] mountpoint is wrong filesystem!";
|
|
|
|
}
|
2007-09-02 08:49:08 +00:00
|
|
|
endmntent(mn);
|
2010-04-25 21:22:36 +00:00
|
|
|
return result;
|
2007-08-23 15:24:28 +00:00
|
|
|
}
|
|
|
|
}
|
2007-09-02 08:49:08 +00:00
|
|
|
endmntent(mn);
|
|
|
|
|
2007-10-13 16:26:38 +00:00
|
|
|
#endif
|
|
|
|
|
2009-11-22 14:29:22 +00:00
|
|
|
#if defined(Q_OS_MACX) || defined(Q_OS_OPENBSD)
|
2008-12-13 10:09:13 +00:00
|
|
|
int num;
|
|
|
|
struct statfs *mntinf;
|
|
|
|
|
|
|
|
num = getmntinfo(&mntinf, MNT_WAIT);
|
|
|
|
while(num--) {
|
2010-02-20 22:46:58 +00:00
|
|
|
// Check for valid filesystem. Allow hfs too, as an Ipod might be a
|
|
|
|
// MacPod.
|
2010-04-25 21:22:36 +00:00
|
|
|
if(QString(mntinf->f_mntfromname) == device) {
|
|
|
|
if(QString(mntinf->f_fstypename).contains("msdos", Qt::CaseInsensitive)
|
|
|
|
|| QString(mntinf->f_fstypename).contains("hfs", Qt::CaseInsensitive)) {
|
|
|
|
qDebug() << "[Autodetect] resolved mountpoint is:" << mntinf->f_mntonname;
|
|
|
|
return QString(mntinf->f_mntonname);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
qDebug() << "[Autodetect] mountpoint is wrong filesystem!";
|
|
|
|
return QString();
|
|
|
|
}
|
2009-11-22 14:29:22 +00:00
|
|
|
}
|
2008-12-13 10:09:13 +00:00
|
|
|
mntinf++;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-06-29 09:50:20 +00:00
|
|
|
#if defined(Q_OS_WIN32)
|
|
|
|
QString result;
|
|
|
|
unsigned int driveno = device.replace(QRegExp("^.*([0-9]+)"), "\\1").toInt();
|
|
|
|
|
2009-04-30 19:14:24 +00:00
|
|
|
int letter;
|
|
|
|
for(letter = 'A'; letter <= 'Z'; letter++) {
|
|
|
|
if(resolveDevicename(QString(letter)).toUInt() == driveno) {
|
|
|
|
result = letter;
|
2010-04-27 21:43:14 +00:00
|
|
|
qDebug() << "[Autodetect] resolved mountpoint is:" << result;
|
2009-04-30 19:14:24 +00:00
|
|
|
break;
|
2008-06-29 09:50:20 +00:00
|
|
|
}
|
2009-04-30 19:14:24 +00:00
|
|
|
}
|
|
|
|
if(!result.isEmpty())
|
|
|
|
return result + ":/";
|
|
|
|
#endif
|
2010-04-27 21:43:14 +00:00
|
|
|
qDebug() << "[Autodetect] resolving mountpoint failed!";
|
2009-04-30 19:14:24 +00:00
|
|
|
return QString("");
|
|
|
|
}
|
|
|
|
|
2008-06-29 09:50:20 +00:00
|
|
|
|
2009-04-30 19:14:24 +00:00
|
|
|
/** Resolve mountpoint to devicename / disk number
|
|
|
|
* @param path mountpoint path / drive letter
|
|
|
|
* @return devicename / disk number
|
|
|
|
*/
|
|
|
|
QString Autodetection::resolveDevicename(QString path)
|
|
|
|
{
|
2009-08-08 12:12:49 +00:00
|
|
|
qDebug() << "[Autodetect] resolving device name" << path;
|
2009-04-30 19:14:24 +00:00
|
|
|
#if defined(Q_OS_LINUX)
|
|
|
|
FILE *mn = setmntent("/etc/mtab", "r");
|
|
|
|
if(!mn)
|
|
|
|
return QString("");
|
|
|
|
|
|
|
|
struct mntent *ent;
|
|
|
|
while((ent = getmntent(mn))) {
|
2010-02-20 22:46:58 +00:00
|
|
|
// check for valid filesystem type.
|
|
|
|
// Linux can handle hfs (and hfsplus), so consider it a valid file
|
|
|
|
// system. Otherwise resolving the device name would fail, which in
|
|
|
|
// turn would make it impossible to warn about a MacPod.
|
|
|
|
if(QString(ent->mnt_dir) == path
|
|
|
|
&& (QString(ent->mnt_type).contains("vfat", Qt::CaseInsensitive)
|
|
|
|
|| QString(ent->mnt_type).contains("hfs", Qt::CaseInsensitive))) {
|
2009-04-30 19:14:24 +00:00
|
|
|
endmntent(mn);
|
2009-11-22 14:29:22 +00:00
|
|
|
qDebug() << "[Autodetect] device name is" << ent->mnt_fsname;
|
2009-04-30 19:14:24 +00:00
|
|
|
return QString(ent->mnt_fsname);
|
2008-06-29 09:50:20 +00:00
|
|
|
}
|
2009-04-30 19:14:24 +00:00
|
|
|
}
|
|
|
|
endmntent(mn);
|
2008-06-29 09:50:20 +00:00
|
|
|
|
2009-04-30 19:14:24 +00:00
|
|
|
#endif
|
|
|
|
|
2009-11-22 14:29:22 +00:00
|
|
|
#if defined(Q_OS_MACX) || defined(Q_OS_OPENBSD)
|
2009-04-30 19:14:24 +00:00
|
|
|
int num;
|
|
|
|
struct statfs *mntinf;
|
|
|
|
|
|
|
|
num = getmntinfo(&mntinf, MNT_WAIT);
|
|
|
|
while(num--) {
|
2010-02-20 22:46:58 +00:00
|
|
|
// check for valid filesystem type. OS X can handle hfs (hfs+ is
|
|
|
|
// treated as hfs), BSD should be the same.
|
|
|
|
if(QString(mntinf->f_mntonname) == path
|
|
|
|
&& (QString(mntinf->f_fstypename).contains("msdos", Qt::CaseInsensitive)
|
|
|
|
|| QString(mntinf->f_fstypename).contains("hfs", Qt::CaseInsensitive))) {
|
2009-11-22 14:29:22 +00:00
|
|
|
qDebug() << "[Autodetect] device name is" << mntinf->f_mntfromname;
|
2009-04-30 19:14:24 +00:00
|
|
|
return QString(mntinf->f_mntfromname);
|
2009-11-22 14:29:22 +00:00
|
|
|
}
|
2009-04-30 19:14:24 +00:00
|
|
|
mntinf++;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(Q_OS_WIN32)
|
|
|
|
DWORD written;
|
|
|
|
HANDLE h;
|
|
|
|
TCHAR uncpath[MAX_PATH];
|
|
|
|
UCHAR buffer[0x400];
|
|
|
|
PVOLUME_DISK_EXTENTS extents = (PVOLUME_DISK_EXTENTS)buffer;
|
|
|
|
|
|
|
|
_stprintf(uncpath, _TEXT("\\\\.\\%c:"), path.toAscii().at(0));
|
|
|
|
h = CreateFile(uncpath, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
|
|
|
|
NULL, OPEN_EXISTING, 0, NULL);
|
|
|
|
if(h == INVALID_HANDLE_VALUE) {
|
|
|
|
//qDebug() << "error getting extents for" << uncpath;
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
// get the extents
|
|
|
|
if(DeviceIoControl(h, IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS,
|
|
|
|
NULL, 0, extents, sizeof(buffer), &written, NULL)) {
|
|
|
|
if(extents->NumberOfDiskExtents > 1) {
|
2009-08-08 12:12:49 +00:00
|
|
|
qDebug() << "[Autodetect] resolving device name: volume spans multiple disks!";
|
2009-04-30 19:14:24 +00:00
|
|
|
return "";
|
|
|
|
}
|
2009-11-22 14:29:22 +00:00
|
|
|
qDebug() << "[Autodetect] device name is" << extents->Extents[0].DiskNumber;
|
2009-04-30 19:14:24 +00:00
|
|
|
return QString("%1").arg(extents->Extents[0].DiskNumber);
|
2008-06-29 09:50:20 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return QString("");
|
2009-04-30 19:14:24 +00:00
|
|
|
|
2007-08-23 15:24:28 +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.
|
2010-01-24 21:12:11 +00:00
|
|
|
QMap<int, QString> usbids = SystemInfo::usbIdMap(SystemInfo::MapDevice);
|
|
|
|
QMap<int, QString> usberror = SystemInfo::usbIdMap(SystemInfo::MapError);
|
|
|
|
QMap<int, QString> 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))) {
|
|
|
|
m_device = usbids.value(attached.at(i));
|
|
|
|
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))) {
|
|
|
|
m_errdev = usberror.value(attached.at(i));
|
|
|
|
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
|
|
|
|