mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-11-14 07:32:35 -05:00
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:
parent
7aaffa51d6
commit
6c73482d00
5 changed files with 83 additions and 62 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@
|
|||
****************************************************************************/
|
||||
|
||||
#include "voicefile.h"
|
||||
#include "utils.h"
|
||||
|
||||
#define STATE_INVALID 0
|
||||
#define STATE_PHRASE 1
|
||||
|
|
@ -49,34 +50,19 @@ bool VoiceFileCreator::createVoiceFile(ProgressloggerInterface* logger)
|
|||
m_path = QDir::tempPath() + "/rbvoice/";
|
||||
|
||||
// read rockbox-info.txt
|
||||
QFile info(m_mountpoint+"/.rockbox/rockbox-info.txt");
|
||||
if(!info.open(QIODevice::ReadOnly))
|
||||
RockboxInfo info(m_mountpoint);
|
||||
if(!info.open())
|
||||
{
|
||||
m_logger->addItem(tr("failed to open rockbox-info.txt"),LOGERROR);
|
||||
m_logger->addItem(tr("could not find rockbox-info.txt"),LOGERROR);
|
||||
m_logger->abort();
|
||||
emit done(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
QString target, features,version;
|
||||
while (!info.atEnd()) {
|
||||
QString line = info.readLine();
|
||||
|
||||
if(line.contains("Target:"))
|
||||
{
|
||||
target = line.remove("Target:").trimmed();
|
||||
}
|
||||
else if(line.contains("Features:"))
|
||||
{
|
||||
features = line.remove("Features:").trimmed();
|
||||
}
|
||||
else if(line.contains("Version:"))
|
||||
{
|
||||
version = line.remove("Version:").trimmed();
|
||||
version = version.left(version.indexOf("-")).remove(0,1);
|
||||
}
|
||||
}
|
||||
info.close();
|
||||
QString target = info.target();
|
||||
QString features = info.features();
|
||||
QString version = info.version();
|
||||
version = version.left(version.indexOf("-")).remove(0,1);
|
||||
|
||||
//prepare download url
|
||||
QUrl genlangUrl = settings->genlangUrl() +"?lang=" +m_lang+"&t="+target+"&rev="+version+"&f="+features;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue