OSDN Git Service

Moved some more OS-specific functions into the MUtilities library.
[lamexp/LameXP.git] / src / Dialog_Update.cpp
index 7c73b61..5e40984 100644 (file)
@@ -1,11 +1,12 @@
 ///////////////////////////////////////////////////////////////////////////////
 // LameXP - Audio Encoder Front-End
-// Copyright (C) 2004-2011 LoRd_MuldeR <MuldeR2@GMX.de>
+// Copyright (C) 2004-2014 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.
+// (at your option) any later version, but always including the *additional*
+// restrictions defined in the "License.txt" file.
 //
 // This program is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
 
 #include "Dialog_Update.h"
 
+//UIC includes
+#include "UIC_UpdateDialog.h"
+
+//LameXP includes
 #include "Global.h"
-#include "Resource.h"
 #include "Dialog_LogView.h"
 #include "Model_Settings.h"
+#include "WinSevenTaskbar.h"
+
+//MUtils
+#include <MUtils/UpdateChecker.h>
+#include <MUtils/Version.h>
+#include <MUtils/Exception.h>
+#include <MUtils/OSSupport.h>
 
+//Qt includes
 #include <QClipboard>
 #include <QFileDialog>
 #include <QTimer>
 #include <QProcess>
-#include <QDate>
-#include <QRegExp>
 #include <QDesktopServices>
 #include <QUrl>
 #include <QCloseEvent>
-
-#include <Windows.h>
-
-///////////////////////////////////////////////////////////////////////////////
-
-static const char *section_id = "LameXP";
-
-static const char *mirror_url_postfix[] = 
-{
-       "update.ver",
-       "update_beta.ver",
-       NULL
-};
-
-static const char *update_mirrors[] =
-{
-       "http://mulder.dummwiedeutsch.de/",
-       "http://mulder.brhack.net/",
-       "http://lamexp.sourceforge.net/",
-       "http://free.pages.at/borschdfresser/",
-       "http://mplayer.savedonthe.net/",
-       "http://www.tricksoft.de/",
-       NULL
-};
-
-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/",
-       "http://sourceforge.net/",
-       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)";
+#include <QMovie>
+#include <QMessageBox>
 
 ///////////////////////////////////////////////////////////////////////////////
 
-class UpdateInfo
-{
-public:
-       UpdateInfo(void) { resetInfo(); }
-       
-       void resetInfo(void)
-       {
-               m_buildNo = 0;
-               m_buildDate.setDate(1900, 1, 1);
-               m_downloadSite.clear();
-               m_downloadAddress.clear();
-               m_downloadFilename.clear();
-               m_downloadFilecode.clear();
-       }
-
-       unsigned int m_buildNo;
-       QDate m_buildDate;
-       QString m_downloadSite;
-       QString m_downloadAddress;
-       QString m_downloadFilename;
-       QString m_downloadFilecode;
-};
+#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 \
+{ \
+       WinSevenTaskbar::setTaskbarState(this->parentWidget(), (STATE)); \
+       WinSevenTaskbar::setOverlayIcon(this->parentWidget(), &QIcon((ICON))); \
+} \
+while(0)
 
 ///////////////////////////////////////////////////////////////////////////////
 
 UpdateDialog::UpdateDialog(SettingsModel *settings, QWidget *parent)
 :
        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")),
-       m_updateInfo(NULL),
+       ui(new Ui::UpdateDialog),
+       m_thread(NULL),
        m_settings(settings),
        m_logFile(new QStringList()),
-       m_success(false)
+       m_betaUpdates(settings ? (settings->autoUpdateCheckBeta() || lamexp_version_demo()) : lamexp_version_demo()),
+       m_success(false),
+       m_firstShow(true),
+       m_updateReadyToInstall(false),
+       m_updaterProcess(NULL),
+       m_binaryUpdater(lamexp_lookup_tool("wupdate.exe")),
+       m_binaryWGet(lamexp_lookup_tool("wget.exe")),
+       m_binaryGnuPG(lamexp_lookup_tool("gpgv.exe")),
+       m_binaryKeys(lamexp_lookup_tool("gpgv.gpg"))
 {
-       if(m_binaryWGet.isEmpty() || m_binaryGnuPG.isEmpty() || m_binaryUpdater.isEmpty() || m_binaryKeys.isEmpty())
+       if(m_binaryUpdater.isEmpty())
        {
-               throw "Tools not initialized correctly!";
+               MUTILS_THROW("Tools not initialized correctly!");
        }
-       
+
        //Init the dialog, from the .ui file
-       setupUi(this);
+       ui->setupUi(this);
        setWindowFlags(windowFlags() ^ Qt::WindowContextHelpButtonHint);
 
        //Disable "X" button
-       HMENU hMenu = GetSystemMenu((HWND) winId(), FALSE);
-       EnableMenuItem(hMenu, SC_CLOSE, MF_BYCOMMAND | MF_GRAYED);
+       lamexp_enable_close_button(this, false);
+
+       //Init animation
+       m_animator = new QMovie(":/images/Loading3.gif");
+       ui->labelAnimationCenter->setMovie(m_animator);
+       m_animator->start();
 
+       //Indicate beta updates
+       if(m_betaUpdates)
+       {
+               setWindowTitle(windowTitle().append(" [Beta]"));
+       }
+       
        //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)));
-       connect(logButton, SIGNAL(clicked()), this, SLOT(logButtonClicked()));
+       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()));
+
+       //Enable progress bar
+       connect(ui->progressBar, SIGNAL(valueChanged(int)), this, SLOT(progressBarValueChanged(int)));
 }
 
 UpdateDialog::~UpdateDialog(void)
 {
-       LAMEXP_DELETE(m_updateInfo);
-       LAMEXP_DELETE(m_logFile);
+       if(m_animator)
+       {
+               m_animator->stop();
+       }
+
+       if(m_thread)
+       {
+               if(!m_thread->wait(1000))
+               {
+                       m_thread->terminate();
+                       m_thread->wait();
+               }
+       }
+
+       MUTILS_DELETE(m_thread);
+       MUTILS_DELETE(m_logFile);
+       MUTILS_DELETE(m_animator);
+
+       WinSevenTaskbar::setTaskbarState(this->parentWidget(), WinSevenTaskbar::WinSevenTaskbarNoState);
+       WinSevenTaskbar::setOverlayIcon(this->parentWidget(), NULL);
+
+       MUTILS_DELETE(ui);
 }
 
 void UpdateDialog::showEvent(QShowEvent *event)
 {
        QDialog::showEvent(event);
        
-       labelVersionInstalled->setText(QString("%1 %2 (%3)").arg(tr("Build"), QString::number(lamexp_version_build()), lamexp_version_date().toString(Qt::ISODate)));
-       labelVersionLatest->setText(QString("(%1)").arg(tr("Unknown")));
-
-       QTimer::singleShot(0, this, SLOT(updateInit()));
-       installButton->setEnabled(false);
-       closeButton->setEnabled(false);
-       retryButton->setEnabled(false);
-       logButton->setEnabled(false);
-       retryButton->hide();
-       logButton->hide();
-       infoLabel->hide();
-       hintLabel->hide();
-       hintIcon->hide();
+       if(m_firstShow)
+       {
+               if(!m_thread)
+               {
+                       m_thread = new MUtils::UpdateChecker(m_binaryWGet, m_binaryGnuPG, m_binaryKeys, QLatin1String("LameXP"), lamexp_version_build(), m_betaUpdates);
+                       connect(m_thread, SIGNAL(statusChanged(int)), this, SLOT(threadStatusChanged(int)));
+                       connect(m_thread, SIGNAL(progressChanged(int)), this, SLOT(threadProgressChanged(int)));
+                       connect(m_thread, SIGNAL(messageLogged(QString)), this, SLOT(threadMessageLogged(QString)));
+                       connect(m_thread, SIGNAL(finished()), this, SLOT(threadFinished()));
+                       connect(m_thread, SIGNAL(terminated()), this, SLOT(threadFinished()));
+               }
+
+               threadStatusChanged(m_thread->getUpdateStatus());
+               ui->labelVersionInstalled->setText(QString("%1 %2 (%3)").arg(tr("Build"), QString::number(lamexp_version_build()), MUtils::Version::app_build_date().toString(Qt::ISODate)));
+               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();
        
-       int counter = 2;
-       for(int i = 0; known_hosts[i]; i++) counter++;
-       for(int i = 0; update_mirrors[i]; i++) counter++;
+               ui->progressBar->setMaximum(m_thread->getMaximumProgress());
+               ui->progressBar->setValue(0);
+
+               m_updaterProcess = NULL;
 
-       progressBar->setMaximum(counter);
-       progressBar->setValue(0);
+               QTimer::singleShot(0, this, SLOT(updateInit()));
+               m_firstShow = false;
+       }
 }
 
 void UpdateDialog::closeEvent(QCloseEvent *event)
 {
-       if(!closeButton->isEnabled()) event->ignore();
+       if(!ui->closeButton->isEnabled())
+       {
+               event->ignore();
+       }
+       else
+       {
+               WinSevenTaskbar::setTaskbarState(this->parentWidget(), WinSevenTaskbar::WinSevenTaskbarNoState);
+               WinSevenTaskbar::setOverlayIcon(this->parentWidget(), NULL);
+       }
 }
 
 void UpdateDialog::keyPressEvent(QKeyEvent *e)
 {
        if(e->key() == Qt::Key_F11)
        {
-               if(closeButton->isEnabled()) logButtonClicked();
+               if(ui->closeButton->isEnabled()) logButtonClicked();
+       }
+       else if((e->key() == Qt::Key_F12) && e->modifiers().testFlag(Qt::ControlModifier))
+       {
+               if(ui->closeButton->isEnabled()) testKnownHosts();
        }
        else
        {
@@ -182,349 +214,159 @@ void UpdateDialog::keyPressEvent(QKeyEvent *e)
        }
 }
 
+bool UpdateDialog::event(QEvent *e)
+{
+       if((e->type() == QEvent::ActivationChange) && (m_updaterProcess != NULL))
+       {
+               lamexp_bring_process_to_front(m_updaterProcess);
+       }
+       return QDialog::event(e);
+}
+
+bool UpdateDialog::winEvent(MSG *message, long *result)
+{
+       return WinSevenTaskbar::handleWinEvent(message, result);
+}
+
 void UpdateDialog::updateInit(void)
 {
        setMinimumSize(size());
        setMaximumHeight(height());
-
-       checkForUpdates();
+       QTimer::singleShot(0, this, SLOT(checkForUpdates()));
 }
 
 void UpdateDialog::checkForUpdates(void)
 {
-       bool success = false;
-       int connectionScore = 0;
-
-       m_updateInfo = new UpdateInfo;
-
-       progressBar->setValue(0);
-       installButton->setEnabled(false);
-       closeButton->setEnabled(false);
-       retryButton->setEnabled(false);
-       logButton->setEnabled(false);
-       if(infoLabel->isVisible()) infoLabel->hide();
-       if(hintLabel->isVisible()) hintLabel->hide();
-       if(hintIcon->isVisible()) hintIcon->hide();
-
-       QApplication::processEvents();
-       QApplication::setOverrideCursor(Qt::WaitCursor);
-
-       statusLabel->setText(tr("Testing your internet connection, please wait..."));
-
-       m_logFile->clear();
-       m_logFile->append("Checking internet connection...");
-
-       for(int i = 0; known_hosts[i]; i++)
+       if(m_thread->isRunning())
        {
-               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(lamexp_temp_folder(), lamexp_rand_str());
-                       if(getFile(known_hosts[i], outFile))
-                       {
-                               connectionScore++;
-                       }
-                       QFile::remove(outFile);
-               }
+               qWarning("Update in progress, cannot check for updates now!");
        }
 
-       if(connectionScore < MIN_CONNSCORE)
+       if(!MUtils::OS::user_is_admin())
        {
-               if(!retryButton->isVisible()) retryButton->show();
-               if(!logButton->isVisible()) logButton->show();
-               closeButton->setEnabled(true);
-               retryButton->setEnabled(true);
-               logButton->setEnabled(true);
-               statusLabel->setText(tr("Network connectivity test has failed!"));
-               progressBar->setValue(progressBar->maximum());
-               hintIcon->setPixmap(QIcon(":/icons/error.png").pixmap(16,16));
-               hintLabel->setText(tr("Please make sure your internet connection is working properly and try again."));
-               hintIcon->show();
-               hintLabel->show();
-               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(tr("Checking for new updates online, please wait..."));
-       m_logFile->append("Checking for updates online...");
-       
-       for(int i = 0; update_mirrors[i]; i++)
-       {
-               progressBar->setValue(progressBar->value() + 1);
-               if(!success)
+               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)
                {
-                       if(tryUpdateMirror(m_updateInfo, update_mirrors[i]))
-                       {
-                               success = true;
-                       }
+                       ui->closeButton->setEnabled(true);
+                       close(); return;
                }
        }
-       
-       QApplication::restoreOverrideCursor();
-       progressBar->setValue(progressBar->maximum());
 
-       if(!success)
-       {
-               if(!retryButton->isVisible()) retryButton->show();
-               if(!logButton->isVisible()) logButton->show();
-               closeButton->setEnabled(true);
-               retryButton->setEnabled(true);
-               logButton->setEnabled(true);
-               statusLabel->setText(tr("Failed to fetch update information from server!"));
-               progressBar->setValue(progressBar->maximum());
-               hintIcon->setPixmap(QIcon(":/icons/server_error.png").pixmap(16,16));
-               hintLabel->setText(tr("Sorry, the update server might be busy at this time. Plase try again later."));
-               hintIcon->show();
-               hintLabel->show();
-               LAMEXP_DELETE(m_updateInfo);
-               if(m_settings->soundsEnabled()) PlaySound(MAKEINTRESOURCE(IDR_WAVE_ERROR), GetModuleHandle(NULL), SND_RESOURCE | SND_ASYNC);
-               return;
-       }
+       WinSevenTaskbar::setTaskbarState(this->parentWidget(), WinSevenTaskbar::WinSevenTaskbarNormalState);
+       WinSevenTaskbar::setOverlayIcon(this->parentWidget(), &QIcon(":/icons/transmit_blue.png"));
 
-       labelVersionLatest->setText(QString("%1 %2 (%3)").arg(tr("Build"), QString::number(m_updateInfo->m_buildNo), m_updateInfo->m_buildDate.toString(Qt::ISODate)));
-       infoLabel->show();
-       infoLabel->setText(QString("%1<br><a href=\"%2\">%2</a>").arg(tr("More information available at:"), m_updateInfo->m_downloadSite));
-       QApplication::processEvents();
-       
-       if(m_updateInfo->m_buildNo > lamexp_version_build())
-       {
-               installButton->setEnabled(true);
-               statusLabel->setText(tr("A new version of LameXP is available!"));
-               hintIcon->setPixmap(QIcon(":/icons/bell.png").pixmap(16,16));
-               hintLabel->setText(tr("We highly recommend all users to install this update as soon as possible."));
-               hintIcon->show();
-               hintLabel->show();
-               MessageBeep(MB_ICONINFORMATION);
-       }
-       else if(m_updateInfo->m_buildNo == lamexp_version_build())
-       {
-               statusLabel->setText(tr("No new updates available at this time."));
-               hintIcon->setPixmap(QIcon(":/icons/information.png").pixmap(16,16));
-               hintLabel->setText(tr("Your version of LameXP is still up-to-date. Please check for updates regularly!"));
-               hintIcon->show();
-               hintLabel->show();
-               MessageBeep(MB_ICONINFORMATION);
-       }
-       else
-       {
-               statusLabel->setText(tr("Your version appears to be newer than the latest release."));
-               hintIcon->setPixmap(QIcon(":/icons/bug.png").pixmap(16,16));
-               hintLabel->setText(tr("This usually indicates your are currently using a pre-release version of LameXP."));
-               hintIcon->show();
-               hintLabel->show();
-               MessageBeep(MB_ICONEXCLAMATION);
-       }
+       ui->progressBar->setValue(0);
+       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();
+       ui->frameAnimation->show();
 
-       closeButton->setEnabled(true);
-       if(retryButton->isVisible()) retryButton->hide();
-       if(logButton->isVisible()) logButton->hide();
+       QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
+       QApplication::setOverrideCursor(Qt::WaitCursor);
 
-       m_success = true;
+       m_logFile->clear();
+       m_thread->start();
 }
 
-bool UpdateDialog::tryUpdateMirror(UpdateInfo *updateInfo, const QString &url)
+void UpdateDialog::threadStatusChanged(const int status)
 {
-       bool success = false;
-       m_logFile->append(QStringList() << "" << "Trying mirror:" << url);
-       
-       QString randPart = lamexp_rand_str();
-       QString outFileVersionInfo = QString("%1/%2.ver").arg(lamexp_temp_folder(), randPart);
-       QString outFileSignature = QString("%1/%2.sig").arg(lamexp_temp_folder(), randPart);
-
-       m_logFile->append(QStringList() << "" << "Downloading update info:");
-       bool ok1 = getFile(QString("%1%2").arg(url, mirror_url_postfix[lamexp_version_demo() ? 1 : 0]), outFileVersionInfo);
-
-       m_logFile->append(QStringList() << "" << "Downloading signature:");
-       bool ok2 = getFile(QString("%1%2.sig").arg(url, mirror_url_postfix[lamexp_version_demo() ? 1 : 0]), outFileSignature);
-
-       if(ok1 && ok2)
-       {
-               m_logFile->append(QStringList() << "" << "Download okay, checking signature:");
-               if(checkSignature(outFileVersionInfo, outFileSignature))
-               {
-                       m_logFile->append(QStringList() << "" << "Signature okay, parsing info:");
-                       success = parseVersionInfo(outFileVersionInfo, updateInfo);
-               }
-               else
-               {
-                       m_logFile->append(QStringList() << "" << "Bad signature, take care!");
-               }
-       }
-       else
+       switch(status)
        {
-               m_logFile->append(QStringList() << "" << "Download has failed!");
+       case MUtils::UpdateChecker::UpdateStatus_NotStartedYet:
+               ui->statusLabel->setText(tr("Initializing, please wait..."));
+               break;
+       case MUtils::UpdateChecker::UpdateStatus_CheckingConnection:
+               ui->statusLabel->setText(tr("Testing your internet connection, please wait..."));
+               break;
+       case MUtils::UpdateChecker::UpdateStatus_FetchingUpdates:
+               ui->statusLabel->setText(tr("Checking for new updates online, please wait..."));
+               break;
+       case MUtils::UpdateChecker::UpdateStatus_CompletedUpdateAvailable:
+               ui->statusLabel->setText(tr("A new version of LameXP is available!"));
+               SHOW_HINT(tr("We highly recommend all users to install this update as soon as possible."), ":/icons/shield_exclamation.png");
+               UPDATE_TASKBAR(WinSevenTaskbar::WinSevenTaskbarNormalState, ":/icons/shield_exclamation.png");
+               break;
+       case MUtils::UpdateChecker::UpdateStatus_CompletedNoUpdates:
+               ui->statusLabel->setText(tr("No new updates available at this time."));
+               SHOW_HINT(tr("Your version of LameXP is still up-to-date. Please check for updates regularly!"), ":/icons/shield_green.png");
+               UPDATE_TASKBAR(WinSevenTaskbar::WinSevenTaskbarNormalState, ":/icons/shield_green.png");
+               break;
+       case MUtils::UpdateChecker::UpdateStatus_CompletedNewVersionOlder:
+               ui->statusLabel->setText(tr("Your version appears to be newer than the latest release."));
+               SHOW_HINT(tr("This usually indicates your are currently using a pre-release version of LameXP."), ":/icons/shield_blue.png");
+               UPDATE_TASKBAR(WinSevenTaskbar::WinSevenTaskbarNormalState, ":/icons/shield_error.png");
+               break;
+       case MUtils::UpdateChecker::UpdateStatus_ErrorNoConnection:
+               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");
+               UPDATE_TASKBAR(WinSevenTaskbar::WinSevenTaskbarErrorState, ":/icons/exclamation.png");
+               break;
+       case MUtils::UpdateChecker::UpdateStatus_ErrorConnectionTestFailed:
+               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");
+               UPDATE_TASKBAR(WinSevenTaskbar::WinSevenTaskbarErrorState, ":/icons/exclamation.png");
+               break;
+       case MUtils::UpdateChecker::UpdateStatus_ErrorFetchUpdateInfo:
+               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");
+               UPDATE_TASKBAR(WinSevenTaskbar::WinSevenTaskbarErrorState, ":/icons/exclamation.png");
+               break;
+       default:
+               qWarning("Unknown status %d !!!", int(status));
        }
-
-       QFile::remove(outFileVersionInfo);
-       QFile::remove(outFileSignature);
-       
-       return success;
 }
 
