mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-15 02:24:50 +02:00
Add platform and Tomahawk version checks to resolver installation.
This commit is contained in:
@@ -51,6 +51,9 @@
|
|||||||
#include "accounts/spotify/SpotifyAccount.h"
|
#include "accounts/spotify/SpotifyAccount.h"
|
||||||
#include "thirdparty/Qocoa/qtoolbartabdialog.h"
|
#include "thirdparty/Qocoa/qtoolbartabdialog.h"
|
||||||
#include "thirdparty/Qocoa/qbutton.h"
|
#include "thirdparty/Qocoa/qbutton.h"
|
||||||
|
#include "jobview/JobStatusView.h"
|
||||||
|
#include "jobview/JobStatusModel.h"
|
||||||
|
#include "jobview/ErrorStatusMessage.h"
|
||||||
|
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
@@ -491,7 +494,18 @@ SettingsDialog::installFromFile()
|
|||||||
|
|
||||||
Account* acct = AccountManager::instance()->accountFromPath( resolver );
|
Account* acct = AccountManager::instance()->accountFromPath( resolver );
|
||||||
|
|
||||||
Q_ASSERT( acct );
|
if ( !acct )
|
||||||
|
{
|
||||||
|
QFileInfo fi( resolver );
|
||||||
|
|
||||||
|
JobStatusView::instance()->model()->addJob( new ErrorStatusMessage(
|
||||||
|
tr( "Resolver installation from file %1 failed." )
|
||||||
|
.arg( fi.fileName() ) ) );
|
||||||
|
|
||||||
|
tDebug() << "Resolver was not installed:" << resolver;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
AccountManager::instance()->addAccount( acct );
|
AccountManager::instance()->addAccount( acct );
|
||||||
TomahawkSettings::instance()->addAccount( acct->accountId() );
|
TomahawkSettings::instance()->addAccount( acct->accountId() );
|
||||||
AccountManager::instance()->enableAccount( acct );
|
AccountManager::instance()->enableAccount( acct );
|
||||||
|
@@ -28,6 +28,10 @@
|
|||||||
#include "Source.h"
|
#include "Source.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
#include "qjson/parser.h"
|
#include "qjson/parser.h"
|
||||||
|
#include "jobview/JobStatusView.h"
|
||||||
|
#include "jobview/JobStatusModel.h"
|
||||||
|
#include "jobview/ErrorStatusMessage.h"
|
||||||
|
#include "TomahawkVersion.h"
|
||||||
|
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
@@ -93,10 +97,18 @@ ResolverAccountFactory::createFromPath( const QString& path, const QString& fact
|
|||||||
uniqueName,
|
uniqueName,
|
||||||
MANUALRESOLVERS_DIR ) );
|
MANUALRESOLVERS_DIR ) );
|
||||||
if ( !( dir.exists() && dir.isReadable() ) ) //decompression fubar
|
if ( !( dir.exists() && dir.isReadable() ) ) //decompression fubar
|
||||||
|
{
|
||||||
|
JobStatusView::instance()->model()->addJob( new ErrorStatusMessage(
|
||||||
|
tr( "Resolver installation error: cannot open bundle." ) ) );
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if ( !dir.cd( "content" ) ) //more fubar
|
if ( !dir.cd( "content" ) ) //more fubar
|
||||||
|
{
|
||||||
|
JobStatusView::instance()->model()->addJob( new ErrorStatusMessage(
|
||||||
|
tr( "Resolver installation error: incomplete bundle." ) ) );
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
QString metadataFilePath = dir.absoluteFilePath( "metadata.json" );
|
QString metadataFilePath = dir.absoluteFilePath( "metadata.json" );
|
||||||
configuration = metadataFromJsonFile( metadataFilePath );
|
configuration = metadataFromJsonFile( metadataFilePath );
|
||||||
@@ -131,8 +143,12 @@ ResolverAccountFactory::createFromPath( const QString& path, const QString& fact
|
|||||||
|
|
||||||
realPath = configuration[ "path" ].toString();
|
realPath = configuration[ "path" ].toString();
|
||||||
if ( realPath.isEmpty() )
|
if ( realPath.isEmpty() )
|
||||||
|
{
|
||||||
|
JobStatusView::instance()->model()->addJob( new ErrorStatusMessage(
|
||||||
|
tr( "Resolver installation error: bad metadata in bundle." ) ) );
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else //either legacy resolver or uncompressed bundle, so we look for a metadata file
|
else //either legacy resolver or uncompressed bundle, so we look for a metadata file
|
||||||
{
|
{
|
||||||
QDir dir = pathInfo.absoluteDir();//assume we are in the code directory of a bundle
|
QDir dir = pathInfo.absoluteDir();//assume we are in the code directory of a bundle
|
||||||
@@ -146,6 +162,46 @@ ResolverAccountFactory::createFromPath( const QString& path, const QString& fact
|
|||||||
//else we just have empty metadata (legacy resolver without desktop file)
|
//else we just have empty metadata (legacy resolver without desktop file)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//check if the bundle specifies a platform, and if so, reject the resolver if the platform is wrong
|
||||||
|
if ( !configuration[ "platform" ].isNull() && configuration[ "platform" ].toString() != "any" )
|
||||||
|
{
|
||||||
|
QString platform( configuration[ "platform" ].toString() );
|
||||||
|
QString myPlatform( "any" );
|
||||||
|
|
||||||
|
#if defined( Q_OS_WIN )
|
||||||
|
myPlatform = "win";
|
||||||
|
#elif defined( Q_OS_MAC )
|
||||||
|
myPlatform = "osx";
|
||||||
|
#elif defined( Q_OS_LINUX )
|
||||||
|
if ( __WORDSIZE == 32 )
|
||||||
|
myPlatform = "linux-x86";
|
||||||
|
else if ( __WORDSIZE == 64 )
|
||||||
|
myPlatform = "linux-x64";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if ( !myPlatform.contains( platform ) )
|
||||||
|
{
|
||||||
|
tDebug() << "Wrong resolver platform.";
|
||||||
|
JobStatusView::instance()->model()->addJob( new ErrorStatusMessage(
|
||||||
|
tr( "Resolver installation error: platform mismatch." ) ) );
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !configuration[ "tomahawkVersion" ].isNull() )
|
||||||
|
{
|
||||||
|
QString thVer = TOMAHAWK_VERSION;
|
||||||
|
QString requiredVer = configuration[ "tomahawkVersion" ].toString();
|
||||||
|
|
||||||
|
if ( TomahawkUtils::compareVersionStrings( thVer, requiredVer ) < 0 )
|
||||||
|
{
|
||||||
|
JobStatusView::instance()->model()->addJob( new ErrorStatusMessage(
|
||||||
|
tr( "Resolver installation error: Tomahawk %1 or newer is required." )
|
||||||
|
.arg( requiredVer ) ) );
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//TODO: handle multi-account resolvers
|
//TODO: handle multi-account resolvers
|
||||||
|
|
||||||
return new ResolverAccount( generateId( factory ), realPath, configuration );
|
return new ResolverAccount( generateId( factory ), realPath, configuration );
|
||||||
@@ -187,6 +243,10 @@ ResolverAccountFactory::metadataFromJsonFile( const QString& path )
|
|||||||
result[ "revision" ] = variant[ "revision" ];
|
result[ "revision" ] = variant[ "revision" ];
|
||||||
if ( !variant[ "timestamp" ].isNull() )
|
if ( !variant[ "timestamp" ].isNull() )
|
||||||
result[ "timestamp" ] = variant[ "timestamp" ];
|
result[ "timestamp" ] = variant[ "timestamp" ];
|
||||||
|
if ( !variant[ "tomahawkVersion" ].isNull() )
|
||||||
|
result[ "tomahawkVersion" ] = variant[ "tomahawkVersion" ];
|
||||||
|
if ( !variant[ "platform" ].isNull() )
|
||||||
|
result[ "platform" ] = variant[ "platform" ];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@@ -45,6 +45,7 @@
|
|||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
#include <QCryptographicHash>
|
#include <QCryptographicHash>
|
||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
|
#include <QStringList>
|
||||||
#include <QTranslator>
|
#include <QTranslator>
|
||||||
|
|
||||||
#if QT_VERSION >= QT_VERSION_CHECK( 5, 0, 0 )
|
#if QT_VERSION >= QT_VERSION_CHECK( 5, 0, 0 )
|
||||||
@@ -1013,6 +1014,53 @@ whitelistedHttpResultHint( const QString& url )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
compareVersionStrings( const QString& first, const QString& second )
|
||||||
|
{
|
||||||
|
QStringList a = first.split( '.', QString::SkipEmptyParts );
|
||||||
|
QStringList b = second.split( '.', QString::SkipEmptyParts );
|
||||||
|
|
||||||
|
const int depth = qMax( a.count(), b.count() );
|
||||||
|
|
||||||
|
while ( a.count() < depth )
|
||||||
|
a.append( "0" );
|
||||||
|
|
||||||
|
while ( b.count() < depth )
|
||||||
|
b.append( "0" );
|
||||||
|
|
||||||
|
int verdict = 0;
|
||||||
|
for ( int i = 0; i < depth; ++i )
|
||||||
|
{
|
||||||
|
bool aOk;
|
||||||
|
int aNumber = a.at( i ).toInt( &aOk );
|
||||||
|
bool bOk;
|
||||||
|
int bNumber = b.at( i ).toInt( &bOk );
|
||||||
|
|
||||||
|
if ( aOk && bOk )
|
||||||
|
{
|
||||||
|
if ( aNumber < bNumber )
|
||||||
|
{
|
||||||
|
verdict = -1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if ( aNumber > bNumber )
|
||||||
|
{
|
||||||
|
verdict = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else //fallback: string comparison
|
||||||
|
{
|
||||||
|
verdict = a.at( i ).compare( b.at( i ) );
|
||||||
|
if ( verdict != 0 )
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return verdict;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
urlAddQueryItem( QUrl& url, const QString& key, const QString& value )
|
urlAddQueryItem( QUrl& url, const QString& key, const QString& value )
|
||||||
{
|
{
|
||||||
|
@@ -206,6 +206,8 @@ namespace TomahawkUtils
|
|||||||
|
|
||||||
DLLEXPORT bool whitelistedHttpResultHint( const QString& url );
|
DLLEXPORT bool whitelistedHttpResultHint( const QString& url );
|
||||||
|
|
||||||
|
DLLEXPORT int compareVersionStrings( const QString& first, const QString& second );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This helper is designed to help "update" an existing playlist with a newer revision of itself.
|
* This helper is designed to help "update" an existing playlist with a newer revision of itself.
|
||||||
* To avoid re-loading the whole playlist and re-resolving tracks that are the same in the old playlist,
|
* To avoid re-loading the whole playlist and re-resolving tracks that are the same in the old playlist,
|
||||||
|
Reference in New Issue
Block a user