2010-11-27 19:41:58 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// LameXP - Audio Encoder Front-End
|
|
|
|
// Copyright (C) 2004-2010 LoRd_MuldeR <MuldeR2@GMX.de>
|
|
|
|
//
|
|
|
|
// 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
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// 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"
|
|
|
|
|
2010-11-28 22:18:07 +01:00
|
|
|
#include "Global.h"
|
|
|
|
#include "Resource.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
|
|
|
|
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 <QUuid>
|
|
|
|
#include <QDate>
|
|
|
|
#include <QRegExp>
|
|
|
|
#include <QDesktopServices>
|
|
|
|
#include <QUrl>
|
|
|
|
#include <QCloseEvent>
|
2010-11-27 19:41:58 +01:00
|
|
|
|
|
|
|
#include <Windows.h>
|
|
|
|
|
2010-11-28 22:18:07 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
static const char *section_id = "LameXP";
|
|
|
|
|
|
|
|
static const char *mirror_url_postfix = "update_beta.ver";
|
|
|
|
|
2010-12-06 18:29:34 +01:00
|
|
|
static const char *update_mirrors[] =
|
2010-11-28 22:18:07 +01:00
|
|
|
{
|
|
|
|
"http://mulder.dummwiedeutsch.de/",
|
|
|
|
"http://mulder.brhack.net/",
|
|
|
|
"http://free.pages.at/borschdfresser/",
|
|
|
|
"http://mplayer.savedonthe.net/",
|
|
|
|
"http://www.tricksoft.de/",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2010-12-06 18:29:34 +01:00
|
|
|
static const char *known_hosts[] =
|
|
|
|
{
|
|
|
|
"http://www.example.com/",
|
|
|
|
"http://www.google.com/",
|
|
|
|
"http://www.wikipedia.org/",
|
|
|
|
"http://www.msn.com/",
|
|
|
|
"http://www.yahoo.com/",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static const int MIN_CONNSCORE = 2;
|
|
|
|
static char *USER_AGENT_STR = "Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.12) Gecko/20101101 IceCat/3.6.12 (like Firefox/3.6.12)";
|
|
|
|
|
2010-11-28 22:18:07 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
class UpdateInfo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
UpdateInfo(void)
|
|
|
|
:
|
|
|
|
m_buildNo(0),
|
|
|
|
m_buildDate(1900, 1, 1),
|
|
|
|
m_downloadSite(""),
|
|
|
|
m_downloadAddress(""),
|
|
|
|
m_downloadFilename(""),
|
|
|
|
m_downloadFilecode("")
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int m_buildNo;
|
|
|
|
QDate m_buildDate;
|
|
|
|
QString m_downloadSite;
|
|
|
|
QString m_downloadAddress;
|
|
|
|
QString m_downloadFilename;
|
|
|
|
QString m_downloadFilecode;
|
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2010-11-29 20:36:27 +01:00
|
|
|
UpdateDialog::UpdateDialog(SettingsModel *settings, QWidget *parent)
|
2010-11-27 19:41:58 +01:00
|
|
|
:
|
2010-11-28 22:18:07 +01:00
|
|
|
QDialog(parent),
|
|
|
|
m_binaryWGet(lamexp_lookup_tool("wget.exe")),
|
|
|
|
m_binaryGnuPG(lamexp_lookup_tool("gpgv.exe")),
|
|
|
|
m_binaryUpdater(lamexp_lookup_tool("wupdate.exe")),
|
|
|
|
m_binaryKeys(lamexp_lookup_tool("gpgv.gpg")),
|
2010-11-29 20:36:27 +01:00
|
|
|
m_updateInfo(NULL),
|
|
|
|
m_settings(settings),
|
|
|
|
m_logFile(new QStringList()),
|
|
|
|
m_success(false)
|
2010-11-27 19:41:58 +01:00
|
|
|
{
|
2010-11-28 22:18:07 +01:00
|
|
|
if(m_binaryWGet.isEmpty() || m_binaryGnuPG.isEmpty() || m_binaryUpdater.isEmpty() || m_binaryKeys.isEmpty())
|
|
|
|
{
|
|
|
|
throw "Tools not initialized correctly!";
|
|
|
|
}
|
|
|
|
|
2010-11-27 19:41:58 +01:00
|
|
|
//Init the dialog, from the .ui file
|
|
|
|
setupUi(this);
|
|
|
|
setWindowFlags(windowFlags() ^ Qt::WindowContextHelpButtonHint);
|
|
|
|
|
|
|
|
//Disable "X" button
|
|
|
|
HMENU hMenu = GetSystemMenu((HWND) winId(), FALSE);
|
|
|
|
EnableMenuItem(hMenu, SC_CLOSE, MF_BYCOMMAND | MF_GRAYED);
|
|
|
|
|
2010-11-28 22:18:07 +01:00
|
|
|
//Enable button
|
|
|
|
connect(retryButton, SIGNAL(clicked()), this, SLOT(checkForUpdates()));
|
|
|
|
connect(installButton, SIGNAL(clicked()), this, SLOT(applyUpdate()));
|
|
|
|
connect(infoLabel, SIGNAL(linkActivated(QString)), this, SLOT(linkActivated(QString)));
|
2010-11-29 20:36:27 +01:00
|
|
|
connect(logButton, SIGNAL(clicked()), this, SLOT(logButtonClicked()));
|
2010-11-27 19:41:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
UpdateDialog::~UpdateDialog(void)
|
|
|
|
{
|
2010-11-28 22:18:07 +01:00
|
|
|
LAMEXP_DELETE(m_updateInfo);
|
2010-11-29 20:36:27 +01:00
|
|
|
LAMEXP_DELETE(m_logFile);
|
2010-11-27 19:41:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void UpdateDialog::showEvent(QShowEvent *event)
|
|
|
|
{
|
2010-11-28 22:18:07 +01:00
|
|
|
QDialog::showEvent(event);
|
|
|
|
|
|
|
|
labelVersionInstalled->setText(QString("Build %1 (%2)").arg(QString::number(lamexp_version_build()), lamexp_version_date().toString(Qt::ISODate)));
|
|
|
|
labelVersionLatest->setText("(Unknown)");
|
|
|
|
|
|
|
|
QTimer::singleShot(0, this, SLOT(updateInit()));
|
2010-11-27 19:41:58 +01:00
|
|
|
installButton->setEnabled(false);
|
|
|
|
closeButton->setEnabled(false);
|
2010-11-28 22:18:07 +01:00
|
|
|
retryButton->setEnabled(false);
|
2010-11-29 20:36:27 +01:00
|
|
|
logButton->setEnabled(false);
|
2010-11-28 22:18:07 +01:00
|
|
|
retryButton->hide();
|
2010-11-29 20:36:27 +01:00
|
|
|
logButton->hide();
|
2010-11-28 22:18:07 +01:00
|
|
|
infoLabel->hide();
|
|
|
|
|
2010-12-06 18:29:34 +01:00
|
|
|
int counter = 2;
|
|
|
|
for(int i = 0; known_hosts[i]; i++) counter++;
|
|
|
|
for(int i = 0; update_mirrors[i]; i++) counter++;
|
2010-11-28 22:18:07 +01:00
|
|
|
|
2010-12-06 18:29:34 +01:00
|
|
|
progressBar->setMaximum(counter);
|
2010-11-28 22:18:07 +01:00
|
|
|
progressBar->setValue(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void UpdateDialog::closeEvent(QCloseEvent *event)
|
|
|
|
{
|
|
|
|
if(!closeButton->isEnabled()) event->ignore();
|
2010-11-27 19:41:58 +01:00
|
|
|
}
|
|
|
|
|
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());
|
|
|
|
|
|
|
|
checkForUpdates();
|
|
|
|
}
|
|
|
|
|
|
|
|
void UpdateDialog::checkForUpdates(void)
|
|
|
|
{
|
|
|
|
bool success = false;
|
2010-12-06 18:29:34 +01:00
|
|
|
int connectionScore = 0;
|
|
|
|
|
2010-11-28 22:18:07 +01:00
|
|
|
m_updateInfo = new UpdateInfo;
|
|
|
|
|
|
|
|
progressBar->setValue(0);
|
|
|
|
installButton->setEnabled(false);
|
|
|
|
closeButton->setEnabled(false);
|
|
|
|
retryButton->setEnabled(false);
|
2010-11-29 20:36:27 +01:00
|
|
|
logButton->setEnabled(false);
|
2010-11-28 22:18:07 +01:00
|
|
|
if(infoLabel->isVisible()) infoLabel->hide();
|
|
|
|
|
|
|
|
QApplication::processEvents();
|
|
|
|
QApplication::setOverrideCursor(Qt::WaitCursor);
|
|
|
|
|
2010-12-06 18:29:34 +01:00
|
|
|
statusLabel->setText("Testing your internet connection, please wait...");
|
|
|
|
|
2010-11-29 20:36:27 +01:00
|
|
|
m_logFile->clear();
|
2010-12-06 18:29:34 +01:00
|
|
|
m_logFile->append("Checking internet connection...");
|
|
|
|
|
|
|
|
for(int i = 0; known_hosts[i]; i++)
|
|
|
|
{
|
|
|
|
progressBar->setValue(progressBar->value() + 1);
|
|
|
|
if(connectionScore < MIN_CONNSCORE)
|
|
|
|
{
|
|
|
|
m_logFile->append(QStringList() << "" << "Testing host:" << known_hosts[i] << "");
|
|
|
|
QString outFile = QString("%1/%2.htm").arg(QDir::tempPath(), QUuid::createUuid().toString());
|
|
|
|
if(getFile(known_hosts[i], outFile))
|
|
|
|
{
|
|
|
|
connectionScore++;
|
|
|
|
}
|
|
|
|
QFile::remove(outFile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(connectionScore < MIN_CONNSCORE)
|
|
|
|
{
|
|
|
|
if(!retryButton->isVisible()) retryButton->show();
|
|
|
|
if(!logButton->isVisible()) logButton->show();
|
|
|
|
closeButton->setEnabled(true);
|
|
|
|
retryButton->setEnabled(true);
|
|
|
|
logButton->setEnabled(true);
|
|
|
|
statusLabel->setText("Connectivity test faild. Please check your internet connection!");
|
|
|
|
progressBar->setValue(progressBar->maximum());
|
|
|
|
LAMEXP_DELETE(m_updateInfo);
|
|
|
|
if(m_settings->soundsEnabled()) PlaySound(MAKEINTRESOURCE(IDR_WAVE_ERROR), GetModuleHandle(NULL), SND_RESOURCE | SND_ASYNC);
|
|
|
|
QApplication::restoreOverrideCursor();
|
|
|
|
progressBar->setValue(progressBar->maximum());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
statusLabel->setText("Checking for new updates online, please wait...");
|
2010-11-29 20:36:27 +01:00
|
|
|
m_logFile->append("Checking for updates online...");
|
|
|
|
|
2010-12-06 18:29:34 +01:00
|
|
|
for(int i = 0; update_mirrors[i]; i++)
|
2010-11-28 22:18:07 +01:00
|
|
|
{
|
2010-12-06 18:29:34 +01:00
|
|
|
progressBar->setValue(progressBar->value() + 1);
|
|
|
|
if(!success)
|
2010-11-28 22:18:07 +01:00
|
|
|
{
|
2010-12-06 18:29:34 +01:00
|
|
|
if(tryUpdateMirror(m_updateInfo, update_mirrors[i]))
|
|
|
|
{
|
|
|
|
success = true;
|
|
|
|
}
|
2010-11-28 22:18:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QApplication::restoreOverrideCursor();
|
2010-12-06 18:29:34 +01:00
|
|
|
progressBar->setValue(progressBar->maximum());
|
2010-11-28 22:18:07 +01:00
|
|
|
|
|
|
|
if(!success)
|
|
|
|
{
|
|
|
|
if(!retryButton->isVisible()) retryButton->show();
|
2010-11-29 20:36:27 +01:00
|
|
|
if(!logButton->isVisible()) logButton->show();
|
2010-11-28 22:18:07 +01:00
|
|
|
closeButton->setEnabled(true);
|
|
|
|
retryButton->setEnabled(true);
|
2010-11-29 20:36:27 +01:00
|
|
|
logButton->setEnabled(true);
|
2010-12-06 18:29:34 +01:00
|
|
|
statusLabel->setText("Failed to fetch update information from server. Try again later!");
|
2010-11-28 22:18:07 +01:00
|
|
|
progressBar->setValue(progressBar->maximum());
|
|
|
|
LAMEXP_DELETE(m_updateInfo);
|
2010-11-29 20:36:27 +01:00
|
|
|
if(m_settings->soundsEnabled()) PlaySound(MAKEINTRESOURCE(IDR_WAVE_ERROR), GetModuleHandle(NULL), SND_RESOURCE | SND_ASYNC);
|
2010-11-28 22:18:07 +01:00
|
|
|
return;
|
|
|
|
}
|
2010-11-29 20:36:27 +01:00
|
|
|
|
2010-11-28 22:18:07 +01:00
|
|
|
labelVersionLatest->setText(QString("Build %1 (%2)").arg(QString::number(m_updateInfo->m_buildNo), m_updateInfo->m_buildDate.toString(Qt::ISODate)));
|
|
|
|
infoLabel->show();
|
|
|
|
infoLabel->setText(QString("More information available at:<br><a href=\"%1\">%1</a>").arg(m_updateInfo->m_downloadSite));
|
|
|
|
QApplication::processEvents();
|
|
|
|
|
|
|
|
if(m_updateInfo->m_buildNo > lamexp_version_build())
|
|
|
|
{
|
|
|
|
installButton->setEnabled(true);
|
|
|
|
statusLabel->setText("A new version of LameXP is available. Update highly recommended!");
|
|
|
|
MessageBeep(MB_ICONINFORMATION);
|
|
|
|
}
|
|
|
|
else if(m_updateInfo->m_buildNo == lamexp_version_build())
|
|
|
|
{
|
|
|
|
statusLabel->setText("No new updates avialbale. Your version of LameXP is up-to-date.");
|
|
|
|
MessageBeep(MB_ICONINFORMATION);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
statusLabel->setText("Your version appears to be newer than the latest release.");
|
|
|
|
MessageBeep(MB_ICONEXCLAMATION);
|
|
|
|
}
|
|
|
|
|
2010-11-27 19:41:58 +01:00
|
|
|
closeButton->setEnabled(true);
|
2010-11-28 22:18:07 +01:00
|
|
|
if(retryButton->isVisible()) retryButton->hide();
|
2010-11-29 20:36:27 +01:00
|
|
|
if(logButton->isVisible()) logButton->hide();
|
|
|
|
|
|
|
|
m_success = true;
|
2010-11-27 19:41:58 +01:00
|
|
|
}
|
|
|
|
|
2010-11-28 22:18:07 +01:00
|
|
|
bool UpdateDialog::tryUpdateMirror(UpdateInfo *updateInfo, const QString &url)
|
|
|
|
{
|
|
|
|
bool success = false;
|
2010-11-29 20:36:27 +01:00
|
|
|
m_logFile->append(QStringList() << "" << "Trying mirror:" << url);
|
2010-11-28 22:18:07 +01:00
|
|
|
|
|
|
|
QUuid uuid = QUuid::createUuid();
|
|
|
|
QString outFileVersionInfo = QString("%1/%2.ver").arg(QDir::tempPath(), uuid.toString());
|
|
|
|
QString outFileSignature = QString("%1/%2.sig").arg(QDir::tempPath(), uuid.toString());
|
|
|
|
|
2010-11-29 20:36:27 +01:00
|
|
|
m_logFile->append(QStringList() << "" << "Downloading update info:");
|
2010-11-28 22:18:07 +01:00
|
|
|
bool ok1 = getFile(QString("%1%2").arg(url,mirror_url_postfix), outFileVersionInfo);
|
|
|
|
|
2010-11-29 20:36:27 +01:00
|
|
|
m_logFile->append(QStringList() << "" << "Downloading signature:");
|
2010-11-28 22:18:07 +01:00
|
|
|
bool ok2 = getFile(QString("%1%2.sig").arg(url,mirror_url_postfix), outFileSignature);
|
|
|
|
|
|
|
|
if(ok1 && ok2)
|
|
|
|
{
|
2010-11-29 20:36:27 +01:00
|
|
|
m_logFile->append(QStringList() << "" << "Download okay, checking signature:");
|
2010-11-28 22:18:07 +01:00
|
|
|
if(checkSignature(outFileVersionInfo, outFileSignature))
|
|
|
|
{
|
2010-11-29 20:36:27 +01:00
|
|
|
m_logFile->append(QStringList() << "" << "Signature okay, parsing info:");
|
2010-11-28 22:18:07 +01:00
|
|
|
success = parseVersionInfo(outFileVersionInfo, updateInfo);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-11-29 20:36:27 +01:00
|
|
|
m_logFile->append(QStringList() << "" << "Bad signature, take care!");
|
2010-11-28 22:18:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-11-29 20:36:27 +01:00
|
|
|
m_logFile->append(QStringList() << "" << "Download has failed!");
|
2010-11-28 22:18:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QFile::remove(outFileVersionInfo);
|
|
|
|
QFile::remove(outFileSignature);
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool UpdateDialog::getFile(const QString &url, const QString &outFile)
|
|
|
|
{
|
|
|
|
QFileInfo output(outFile);
|
|
|
|
output.setCaching(false);
|
|
|
|
|
|
|
|
if(output.exists())
|
|
|
|
{
|
|
|
|
QFile::remove(output.canonicalFilePath());
|
|
|
|
if(output.exists())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QProcess process;
|
|
|
|
process.setProcessChannelMode(QProcess::MergedChannels);
|
|
|
|
process.setReadChannel(QProcess::StandardOutput);
|
2010-12-06 22:25:20 +01:00
|
|
|
process.setWorkingDirectory(output.absolutePath());
|
2010-11-28 22:18:07 +01:00
|
|
|
|
|
|
|
QEventLoop loop;
|
|
|
|
connect(&process, SIGNAL(error(QProcess::ProcessError)), &loop, SLOT(quit()));
|
|
|
|
connect(&process, SIGNAL(finished(int,QProcess::ExitStatus)), &loop, SLOT(quit()));
|
|
|
|
connect(&process, SIGNAL(readyRead()), &loop, SLOT(quit()));
|
|
|
|
|
2010-12-06 22:25:20 +01:00
|
|
|
process.start(m_binaryWGet, QStringList() << "-U" << USER_AGENT_STR << "-O" << output.fileName() << url);
|
2010-11-28 22:18:07 +01:00
|
|
|
|
|
|
|
if(!process.waitForStarted())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
while(process.state() == QProcess::Running)
|
|
|
|
{
|
|
|
|
loop.exec();
|
|
|
|
while(process.canReadLine())
|
|
|
|
{
|
2010-11-29 20:36:27 +01:00
|
|
|
m_logFile->append(QString::fromLatin1(process.readLine()).simplified());
|
2010-11-28 22:18:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-29 20:36:27 +01:00
|
|
|
m_logFile->append(QString().sprintf("Exited with code %d", process.exitCode()));
|
2010-11-28 22:18:07 +01:00
|
|
|
return (process.exitCode() == 0) && output.exists() && output.isFile();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool UpdateDialog::checkSignature(const QString &file, const QString &signature)
|
|
|
|
{
|
2010-12-06 22:25:20 +01:00
|
|
|
if(QFileInfo(file).absolutePath().compare(QFileInfo(signature).absolutePath(), Qt::CaseInsensitive) != 0)
|
|
|
|
{
|
|
|
|
qWarning("CheckSignature: File and signature should be in same folder!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString keyring = QString("%1/%2.gpg").arg(QFileInfo(file).absolutePath(), QUuid::createUuid().toString());
|
|
|
|
|
|
|
|
if(!QFile::copy(m_binaryKeys, keyring))
|
|
|
|
{
|
|
|
|
qWarning("CheckSignature: Failed to copy keyring file to destination folder!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-11-28 22:18:07 +01:00
|
|
|
QProcess process;
|
|
|
|
process.setProcessChannelMode(QProcess::MergedChannels);
|
|
|
|
process.setReadChannel(QProcess::StandardOutput);
|
2010-12-06 22:25:20 +01:00
|
|
|
process.setWorkingDirectory(QFileInfo(file).absolutePath());
|
2010-11-28 22:18:07 +01:00
|
|
|
|
|
|
|
QEventLoop loop;
|
|
|
|
connect(&process, SIGNAL(error(QProcess::ProcessError)), &loop, SLOT(quit()));
|
|
|
|
connect(&process, SIGNAL(finished(int,QProcess::ExitStatus)), &loop, SLOT(quit()));
|
|
|
|
connect(&process, SIGNAL(readyRead()), &loop, SLOT(quit()));
|
|
|
|
|
2010-12-06 22:25:20 +01:00
|
|
|
process.start(m_binaryGnuPG, QStringList() << "--homedir" << "." << "--keyring" << QFileInfo(keyring).fileName() << QFileInfo(signature).fileName() << QFileInfo(file).fileName());
|
2010-11-28 22:18:07 +01:00
|
|
|
|
|
|
|
if(!process.waitForStarted())
|
|
|
|
{
|
2010-12-06 22:25:20 +01:00
|
|
|
QFile::remove(keyring);
|
2010-11-28 22:18:07 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
while(process.state() == QProcess::Running)
|
|
|
|
{
|
|
|
|
loop.exec();
|
|
|
|
while(process.canReadLine())
|
|
|
|
{
|
2010-11-29 20:36:27 +01:00
|
|
|
m_logFile->append(QString::fromLatin1(process.readLine()).simplified());
|
2010-11-28 22:18:07 +01:00
|
|
|
}
|
|
|
|
}
|
2010-12-06 22:25:20 +01:00
|
|
|
|
|
|
|
QFile::remove(keyring);
|
2010-11-28 22:18:07 +01:00
|
|
|
|
2010-11-29 20:36:27 +01:00
|
|
|
m_logFile->append(QString().sprintf("Exited with code %d", process.exitCode()));
|
2010-11-28 22:18:07 +01:00
|
|
|
return (process.exitCode() == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool UpdateDialog::parseVersionInfo(const QString &file, UpdateInfo *updateInfo)
|
|
|
|
{
|
|
|
|
|
|
|
|
QRegExp value("^(\\w+)=(.+)$");
|
|
|
|
QRegExp section("^\\[(.+)\\]$");
|
|
|
|
|
|
|
|
QFile data(file);
|
|
|
|
if(!data.open(QIODevice::ReadOnly))
|
|
|
|
{
|
|
|
|
qWarning("Cannot open update info file for reading!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool inSection = false;
|
|
|
|
|
|
|
|
while(!data.atEnd())
|
|
|
|
{
|
|
|
|
QString line = QString::fromLatin1(data.readLine()).trimmed();
|
|
|
|
if(section.indexIn(line) >= 0)
|
|
|
|
{
|
2010-11-29 20:36:27 +01:00
|
|
|
m_logFile->append(QString("[%1]").arg(section.cap(1)));
|
2010-11-28 22:18:07 +01:00
|
|
|
inSection = (section.cap(1).compare(section_id, Qt::CaseInsensitive) == 0);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if(inSection && value.indexIn(line) >= 0)
|
|
|
|
{
|
2010-11-29 20:36:27 +01:00
|
|
|
m_logFile->append(QString("'%1' ==> '%2").arg(value.cap(1), value.cap(2)));
|
2010-11-28 22:18:07 +01:00
|
|
|
if(value.cap(1).compare("BuildNo", Qt::CaseInsensitive) == 0)
|
|
|
|
{
|
|
|
|
bool ok = false;
|
|
|
|
unsigned int temp = value.cap(2).toUInt(&ok);
|
|
|
|
if(ok) updateInfo->m_buildNo = temp;
|
|
|
|
}
|
|
|
|
else if(value.cap(1).compare("BuildDate", Qt::CaseInsensitive) == 0)
|
|
|
|
{
|
|
|
|
QDate temp = QDate::fromString(value.cap(2).trimmed(), Qt::ISODate);
|
|
|
|
if(temp.isValid()) updateInfo->m_buildDate = temp;
|
|
|
|
}
|
|
|
|
else if(value.cap(1).compare("DownloadSite", Qt::CaseInsensitive) == 0)
|
|
|
|
{
|
|
|
|
updateInfo->m_downloadSite = value.cap(2).trimmed();
|
|
|
|
}
|
|
|
|
else if(value.cap(1).compare("DownloadAddress", Qt::CaseInsensitive) == 0)
|
|
|
|
{
|
|
|
|
updateInfo->m_downloadAddress = value.cap(2).trimmed();
|
|
|
|
}
|
|
|
|
else if(value.cap(1).compare("DownloadFilename", Qt::CaseInsensitive) == 0)
|
|
|
|
{
|
|
|
|
updateInfo->m_downloadFilename = value.cap(2).trimmed();
|
|
|
|
}
|
|
|
|
else if(value.cap(1).compare("DownloadFilecode", Qt::CaseInsensitive) == 0)
|
|
|
|
{
|
|
|
|
updateInfo->m_downloadFilecode = value.cap(2).trimmed();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool complete = true;
|
|
|
|
|
|
|
|
if(!(updateInfo->m_buildNo > 0)) complete = false;
|
|
|
|
if(!(updateInfo->m_buildDate.year() >= 2010)) complete = false;
|
|
|
|
if(updateInfo->m_downloadSite.isEmpty()) complete = false;
|
|
|
|
if(updateInfo->m_downloadAddress.isEmpty()) complete = false;
|
|
|
|
if(updateInfo->m_downloadFilename.isEmpty()) complete = false;
|
|
|
|
if(updateInfo->m_downloadFilecode.isEmpty()) complete = false;
|
|
|
|
|
|
|
|
return complete;
|
|
|
|
}
|
|
|
|
|
|
|
|
void UpdateDialog::linkActivated(const QString &link)
|
|
|
|
{
|
|
|
|
QDesktopServices::openUrl(QUrl(link));
|
|
|
|
}
|
|
|
|
|
|
|
|
void UpdateDialog::applyUpdate(void)
|
|
|
|
{
|
|
|
|
installButton->setEnabled(false);
|
|
|
|
closeButton->setEnabled(false);
|
|
|
|
retryButton->setEnabled(false);
|
|
|
|
|
|
|
|
if(m_updateInfo)
|
|
|
|
{
|
|
|
|
statusLabel->setText("Update is being downloaded, please be patient...");
|
|
|
|
QApplication::processEvents();
|
|
|
|
|
|
|
|
QProcess process;
|
|
|
|
QStringList args;
|
|
|
|
QEventLoop loop;
|
|
|
|
|
|
|
|
connect(&process, SIGNAL(error(QProcess::ProcessError)), &loop, SLOT(quit()));
|
|
|
|
connect(&process, SIGNAL(finished(int,QProcess::ExitStatus)), &loop, SLOT(quit()));
|
|
|
|
|
|
|
|
args << QString("/Location=%1").arg(m_updateInfo->m_downloadAddress);
|
|
|
|
args << QString("/Filename=%1").arg(m_updateInfo->m_downloadFilename);
|
|
|
|
args << QString("/TicketID=%1").arg(m_updateInfo->m_downloadFilecode);
|
|
|
|
args << QString("/ToFolder=%1").arg(QDir::toNativeSeparators(QApplication::applicationDirPath()));
|
|
|
|
args << QString("/AppTitle=LameXP (Build #%1)").arg(QString::number(m_updateInfo->m_buildNo));
|
|
|
|
|
|
|
|
QApplication::setOverrideCursor(Qt::WaitCursor);
|
|
|
|
process.start(m_binaryUpdater, args);
|
|
|
|
loop.exec();
|
|
|
|
QApplication::restoreOverrideCursor();
|
|
|
|
|
|
|
|
if(process.exitCode() == 0)
|
|
|
|
{
|
|
|
|
statusLabel->setText("Update ready to install. Applicaion will quit...");
|
|
|
|
QApplication::quit();
|
2010-11-29 20:36:27 +01:00
|
|
|
accept();
|
2010-11-28 22:18:07 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
statusLabel->setText("Update failed. Please try again or download manually!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
installButton->setEnabled(true);
|
|
|
|
closeButton->setEnabled(true);
|
|
|
|
}
|
2010-11-29 20:36:27 +01:00
|
|
|
|
|
|
|
void UpdateDialog::logButtonClicked(void)
|
|
|
|
{
|
|
|
|
LogViewDialog *logView = new LogViewDialog(this);
|
|
|
|
logView->exec(*m_logFile);
|
|
|
|
LAMEXP_DELETE(logView);
|
|
|
|
}
|