1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
9 * Copyright (C) 2007 by Dominik Wenger
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
20 #include "autodetection.h"
22 #if defined(Q_OS_LINUX)
27 Autodetection::Autodetection(QObject
* parent
): QObject(parent
)
32 bool Autodetection::detect()
37 // Try detection via rockbox.info / rbutil.log
38 QStringList mountpoints
= getMountpoints();
40 for(int i
=0; i
< mountpoints
.size();i
++)
42 // do the file checking
43 QDir
dir(mountpoints
.at(i
));
46 // check logfile first.
47 if(QFile(mountpoints
.at(i
) + "/.rockbox/rbutil.log").exists()) {
48 QSettings
log(mountpoints
.at(i
) + "/.rockbox/rbutil.log",
49 QSettings::IniFormat
, this);
50 if(!log
.value("platform").toString().isEmpty()) {
51 m_device
= log
.value("platform").toString();
52 m_mountpoint
= mountpoints
.at(i
);
53 qDebug() << "rbutil.log detected:" << m_device
<< m_mountpoint
;
58 // check rockbox-info.txt afterwards.
59 QFile
file(mountpoints
.at(i
) + "/.rockbox/rockbox-info.txt");
62 file
.open(QIODevice::ReadOnly
| QIODevice::Text
);
63 QString line
= file
.readLine();
64 if(line
.startsWith("Target: "))
66 line
.remove("Target: ");
67 m_device
= line
.trimmed(); // trim whitespaces
68 m_mountpoint
= mountpoints
.at(i
);
69 qDebug() << "rockbox-info.txt detected:" << m_device
<< m_mountpoint
;
73 // check for some specific files in root folder
74 QDir
root(mountpoints
.at(i
));
75 QStringList rootentries
= root
.entryList(QDir::Files
);
76 if(rootentries
.contains("archos.mod", Qt::CaseInsensitive
))
78 // archos.mod in root folder -> Archos Player
80 m_mountpoint
= mountpoints
.at(i
);
83 if(rootentries
.contains("ONDIOST.BIN"), Qt::CaseInsensitive
)
85 // ONDIOST.BIN in root -> Ondio FM
87 m_mountpoint
= mountpoints
.at(i
);
90 if(rootentries
.contains("ONDIOSP.BIN"), Qt::CaseInsensitive
)
92 // ONDIOSP.BIN in root -> Ondio SP
94 m_mountpoint
= mountpoints
.at(i
);
97 if(rootentries
.contains("ajbrec.ajz"), Qt::CaseInsensitive
)
99 qDebug() << "it's an archos. further detection needed";
101 // detection based on player specific folders
102 QStringList rootfolders
= root
.entryList(QDir::Dirs
| QDir::NoDotAndDotDot
);
103 if(rootfolders
.contains("GBSYSTEM"), Qt::CaseInsensitive
)
105 // GBSYSTEM folder -> Gigabeat
106 m_device
= "gigabeatf";
107 m_mountpoint
= mountpoints
.at(i
);
110 qDebug() << rootfolders
;
118 n
= ipod_scan(&ipod
);
120 qDebug() << "Ipod found:" << ipod
.modelstr
<< "at" << ipod
.diskname
;
121 m_device
= ipod
.targetname
;
122 m_mountpoint
= resolveMountPoint(ipod
.diskname
);
127 struct sansa_t sansa
;
128 n
= sansa_scan(&sansa
);
130 qDebug() << "Sansa found:" << "sansae200" << "at" << sansa
.diskname
;
131 m_device
= "sansae200";
132 m_mountpoint
= resolveMountPoint(sansa
.diskname
);
140 QStringList
Autodetection::getMountpoints()
142 #if defined(Q_OS_WIN32)
143 QStringList tempList
;
144 QFileInfoList list
= QDir::drives();
145 for(int i
=0; i
<list
.size();i
++)
147 tempList
<< list
.at(i
).absolutePath();
151 #elif defined(Q_OS_MACX)
152 QDir
dir("/Volumes");
153 return dir
.entryList();
154 #elif defined(Q_OS_LINUX)
155 QStringList tempList
;
157 FILE *mn
= setmntent("/etc/mtab", "r");
159 return QStringList("");
162 while((ent
= getmntent(mn
)))
163 tempList
<< QString(ent
->mnt_dir
);
168 #error Unknown Plattform
172 QString
Autodetection::resolveMountPoint(QString device
)
174 qDebug() << "Autodetection::resolveMountPoint(QString)" << device
;
176 #if defined(Q_OS_LINUX)
177 FILE *mn
= setmntent("/etc/mtab", "r");
182 while((ent
= getmntent(mn
))) {
183 if(QString(ent
->mnt_fsname
).startsWith(device
)
184 && QString(ent
->mnt_type
).contains("vfat", Qt::CaseInsensitive
)) {
186 return QString(ent
->mnt_dir
);