Ejemplo n.º 1
0
bool Autodetection::detect()
{
    m_device = "";
    m_mountpoint = "";
    m_errdev = "";

    detectUsb();

    // Try detection via rockbox.info / rbutil.log
    QStringList mounts = mountpoints();

    for(int i=0; i< mounts.size();i++)
    {
        // do the file checking
        QDir dir(mounts.at(i));
        qDebug() << "[Autodetect] paths to check:" << mounts;
        if(dir.exists())
        {
            // check logfile first.
            if(QFile(mounts.at(i) + "/.rockbox/rbutil.log").exists()) {
                QSettings log(mounts.at(i) + "/.rockbox/rbutil.log",
                              QSettings::IniFormat, this);
                if(!log.value("platform").toString().isEmpty()) {
                    if(m_device.isEmpty())
                        m_device = log.value("platform").toString();
                    m_mountpoint = mounts.at(i);
                    qDebug() << "[Autodetect] rbutil.log detected:" << m_device << m_mountpoint;
                    return true;
                }
            }

            // check rockbox-info.txt afterwards.
            RockboxInfo info(mounts.at(i));
            if(info.success())
            {
                if(m_device.isEmpty())
                {
                    m_device = info.target();
                    // special case for video64mb. This is a workaround, and
                    // should get replaced when autodetection is reworked.
                    if(m_device == "ipodvideo" && info.ram() == 64)
                    {
                        m_device = "ipodvideo64mb";
                    }
                }
                m_mountpoint = mounts.at(i);
                qDebug() << "[Autodetect] rockbox-info.txt detected:"
                         << m_device << m_mountpoint;
                return true;
            }

            // check for some specific files in root folder
            QDir root(mounts.at(i));
            QStringList rootentries = root.entryList(QDir::Files);
            if(rootentries.contains("archos.mod", Qt::CaseInsensitive))
            {
                // archos.mod in root folder -> Archos Player
                m_device = "player";
                m_mountpoint = mounts.at(i);
                return true;
            }
            if(rootentries.contains("ONDIOST.BIN", Qt::CaseInsensitive))
            {
                // ONDIOST.BIN in root -> Ondio FM
                m_device = "ondiofm";
                m_mountpoint = mounts.at(i);
                return true;
            }
            if(rootentries.contains("ONDIOSP.BIN", Qt::CaseInsensitive))
            {
                // ONDIOSP.BIN in root -> Ondio SP
                m_device = "ondiosp";
                m_mountpoint = mounts.at(i);
                return true;
            }
            if(rootentries.contains("ajbrec.ajz", Qt::CaseInsensitive))
            {
                qDebug() << "[Autodetect] ajbrec.ajz found. Trying detectAjbrec()";
                if(detectAjbrec(mounts.at(i))) {
                    m_mountpoint = mounts.at(i);
                    qDebug() << "[Autodetect]" << m_device;
                    return true;
                }
            }
            // detection based on player specific folders
            QStringList rootfolders = root.entryList(QDir::Dirs
                    | QDir::NoDotAndDotDot | QDir::Hidden | QDir::System);
            if(rootfolders.contains("GBSYSTEM", Qt::CaseInsensitive))
            {
                // GBSYSTEM folder -> Gigabeat
                m_device = "gigabeatf";
                m_mountpoint = mounts.at(i);
                return true;
            }
#if defined(Q_OS_WIN32)
            // on windows, try to detect the drive letter of an Ipod
            if(rootfolders.contains("iPod_Control", Qt::CaseInsensitive))
            {
                // iPod_Control folder -> Ipod found
                // detecting of the Ipod type is done below using ipodpatcher
                m_mountpoint = mounts.at(i);
            }
#endif
        }

    }

    int n;
    // try ipodpatcher
    // initialize sector buffer. Needed.
    ipod_sectorbuf = NULL;
    ipod_alloc_buffer(&ipod_sectorbuf, BUFFER_SIZE);
    struct ipod_t ipod;
    n = ipod_scan(&ipod);
    if(n == 1) {
        qDebug() << "[Autodetect] Ipod found:" << ipod.modelstr << "at" << ipod.diskname;
        // if the found ipod is a macpod also notice it as device with problem.
        if(ipod.macpod)
            m_errdev = ipod.targetname;
        m_device = ipod.targetname;
        // 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);
        return true;
    }
    else {
        qDebug() << "[Autodetect] ipodpatcher: no Ipod found." << n;
    }
    free(ipod_sectorbuf);
    ipod_sectorbuf = NULL;

    // try sansapatcher
    // initialize sector buffer. Needed.
    sansa_sectorbuf = NULL;
    sansa_alloc_buffer(&sansa_sectorbuf, BUFFER_SIZE);
    struct sansa_t sansa;
    n = sansa_scan(&sansa);
    if(n == 1) {
        qDebug() << "[Autodetect] Sansa found:" << sansa.targetname << "at" << sansa.diskname;
        m_device = QString("sansa%1").arg(sansa.targetname);
        QString mp(sansa.diskname);
#ifdef Q_OS_LINUX
        mp.append("1");
#endif
#ifdef Q_OS_MACX
        mp.append("s1");
#endif
        m_mountpoint = resolveMountPoint(mp);
        return true;
    }
    else {
        qDebug() << "[Autodetect] sansapatcher: no Sansa found." << n;
    }
    free(sansa_sectorbuf);
    sansa_sectorbuf = NULL;

    if(m_mountpoint.isEmpty() && m_device.isEmpty()
            && m_errdev.isEmpty() && m_incompat.isEmpty())
        return false;
    return true;
}
Ejemplo n.º 2
0
// Merge players detected by checking mounted filesystems for known files:
// - rockbox-info.txt / rbutil.log
// - player specific files
void Autodetection::mergeMounted(void)
{
    QStringList mounts = Utils::mountpoints(Utils::MountpointsSupported);
    LOG_INFO() << "paths to check:" << mounts;

    for(int i = 0; i < mounts.size(); i++)
    {
        // do the file checking
        QDir dir(mounts.at(i));
        if(dir.exists())
        {
            // check logfile first.
            if(QFile(mounts.at(i) + "/.rockbox/rbutil.log").exists()) {
                QSettings log(mounts.at(i) + "/.rockbox/rbutil.log",
                              QSettings::IniFormat, this);
                if(!log.value("platform").toString().isEmpty()) {
                    struct Detected d;
                    d.device = log.value("platform").toString();
                    d.mountpoint = mounts.at(i);
                    d.status = PlayerOk;
                    updateDetectedDevice(d);
                    LOG_INFO() << "rbutil.log detected:"
                               << log.value("platform").toString() << mounts.at(i);
                }
            }

            // check rockbox-info.txt afterwards.
            RockboxInfo info(mounts.at(i));
            if(info.success())
            {
                struct Detected d;
                d.device = info.target();
                d.mountpoint = mounts.at(i);
                d.status = PlayerOk;
                updateDetectedDevice(d);
                LOG_INFO() << "rockbox-info.txt detected:"
                           << info.target() << mounts.at(i);
            }

            // check for some specific files in root folder
            QDir root(mounts.at(i));
            QStringList rootentries = root.entryList(QDir::Files);
            if(rootentries.contains("archos.mod", Qt::CaseInsensitive))
            {
                // archos.mod in root folder -> Archos Player
                struct Detected d;
                d.device = "player";
                d.mountpoint = mounts.at(i);
                d.status = PlayerOk;
                updateDetectedDevice(d);
            }
            if(rootentries.contains("ONDIOST.BIN", Qt::CaseInsensitive))
            {
                // ONDIOST.BIN in root -> Ondio FM
                struct Detected d;
                d.device = "ondiofm";
                d.mountpoint = mounts.at(i);
                d.status = PlayerOk;
                updateDetectedDevice(d);
            }
            if(rootentries.contains("ONDIOSP.BIN", Qt::CaseInsensitive))
            {
                // ONDIOSP.BIN in root -> Ondio SP
                struct Detected d;
                d.device = "ondiosp";
                d.mountpoint = mounts.at(i);
                d.status = PlayerOk;
                updateDetectedDevice(d);
            }
            if(rootentries.contains("ajbrec.ajz", Qt::CaseInsensitive))
            {
                LOG_INFO() << "ajbrec.ajz found. Trying detectAjbrec()";
                struct Detected d;
                d.device = detectAjbrec(mounts.at(i));
                d.mountpoint = mounts.at(i);
                d.status = PlayerOk;
                if(!d.device.isEmpty()) {
                    LOG_INFO() << d.device;
                    updateDetectedDevice(d);
                }
            }
            // detection based on player specific folders
            QStringList rootfolders = root.entryList(QDir::Dirs
                                      | QDir::NoDotAndDotDot | QDir::Hidden | QDir::System);
            if(rootfolders.contains("GBSYSTEM", Qt::CaseInsensitive))
            {
                // GBSYSTEM folder -> Gigabeat
                struct Detected d;
                d.device = "gigabeatf";
                d.mountpoint = mounts.at(i);
                updateDetectedDevice(d);
            }
        }
    }
#if 0
    // Ipods have a folder "iPod_Control" in the root.
    for(int i = 0; i < m_detected.size(); ++i) {
        struct Detected entry = m_detected.at(i);
        for(int j = 0; j < entry.usbdevices.size(); ++j) {
            // limit this to Ipods only.
            if(!entry.usbdevices.at(j).startsWith("ipod")
                    && !entry.device.startsWith("ipod")) {
                continue;
            }
            // look for iPod_Control on all supported volumes.
            for(int k = 0; k < mounts.size(); k++) {
                QDir root(mounts.at(k));
                QStringList rootfolders = root.entryList(QDir::Dirs
                                          | QDir::NoDotAndDotDot | QDir::Hidden | QDir::System);
                if(rootfolders.contains("iPod_Control", Qt::CaseInsensitive)) {
                    entry.mountpoint = mounts.at(k);
                    m_detected.takeAt(i);
                    m_detected.append(entry);
                }
            }
        }
    }
#endif

}