summaryrefslogtreecommitdiff
path: root/rbutil/rbutilqt
diff options
context:
space:
mode:
Diffstat (limited to 'rbutil/rbutilqt')
-rw-r--r--rbutil/rbutilqt/base/utils.cpp67
-rw-r--r--rbutil/rbutilqt/base/utils.h1
-rw-r--r--rbutil/rbutilqt/rbutilqt.cpp62
-rw-r--r--rbutil/rbutilqt/rbutilqt.h1
4 files changed, 76 insertions, 55 deletions
diff --git a/rbutil/rbutilqt/base/utils.cpp b/rbutil/rbutilqt/base/utils.cpp
index 767b3c1c52..ce8cb1c5a9 100644
--- a/rbutil/rbutilqt/base/utils.cpp
+++ b/rbutil/rbutilqt/base/utils.cpp
@@ -203,4 +203,71 @@ QString Utils::checkEnvironment(bool permission)
203 else 203 else
204 return text; 204 return text;
205} 205}
206/** @brief Compare two version strings.
207 * @param s1 first version string
208 * @param s2 second version string
209 * @return 0 if strings identical, 1 if second is newer, -1 if first.
210 */
211int Utils::compareVersionStrings(QString s1, QString s2)
212{
213 QString a = s1.trimmed();
214 QString b = s2.trimmed();
215 qDebug() << "[Utils] comparing version strings" << a << "and" << b;
216 // if strings are identical return 0.
217 if(a.isEmpty())
218 return 1;
219 if(b.isEmpty())
220 return -1;
221
222 while(!a.isEmpty() || !b.isEmpty()) {
223 // trim all leading non-digits and non-dots (dots are removed afterwards)
224 a.remove(QRegExp("^[^\\d\\.]*"));
225 b.remove(QRegExp("^[^\\d\\.]*"));
226
227 // trim all trailing non-digits for conversion (QString::toInt()
228 // requires this). Copy strings first as replace() changes the string.
229 QString numa = a;
230 QString numb = b;
231 numa.remove(QRegExp("\\D+.*$"));
232 numb.remove(QRegExp("\\D+.*$"));
233
234 // convert to number
235 bool ok1, ok2;
236 int vala = numa.toUInt(&ok1);
237 int valb = numb.toUInt(&ok2);
238 // if none of the numbers converted successfully we're at trailing garbage.
239 if(!ok1 && !ok2)
240 break;
241 if(!ok1)
242 return 1;
243 if(!ok2)
244 return -1;
245
246 // if numbers mismatch we have a decision.
247 if(vala != valb)
248 return (vala > valb) ? -1 : 1;
249
250 // trim leading digits.
251 a.remove(QRegExp("^\\d*"));
252 b.remove(QRegExp("^\\d*"));
253
254 // if number is immediately followed by a character consider it as
255 // version addon (like 1.2.3b). In this case compare characters too.
256 QChar ltra;
257 QChar ltrb;
258 if(a.contains(QRegExp("^[a-zA-Z]")))
259 ltra = a.at(0);
260 if(b.contains(QRegExp("^[a-zA-Z]")))
261 ltrb = b.at(0);
262 if(ltra != ltrb)
263 return (ltra < ltrb) ? 1 : -1;
264 // both are identical or no addon characters, ignore.
265 // remove modifiers and following dot.
266 a.remove(QRegExp("^[a-zA-Z]*\\."));
267 b.remove(QRegExp("^[a-zA-Z]*\\."));
268 }
269
270 // no differences found.
271 return 0;
272}
206 273
diff --git a/rbutil/rbutilqt/base/utils.h b/rbutil/rbutilqt/base/utils.h
index cdc3d3be5b..266044d567 100644
--- a/rbutil/rbutilqt/base/utils.h
+++ b/rbutil/rbutilqt/base/utils.h
@@ -34,6 +34,7 @@ public:
34 static qulonglong filesystemFree(QString path); 34 static qulonglong filesystemFree(QString path);
35 static QString findExecutable(QString name); 35 static QString findExecutable(QString name);
36 static QString checkEnvironment(bool permission); 36 static QString checkEnvironment(bool permission);
37 static int compareVersionStrings(QString s1, QString s2);
37}; 38};
38 39
39#endif 40#endif
diff --git a/rbutil/rbutilqt/rbutilqt.cpp b/rbutil/rbutilqt/rbutilqt.cpp
index 274efb46af..98c1024f60 100644
--- a/rbutil/rbutilqt/rbutilqt.cpp
+++ b/rbutil/rbutilqt/rbutilqt.cpp
@@ -1269,6 +1269,7 @@ void RbUtilQt::checkUpdate(void)
1269 if(RbSettings::value(RbSettings::CacheOffline).toBool()) 1269 if(RbSettings::value(RbSettings::CacheOffline).toBool())
1270 update->setCache(true); 1270 update->setCache(true);
1271 1271
1272 ui.statusbar->showMessage(tr("Checking for update ..."));
1272 update->getFile(QUrl(url)); 1273 update->getFile(QUrl(url));
1273} 1274}
1274 1275
@@ -1290,7 +1291,7 @@ void RbUtilQt::downloadUpdateDone(bool error)
1290 } 1291 }
1291 qDebug() << "[Checkupdate] " << rbutilList; 1292 qDebug() << "[Checkupdate] " << rbutilList;
1292 1293
1293 QString newVersion =""; 1294 QString newVersion = "";
1294 //check if there is a binary with higher version in this list 1295 //check if there is a binary with higher version in this list
1295 for(int i=0; i < rbutilList.size(); i++) 1296 for(int i=0; i < rbutilList.size(); i++)
1296 { 1297 {
@@ -1306,9 +1307,9 @@ void RbUtilQt::downloadUpdateDone(bool error)
1306#endif 1307#endif
1307#endif 1308#endif
1308 //check if it is newer, and remember newest 1309 //check if it is newer, and remember newest
1309 if(newerVersion(VERSION,rbutilList.at(i))) 1310 if(Utils::compareVersionStrings(VERSION, rbutilList.at(i)) == 1)
1310 { 1311 {
1311 if(newVersion == "" || newerVersion(newVersion,rbutilList.at(i))) 1312 if(Utils::compareVersionStrings(newVersion, rbutilList.at(i)) == 1)
1312 { 1313 {
1313 newVersion = rbutilList.at(i); 1314 newVersion = rbutilList.at(i);
1314 } 1315 }
@@ -1331,58 +1332,11 @@ void RbUtilQt::downloadUpdateDone(bool error)
1331 QMessageBox::information(this,tr("RockboxUtility Update available"), 1332 QMessageBox::information(this,tr("RockboxUtility Update available"),
1332 tr("<b>New RockboxUtility Version available.</b> <br><br>" 1333 tr("<b>New RockboxUtility Version available.</b> <br><br>"
1333 "Download it from here: <a href='%1'>%2</a>").arg(url).arg(newVersion) ); 1334 "Download it from here: <a href='%1'>%2</a>").arg(url).arg(newVersion) );
1335 ui.statusbar->showMessage(tr("New version of Rockbox Utility available."));
1336 }
1337 else {
1338 ui.statusbar->showMessage(tr("Rockbox Utility is up to date."), 5000);
1334 } 1339 }
1335 } 1340 }
1336} 1341}
1337 1342
1338bool RbUtilQt::newerVersion(QString versionOld,QString versionNew)
1339{
1340 QRegExp chars("\\d*(\\D)");
1341
1342 //strip non-number from beginning
1343 versionOld = versionOld.remove(0,versionOld.indexOf(QRegExp("\\d")));
1344 versionNew = versionNew.remove(0,versionNew.indexOf(QRegExp("\\d")));
1345
1346 // split versions by "."
1347 QStringList versionListOld = versionOld.split(".");
1348 QStringList versionListNew = versionNew.split(".");
1349
1350 QStringListIterator iteratorOld(versionListOld);
1351 QStringListIterator iteratorNew(versionListNew);
1352
1353 //check every section
1354 while(iteratorOld.hasNext() && iteratorNew.hasNext())
1355 {
1356 QString newPart = iteratorNew.next();
1357 QString oldPart = iteratorOld.next();
1358 QString newPartChar = "", oldPartChar = "";
1359 int newPartInt = 0, oldPartInt =0;
1360
1361 //convert to int, if it contains chars, put into seperated variable
1362 if(newPart.contains(chars))
1363 {
1364 newPartChar = chars.cap(1);
1365 newPart = newPart.remove(newPartChar);
1366 }
1367 newPartInt = newPart.toInt();
1368 //convert to int, if it contains chars, put into seperated variable
1369 if(oldPart.contains(chars))
1370 {
1371 oldPartChar = chars.cap(1);
1372 oldPart = oldPart.remove(oldPartChar);
1373 }
1374 oldPartInt = oldPart.toInt();
1375
1376 if(newPartInt > oldPartInt) // this section int is higher -> true
1377 return true;
1378 else if(newPartInt < oldPartInt) //this section int is lower -> false
1379 return false;
1380 else if(newPartChar > oldPartChar) //ints are the same, chars is higher -> true
1381 return true;
1382 else if(newPartChar < oldPartChar) //ints are the same, chars is lower -> false
1383 return false;
1384 //all the same, next section
1385 }
1386 // all the same -> false
1387 return false;
1388}
diff --git a/rbutil/rbutilqt/rbutilqt.h b/rbutil/rbutilqt/rbutilqt.h
index 76747bca07..42656540e6 100644
--- a/rbutil/rbutilqt/rbutilqt.h
+++ b/rbutil/rbutilqt/rbutilqt.h
@@ -113,7 +113,6 @@ class RbUtilQt : public QMainWindow
113 113
114 void checkUpdate(void); 114 void checkUpdate(void);
115 void downloadUpdateDone(bool errror); 115 void downloadUpdateDone(bool errror);
116 bool newerVersion(QString versionOld,QString versionNew);
117}; 116};
118 117
119#endif 118#endif