-bool UpdateDialog::getFile(const QString &url, const QString &outFile)
+void UpdateDialog::threadProgressChanged(const int progress)
 {
-       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);
-       process.setWorkingDirectory(output.absolutePath());
-
-       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()));
-
-       process.start(m_binaryWGet, QStringList() << "-U" << USER_AGENT_STR << "-O" << output.fileName() << url);
-       
-       if(!process.waitForStarted())
-       {
-               return false;
-       }
-
-       while(process.state() == QProcess::Running)
-       {
-               loop.exec();
-               while(process.canReadLine())
-               {
-                       m_logFile->append(QString::fromLatin1(process.readLine()).simplified());
-               }
-       }
-       
-       m_logFile->append(QString().sprintf("Exited with code %d", process.exitCode()));
-       return (process.exitCode() == 0) && output.exists() && output.isFile();
+       ui->progressBar->setValue(progress);
 }
 
-bool UpdateDialog::checkSignature(const QString &file, const QString &signature)
+void UpdateDialog::threadMessageLogged(const QString &message)
 {
-       if(QFileInfo(file).absolutePath().compare(QFileInfo(signature).absolutePath(), Qt::CaseInsensitive) != 0)
-       {
-               qWarning("CheckSignature: File and signature should be in same folder!");
-               return false;
-       }
-       if(QFileInfo(file).absolutePath().compare(QFileInfo(m_binaryKeys).absolutePath(), Qt::CaseInsensitive) != 0)
-       {
-               qWarning("CheckSignature: File and keyring should be in same folder!");
-               return false;
-       }
-
-       QProcess process;
-       process.setProcessChannelMode(QProcess::MergedChannels);
-       process.setReadChannel(QProcess::StandardOutput);
-       process.setWorkingDirectory(QFileInfo(file).absolutePath());
-
-       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()));
-       
-       process.start(m_binaryGnuPG, QStringList() << "--homedir" << "." << "--keyring" << QFileInfo(m_binaryKeys).fileName() << QFileInfo(signature).fileName() << QFileInfo(file).fileName());
-
-       if(!process.waitForStarted())
-       {
-               return false;
-       }
-
-       while(process.state() == QProcess::Running)
-       {
-               loop.exec();
-               while(process.canReadLine())
-               {
-                       m_logFile->append(QString::fromLatin1(process.readLine()).simplified());
-               }
-       }
-       
-       m_logFile->append(QString().sprintf("Exited with code %d", process.exitCode()));
-       return (process.exitCode() == 0);
+       (*m_logFile) << message;
 }
 
