mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-16 19:14:06 +02:00
Refactor platform check into its own function
This commit is contained in:
@@ -72,6 +72,38 @@ ResolverAccountFactory::createFromPath( const QString& path )
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if the bundle specifies a platform, and if so, reject the
|
||||
* resolver if the platform is wrong.
|
||||
*/
|
||||
bool
|
||||
isPlatformSupported( const QVariant& variant )
|
||||
{
|
||||
// No platform specified, so accept it.
|
||||
if ( variant.isNull() )
|
||||
return true;
|
||||
|
||||
const QString platform( variant.toString() );
|
||||
// We accept any platform
|
||||
if ( platform == "any" )
|
||||
return true;
|
||||
|
||||
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
|
||||
|
||||
return myPlatform.contains( platform );
|
||||
}
|
||||
|
||||
|
||||
Account*
|
||||
ResolverAccountFactory::createFromPath( const QString& path, const QString& factory, bool isAttica )
|
||||
{
|
||||
@@ -170,28 +202,10 @@ ResolverAccountFactory::createFromPath( const QString& path, const QString& fact
|
||||
//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" )
|
||||
if ( !isPlatformSupported( configuration[ "platform" ] ) )
|
||||
{
|
||||
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 ) )
|
||||
{
|
||||
displayError( tr( "Resolver installation error: platform mismatch." ) );
|
||||
return nullptr;
|
||||
}
|
||||
displayError( tr( "Resolver installation error: platform mismatch." ) );
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if ( !configuration[ "tomahawkVersion" ].isNull() )
|
||||
|
Reference in New Issue
Block a user