From 5dddc0cb7e2a4018279a4570f946e99d64b66a75 Mon Sep 17 00:00:00 2001 From: Nodir Temirkhodjaev Date: Sun, 21 Apr 2024 20:21:48 +0300 Subject: [PATCH] UI: TaskInfoUpdateChecker: Save download size --- src/ui/manager/autoupdatemanager.cpp | 6 +++++- src/ui/task/taskinfoupdatechecker.cpp | 11 ++++++----- src/ui/task/taskinfoupdatechecker.h | 7 +++++-- src/ui/task/taskupdatechecker.h | 1 + 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/ui/manager/autoupdatemanager.cpp b/src/ui/manager/autoupdatemanager.cpp index 82f0f22a..1fdd2751 100644 --- a/src/ui/manager/autoupdatemanager.cpp +++ b/src/ui/manager/autoupdatemanager.cpp @@ -71,10 +71,14 @@ void AutoUpdateManager::clearUpdateDir() bool AutoUpdateManager::runInstaller() { + const QByteArray fileData = downloader()->takeBuffer(); + if (fileData.size() != m_taskInfo->downloadSize()) + return false; + const QString fileName = QUrl(downloader()->url()).fileName(); const QString exePath = m_updatePath + fileName; - if (!FileUtil::writeFileData(exePath, downloader()->takeBuffer())) + if (!FileUtil::writeFileData(exePath, fileData)) return false; QStringList args; diff --git a/src/ui/task/taskinfoupdatechecker.cpp b/src/ui/task/taskinfoupdatechecker.cpp index 551ccc1d..6c2899f4 100644 --- a/src/ui/task/taskinfoupdatechecker.cpp +++ b/src/ui/task/taskinfoupdatechecker.cpp @@ -13,7 +13,7 @@ namespace { const QLoggingCategory LC("task.updateChecker"); -constexpr int TASK_INFO_VERSION = 2; +constexpr int TASK_INFO_VERSION = 3; } @@ -37,8 +37,8 @@ QByteArray TaskInfoUpdateChecker::data() const // Store data const quint16 infoVersion = TASK_INFO_VERSION; - stream << infoVersion << QString::fromLatin1(APP_VERSION_STR) << m_version << m_downloadUrl - << m_releaseText; + stream << infoVersion << QString::fromLatin1(APP_VERSION_STR) << m_version << m_releaseText + << m_downloadUrl << m_downloadSize; return data; } @@ -66,7 +66,7 @@ void TaskInfoUpdateChecker::setData(const QByteArray &data) if (appVersion != APP_VERSION_STR) return; // app upgraded - stream >> m_version >> m_downloadUrl >> m_releaseText; + stream >> m_version >> m_releaseText >> m_downloadUrl >> m_downloadSize; emitAppVersionUpdated(); } @@ -91,8 +91,9 @@ bool TaskInfoUpdateChecker::processResult(bool success) } m_version = worker->version(); - m_downloadUrl = worker->downloadUrl(); m_releaseText = worker->releaseText(); + m_downloadUrl = worker->downloadUrl(); + m_downloadSize = worker->downloadSize(); emitAppVersionUpdated(); diff --git a/src/ui/task/taskinfoupdatechecker.h b/src/ui/task/taskinfoupdatechecker.h index f1a2cebd..d5f4250e 100644 --- a/src/ui/task/taskinfoupdatechecker.h +++ b/src/ui/task/taskinfoupdatechecker.h @@ -14,8 +14,9 @@ public: bool isNewVersion() const; QString version() const { return m_version; } - QString downloadUrl() const { return m_downloadUrl; } QString releaseText() const { return m_releaseText; } + QString downloadUrl() const { return m_downloadUrl; } + int downloadSize() const { return m_downloadSize; } QByteArray data() const override; void setData(const QByteArray &data) override; @@ -30,8 +31,10 @@ private: private: QString m_version; - QString m_downloadUrl; QString m_releaseText; + + QString m_downloadUrl; + int m_downloadSize = 0; }; #endif // TASKINFOUPDATECHECKER_H diff --git a/src/ui/task/taskupdatechecker.h b/src/ui/task/taskupdatechecker.h index 554ec971..70637143 100644 --- a/src/ui/task/taskupdatechecker.h +++ b/src/ui/task/taskupdatechecker.h @@ -12,6 +12,7 @@ public: QString version() const { return m_version; } QString downloadUrl() const { return m_downloadUrl; } + int downloadSize() const { return m_downloadSize; } QString releaseText() const;