summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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)
else
return text;
}
+/** @brief Compare two version strings.
+ * @param s1 first version string
+ * @param s2 second version string
+ * @return 0 if strings identical, 1 if second is newer, -1 if first.
+ */
+int Utils::compareVersionStrings(QString s1, QString s2)
+{
+ QString a = s1.trimmed();
+ QString b = s2.trimmed();
+ qDebug() << "[Utils] comparing version strings" << a << "and" << b;
+ // if strings are identical return 0.
+ if(a.isEmpty())
+ return 1;
+ if(b.isEmpty())
+ return -1;
+
+ while(!a.isEmpty() || !b.isEmpty()) {
+ // trim all leading non-digits and non-dots (dots are removed afterwards)
+ a.remove(QRegExp("^[^\\d\\.]*"));
+ b.remove(QRegExp("^[^\\d\\.]*"));
+
+ // trim all trailing non-digits for conversion (QString::toInt()
+ // requires this). Copy strings first as replace() changes the string.
+ QString numa = a;
+ QString numb = b;
+ numa.remove(QRegExp("\\D+.*$"));
+ numb.remove(QRegExp("\\D+.*$"));
+
+ // convert to number
+ bool ok1, ok2;
+ int vala = numa.toUInt(&ok1);
+ int valb = numb.toUInt(&ok2);
+ // if none of the numbers converted successfully we're at trailing garbage.
+ if(!ok1 && !ok2)
+ break;
+ if(!ok1)
+ return 1;
+ if(!ok2)
+ return -1;
+
+ // if numbers mismatch we have a decision.
+ if(vala != valb)
+ return (vala > valb) ? -1 : 1;
+
+ // trim leading digits.
+ a.remove(QRegExp("^\\d*"));
+ b.remove(QRegExp("^\\d*"));
+
+ // if number is immediately followed by a character consider it as
+ // version addon (like 1.2.3b). In this case compare characters too.
+ QChar ltra;
+ QChar ltrb;
+ if(a.contains(QRegExp("^[a-zA-Z]")))
+ ltra = a.at(0);
+ if(b.contains(QRegExp("^[a-zA-Z]")))
+ ltrb = b.at(0);
+ if(ltra != ltrb)
+ return (ltra < ltrb) ? 1 : -1;
+ // both are identical or no addon characters, ignore.
+ // remove modifiers and following dot.
+ a.remove(QRegExp("^[a-zA-Z]*\\."));
+ b.remove(QRegExp("^[a-zA-Z]*\\."));
+ }
+
+ // no differences found.
+ return 0;
+}
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:
static qulonglong filesystemFree(QString path);
static QString findExecutable(QString name);
static QString checkEnvironment(bool permission);
+ static int compareVersionStrings(QString s1, QString s2);
};
#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)
if(RbSettings::value(RbSettings::CacheOffline).toBool())
update->setCache(true);
+ ui.statusbar->showMessage(tr("Checking for update ..."));
update->getFile(QUrl(url));
}
@@ -1290,7 +1291,7 @@ void RbUtilQt::downloadUpdateDone(bool error)
}
qDebug() << "[Checkupdate] " << rbutilList;
- QString newVersion ="";
+ QString newVersion = "";
//check if there is a binary with higher version in this list
for(int i=0; i < rbutilList.size(); i++)
{
@@ -1306,9 +1307,9 @@ void RbUtilQt::downloadUpdateDone(bool error)
#endif
#endif
//check if it is newer, and remember newest
- if(newerVersion(VERSION,rbutilList.at(i)))
+ if(Utils::compareVersionStrings(VERSION, rbutilList.at(i)) == 1)
{
- if(newVersion == "" || newerVersion(newVersion,rbutilList.at(i)))
+ if(Utils::compareVersionStrings(newVersion, rbutilList.at(i)) == 1)
{
newVersion = rbutilList.at(i);
}
@@ -1331,58 +1332,11 @@ void RbUtilQt::downloadUpdateDone(bool error)
QMessageBox::information(this,tr("RockboxUtility Update available"),
tr("<b>New RockboxUtility Version available.</b> <br><br>"
"Download it from here: <a href='%1'>%2</a>").arg(url).arg(newVersion) );
+ ui.statusbar->showMessage(tr("New version of Rockbox Utility available."));
+ }
+ else {
+ ui.statusbar->showMessage(tr("Rockbox Utility is up to date."), 5000);
}
}
}
-bool RbUtilQt::newerVersion(QString versionOld,QString versionNew)
-{
- QRegExp chars("\\d*(\\D)");
-
- //strip non-number from beginning
- versionOld = versionOld.remove(0,versionOld.indexOf(QRegExp("\\d")));
- versionNew = versionNew.remove(0,versionNew.indexOf(QRegExp("\\d")));
-
- // split versions by "."
- QStringList versionListOld = versionOld.split(".");
- QStringList versionListNew = versionNew.split(".");
-
- QStringListIterator iteratorOld(versionListOld);
- QStringListIterator iteratorNew(versionListNew);
-
- //check every section
- while(iteratorOld.hasNext() && iteratorNew.hasNext())
- {
- QString newPart = iteratorNew.next();
- QString oldPart = iteratorOld.next();
- QString newPartChar = "", oldPartChar = "";
- int newPartInt = 0, oldPartInt =0;
-
- //convert to int, if it contains chars, put into seperated variable
- if(newPart.contains(chars))
- {
- newPartChar = chars.cap(1);
- newPart = newPart.remove(newPartChar);
- }
- newPartInt = newPart.toInt();
- //convert to int, if it contains chars, put into seperated variable
- if(oldPart.contains(chars))
- {
- oldPartChar = chars.cap(1);
- oldPart = oldPart.remove(oldPartChar);
- }
- oldPartInt = oldPart.toInt();
-
- if(newPartInt > oldPartInt) // this section int is higher -> true
- return true;
- else if(newPartInt < oldPartInt) //this section int is lower -> false
- return false;
- else if(newPartChar > oldPartChar) //ints are the same, chars is higher -> true
- return true;
- else if(newPartChar < oldPartChar) //ints are the same, chars is lower -> false
- return false;
- //all the same, next section
- }
- // all the same -> false
- return false;
-}
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
void checkUpdate(void);
void downloadUpdateDone(bool errror);
- bool newerVersion(QString versionOld,QString versionNew);
};
#endif