OSDN Git Service

Improved progress indicator + refactored update info parsing code.
[mutilities/MUtilities.git] / include / MUtils / UpdateChecker.h
index 4bc866c..155fa0f 100644 (file)
@@ -1,6 +1,6 @@
 ///////////////////////////////////////////////////////////////////////////////
 // MuldeR's Utilities for Qt
-// Copyright (C) 2004-2017 LoRd_MuldeR <MuldeR2@GMX.de>
+// Copyright (C) 2004-2018 LoRd_MuldeR <MuldeR2@GMX.de>
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -28,6 +28,8 @@
 #include <QThread>
 #include <QDate>
 
+class QUrl;
+
 ///////////////////////////////////////////////////////////////////////////////
 
 namespace MUtils
@@ -81,7 +83,7 @@ namespace MUtils
                }
                update_status_t;
 
-               UpdateChecker(const QString &binWGet, const QString &binNC, const QString &binGnuPG, const QString &binKeys, const QString &applicationId, const quint32 &installedBuildNo, const bool betaUpdates, const bool testMode = false);
+               UpdateChecker(const QString &binCurl, const QString &binGnuPG, const QString &binKeys, const QString &applicationId, const quint32 &installedBuildNo, const bool betaUpdates, const bool testMode = false);
                ~UpdateChecker(void);
 
                const int  getUpdateStatus(void)             const { return m_status; }
@@ -90,7 +92,7 @@ namespace MUtils
                const int  getCurrentProgress(void)          const { return m_progress; };
                const UpdateCheckerInfo *getUpdateInfo(void) const { return m_updateInfo.data(); }
 
-               void cancel(void) { m_cancelled = true; }
+               bool cancel(void) { return m_cancelled.ref(); }
 
        public slots:
                void start(Priority = InheritPriority);
@@ -98,7 +100,7 @@ namespace MUtils
        protected:
                void run(void);
                void checkForUpdates(void);
-               void testKnownHosts(void);
+               void testMirrorsList(void);
 
        signals:
                void statusChanged(const int status);
@@ -115,13 +117,14 @@ namespace MUtils
                const QString m_applicationId;
                const quint32 m_installedBuildNo;
 
-               const QString m_binaryWGet;
-               const QString m_binaryNC;
+               const QString m_binaryCurl;
                const QString m_binaryGnuPG;
                const QString m_binaryKeys;
 
-               volatile bool m_success;
-               volatile bool m_cancelled;
+               const QScopedPointer<const QHash<QString, QString>> m_environment;
+
+               QAtomicInt m_success;
+               QAtomicInt m_cancelled;
 
                int m_status;
                int m_progress;
@@ -132,11 +135,17 @@ namespace MUtils
 
                bool getUpdateInfo(const QString &url, const QString &outFileVers, const QString &outFileSign);
                bool tryContactHost(const QString &hostname, const int &timeoutMsec);
-               bool parseVersionInfo(const QString &file, UpdateCheckerInfo *updateInfo);
 
-               bool getFile(const QString &url, const QString &outFile, const unsigned int maxRedir = 5U);
-               bool getFile(const QString &url, const bool forceIp4, const QString &outFile, const unsigned int maxRedir = 5U);
+               bool parseVersionInfo(const QString &file, UpdateCheckerInfo *const updateInfo);
+               int parseSectionHeaderStr(const QString &name);
+               void parseHeaderValue(const QString &key, const QString &val, QDate &updateInfoDate);
+               void parseUpdateInfoValue(const QString &key, const QString &val, UpdateCheckerInfo *const updateInfo);
+
+               bool getFile(const QUrl &url, const QString &outFile, const unsigned int maxRedir = 8U);
                bool checkSignature(const QString &file, const QString &signature);
                bool tryUpdateMirror(UpdateCheckerInfo *updateInfo, const QString &url, const bool &quick);
+
+               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);
        };
 }