From 293a4b62d7220f855cb4d13f79b8ff97467f0242 Mon Sep 17 00:00:00 2001 From: Dominik Wenger Date: Fri, 18 Sep 2009 22:28:09 +0000 Subject: rbutil: check for new Versions at startup. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@22734 a1c6a512-1295-4272-9138-f99709370657 --- rbutil/rbutilqt/base/rbsettings.cpp | 1 + rbutil/rbutilqt/base/rbsettings.h | 1 + rbutil/rbutilqt/rbutil.ini | 1 + rbutil/rbutilqt/rbutilqt.cpp | 139 +++++++++++++++++++++++++++++++++++- rbutil/rbutilqt/rbutilqt.h | 5 ++ 5 files changed, 146 insertions(+), 1 deletion(-) (limited to 'rbutil/rbutilqt') diff --git a/rbutil/rbutilqt/base/rbsettings.cpp b/rbutil/rbutilqt/base/rbsettings.cpp index 116f321a4c..b1c6500ed2 100644 --- a/rbutil/rbutilqt/base/rbsettings.cpp +++ b/rbutil/rbutilqt/base/rbsettings.cpp @@ -44,6 +44,7 @@ const static struct { { RbSettings::ServerConfUrl, "server_conf_url", "" }, { RbSettings::GenlangUrl, "genlang_url", "" }, { RbSettings::ThemesUrl, "themes_url", "" }, + { RbSettings::RbutilUrl, "rbutil_url", "" }, { RbSettings::BleedingInfo, "bleeding_info", "" }, { RbSettings::CurPlatformName, ":platform:/name", "" }, { RbSettings::CurManual, ":platform:/manualname","rockbox-:platform:" }, diff --git a/rbutil/rbutilqt/base/rbsettings.h b/rbutil/rbutilqt/base/rbsettings.h index e178be0e52..b3f0430208 100644 --- a/rbutil/rbutilqt/base/rbsettings.h +++ b/rbutil/rbutilqt/base/rbsettings.h @@ -83,6 +83,7 @@ class RbSettings : public QObject ServerConfUrl, GenlangUrl, ThemesUrl, + RbutilUrl, BleedingInfo, CurPlatformName, CurManual, diff --git a/rbutil/rbutilqt/rbutil.ini b/rbutil/rbutilqt/rbutil.ini index ca27dba437..f082163411 100644 --- a/rbutil/rbutilqt/rbutil.ini +++ b/rbutil/rbutilqt/rbutil.ini @@ -13,6 +13,7 @@ manual_url=http://download.rockbox.org/daily/manual doom_url=http://download.rockbox.org/useful/rockdoom.zip voice_url=http://download.rockbox.org/daily/voices/ genlang_url=http://www.rockbox.org/genlang/ +rbutil_url=http://download.rockbox.org/rbutil/ [platforms] platform01=player diff --git a/rbutil/rbutilqt/rbutilqt.cpp b/rbutil/rbutilqt/rbutilqt.cpp index ec06955eef..083d35d8d9 100644 --- a/rbutil/rbutilqt/rbutilqt.cpp +++ b/rbutil/rbutilqt/rbutilqt.cpp @@ -212,7 +212,7 @@ void RbUtilQt::downloadDone(bool error) bleeding = new HttpGet(this); connect(bleeding, SIGNAL(done(bool)), this, SLOT(downloadBleedingDone(bool))); connect(bleeding, SIGNAL(requestFinished(int, bool)), this, SLOT(downloadDone(int, bool))); - connect(qApp, SIGNAL(lastWindowClosed()), daily, SLOT(abort())); + connect(qApp, SIGNAL(lastWindowClosed()), bleeding, SLOT(abort())); if(RbSettings::value(RbSettings::CacheOffline).toBool()) bleeding->setCache(true); bleeding->setFile(&bleedingInfo); @@ -251,6 +251,9 @@ void RbUtilQt::downloadBleedingDone(bool error) qDebug() << "[RbUtil] version map:" << versmap; m_gotInfo = true; + + //start check for updates + checkUpdate(); } } @@ -1217,4 +1220,138 @@ bool RbUtilQt::chkConfig(bool warn) return error; } +void RbUtilQt::checkUpdate(void) +{ + QString url = RbSettings::value(RbSettings::RbutilUrl).toString(); +#if defined(Q_OS_WIN32) + url += "win32/"; +#elif defined(Q_OS_LINUX) + url += "linux/"; +#elif defined(Q_OS_MACX) + url += "macosx/"; +#endif + + update = new HttpGet(this); + connect(update, SIGNAL(done(bool)), this, SLOT(downloadUpdateDone(bool))); + connect(update, SIGNAL(requestFinished(int, bool)), this, SLOT(downloadDone(int, bool))); + connect(qApp, SIGNAL(lastWindowClosed()), update, SLOT(abort())); + if(RbSettings::value(RbSettings::CacheOffline).toBool()) + update->setCache(true); + + update->getFile(QUrl(url)); +} +void RbUtilQt::downloadUpdateDone(bool error) +{ + if(error) { + qDebug() << "[RbUtil] network error:" << update->error(); + } + else { + QString toParse(update->readAll()); + qDebug() << "[Checkupdate] " << toParse; + + QRegExp searchString("]*>(rbutilqt[^<]*)"); + QStringList rbutilList; + int pos = 0; + while ((pos = searchString.indexIn(toParse, pos)) != -1) + { + rbutilList << searchString.cap(1); + pos += searchString.matchedLength(); + } + + QString newVersion =""; + //check if there is a binary with higher version in this list + for(int i=0; i < rbutilList.size(); i++) + { +#if defined(Q_OS_LINUX) +#if defined(__amd64__) + //skip if it isnt a 64bit build + if( !rbutilList.at(i).contains("64bit")) + continue; +#else + //skip if it is a 64bit build + if(rbutilList.at(i).contains("64bit")) + continue; +#endif +#endif + //check if it is newer, and remember newest + if(newerVersion(VERSION,rbutilList.at(i))) + { + if(newVersion == "" || newerVersion(newVersion,rbutilList.at(i))) + { + newVersion = rbutilList.at(i); + } + } + } + + // if we found something newer, display info + if(newVersion != "") + { + QString url = RbSettings::value(RbSettings::RbutilUrl).toString(); +#if defined(Q_OS_WIN32) + url += "win32/"; +#elif defined(Q_OS_LINUX) + url += "linux/"; +#elif defined(Q_OS_MACX) + url += "macosx/"; +#endif + url += newVersion; + + QMessageBox::information(this,tr("RockboxUtility Update available"), + tr("New RockboxUtility Version available.

" + "Download it from here: %2").arg(url).arg(newVersion) ); + } + } +} + +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 b5368c9ae3..31bae73630 100644 --- a/rbutil/rbutilqt/rbutilqt.h +++ b/rbutil/rbutilqt/rbutilqt.h @@ -47,6 +47,7 @@ class RbUtilQt : public QMainWindow QString platform; HttpGet *daily; HttpGet *bleeding; + HttpGet *update; QString absolutePath; QTemporaryFile buildInfo; QTemporaryFile bleedingInfo; @@ -110,6 +111,10 @@ class RbUtilQt : public QMainWindow void installPortable(void); void updateInfo(void); void updateTabs(int); + + void checkUpdate(void); + void downloadUpdateDone(bool errror); + bool newerVersion(QString versionOld,QString versionNew); }; #endif -- cgit v1.2.3