mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-03-10 12:21:12 +00:00
Program updater: More reliable version detection / comparison
This commit is contained in:
parent
78bb4104b0
commit
c0eb048fe2
@ -196,40 +196,42 @@ void ProgramUpdater::updateProgram()
|
|||||||
|
|
||||||
// title on Windows: /qbittorrent-win32/qbittorrent-2.4.7/qbittorrent_2.4.7_setup.exe
|
// title on Windows: /qbittorrent-win32/qbittorrent-2.4.7/qbittorrent_2.4.7_setup.exe
|
||||||
// title on Mac: /qbittorrent-mac/qbittorrent-2.4.4/qbittorrent-2.4.4.dmg
|
// title on Mac: /qbittorrent-mac/qbittorrent-2.4.4/qbittorrent-2.4.4.dmg
|
||||||
QString ProgramUpdater::extractVersionNumber(QString title) const
|
QString ProgramUpdater::extractVersionNumber(const QString& title) const
|
||||||
{
|
{
|
||||||
QString version;
|
qDebug() << Q_FUNC_INFO << title;
|
||||||
QStringList parts = title.split("/");
|
QRegExp regVer("qbittorrent[_-]([0-9.]+)(_setup)?(\\.exe|\\.dmg)");
|
||||||
if(parts.size() != 4) {
|
if (regVer.indexIn(title) < 0) {
|
||||||
qDebug("ProgramUpdater: Unrecognized title: %s", qPrintable(title));
|
qWarning() << Q_FUNC_INFO << "Failed to extract version from file name:" << title;
|
||||||
return version;
|
|
||||||
}
|
|
||||||
QString folder = parts.at(2);
|
|
||||||
if(!folder.contains("-")) {
|
|
||||||
qDebug("ProgramUpdater: Unrecognized folder name: %s", qPrintable(folder));
|
|
||||||
return version;
|
|
||||||
}
|
|
||||||
version = folder.mid(folder.lastIndexOf("-")+1);
|
|
||||||
if(version.split(".").size() != 3) {
|
|
||||||
qDebug("ProgramUpdater: Unrecognized version format: %s", qPrintable(version));
|
|
||||||
return QString::null;
|
return QString::null;
|
||||||
|
} else {
|
||||||
|
QString version = regVer.cap(1);
|
||||||
|
qDebug() << Q_FUNC_INFO << "Extracted version:" << version;
|
||||||
|
return version;
|
||||||
}
|
}
|
||||||
return version;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ProgramUpdater::isVersionMoreRecent(QString new_version) const
|
bool ProgramUpdater::isVersionMoreRecent(const QString& remote_version) const
|
||||||
{
|
{
|
||||||
const QStringList parts = new_version.split(".");
|
QRegExp regVer("([0-9.]+)");
|
||||||
Q_ASSERT(parts.size() == 3);
|
if (regVer.indexIn(QString(VERSION)) >= 0) {
|
||||||
const int major = parts.at(0).toInt();
|
QString local_version = regVer.cap(1);
|
||||||
const int minor = parts.at(1).toInt();
|
qDebug() << Q_FUNC_INFO << "local version:" << local_version << "/" << VERSION;
|
||||||
const int bugfix = parts.at(2).toInt();
|
QStringList remote_parts = remote_version.split('.');
|
||||||
if(major < VERSION_MAJOR)
|
QStringList local_parts = local_version.split('.');
|
||||||
return false;
|
for (int i=0; i<qMin(remote_parts.size(), local_parts.size()); ++i) {
|
||||||
if(minor < VERSION_MINOR)
|
if (remote_parts[i].toInt() > local_parts[i].toInt())
|
||||||
return false;
|
return true;
|
||||||
if(bugfix <= VERSION_BUGFIX)
|
if (remote_parts[i].toInt() < local_parts[i].toInt())
|
||||||
return false;
|
return false;
|
||||||
return true;
|
}
|
||||||
|
// Compared parts were equal, if remote version is longer, then it's more recent (2.9.2.1 > 2.9.2)
|
||||||
|
if (remote_parts.size() > local_parts.size())
|
||||||
|
return true;
|
||||||
|
// versions are equal, check if the local version is a development release, in which case it is older (2.9.2beta < 2.9.2)
|
||||||
|
QRegExp regDevel("(alpha|beta|rc)");
|
||||||
|
if (regDevel.indexIn(VERSION) >= 0)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,8 +47,8 @@ public:
|
|||||||
void updateProgram();
|
void updateProgram();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QString extractVersionNumber(QString title) const;
|
QString extractVersionNumber(const QString& title) const;
|
||||||
bool isVersionMoreRecent(QString new_version) const;
|
bool isVersionMoreRecent(const QString& new_version) const;
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
void rssDownloadFinished(QNetworkReply* reply);
|
void rssDownloadFinished(QNetworkReply* reply);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user