2026-07-09 09:17:30 +00:00
|
|
|
#pragma once
|
|
|
|
|
#include <QObject>
|
|
|
|
|
#include "HttpHelper.h"
|
|
|
|
|
#include "FileHelper.h"
|
|
|
|
|
#include <QJsonObject>
|
|
|
|
|
#include <QJsonArray>
|
|
|
|
|
#include <QJsonDocument>
|
|
|
|
|
#include <QStringList>
|
|
|
|
|
#include <QNetworkReply>
|
|
|
|
|
#include <QMap>
|
|
|
|
|
#include <QElapsedTimer>
|
|
|
|
|
|
|
|
|
|
struct FileDownloadItem
|
|
|
|
|
{
|
|
|
|
|
QString path;
|
|
|
|
|
QString url;
|
|
|
|
|
QString sha256;
|
|
|
|
|
qint64 size;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class UpdaterLogic : public QObject
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
public:
|
|
|
|
|
explicit UpdaterLogic(QObject* parent = nullptr);
|
|
|
|
|
|
|
|
|
|
void getManifest(const QString& appId, const QString& channel, const QString& targetVer, int versionId);
|
2026-07-10 00:38:23 -07:00
|
|
|
bool verifyManifestSignature(const QString& publicKeyPath = ":/simcae/update-client/manifest-public-key.pem") const;
|
2026-07-09 09:17:30 +00:00
|
|
|
bool validateLocalFiles(const QString& stagingDir, const QString& installedDir = QString()) const;
|
|
|
|
|
bool saveManifestCache(const QString& cacheDir) const;
|
|
|
|
|
bool loadManifestCache(const QString& cacheDir, const QString& version);
|
|
|
|
|
bool loadOfflinePackage(const QString& packagePath, const QString& stagingDir = QString());
|
|
|
|
|
QString offlineError() const { return m_offlineError; }
|
|
|
|
|
|
|
|
|
|
void getDownloadUrl(const QString& appId, const QString& channel, const QString& targetVer, int versionId);
|
|
|
|
|
void reportResult(const QString& deviceId, const QString& fromVer, const QString& toVer, bool success);
|
|
|
|
|
void reportDownloadResult(const QString& appId, const QString& channel, const QString& version, bool success);
|
|
|
|
|
bool downloadAllFiles(const QString& tempDir, const QString& targetDir);
|
|
|
|
|
qint64 estimateAdditionalDiskBytes(const QString& targetDir, const QStringList& obsoletePaths) const;
|
|
|
|
|
QString calcLocalFileSha256(const QString& filePath) const;
|
|
|
|
|
|
|
|
|
|
QList<FileDownloadItem> getFileList() const;
|
|
|
|
|
QJsonObject getManifest() const { return m_manifest; }
|
|
|
|
|
QStringList obsoleteFilesComparedTo(const QJsonObject& oldManifest) const;
|
|
|
|
|
QString getManifestText() const { return m_manifestText; }
|
|
|
|
|
bool allDownloadSuccess() const { return m_downloadAllOk; }
|
|
|
|
|
|
|
|
|
|
signals:
|
|
|
|
|
void fetchUrlFinished();
|
|
|
|
|
void downloadProgress(qint64 receivedBytes, qint64 totalBytes,
|
|
|
|
|
const QString& currentPath, double bytesPerSecond);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
bool downloadSingleFile(const QString& url, const QString& savePath, const QString& expectSha256,
|
|
|
|
|
qint64 expectedSize, const QString& resumePartPath);
|
2026-07-10 00:38:23 -07:00
|
|
|
bool validateOnlineManifest(const QJsonObject& manifest, const QString& appId,
|
|
|
|
|
const QString& channel, const QString& targetVer,
|
|
|
|
|
int versionId, QList<FileDownloadItem>* fileItems) const;
|
2026-07-09 09:17:30 +00:00
|
|
|
bool isSafeRelativePath(const QString& path) const;
|
|
|
|
|
bool isRuntimeProtectedPath(const QString& path) const;
|
|
|
|
|
QByteArray canonicalManifestBytes(const QJsonObject& manifest) const;
|
|
|
|
|
bool verifySignature(const QByteArray& payload, const QString& signatureBase64, const QString& publicKeyPath) const;
|
|
|
|
|
|
|
|
|
|
HttpHelper m_http;
|
|
|
|
|
QString m_serverAddr;
|
|
|
|
|
QJsonObject m_manifest;
|
|
|
|
|
QString m_manifestText;
|
|
|
|
|
QList<FileDownloadItem> m_fileItems;
|
2026-07-10 00:38:23 -07:00
|
|
|
mutable bool m_manifestSignatureVerified = false;
|
2026-07-09 09:17:30 +00:00
|
|
|
bool m_downloadAllOk = false;
|
|
|
|
|
qint64 m_downloadTotalBytes = 0;
|
|
|
|
|
qint64 m_downloadCompletedBytes = 0;
|
|
|
|
|
qint64 m_sessionDownloadedBytes = 0;
|
|
|
|
|
QString m_currentDownloadPath;
|
|
|
|
|
QString m_offlineError;
|
|
|
|
|
QElapsedTimer m_downloadTimer;
|
2026-07-10 00:38:23 -07:00
|
|
|
};
|