mirror of
https://github.com/tnodir/fort
synced 2024-11-15 11:45:09 +00:00
UI: AutoUpdateManager: Separate save/run installer
This commit is contained in:
parent
0dd76cb897
commit
a545d1ba71
@ -50,7 +50,7 @@ void AutoUpdateManager::setupDownloader()
|
|||||||
void AutoUpdateManager::downloadFinished(bool success)
|
void AutoUpdateManager::downloadFinished(bool success)
|
||||||
{
|
{
|
||||||
if (success) {
|
if (success) {
|
||||||
success = runInstaller();
|
success = saveInstaller();
|
||||||
}
|
}
|
||||||
|
|
||||||
finish(success);
|
finish(success);
|
||||||
@ -65,7 +65,10 @@ void AutoUpdateManager::checkAutoUpdate()
|
|||||||
if (!confManager->conf()->ini().updaterAutoUpdate())
|
if (!confManager->conf()->ini().updaterAutoUpdate())
|
||||||
return;
|
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();
|
run();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -75,29 +78,19 @@ void AutoUpdateManager::clearUpdateDir()
|
|||||||
FileUtil::removePath(m_updatePath);
|
FileUtil::removePath(m_updatePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AutoUpdateManager::runInstaller()
|
bool AutoUpdateManager::saveInstaller()
|
||||||
{
|
{
|
||||||
const QByteArray fileData = downloader()->takeBuffer();
|
const QByteArray fileData = downloader()->takeBuffer();
|
||||||
if (fileData.size() != m_taskInfo->downloadSize())
|
if (fileData.size() != m_taskInfo->downloadSize())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
const QString fileName = QUrl(downloader()->url()).fileName();
|
return FileUtil::writeFileData(installerPath(), fileData);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AutoUpdateManager::prepareInstaller(QStringList &args) const
|
bool AutoUpdateManager::runInstaller()
|
||||||
{
|
{
|
||||||
|
QStringList args;
|
||||||
|
|
||||||
auto settings = IoC<FortSettings>();
|
auto settings = IoC<FortSettings>();
|
||||||
|
|
||||||
if (!settings->isPortable()) {
|
if (!settings->isPortable()) {
|
||||||
@ -106,5 +99,9 @@ void AutoUpdateManager::prepareInstaller(QStringList &args) const
|
|||||||
|
|
||||||
if (!settings->hasService()) {
|
if (!settings->hasService()) {
|
||||||
args << "/AUTORUN";
|
args << "/AUTORUN";
|
||||||
|
} else if (settings->isService()) {
|
||||||
|
emit restartClients();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return QProcess::startDetached(installerPath(), args);
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,9 @@ public:
|
|||||||
signals:
|
signals:
|
||||||
void restartClients();
|
void restartClients();
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
bool runInstaller();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void setupTaskInfo();
|
void setupTaskInfo();
|
||||||
|
|
||||||
@ -33,8 +36,9 @@ protected slots:
|
|||||||
|
|
||||||
void clearUpdateDir();
|
void clearUpdateDir();
|
||||||
|
|
||||||
bool runInstaller();
|
bool saveInstaller();
|
||||||
void prepareInstaller(QStringList &args) const;
|
|
||||||
|
QString installerPath() const { return m_updatePath + m_fileName; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static QString getDownloadUrl();
|
static QString getDownloadUrl();
|
||||||
|
Loading…
Reference in New Issue
Block a user