From a545d1ba712fc424c72236fe9e0b59ce320d5b0f Mon Sep 17 00:00:00 2001 From: Nodir Temirkhodjaev Date: Tue, 23 Apr 2024 15:44:45 +0300 Subject: [PATCH] UI: AutoUpdateManager: Separate save/run installer --- src/ui/manager/autoupdatemanager.cpp | 31 +++++++++++++--------------- src/ui/manager/autoupdatemanager.h | 8 +++++-- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/ui/manager/autoupdatemanager.cpp b/src/ui/manager/autoupdatemanager.cpp index a7727f94..006e1c08 100644 --- a/src/ui/manager/autoupdatemanager.cpp +++ b/src/ui/manager/autoupdatemanager.cpp @@ -50,7 +50,7 @@ void AutoUpdateManager::setupDownloader() void AutoUpdateManager::downloadFinished(bool success) { if (success) { - success = runInstaller(); + success = saveInstaller(); } finish(success); @@ -65,7 +65,10 @@ void AutoUpdateManager::checkAutoUpdate() if (!confManager->conf()->ini().updaterAutoUpdate()) return; - if (m_taskInfo->isNewVersion() && !m_taskInfo->downloadUrl().isEmpty()) { + const QString downloadUrl = m_taskInfo->downloadUrl(); + if (!downloadUrl.isEmpty() && m_taskInfo->isNewVersion()) { + m_fileName = QUrl(downloadUrl).fileName(); + run(); } } @@ -75,29 +78,19 @@ void AutoUpdateManager::clearUpdateDir() FileUtil::removePath(m_updatePath); } -bool AutoUpdateManager::runInstaller() +bool AutoUpdateManager::saveInstaller() { 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, fileData)) - return false; - - QStringList args; - prepareInstaller(args); - - if (!QProcess::startDetached(exePath, args)) - return false; - - return true; + return FileUtil::writeFileData(installerPath(), fileData); } -void AutoUpdateManager::prepareInstaller(QStringList &args) const +bool AutoUpdateManager::runInstaller() { + QStringList args; + auto settings = IoC(); if (!settings->isPortable()) { @@ -106,5 +99,9 @@ void AutoUpdateManager::prepareInstaller(QStringList &args) const if (!settings->hasService()) { args << "/AUTORUN"; + } else if (settings->isService()) { + emit restartClients(); } + + return QProcess::startDetached(installerPath(), args); } diff --git a/src/ui/manager/autoupdatemanager.h b/src/ui/manager/autoupdatemanager.h index 4d72dbf1..f38561a0 100644 --- a/src/ui/manager/autoupdatemanager.h +++ b/src/ui/manager/autoupdatemanager.h @@ -21,6 +21,9 @@ public: signals: void restartClients(); +public slots: + bool runInstaller(); + protected: void setupTaskInfo(); @@ -33,8 +36,9 @@ protected slots: void clearUpdateDir(); - bool runInstaller(); - void prepareInstaller(QStringList &args) const; + bool saveInstaller(); + + QString installerPath() const { return m_updatePath + m_fileName; } private: static QString getDownloadUrl();