mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-11 15:27:54 +00:00
Change update URL to FossHub. Closes #4188.
This commit is contained in:
parent
9e20553dab
commit
970e21fc33
@ -42,14 +42,19 @@
|
|||||||
#include "base/utils/fs.h"
|
#include "base/utils/fs.h"
|
||||||
#include "base/preferences.h"
|
#include "base/preferences.h"
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
const QUrl RSS_URL("http://www.fosshub.com/software/feedqBittorent");
|
||||||
|
|
||||||
#ifdef Q_OS_MAC
|
#ifdef Q_OS_MAC
|
||||||
const QUrl RSS_URL("http://sourceforge.net/projects/qbittorrent/rss?path=/qbittorrent-mac");
|
const QString OS_TYPE("Mac OS X");
|
||||||
const QString FILE_EXT = "DMG";
|
|
||||||
#else
|
#else
|
||||||
const QUrl RSS_URL("http://sourceforge.net/projects/qbittorrent/rss?path=/qbittorrent-win32");
|
const QString OS_TYPE("Windows");
|
||||||
const QString FILE_EXT = "EXE";
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
QString getStringValue(QXmlStreamReader &xml);
|
||||||
|
}
|
||||||
|
|
||||||
ProgramUpdater::ProgramUpdater(QObject *parent, bool invokedByUser)
|
ProgramUpdater::ProgramUpdater(QObject *parent, bool invokedByUser)
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
, m_invokedByUser(invokedByUser)
|
, m_invokedByUser(invokedByUser)
|
||||||
@ -91,66 +96,60 @@ void ProgramUpdater::checkForUpdates()
|
|||||||
this, SLOT(rssDownloadFinished(QNetworkReply*)));
|
this, SLOT(rssDownloadFinished(QNetworkReply*)));
|
||||||
// Send the request
|
// Send the request
|
||||||
QNetworkRequest request(RSS_URL);
|
QNetworkRequest request(RSS_URL);
|
||||||
|
// Don't change this User-Agent. In case our updater goes haywire, the filehost can indetify it and contact us.
|
||||||
request.setRawHeader("User-Agent", QString("qBittorrent/%1 ProgramUpdater (www.qbittorrent.org)").arg(VERSION).toLocal8Bit());
|
request.setRawHeader("User-Agent", QString("qBittorrent/%1 ProgramUpdater (www.qbittorrent.org)").arg(VERSION).toLocal8Bit());
|
||||||
m_networkManager->get(request);
|
m_networkManager->get(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProgramUpdater::setUpdateUrl(QString title)
|
|
||||||
{
|
|
||||||
m_updateUrl = "http://downloads.sourceforge.net/project/qbittorrent" + title;
|
|
||||||
qDebug("The Update URL is %s", qPrintable(m_updateUrl));
|
|
||||||
}
|
|
||||||
|
|
||||||
void ProgramUpdater::rssDownloadFinished(QNetworkReply *reply)
|
void ProgramUpdater::rssDownloadFinished(QNetworkReply *reply)
|
||||||
{
|
{
|
||||||
// Disconnect SIGNAL/SLOT
|
// Disconnect SIGNAL/SLOT
|
||||||
disconnect(m_networkManager, 0, this, 0);
|
disconnect(m_networkManager, 0, this, 0);
|
||||||
qDebug("Finished downloading the new qBittorrent updates RSS");
|
qDebug("Finished downloading the new qBittorrent updates RSS");
|
||||||
QString new_version;
|
QString version;
|
||||||
|
|
||||||
if (!reply->error()) {
|
if (!reply->error()) {
|
||||||
qDebug("No download error, good.");
|
qDebug("No download error, good.");
|
||||||
QXmlStreamReader xml(reply);
|
QXmlStreamReader xml(reply);
|
||||||
QString item_title;
|
bool inItem = false;
|
||||||
bool in_title = false;
|
QString updateLink;
|
||||||
bool in_item = false;
|
QString type;
|
||||||
|
|
||||||
while (!xml.atEnd()) {
|
while (!xml.atEnd()) {
|
||||||
xml.readNext();
|
xml.readNext();
|
||||||
|
|
||||||
if (xml.isStartElement()) {
|
if (xml.isStartElement()) {
|
||||||
if (in_item && xml.name() == "title") {
|
if (xml.name() == "item")
|
||||||
in_title = true;
|
inItem = true;
|
||||||
item_title = "";
|
else if (inItem && xml.name() == "link")
|
||||||
}
|
updateLink = getStringValue(xml);
|
||||||
else if (xml.name() == "item") {
|
else if (inItem && xml.name() == "type")
|
||||||
in_item = true;
|
type = getStringValue(xml);
|
||||||
}
|
else if (inItem && xml.name() == "version")
|
||||||
|
version = getStringValue(xml);
|
||||||
}
|
}
|
||||||
else if (xml.isEndElement()) {
|
else if (xml.isEndElement()) {
|
||||||
if (in_item && xml.name() == "title") {
|
if (inItem && xml.name() == "item") {
|
||||||
in_title = false;
|
if (type.compare(OS_TYPE, Qt::CaseInsensitive) == 0) {
|
||||||
const QString ext = Utils::Fs::fileExtension(item_title).toUpper();
|
qDebug("The last update available is %s", qPrintable(version));
|
||||||
qDebug("Found an update with file extension: %s", qPrintable(ext));
|
if (!version.isEmpty()) {
|
||||||
if (ext == FILE_EXT) {
|
qDebug("Detected version is %s", qPrintable(version));
|
||||||
qDebug("The last update available is %s", qPrintable(item_title));
|
if (isVersionMoreRecent(version))
|
||||||
new_version = extractVersionNumber(item_title);
|
m_updateUrl = updateLink;
|
||||||
if (!new_version.isEmpty()) {
|
|
||||||
qDebug("Detected version is %s", qPrintable(new_version));
|
|
||||||
if (isVersionMoreRecent(new_version))
|
|
||||||
setUpdateUrl(item_title);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inItem = false;
|
||||||
|
updateLink.clear();
|
||||||
|
type.clear();
|
||||||
|
version.clear();
|
||||||
}
|
}
|
||||||
else if (xml.name() == "item") {
|
|
||||||
in_item = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (xml.isCharacters() && !xml.isWhitespace()) {
|
|
||||||
if (in_item && in_title)
|
|
||||||
item_title += xml.text().toString();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
emit updateCheckFinished(!m_updateUrl.isEmpty(), new_version, m_invokedByUser);
|
|
||||||
|
emit updateCheckFinished(!m_updateUrl.isEmpty(), version, m_invokedByUser);
|
||||||
// Clean up
|
// Clean up
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
}
|
}
|
||||||
@ -162,23 +161,6 @@ void ProgramUpdater::updateProgram()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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
|
|
||||||
QString ProgramUpdater::extractVersionNumber(const QString& title) const
|
|
||||||
{
|
|
||||||
qDebug() << Q_FUNC_INFO << title;
|
|
||||||
QRegExp regVer("qbittorrent[_-]([0-9.]+)(_setup)?(\\.exe|\\.dmg)");
|
|
||||||
if (regVer.indexIn(title) < 0) {
|
|
||||||
qWarning() << Q_FUNC_INFO << "Failed to extract version from file name:" << title;
|
|
||||||
return QString::null;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
QString version = regVer.cap(1);
|
|
||||||
qDebug() << Q_FUNC_INFO << "Extracted version:" << version;
|
|
||||||
return version;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ProgramUpdater::isVersionMoreRecent(const QString &remoteVersion) const
|
bool ProgramUpdater::isVersionMoreRecent(const QString &remoteVersion) const
|
||||||
{
|
{
|
||||||
QRegExp regVer("([0-9.]+)");
|
QRegExp regVer("([0-9.]+)");
|
||||||
@ -204,3 +186,14 @@ bool ProgramUpdater::isVersionMoreRecent(const QString &remoteVersion) const
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
QString getStringValue(QXmlStreamReader &xml)
|
||||||
|
{
|
||||||
|
xml.readNext();
|
||||||
|
if (xml.isCharacters() && !xml.isWhitespace())
|
||||||
|
return xml.text().toString();
|
||||||
|
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -47,12 +47,10 @@ public:
|
|||||||
void updateProgram();
|
void updateProgram();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QString extractVersionNumber(const QString& title) const;
|
|
||||||
bool isVersionMoreRecent(const QString &remoteVersion) const;
|
bool isVersionMoreRecent(const QString &remoteVersion) const;
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
void rssDownloadFinished(QNetworkReply* reply);
|
void rssDownloadFinished(QNetworkReply* reply);
|
||||||
void setUpdateUrl(QString title);
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void updateCheckFinished(bool updateAvailable, QString version, bool invokedByUser);
|
void updateCheckFinished(bool updateAvailable, QString version, bool invokedByUser);
|
||||||
|
Loading…
Reference in New Issue
Block a user