fixed manual updates for portable mode on windows

This commit is contained in:
fourtf
2019-08-18 23:51:10 +02:00
parent 23f1dd4646
commit 0a81a358b5
2 changed files with 120 additions and 51 deletions
+73 -5
View File
@@ -63,6 +63,60 @@ void Updates::installUpdates()
box->exec(); box->exec();
QDesktopServices::openUrl(this->updateGuideLink_); QDesktopServices::openUrl(this->updateGuideLink_);
#elif defined Q_OS_WIN #elif defined Q_OS_WIN
if (getPaths()->isPortable())
{
QMessageBox *box =
new QMessageBox(QMessageBox::Information, "Chatterino Update",
"Chatterino is downloading the update "
"in the background and will run the "
"updater once it is finished.");
box->setAttribute(Qt::WA_DeleteOnClose);
box->show();
NetworkRequest req(this->updatePortable_);
req.setTimeout(600000);
req.onError([this](int) -> bool {
this->setStatus_(DownloadFailed);
postToThread([] {
QMessageBox *box = new QMessageBox(
QMessageBox::Information, "Chatterino Update",
"Failed while trying to download the update.");
box->setAttribute(Qt::WA_DeleteOnClose);
box->show();
box->raise();
});
return true;
});
req.onSuccess([this](auto result) -> Outcome {
QByteArray object = result.getData();
auto filename =
combinePath(getPaths()->miscDirectory, "update.zip");
QFile file(filename);
file.open(QIODevice::Truncate | QIODevice::WriteOnly);
if (file.write(object) == -1)
{
this->setStatus_(WriteFileFailed);
return Failure;
}
QProcess::startDetached(
combinePath(QCoreApplication::applicationDirPath(),
"updater.1/ChatterinoUpdater.exe"),
{filename, "restart"});
QApplication::exit(0);
return Success;
});
this->setStatus_(Downloading);
req.execute();
}
else
{
QMessageBox *box = QMessageBox *box =
new QMessageBox(QMessageBox::Information, "Chatterino Update", new QMessageBox(QMessageBox::Information, "Chatterino Update",
"Chatterino is downloading the update " "Chatterino is downloading the update "
@@ -76,8 +130,8 @@ void Updates::installUpdates()
req.onError([this](int) -> bool { req.onError([this](int) -> bool {
this->setStatus_(DownloadFailed); this->setStatus_(DownloadFailed);
QMessageBox *box = QMessageBox *box = new QMessageBox(
new QMessageBox(QMessageBox::Information, "Chatterino Update", QMessageBox::Information, "Chatterino Update",
"Failed to download the update. \n\nTry manually " "Failed to download the update. \n\nTry manually "
"downloading the update."); "downloading the update.");
box->setAttribute(Qt::WA_DeleteOnClose); box->setAttribute(Qt::WA_DeleteOnClose);
@@ -87,7 +141,8 @@ void Updates::installUpdates()
req.onSuccess([this](auto result) -> Outcome { req.onSuccess([this](auto result) -> Outcome {
QByteArray object = result.getData(); QByteArray object = result.getData();
auto filename = combinePath(getPaths()->miscDirectory, "Update.exe"); auto filename =
combinePath(getPaths()->miscDirectory, "Update.exe");
QFile file(filename); QFile file(filename);
file.open(QIODevice::Truncate | QIODevice::WriteOnly); file.open(QIODevice::Truncate | QIODevice::WriteOnly);
@@ -116,8 +171,10 @@ void Updates::installUpdates()
{ {
QMessageBox *box = new QMessageBox( QMessageBox *box = new QMessageBox(
QMessageBox::Information, "Chatterino Update", QMessageBox::Information, "Chatterino Update",
"Failed to execute update binary. This could be due to window " "Failed to execute update binary. This could be due to "
"settings or antivirus software.\n\nTry manually downloading " "window "
"settings or antivirus software.\n\nTry manually "
"downloading "
"the update."); "the update.");
box->setAttribute(Qt::WA_DeleteOnClose); box->setAttribute(Qt::WA_DeleteOnClose);
box->exec(); box->exec();
@@ -129,6 +186,7 @@ void Updates::installUpdates()
}); });
this->setStatus_(Downloading); this->setStatus_(Downloading);
req.execute(); req.execute();
}
#endif #endif
} }
@@ -163,6 +221,16 @@ void Updates::checkForUpdates()
} }
this->updateExe_ = updateExe_val.toString(); this->updateExe_ = updateExe_val.toString();
/// Windows portable
QJsonValue portable_val = object.value("portable_download");
if (!portable_val.isString())
{
this->setStatus_(SearchFailed);
qDebug() << "error updating";
return Failure;
}
this->updatePortable_ = portable_val.toString();
#elif defined Q_OS_LINUX #elif defined Q_OS_LINUX
QJsonValue updateGuide_val = object.value("updateguide"); QJsonValue updateGuide_val = object.value("updateguide");
if (updateGuide_val.isString()) if (updateGuide_val.isString())
+1
View File
@@ -41,6 +41,7 @@ private:
Status status_ = None; Status status_ = None;
QString updateExe_; QString updateExe_;
QString updatePortable_;
QString updateGuideLink_; QString updateGuideLink_;
void setStatus_(Status status); void setStatus_(Status status);