From 8f34a0af59d0aa0c22d034c84bc1f275eb7b374f Mon Sep 17 00:00:00 2001 From: fourtf Date: Thu, 21 Jun 2018 23:02:42 +0200 Subject: [PATCH] fixed the updating mechanism --- src/singletons/updatemanager.cpp | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/singletons/updatemanager.cpp b/src/singletons/updatemanager.cpp index a0a5b9617..1ede53b73 100644 --- a/src/singletons/updatemanager.cpp +++ b/src/singletons/updatemanager.cpp @@ -42,7 +42,7 @@ void UpdateManager::installUpdates() return; } -#ifdef Q_OS_WIN + //#ifdef Q_OS_WIN QMessageBox *box = new QMessageBox(QMessageBox::Information, "Chatterino Update", "Chatterino is downloading the update " "in the background and will run the " @@ -55,10 +55,12 @@ void UpdateManager::installUpdates() req.onError([this](int) -> bool { this->setStatus_(DownloadFailed); - QMessageBox *box = new QMessageBox(QMessageBox::Information, "Chatterino Update", - "Failed while trying to download the update."); - box->setAttribute(Qt::WA_DeleteOnClose); - box->show(); + util::postToThread([] { + QMessageBox *box = new QMessageBox(QMessageBox::Information, "Chatterino Update", + "Failed while trying to download the update."); + box->setAttribute(Qt::WA_DeleteOnClose); + box->show(); + }); return true; }); @@ -66,24 +68,28 @@ void UpdateManager::installUpdates() auto filename = util::combinePath(getApp()->paths->miscDirectory, "update.zip"); QFile file(filename); + file.open(QIODevice::Truncate | QIODevice::WriteOnly); + if (file.write(object) == -1) { this->setStatus_(WriteFileFailed); return false; } - QProcess::startDetached("./updater.1/ChatterinoUpdater.exe", {filename, "restart"}); + QProcess::startDetached(util::combinePath(QCoreApplication::applicationDirPath(), + "updater.1/ChatterinoUpdater.exe"), + {filename, "restart"}); QApplication::exit(0); return false; }); this->setStatus_(Downloading); req.execute(); -#endif + //#endif } void UpdateManager::checkForUpdates() { -#ifdef Q_OS_WIN + //#ifdef Q_OS_WIN QString url = "https://notitia.chatterino.com/version/chatterino/" CHATTERINO_OS "/stable"; util::NetworkRequest req(url); @@ -120,7 +126,7 @@ void UpdateManager::checkForUpdates() box->setAttribute(Qt::WA_DeleteOnClose); box->show(); if (box->exec() == QMessageBox::Yes) { - this->installUpdates(); + util::postToThread([this] { this->installUpdates(); }); } } else { this->setStatus_(NoUpdateAvailable); @@ -128,7 +134,7 @@ void UpdateManager::checkForUpdates() }); this->setStatus_(Searching); req.execute(); -#endif + //#endif } UpdateManager::UpdateStatus UpdateManager::getStatus() const