-bool UpdateDialog::parseVersionInfo(const QString &file, UpdateInfo *updateInfo)
+void UpdateDialog::threadFinished(void)
 {
-       QRegExp value("^(\\w+)=(.+)$");
-       QRegExp section("^\\[(.+)\\]$");
-
-       updateInfo->resetInfo();
+       const bool bSuccess = m_thread->getSuccess();
+       
+       ui->closeButton->setEnabled(true);
+       if(ui->frameAnimation->isVisible()) ui->frameAnimation->hide();
+       ui->progressBar->setValue(ui->progressBar->maximum());
 
-       QFile data(file);
-       if(!data.open(QIODevice::ReadOnly))
+       if(!bSuccess)
        {
-               qWarning("Cannot open update info file for reading!");
-               return false;
+               if(m_settings->soundsEnabled()) lamexp_play_sound("error", true);
        }
-       
-       bool inSection = false;
-       
-       while(!data.atEnd())
+       else
        {
-               QString line = QString::fromLatin1(data.readLine()).trimmed();
-               if(section.indexIn(line) >= 0)
-               {
-                       m_logFile->append(QString("Sec: [%1]").arg(section.cap(1)));
-                       inSection = (section.cap(1).compare(section_id, Qt::CaseInsensitive) == 0);
-                       continue;
-               }
-               if(inSection && value.indexIn(line) >= 0)
+               const bool bHaveUpdate = (m_thread->getUpdateStatus() == MUtils::UpdateChecker::UpdateStatus_CompletedUpdateAvailable);
+               ui->installButton->setEnabled(bHaveUpdate);
+               lamexp_beep(bHaveUpdate ? lamexp_beep_info : lamexp_beep_warning);
+
+               if(const MUtils::UpdateCheckerInfo *const updateInfo = m_thread->getUpdateInfo())
                {
-                       m_logFile->append(QString("Val: '%1' ==> '%2").arg(value.cap(1), value.cap(2)));
-                       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();
-                       }
+                       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)));
+                       ui->infoLabel->show();
                }
+
+               m_success = true;
        }
-       
-       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;
-       
-       if(!complete)
-       {
-               m_logFile->append("WARNING: Version info is incomplete!");
-       }
 
-       return complete;
+       ui->retryButton->setVisible(!bSuccess);
+       ui->logButton->setVisible(!bSuccess);
+       ui->retryButton->setEnabled(!bSuccess);
+       ui->logButton->setEnabled(!bSuccess);
+
+       QApplication::restoreOverrideCursor();
 }
 
 void UpdateDialog::linkActivated(const QString &link)
