Sandboxie/SandboxiePlus/SandMan/OnlineUpdater.h

175 lines
4.5 KiB
C
Raw Normal View History

2022-08-09 17:19:46 +01:00
#pragma once
#include <QObject>
#include "../MiscHelpers/Common/NetworkAccessManager.h"
#include "SbiePlusAPI.h"
2023-07-02 10:17:31 +01:00
#define UPDATE_INTERVAL (7 * 24 * 60 * 60)
2023-08-15 08:49:03 +01:00
class CUpdatesJob : public QObject
2022-08-11 23:09:35 +01:00
{
Q_OBJECT
protected:
friend class COnlineUpdater;
2023-08-15 08:49:03 +01:00
CUpdatesJob(const QVariantMap& Params, QObject* parent = nullptr) : QObject(parent)
{
m_Params = Params;
m_pProgress = CSbieProgressPtr(new CSbieProgress());
}
virtual ~CUpdatesJob() {}
virtual void Finish(QNetworkReply* pReply) = 0;
QVariantMap m_Params;
CSbieProgressPtr m_pProgress;
private slots:
void OnDownloadProgress(qint64 bytes, qint64 bytesTotal)
{
if (bytesTotal != 0 && !m_pProgress.isNull())
m_pProgress->Progress(100 * bytes / bytesTotal);
}
};
class CGetUpdatesJob : public CUpdatesJob
{
Q_OBJECT
protected:
friend class COnlineUpdater;
2022-08-11 23:09:35 +01:00
2023-08-15 08:49:03 +01:00
CGetUpdatesJob(const QVariantMap& Params, QObject* parent = nullptr) : CUpdatesJob(Params, parent) {}
virtual void Finish(QNetworkReply* pReply);
2022-08-11 23:09:35 +01:00
signals:
2023-07-01 17:54:53 +01:00
void UpdateData(const QVariantMap& Data, const QVariantMap& Params);
2023-08-15 08:49:03 +01:00
};
class CGetFileJob : public CUpdatesJob
{
Q_OBJECT
protected:
friend class COnlineUpdater;
CGetFileJob(const QVariantMap& Params, QObject* parent = nullptr) : CUpdatesJob(Params, parent) {}
virtual void Finish(QNetworkReply* pReply);
signals:
2023-07-01 17:54:53 +01:00
void Download(const QString& Path, const QVariantMap& Params);
2022-08-11 23:09:35 +01:00
};
2023-08-15 08:49:03 +01:00
class CGetCertJob : public CUpdatesJob
{
Q_OBJECT
protected:
friend class COnlineUpdater;
CGetCertJob(const QVariantMap& Params, QObject* parent = nullptr) : CUpdatesJob(Params, parent) {}
virtual void Finish(QNetworkReply* pReply);
signals:
void Certificate(const QByteArray& Certificate, const QVariantMap& Params);
};
2022-08-11 23:09:35 +01:00
2022-08-09 17:19:46 +01:00
class COnlineUpdater : public QObject
{
Q_OBJECT
public:
COnlineUpdater(QObject* parent);
2023-08-15 08:49:03 +01:00
SB_PROGRESS GetUpdates(QObject* receiver, const char* member, const QVariantMap& Params = QVariantMap());
SB_PROGRESS DownloadFile(const QString& Url, QObject* receiver, const char* member, const QVariantMap& Params = QVariantMap());
SB_PROGRESS GetSupportCert(const QString& Serial, QObject* receiver, const char* member, const QVariantMap& Params = QVariantMap());
static SB_RESULT(int) RunUpdater(const QStringList& Params, bool bSilent, bool Wait = false);
2022-08-09 17:19:46 +01:00
2023-08-15 08:49:03 +01:00
void Process();
2022-08-11 23:09:35 +01:00
2023-07-01 20:24:12 +01:00
QVariantMap GetUpdateData() { return m_UpdateData; }
QDateTime GetLastUpdateTime() { return m_LastUpdate; }
2022-11-20 16:23:15 +00:00
void CheckForUpdates(bool bManual = false);
bool DownloadUpdate(const QVariantMap& Update, bool bAndApply = false);
bool ApplyUpdate(bool bSilent);
bool DownloadInstaller(const QVariantMap& Release, bool bAndRun = false);
bool RunInstaller(bool bSilent);
static QString MakeVersionStr(const QVariantMap& Data);
static QString ParseVersionStr(const QString& Str, int* pUpdate = NULL);
static QString GetCurrentVersion();
static int GetCurrentUpdate();
static bool IsVersionNewer(const QString& VersionStr);
2023-08-15 08:49:03 +01:00
static QString GetUpdateDir(bool bCreate = false);
2022-08-09 17:19:46 +01:00
2023-07-01 17:54:53 +01:00
static quint32 CurrentVersion();
static quint32 VersionToInt(const QString& VersionStr);
2023-10-20 16:01:26 +01:00
static quint64 GetRandID();
2022-08-09 17:19:46 +01:00
private slots:
2023-08-15 08:49:03 +01:00
void OnRequestFinished();
2022-11-20 16:23:15 +00:00
2023-07-01 17:54:53 +01:00
void OnInstallerDownload(const QString& Path, const QVariantMap& Params);
2022-11-20 16:23:15 +00:00
2022-08-11 23:09:35 +01:00
void OnUpdateData(const QVariantMap& Data, const QVariantMap& Params);
2022-08-09 17:19:46 +01:00
2022-11-20 16:23:15 +00:00
void OnPrepareOutput();
void OnPrepareError();
void OnPrepareFinished(int exitCode, QProcess::ExitStatus exitStatus);
2022-08-09 17:19:46 +01:00
protected:
2023-08-15 08:49:03 +01:00
void StartJob(CUpdatesJob* pJob, const QUrl& Url);
void LoadState();
2022-11-20 16:23:15 +00:00
bool HandleUserMessage(const QVariantMap& Data);
bool HandleUpdate();
2023-09-02 08:10:24 +01:00
QString GetOnNewUpdateOption() const;
QString GetOnNewReleaseOption() const;
bool ShowCertWarningIfNeeded();
2022-11-20 16:23:15 +00:00
enum EUpdateScope
{
eNone = 0, // No files updated
eMeta, // Only Templates.ini and/or translations changed
eCore, // Core sandboxie Components Changed
eFull // Plus components changed
};
EUpdateScope ScanUpdateFiles(const QVariantMap& Update);
EUpdateScope GetFileScope(const QString& Path);
2023-12-03 19:05:40 +00:00
bool AskDownload(const QVariantMap& Update, bool bAuto);
2023-07-30 13:28:35 +01:00
static bool RunInstaller2(const QString& FilePath, bool bSilent);
2022-08-09 17:19:46 +01:00
CNetworkAccessManager* m_RequestManager;
2023-08-15 08:49:03 +01:00
QMap<QNetworkReply*, CUpdatesJob*> m_JobQueue;
2022-11-20 16:23:15 +00:00
QStringList m_IgnoredUpdates;
enum ECHeckMode
{
eInit = 0,
eAuto,
eManual,
ePendingUpdate,
ePendingInstall
} m_CheckMode;
QVariantMap m_UpdateData;
2023-07-01 20:24:12 +01:00
QDateTime m_LastUpdate;
2023-08-15 08:49:03 +01:00
2022-11-20 16:23:15 +00:00
QProcess* m_pUpdaterUtil;
2023-08-15 08:49:03 +01:00
CSbieProgressPtr m_pUpdateProgress;
2022-08-09 17:19:46 +01:00
};