1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2013 LoRd_MuldeR <MuldeR2@GMX.de>
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License along
16 // with this program; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 // http://www.gnu.org/licenses/gpl-2.0.txt
20 ///////////////////////////////////////////////////////////////////////////////
22 #include "Dialog_Update.h"
25 #include "..\tmp\UIC_UpdateDialog.h"
30 #include "Dialog_LogView.h"
31 #include "Model_Settings.h"
32 #include "WinSevenTaskbar.h"
36 #include <QFileDialog>
41 #include <QDesktopServices>
43 #include <QCloseEvent>
45 #include <QtConcurrentRun>
51 ///////////////////////////////////////////////////////////////////////////////
53 static const char *header_id = "!Update";
54 static const char *section_id = "LameXP";
56 static const char *mirror_url_postfix[] =
63 static const char *update_mirrors_prim[] =
65 "http://muldersoft.com/",
66 "http://mulder.brhack.net/",
67 "http://mulder.bplaced.net/",
68 "http://mulder.cwsurf.de/",
69 "http://mulder.6te.net/",
70 "http://mulder.webuda.com/",
71 "http://lamexp.sourceforge.net/",
72 "http://lordmulder.github.com/LameXP/",
73 "http://lord_mulder.bitbucket.org/",
74 "http://www.tricksoft.de/",
78 static const char *update_mirrors_back[] =
80 "http://mplayer.savedonthe.net/",
81 "http://www.rarewares.org/",
82 "http://lord_mulder.doom9.net/",
86 static const char *known_hosts[] = //Taken form: http://www.alexa.com/topsites !!!
88 "http://www.163.com/",
89 "http://www.360buy.com/",
90 "http://www.ac3filter.net/",
91 "http://www.amazon.com/",
92 "http://www.aol.com/",
93 "http://www.apache.org/",
94 "http://www.apple.com/",
95 "http://www.adobe.com/",
96 "http://www.avidemux.org/",
97 "http://www.babylon.com/",
98 "http://www.baidu.com/",
99 "http://www.bbc.co.uk/",
100 "http://www.bing.com/",
101 "http://www.cnet.com/",
103 "http://codecs.com/",
104 "http://qt.digia.com/",
105 "http://www.ebay.com/",
106 "http://www.equation.com/",
108 "http://www.ffmpeg.org/",
109 "http://www.flickr.com/",
110 "http://www.gitorious.org/",
111 "http://git-scm.com/",
112 "http://www.gnome.org/",
113 "http://www.gnu.org/",
115 "http://code.google.com/",
116 "http://www.heise.de/",
117 "http://www.huffingtonpost.co.uk/",
118 "http://www.iana.org/",
119 "http://www.imdb.com/",
120 "http://www.imgburn.com/",
122 "http://mirrors.kernel.org/",
123 "http://www.libav.org/",
124 "http://www.linkedin.com/",
125 "http://www.livedoor.com/",
126 "http://www.livejournal.com/",
128 "http://www.mediafire.com/",
129 "http://www.mozilla.org/en-US/",
130 "http://mplayerhq.hu/",
131 "http://www.msn.com/?st=1",
132 "http://oss.netfarm.it/",
133 "http://www.nytimes.com/",
134 "http://www.opera.com/",
135 "http://www.portablefreeware.com/",
136 "http://qt-project.org/",
137 "http://www.quakelive.com/",
138 "http://www.seamonkey-project.org/",
139 "http://www.sina.com.cn/",
140 "http://www.sohu.com/",
141 "http://www.soso.com/",
142 "http://sourceforge.net/",
143 "http://www.spiegel.de/",
144 "http://tdm-gcc.tdragon.net/",
145 "http://www.tdrsmusic.com/",
146 "http://www.ubuntu.com/",
147 "http://blog.twitter.com/",
148 "http://www.uol.com.br/",
149 "http://www.videohelp.com/",
150 "http://www.videolan.org/",
151 "http://www.weibo.com/",
152 "http://www.wikipedia.org/",
153 "http://www.winamp.com/",
154 "http://wordpress.com/",
155 "http://us.yahoo.com/",
156 "http://www.yandex.ru/",
157 "http://www.youtube.com/",
158 "http://www.zedo.com/",
159 "http://ffmpeg.zeranoe.com/",
163 static const int MIN_CONNSCORE = 8;
164 static const int VERSION_INFO_EXPIRES_MONTHS = 6;
165 static char *USER_AGENT_STR = "Mozilla/5.0 (X11; Linux i686; rv:7.0.1) Gecko/20111106 IceCat/7.0.1";
167 static BOOL getInternetConnectedState(void)
169 DWORD lpdwFlags = NULL;
170 BOOL result = InternetGetConnectedState(&lpdwFlags, NULL);
174 static BOOL CALLBACK focusUpdaterWindow(HWND hwnd, LPARAM lParam)
176 DWORD processId = *reinterpret_cast<WORD*>(lParam);
177 DWORD windowProcessId = NULL;
178 GetWindowThreadProcessId(hwnd, &windowProcessId);
179 if(windowProcessId == processId)
181 SwitchToThisWindow(hwnd, TRUE);
182 SetForegroundWindow(hwnd);
189 ///////////////////////////////////////////////////////////////////////////////
194 UpdateInfo(void) { resetInfo(); }
199 m_buildDate.setDate(1900, 1, 1);
200 m_downloadSite.clear();
201 m_downloadAddress.clear();
202 m_downloadFilename.clear();
203 m_downloadFilecode.clear();
206 unsigned int m_buildNo;
208 QString m_downloadSite;
209 QString m_downloadAddress;
210 QString m_downloadFilename;
211 QString m_downloadFilecode;
214 ///////////////////////////////////////////////////////////////////////////////
216 UpdateDialog::UpdateDialog(SettingsModel *settings, QWidget *parent)
219 ui(new Ui::UpdateDialog),
220 m_binaryWGet(lamexp_lookup_tool("wget.exe")),
221 m_binaryGnuPG(lamexp_lookup_tool("gpgv.exe")),
222 m_binaryUpdater(lamexp_lookup_tool("wupdate.exe")),
223 m_binaryKeys(lamexp_lookup_tool("gpgv.gpg")),
225 m_settings(settings),
226 m_logFile(new QStringList()),
227 m_betaUpdates(settings ? (settings->autoUpdateCheckBeta() || lamexp_version_demo()) : lamexp_version_demo()),
230 m_updateReadyToInstall(false),
231 m_updaterProcess(NULL)
233 if(m_binaryWGet.isEmpty() || m_binaryGnuPG.isEmpty() || m_binaryUpdater.isEmpty() || m_binaryKeys.isEmpty())
235 throw "Tools not initialized correctly!";
238 //Init the dialog, from the .ui file
240 setWindowFlags(windowFlags() ^ Qt::WindowContextHelpButtonHint);
243 HMENU hMenu = GetSystemMenu((HWND) winId(), FALSE);
244 EnableMenuItem(hMenu, SC_CLOSE, MF_BYCOMMAND | MF_GRAYED);
247 m_animator = new QMovie(":/images/Loading3.gif");
248 ui->labelAnimationCenter->setMovie(m_animator);
251 //Indicate beta updates
254 setWindowTitle(windowTitle().append(" [Beta]"));
258 connect(ui->retryButton, SIGNAL(clicked()), this, SLOT(checkForUpdates()));
259 connect(ui->installButton, SIGNAL(clicked()), this, SLOT(applyUpdate()));
260 connect(ui->infoLabel, SIGNAL(linkActivated(QString)), this, SLOT(linkActivated(QString)));
261 connect(ui->logButton, SIGNAL(clicked()), this, SLOT(logButtonClicked()));
263 //Enable progress bar
264 connect(ui->progressBar, SIGNAL(valueChanged(int)), this, SLOT(progressBarValueChanged(int)));
267 UpdateDialog::~UpdateDialog(void)
269 if(m_animator) m_animator->stop();
271 LAMEXP_DELETE(m_updateInfo);
272 LAMEXP_DELETE(m_logFile);
273 LAMEXP_DELETE(m_animator);
275 WinSevenTaskbar::setTaskbarState(this->parentWidget(), WinSevenTaskbar::WinSevenTaskbarNoState);
276 WinSevenTaskbar::setOverlayIcon(this->parentWidget(), NULL);
281 void UpdateDialog::showEvent(QShowEvent *event)
283 QDialog::showEvent(event);
287 ui->labelVersionInstalled->setText(QString("%1 %2 (%3)").arg(tr("Build"), QString::number(lamexp_version_build()), lamexp_version_date().toString(Qt::ISODate)));
288 ui->labelVersionLatest->setText(QString("(%1)").arg(tr("Unknown")));
290 ui->installButton->setEnabled(false);
291 ui->closeButton->setEnabled(false);
292 ui->retryButton->setEnabled(false);
293 ui->logButton->setEnabled(false);
294 ui->retryButton->hide();
295 ui->logButton->hide();
296 ui->infoLabel->hide();
297 ui->hintLabel->hide();
298 ui->hintIcon->hide();
299 ui->frameAnimation->hide();
301 int counter = MIN_CONNSCORE + 2;
302 for(int i = 0; update_mirrors_prim[i]; i++) counter++;
303 for(int i = 0; update_mirrors_back[i]; i++) counter++;
305 ui->progressBar->setMaximum(counter);
306 ui->progressBar->setValue(0);
308 m_updaterProcess = NULL;
310 QTimer::singleShot(0, this, SLOT(updateInit()));
315 void UpdateDialog::closeEvent(QCloseEvent *event)
317 if(!ui->closeButton->isEnabled())
323 WinSevenTaskbar::setTaskbarState(this->parentWidget(), WinSevenTaskbar::WinSevenTaskbarNoState);
324 WinSevenTaskbar::setOverlayIcon(this->parentWidget(), NULL);
328 void UpdateDialog::keyPressEvent(QKeyEvent *e)
330 if(e->key() == Qt::Key_F11)
332 if(ui->closeButton->isEnabled()) logButtonClicked();
334 else if((e->key() == Qt::Key_F12) && e->modifiers().testFlag(Qt::ControlModifier))
336 if(ui->closeButton->isEnabled())
344 QDialog::keyPressEvent(e);
348 bool UpdateDialog::event(QEvent *e)
350 if((e->type() == QEvent::ActivationChange) && (m_updaterProcess != NULL))
352 EnumWindows(focusUpdaterWindow, reinterpret_cast<LPARAM>(&m_updaterProcess));
354 return QDialog::event(e);
357 bool UpdateDialog::winEvent(MSG *message, long *result)
359 return WinSevenTaskbar::handleWinEvent(message, result);
362 void UpdateDialog::updateInit(void)
364 setMinimumSize(size());
365 setMaximumHeight(height());
366 QApplication::processEvents();
370 void UpdateDialog::checkForUpdates(void)
372 bool success = false;
373 int connectionScore = 0;
375 // ----- Initialization ----- //
377 m_updateInfo = new UpdateInfo;
379 ui->progressBar->setValue(0);
380 WinSevenTaskbar::setTaskbarState(this->parentWidget(), WinSevenTaskbar::WinSevenTaskbarNormalState);
381 WinSevenTaskbar::setOverlayIcon(this->parentWidget(), &QIcon(":/icons/transmit_blue.png"));
382 ui->installButton->setEnabled(false);
383 ui->closeButton->setEnabled(false);
384 ui->retryButton->setEnabled(false);
385 ui->logButton->setEnabled(false);
386 if(ui->infoLabel->isVisible()) ui->infoLabel->hide();
387 if(ui->hintLabel->isVisible()) ui->hintLabel->hide();
388 if(ui->hintIcon->isVisible()) ui->hintIcon->hide();
389 ui->frameAnimation->show();
391 QApplication::processEvents();
392 QApplication::setOverrideCursor(Qt::WaitCursor);
394 // ----- Test Internet Connection ----- //
396 ui->statusLabel->setText(tr("Testing your internet connection, please wait..."));
399 m_logFile->append("Checking internet connection...");
401 QFuture<BOOL> connectedState = QtConcurrent::run(getInternetConnectedState);
402 while(!connectedState.isFinished())
404 QApplication::processEvents(QEventLoop::WaitForMoreEvents);
407 if(!connectedState.result())
409 m_logFile->append(QStringList() << "" << "Operating system reports that the computer is currently offline !!!");
410 if(!ui->retryButton->isVisible()) ui->retryButton->show();
411 if(!ui->logButton->isVisible()) ui->logButton->show();
412 ui->closeButton->setEnabled(true);
413 ui->retryButton->setEnabled(true);
414 ui->logButton->setEnabled(true);
415 if(ui->frameAnimation->isVisible()) ui->frameAnimation->hide();
416 ui->statusLabel->setText(tr("It appears that the computer currently is offline!"));
417 ui->progressBar->setValue(ui->progressBar->maximum());
418 ui->hintIcon->setPixmap(QIcon(":/icons/network_error.png").pixmap(16,16));
419 ui->hintLabel->setText(tr("Please make sure your computer is connected to the internet and try again."));
420 ui->hintIcon->show();
421 ui->hintLabel->show();
422 LAMEXP_DELETE(m_updateInfo);
423 if(m_settings->soundsEnabled()) PlaySound(MAKEINTRESOURCE(IDR_WAVE_ERROR), GetModuleHandle(NULL), SND_RESOURCE | SND_ASYNC);
424 QApplication::restoreOverrideCursor();
425 ui->progressBar->setValue(ui->progressBar->maximum());
426 WinSevenTaskbar::setTaskbarState(this->parentWidget(), WinSevenTaskbar::WinSevenTaskbarErrorState);
427 WinSevenTaskbar::setOverlayIcon(this->parentWidget(), &QIcon(":/icons/exclamation.png"));
431 ui->progressBar->setValue(1);
432 QApplication::processEvents();
434 // ----- Test Known Hosts Connectivity ----- //
436 QStringList hostList;
437 for(int i = 0; known_hosts[i]; i++)
439 hostList << QString::fromLatin1(known_hosts[i]);
443 while(!hostList.isEmpty())
445 QString currentHost = hostList.takeAt(lamexp_rand() % hostList.count());
446 if(connectionScore < MIN_CONNSCORE)
448 m_logFile->append(QStringList() << "" << "Testing host:" << currentHost << "");
449 QString outFile = QString("%1/%2.htm").arg(lamexp_temp_folder2(), lamexp_rand_str());
451 if(getFile(currentHost, outFile, 0, &httpOk))
454 ui->progressBar->setValue(qBound(1, connectionScore + 1, MIN_CONNSCORE + 1));
455 QApplication::processEvents();
461 ui->progressBar->setValue(qBound(1, connectionScore + 1, MIN_CONNSCORE + 1));
462 QApplication::processEvents();
465 QFile::remove(outFile);
469 if(connectionScore < MIN_CONNSCORE)
471 if(!ui->retryButton->isVisible()) ui->retryButton->show();
472 if(!ui->logButton->isVisible()) ui->logButton->show();
473 ui->closeButton->setEnabled(true);
474 ui->retryButton->setEnabled(true);
475 ui->logButton->setEnabled(true);
476 if(ui->frameAnimation->isVisible()) ui->frameAnimation->hide();
477 ui->statusLabel->setText(tr("Network connectivity test has failed!"));
478 ui->progressBar->setValue(ui->progressBar->maximum());
479 ui->hintIcon->setPixmap(QIcon(":/icons/network_error.png").pixmap(16,16));
480 ui->hintLabel->setText(tr("Please make sure your internet connection is working properly and try again."));
481 ui->hintIcon->show();
482 ui->hintLabel->show();
483 LAMEXP_DELETE(m_updateInfo);
484 if(m_settings->soundsEnabled()) PlaySound(MAKEINTRESOURCE(IDR_WAVE_ERROR), GetModuleHandle(NULL), SND_RESOURCE | SND_ASYNC);
485 QApplication::restoreOverrideCursor();
486 ui->progressBar->setValue(ui->progressBar->maximum());
487 WinSevenTaskbar::setTaskbarState(this->parentWidget(), WinSevenTaskbar::WinSevenTaskbarErrorState);
488 WinSevenTaskbar::setOverlayIcon(this->parentWidget(), &QIcon(":/icons/exclamation.png"));
492 // ----- Build Mirror List ----- //
494 ui->statusLabel->setText(tr("Checking for new updates online, please wait..."));
495 m_logFile->append(QStringList() << "" << "----" << "" << "Checking for updates online...");
497 QStringList mirrorList;
498 for(int index = 0; update_mirrors_prim[index]; index++)
500 mirrorList << QString::fromLatin1(update_mirrors_prim[index]);
504 if(const int len = mirrorList.count())
506 const int rounds = len * 1097;
507 for(int i = 0; i < rounds; i++)
509 mirrorList.swap(i % len, lamexp_rand() % len);
513 for(int index = 0; update_mirrors_back[index]; index++)
515 mirrorList << QString::fromLatin1(update_mirrors_back[index]);
518 // ----- Fetch Update Info From Server ----- //
520 while(!mirrorList.isEmpty())
522 QString currentMirror = mirrorList.takeFirst();
523 ui->progressBar->setValue(ui->progressBar->value() + 1);
526 if(tryUpdateMirror(m_updateInfo, currentMirror))
533 QApplication::processEvents();
538 QApplication::restoreOverrideCursor();
539 ui->progressBar->setValue(ui->progressBar->maximum());
543 if(!ui->retryButton->isVisible()) ui->retryButton->show();
544 if(!ui->logButton->isVisible()) ui->logButton->show();
545 ui->closeButton->setEnabled(true);
546 ui->retryButton->setEnabled(true);
547 ui->logButton->setEnabled(true);
548 if(ui->frameAnimation->isVisible()) ui->frameAnimation->hide();
549 ui->statusLabel->setText(tr("Failed to fetch update information from server!"));
550 ui->progressBar->setValue(ui->progressBar->maximum());
551 WinSevenTaskbar::setTaskbarState(this->parentWidget(), WinSevenTaskbar::WinSevenTaskbarErrorState);
552 WinSevenTaskbar::setOverlayIcon(this->parentWidget(), &QIcon(":/icons/exclamation.png"));
553 ui->hintIcon->setPixmap(QIcon(":/icons/server_error.png").pixmap(16,16));
554 ui->hintLabel->setText(tr("Sorry, the update server might be busy at this time. Plase try again later."));
555 ui->hintIcon->show();
556 ui->hintLabel->show();
557 LAMEXP_DELETE(m_updateInfo);
558 if(m_settings->soundsEnabled()) PlaySound(MAKEINTRESOURCE(IDR_WAVE_ERROR), GetModuleHandle(NULL), SND_RESOURCE | SND_ASYNC);
562 // ----- Download New Program Version ----- //
564 ui->labelVersionLatest->setText(QString("%1 %2 (%3)").arg(tr("Build"), QString::number(m_updateInfo->m_buildNo), m_updateInfo->m_buildDate.toString(Qt::ISODate)));
565 ui->infoLabel->show();
566 ui->infoLabel->setText(QString("%1<br><a href=\"%2\">%2</a>").arg(tr("More information available at:"), m_updateInfo->m_downloadSite));
567 QApplication::processEvents();
569 if(m_updateInfo->m_buildNo > lamexp_version_build())
571 ui->installButton->setEnabled(true);
572 ui->statusLabel->setText(tr("A new version of LameXP is available!"));
573 ui->hintIcon->setPixmap(QIcon(":/icons/shield_exclamation.png").pixmap(16,16));
574 ui->hintLabel->setText(tr("We highly recommend all users to install this update as soon as possible."));
575 if(ui->frameAnimation->isVisible()) ui->frameAnimation->hide();
576 ui->hintIcon->show();
577 ui->hintLabel->show();
578 WinSevenTaskbar::setOverlayIcon(this->parentWidget(), &QIcon(":/icons/shield_exclamation.png"));
579 MessageBeep(MB_ICONINFORMATION);
581 else if(m_updateInfo->m_buildNo == lamexp_version_build())
583 ui->statusLabel->setText(tr("No new updates available at this time."));
584 ui->hintIcon->setPixmap(QIcon(":/icons/shield_green.png").pixmap(16,16));
585 ui->hintLabel->setText(tr("Your version of LameXP is still up-to-date. Please check for updates regularly!"));
586 if(ui->frameAnimation->isVisible()) ui->frameAnimation->hide();
587 ui->hintIcon->show();
588 ui->hintLabel->show();
589 WinSevenTaskbar::setOverlayIcon(this->parentWidget(), &QIcon(":/icons/shield_green.png"));
590 MessageBeep(MB_ICONINFORMATION);
594 ui->statusLabel->setText(tr("Your version appears to be newer than the latest release."));
595 ui->hintIcon->setPixmap(QIcon(":/icons/shield_error.png").pixmap(16,16));
596 ui->hintLabel->setText(tr("This usually indicates your are currently using a pre-release version of LameXP."));
597 if(ui->frameAnimation->isVisible()) ui->frameAnimation->hide();
598 ui->hintIcon->show();
599 ui->hintLabel->show();
600 WinSevenTaskbar::setOverlayIcon(this->parentWidget(), &QIcon(":/icons/shield_error.png"));
601 MessageBeep(MB_ICONEXCLAMATION);
604 ui->closeButton->setEnabled(true);
605 if(ui->retryButton->isVisible()) ui->retryButton->hide();
606 if(ui->logButton->isVisible()) ui->logButton->hide();
607 if(ui->frameAnimation->isVisible()) ui->frameAnimation->hide();
612 bool UpdateDialog::tryUpdateMirror(UpdateInfo *updateInfo, const QString &url)
614 bool success = false;
615 m_logFile->append(QStringList() << "" << "Trying mirror:" << url);
617 QString randPart = lamexp_rand_str();
618 QString outFileVersionInfo = QString("%1/%2.ver").arg(lamexp_temp_folder2(), randPart);
619 QString outFileSignature = QString("%1/%2.sig").arg(lamexp_temp_folder2(), randPart);
621 m_logFile->append(QStringList() << "" << "Downloading update info:");
622 bool ok1 = getFile(QString("%1%2").arg(url, mirror_url_postfix[m_betaUpdates ? 1 : 0]), outFileVersionInfo);
624 m_logFile->append(QStringList() << "" << "Downloading signature:");
625 bool ok2 = getFile(QString("%1%2.sig").arg(url, mirror_url_postfix[m_betaUpdates ? 1 : 0]), outFileSignature);
629 m_logFile->append(QStringList() << "" << "Download okay, checking signature:");
630 if(checkSignature(outFileVersionInfo, outFileSignature))
632 m_logFile->append(QStringList() << "" << "Signature okay, parsing info:");
633 success = parseVersionInfo(outFileVersionInfo, updateInfo);
637 m_logFile->append(QStringList() << "" << "Bad signature, take care!");
642 m_logFile->append(QStringList() << "" << "Download has failed!");
645 QFile::remove(outFileVersionInfo);
646 QFile::remove(outFileSignature);
651 bool UpdateDialog::getFile(const QString &url, const QString &outFile, unsigned int maxRedir, bool *httpOk)
653 QFileInfo output(outFile);
654 output.setCaching(false);
655 if(httpOk) *httpOk = false;
659 QFile::remove(output.canonicalFilePath());
667 process.setProcessChannelMode(QProcess::MergedChannels);
668 process.setReadChannel(QProcess::StandardOutput);
669 process.setWorkingDirectory(output.absolutePath());
672 args << "--no-cache" << "--no-dns-cache" << QString().sprintf("--max-redirect=%u", maxRedir);
673 args << QString("--referer=%1://%2/").arg(QUrl(url).scheme(), QUrl(url).host()) << "-U" << USER_AGENT_STR;
674 args << "-O" << output.fileName() << url;
677 connect(&process, SIGNAL(error(QProcess::ProcessError)), &loop, SLOT(quit()));
678 connect(&process, SIGNAL(finished(int,QProcess::ExitStatus)), &loop, SLOT(quit()));
679 connect(&process, SIGNAL(readyRead()), &loop, SLOT(quit()));
682 timer.setSingleShot(true);
683 timer.setInterval(25000);
684 connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
686 const QRegExp httpResponseOK("200 OK$");
688 process.start(m_binaryWGet, args);
690 if(!process.waitForStarted())
697 while(process.state() == QProcess::Running)
700 bool bTimeOut = (!timer.isActive());
701 while(process.canReadLine())
703 QString line = QString::fromLatin1(process.readLine()).simplified();
704 if(line.contains(httpResponseOK))
706 line.append(" [OK]");
707 if(httpOk) *httpOk = true;
709 m_logFile->append(line);
713 qWarning("WGet process timed out <-- killing!");
715 process.waitForFinished();
716 m_logFile->append("!!! TIMEOUT !!!");
722 timer.disconnect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
724 m_logFile->append(QString().sprintf("Exited with code %d", process.exitCode()));
725 return (process.exitCode() == 0) && output.exists() && output.isFile();
728 bool UpdateDialog::checkSignature(const QString &file, const QString &signature)
730 if(QFileInfo(file).absolutePath().compare(QFileInfo(signature).absolutePath(), Qt::CaseInsensitive) != 0)
732 qWarning("CheckSignature: File and signature should be in same folder!");
735 if(QFileInfo(file).absolutePath().compare(QFileInfo(m_binaryKeys).absolutePath(), Qt::CaseInsensitive) != 0)
737 qWarning("CheckSignature: File and keyring should be in same folder!");
742 process.setProcessChannelMode(QProcess::MergedChannels);
743 process.setReadChannel(QProcess::StandardOutput);
744 process.setWorkingDirectory(QFileInfo(file).absolutePath());
747 connect(&process, SIGNAL(error(QProcess::ProcessError)), &loop, SLOT(quit()));
748 connect(&process, SIGNAL(finished(int,QProcess::ExitStatus)), &loop, SLOT(quit()));
749 connect(&process, SIGNAL(readyRead()), &loop, SLOT(quit()));
751 process.start(m_binaryGnuPG, QStringList() << "--homedir" << "." << "--keyring" << QFileInfo(m_binaryKeys).fileName() << QFileInfo(signature).fileName() << QFileInfo(file).fileName());
753 if(!process.waitForStarted())
758 while(process.state() == QProcess::Running)
761 while(process.canReadLine())
763 m_logFile->append(QString::fromLatin1(process.readLine()).simplified());
767 m_logFile->append(QString().sprintf("Exited with code %d", process.exitCode()));
768 return (process.exitCode() == 0);
771 bool UpdateDialog::parseVersionInfo(const QString &file, UpdateInfo *updateInfo)
773 QRegExp value("^(\\w+)=(.+)$");
774 QRegExp section("^\\[(.+)\\]$");
776 QDate updateInfoDate;
777 updateInfo->resetInfo();
780 if(!data.open(QIODevice::ReadOnly))
782 qWarning("Cannot open update info file for reading!");
786 bool inHeader = false;
787 bool inSection = false;
791 QString line = QString::fromLatin1(data.readLine()).trimmed();
792 if(section.indexIn(line) >= 0)
794 m_logFile->append(QString("Sec: [%1]").arg(section.cap(1)));
795 inSection = (section.cap(1).compare(section_id, Qt::CaseInsensitive) == 0);
796 inHeader = (section.cap(1).compare(header_id, Qt::CaseInsensitive) == 0);
799 if(inSection && (value.indexIn(line) >= 0))
801 m_logFile->append(QString("Val: '%1' ==> '%2").arg(value.cap(1), value.cap(2)));
802 if(value.cap(1).compare("BuildNo", Qt::CaseInsensitive) == 0)
805 unsigned int temp = value.cap(2).toUInt(&ok);
806 if(ok) updateInfo->m_buildNo = temp;
808 else if(value.cap(1).compare("BuildDate", Qt::CaseInsensitive) == 0)
810 QDate temp = QDate::fromString(value.cap(2).trimmed(), Qt::ISODate);
811 if(temp.isValid()) updateInfo->m_buildDate = temp;
813 else if(value.cap(1).compare("DownloadSite", Qt::CaseInsensitive) == 0)
815 updateInfo->m_downloadSite = value.cap(2).trimmed();
817 else if(value.cap(1).compare("DownloadAddress", Qt::CaseInsensitive) == 0)
819 updateInfo->m_downloadAddress = value.cap(2).trimmed();
821 else if(value.cap(1).compare("DownloadFilename", Qt::CaseInsensitive) == 0)
823 updateInfo->m_downloadFilename = value.cap(2).trimmed();
825 else if(value.cap(1).compare("DownloadFilecode", Qt::CaseInsensitive) == 0)
827 updateInfo->m_downloadFilecode = value.cap(2).trimmed();
830 if(inHeader && (value.indexIn(line) >= 0))
832 m_logFile->append(QString("Val: '%1' ==> '%2").arg(value.cap(1), value.cap(2)));
833 if(value.cap(1).compare("TimestampCreated", Qt::CaseInsensitive) == 0)
835 QDate temp = QDate::fromString(value.cap(2).trimmed(), Qt::ISODate);
836 if(temp.isValid()) updateInfoDate = temp;
841 if(!updateInfoDate.isValid())
843 updateInfo->resetInfo();
844 m_logFile->append("WARNING: Version info timestamp is missing!");
847 else if(updateInfoDate.addMonths(VERSION_INFO_EXPIRES_MONTHS) < lamexp_current_date_safe())
849 updateInfo->resetInfo();
850 m_logFile->append(QString::fromLatin1("WARNING: This version info has expired at %1!").arg(updateInfoDate.addMonths(VERSION_INFO_EXPIRES_MONTHS).toString(Qt::ISODate)));
853 else if(lamexp_current_date_safe() < updateInfoDate)
855 m_logFile->append("Version info is from the future, take care!");
856 qWarning("Version info is from the future, take care!");
859 bool complete = true;
861 if(!(updateInfo->m_buildNo > 0)) complete = false;
862 if(!(updateInfo->m_buildDate.year() >= 2010)) complete = false;
863 if(updateInfo->m_downloadSite.isEmpty()) complete = false;
864 if(updateInfo->m_downloadAddress.isEmpty()) complete = false;
865 if(updateInfo->m_downloadFilename.isEmpty()) complete = false;
866 if(updateInfo->m_downloadFilecode.isEmpty()) complete = false;
870 m_logFile->append("WARNING: Version info is incomplete!");
876 void UpdateDialog::linkActivated(const QString &link)
878 QDesktopServices::openUrl(QUrl(link));
881 void UpdateDialog::applyUpdate(void)
883 ui->installButton->setEnabled(false);
884 ui->closeButton->setEnabled(false);
885 ui->retryButton->setEnabled(false);
889 ui->statusLabel->setText(tr("Update is being downloaded, please be patient..."));
890 ui->frameAnimation->show();
891 if(ui->hintLabel->isVisible()) ui->hintLabel->hide();
892 if(ui->hintIcon->isVisible()) ui->hintIcon->hide();
893 int oldMax = ui->progressBar->maximum();
894 int oldMin = ui->progressBar->minimum();
895 ui->progressBar->setRange(0, 0);
896 QApplication::processEvents();
902 connect(&process, SIGNAL(error(QProcess::ProcessError)), &loop, SLOT(quit()));
903 connect(&process, SIGNAL(finished(int,QProcess::ExitStatus)), &loop, SLOT(quit()));
905 args << QString("/Location=%1").arg(m_updateInfo->m_downloadAddress);
906 args << QString("/Filename=%1").arg(m_updateInfo->m_downloadFilename);
907 args << QString("/TicketID=%1").arg(m_updateInfo->m_downloadFilecode);
908 args << QString("/ToFolder=%1").arg(QDir::toNativeSeparators(QDir(QApplication::applicationDirPath()).canonicalPath()));
909 args << QString("/ToExFile=%1.exe").arg(QFileInfo(QFileInfo(QApplication::applicationFilePath()).canonicalFilePath()).completeBaseName());
910 args << QString("/AppTitle=LameXP (Build #%1)").arg(QString::number(m_updateInfo->m_buildNo));
912 QApplication::setOverrideCursor(Qt::WaitCursor);
913 WinSevenTaskbar::setTaskbarState(this->parentWidget(), WinSevenTaskbar::WinSevenTaskbarIndeterminateState);
914 WinSevenTaskbar::setOverlayIcon(this->parentWidget(), &QIcon(":/icons/transmit_blue.png"));
916 process.start(m_binaryUpdater, args);
917 bool updateStarted = process.waitForStarted();
920 m_updaterProcess = process.pid()->dwProcessId;
923 m_updaterProcess = NULL;
924 QApplication::restoreOverrideCursor();
926 ui->hintLabel->show();
927 ui->hintIcon->show();
928 ui->progressBar->setRange(oldMin, oldMax);
929 ui->progressBar->setValue(oldMax);
930 ui->frameAnimation->hide();
932 if(updateStarted && (process.exitCode() == 0))
934 ui->statusLabel->setText(tr("Update ready to install. Applicaion will quit..."));
935 m_updateReadyToInstall = true;
936 WinSevenTaskbar::setTaskbarState(this->parentWidget(), WinSevenTaskbar::WinSevenTaskbarNoState);
937 WinSevenTaskbar::setOverlayIcon(this->parentWidget(), NULL);
942 ui->statusLabel->setText(tr("Update failed. Please try again or download manually!"));
943 WinSevenTaskbar::setTaskbarState(this->parentWidget(), WinSevenTaskbar::WinSevenTaskbarErrorState);
944 WinSevenTaskbar::setOverlayIcon(this->parentWidget(), &QIcon(":/icons/exclamation.png"));
945 WinSevenTaskbar::setTaskbarProgress(this->parentWidget(), 100, 100);
949 ui->installButton->setEnabled(true);
950 ui->closeButton->setEnabled(true);
953 void UpdateDialog::logButtonClicked(void)
955 LogViewDialog *logView = new LogViewDialog(this);
956 logView->exec(*m_logFile);
957 LAMEXP_DELETE(logView);
960 void UpdateDialog::progressBarValueChanged(int value)
962 WinSevenTaskbar::setTaskbarProgress(this->parentWidget(), value, ui->progressBar->maximum());
965 void UpdateDialog::testKnownWebSites(void)
967 int connectionScore = 0;
969 // ----- Initialization ----- //
971 ui->progressBar->setValue(0);
972 WinSevenTaskbar::setTaskbarState(this->parentWidget(), WinSevenTaskbar::WinSevenTaskbarNormalState);
973 WinSevenTaskbar::setOverlayIcon(this->parentWidget(), &QIcon(":/icons/transmit_blue.png"));
974 ui->installButton->setEnabled(false);
975 ui->closeButton->setEnabled(false);
976 ui->retryButton->setEnabled(false);
977 ui->logButton->setEnabled(false);
978 if(ui->infoLabel->isVisible()) ui->infoLabel->hide();
979 if(ui->hintLabel->isVisible()) ui->hintLabel->hide();
980 if(ui->hintIcon->isVisible()) ui->hintIcon->hide();
981 ui->frameAnimation->show();
983 QApplication::processEvents();
984 QApplication::setOverrideCursor(Qt::WaitCursor);
986 // ----- Test Internet Connection ----- //
988 ui->statusLabel->setText("Testing all known hosts, this may take a few minutes...");
991 m_logFile->append("Checking internet connection...");
993 QFuture<BOOL> connectedState = QtConcurrent::run(getInternetConnectedState);
994 while(!connectedState.isFinished())
996 QApplication::processEvents(QEventLoop::WaitForMoreEvents);
999 if(!connectedState.result())
1001 m_logFile->append(QStringList() << "" << "Operating system reports that the computer is currently offline !!!");
1002 if(!ui->retryButton->isVisible()) ui->retryButton->show();
1003 if(!ui->logButton->isVisible()) ui->logButton->show();
1004 ui->closeButton->setEnabled(true);
1005 ui->retryButton->setEnabled(true);
1006 ui->logButton->setEnabled(true);
1007 if(ui->frameAnimation->isVisible()) ui->frameAnimation->hide();
1008 ui->statusLabel->setText(tr("It appears that the computer currently is offline!"));
1009 ui->progressBar->setValue(ui->progressBar->maximum());
1010 ui->hintIcon->setPixmap(QIcon(":/icons/network_error.png").pixmap(16,16));
1011 ui->hintLabel->setText(tr("Please make sure your computer is connected to the internet and try again."));
1012 ui->hintIcon->show();
1013 ui->hintLabel->show();
1014 LAMEXP_DELETE(m_updateInfo);
1015 if(m_settings->soundsEnabled()) PlaySound(MAKEINTRESOURCE(IDR_WAVE_ERROR), GetModuleHandle(NULL), SND_RESOURCE | SND_ASYNC);
1016 QApplication::restoreOverrideCursor();
1017 ui->progressBar->setValue(ui->progressBar->maximum());
1018 WinSevenTaskbar::setTaskbarState(this->parentWidget(), WinSevenTaskbar::WinSevenTaskbarErrorState);
1019 WinSevenTaskbar::setOverlayIcon(this->parentWidget(), &QIcon(":/icons/exclamation.png"));
1023 // ----- Test Known Hosts Connectivity ----- //
1025 QStringList hostList;
1026 for(int i = 0; known_hosts[i]; i++)
1028 hostList << QString::fromLatin1(known_hosts[i]);
1031 qDebug("[Known Hosts]");
1033 int hostCount = hostList.count();
1034 while(!hostList.isEmpty())
1036 QString currentHost = hostList.takeFirst();
1037 ui->progressBar->setValue(qRound((static_cast<double>(ui->progressBar->maximum() - 1) / static_cast<double>(hostCount)) * static_cast<double>(connectionScore)) + 1);
1038 qDebug("Testing: %s", currentHost.toLatin1().constData());
1039 m_logFile->append(QStringList() << "" << "Testing host:" << currentHost << "");
1040 QString outFile = QString("%1/%2.htm").arg(lamexp_temp_folder2(), lamexp_rand_str());
1041 bool httpOk = false;
1042 if(getFile(currentHost, outFile, 0, &httpOk))
1050 qWarning("\nConnectivity test was SLOW on the following site:\n%s\n", currentHost.toLatin1().constData());
1055 qWarning("\nConnectivity test FAILED on the following site:\n%s\n", currentHost.toLatin1().constData());
1058 QFile::remove(outFile);
1061 if(connectionScore < hostCount)
1063 if(!ui->retryButton->isVisible()) ui->retryButton->show();
1064 if(!ui->logButton->isVisible()) ui->logButton->show();
1065 ui->closeButton->setEnabled(true);
1066 ui->retryButton->setEnabled(true);
1067 ui->logButton->setEnabled(true);
1068 if(ui->frameAnimation->isVisible()) ui->frameAnimation->hide();
1069 ui->statusLabel->setText("At least one host could not be reached!");
1070 ui->progressBar->setValue(ui->progressBar->maximum());
1071 ui->hintIcon->setPixmap(QIcon(":/icons/network_error.png").pixmap(16,16));
1072 ui->hintLabel->setText("Please make sure your internet connection is working properly and try again.");
1073 ui->hintIcon->show();
1074 ui->hintLabel->show();
1075 LAMEXP_DELETE(m_updateInfo);
1076 if(m_settings->soundsEnabled()) PlaySound(MAKEINTRESOURCE(IDR_WAVE_ERROR), GetModuleHandle(NULL), SND_RESOURCE | SND_ASYNC);
1077 QApplication::restoreOverrideCursor();
1078 ui->progressBar->setValue(ui->progressBar->maximum());
1079 WinSevenTaskbar::setTaskbarState(this->parentWidget(), WinSevenTaskbar::WinSevenTaskbarErrorState);
1080 WinSevenTaskbar::setOverlayIcon(this->parentWidget(), &QIcon(":/icons/exclamation.png"));
1084 // ----- Done ----- //
1086 QApplication::restoreOverrideCursor();
1087 ui->progressBar->setValue(ui->progressBar->maximum());
1089 ui->statusLabel->setText("Test completed.");
1090 ui->hintIcon->setPixmap(QIcon(":/icons/shield_green.png").pixmap(16,16));
1091 ui->hintLabel->setText("Congratulations, the test has completed.");
1092 if(ui->frameAnimation->isVisible()) ui->frameAnimation->hide();
1093 ui->hintIcon->show();
1094 ui->hintLabel->show();
1095 WinSevenTaskbar::setOverlayIcon(this->parentWidget(), &QIcon(":/icons/shield_green.png"));
1096 MessageBeep(MB_ICONINFORMATION);
1098 ui->closeButton->setEnabled(true);
1099 if(ui->retryButton->isVisible()) ui->retryButton->hide();
1100 if(ui->logButton->isVisible()) ui->logButton->hide();
1101 if(ui->frameAnimation->isVisible()) ui->frameAnimation->hide();