@@ -534,53 +376,114 @@ void UpdateDialog::linkActivated(const QString &link)
 
 void UpdateDialog::applyUpdate(void)
 {
-       installButton->setEnabled(false);
-       closeButton->setEnabled(false);
-       retryButton->setEnabled(false);
+       ui->installButton->setEnabled(false);
+       ui->closeButton->setEnabled(false);
+       ui->retryButton->setEnabled(false);
 
-       if(m_updateInfo)
+       if(const MUtils::UpdateCheckerInfo *updateInfo = m_thread->getUpdateInfo())
        {
-               statusLabel->setText("Update is being downloaded, please be patient...");
-               QApplication::processEvents();
+               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);
+               QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
                
                QProcess process;
                QStringList args;
                QEventLoop loop;
 
+               MUtils::init_process(process, QFileInfo(m_binaryUpdater).absolutePath(), false);
+
                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("/Location=%1").arg(updateInfo->getDownloadAddress());
+               args << QString("/Filename=%1").arg(updateInfo->getDownloadFilename());
+               args << QString("/TicketID=%1").arg(updateInfo->getDownloadFilecode());
                args << QString("/ToFolder=%1").arg(QDir::toNativeSeparators(QDir(QApplication::applicationDirPath()).canonicalPath())); 
                args << QString("/ToExFile=%1.exe").arg(QFileInfo(QFileInfo(QApplication::applicationFilePath()).canonicalFilePath()).completeBaseName());
-               args << QString("/AppTitle=LameXP (Build #%1)").arg(QString::number(m_updateInfo->m_buildNo));
+               args << QString("/AppTitle=LameXP (Build #%1)").arg(QString::number(updateInfo->getBuildNo()));
 
                QApplication::setOverrideCursor(Qt::WaitCursor);
+               UPDATE_TASKBAR(WinSevenTaskbar::WinSevenTaskbarIndeterminateState, ":/icons/transmit_blue.png");
+
                process.start(m_binaryUpdater, args);
-               loop.exec();
+               bool updateStarted = process.waitForStarted();
+               if(updateStarted)
+               {
+                       m_updaterProcess = MUtils::OS::process_id(&process);
+                       loop.exec(QEventLoop::ExcludeUserInputEvents);
+               }
+
+               m_updaterProcess = NULL;
                QApplication::restoreOverrideCursor();
-               
-               if(process.exitCode() == 0)
+
+               ui->hintLabel->show();
+               ui->hintIcon->show();
+               ui->progressBar->setRange(oldMin, oldMax);
+               ui->progressBar->setValue(oldMax);
+               ui->frameAnimation->hide();
+
+               if(updateStarted && (process.exitCode() == 0))
                {
-                       statusLabel->setText("Update ready to install. Applicaion will quit...");
-                       QApplication::quit();
+                       ui->statusLabel->setText(tr("Update ready to install. Applicaion will quit..."));
+                       m_updateReadyToInstall = true;
+                       WinSevenTaskbar::setTaskbarState(this->parentWidget(), WinSevenTaskbar::WinSevenTaskbarNoState);
+                       WinSevenTaskbar::setOverlayIcon(this->parentWidget(), NULL);
                        accept();
                }
                else
                {
-                       statusLabel->setText("Update failed. Please try again or download manually!");
+                       ui->statusLabel->setText(tr("Update failed. Please try again or download manually!"));
+                       WinSevenTaskbar::setTaskbarState(this->parentWidget(), WinSevenTaskbar::WinSevenTaskbarErrorState);
+                       WinSevenTaskbar::setOverlayIcon(this->parentWidget(), &QIcon(":/icons/exclamation.png"));
+                       WinSevenTaskbar::setTaskbarProgress(this->parentWidget(), 100, 100);
                }
        }
 
-       installButton->setEnabled(true);
-       closeButton->setEnabled(true);
+       ui->installButton->setEnabled(true);
+       ui->closeButton->setEnabled(true);
 }
 
 void UpdateDialog::logButtonClicked(void)
 {
        LogViewDialog *logView = new LogViewDialog(this);
        logView->exec(*m_logFile);
-       LAMEXP_DELETE(logView);
+       MUTILS_DELETE(logView);
+}
+
+void UpdateDialog::progressBarValueChanged(int value)
+{
+       WinSevenTaskbar::setTaskbarProgress(this->parentWidget(), value, ui->progressBar->maximum());
+}
+
+void UpdateDialog::testKnownHosts(void)
+{
+       ui->statusLabel->setText("Testing all known hosts, this may take a few minutes...");
+       
+       if(MUtils::UpdateChecker *testThread = new MUtils::UpdateChecker(m_binaryWGet, m_binaryGnuPG, m_binaryKeys, QLatin1String("LameXP"), lamexp_version_build(), m_betaUpdates, true))
+       {
+               QEventLoop loop;
+               m_logFile->clear();
+
+               connect(testThread, SIGNAL(messageLogged(QString)), this, SLOT(threadMessageLogged(QString)));
+               connect(testThread, SIGNAL(finished()), &loop, SLOT(quit()));
+               connect(testThread, SIGNAL(terminated()), &loop, SLOT(quit()));
+
+               testThread->start();
+               while(testThread->isRunning())
+               {
+                       QTimer::singleShot(5000, &loop, SLOT(quit()));
+                       loop.exec(QEventLoop::ExcludeUserInputEvents);
+               }
+
+               MUTILS_DELETE(testThread);
+               logButtonClicked();
+       }
+
+       ui->statusLabel->setText("Test completed.");
+       lamexp_beep(lamexp_beep_info);
 }