Skip to content

Commit

Permalink
updateDialog now works on windows
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://svn.last.fm/svn/clientside/trunk/desktop@123869 ab8f4a45-97f9-0310-bbd1-854ce3dcee89
  • Loading branch information
dougma committed Mar 11, 2009
1 parent ce49421 commit c1d0fd3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
35 changes: 21 additions & 14 deletions lib/unicorn/widgets/UpdateDialog.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
#include "common/qt/md5.cpp" #include "common/qt/md5.cpp"
#include <QCoreApplication> #include <QCoreApplication>
#include <QDesktopServices> #include <QDesktopServices>
#include <QTemporaryFile>
#include <QFileInfo> #include <QFileInfo>
#include <QDir>
#include <QLabel> #include <QLabel>
#include <QProgressBar> #include <QProgressBar>
#include <QPushButton> #include <QPushButton>
Expand All @@ -34,6 +36,7 @@
#include <shellapi.h> #include <shellapi.h>
#endif #endif



UpdateDialog::UpdateDialog( QWidget* parent ) : QDialog( parent ), checking( 0 ) UpdateDialog::UpdateDialog( QWidget* parent ) : QDialog( parent ), checking( 0 )
{ {
QVBoxLayout* v = new QVBoxLayout( this ); QVBoxLayout* v = new QVBoxLayout( this );
Expand All @@ -60,7 +63,7 @@ UpdateDialog::UpdateDialog( QWidget* parent ) : QDialog( parent ), checking( 0 )
#endif #endif


QUrl url( "http://cdn.last.fm/client/" + qApp->applicationName().toLower() + PLATFORM + qApp->applicationVersion() + ".txt" ); QUrl url( "http://cdn.last.fm/client/" + qApp->applicationName().toLower() + PLATFORM + qApp->applicationVersion() + ".txt" );
// QUrl url( "http://static.last.fm/client/update_test/200.txt" ); // QUrl url( "http://static.last.fm/client/update_test/201.txt" );
checking = nam.get( QNetworkRequest(url) ); checking = nam.get( QNetworkRequest(url) );
checking->setParent( this ); checking->setParent( this );


Expand Down Expand Up @@ -88,9 +91,6 @@ UpdateDialog::onGot()
reply->setParent( this ); reply->setParent( this );
connect( reply, SIGNAL(downloadProgress( qint64, qint64 )), SLOT(onProgress( qint64, qint64 )) ); connect( reply, SIGNAL(downloadProgress( qint64, qint64 )), SLOT(onProgress( qint64, qint64 )) );
connect( reply, SIGNAL(finished()), SLOT(onDownloaded()) ); connect( reply, SIGNAL(finished()), SLOT(onDownloaded()) );

// ensure the extension still is at end, so QDesktopServices works
tmp.setFileTemplate( "XXXXXX_" + QFileInfo( url.path() ).fileName() );
} }
} }


Expand All @@ -115,7 +115,7 @@ UpdateDialog::onDownloaded()


bar->setRange( 0, 100 ); bar->setRange( 0, 100 );
bar->setValue( 100 ); bar->setValue( 100 );
text->setText( tr( "A new version of Last.fm is available" ) ); text->setText( tr( "A new version of %1 is available" ).arg( qApp->applicationName() ) );
#ifdef __APPLE__ #ifdef __APPLE__
button->setText( tr("Thanks!") ); //will open DMG file now button->setText( tr("Thanks!") ); //will open DMG file now
#else #else
Expand All @@ -124,9 +124,15 @@ UpdateDialog::onDownloaded()


show(); show();


tmp.setAutoRemove( false ); //TODO naughty! maybe a script that waits on the dmg open complete and then deletes // ensure the extension is still at end (so we can launch it)
tmp.open(); QString templ = QDir::tempPath() + "/" + "XXXXXX_" + QFileInfo( url.path() ).fileName();
tmp.write( data ); {
QTemporaryFile temp( templ );
temp.setAutoRemove( false );
temp.open();
temp.write( data );
tmpFileName = QDir::toNativeSeparators( temp.fileName() );
}


disconnect( button, SIGNAL(clicked()), this, SLOT(close()) ); disconnect( button, SIGNAL(clicked()), this, SLOT(close()) );
connect( button, SIGNAL(clicked()), SLOT(install()) ); connect( button, SIGNAL(clicked()), SLOT(install()) );
Expand All @@ -136,25 +142,22 @@ void
UpdateDialog::install() UpdateDialog::install()
{ {
#ifdef __APPLE__ #ifdef __APPLE__
QDesktopServices::openUrl( QUrl::fromLocalFile( tmp.fileName() ) ); QDesktopServices::openUrl( QUrl::fromLocalFile( tmpFileName ) );
qApp->quit(); qApp->quit();
//TODO auto shut this instance if possible //TODO auto shut this instance if possible
#endif #endif
#ifdef WIN32 #ifdef WIN32
// Must use ShellExecute because otherwise the elevation dialog // Must use ShellExecute because otherwise the elevation dialog
// doesn't appear when launching the installer on Vista. // doesn't appear when launching the installer on Vista.


QString const path = tmp.fileName();
tmp.close();

SHELLEXECUTEINFOW sei; SHELLEXECUTEINFOW sei;
memset(&sei, 0, sizeof(sei)); memset(&sei, 0, sizeof(sei));


sei.cbSize = sizeof(sei); sei.cbSize = sizeof(sei);
sei.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_DDEWAIT; sei.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_DDEWAIT;
sei.hwnd = GetForegroundWindow(); sei.hwnd = GetForegroundWindow();
sei.lpVerb = L"open"; sei.lpVerb = L"open";
sei.lpFile = reinterpret_cast<LPCWSTR>(path.utf16()); sei.lpFile = reinterpret_cast<LPCWSTR>( tmpFileName.utf16() );
sei.lpParameters = 0; sei.lpParameters = 0;
sei.nShow = SW_SHOWNORMAL; sei.nShow = SW_SHOWNORMAL;


Expand All @@ -166,10 +169,14 @@ UpdateDialog::install()
QApplication::restoreOverrideCursor(); QApplication::restoreOverrideCursor();
} }
else { else {
qWarning() << "Couldn't open" << path; qWarning() << "Couldn't open" << tmpFileName;
text->setText( tr("The installer could not be launched") ); text->setText( tr("The installer could not be launched") );
} }


qApp->quit(); qApp->quit();

#endif #endif

// TODO: remove downloaded msi/exe/dmg turd, somehow

} }
3 changes: 1 addition & 2 deletions lib/unicorn/widgets/UpdateDialog.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include "lib/DllExportMacro.h" #include "lib/DllExportMacro.h"
#include <lastfm/WsAccessManager> #include <lastfm/WsAccessManager>
#include <QDialog> #include <QDialog>
#include <QTemporaryFile>




/** we did use QProgressDialog, but it's so amazingly shit. We stopped. /** we did use QProgressDialog, but it's so amazingly shit. We stopped.
Expand All @@ -36,7 +35,7 @@ class UNICORN_DLLEXPORT UpdateDialog : public QDialog
QNetworkReply* checking; QNetworkReply* checking;
QByteArray md5; QByteArray md5;
QUrl url; QUrl url;
QTemporaryFile tmp; QString tmpFileName;


class QLabel* text; class QLabel* text;
class QProgressBar* bar; class QProgressBar* bar;
Expand Down

0 comments on commit c1d0fd3

Please sign in to comment.