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
+119 -51
View File
@@ -63,72 +63,130 @@ 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
QMessageBox *box = if (getPaths()->isPortable())
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->updateExe_);
req.setTimeout(600000);
req.onError([this](int) -> bool {
this->setStatus_(DownloadFailed);
QMessageBox *box = QMessageBox *box =
new QMessageBox(QMessageBox::Information, "Chatterino Update", new QMessageBox(QMessageBox::Information, "Chatterino Update",
"Failed to download the update. \n\nTry manually " "Chatterino is downloading the update "
"downloading the update."); "in the background and will run the "
"updater once it is finished.");
box->setAttribute(Qt::WA_DeleteOnClose); box->setAttribute(Qt::WA_DeleteOnClose);
box->exec(); box->show();
return true;
});
req.onSuccess([this](auto result) -> Outcome { NetworkRequest req(this->updatePortable_);
QByteArray object = result.getData(); req.setTimeout(600000);
auto filename = combinePath(getPaths()->miscDirectory, "Update.exe"); req.onError([this](int) -> bool {
this->setStatus_(DownloadFailed);
QFile file(filename); postToThread([] {
file.open(QIODevice::Truncate | QIODevice::WriteOnly); 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 =
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->updateExe_);
req.setTimeout(600000);
req.onError([this](int) -> bool {
this->setStatus_(DownloadFailed);
if (file.write(object) == -1)
{
this->setStatus_(WriteFileFailed);
QMessageBox *box = new QMessageBox( QMessageBox *box = new QMessageBox(
QMessageBox::Information, "Chatterino Update", QMessageBox::Information, "Chatterino Update",
"Failed to save the update file. This could be due to " "Failed to download the update. \n\nTry manually "
"window settings or antivirus software.\n\nTry manually "
"downloading the update."); "downloading the update.");
box->setAttribute(Qt::WA_DeleteOnClose); box->setAttribute(Qt::WA_DeleteOnClose);
box->exec(); box->exec();
return true;
});
QDesktopServices::openUrl(this->updateExe_); req.onSuccess([this](auto result) -> Outcome {
return Failure; QByteArray object = result.getData();
} auto filename =
file.close(); combinePath(getPaths()->miscDirectory, "Update.exe");
if (QProcess::startDetached(filename)) QFile file(filename);
{ file.open(QIODevice::Truncate | QIODevice::WriteOnly);
QApplication::exit(0);
}
else
{
QMessageBox *box = new QMessageBox(
QMessageBox::Information, "Chatterino Update",
"Failed to execute update binary. This could be due to window "
"settings or antivirus software.\n\nTry manually downloading "
"the update.");
box->setAttribute(Qt::WA_DeleteOnClose);
box->exec();
QDesktopServices::openUrl(this->updateExe_); if (file.write(object) == -1)
} {
this->setStatus_(WriteFileFailed);
QMessageBox *box = new QMessageBox(
QMessageBox::Information, "Chatterino Update",
"Failed to save the update file. This could be due to "
"window settings or antivirus software.\n\nTry manually "
"downloading the update.");
box->setAttribute(Qt::WA_DeleteOnClose);
box->exec();
return Success; QDesktopServices::openUrl(this->updateExe_);
}); return Failure;
this->setStatus_(Downloading); }
req.execute(); file.close();
if (QProcess::startDetached(filename))
{
QApplication::exit(0);
}
else
{
QMessageBox *box = new QMessageBox(
QMessageBox::Information, "Chatterino Update",
"Failed to execute update binary. This could be due to "
"window "
"settings or antivirus software.\n\nTry manually "
"downloading "
"the update.");
box->setAttribute(Qt::WA_DeleteOnClose);
box->exec();
QDesktopServices::openUrl(this->updateExe_);
}
return Success;
});
this->setStatus_(Downloading);
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);