2010-10-24 01:46:05 +04:00
|
|
|
/*
|
2018-06-06 16:48:17 +03:00
|
|
|
* Bittorrent Client using Qt and libtorrent.
|
2021-01-25 10:49:29 +03:00
|
|
|
* Copyright (C) 2021 Mike Tzou (Chocobo1)
|
2018-05-24 18:39:02 +03:00
|
|
|
* Copyright (C) 2010 Christophe Dumez <chris@qbittorrent.org>
|
2010-10-24 01:46:05 +04:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* In addition, as a special exception, the copyright holders give permission to
|
|
|
|
* link this program with the OpenSSL project's "OpenSSL" library (or with
|
|
|
|
* modified versions of it that use the same license as the "OpenSSL" library),
|
|
|
|
* and distribute the linked executables. You must obey the GNU General Public
|
|
|
|
* License in all respects for all of the code used other than "OpenSSL". If you
|
|
|
|
* modify file(s), you may extend this exception to your version of the file(s),
|
|
|
|
* but you are not obligated to do so. If you do not wish to do so, delete this
|
|
|
|
* exception statement from your version.
|
|
|
|
*/
|
|
|
|
|
2018-05-24 18:39:02 +03:00
|
|
|
#include "programupdater.h"
|
|
|
|
|
2019-07-25 20:21:53 +03:00
|
|
|
#if defined(Q_OS_WIN)
|
|
|
|
#include <Windows.h>
|
|
|
|
#include <versionhelpers.h> // must follow after Windows.h
|
|
|
|
#endif
|
|
|
|
|
2014-07-05 16:44:13 +04:00
|
|
|
#include <QDebug>
|
2018-05-24 18:39:02 +03:00
|
|
|
#include <QDesktopServices>
|
2018-05-24 18:41:03 +03:00
|
|
|
#include <QRegularExpression>
|
2018-05-24 18:39:02 +03:00
|
|
|
#include <QXmlStreamReader>
|
2010-10-24 01:46:05 +04:00
|
|
|
|
2019-07-25 20:21:53 +03:00
|
|
|
#if defined(Q_OS_WIN)
|
|
|
|
#include <QSysInfo>
|
|
|
|
#endif
|
|
|
|
|
2022-03-19 10:57:41 +03:00
|
|
|
#include "base/global.h"
|
2018-05-24 18:39:02 +03:00
|
|
|
#include "base/net/downloadmanager.h"
|
2021-01-23 08:47:43 +03:00
|
|
|
#include "base/utils/version.h"
|
2021-01-04 10:02:13 +03:00
|
|
|
#include "base/version.h"
|
2010-10-24 01:46:05 +04:00
|
|
|
|
2015-12-06 16:19:00 +03:00
|
|
|
namespace
|
|
|
|
{
|
2021-01-23 08:43:33 +03:00
|
|
|
bool isVersionMoreRecent(const QString &remoteVersion)
|
|
|
|
{
|
2021-01-23 08:47:43 +03:00
|
|
|
using Version = Utils::Version<int, 4, 3>;
|
2015-12-06 16:19:00 +03:00
|
|
|
|
2021-01-23 08:47:43 +03:00
|
|
|
try
|
|
|
|
{
|
|
|
|
const Version newVersion {remoteVersion};
|
|
|
|
const Version currentVersion {QBT_VERSION_MAJOR, QBT_VERSION_MINOR, QBT_VERSION_BUGFIX, QBT_VERSION_BUILD};
|
|
|
|
if (newVersion == currentVersion)
|
2021-01-23 08:43:33 +03:00
|
|
|
{
|
2022-03-29 05:41:17 +03:00
|
|
|
const bool isDevVersion = QStringLiteral(QBT_VERSION_STATUS).contains(
|
|
|
|
QRegularExpression(u"(alpha|beta|rc)"_qs));
|
2021-01-23 08:47:43 +03:00
|
|
|
if (isDevVersion)
|
2021-01-23 08:43:33 +03:00
|
|
|
return true;
|
|
|
|
}
|
2021-01-23 08:47:43 +03:00
|
|
|
return (newVersion > currentVersion);
|
|
|
|
}
|
2021-05-05 16:41:30 +03:00
|
|
|
catch (const RuntimeError &)
|
2021-01-23 08:47:43 +03:00
|
|
|
{
|
|
|
|
return false;
|
2021-01-23 08:43:33 +03:00
|
|
|
}
|
|
|
|
}
|
2015-12-06 16:19:00 +03:00
|
|
|
}
|
|
|
|
|
2021-01-23 08:43:33 +03:00
|
|
|
void ProgramUpdater::checkForUpdates() const
|
2010-10-24 01:46:05 +04:00
|
|
|
{
|
2022-03-29 05:41:17 +03:00
|
|
|
const auto RSS_URL = u"https://www.fosshub.com/feed/5b8793a7f9ee5a5c3e97a3b2.xml"_qs;
|
2018-06-25 20:31:32 +03:00
|
|
|
// Don't change this User-Agent. In case our updater goes haywire,
|
|
|
|
// the filehost can identify it and contact us.
|
2019-03-03 12:43:42 +03:00
|
|
|
Net::DownloadManager::instance()->download(
|
2022-03-19 10:57:41 +03:00
|
|
|
Net::DownloadRequest(RSS_URL).userAgent(QStringLiteral("qBittorrent/" QBT_VERSION_2 " ProgramUpdater (www.qbittorrent.org)"))
|
2021-01-23 08:43:33 +03:00
|
|
|
, this, &ProgramUpdater::rssDownloadFinished);
|
2010-10-24 01:46:05 +04:00
|
|
|
}
|
|
|
|
|
2021-01-25 10:49:29 +03:00
|
|
|
QString ProgramUpdater::getNewVersion() const
|
|
|
|
{
|
|
|
|
return m_newVersion;
|
|
|
|
}
|
|
|
|
|
2019-03-01 10:38:16 +03:00
|
|
|
void ProgramUpdater::rssDownloadFinished(const Net::DownloadResult &result)
|
2010-10-24 01:46:05 +04:00
|
|
|
{
|
2020-11-16 10:02:11 +03:00
|
|
|
if (result.status != Net::DownloadStatus::Success)
|
|
|
|
{
|
2019-03-01 10:38:16 +03:00
|
|
|
qDebug() << "Downloading the new qBittorrent updates RSS failed:" << result.errorString;
|
2021-01-25 10:49:29 +03:00
|
|
|
emit updateCheckFinished();
|
2019-03-01 10:38:16 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-12-06 14:14:07 +03:00
|
|
|
qDebug("Finished downloading the new qBittorrent updates RSS");
|
2015-12-06 16:19:00 +03:00
|
|
|
|
2021-01-23 08:43:33 +03:00
|
|
|
const auto getStringValue = [](QXmlStreamReader &xml) -> QString
|
|
|
|
{
|
|
|
|
xml.readNext();
|
|
|
|
return (xml.isCharacters() && !xml.isWhitespace())
|
|
|
|
? xml.text().toString()
|
|
|
|
: QString {};
|
|
|
|
};
|
|
|
|
|
2019-09-05 15:11:33 +03:00
|
|
|
#ifdef Q_OS_MACOS
|
2022-03-19 10:57:41 +03:00
|
|
|
const QString OS_TYPE = u"Mac OS X"_qs;
|
2018-08-04 17:22:35 +03:00
|
|
|
#elif defined(Q_OS_WIN)
|
2022-03-19 10:57:41 +03:00
|
|
|
const QString OS_TYPE = (::IsWindows7OrGreater() && QSysInfo::currentCpuArchitecture().endsWith(u"64"))
|
|
|
|
? u"Windows x64"_qs
|
|
|
|
: u"Windows"_qs;
|
2018-08-04 17:22:35 +03:00
|
|
|
#endif
|
|
|
|
|
2015-12-19 09:48:46 +03:00
|
|
|
bool inItem = false;
|
2021-01-25 10:49:29 +03:00
|
|
|
QString version;
|
2015-12-19 09:48:46 +03:00
|
|
|
QString updateLink;
|
|
|
|
QString type;
|
2021-01-25 10:49:29 +03:00
|
|
|
QXmlStreamReader xml(result.data);
|
2015-12-19 09:48:46 +03:00
|
|
|
|
2020-11-16 10:02:11 +03:00
|
|
|
while (!xml.atEnd())
|
|
|
|
{
|
2015-12-19 09:48:46 +03:00
|
|
|
xml.readNext();
|
|
|
|
|
2020-11-16 10:02:11 +03:00
|
|
|
if (xml.isStartElement())
|
|
|
|
{
|
2022-03-29 05:41:17 +03:00
|
|
|
if (xml.name() == u"item")
|
2015-12-19 09:48:46 +03:00
|
|
|
inItem = true;
|
2022-03-29 05:41:17 +03:00
|
|
|
else if (inItem && (xml.name() == u"link"))
|
2015-12-19 09:48:46 +03:00
|
|
|
updateLink = getStringValue(xml);
|
2022-03-29 05:41:17 +03:00
|
|
|
else if (inItem && (xml.name() == u"type"))
|
2015-12-19 09:48:46 +03:00
|
|
|
type = getStringValue(xml);
|
2022-03-29 05:41:17 +03:00
|
|
|
else if (inItem && (xml.name() == u"version"))
|
2015-12-19 09:48:46 +03:00
|
|
|
version = getStringValue(xml);
|
|
|
|
}
|
2020-11-16 10:02:11 +03:00
|
|
|
else if (xml.isEndElement())
|
|
|
|
{
|
2022-03-29 05:41:17 +03:00
|
|
|
if (inItem && (xml.name() == u"item"))
|
2020-11-16 10:02:11 +03:00
|
|
|
{
|
|
|
|
if (type.compare(OS_TYPE, Qt::CaseInsensitive) == 0)
|
|
|
|
{
|
2017-08-13 13:56:03 +03:00
|
|
|
qDebug("The last update available is %s", qUtf8Printable(version));
|
2020-11-16 10:02:11 +03:00
|
|
|
if (!version.isEmpty())
|
|
|
|
{
|
2017-08-13 13:56:03 +03:00
|
|
|
qDebug("Detected version is %s", qUtf8Printable(version));
|
2015-12-19 09:48:46 +03:00
|
|
|
if (isVersionMoreRecent(version))
|
2021-01-25 10:49:29 +03:00
|
|
|
{
|
|
|
|
m_newVersion = version;
|
|
|
|
m_updateURL = updateLink;
|
|
|
|
}
|
2015-12-06 14:14:07 +03:00
|
|
|
}
|
2015-12-19 09:48:46 +03:00
|
|
|
break;
|
2015-12-06 14:14:07 +03:00
|
|
|
}
|
2015-12-19 09:48:46 +03:00
|
|
|
|
|
|
|
inItem = false;
|
|
|
|
updateLink.clear();
|
|
|
|
type.clear();
|
|
|
|
version.clear();
|
2010-10-24 01:46:05 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-12-06 16:19:00 +03:00
|
|
|
|
2021-01-25 10:49:29 +03:00
|
|
|
emit updateCheckFinished();
|
2015-12-19 09:48:46 +03:00
|
|
|
}
|
|
|
|
|
2021-01-25 10:49:29 +03:00
|
|
|
bool ProgramUpdater::updateProgram() const
|
2010-10-24 01:46:05 +04:00
|
|
|
{
|
2021-01-25 10:49:29 +03:00
|
|
|
return QDesktopServices::openUrl(m_updateURL);
|
2015-12-06 16:19:00 +03:00
|
|
|
}
|