mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
fixed manual updates for portable mode on windows
This commit is contained in:
parent
23f1dd4646
commit
0a81a358b5
|
@ -63,6 +63,60 @@ void Updates::installUpdates()
|
|||
box->exec();
|
||||
QDesktopServices::openUrl(this->updateGuideLink_);
|
||||
#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 =
|
||||
new QMessageBox(QMessageBox::Information, "Chatterino Update",
|
||||
"Chatterino is downloading the update "
|
||||
|
@ -76,8 +130,8 @@ void Updates::installUpdates()
|
|||
req.onError([this](int) -> bool {
|
||||
this->setStatus_(DownloadFailed);
|
||||
|
||||
QMessageBox *box =
|
||||
new QMessageBox(QMessageBox::Information, "Chatterino Update",
|
||||
QMessageBox *box = new QMessageBox(
|
||||
QMessageBox::Information, "Chatterino Update",
|
||||
"Failed to download the update. \n\nTry manually "
|
||||
"downloading the update.");
|
||||
box->setAttribute(Qt::WA_DeleteOnClose);
|
||||
|
@ -87,7 +141,8 @@ void Updates::installUpdates()
|
|||
|
||||
req.onSuccess([this](auto result) -> Outcome {
|
||||
QByteArray object = result.getData();
|
||||
auto filename = combinePath(getPaths()->miscDirectory, "Update.exe");
|
||||
auto filename =
|
||||
combinePath(getPaths()->miscDirectory, "Update.exe");
|
||||
|
||||
QFile file(filename);
|
||||
file.open(QIODevice::Truncate | QIODevice::WriteOnly);
|
||||
|
@ -116,8 +171,10 @@ void Updates::installUpdates()
|
|||
{
|
||||
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 "
|
||||
"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();
|
||||
|
@ -129,6 +186,7 @@ void Updates::installUpdates()
|
|||
});
|
||||
this->setStatus_(Downloading);
|
||||
req.execute();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -163,6 +221,16 @@ void Updates::checkForUpdates()
|
|||
}
|
||||
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
|
||||
QJsonValue updateGuide_val = object.value("updateguide");
|
||||
if (updateGuide_val.isString())
|
||||
|
|
|
@ -41,6 +41,7 @@ private:
|
|||
Status status_ = None;
|
||||
|
||||
QString updateExe_;
|
||||
QString updatePortable_;
|
||||
QString updateGuideLink_;
|
||||
|
||||
void setStatus_(Status status);
|
||||
|
|
Loading…
Reference in a new issue