2014-11-21 17:11:57 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// MuldeR's Utilities for Qt
|
2021-02-08 20:59:25 +01:00
|
|
|
// Copyright (C) 2004-2021 LoRd_MuldeR <MuldeR2@GMX.de>
|
2014-11-21 17:11:57 +01:00
|
|
|
//
|
|
|
|
// This library is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Lesser General Public
|
|
|
|
// License as published by the Free Software Foundation; either
|
|
|
|
// version 2.1 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This library 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
|
|
|
|
// Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
// License along with this library; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
//
|
|
|
|
// http://www.gnu.org/licenses/lgpl-2.1.txt
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2014-11-24 19:35:32 +01:00
|
|
|
//MUtils
|
|
|
|
#include <MUtils/Global.h>
|
|
|
|
|
|
|
|
//Qt
|
2014-11-21 17:11:57 +01:00
|
|
|
#include <QThread>
|
|
|
|
#include <QDate>
|
|
|
|
|
2018-10-16 23:18:00 +02:00
|
|
|
class QUrl;
|
|
|
|
|
2014-11-21 17:11:57 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2014-11-21 17:54:46 +01:00
|
|
|
namespace MUtils
|
|
|
|
{
|
2014-11-24 19:35:32 +01:00
|
|
|
class MUTILS_API UpdateCheckerInfo
|
2014-11-21 17:11:57 +01:00
|
|
|
{
|
|
|
|
friend class UpdateChecker;
|
|
|
|
|
|
|
|
public:
|
|
|
|
UpdateCheckerInfo(void);
|
|
|
|
void resetInfo(void);
|
2015-08-16 16:27:43 +02:00
|
|
|
bool isComplete(void);
|
2014-11-21 17:11:57 +01:00
|
|
|
|
|
|
|
const quint32 &getBuildNo(void) const { return m_buildNo; }
|
|
|
|
const QDate &getBuildDate(void) const { return m_buildDate; }
|
|
|
|
const QString &getDownloadSite(void) const { return m_downloadSite; }
|
|
|
|
const QString &getDownloadAddress(void) const { return m_downloadAddress; }
|
|
|
|
const QString &getDownloadFilename(void) const { return m_downloadFilename; }
|
|
|
|
const QString &getDownloadFilecode(void) const { return m_downloadFilecode; }
|
2015-08-16 16:27:43 +02:00
|
|
|
const QString &getDownloadChecksum(void) const { return m_downloadChecksum; }
|
2014-11-21 17:11:57 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
quint32 m_buildNo;
|
|
|
|
QDate m_buildDate;
|
|
|
|
QString m_downloadSite;
|
|
|
|
QString m_downloadAddress;
|
|
|
|
QString m_downloadFilename;
|
|
|
|
QString m_downloadFilecode;
|
2015-08-16 16:27:43 +02:00
|
|
|
QString m_downloadChecksum;
|
2014-11-21 17:11:57 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------
|
|
|
|
|
2014-11-24 19:35:32 +01:00
|
|
|
class MUTILS_API UpdateChecker : public QThread
|
2014-11-21 17:11:57 +01:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
UpdateStatus_NotStartedYet = 0,
|
|
|
|
UpdateStatus_CheckingConnection = 1,
|
|
|
|
UpdateStatus_FetchingUpdates = 2,
|
|
|
|
UpdateStatus_CompletedUpdateAvailable = 3,
|
|
|
|
UpdateStatus_CompletedNoUpdates = 4,
|
|
|
|
UpdateStatus_CompletedNewVersionOlder = 5,
|
|
|
|
UpdateStatus_ErrorNoConnection = 6,
|
|
|
|
UpdateStatus_ErrorConnectionTestFailed = 7,
|
2017-03-28 21:13:14 +02:00
|
|
|
UpdateStatus_ErrorFetchUpdateInfo = 8,
|
|
|
|
UpdateStatus_CancelledByUser = 9
|
2014-11-21 17:11:57 +01:00
|
|
|
}
|
|
|
|
update_status_t;
|
|
|
|
|
2021-06-27 21:21:22 +02:00
|
|
|
UpdateChecker(const QString &binCurl, const QString &binVerify, const QString &applicationId, const quint32 &installedBuildNo, const bool betaUpdates, const bool testMode = false);
|
2014-11-21 17:11:57 +01:00
|
|
|
~UpdateChecker(void);
|
|
|
|
|
2015-08-16 16:27:43 +02:00
|
|
|
const int getUpdateStatus(void) const { return m_status; }
|
|
|
|
const bool getSuccess(void) const { return m_success; };
|
|
|
|
const int getMaximumProgress(void) const { return m_maxProgress; };
|
|
|
|
const int getCurrentProgress(void) const { return m_progress; };
|
|
|
|
const UpdateCheckerInfo *getUpdateInfo(void) const { return m_updateInfo.data(); }
|
2014-11-21 17:11:57 +01:00
|
|
|
|
2017-04-18 21:03:38 +02:00
|
|
|
bool cancel(void) { return m_cancelled.ref(); }
|
2017-03-28 21:13:14 +02:00
|
|
|
|
|
|
|
public slots:
|
|
|
|
void start(Priority = InheritPriority);
|
|
|
|
|
2014-11-21 17:11:57 +01:00
|
|
|
protected:
|
|
|
|
void run(void);
|
|
|
|
void checkForUpdates(void);
|
2017-11-26 15:22:37 +01:00
|
|
|
void testMirrorsList(void);
|
2014-11-21 17:11:57 +01:00
|
|
|
|
|
|
|
signals:
|
|
|
|
void statusChanged(const int status);
|
|
|
|
void progressChanged(const int progress);
|
|
|
|
void messageLogged(const QString &text);
|
|
|
|
|
|
|
|
private:
|
|
|
|
const int m_maxProgress;
|
2015-08-16 16:27:43 +02:00
|
|
|
QScopedPointer<UpdateCheckerInfo> m_updateInfo;
|
2014-11-21 17:11:57 +01:00
|
|
|
|
|
|
|
const bool m_betaUpdates;
|
|
|
|
const bool m_testMode;
|
|
|
|
|
2014-11-21 20:56:36 +01:00
|
|
|
const QString m_applicationId;
|
2014-11-21 19:51:21 +01:00
|
|
|
const quint32 m_installedBuildNo;
|
|
|
|
|
2018-10-15 23:26:36 +02:00
|
|
|
const QString m_binaryCurl;
|
2021-06-27 21:21:22 +02:00
|
|
|
const QString m_binaryVerify;
|
2014-11-21 17:11:57 +01:00
|
|
|
|
2018-10-15 23:26:36 +02:00
|
|
|
const QScopedPointer<const QHash<QString, QString>> m_environment;
|
|
|
|
|
2017-04-19 23:51:17 +02:00
|
|
|
QAtomicInt m_success;
|
2017-04-18 21:03:38 +02:00
|
|
|
QAtomicInt m_cancelled;
|
2014-11-21 17:11:57 +01:00
|
|
|
|
|
|
|
int m_status;
|
|
|
|
int m_progress;
|
|
|
|
|
|
|
|
inline void setStatus(const int status);
|
|
|
|
inline void setProgress(const int progress);
|
|
|
|
inline void log(const QString &str1, const QString &str2 = QString(), const QString &str3 = QString(), const QString &str4 = QString());
|
|
|
|
|
2016-04-23 13:25:01 +02:00
|
|
|
bool getUpdateInfo(const QString &url, const QString &outFileVers, const QString &outFileSign);
|
2018-10-15 23:26:36 +02:00
|
|
|
bool tryContactHost(const QString &hostname, const int &timeoutMsec);
|
2018-10-18 22:26:01 +02:00
|
|
|
bool parseVersionInfo(const QString &file, UpdateCheckerInfo *const updateInfo);
|
2016-04-23 13:25:01 +02:00
|
|
|
|
2018-10-16 23:18:00 +02:00
|
|
|
bool getFile(const QUrl &url, const QString &outFile, const unsigned int maxRedir = 8U);
|
2014-11-21 17:11:57 +01:00
|
|
|
bool checkSignature(const QString &file, const QString &signature);
|
2017-03-29 21:39:05 +02:00
|
|
|
bool tryUpdateMirror(UpdateCheckerInfo *updateInfo, const QString &url, const bool &quick);
|
2018-10-16 23:18:00 +02:00
|
|
|
|
2018-10-17 21:26:47 +02:00
|
|
|
bool execCurl(const QStringList &args, const QString &workingDir, const int timeout);
|
|
|
|
int execProcess(const QString &programFile, const QStringList &args, const QString &workingDir, const int timeout);
|
2014-11-21 17:11:57 +01:00
|
|
|
};
|
|
|
|
}
|