2010-11-27 19:41:58 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// LameXP - Audio Encoder Front-End
|
2017-03-12 12:12:49 +01:00
|
|
|
// Copyright (C) 2004-2017 LoRd_MuldeR <MuldeR2@GMX.de>
|
2010-11-27 19:41:58 +01:00
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation; either version 2 of the License, or
|
2013-10-23 20:56:57 +02:00
|
|
|
// (at your option) any later version, but always including the *additional*
|
|
|
|
// restrictions defined in the "License.txt" file.
|
2010-11-27 19:41:58 +01:00
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License along
|
|
|
|
// with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
//
|
|
|
|
// http://www.gnu.org/licenses/gpl-2.0.txt
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "Dialog_Update.h"
|
|
|
|
|
2012-12-09 22:39:17 +01:00
|
|
|
//UIC includes
|
2014-11-24 18:28:53 +01:00
|
|
|
#include "UIC_UpdateDialog.h"
|
2012-12-09 22:39:17 +01:00
|
|
|
|
|
|
|
//LameXP includes
|
2010-11-28 22:18:07 +01:00
|
|
|
#include "Global.h"
|
2010-11-29 20:36:27 +01:00
|
|
|
#include "Dialog_LogView.h"
|
|
|
|
#include "Model_Settings.h"
|
2010-11-28 22:18:07 +01:00
|
|
|
|
2014-11-24 19:33:12 +01:00
|
|
|
//MUtils
|
|
|
|
#include <MUtils/UpdateChecker.h>
|
2014-11-25 02:14:42 +01:00
|
|
|
#include <MUtils/Version.h>
|
2014-11-30 21:32:23 +01:00
|
|
|
#include <MUtils/Exception.h>
|
2014-12-05 21:08:26 +01:00
|
|
|
#include <MUtils/Sound.h>
|
2014-12-08 22:06:01 +01:00
|
|
|
#include <MUtils/GUI.h>
|
2014-12-04 00:02:42 +01:00
|
|
|
#include <MUtils/OSSupport.h>
|
2014-12-18 22:49:37 +01:00
|
|
|
#include <MUtils/Taskbar7.h>
|
2014-12-05 21:08:26 +01:00
|
|
|
|
2012-12-09 22:39:17 +01:00
|
|
|
//Qt includes
|
2010-11-27 19:41:58 +01:00
|
|
|
#include <QClipboard>
|
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QTimer>
|
2010-11-28 22:18:07 +01:00
|
|
|
#include <QProcess>
|
|
|
|
#include <QDesktopServices>
|
|
|
|
#include <QUrl>
|
|
|
|
#include <QCloseEvent>
|
2011-03-24 15:37:49 +01:00
|
|
|
#include <QMovie>
|
2013-12-16 18:07:45 +01:00
|
|
|
#include <QMessageBox>
|
2010-12-06 18:29:34 +01:00
|
|
|
|
2010-11-28 22:18:07 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2013-11-17 21:53:28 +01:00
|
|
|
#define SHOW_HINT(TEXT, ICON) do \
|
|
|
|
{ \
|
|
|
|
ui->hintLabel->setText((TEXT)); \
|
|
|
|
ui->hintIcon->setPixmap(QIcon((ICON)).pixmap(16,16)); \
|
|
|
|
ui->hintIcon->show(); \
|
|
|
|
ui->hintLabel->show(); \
|
|
|
|
} \
|
|
|
|
while(0)
|
|
|
|
|
|
|
|
#define UPDATE_TASKBAR(STATE, ICON) do \
|
|
|
|
{ \
|
2014-12-18 22:49:37 +01:00
|
|
|
m_taskbar->setTaskbarState((STATE)); \
|
|
|
|
m_taskbar->setOverlayIcon(&QIcon((ICON))); \
|
2013-11-17 21:53:28 +01:00
|
|
|
} \
|
|
|
|
while(0)
|
2010-11-28 22:18:07 +01:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2014-12-18 22:49:37 +01:00
|
|
|
UpdateDialog::UpdateDialog(const SettingsModel *const settings, QWidget *parent)
|
2010-11-27 19:41:58 +01:00
|
|
|
:
|
2010-11-28 22:18:07 +01:00
|
|
|
QDialog(parent),
|
2012-12-09 22:39:17 +01:00
|
|
|
ui(new Ui::UpdateDialog),
|
2014-12-18 22:49:37 +01:00
|
|
|
m_taskbar(new MUtils::Taskbar7(parent)),
|
2010-11-29 20:36:27 +01:00
|
|
|
m_settings(settings),
|
|
|
|
m_logFile(new QStringList()),
|
2011-05-03 14:28:06 +02:00
|
|
|
m_betaUpdates(settings ? (settings->autoUpdateCheckBeta() || lamexp_version_demo()) : lamexp_version_demo()),
|
2011-02-18 00:53:36 +01:00
|
|
|
m_success(false),
|
2012-04-11 00:44:40 +02:00
|
|
|
m_firstShow(true),
|
2012-01-24 02:46:29 +01:00
|
|
|
m_updateReadyToInstall(false),
|
2013-11-17 21:53:28 +01:00
|
|
|
m_updaterProcess(NULL),
|
2014-12-20 23:44:43 +01:00
|
|
|
m_binaryUpdater(lamexp_tools_lookup("wupdate.exe")),
|
|
|
|
m_binaryWGet(lamexp_tools_lookup("wget.exe")),
|
2017-04-07 20:49:12 +02:00
|
|
|
m_binaryMCat(lamexp_tools_lookup("mcat.exe")),
|
2014-12-20 23:44:43 +01:00
|
|
|
m_binaryGnuPG(lamexp_tools_lookup("gpgv.exe")),
|
2015-08-24 22:08:57 +02:00
|
|
|
m_binaryKeys(lamexp_tools_lookup("keyring.gpg"))
|
2010-11-27 19:41:58 +01:00
|
|
|
{
|
2017-04-07 20:49:12 +02:00
|
|
|
if(m_binaryUpdater.isEmpty() || m_binaryWGet.isEmpty() || m_binaryMCat.isEmpty() || m_binaryGnuPG.isEmpty() || m_binaryKeys.isEmpty())
|
2010-11-28 22:18:07 +01:00
|
|
|
{
|
2014-11-30 21:32:23 +01:00
|
|
|
MUTILS_THROW("Tools not initialized correctly!");
|
2010-11-28 22:18:07 +01:00
|
|
|
}
|
2013-11-17 21:53:28 +01:00
|
|
|
|
2010-11-27 19:41:58 +01:00
|
|
|
//Init the dialog, from the .ui file
|
2012-12-09 22:39:17 +01:00
|
|
|
ui->setupUi(this);
|
2010-11-27 19:41:58 +01:00
|
|
|
setWindowFlags(windowFlags() ^ Qt::WindowContextHelpButtonHint);
|
|
|
|
|
|
|
|
//Disable "X" button
|
2014-12-08 22:06:01 +01:00
|
|
|
MUtils::GUI::enable_close_button(this, false);
|
2010-11-27 19:41:58 +01:00
|
|
|
|
2011-03-24 15:37:49 +01:00
|
|
|
//Init animation
|
2014-12-18 22:49:37 +01:00
|
|
|
m_animator.reset(new QMovie(":/images/Loading3.gif"));
|
|
|
|
ui->labelAnimationCenter->setMovie(m_animator.data());
|
2011-03-24 15:37:49 +01:00
|
|
|
m_animator->start();
|
|
|
|
|
2011-05-07 00:50:18 +02:00
|
|
|
//Indicate beta updates
|
|
|
|
if(m_betaUpdates)
|
|
|
|
{
|
|
|
|
setWindowTitle(windowTitle().append(" [Beta]"));
|
|
|
|
}
|
|
|
|
|
2010-11-28 22:18:07 +01:00
|
|
|
//Enable button
|
2012-12-09 22:39:17 +01:00
|
|
|
connect(ui->retryButton, SIGNAL(clicked()), this, SLOT(checkForUpdates()));
|
|
|
|
connect(ui->installButton, SIGNAL(clicked()), this, SLOT(applyUpdate()));
|
|
|
|
connect(ui->infoLabel, SIGNAL(linkActivated(QString)), this, SLOT(linkActivated(QString)));
|
|
|
|
connect(ui->logButton, SIGNAL(clicked()), this, SLOT(logButtonClicked()));
|
2011-02-25 13:40:45 +01:00
|
|
|
|
|
|
|
//Enable progress bar
|
2012-12-09 22:39:17 +01:00
|
|
|
connect(ui->progressBar, SIGNAL(valueChanged(int)), this, SLOT(progressBarValueChanged(int)));
|
2010-11-27 19:41:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
UpdateDialog::~UpdateDialog(void)
|
|
|
|
{
|
2013-11-17 21:53:28 +01:00
|
|
|
if(m_animator)
|
|
|
|
{
|
|
|
|
m_animator->stop();
|
|
|
|
}
|
|
|
|
|
2014-12-18 22:49:37 +01:00
|
|
|
if(!m_thread.isNull())
|
2013-11-17 21:53:28 +01:00
|
|
|
{
|
|
|
|
if(!m_thread->wait(1000))
|
|
|
|
{
|
|
|
|
m_thread->terminate();
|
|
|
|
m_thread->wait();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-18 22:49:37 +01:00
|
|
|
m_taskbar->setTaskbarState(MUtils::Taskbar7::TASKBAR_STATE_NONE);
|
|
|
|
m_taskbar->setOverlayIcon(NULL);
|
2012-12-09 22:39:17 +01:00
|
|
|
|
2014-12-18 22:49:37 +01:00
|
|
|
delete ui;
|
2010-11-27 19:41:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void UpdateDialog::showEvent(QShowEvent *event)
|
|
|
|
{
|
2010-11-28 22:18:07 +01:00
|
|
|
QDialog::showEvent(event);
|
|
|
|
|
2012-04-11 00:44:40 +02:00
|
|
|
if(m_firstShow)
|
|
|
|
{
|
2014-12-18 22:49:37 +01:00
|
|
|
if(m_thread.isNull())
|
2013-11-17 21:53:28 +01:00
|
|
|
{
|
2017-04-07 20:49:12 +02:00
|
|
|
m_thread.reset(new MUtils::UpdateChecker(m_binaryWGet, m_binaryMCat, m_binaryGnuPG, m_binaryKeys, QLatin1String("LameXP"), lamexp_version_build(), m_betaUpdates));
|
2014-12-18 22:49:37 +01:00
|
|
|
connect(m_thread.data(), SIGNAL(statusChanged(int)), this, SLOT(threadStatusChanged(int)));
|
|
|
|
connect(m_thread.data(), SIGNAL(progressChanged(int)), this, SLOT(threadProgressChanged(int)));
|
|
|
|
connect(m_thread.data(), SIGNAL(messageLogged(QString)), this, SLOT(threadMessageLogged(QString)));
|
|
|
|
connect(m_thread.data(), SIGNAL(finished()), this, SLOT(threadFinished()));
|
|
|
|
connect(m_thread.data(), SIGNAL(terminated()), this, SLOT(threadFinished()));
|
2013-11-17 21:53:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
threadStatusChanged(m_thread->getUpdateStatus());
|
2014-11-25 22:34:20 +01:00
|
|
|
ui->labelVersionInstalled->setText(QString("%1 %2 (%3)").arg(tr("Build"), QString::number(lamexp_version_build()), MUtils::Version::app_build_date().toString(Qt::ISODate)));
|
2012-12-09 22:39:17 +01:00
|
|
|
ui->labelVersionLatest->setText(QString("(%1)").arg(tr("Unknown")));
|
|
|
|
|
|
|
|
ui->installButton->setEnabled(false);
|
|
|
|
ui->closeButton->setEnabled(false);
|
|
|
|
ui->retryButton->setEnabled(false);
|
|
|
|
ui->logButton->setEnabled(false);
|
|
|
|
ui->retryButton->hide();
|
|
|
|
ui->logButton->hide();
|
|
|
|
ui->infoLabel->hide();
|
|
|
|
ui->hintLabel->hide();
|
|
|
|
ui->hintIcon->hide();
|
|
|
|
ui->frameAnimation->hide();
|
2017-03-28 21:12:02 +02:00
|
|
|
ui->cancelLabel->hide();
|
2010-11-28 22:18:07 +01:00
|
|
|
|
2013-11-17 21:53:28 +01:00
|
|
|
ui->progressBar->setMaximum(m_thread->getMaximumProgress());
|
2012-12-09 22:39:17 +01:00
|
|
|
ui->progressBar->setValue(0);
|
2011-11-11 18:08:22 +01:00
|
|
|
|
2012-04-11 00:44:40 +02:00
|
|
|
m_updaterProcess = NULL;
|
2012-01-24 02:46:29 +01:00
|
|
|
|
2012-04-11 00:44:40 +02:00
|
|
|
QTimer::singleShot(0, this, SLOT(updateInit()));
|
|
|
|
m_firstShow = false;
|
|
|
|
}
|
2010-11-28 22:18:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void UpdateDialog::closeEvent(QCloseEvent *event)
|
|
|
|
{
|
2012-12-09 22:39:17 +01:00
|
|
|
if(!ui->closeButton->isEnabled())
|
2011-02-25 13:40:45 +01:00
|
|
|
{
|
|
|
|
event->ignore();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-12-18 22:49:37 +01:00
|
|
|
m_taskbar->setTaskbarState(MUtils::Taskbar7::TASKBAR_STATE_NONE);
|
|
|
|
m_taskbar->setOverlayIcon(NULL);
|
2011-02-25 13:40:45 +01:00
|
|
|
}
|
2010-11-27 19:41:58 +01:00
|
|
|
}
|
|
|
|
|
2010-12-08 20:52:18 +01:00
|
|
|
void UpdateDialog::keyPressEvent(QKeyEvent *e)
|
|
|
|
{
|
2017-03-28 21:12:02 +02:00
|
|
|
if (e->key() == Qt::Key_Escape)
|
|
|
|
{
|
|
|
|
if (!m_thread.isNull() && m_thread->isRunning())
|
|
|
|
{
|
|
|
|
ui->cancelLabel->hide();
|
|
|
|
ui->statusLabel->setText(tr("Stopping update check, please wait..."));
|
|
|
|
m_thread->cancel();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(e->key() == Qt::Key_F11)
|
2010-12-08 20:52:18 +01:00
|
|
|
{
|
2012-12-09 22:39:17 +01:00
|
|
|
if(ui->closeButton->isEnabled()) logButtonClicked();
|
2010-12-08 20:52:18 +01:00
|
|
|
}
|
2011-12-01 22:16:06 +01:00
|
|
|
else if((e->key() == Qt::Key_F12) && e->modifiers().testFlag(Qt::ControlModifier))
|
|
|
|
{
|
2013-11-17 21:53:28 +01:00
|
|
|
if(ui->closeButton->isEnabled()) testKnownHosts();
|
2011-12-01 22:16:06 +01:00
|
|
|
}
|
2010-12-08 20:52:18 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
QDialog::keyPressEvent(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-24 02:46:29 +01:00
|
|
|
bool UpdateDialog::event(QEvent *e)
|
|
|
|
{
|
|
|
|
if((e->type() == QEvent::ActivationChange) && (m_updaterProcess != NULL))
|
|
|
|
{
|
2014-12-08 22:06:01 +01:00
|
|
|
MUtils::GUI::bring_to_front(m_updaterProcess);
|
2012-01-24 02:46:29 +01:00
|
|
|
}
|
|
|
|
return QDialog::event(e);
|
|
|
|
}
|
|
|
|
|
2010-11-28 22:18:07 +01:00
|
|
|
void UpdateDialog::updateInit(void)
|
2010-11-27 19:41:58 +01:00
|
|
|
{
|
2010-11-28 22:18:07 +01:00
|
|
|
setMinimumSize(size());
|
|
|
|
setMaximumHeight(height());
|
2013-12-16 18:07:45 +01:00
|
|
|
QTimer::singleShot(0, this, SLOT(checkForUpdates()));
|
2010-11-28 22:18:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void UpdateDialog::checkForUpdates(void)
|
|
|
|
{
|
2013-11-17 21:53:28 +01:00
|
|
|
if(m_thread->isRunning())
|
|
|
|
{
|
|
|
|
qWarning("Update in progress, cannot check for updates now!");
|
|
|
|
}
|
2010-11-28 22:18:07 +01:00
|
|
|
|
2014-12-04 00:02:42 +01:00
|
|
|
if(!MUtils::OS::user_is_admin())
|
2013-12-16 18:07:45 +01:00
|
|
|
{
|
|
|
|
qWarning("User is not in the \"admin\" group, cannot update!");
|
|
|
|
QString message;
|
|
|
|
message += QString("<nobr>%1</nobr><br>").arg(tr("Sorry, but only users in the \"Administrators\" group can install updates."));
|
|
|
|
message += QString("<nobr>%1</nobr>").arg(tr("Please start application from an administrator account and try again!"));
|
|
|
|
if(QMessageBox::critical(this, this->windowTitle(), message, tr("Discard"), tr("Ignore")) != 1)
|
|
|
|
{
|
|
|
|
ui->closeButton->setEnabled(true);
|
|
|
|
close(); return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-18 22:49:37 +01:00
|
|
|
m_taskbar->setTaskbarState(MUtils::Taskbar7::TASKBAR_STATE_NORMAL);
|
|
|
|
m_taskbar->setOverlayIcon(&QIcon(":/icons/transmit_blue.png"));
|
2013-11-17 21:53:28 +01:00
|
|
|
|
|
|
|
ui->progressBar->setValue(0);
|
2012-12-09 22:39:17 +01:00
|
|
|
ui->installButton->setEnabled(false);
|
|
|
|
ui->closeButton->setEnabled(false);
|
|
|
|
ui->retryButton->setEnabled(false);
|
|
|
|
ui->logButton->setEnabled(false);
|
|
|
|
if(ui->infoLabel->isVisible()) ui->infoLabel->hide();
|
|
|
|
if(ui->hintLabel->isVisible()) ui->hintLabel->hide();
|
|
|
|
if(ui->hintIcon->isVisible()) ui->hintIcon->hide();
|
2017-03-28 21:12:02 +02:00
|
|
|
ui->cancelLabel->show();
|
2012-12-09 22:39:17 +01:00
|
|
|
ui->frameAnimation->show();
|
2010-11-28 22:18:07 +01:00
|
|
|
|
2013-10-19 16:00:13 +02:00
|
|
|
QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
|
2010-11-28 22:18:07 +01:00
|
|
|
QApplication::setOverrideCursor(Qt::WaitCursor);
|
|
|
|
|
2010-11-29 20:36:27 +01:00
|
|
|
m_logFile->clear();
|
2013-11-17 21:53:28 +01:00
|
|
|
m_thread->start();
|
|
|
|
}
|
2010-11-29 20:36:27 +01:00
|
|
|
|
2013-11-17 21:53:28 +01:00
|
|
|
void UpdateDialog::threadStatusChanged(const int status)
|
|
|
|
{
|
|
|
|
switch(status)
|
|
|
|
{
|
2014-11-24 19:33:12 +01:00
|
|
|
case MUtils::UpdateChecker::UpdateStatus_NotStartedYet:
|
2013-11-17 21:53:28 +01:00
|
|
|
ui->statusLabel->setText(tr("Initializing, please wait..."));
|
|
|
|
break;
|
2014-11-24 19:33:12 +01:00
|
|
|
case MUtils::UpdateChecker::UpdateStatus_CheckingConnection:
|
2013-11-17 21:53:28 +01:00
|
|
|
ui->statusLabel->setText(tr("Testing your internet connection, please wait..."));
|
|
|
|
break;
|
2014-11-24 19:33:12 +01:00
|
|
|
case MUtils::UpdateChecker::UpdateStatus_FetchingUpdates:
|
2013-11-17 21:53:28 +01:00
|
|
|
ui->statusLabel->setText(tr("Checking for new updates online, please wait..."));
|
|
|
|
break;
|
2014-11-24 19:33:12 +01:00
|
|
|
case MUtils::UpdateChecker::UpdateStatus_CompletedUpdateAvailable:
|
2012-12-09 22:39:17 +01:00
|
|
|
ui->statusLabel->setText(tr("A new version of LameXP is available!"));
|
2013-11-17 21:53:28 +01:00
|
|
|
SHOW_HINT(tr("We highly recommend all users to install this update as soon as possible."), ":/icons/shield_exclamation.png");
|
2014-12-18 22:49:37 +01:00
|
|
|
UPDATE_TASKBAR(MUtils::Taskbar7::TASKBAR_STATE_NORMAL, ":/icons/shield_exclamation.png");
|
2013-11-17 21:53:28 +01:00
|
|
|
break;
|
2014-11-24 19:33:12 +01:00
|
|
|
case MUtils::UpdateChecker::UpdateStatus_CompletedNoUpdates:
|
2012-12-09 22:39:17 +01:00
|
|
|
ui->statusLabel->setText(tr("No new updates available at this time."));
|
2013-11-17 21:53:28 +01:00
|
|
|
SHOW_HINT(tr("Your version of LameXP is still up-to-date. Please check for updates regularly!"), ":/icons/shield_green.png");
|
2014-12-18 22:49:37 +01:00
|
|
|
UPDATE_TASKBAR(MUtils::Taskbar7::TASKBAR_STATE_NORMAL, ":/icons/shield_green.png");
|
2013-11-17 21:53:28 +01:00
|
|
|
break;
|
2014-11-24 19:33:12 +01:00
|
|
|
case MUtils::UpdateChecker::UpdateStatus_CompletedNewVersionOlder:
|
2012-12-09 22:39:17 +01:00
|
|
|
ui->statusLabel->setText(tr("Your version appears to be newer than the latest release."));
|
2013-12-16 18:07:45 +01:00
|
|
|
SHOW_HINT(tr("This usually indicates your are currently using a pre-release version of LameXP."), ":/icons/shield_blue.png");
|
2014-12-18 22:49:37 +01:00
|
|
|
UPDATE_TASKBAR(MUtils::Taskbar7::TASKBAR_STATE_NORMAL, ":/icons/shield_error.png");
|
2013-11-17 21:53:28 +01:00
|
|
|
break;
|
2014-11-24 19:33:12 +01:00
|
|
|
case MUtils::UpdateChecker::UpdateStatus_ErrorNoConnection:
|
2013-11-17 21:53:28 +01:00
|
|
|
ui->statusLabel->setText(tr("It appears that the computer currently is offline!"));
|
|
|
|
SHOW_HINT(tr("Please make sure your computer is connected to the internet and try again."), ":/icons/network_error.png");
|
2014-12-18 22:49:37 +01:00
|
|
|
UPDATE_TASKBAR(MUtils::Taskbar7::TASKBAR_STATE_NORMAL, ":/icons/exclamation.png");
|
2013-11-17 21:53:28 +01:00
|
|
|
break;
|
2014-11-24 19:33:12 +01:00
|
|
|
case MUtils::UpdateChecker::UpdateStatus_ErrorConnectionTestFailed:
|
2013-11-17 21:53:28 +01:00
|
|
|
ui->statusLabel->setText(tr("Network connectivity test has failed!"));
|
|
|
|
SHOW_HINT(tr("Please make sure your computer is connected to the internet and try again."), ":/icons/network_error.png");
|
2014-12-18 22:49:37 +01:00
|
|
|
UPDATE_TASKBAR(MUtils::Taskbar7::TASKBAR_STATE_NORMAL, ":/icons/exclamation.png");
|
2013-11-17 21:53:28 +01:00
|
|
|
break;
|
2014-11-24 19:33:12 +01:00
|
|
|
case MUtils::UpdateChecker::UpdateStatus_ErrorFetchUpdateInfo:
|
2013-11-17 21:53:28 +01:00
|
|
|
ui->statusLabel->setText(tr("Failed to fetch update information from server!"));
|
|
|
|
SHOW_HINT(tr("Sorry, the update server might be busy at this time. Plase try again later."), ":/icons/server_error.png");
|
2014-12-18 22:49:37 +01:00
|
|
|
UPDATE_TASKBAR(MUtils::Taskbar7::TASKBAR_STATE_NORMAL, ":/icons/exclamation.png");
|
2013-11-17 21:53:28 +01:00
|
|
|
break;
|
2017-03-28 21:12:02 +02:00
|
|
|
case MUtils::UpdateChecker::UpdateStatus_CancelledByUser:
|
|
|
|
ui->statusLabel->setText(tr("Update check has been cancelled!"));
|
|
|
|
SHOW_HINT(tr("The update check has been cancelled by the user. Please try again later."), ":/icons/server_error.png");
|
|
|
|
UPDATE_TASKBAR(MUtils::Taskbar7::TASKBAR_STATE_NORMAL, ":/icons/exclamation.png");
|
|
|
|
break;
|
2013-11-17 21:53:28 +01:00
|
|
|
default:
|
|
|
|
qWarning("Unknown status %d !!!", int(status));
|
2010-11-28 22:18:07 +01:00
|
|
|
}
|
2010-11-27 19:41:58 +01:00
|
|
|
}
|
|
|
|
|
2013-11-17 21:53:28 +01:00
|
|
|
void UpdateDialog::threadProgressChanged(const int progress)
|
2010-11-28 22:18:07 +01:00
|
|
|
{
|
2013-11-17 21:53:28 +01:00
|
|
|
ui->progressBar->setValue(progress);
|
2010-11-28 22:18:07 +01:00
|
|
|
}
|
|
|
|
|
2013-11-17 21:53:28 +01:00
|
|
|
void UpdateDialog::threadMessageLogged(const QString &message)
|
2010-11-28 22:18:07 +01:00
|
|
|
{
|
2013-11-17 21:53:28 +01:00
|
|
|
(*m_logFile) << message;
|
2010-11-28 22:18:07 +01:00
|
|
|
}
|
|
|
|
|
2013-11-17 21:53:28 +01:00
|
|
|
void UpdateDialog::threadFinished(void)
|
2010-11-28 22:18:07 +01:00
|
|
|
{
|
2013-11-17 21:53:28 +01:00
|
|
|
const bool bSuccess = m_thread->getSuccess();
|
2010-11-28 22:18:07 +01:00
|
|
|
|
2013-11-17 21:53:28 +01:00
|
|
|
ui->closeButton->setEnabled(true);
|
2017-03-28 21:12:02 +02:00
|
|
|
ui->cancelLabel->hide();
|
2013-11-17 21:53:28 +01:00
|
|
|
if(ui->frameAnimation->isVisible()) ui->frameAnimation->hide();
|
|
|
|
ui->progressBar->setValue(ui->progressBar->maximum());
|
2010-11-28 22:18:07 +01:00
|
|
|
|
2013-11-17 21:53:28 +01:00
|
|
|
if(!bSuccess)
|
2010-11-28 22:18:07 +01:00
|
|
|
{
|
2014-12-05 21:08:26 +01:00
|
|
|
if(m_settings->soundsEnabled()) MUtils::Sound::play_sound("error", true);
|
2010-11-28 22:18:07 +01:00
|
|
|
}
|
2013-11-17 21:53:28 +01:00
|
|
|
else
|
2010-11-28 22:18:07 +01:00
|
|
|
{
|
2014-11-24 19:33:12 +01:00
|
|
|
const bool bHaveUpdate = (m_thread->getUpdateStatus() == MUtils::UpdateChecker::UpdateStatus_CompletedUpdateAvailable);
|
2013-11-17 21:53:28 +01:00
|
|
|
ui->installButton->setEnabled(bHaveUpdate);
|
2014-12-05 21:08:26 +01:00
|
|
|
MUtils::Sound::beep(bHaveUpdate ? MUtils::Sound::BEEP_NFO : MUtils::Sound::BEEP_WRN);
|
2010-11-28 22:18:07 +01:00
|
|
|
|
2014-11-24 19:33:12 +01:00
|
|
|
if(const MUtils::UpdateCheckerInfo *const updateInfo = m_thread->getUpdateInfo())
|
2010-11-28 22:18:07 +01:00
|
|
|
{
|
2014-11-24 19:33:12 +01:00
|
|
|
ui->infoLabel->setText(QString("%1<br><a href=\"%2\">%2</a>").arg(tr("More information available at:"), updateInfo->getDownloadSite()));
|
|
|
|
ui->labelVersionLatest->setText(QString("%1 %2 (%3)").arg(tr("Build"), QString::number(updateInfo->getBuildNo()), updateInfo->getBuildDate().toString(Qt::ISODate)));
|
2013-11-17 21:53:28 +01:00
|
|
|
ui->infoLabel->show();
|
2010-11-28 22:18:07 +01:00
|
|
|
}
|
|
|
|
|
2013-11-17 21:53:28 +01:00
|
|
|
m_success = true;
|
2011-02-12 22:17:42 +01:00
|
|
|
}
|
2010-11-28 22:18:07 +01:00
|
|
|
|
2013-11-17 21:53:28 +01:00
|
|
|
ui->retryButton->setVisible(!bSuccess);
|
|
|
|
ui->logButton->setVisible(!bSuccess);
|
|
|
|
ui->retryButton->setEnabled(!bSuccess);
|
|
|
|
ui->logButton->setEnabled(!bSuccess);
|
|
|
|
|
|
|
|
QApplication::restoreOverrideCursor();
|
2010-11-28 22:18:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void UpdateDialog::linkActivated(const QString &link)
|
|
|
|
{
|
|
|
|
QDesktopServices::openUrl(QUrl(link));
|
|
|
|
}
|
|
|
|
|
|
|
|
void UpdateDialog::applyUpdate(void)
|
|
|
|
{
|
2012-12-09 22:39:17 +01:00
|
|
|
ui->installButton->setEnabled(false);
|
|
|
|
ui->closeButton->setEnabled(false);
|
|
|
|
ui->retryButton->setEnabled(false);
|
2010-11-28 22:18:07 +01:00
|
|
|
|
2014-11-24 19:33:12 +01:00
|
|
|
if(const MUtils::UpdateCheckerInfo *updateInfo = m_thread->getUpdateInfo())
|
2010-11-28 22:18:07 +01:00
|
|
|
{
|
2012-12-09 22:39:17 +01:00
|
|
|
ui->statusLabel->setText(tr("Update is being downloaded, please be patient..."));
|
|
|
|
ui->frameAnimation->show();
|
|
|
|
if(ui->hintLabel->isVisible()) ui->hintLabel->hide();
|
|
|
|
if(ui->hintIcon->isVisible()) ui->hintIcon->hide();
|
|
|
|
int oldMax = ui->progressBar->maximum();
|
|
|
|
int oldMin = ui->progressBar->minimum();
|
|
|
|
ui->progressBar->setRange(0, 0);
|
2013-10-19 16:00:13 +02:00
|
|
|
QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
|
2010-11-28 22:18:07 +01:00
|
|
|
|
|
|
|
QProcess process;
|
|
|
|
QStringList args;
|
|
|
|
QEventLoop loop;
|
|
|
|
|
2014-11-25 02:14:42 +01:00
|
|
|
MUtils::init_process(process, QFileInfo(m_binaryUpdater).absolutePath(), false);
|
2013-10-29 02:05:43 +01:00
|
|
|
|
2010-11-28 22:18:07 +01:00
|
|
|
connect(&process, SIGNAL(error(QProcess::ProcessError)), &loop, SLOT(quit()));
|
|
|
|
connect(&process, SIGNAL(finished(int,QProcess::ExitStatus)), &loop, SLOT(quit()));
|
|
|
|
|
2014-11-24 19:33:12 +01:00
|
|
|
args << QString("/Location=%1").arg(updateInfo->getDownloadAddress());
|
|
|
|
args << QString("/Filename=%1").arg(updateInfo->getDownloadFilename());
|
|
|
|
args << QString("/TicketID=%1").arg(updateInfo->getDownloadFilecode());
|
2015-08-16 16:25:02 +02:00
|
|
|
args << QString("/CheckSum=%1").arg(updateInfo->getDownloadChecksum());
|
|
|
|
args << QString("/ToFolder=%1").arg(QDir::toNativeSeparators(QDir(QApplication::applicationDirPath()).canonicalPath()));
|
2011-01-25 00:11:28 +01:00
|
|
|
args << QString("/ToExFile=%1.exe").arg(QFileInfo(QFileInfo(QApplication::applicationFilePath()).canonicalFilePath()).completeBaseName());
|
2014-11-24 19:33:12 +01:00
|
|
|
args << QString("/AppTitle=LameXP (Build #%1)").arg(QString::number(updateInfo->getBuildNo()));
|
2010-11-28 22:18:07 +01:00
|
|
|
|
|
|
|
QApplication::setOverrideCursor(Qt::WaitCursor);
|
2014-12-18 22:49:37 +01:00
|
|
|
UPDATE_TASKBAR(MUtils::Taskbar7::TASKBAR_STATE_INTERMEDIATE, ":/icons/transmit_blue.png");
|
2011-02-25 13:40:45 +01:00
|
|
|
|
2010-11-28 22:18:07 +01:00
|
|
|
process.start(m_binaryUpdater, args);
|
2012-01-24 02:46:29 +01:00
|
|
|
bool updateStarted = process.waitForStarted();
|
|
|
|
if(updateStarted)
|
|
|
|
{
|
2014-12-04 00:02:42 +01:00
|
|
|
m_updaterProcess = MUtils::OS::process_id(&process);
|
2013-10-29 02:05:43 +01:00
|
|
|
loop.exec(QEventLoop::ExcludeUserInputEvents);
|
2012-01-24 02:46:29 +01:00
|
|
|
}
|
2013-11-25 02:20:44 +01:00
|
|
|
|
2012-01-24 02:46:29 +01:00
|
|
|
m_updaterProcess = NULL;
|
2010-11-28 22:18:07 +01:00
|
|
|
QApplication::restoreOverrideCursor();
|
2011-02-25 13:40:45 +01:00
|
|
|
|
2012-12-09 22:39:17 +01:00
|
|
|
ui->hintLabel->show();
|
|
|
|
ui->hintIcon->show();
|
|
|
|
ui->progressBar->setRange(oldMin, oldMax);
|
|
|
|
ui->progressBar->setValue(oldMax);
|
|
|
|
ui->frameAnimation->hide();
|
2011-03-25 15:18:13 +01:00
|
|
|
|
2012-01-24 02:46:29 +01:00
|
|
|
if(updateStarted && (process.exitCode() == 0))
|
2010-11-28 22:18:07 +01:00
|
|
|
{
|
2012-12-09 22:39:17 +01:00
|
|
|
ui->statusLabel->setText(tr("Update ready to install. Applicaion will quit..."));
|
2011-02-18 00:53:36 +01:00
|
|
|
m_updateReadyToInstall = true;
|
2014-12-18 22:49:37 +01:00
|
|
|
m_taskbar->setTaskbarState(MUtils::Taskbar7::TASKBAR_STATE_NONE);
|
|
|
|
m_taskbar->setOverlayIcon(NULL);
|
2010-11-29 20:36:27 +01:00
|
|
|
accept();
|
2010-11-28 22:18:07 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-12-09 22:39:17 +01:00
|
|
|
ui->statusLabel->setText(tr("Update failed. Please try again or download manually!"));
|
2014-12-18 22:49:37 +01:00
|
|
|
m_taskbar->setTaskbarState(MUtils::Taskbar7::TASKBAR_STATE_ERROR);
|
|
|
|
m_taskbar->setOverlayIcon(&QIcon(":/icons/exclamation.png"));
|
|
|
|
m_taskbar->setTaskbarProgress(100, 100);
|
2010-11-28 22:18:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-09 22:39:17 +01:00
|
|
|
ui->installButton->setEnabled(true);
|
|
|
|
ui->closeButton->setEnabled(true);
|
2010-11-28 22:18:07 +01:00
|
|
|
}
|
2010-11-29 20:36:27 +01:00
|
|
|
|
|
|
|
void UpdateDialog::logButtonClicked(void)
|
|
|
|
{
|
|
|
|
LogViewDialog *logView = new LogViewDialog(this);
|
|
|
|
logView->exec(*m_logFile);
|
2014-11-25 02:14:42 +01:00
|
|
|
MUTILS_DELETE(logView);
|
2010-11-29 20:36:27 +01:00
|
|
|
}
|
2011-02-25 13:40:45 +01:00
|
|
|
|
|
|
|
void UpdateDialog::progressBarValueChanged(int value)
|
|
|
|
{
|
2014-12-18 22:49:37 +01:00
|
|
|
m_taskbar->setTaskbarProgress(value, ui->progressBar->maximum());
|
2011-02-25 13:40:45 +01:00
|
|
|
}
|
2011-12-01 22:16:06 +01:00
|
|
|
|
2013-11-17 21:53:28 +01:00
|
|
|
void UpdateDialog::testKnownHosts(void)
|
2011-12-01 22:16:06 +01:00
|
|
|
{
|
2012-12-09 22:39:17 +01:00
|
|
|
ui->statusLabel->setText("Testing all known hosts, this may take a few minutes...");
|
2011-12-01 22:16:06 +01:00
|
|
|
|
2017-04-07 20:49:12 +02:00
|
|
|
if(MUtils::UpdateChecker *testThread = new MUtils::UpdateChecker(m_binaryWGet, m_binaryMCat, m_binaryGnuPG, m_binaryKeys, QLatin1String("LameXP"), lamexp_version_build(), m_betaUpdates, true))
|
2011-12-01 22:16:06 +01:00
|
|
|
{
|
2013-11-17 21:53:28 +01:00
|
|
|
QEventLoop loop;
|
|
|
|
m_logFile->clear();
|
2011-12-01 22:16:06 +01:00
|
|
|
|
2013-11-17 21:53:28 +01:00
|
|
|
connect(testThread, SIGNAL(messageLogged(QString)), this, SLOT(threadMessageLogged(QString)));
|
|
|
|
connect(testThread, SIGNAL(finished()), &loop, SLOT(quit()));
|
|
|
|
connect(testThread, SIGNAL(terminated()), &loop, SLOT(quit()));
|
2011-12-02 22:40:12 +01:00
|
|
|
|
2013-11-17 21:53:28 +01:00
|
|
|
testThread->start();
|
2017-12-08 22:43:54 +01:00
|
|
|
|
|
|
|
ui->progressBar->setMaximum(0);
|
|
|
|
ui->progressBar->setMinimum(0);
|
|
|
|
|
|
|
|
bool status[4];
|
|
|
|
status[0] = ui->closeButton ->isEnabled(); ui->closeButton ->setEnabled(false);
|
|
|
|
status[1] = ui->installButton->isEnabled(); ui->installButton->setEnabled(false);
|
|
|
|
status[2] = ui->retryButton ->isEnabled(); ui->retryButton ->setEnabled(false);
|
|
|
|
status[3] = ui->logButton ->isEnabled(); ui->logButton ->setEnabled(false);
|
|
|
|
|
2013-11-17 21:53:28 +01:00
|
|
|
while(testThread->isRunning())
|
2011-12-01 22:16:06 +01:00
|
|
|
{
|
2017-12-08 22:43:54 +01:00
|
|
|
QTimer::singleShot(8000, &loop, SLOT(quit()));
|
2013-11-17 21:53:28 +01:00
|
|
|
loop.exec(QEventLoop::ExcludeUserInputEvents);
|
2011-12-01 22:16:06 +01:00
|
|
|
}
|
|
|
|
|
2017-12-08 22:43:54 +01:00
|
|
|
ui->progressBar->setMaximum(m_thread.isNull() ? 100 : m_thread->getMaximumProgress());
|
|
|
|
ui->progressBar->setValue(ui->progressBar->maximum());
|
|
|
|
|
|
|
|
ui->closeButton ->setEnabled(status[0]);
|
|
|
|
ui->installButton->setEnabled(status[1]);
|
|
|
|
ui->retryButton ->setEnabled(status[2]);
|
|
|
|
ui->logButton ->setEnabled(status[3]);
|
|
|
|
|
2014-11-25 02:14:42 +01:00
|
|
|
MUTILS_DELETE(testThread);
|
2013-11-17 21:53:28 +01:00
|
|
|
logButtonClicked();
|
2011-12-01 22:16:06 +01:00
|
|
|
}
|
|
|
|
|
2012-12-09 22:39:17 +01:00
|
|
|
ui->statusLabel->setText("Test completed.");
|
2014-12-05 21:08:26 +01:00
|
|
|
MUtils::Sound::beep(MUtils::Sound::BEEP_NFO);
|
2011-12-01 22:16:06 +01:00
|
|
|
}
|