fixed the updating mechanism

This commit is contained in:
fourtf 2018-06-21 23:02:42 +02:00
parent 00d538b368
commit 8f34a0af59

View file

@ -42,7 +42,7 @@ void UpdateManager::installUpdates()
return; return;
} }
#ifdef Q_OS_WIN //#ifdef Q_OS_WIN
QMessageBox *box = new QMessageBox(QMessageBox::Information, "Chatterino Update", QMessageBox *box = new QMessageBox(QMessageBox::Information, "Chatterino Update",
"Chatterino is downloading the update " "Chatterino is downloading the update "
"in the background and will run the " "in the background and will run the "
@ -55,10 +55,12 @@ void UpdateManager::installUpdates()
req.onError([this](int) -> bool { req.onError([this](int) -> bool {
this->setStatus_(DownloadFailed); this->setStatus_(DownloadFailed);
QMessageBox *box = new QMessageBox(QMessageBox::Information, "Chatterino Update", util::postToThread([] {
"Failed while trying to download the update."); QMessageBox *box = new QMessageBox(QMessageBox::Information, "Chatterino Update",
box->setAttribute(Qt::WA_DeleteOnClose); "Failed while trying to download the update.");
box->show(); box->setAttribute(Qt::WA_DeleteOnClose);
box->show();
});
return true; return true;
}); });
@ -66,24 +68,28 @@ void UpdateManager::installUpdates()
auto filename = util::combinePath(getApp()->paths->miscDirectory, "update.zip"); auto filename = util::combinePath(getApp()->paths->miscDirectory, "update.zip");
QFile file(filename); QFile file(filename);
file.open(QIODevice::Truncate | QIODevice::WriteOnly);
if (file.write(object) == -1) { if (file.write(object) == -1) {
this->setStatus_(WriteFileFailed); this->setStatus_(WriteFileFailed);
return false; 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); QApplication::exit(0);
return false; return false;
}); });
this->setStatus_(Downloading); this->setStatus_(Downloading);
req.execute(); req.execute();
#endif //#endif
} }
void UpdateManager::checkForUpdates() void UpdateManager::checkForUpdates()
{ {
#ifdef Q_OS_WIN //#ifdef Q_OS_WIN
QString url = "https://notitia.chatterino.com/version/chatterino/" CHATTERINO_OS "/stable"; QString url = "https://notitia.chatterino.com/version/chatterino/" CHATTERINO_OS "/stable";
util::NetworkRequest req(url); util::NetworkRequest req(url);
@ -120,7 +126,7 @@ void UpdateManager::checkForUpdates()
box->setAttribute(Qt::WA_DeleteOnClose); box->setAttribute(Qt::WA_DeleteOnClose);
box->show(); box->show();
if (box->exec() == QMessageBox::Yes) { if (box->exec() == QMessageBox::Yes) {
this->installUpdates(); util::postToThread([this] { this->installUpdates(); });
} }
} else { } else {
this->setStatus_(NoUpdateAvailable); this->setStatus_(NoUpdateAvailable);
@ -128,7 +134,7 @@ void UpdateManager::checkForUpdates()
}); });
this->setStatus_(Searching); this->setStatus_(Searching);
req.execute(); req.execute();
#endif //#endif
} }
UpdateManager::UpdateStatus UpdateManager::getStatus() const UpdateManager::UpdateStatus UpdateManager::getStatus() const