rbutil: create a RockboxInfo class so all rockbox-info.txt handling is in one place.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@20429 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Dominik Wenger 2009-03-21 16:30:40 +00:00
parent 7aaffa51d6
commit 6c73482d00
5 changed files with 83 additions and 62 deletions

View file

@ -90,21 +90,18 @@ bool Autodetection::detect()
}
// check rockbox-info.txt afterwards.
QFile file(mounts.at(i) + "/.rockbox/rockbox-info.txt");
if(file.exists())
RockboxInfo info(mounts.at(i));
if(info.open())
{
file.open(QIODevice::ReadOnly | QIODevice::Text);
QString line = file.readLine();
if(line.startsWith("Target: "))
if(m_device.isEmpty())
{
line.remove("Target: ");
if(m_device.isEmpty())
m_device = line.trimmed(); // trim whitespaces
m_mountpoint = mounts.at(i);
qDebug() << "rockbox-info.txt detected:" << m_device << m_mountpoint;
return true;
}
m_device = info.target();
}
m_mountpoint = mounts.at(i);
qDebug() << "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);

View file

@ -58,6 +58,7 @@
#include <sys/mount.h>
#endif
#include "utils.h"
/** @brief detect permission of user (only Windows at moment).
* @return enum userlevel.
@ -352,23 +353,13 @@ QUrl Detect::systemProxy(void)
*/
QString Detect::installedVersion(QString mountpoint)
{
// read rockbox-info.txt
QFile info(mountpoint +"/.rockbox/rockbox-info.txt");
if(!info.open(QIODevice::ReadOnly))
RockboxInfo info(mountpoint);
if(!info.open())
{
return "";
}
while (!info.atEnd()) {
QString line = info.readLine();
if(line.contains("Version:"))
{
return line.remove("Version:").trimmed();
}
}
info.close();
return "";
return info.version();
}
@ -377,24 +368,13 @@ QString Detect::installedVersion(QString mountpoint)
*/
QString Detect::installedTarget(QString mountpoint)
{
// read rockbox-info.txt
QFile info(mountpoint +"/.rockbox/rockbox-info.txt");
if(!info.open(QIODevice::ReadOnly))
RockboxInfo info(mountpoint);
if(!info.open())
{
return "";
}
while (!info.atEnd())
{
QString line = info.readLine();
if(line.contains("Target:"))
{
qDebug() << line;
return line.remove("Target:").trimmed();
}
}
info.close();
return "";
return info.target();
}

View file

@ -130,3 +130,43 @@ qulonglong filesystemFree(QString path)
return size;
}
RockboxInfo::RockboxInfo(QString mountpoint)
{
m_path = mountpoint +"/.rockbox/rockbox-info.txt";
}
bool RockboxInfo::open()
{
QFile file(m_path);
if(!file.exists())
return false;
if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
return false;
// read file contents
while (!file.atEnd())
{
QString line = file.readLine();
if(line.contains("Version:"))
{
m_version = line.remove("Version:").trimmed();
}
else if(line.contains("Target: "))
{
m_target = line.remove("Target: ").trimmed();
}
else if(line.contains("Features:"))
{
m_features = line.remove("Features:").trimmed();
}
else if(line.contains("Target id:"))
{
m_targetid = line.remove("Target id:").trimmed();
}
}
file.close();
return true;
}

View file

@ -30,5 +30,23 @@ bool recRmdir( const QString &dirName );
QString resolvePathCase(QString path);
qulonglong filesystemFree(QString path);
class RockboxInfo
{
public:
RockboxInfo(QString mountpoint);
bool open();
QString version() {return m_version;}
QString features(){return m_features;}
QString targetID() {return m_targetid;}
QString target() {return m_target;}
private:
QString m_path;
QString m_version;
QString m_features;
QString m_targetid;
QString m_target;
};
#endif