diff options
Diffstat (limited to 'utils')
-rw-r--r-- | utils/rbutilqt/base/rockboxinfo.cpp | 70 | ||||
-rw-r--r-- | utils/rbutilqt/test/test-rockboxinfo.cpp | 14 |
2 files changed, 47 insertions, 37 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 | ||
25 | RockboxInfo::RockboxInfo(QString mountpoint, QString fname) | 26 | RockboxInfo::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 | ||
diff --git a/utils/rbutilqt/test/test-rockboxinfo.cpp b/utils/rbutilqt/test/test-rockboxinfo.cpp index 9d2b53b3ab..69189f585e 100644 --- a/utils/rbutilqt/test/test-rockboxinfo.cpp +++ b/utils/rbutilqt/test/test-rockboxinfo.cpp | |||
@@ -20,6 +20,7 @@ | |||
20 | 20 | ||
21 | #include <QtTest/QtTest> | 21 | #include <QtTest/QtTest> |
22 | #include <QObject> | 22 | #include <QObject> |
23 | #include <QFileInfo> | ||
23 | #include "rockboxinfo.h" | 24 | #include "rockboxinfo.h" |
24 | 25 | ||
25 | 26 | ||
@@ -83,12 +84,12 @@ void TestRockboxInfo::testVersion() | |||
83 | QFETCH(QString, release); | 84 | QFETCH(QString, release); |
84 | QTemporaryFile tf(this); | 85 | QTemporaryFile tf(this); |
85 | tf.open(); | 86 | tf.open(); |
86 | QString filename = tf.fileName(); | 87 | QFileInfo finfo(tf); |
87 | tf.write(input.toLatin1()); | 88 | tf.write(input.toLatin1()); |
88 | tf.write("\n"); | 89 | tf.write("\n"); |
89 | tf.close(); | 90 | tf.close(); |
90 | 91 | ||
91 | RockboxInfo info("", filename); | 92 | RockboxInfo info(finfo.path(), finfo.fileName()); |
92 | QCOMPARE(info.version(), QString(version)); | 93 | QCOMPARE(info.version(), QString(version)); |
93 | QCOMPARE(info.revision(), QString(revision)); | 94 | QCOMPARE(info.revision(), QString(revision)); |
94 | QCOMPARE(info.release(), QString(release)); | 95 | QCOMPARE(info.release(), QString(release)); |
@@ -112,13 +113,14 @@ void TestRockboxInfo::testTarget() | |||
112 | QFETCH(QString, target); | 113 | QFETCH(QString, target); |
113 | QTemporaryFile tf(this); | 114 | QTemporaryFile tf(this); |
114 | tf.open(); | 115 | tf.open(); |
116 | QFileInfo finfo(tf); | ||
115 | QString filename = tf.fileName(); | 117 | QString filename = tf.fileName(); |
116 | tf.write(prefix.at(j).toLatin1()); | 118 | tf.write(prefix.at(j).toLatin1()); |
117 | tf.write(target.toLatin1()); | 119 | tf.write(target.toLatin1()); |
118 | tf.write("\n"); | 120 | tf.write("\n"); |
119 | tf.close(); | 121 | tf.close(); |
120 | 122 | ||
121 | RockboxInfo info("", filename); | 123 | RockboxInfo info(finfo.path(), finfo.fileName()); |
122 | QCOMPARE(info.target(), target); | 124 | QCOMPARE(info.target(), target); |
123 | } | 125 | } |
124 | } | 126 | } |
@@ -141,13 +143,14 @@ void TestRockboxInfo::testMemory() | |||
141 | QFETCH(QString, memory); | 143 | QFETCH(QString, memory); |
142 | QTemporaryFile tf(this); | 144 | QTemporaryFile tf(this); |
143 | tf.open(); | 145 | tf.open(); |
146 | QFileInfo finfo(tf); | ||
144 | QString filename = tf.fileName(); | 147 | QString filename = tf.fileName(); |
145 | tf.write(prefix.at(j).toLatin1()); | 148 | tf.write(prefix.at(j).toLatin1()); |
146 | tf.write(memory.toLatin1()); | 149 | tf.write(memory.toLatin1()); |
147 | tf.write("\n"); | 150 | tf.write("\n"); |
148 | tf.close(); | 151 | tf.close(); |
149 | 152 | ||
150 | RockboxInfo info("", filename); | 153 | RockboxInfo info(finfo.path(), finfo.fileName()); |
151 | QCOMPARE(info.ram(), memory.toInt()); | 154 | QCOMPARE(info.ram(), memory.toInt()); |
152 | } | 155 | } |
153 | } | 156 | } |
@@ -168,13 +171,14 @@ void TestRockboxInfo::testFeatures() | |||
168 | QFETCH(QString, features); | 171 | QFETCH(QString, features); |
169 | QTemporaryFile tf(this); | 172 | QTemporaryFile tf(this); |
170 | tf.open(); | 173 | tf.open(); |
174 | QFileInfo finfo(tf); | ||
171 | QString filename = tf.fileName(); | 175 | QString filename = tf.fileName(); |
172 | tf.write(prefix.at(j).toLatin1()); | 176 | tf.write(prefix.at(j).toLatin1()); |
173 | tf.write(features.toLatin1()); | 177 | tf.write(features.toLatin1()); |
174 | tf.write("\n"); | 178 | tf.write("\n"); |
175 | tf.close(); | 179 | tf.close(); |
176 | 180 | ||
177 | RockboxInfo info("", filename); | 181 | RockboxInfo info(finfo.path(), finfo.fileName()); |
178 | QCOMPARE(info.features(), features); | 182 | QCOMPARE(info.features(), features); |
179 | } | 183 | } |
180 | } | 184 | } |