2010-11-27 19:41:58 +01:00
///////////////////////////////////////////////////////////////////////////////
// LameXP - Audio Encoder Front-End
2013-02-08 23:50:51 +01:00
// Copyright (C) 2004-2013 LoRd_MuldeR <MuldeR2@GMX.de>
2010-11-27 19:41:58 +01:00
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (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"
2012-12-09 22:39:17 +01:00
//UIC includes
# include "..\tmp\UIC_UpdateDialog.h"
//LameXP includes
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"
2011-02-25 13:40:45 +01:00
# include "WinSevenTaskbar.h"
2010-11-28 22:18:07 +01:00
2012-12-09 22:39:17 +01:00
//Qt includes
2010-11-27 19:41:58 +01:00
# include <QClipboard>
# include <QFileDialog>
# include <QTimer>
2010-11-28 22:18:07 +01:00
# include <QProcess>
# include <QDate>
# include <QRegExp>
# include <QDesktopServices>
# include <QUrl>
# include <QCloseEvent>
2011-03-24 15:37:49 +01:00
# include <QMovie>
2011-07-10 21:46:43 +02:00
# include <QtConcurrentRun>
2013-10-19 16:00:13 +02:00
# include <QFutureWatcher>
2010-11-27 19:41:58 +01:00
2010-11-28 22:18:07 +01:00
///////////////////////////////////////////////////////////////////////////////
2011-03-25 15:18:13 +01:00
static const char * header_id = " !Update " ;
2010-11-28 22:18:07 +01:00
static const char * section_id = " LameXP " ;
2011-02-12 22:17:42 +01:00
static const char * mirror_url_postfix [ ] =
{
" update.ver " ,
" update_beta.ver " ,
NULL
} ;
2010-11-28 22:18:07 +01:00
2011-07-10 21:46:43 +02:00
static const char * update_mirrors_prim [ ] =
2010-11-28 22:18:07 +01:00
{
2013-10-07 00:10:05 +02:00
" http://muldersoft.com/ " ,
2011-07-10 21:46:43 +02:00
" http://mulder.bplaced.net/ " ,
2012-10-28 15:08:59 +01:00
" http://mulder.cwsurf.de/ " ,
" http://mulder.6te.net/ " ,
2012-10-31 22:54:35 +01:00
" http://mulder.webuda.com/ " ,
2013-05-02 23:01:00 +02:00
" http://mulder.byethost13.com/ " ,
2013-06-14 20:32:24 +02:00
" http://muldersoft.kilu.de/ " ,
" http://muldersoft.zxq.net/ " ,
2011-02-02 21:40:18 +01:00
" http://lamexp.sourceforge.net/ " ,
2013-10-07 00:10:05 +02:00
" http://lamexp.berlios.de/ " ,
2012-05-29 19:53:53 +02:00
" http://lordmulder.github.com/LameXP/ " ,
2012-10-09 01:58:36 +02:00
" http://lord_mulder.bitbucket.org/ " ,
2011-12-02 22:40:12 +01:00
" http://www.tricksoft.de/ " ,
2011-07-10 21:46:43 +02:00
NULL
} ;
static const char * update_mirrors_back [ ] =
{
2010-11-28 22:18:07 +01:00
" http://mplayer.savedonthe.net/ " ,
NULL
} ;
2012-10-28 15:08:59 +01:00
static const char * known_hosts [ ] = //Taken form: http://www.alexa.com/topsites !!!
2010-12-06 18:29:34 +01:00
{
2011-12-01 22:16:06 +01:00
" http://www.163.com/ " ,
2013-03-17 03:10:26 +01:00
" http://www.ac3filter.net/ " ,
2011-03-28 04:23:57 +02:00
" http://www.amazon.com/ " ,
" http://www.aol.com/ " ,
2011-05-09 22:22:15 +02:00
" http://www.apache.org/ " ,
2011-12-01 22:16:06 +01:00
" http://www.apple.com/ " ,
" http://www.adobe.com/ " ,
2011-05-09 22:22:15 +02:00
" http://www.avidemux.org/ " ,
2011-12-01 22:16:06 +01:00
" http://www.babylon.com/ " ,
" http://www.baidu.com/ " ,
2011-05-09 22:22:15 +02:00
" http://www.bbc.co.uk/ " ,
2013-10-19 16:00:13 +02:00
" http://www.berlios.de/ " ,
2011-05-09 22:22:15 +02:00
" http://www.bing.com/ " ,
2011-12-01 22:16:06 +01:00
" http://www.cnet.com/ " ,
" http://cnzz.com/ " ,
2013-03-17 03:10:26 +01:00
" http://codecs.com/ " ,
2013-10-19 16:00:13 +02:00
" http://www.codeplex.com/ " ,
2012-10-09 17:43:17 +02:00
" http://qt.digia.com/ " ,
2011-03-28 04:23:57 +02:00
" http://www.ebay.com/ " ,
2011-05-09 22:22:15 +02:00
" http://www.equation.com/ " ,
2011-12-01 22:16:06 +01:00
" http://fc2.com/ " ,
2011-05-09 22:22:15 +02:00
" http://www.ffmpeg.org/ " ,
2011-12-01 22:16:06 +01:00
" http://www.flickr.com/ " ,
2013-10-19 16:00:13 +02:00
" http://blog.gitorious.org/ " ,
2012-10-09 17:43:17 +02:00
" http://git-scm.com/ " ,
2011-05-09 22:22:15 +02:00
" http://www.gnome.org/ " ,
" http://www.gnu.org/ " ,
2011-12-01 22:16:06 +01:00
" http://go.com/ " ,
2011-05-09 22:22:15 +02:00
" http://code.google.com/ " ,
" http://www.heise.de/ " ,
2011-12-01 22:16:06 +01:00
" http://www.huffingtonpost.co.uk/ " ,
2011-05-09 22:22:15 +02:00
" http://www.iana.org/ " ,
2011-12-01 22:16:06 +01:00
" http://www.imdb.com/ " ,
2011-05-09 22:22:15 +02:00
" http://www.imgburn.com/ " ,
2011-12-01 22:16:06 +01:00
" http://imgur.com/ " ,
2013-10-19 16:00:13 +02:00
" http://en.jd.com/ " ,
2013-03-17 03:10:26 +01:00
" http://mirrors.kernel.org/ " ,
2011-05-09 22:22:15 +02:00
" http://www.libav.org/ " ,
2011-12-01 22:16:06 +01:00
" http://www.linkedin.com/ " ,
" http://www.livedoor.com/ " ,
" http://www.livejournal.com/ " ,
" http://mail.ru/ " ,
" http://www.mediafire.com/ " ,
2012-10-09 17:43:17 +02:00
" http://www.mozilla.org/en-US/ " ,
2011-05-09 22:22:15 +02:00
" http://mplayerhq.hu/ " ,
" http://www.msn.com/?st=1 " ,
" http://oss.netfarm.it/ " ,
2011-12-01 22:16:06 +01:00
" http://www.nytimes.com/ " ,
2011-05-09 22:22:15 +02:00
" http://www.opera.com/ " ,
2013-03-17 03:10:26 +01:00
" http://www.portablefreeware.com/ " ,
2012-10-09 17:43:17 +02:00
" http://qt-project.org/ " ,
2013-03-17 03:10:26 +01:00
" http://www.quakelive.com/ " ,
2011-05-09 22:22:15 +02:00
" http://www.seamonkey-project.org/ " ,
2011-12-01 22:16:06 +01:00
" http://www.sina.com.cn/ " ,
" http://www.sohu.com/ " ,
" http://www.soso.com/ " ,
2011-02-02 21:40:18 +01:00
" http://sourceforge.net/ " ,
2011-05-09 22:22:15 +02:00
" http://www.spiegel.de/ " ,
" http://tdm-gcc.tdragon.net/ " ,
" http://www.tdrsmusic.com/ " ,
2011-12-01 22:16:06 +01:00
" http://www.ubuntu.com/ " ,
2013-07-13 00:11:43 +02:00
" http://status.twitter.com/ " ,
2011-12-01 22:16:06 +01:00
" http://www.uol.com.br/ " ,
2011-05-09 22:22:15 +02:00
" http://www.videohelp.com/ " ,
" http://www.videolan.org/ " ,
2011-12-01 22:16:06 +01:00
" http://www.weibo.com/ " ,
2011-03-28 04:23:57 +02:00
" http://www.wikipedia.org/ " ,
2013-03-17 03:10:26 +01:00
" http://www.winamp.com/ " ,
2011-12-01 22:16:06 +01:00
" http://wordpress.com/ " ,
2011-12-03 16:10:33 +01:00
" http://us.yahoo.com/ " ,
2011-12-01 22:16:06 +01:00
" http://www.yandex.ru/ " ,
2011-03-24 15:37:49 +01:00
" http://www.youtube.com/ " ,
2011-12-01 22:16:06 +01:00
" http://www.zedo.com/ " ,
2012-10-09 17:43:17 +02:00
" http://ffmpeg.zeranoe.com/ " ,
2010-12-06 18:29:34 +01:00
NULL
} ;
2011-12-02 20:05:23 +01:00
static const int MIN_CONNSCORE = 8 ;
2011-03-25 15:18:13 +01:00
static const int VERSION_INFO_EXPIRES_MONTHS = 6 ;
2011-12-02 22:40:12 +01:00
static char * USER_AGENT_STR = " Mozilla/5.0 (X11; Linux i686; rv:7.0.1) Gecko/20111106 IceCat/7.0.1 " ;
2010-12-06 18:29:34 +01:00
2010-11-28 22:18:07 +01:00
///////////////////////////////////////////////////////////////////////////////
2013-10-19 16:00:13 +02:00
template < class T >
T DO_ASYNC ( T ( * functionPointer ) ( ) )
{
QFutureWatcher < T > watcher ; QEventLoop loop ;
QObject : : connect ( & watcher , SIGNAL ( finished ( ) ) , & loop , SLOT ( quit ( ) ) ) ;
watcher . setFuture ( QtConcurrent : : run ( functionPointer ) ) ;
loop . exec ( QEventLoop : : ExcludeUserInputEvents ) ;
return watcher . result ( ) ;
}
///////////////////////////////////////////////////////////////////////////////
2010-11-28 22:18:07 +01:00
class UpdateInfo
{
public :
2011-02-12 22:17:42 +01:00
UpdateInfo ( void ) { resetInfo ( ) ; }
void resetInfo ( void )
2010-11-28 22:18:07 +01:00
{
2011-02-12 22:17:42 +01:00
m_buildNo = 0 ;
m_buildDate . setDate ( 1900 , 1 , 1 ) ;
m_downloadSite . clear ( ) ;
m_downloadAddress . clear ( ) ;
m_downloadFilename . clear ( ) ;
m_downloadFilecode . clear ( ) ;
2010-11-28 22:18:07 +01:00
}
2011-02-12 22:17:42 +01:00
2010-11-28 22:18:07 +01:00
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 ) ,
2012-12-09 22:39:17 +01:00
ui ( new Ui : : UpdateDialog ) ,
2010-11-28 22:18:07 +01:00
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 ( ) ) ,
2011-05-03 14:28:06 +02:00
m_betaUpdates ( settings ? ( settings - > autoUpdateCheckBeta ( ) | | lamexp_version_demo ( ) ) : lamexp_version_demo ( ) ) ,
2011-02-18 00:53:36 +01:00
m_success ( false ) ,
2012-04-11 00:44:40 +02:00
m_firstShow ( true ) ,
2012-01-24 02:46:29 +01:00
m_updateReadyToInstall ( false ) ,
m_updaterProcess ( NULL )
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 ( ) )
{
2013-10-18 21:37:40 +02:00
THROW ( " Tools not initialized correctly! " ) ;
2010-11-28 22:18:07 +01:00
}
2010-11-27 19:41:58 +01:00
//Init the dialog, from the .ui file
2012-12-09 22:39:17 +01:00
ui - > setupUi ( this ) ;
2010-11-27 19:41:58 +01:00
setWindowFlags ( windowFlags ( ) ^ Qt : : WindowContextHelpButtonHint ) ;
//Disable "X" button
2013-10-07 00:01:15 +02:00
lamexp_enable_close_button ( this , false ) ;
2010-11-27 19:41:58 +01:00
2011-03-24 15:37:49 +01:00
//Init animation
m_animator = new QMovie ( " :/images/Loading3.gif " ) ;
2012-12-09 22:39:17 +01:00
ui - > labelAnimationCenter - > setMovie ( m_animator ) ;
2011-03-24 15:37:49 +01:00
m_animator - > start ( ) ;
2011-05-07 00:50:18 +02:00
//Indicate beta updates
if ( m_betaUpdates )
{
setWindowTitle ( windowTitle ( ) . append ( " [Beta] " ) ) ;
}
2010-11-28 22:18:07 +01:00
//Enable button
2012-12-09 22:39:17 +01:00
connect ( ui - > retryButton , SIGNAL ( clicked ( ) ) , this , SLOT ( checkForUpdates ( ) ) ) ;
connect ( ui - > installButton , SIGNAL ( clicked ( ) ) , this , SLOT ( applyUpdate ( ) ) ) ;
connect ( ui - > infoLabel , SIGNAL ( linkActivated ( QString ) ) , this , SLOT ( linkActivated ( QString ) ) ) ;
connect ( ui - > logButton , SIGNAL ( clicked ( ) ) , this , SLOT ( logButtonClicked ( ) ) ) ;
2011-02-25 13:40:45 +01:00
//Enable progress bar
2012-12-09 22:39:17 +01:00
connect ( ui - > progressBar , SIGNAL ( valueChanged ( int ) ) , this , SLOT ( progressBarValueChanged ( int ) ) ) ;
2010-11-27 19:41:58 +01:00
}
UpdateDialog : : ~ UpdateDialog ( void )
{
2011-03-24 15:37:49 +01:00
if ( m_animator ) m_animator - > stop ( ) ;
2010-11-28 22:18:07 +01:00
LAMEXP_DELETE ( m_updateInfo ) ;
2010-11-29 20:36:27 +01:00
LAMEXP_DELETE ( m_logFile ) ;
2011-03-24 15:37:49 +01:00
LAMEXP_DELETE ( m_animator ) ;
2011-02-25 13:40:45 +01:00
WinSevenTaskbar : : setTaskbarState ( this - > parentWidget ( ) , WinSevenTaskbar : : WinSevenTaskbarNoState ) ;
WinSevenTaskbar : : setOverlayIcon ( this - > parentWidget ( ) , NULL ) ;
2012-12-09 22:39:17 +01:00
LAMEXP_DELETE ( ui ) ;
2010-11-27 19:41:58 +01:00
}
void UpdateDialog : : showEvent ( QShowEvent * event )
{
2010-11-28 22:18:07 +01:00
QDialog : : showEvent ( event ) ;
2012-04-11 00:44:40 +02:00
if ( m_firstShow )
{
2012-12-09 22:39:17 +01:00
ui - > labelVersionInstalled - > setText ( QString ( " %1 %2 (%3) " ) . arg ( tr ( " Build " ) , QString : : number ( lamexp_version_build ( ) ) , lamexp_version_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 ( ) ;
2010-11-28 22:18:07 +01:00
2012-04-11 00:44:40 +02:00
int counter = MIN_CONNSCORE + 2 ;
for ( int i = 0 ; update_mirrors_prim [ i ] ; i + + ) counter + + ;
for ( int i = 0 ; update_mirrors_back [ i ] ; i + + ) counter + + ;
2010-11-28 22:18:07 +01:00
2012-12-09 22:39:17 +01:00
ui - > progressBar - > setMaximum ( counter ) ;
ui - > progressBar - > setValue ( 0 ) ;
2011-11-11 18:08:22 +01:00
2012-04-11 00:44:40 +02:00
m_updaterProcess = NULL ;
2012-01-24 02:46:29 +01:00
2012-04-11 00:44:40 +02:00
QTimer : : singleShot ( 0 , this , SLOT ( updateInit ( ) ) ) ;
m_firstShow = false ;
}
2010-11-28 22:18:07 +01:00
}
void UpdateDialog : : closeEvent ( QCloseEvent * event )
{
2012-12-09 22:39:17 +01:00
if ( ! ui - > closeButton - > isEnabled ( ) )
2011-02-25 13:40:45 +01:00
{
event - > ignore ( ) ;
}
else
{
WinSevenTaskbar : : setTaskbarState ( this - > parentWidget ( ) , WinSevenTaskbar : : WinSevenTaskbarNoState ) ;
WinSevenTaskbar : : setOverlayIcon ( this - > parentWidget ( ) , NULL ) ;
}
2010-11-27 19:41:58 +01:00
}
2010-12-08 20:52:18 +01:00
void UpdateDialog : : keyPressEvent ( QKeyEvent * e )
{
if ( e - > key ( ) = = Qt : : Key_F11 )
{
2012-12-09 22:39:17 +01:00
if ( ui - > closeButton - > isEnabled ( ) ) logButtonClicked ( ) ;
2010-12-08 20:52:18 +01:00
}
2011-12-01 22:16:06 +01:00
else if ( ( e - > key ( ) = = Qt : : Key_F12 ) & & e - > modifiers ( ) . testFlag ( Qt : : ControlModifier ) )
{
2012-12-09 22:39:17 +01:00
if ( ui - > closeButton - > isEnabled ( ) )
2011-12-01 22:16:06 +01:00
{
testKnownWebSites ( ) ;
logButtonClicked ( ) ;
}
}
2010-12-08 20:52:18 +01:00
else
{
QDialog : : keyPressEvent ( e ) ;
}
}
2012-01-24 02:46:29 +01:00
bool UpdateDialog : : event ( QEvent * e )
{
if ( ( e - > type ( ) = = QEvent : : ActivationChange ) & & ( m_updaterProcess ! = NULL ) )
{
2013-10-07 00:01:15 +02:00
lamexp_bring_process_to_front ( m_updaterProcess ) ;
2012-01-24 02:46:29 +01:00
}
return QDialog : : event ( e ) ;
}
2011-11-07 17:13:41 +01:00
bool UpdateDialog : : winEvent ( MSG * message , long * result )
{
return WinSevenTaskbar : : handleWinEvent ( message , result ) ;
}
2010-11-28 22:18:07 +01:00
void UpdateDialog : : updateInit ( void )
2010-11-27 19:41:58 +01:00
{
2010-11-28 22:18:07 +01:00
setMinimumSize ( size ( ) ) ;
setMaximumHeight ( height ( ) ) ;
2013-10-19 16:00:13 +02:00
QApplication : : processEvents ( QEventLoop : : ExcludeUserInputEvents ) ;
2010-11-28 22:18:07 +01:00
checkForUpdates ( ) ;
}
void UpdateDialog : : checkForUpdates ( void )
{
bool success = false ;
2010-12-06 18:29:34 +01:00
int connectionScore = 0 ;
2011-07-10 21:46:43 +02:00
// ----- Initialization ----- //
2010-11-28 22:18:07 +01:00
m_updateInfo = new UpdateInfo ;
2012-12-09 22:39:17 +01:00
ui - > progressBar - > setValue ( 0 ) ;
2011-02-25 13:40:45 +01:00
WinSevenTaskbar : : setTaskbarState ( this - > parentWidget ( ) , WinSevenTaskbar : : WinSevenTaskbarNormalState ) ;
WinSevenTaskbar : : setOverlayIcon ( this - > parentWidget ( ) , & QIcon ( " :/icons/transmit_blue.png " ) ) ;
2012-12-09 22:39:17 +01:00
ui - > installButton - > setEnabled ( false ) ;
ui - > closeButton - > setEnabled ( false ) ;
ui - > retryButton - > setEnabled ( false ) ;
ui - > logButton - > setEnabled ( false ) ;
if ( ui - > infoLabel - > isVisible ( ) ) ui - > infoLabel - > hide ( ) ;
if ( ui - > hintLabel - > isVisible ( ) ) ui - > hintLabel - > hide ( ) ;
if ( ui - > hintIcon - > isVisible ( ) ) ui - > hintIcon - > hide ( ) ;
ui - > frameAnimation - > show ( ) ;
2010-11-28 22:18:07 +01:00
2013-10-19 16:00:13 +02:00
QApplication : : processEvents ( QEventLoop : : ExcludeUserInputEvents ) ;
2010-11-28 22:18:07 +01:00
QApplication : : setOverrideCursor ( Qt : : WaitCursor ) ;
2011-07-10 21:46:43 +02:00
// ----- Test Internet Connection ----- //
2012-12-09 22:39:17 +01:00
ui - > statusLabel - > setText ( tr ( " Testing your internet connection, please wait... " ) ) ;
2010-12-06 18:29:34 +01:00
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... " ) ;
2011-07-10 21:46:43 +02:00
2013-10-19 16:00:13 +02:00
const int networkStatus = DO_ASYNC ( lamexp_network_status ) ;
if ( networkStatus = = lamexp_network_non )
2011-05-09 22:22:15 +02:00
{
m_logFile - > append ( QStringList ( ) < < " " < < " Operating system reports that the computer is currently offline !!! " ) ;
2012-12-09 22:39:17 +01:00
if ( ! ui - > retryButton - > isVisible ( ) ) ui - > retryButton - > show ( ) ;
if ( ! ui - > logButton - > isVisible ( ) ) ui - > logButton - > show ( ) ;
ui - > closeButton - > setEnabled ( true ) ;
ui - > retryButton - > setEnabled ( true ) ;
ui - > logButton - > setEnabled ( true ) ;
if ( ui - > frameAnimation - > isVisible ( ) ) ui - > frameAnimation - > hide ( ) ;
ui - > statusLabel - > setText ( tr ( " It appears that the computer currently is offline! " ) ) ;
ui - > progressBar - > setValue ( ui - > progressBar - > maximum ( ) ) ;
ui - > hintIcon - > setPixmap ( QIcon ( " :/icons/network_error.png " ) . pixmap ( 16 , 16 ) ) ;
ui - > hintLabel - > setText ( tr ( " Please make sure your computer is connected to the internet and try again. " ) ) ;
ui - > hintIcon - > show ( ) ;
ui - > hintLabel - > show ( ) ;
2011-05-09 22:22:15 +02:00
LAMEXP_DELETE ( m_updateInfo ) ;
2013-10-07 00:01:15 +02:00
if ( m_settings - > soundsEnabled ( ) ) lamexp_play_sound ( IDR_WAVE_ERROR , true ) ;
2011-05-09 22:22:15 +02:00
QApplication : : restoreOverrideCursor ( ) ;
2012-12-09 22:39:17 +01:00
ui - > progressBar - > setValue ( ui - > progressBar - > maximum ( ) ) ;
2011-05-09 22:22:15 +02:00
WinSevenTaskbar : : setTaskbarState ( this - > parentWidget ( ) , WinSevenTaskbar : : WinSevenTaskbarErrorState ) ;
WinSevenTaskbar : : setOverlayIcon ( this - > parentWidget ( ) , & QIcon ( " :/icons/exclamation.png " ) ) ;
return ;
}
2012-12-09 22:39:17 +01:00
ui - > progressBar - > setValue ( 1 ) ;
2013-10-19 16:00:13 +02:00
QApplication : : processEvents ( QEventLoop : : ExcludeUserInputEvents ) ;
2011-12-02 22:40:12 +01:00
2011-07-10 21:46:43 +02:00
// ----- Test Known Hosts Connectivity ----- //
2011-03-24 15:37:49 +01:00
QStringList hostList ;
2010-12-06 18:29:34 +01:00
for ( int i = 0 ; known_hosts [ i ] ; i + + )
2011-03-24 15:37:49 +01:00
{
hostList < < QString : : fromLatin1 ( known_hosts [ i ] ) ;
}
2012-10-13 12:36:41 +02:00
lamexp_seed_rand ( ) ;
2011-03-24 15:37:49 +01:00
while ( ! hostList . isEmpty ( ) )
2010-12-06 18:29:34 +01:00
{
2012-10-13 12:36:41 +02:00
QString currentHost = hostList . takeAt ( lamexp_rand ( ) % hostList . count ( ) ) ;
2010-12-06 18:29:34 +01:00
if ( connectionScore < MIN_CONNSCORE )
{
2011-03-24 15:37:49 +01:00
m_logFile - > append ( QStringList ( ) < < " " < < " Testing host: " < < currentHost < < " " ) ;
2011-02-25 22:03:39 +01:00
QString outFile = QString ( " %1/%2.htm " ) . arg ( lamexp_temp_folder2 ( ) , lamexp_rand_str ( ) ) ;
2011-12-02 20:05:23 +01:00
bool httpOk = false ;
if ( getFile ( currentHost , outFile , 0 , & httpOk ) )
{
connectionScore + + ;
2012-12-09 22:39:17 +01:00
ui - > progressBar - > setValue ( qBound ( 1 , connectionScore + 1 , MIN_CONNSCORE + 1 ) ) ;
2013-10-19 16:00:13 +02:00
QApplication : : processEvents ( QEventLoop : : ExcludeUserInputEvents ) ;
2013-10-07 00:01:15 +02:00
lamexp_sleep ( 64 ) ;
2011-12-02 20:05:23 +01:00
}
if ( httpOk )
2010-12-06 18:29:34 +01:00
{
connectionScore + + ;
2012-12-09 22:39:17 +01:00
ui - > progressBar - > setValue ( qBound ( 1 , connectionScore + 1 , MIN_CONNSCORE + 1 ) ) ;
2013-10-19 16:00:13 +02:00
QApplication : : processEvents ( QEventLoop : : ExcludeUserInputEvents ) ;
2013-10-07 00:01:15 +02:00
lamexp_sleep ( 64 ) ;
2010-12-06 18:29:34 +01:00
}
QFile : : remove ( outFile ) ;
}
}
if ( connectionScore < MIN_CONNSCORE )
{
2012-12-09 22:39:17 +01:00
if ( ! ui - > retryButton - > isVisible ( ) ) ui - > retryButton - > show ( ) ;
if ( ! ui - > logButton - > isVisible ( ) ) ui - > logButton - > show ( ) ;
ui - > closeButton - > setEnabled ( true ) ;
ui - > retryButton - > setEnabled ( true ) ;
ui - > logButton - > setEnabled ( true ) ;
if ( ui - > frameAnimation - > isVisible ( ) ) ui - > frameAnimation - > hide ( ) ;
ui - > statusLabel - > setText ( tr ( " Network connectivity test has failed! " ) ) ;
ui - > progressBar - > setValue ( ui - > progressBar - > maximum ( ) ) ;
ui - > hintIcon - > setPixmap ( QIcon ( " :/icons/network_error.png " ) . pixmap ( 16 , 16 ) ) ;
ui - > hintLabel - > setText ( tr ( " Please make sure your internet connection is working properly and try again. " ) ) ;
ui - > hintIcon - > show ( ) ;
ui - > hintLabel - > show ( ) ;
2010-12-06 18:29:34 +01:00
LAMEXP_DELETE ( m_updateInfo ) ;
2013-10-07 00:01:15 +02:00
if ( m_settings - > soundsEnabled ( ) ) lamexp_play_sound ( IDR_WAVE_ERROR , true ) ;
2010-12-06 18:29:34 +01:00
QApplication : : restoreOverrideCursor ( ) ;
2012-12-09 22:39:17 +01:00
ui - > progressBar - > setValue ( ui - > progressBar - > maximum ( ) ) ;
2011-02-25 13:40:45 +01:00
WinSevenTaskbar : : setTaskbarState ( this - > parentWidget ( ) , WinSevenTaskbar : : WinSevenTaskbarErrorState ) ;
WinSevenTaskbar : : setOverlayIcon ( this - > parentWidget ( ) , & QIcon ( " :/icons/exclamation.png " ) ) ;
2010-12-06 18:29:34 +01:00
return ;
}
2011-07-10 21:46:43 +02:00
// ----- Build Mirror List ----- //
2012-12-09 22:39:17 +01:00
ui - > statusLabel - > setText ( tr ( " Checking for new updates online, please wait... " ) ) ;
2011-05-09 22:22:15 +02:00
m_logFile - > append ( QStringList ( ) < < " " < < " ---- " < < " " < < " Checking for updates online... " ) ;
2012-10-09 01:58:36 +02:00
2011-03-24 15:37:49 +01:00
QStringList mirrorList ;
2011-07-10 21:46:43 +02:00
for ( int index = 0 ; update_mirrors_prim [ index ] ; index + + )
2010-11-28 22:18:07 +01:00
{
2011-07-10 21:46:43 +02:00
mirrorList < < QString : : fromLatin1 ( update_mirrors_prim [ index ] ) ;
2011-03-24 15:37:49 +01:00
}
2012-10-13 12:36:41 +02:00
lamexp_seed_rand ( ) ;
2012-10-09 01:58:36 +02:00
if ( const int len = mirrorList . count ( ) )
2011-03-24 15:37:49 +01:00
{
2012-10-09 17:43:17 +02:00
const int rounds = len * 1097 ;
2012-10-09 01:58:36 +02:00
for ( int i = 0 ; i < rounds ; i + + )
{
2012-10-13 12:36:41 +02:00
mirrorList . swap ( i % len , lamexp_rand ( ) % len ) ;
2012-10-09 01:58:36 +02:00
}
2011-03-24 15:37:49 +01:00
}
2011-07-10 21:46:43 +02:00
for ( int index = 0 ; update_mirrors_back [ index ] ; index + + )
{
mirrorList < < QString : : fromLatin1 ( update_mirrors_back [ index ] ) ;
}
2011-10-08 18:20:20 +02:00
2011-07-10 21:46:43 +02:00
// ----- Fetch Update Info From Server ----- //
2011-03-24 15:37:49 +01:00
while ( ! mirrorList . isEmpty ( ) )
{
QString currentMirror = mirrorList . takeFirst ( ) ;
2012-12-09 22:39:17 +01:00
ui - > progressBar - > setValue ( ui - > progressBar - > value ( ) + 1 ) ;
2010-12-06 18:29:34 +01:00
if ( ! success )
2010-11-28 22:18:07 +01:00
{
2011-03-24 15:37:49 +01:00
if ( tryUpdateMirror ( m_updateInfo , currentMirror ) )
2010-12-06 18:29:34 +01:00
{
success = true ;
}
2010-11-28 22:18:07 +01:00
}
2011-05-09 22:22:15 +02:00
else
{
2013-10-19 16:00:13 +02:00
QApplication : : processEvents ( QEventLoop : : ExcludeUserInputEvents ) ;
2013-10-07 00:01:15 +02:00
lamexp_sleep ( 64 ) ;
2011-05-09 22:22:15 +02:00
}
2010-11-28 22:18:07 +01:00
}
QApplication : : restoreOverrideCursor ( ) ;
2012-12-09 22:39:17 +01:00
ui - > progressBar - > setValue ( ui - > progressBar - > maximum ( ) ) ;
2011-02-25 13:40:45 +01:00
2010-11-28 22:18:07 +01:00
if ( ! success )
{
2012-12-09 22:39:17 +01:00
if ( ! ui - > retryButton - > isVisible ( ) ) ui - > retryButton - > show ( ) ;
if ( ! ui - > logButton - > isVisible ( ) ) ui - > logButton - > show ( ) ;
ui - > closeButton - > setEnabled ( true ) ;
ui - > retryButton - > setEnabled ( true ) ;
ui - > logButton - > setEnabled ( true ) ;
if ( ui - > frameAnimation - > isVisible ( ) ) ui - > frameAnimation - > hide ( ) ;
ui - > statusLabel - > setText ( tr ( " Failed to fetch update information from server! " ) ) ;
ui - > progressBar - > setValue ( ui - > progressBar - > maximum ( ) ) ;
2011-02-25 13:40:45 +01:00
WinSevenTaskbar : : setTaskbarState ( this - > parentWidget ( ) , WinSevenTaskbar : : WinSevenTaskbarErrorState ) ;
WinSevenTaskbar : : setOverlayIcon ( this - > parentWidget ( ) , & QIcon ( " :/icons/exclamation.png " ) ) ;
2012-12-09 22:39:17 +01:00
ui - > hintIcon - > setPixmap ( QIcon ( " :/icons/server_error.png " ) . pixmap ( 16 , 16 ) ) ;
ui - > hintLabel - > setText ( tr ( " Sorry, the update server might be busy at this time. Plase try again later. " ) ) ;
ui - > hintIcon - > show ( ) ;
ui - > hintLabel - > show ( ) ;
2010-11-28 22:18:07 +01:00
LAMEXP_DELETE ( m_updateInfo ) ;
2013-10-07 00:01:15 +02:00
if ( m_settings - > soundsEnabled ( ) ) lamexp_play_sound ( IDR_WAVE_ERROR , true ) ;
2010-11-28 22:18:07 +01:00
return ;
}
2010-11-29 20:36:27 +01:00
2011-07-10 21:46:43 +02:00
// ----- Download New Program Version ----- //
2012-12-09 22:39:17 +01:00
ui - > labelVersionLatest - > setText ( QString ( " %1 %2 (%3) " ) . arg ( tr ( " Build " ) , QString : : number ( m_updateInfo - > m_buildNo ) , m_updateInfo - > m_buildDate . toString ( Qt : : ISODate ) ) ) ;
ui - > infoLabel - > show ( ) ;
ui - > infoLabel - > setText ( QString ( " %1<br><a href= \" %2 \" >%2</a> " ) . arg ( tr ( " More information available at: " ) , m_updateInfo - > m_downloadSite ) ) ;
2013-10-19 16:00:13 +02:00
QApplication : : processEvents ( QEventLoop : : ExcludeUserInputEvents ) ;
2010-11-28 22:18:07 +01:00
if ( m_updateInfo - > m_buildNo > lamexp_version_build ( ) )
{
2012-12-09 22:39:17 +01:00
ui - > installButton - > setEnabled ( true ) ;
ui - > statusLabel - > setText ( tr ( " A new version of LameXP is available! " ) ) ;
ui - > hintIcon - > setPixmap ( QIcon ( " :/icons/shield_exclamation.png " ) . pixmap ( 16 , 16 ) ) ;
ui - > hintLabel - > setText ( tr ( " We highly recommend all users to install this update as soon as possible. " ) ) ;
if ( ui - > frameAnimation - > isVisible ( ) ) ui - > frameAnimation - > hide ( ) ;
ui - > hintIcon - > show ( ) ;
ui - > hintLabel - > show ( ) ;
2011-03-24 01:01:14 +01:00
WinSevenTaskbar : : setOverlayIcon ( this - > parentWidget ( ) , & QIcon ( " :/icons/shield_exclamation.png " ) ) ;
2013-10-07 00:01:15 +02:00
lamexp_beep ( lamexp_beep_info ) ;
2010-11-28 22:18:07 +01:00
}
else if ( m_updateInfo - > m_buildNo = = lamexp_version_build ( ) )
{
2012-12-09 22:39:17 +01:00
ui - > statusLabel - > setText ( tr ( " No new updates available at this time. " ) ) ;
ui - > hintIcon - > setPixmap ( QIcon ( " :/icons/shield_green.png " ) . pixmap ( 16 , 16 ) ) ;
ui - > hintLabel - > setText ( tr ( " Your version of LameXP is still up-to-date. Please check for updates regularly! " ) ) ;
if ( ui - > frameAnimation - > isVisible ( ) ) ui - > frameAnimation - > hide ( ) ;
ui - > hintIcon - > show ( ) ;
ui - > hintLabel - > show ( ) ;
2011-03-24 01:01:14 +01:00
WinSevenTaskbar : : setOverlayIcon ( this - > parentWidget ( ) , & QIcon ( " :/icons/shield_green.png " ) ) ;
2013-10-07 00:01:15 +02:00
lamexp_beep ( lamexp_beep_info ) ;
2010-11-28 22:18:07 +01:00
}
else
{
2012-12-09 22:39:17 +01:00
ui - > statusLabel - > setText ( tr ( " Your version appears to be newer than the latest release. " ) ) ;
ui - > hintIcon - > setPixmap ( QIcon ( " :/icons/shield_error.png " ) . pixmap ( 16 , 16 ) ) ;
ui - > hintLabel - > setText ( tr ( " This usually indicates your are currently using a pre-release version of LameXP. " ) ) ;
if ( ui - > frameAnimation - > isVisible ( ) ) ui - > frameAnimation - > hide ( ) ;
ui - > hintIcon - > show ( ) ;
ui - > hintLabel - > show ( ) ;
2011-03-28 04:23:57 +02:00
WinSevenTaskbar : : setOverlayIcon ( this - > parentWidget ( ) , & QIcon ( " :/icons/shield_error.png " ) ) ;
2013-10-07 00:01:15 +02:00
lamexp_beep ( lamexp_beep_warning ) ;
2010-11-28 22:18:07 +01:00
}
2012-12-09 22:39:17 +01:00
ui - > closeButton - > setEnabled ( true ) ;
if ( ui - > retryButton - > isVisible ( ) ) ui - > retryButton - > hide ( ) ;
if ( ui - > logButton - > isVisible ( ) ) ui - > logButton - > hide ( ) ;
if ( ui - > frameAnimation - > isVisible ( ) ) ui - > frameAnimation - > hide ( ) ;
2010-11-29 20:36:27 +01:00
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 ) ;
2011-05-09 22:22:15 +02:00
2010-12-07 22:58:28 +01:00
QString randPart = lamexp_rand_str ( ) ;
2011-02-25 22:03:39 +01:00
QString outFileVersionInfo = QString ( " %1/%2.ver " ) . arg ( lamexp_temp_folder2 ( ) , randPart ) ;
QString outFileSignature = QString ( " %1/%2.sig " ) . arg ( lamexp_temp_folder2 ( ) , randPart ) ;
2010-11-28 22:18:07 +01:00
2010-11-29 20:36:27 +01:00
m_logFile - > append ( QStringList ( ) < < " " < < " Downloading update info: " ) ;
2011-05-03 14:28:06 +02:00
bool ok1 = getFile ( QString ( " %1%2 " ) . arg ( url , mirror_url_postfix [ m_betaUpdates ? 1 : 0 ] ) , outFileVersionInfo ) ;
2010-11-28 22:18:07 +01:00
2010-11-29 20:36:27 +01:00
m_logFile - > append ( QStringList ( ) < < " " < < " Downloading signature: " ) ;
2011-05-03 14:28:06 +02:00
bool ok2 = getFile ( QString ( " %1%2.sig " ) . arg ( url , mirror_url_postfix [ m_betaUpdates ? 1 : 0 ] ) , outFileSignature ) ;
2010-11-28 22:18:07 +01:00
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 ;
}
2011-12-02 20:05:23 +01:00
bool UpdateDialog : : getFile ( const QString & url , const QString & outFile , unsigned int maxRedir , bool * httpOk )
2010-11-28 22:18:07 +01:00
{
QFileInfo output ( outFile ) ;
output . setCaching ( false ) ;
2011-12-02 20:05:23 +01:00
if ( httpOk ) * httpOk = false ;
2010-11-28 22:18:07 +01:00
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
2011-05-09 22:22:15 +02:00
QStringList args ;
args < < " --no-cache " < < " --no-dns-cache " < < QString ( ) . sprintf ( " --max-redirect=%u " , maxRedir ) ;
args < < QString ( " --referer=%1://%2/ " ) . arg ( QUrl ( url ) . scheme ( ) , QUrl ( url ) . host ( ) ) < < " -U " < < USER_AGENT_STR ;
args < < " -O " < < output . fileName ( ) < < url ;
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 ( ) ) ) ;
2011-03-24 15:37:49 +01:00
QTimer timer ;
timer . setSingleShot ( true ) ;
2011-12-01 22:16:06 +01:00
timer . setInterval ( 25000 ) ;
2011-03-24 15:37:49 +01:00
connect ( & timer , SIGNAL ( timeout ( ) ) , & loop , SLOT ( quit ( ) ) ) ;
2011-12-02 22:40:12 +01:00
const QRegExp httpResponseOK ( " 200 OK$ " ) ;
2011-05-09 22:22:15 +02:00
process . start ( m_binaryWGet , args ) ;
2010-11-28 22:18:07 +01:00
if ( ! process . waitForStarted ( ) )
{
return false ;
}
2011-03-24 15:37:49 +01:00
timer . start ( ) ;
2010-11-28 22:18:07 +01:00
while ( process . state ( ) = = QProcess : : Running )
{
loop . exec ( ) ;
2011-12-02 22:40:12 +01:00
bool bTimeOut = ( ! timer . isActive ( ) ) ;
2010-11-28 22:18:07 +01:00
while ( process . canReadLine ( ) )
{
2011-12-02 20:05:23 +01:00
QString line = QString : : fromLatin1 ( process . readLine ( ) ) . simplified ( ) ;
2011-12-02 22:40:12 +01:00
if ( line . contains ( httpResponseOK ) )
2011-12-02 20:05:23 +01:00
{
2011-12-02 22:40:12 +01:00
line . append ( " [OK] " ) ;
2011-12-02 20:05:23 +01:00
if ( httpOk ) * httpOk = true ;
}
2011-12-02 22:40:12 +01:00
m_logFile - > append ( line ) ;
}
if ( bTimeOut )
{
qWarning ( " WGet process timed out <-- killing! " ) ;
process . kill ( ) ;
process . waitForFinished ( ) ;
m_logFile - > append ( " !!! TIMEOUT !!! " ) ;
return false ;
2010-11-28 22:18:07 +01:00
}
}
2011-03-24 15:37:49 +01:00
timer . stop ( ) ;
timer . disconnect ( & timer , SIGNAL ( timeout ( ) ) , & loop , SLOT ( quit ( ) ) ) ;
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 ;
}
2010-12-07 22:58:28 +01:00
if ( QFileInfo ( file ) . absolutePath ( ) . compare ( QFileInfo ( m_binaryKeys ) . absolutePath ( ) , Qt : : CaseInsensitive ) ! = 0 )
2010-12-06 22:25:20 +01:00
{
2010-12-07 22:58:28 +01:00
qWarning ( " CheckSignature: File and keyring should be in same folder! " ) ;
2010-12-06 22:25:20 +01:00
return false ;
}
2010-12-07 22:58:28 +01:00
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-07 22:58:28 +01:00
process . start ( m_binaryGnuPG , QStringList ( ) < < " --homedir " < < " . " < < " --keyring " < < QFileInfo ( m_binaryKeys ) . fileName ( ) < < QFileInfo ( signature ) . fileName ( ) < < QFileInfo ( file ) . fileName ( ) ) ;
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 ) ;
}
bool UpdateDialog : : parseVersionInfo ( const QString & file , UpdateInfo * updateInfo )
{
QRegExp value ( " ^( \\ w+) = ( . + ) $ " ) ;
QRegExp section ( " ^ \\ [(.+) \ \ ] $ " ) ;
2011-03-25 15:18:13 +01:00
QDate updateInfoDate ;
2011-02-12 22:17:42 +01:00
updateInfo - > resetInfo ( ) ;
2010-11-28 22:18:07 +01:00
QFile data ( file ) ;
if ( ! data . open ( QIODevice : : ReadOnly ) )
{
qWarning ( " Cannot open update info file for reading! " ) ;
return false ;
}
2011-03-25 15:18:13 +01:00
bool inHeader = false ;
2010-11-28 22:18:07 +01:00
bool inSection = false ;
while ( ! data . atEnd ( ) )
{
QString line = QString : : fromLatin1 ( data . readLine ( ) ) . trimmed ( ) ;
if ( section . indexIn ( line ) > = 0 )
{
2011-02-12 22:17:42 +01:00
m_logFile - > append ( QString ( " Sec: [%1] " ) . arg ( section . cap ( 1 ) ) ) ;
2010-11-28 22:18:07 +01:00
inSection = ( section . cap ( 1 ) . compare ( section_id , Qt : : CaseInsensitive ) = = 0 ) ;
2011-03-25 15:18:13 +01:00
inHeader = ( section . cap ( 1 ) . compare ( header_id , Qt : : CaseInsensitive ) = = 0 ) ;
2010-11-28 22:18:07 +01:00
continue ;
}
2011-03-25 15:18:13 +01:00
if ( inSection & & ( value . indexIn ( line ) > = 0 ) )
2010-11-28 22:18:07 +01:00
{
2011-02-12 22:17:42 +01:00
m_logFile - > append ( QString ( " Val: '%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 ( ) ;
}
}
2011-03-25 15:18:13 +01:00
if ( inHeader & & ( value . indexIn ( line ) > = 0 ) )
{
m_logFile - > append ( QString ( " Val: '%1' ==> '%2 " ) . arg ( value . cap ( 1 ) , value . cap ( 2 ) ) ) ;
if ( value . cap ( 1 ) . compare ( " TimestampCreated " , Qt : : CaseInsensitive ) = = 0 )
{
QDate temp = QDate : : fromString ( value . cap ( 2 ) . trimmed ( ) , Qt : : ISODate ) ;
if ( temp . isValid ( ) ) updateInfoDate = temp ;
}
}
2010-11-28 22:18:07 +01:00
}
2011-03-25 15:18:13 +01:00
if ( ! updateInfoDate . isValid ( ) )
{
updateInfo - > resetInfo ( ) ;
m_logFile - > append ( " WARNING: Version info timestamp is missing! " ) ;
return false ;
}
2013-01-12 01:53:43 +01:00
else if ( updateInfoDate . addMonths ( VERSION_INFO_EXPIRES_MONTHS ) < lamexp_current_date_safe ( ) )
2011-03-25 15:18:13 +01:00
{
updateInfo - > resetInfo ( ) ;
m_logFile - > append ( QString : : fromLatin1 ( " WARNING: This version info has expired at %1! " ) . arg ( updateInfoDate . addMonths ( VERSION_INFO_EXPIRES_MONTHS ) . toString ( Qt : : ISODate ) ) ) ;
return false ;
}
2013-01-12 01:53:43 +01:00
else if ( lamexp_current_date_safe ( ) < updateInfoDate )
2011-03-25 15:18:13 +01:00
{
m_logFile - > append ( " Version info is from the future, take care! " ) ;
qWarning ( " Version info is from the future, take care! " ) ;
}
2010-11-28 22:18:07 +01:00
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 ;
2011-02-12 22:17:42 +01:00
if ( ! complete )
{
m_logFile - > append ( " WARNING: Version info is incomplete! " ) ;
}
2010-11-28 22:18:07 +01:00
return complete ;
}
void UpdateDialog : : linkActivated ( const QString & link )
{
QDesktopServices : : openUrl ( QUrl ( link ) ) ;
}
void UpdateDialog : : applyUpdate ( void )
{
2012-12-09 22:39:17 +01:00
ui - > installButton - > setEnabled ( false ) ;
ui - > closeButton - > setEnabled ( false ) ;
ui - > retryButton - > setEnabled ( false ) ;
2010-11-28 22:18:07 +01:00
if ( m_updateInfo )
{
2012-12-09 22:39:17 +01:00
ui - > statusLabel - > setText ( tr ( " Update is being downloaded, please be patient... " ) ) ;
ui - > frameAnimation - > show ( ) ;
if ( ui - > hintLabel - > isVisible ( ) ) ui - > hintLabel - > hide ( ) ;
if ( ui - > hintIcon - > isVisible ( ) ) ui - > hintIcon - > hide ( ) ;
int oldMax = ui - > progressBar - > maximum ( ) ;
int oldMin = ui - > progressBar - > minimum ( ) ;
ui - > progressBar - > setRange ( 0 , 0 ) ;
2013-10-19 16:00:13 +02:00
QApplication : : processEvents ( QEventLoop : : ExcludeUserInputEvents ) ;
2010-11-28 22:18:07 +01:00
QProcess process ;
QStringList args ;
QEventLoop loop ;
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 ) ;
2011-01-25 00:11:28 +01:00
args < < QString ( " /ToFolder=%1 " ) . arg ( QDir : : toNativeSeparators ( QDir ( QApplication : : applicationDirPath ( ) ) . canonicalPath ( ) ) ) ;
args < < QString ( " /ToExFile=%1.exe " ) . arg ( QFileInfo ( QFileInfo ( QApplication : : applicationFilePath ( ) ) . canonicalFilePath ( ) ) . completeBaseName ( ) ) ;
2010-11-28 22:18:07 +01:00
args < < QString ( " /AppTitle=LameXP (Build #%1) " ) . arg ( QString : : number ( m_updateInfo - > m_buildNo ) ) ;
QApplication : : setOverrideCursor ( Qt : : WaitCursor ) ;
2011-02-25 13:40:45 +01:00
WinSevenTaskbar : : setTaskbarState ( this - > parentWidget ( ) , WinSevenTaskbar : : WinSevenTaskbarIndeterminateState ) ;
WinSevenTaskbar : : setOverlayIcon ( this - > parentWidget ( ) , & QIcon ( " :/icons/transmit_blue.png " ) ) ;
2010-11-28 22:18:07 +01:00
process . start ( m_binaryUpdater , args ) ;
2012-01-24 02:46:29 +01:00
bool updateStarted = process . waitForStarted ( ) ;
if ( updateStarted )
{
2013-10-07 00:01:15 +02:00
m_updaterProcess = lamexp_process_id ( & process ) ;
2012-01-24 02:46:29 +01:00
loop . exec ( ) ;
}
m_updaterProcess = NULL ;
2010-11-28 22:18:07 +01:00
QApplication : : restoreOverrideCursor ( ) ;
2011-02-25 13:40:45 +01:00
2012-12-09 22:39:17 +01:00
ui - > hintLabel - > show ( ) ;
ui - > hintIcon - > show ( ) ;
ui - > progressBar - > setRange ( oldMin , oldMax ) ;
ui - > progressBar - > setValue ( oldMax ) ;
ui - > frameAnimation - > hide ( ) ;
2011-03-25 15:18:13 +01:00
2012-01-24 02:46:29 +01:00
if ( updateStarted & & ( process . exitCode ( ) = = 0 ) )
2010-11-28 22:18:07 +01:00
{
2012-12-09 22:39:17 +01:00
ui - > statusLabel - > setText ( tr ( " Update ready to install. Applicaion will quit... " ) ) ;
2011-02-18 00:53:36 +01:00
m_updateReadyToInstall = true ;
2011-02-25 13:40:45 +01:00
WinSevenTaskbar : : setTaskbarState ( this - > parentWidget ( ) , WinSevenTaskbar : : WinSevenTaskbarNoState ) ;
WinSevenTaskbar : : setOverlayIcon ( this - > parentWidget ( ) , NULL ) ;
2010-11-29 20:36:27 +01:00
accept ( ) ;
2010-11-28 22:18:07 +01:00
}
else
{
2012-12-09 22:39:17 +01:00
ui - > statusLabel - > setText ( tr ( " Update failed. Please try again or download manually! " ) ) ;
2011-02-25 13:40:45 +01:00
WinSevenTaskbar : : setTaskbarState ( this - > parentWidget ( ) , WinSevenTaskbar : : WinSevenTaskbarErrorState ) ;
WinSevenTaskbar : : setOverlayIcon ( this - > parentWidget ( ) , & QIcon ( " :/icons/exclamation.png " ) ) ;
WinSevenTaskbar : : setTaskbarProgress ( this - > parentWidget ( ) , 100 , 100 ) ;
2010-11-28 22:18:07 +01:00
}
}
2012-12-09 22:39:17 +01:00
ui - > installButton - > setEnabled ( true ) ;
ui - > closeButton - > setEnabled ( true ) ;
2010-11-28 22:18:07 +01:00
}
2010-11-29 20:36:27 +01:00
void UpdateDialog : : logButtonClicked ( void )
{
LogViewDialog * logView = new LogViewDialog ( this ) ;
logView - > exec ( * m_logFile ) ;
LAMEXP_DELETE ( logView ) ;
}
2011-02-25 13:40:45 +01:00
void UpdateDialog : : progressBarValueChanged ( int value )
{
2012-12-09 22:39:17 +01:00
WinSevenTaskbar : : setTaskbarProgress ( this - > parentWidget ( ) , value , ui - > progressBar - > maximum ( ) ) ;
2011-02-25 13:40:45 +01:00
}
2011-12-01 22:16:06 +01:00
void UpdateDialog : : testKnownWebSites ( void )
{
int connectionScore = 0 ;
// ----- Initialization ----- //
2012-12-09 22:39:17 +01:00
ui - > progressBar - > setValue ( 0 ) ;
2011-12-01 22:16:06 +01:00
WinSevenTaskbar : : setTaskbarState ( this - > parentWidget ( ) , WinSevenTaskbar : : WinSevenTaskbarNormalState ) ;
WinSevenTaskbar : : setOverlayIcon ( this - > parentWidget ( ) , & QIcon ( " :/icons/transmit_blue.png " ) ) ;
2012-12-09 22:39:17 +01:00
ui - > installButton - > setEnabled ( false ) ;
ui - > closeButton - > setEnabled ( false ) ;
ui - > retryButton - > setEnabled ( false ) ;
ui - > logButton - > setEnabled ( false ) ;
if ( ui - > infoLabel - > isVisible ( ) ) ui - > infoLabel - > hide ( ) ;
if ( ui - > hintLabel - > isVisible ( ) ) ui - > hintLabel - > hide ( ) ;
if ( ui - > hintIcon - > isVisible ( ) ) ui - > hintIcon - > hide ( ) ;
ui - > frameAnimation - > show ( ) ;
2011-12-01 22:16:06 +01:00
2013-10-19 16:00:13 +02:00
QApplication : : processEvents ( QEventLoop : : ExcludeUserInputEvents ) ;
2011-12-01 22:16:06 +01:00
QApplication : : setOverrideCursor ( Qt : : WaitCursor ) ;
// ----- Test Internet Connection ----- //
2012-12-09 22:39:17 +01:00
ui - > statusLabel - > setText ( " Testing all known hosts, this may take a few minutes... " ) ;
2011-12-01 22:16:06 +01:00
m_logFile - > clear ( ) ;
m_logFile - > append ( " Checking internet connection... " ) ;
2013-10-19 16:00:13 +02:00
const int networkStatus = DO_ASYNC ( lamexp_network_status ) ;
if ( networkStatus = = lamexp_network_non )
2011-12-01 22:16:06 +01:00
{
m_logFile - > append ( QStringList ( ) < < " " < < " Operating system reports that the computer is currently offline !!! " ) ;
2012-12-09 22:39:17 +01:00
if ( ! ui - > retryButton - > isVisible ( ) ) ui - > retryButton - > show ( ) ;
if ( ! ui - > logButton - > isVisible ( ) ) ui - > logButton - > show ( ) ;
ui - > closeButton - > setEnabled ( true ) ;
ui - > retryButton - > setEnabled ( true ) ;
ui - > logButton - > setEnabled ( true ) ;
if ( ui - > frameAnimation - > isVisible ( ) ) ui - > frameAnimation - > hide ( ) ;
ui - > statusLabel - > setText ( tr ( " It appears that the computer currently is offline! " ) ) ;
ui - > progressBar - > setValue ( ui - > progressBar - > maximum ( ) ) ;
ui - > hintIcon - > setPixmap ( QIcon ( " :/icons/network_error.png " ) . pixmap ( 16 , 16 ) ) ;
ui - > hintLabel - > setText ( tr ( " Please make sure your computer is connected to the internet and try again. " ) ) ;
ui - > hintIcon - > show ( ) ;
ui - > hintLabel - > show ( ) ;
2011-12-01 22:16:06 +01:00
LAMEXP_DELETE ( m_updateInfo ) ;
2013-10-07 00:01:15 +02:00
if ( m_settings - > soundsEnabled ( ) ) lamexp_play_sound ( IDR_WAVE_ERROR , true ) ;
2011-12-01 22:16:06 +01:00
QApplication : : restoreOverrideCursor ( ) ;
2012-12-09 22:39:17 +01:00
ui - > progressBar - > setValue ( ui - > progressBar - > maximum ( ) ) ;
2011-12-01 22:16:06 +01:00
WinSevenTaskbar : : setTaskbarState ( this - > parentWidget ( ) , WinSevenTaskbar : : WinSevenTaskbarErrorState ) ;
WinSevenTaskbar : : setOverlayIcon ( this - > parentWidget ( ) , & QIcon ( " :/icons/exclamation.png " ) ) ;
return ;
}
// ----- Test Known Hosts Connectivity ----- //
QStringList hostList ;
for ( int i = 0 ; known_hosts [ i ] ; i + + )
{
hostList < < QString : : fromLatin1 ( known_hosts [ i ] ) ;
}
2011-12-02 22:40:12 +01:00
qDebug ( " [Known Hosts] " ) ;
2011-12-02 20:05:23 +01:00
int hostCount = hostList . count ( ) ;
2011-12-01 22:16:06 +01:00
while ( ! hostList . isEmpty ( ) )
{
QString currentHost = hostList . takeFirst ( ) ;
2012-12-09 22:39:17 +01:00
ui - > progressBar - > setValue ( qRound ( ( static_cast < double > ( ui - > progressBar - > maximum ( ) - 1 ) / static_cast < double > ( hostCount ) ) * static_cast < double > ( connectionScore ) ) + 1 ) ;
2011-12-01 22:16:06 +01:00
qDebug ( " Testing: %s " , currentHost . toLatin1 ( ) . constData ( ) ) ;
m_logFile - > append ( QStringList ( ) < < " " < < " Testing host: " < < currentHost < < " " ) ;
QString outFile = QString ( " %1/%2.htm " ) . arg ( lamexp_temp_folder2 ( ) , lamexp_rand_str ( ) ) ;
2011-12-02 20:05:23 +01:00
bool httpOk = false ;
if ( getFile ( currentHost , outFile , 0 , & httpOk ) )
2011-12-01 22:16:06 +01:00
{
connectionScore + + ;
}
else
{
2011-12-02 20:05:23 +01:00
if ( httpOk )
{
2011-12-02 22:40:12 +01:00
qWarning ( " \n Connectivity test was SLOW on the following site: \n %s \n " , currentHost . toLatin1 ( ) . constData ( ) ) ;
2011-12-02 20:05:23 +01:00
connectionScore + + ;
}
else
{
2011-12-02 22:40:12 +01:00
qWarning ( " \n Connectivity test FAILED on the following site: \n %s \n " , currentHost . toLatin1 ( ) . constData ( ) ) ;
2011-12-02 20:05:23 +01:00
}
2011-12-01 22:16:06 +01:00
}
QFile : : remove ( outFile ) ;
}
2011-12-02 20:05:23 +01:00
if ( connectionScore < hostCount )
2011-12-01 22:16:06 +01:00
{
2012-12-09 22:39:17 +01:00
if ( ! ui - > retryButton - > isVisible ( ) ) ui - > retryButton - > show ( ) ;
if ( ! ui - > logButton - > isVisible ( ) ) ui - > logButton - > show ( ) ;
ui - > closeButton - > setEnabled ( true ) ;
ui - > retryButton - > setEnabled ( true ) ;
ui - > logButton - > setEnabled ( true ) ;
if ( ui - > frameAnimation - > isVisible ( ) ) ui - > frameAnimation - > hide ( ) ;
ui - > statusLabel - > setText ( " At least one host could not be reached! " ) ;
ui - > progressBar - > setValue ( ui - > progressBar - > maximum ( ) ) ;
ui - > hintIcon - > setPixmap ( QIcon ( " :/icons/network_error.png " ) . pixmap ( 16 , 16 ) ) ;
ui - > hintLabel - > setText ( " Please make sure your internet connection is working properly and try again. " ) ;
ui - > hintIcon - > show ( ) ;
ui - > hintLabel - > show ( ) ;
2011-12-01 22:16:06 +01:00
LAMEXP_DELETE ( m_updateInfo ) ;
2013-10-07 00:01:15 +02:00
if ( m_settings - > soundsEnabled ( ) ) lamexp_play_sound ( IDR_WAVE_ERROR , true ) ;
2011-12-01 22:16:06 +01:00
QApplication : : restoreOverrideCursor ( ) ;
2012-12-09 22:39:17 +01:00
ui - > progressBar - > setValue ( ui - > progressBar - > maximum ( ) ) ;
2011-12-01 22:16:06 +01:00
WinSevenTaskbar : : setTaskbarState ( this - > parentWidget ( ) , WinSevenTaskbar : : WinSevenTaskbarErrorState ) ;
WinSevenTaskbar : : setOverlayIcon ( this - > parentWidget ( ) , & QIcon ( " :/icons/exclamation.png " ) ) ;
return ;
}
// ----- Done ----- //
QApplication : : restoreOverrideCursor ( ) ;
2012-12-09 22:39:17 +01:00
ui - > progressBar - > setValue ( ui - > progressBar - > maximum ( ) ) ;
ui - > statusLabel - > setText ( " Test completed. " ) ;
ui - > hintIcon - > setPixmap ( QIcon ( " :/icons/shield_green.png " ) . pixmap ( 16 , 16 ) ) ;
ui - > hintLabel - > setText ( " Congratulations, the test has completed. " ) ;
if ( ui - > frameAnimation - > isVisible ( ) ) ui - > frameAnimation - > hide ( ) ;
ui - > hintIcon - > show ( ) ;
ui - > hintLabel - > show ( ) ;
2011-12-01 22:16:06 +01:00
WinSevenTaskbar : : setOverlayIcon ( this - > parentWidget ( ) , & QIcon ( " :/icons/shield_green.png " ) ) ;
2013-10-07 00:01:15 +02:00
lamexp_beep ( lamexp_beep_info ) ;
2011-12-01 22:16:06 +01:00
2012-12-09 22:39:17 +01:00
ui - > closeButton - > setEnabled ( true ) ;
if ( ui - > retryButton - > isVisible ( ) ) ui - > retryButton - > hide ( ) ;
if ( ui - > logButton - > isVisible ( ) ) ui - > logButton - > hide ( ) ;
if ( ui - > frameAnimation - > isVisible ( ) ) ui - > frameAnimation - > hide ( ) ;
2011-12-01 22:16:06 +01:00
}