Skip to content

Commit 45d20ba

Browse files
committed
Revived direct upgrades.
1 parent cd6e5c4 commit 45d20ba

1 file changed

Lines changed: 39 additions & 18 deletions

File tree

src/gui/dialogs/formupdate.cpp

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
#include <QNetworkReply>
3131
#include <QProcess>
3232

33+
#if defined(Q_OS_WIN)
34+
#include <windows.h>
35+
#endif
36+
3337

3438
FormUpdate::FormUpdate(QWidget *parent)
3539
: QDialog(parent), m_downloader(nullptr), m_readyToInstall(false), m_ui(new Ui::FormUpdate) {
@@ -105,15 +109,17 @@ void FormUpdate::checkForUpdates() {
105109
}
106110

107111
void FormUpdate::updateProgress(qint64 bytes_received, qint64 bytes_total) {
108-
qApp->processEvents();
109-
m_ui->m_lblStatus->setStatus(WidgetWithStatus::Information,
110-
tr("Downloaded %1% (update size is %2 kB).").arg(QString::number(bytes_total == 0 ? 0 : (bytes_received * 100.0) / bytes_total,
111-
'f',
112-
2),
113-
QString::number(bytes_total / 1000,
114-
'f',
115-
2)),
116-
tr("Downloading update..."));
112+
if (bytes_received % 10 == 0) {
113+
qApp->processEvents();
114+
m_ui->m_lblStatus->setStatus(WidgetWithStatus::Information,
115+
tr("Downloaded %1% (update size is %2 kB).").arg(QString::number(bytes_total == 0 ? 0 : (bytes_received * 100.0) / bytes_total,
116+
'f',
117+
2),
118+
QString::number(bytes_total / 1000,
119+
'f',
120+
2)),
121+
tr("Downloading update..."));
122+
}
117123
}
118124

119125
void FormUpdate::saveUpdateFile(const QByteArray &file_contents) {
@@ -154,7 +160,7 @@ void FormUpdate::updateCompleted(QNetworkReply::NetworkError status, QByteArray
154160
case QNetworkReply::NoError:
155161
saveUpdateFile(contents);
156162
m_ui->m_lblStatus->setStatus(WidgetWithStatus::Ok, tr("Downloaded successfully"), tr("Package was downloaded successfully.\nYou must install it manually."));
157-
m_btnUpdate->setText(tr("Go to update file"));
163+
m_btnUpdate->setText(tr("Install"));
158164
m_btnUpdate->setEnabled(true);
159165
break;
160166

@@ -176,15 +182,29 @@ void FormUpdate::startUpdate() {
176182
url_file = APP_URL;
177183
}
178184

179-
if (m_readyToInstall) {
180-
if (!SystemFactory::openFolderFile(m_updateFilePath)) {
181-
MessageBox::show(this,
182-
QMessageBox::Warning,
183-
tr("Cannot open directory"),
184-
tr("Cannot open output directory. Open it manually."),
185-
QString(),
186-
m_updateFilePath);
185+
if (m_readyToInstall) {
186+
close();
187+
qDebug("Preparing to launch external installer '%s'.", qPrintable(QDir::toNativeSeparators(m_updateFilePath)));
188+
189+
#if defined(Q_OS_WIN)
190+
HINSTANCE exec_result = ShellExecute(NULL,
191+
NULL,
192+
reinterpret_cast<const WCHAR*>(QDir::toNativeSeparators(m_updateFilePath).utf16()),
193+
NULL,
194+
NULL,
195+
SW_NORMAL);
196+
197+
if (((int)exec_result) <= 32) {
198+
qDebug("External updater was not launched due to error.");
199+
200+
qApp->showGuiMessage(tr("Cannot update application"),
201+
tr("Cannot launch external updater. Update application manually."),
202+
QSystemTrayIcon::Warning, this);
187203
}
204+
else {
205+
qApp->quit();
206+
}
207+
#endif
188208
}
189209
else if (update_for_this_system) {
190210
// Nothing is downloaded yet, but update for this system
@@ -196,6 +216,7 @@ void FormUpdate::startUpdate() {
196216

197217
connect(m_downloader, SIGNAL(progress(qint64,qint64)), this, SLOT(updateProgress(qint64,qint64)));
198218
connect(m_downloader, SIGNAL(completed(QNetworkReply::NetworkError,QByteArray)), this, SLOT(updateCompleted(QNetworkReply::NetworkError,QByteArray)));
219+
updateProgress(0, 100);
199220
}
200221

201222
m_btnUpdate->setText(tr("Downloading update..."));

0 commit comments

Comments
 (0)