summaryrefslogtreecommitdiff
path: root/utils/rbutilqt/base/rockboxinfo.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'utils/rbutilqt/base/rockboxinfo.cpp')
-rw-r--r--utils/rbutilqt/base/rockboxinfo.cpp70
1 files changed, 38 insertions, 32 deletions
diff --git a/utils/rbutilqt/base/rockboxinfo.cpp b/utils/rbutilqt/base/rockboxinfo.cpp
index f34adbfc2f..744559fdec 100644
--- a/utils/rbutilqt/base/rockboxinfo.cpp
+++ b/utils/rbutilqt/base/rockboxinfo.cpp
@@ -18,15 +18,18 @@
18 18
19#include "rockboxinfo.h" 19#include "rockboxinfo.h"
20 20
21#include <QtCore> 21#include <QRegularExpression>
22#include <QDebug> 22#include <QString>
23#include <QFile>
23#include "Logger.h" 24#include "Logger.h"
24 25
25RockboxInfo::RockboxInfo(QString mountpoint, QString fname) 26RockboxInfo::RockboxInfo(QString mountpoint, QString fname) :
27 m_ram(0),
28 m_voicefmt(0),
29 m_success(false)
26{ 30{
27 LOG_INFO() << "Getting version info from rockbox-info.txt"; 31 LOG_INFO() << "Getting version info from rockbox-info.txt";
28 QFile file(mountpoint + "/" + fname); 32 QFile file(mountpoint + "/" + fname);
29 m_success = false;
30 m_voicefmt = 400; // default value for compatibility 33 m_voicefmt = 400; // default value for compatibility
31 if(!file.exists()) 34 if(!file.exists())
32 return; 35 return;
@@ -35,44 +38,47 @@ RockboxInfo::RockboxInfo(QString mountpoint, QString fname)
35 return; 38 return;
36 39
37 // read file contents 40 // read file contents
38 QRegExp hash("^Version:\\s+(r?)([0-9a-fM]+)"); 41 QRegularExpression parts("^([A-Z][a-z ]+):\\s+(.*)");
39 QRegExp version("^Version:\\s+(\\S.*)"); 42
40 QRegExp release("^Version:\\s+([0-9\\.]+)\\s*$");
41 QRegExp target("^Target:\\s+(\\S.*)");
42 QRegExp features("^Features:\\s+(\\S.*)");
43 QRegExp targetid("^Target id:\\s+(\\S.*)");
44 QRegExp memory("^Memory:\\s+(\\S.*)");
45 QRegExp voicefmt("^Voice format:\\s+(\\S.*)");
46 while (!file.atEnd()) 43 while (!file.atEnd())
47 { 44 {
48 QString line = file.readLine().trimmed(); 45 QString line = file.readLine().trimmed();
49 46
50 if(version.indexIn(line) >= 0) { 47 auto match = parts.match(line);
51 m_version = version.cap(1); 48 if(!match.isValid())
52 } 49 {
53 if(release.indexIn(line) >= 0) { 50 continue;
54 m_release = release.cap(1);
55 } 51 }
56 if(hash.indexIn(line) >= 0) { 52
57 // git hashes are usually at least 7 characters. 53 if(match.captured(1) == "Version") {
58 // svn revisions are expected to be at least 4 digits. 54 m_version = match.captured(2);
59 if(hash.cap(2).size() > 3) 55
60 m_revision = hash.cap(2); 56 if(match.captured(2).contains(".")) {
57 // version number
58 m_release = match.captured(2);
59 }
60 if(match.captured(2).contains("-")) {
61 // hash-date format. Revision is first part.
62 m_revision = match.captured(2).split("-").at(0);
63 if(m_revision.startsWith("r")) {
64 m_revision.remove(0, 1);
65 }
66 }
61 } 67 }
62 else if(target.indexIn(line) >= 0) { 68 else if(match.captured(1) == "Target") {
63 m_target = target.cap(1); 69 m_target = match.captured(2);
64 } 70 }
65 else if(features.indexIn(line) >= 0) { 71 else if(match.captured(1) == "Features") {
66 m_features = features.cap(1); 72 m_features = match.captured(2);
67 } 73 }
68 else if(targetid.indexIn(line) >= 0) { 74 else if(match.captured(1) == "Target id") {
69 m_targetid = targetid.cap(1); 75 m_targetid = match.captured(2);
70 } 76 }
71 else if(memory.indexIn(line) >= 0) { 77 else if(match.captured(1) == "Memory") {
72 m_ram = memory.cap(1).toInt(); 78 m_ram = match.captured(2).toInt();
73 } 79 }
74 else if(voicefmt.indexIn(line) >= 0) { 80 else if(match.captured(1) == "Voice format") {
75 m_voicefmt = voicefmt.cap(1).toInt(); 81 m_voicefmt = match.captured(2).toInt();
76 } 82 }
77 } 83 }
78 84