Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Add platform and Tomahawk version checks to resolver installation.

  • Loading branch information...
commit 8285857ac2ac1cb2b6379a53af325bf3c75adddb 1 parent a0f0815
Teo Mrnjavac teo authored
16 src/SettingsDialog.cpp
@@ -51,6 +51,9 @@
51 51 #include "accounts/spotify/SpotifyAccount.h"
52 52 #include "thirdparty/Qocoa/qtoolbartabdialog.h"
53 53 #include "thirdparty/Qocoa/qbutton.h"
  54 +#include "jobview/JobStatusView.h"
  55 +#include "jobview/JobStatusModel.h"
  56 +#include "jobview/ErrorStatusMessage.h"
54 57
55 58 #include <QDesktopServices>
56 59 #include <QFileDialog>
@@ -491,7 +494,18 @@ SettingsDialog::installFromFile()
491 494
492 495 Account* acct = AccountManager::instance()->accountFromPath( resolver );
493 496
494   - Q_ASSERT( acct );
  497 + if ( !acct )
  498 + {
  499 + QFileInfo fi( resolver );
  500 +
  501 + JobStatusView::instance()->model()->addJob( new ErrorStatusMessage(
  502 + tr( "Resolver installation from file %1 failed." )
  503 + .arg( fi.fileName() ) ) );
  504 +
  505 + tDebug() << "Resolver was not installed:" << resolver;
  506 + return;
  507 + }
  508 +
495 509 AccountManager::instance()->addAccount( acct );
496 510 TomahawkSettings::instance()->addAccount( acct->accountId() );
497 511 AccountManager::instance()->enableAccount( acct );
60 src/libtomahawk/accounts/ResolverAccount.cpp
@@ -28,6 +28,10 @@
28 28 #include "Source.h"
29 29 #include "utils/Logger.h"
30 30 #include "qjson/parser.h"
  31 +#include "jobview/JobStatusView.h"
  32 +#include "jobview/JobStatusModel.h"
  33 +#include "jobview/ErrorStatusMessage.h"
  34 +#include "TomahawkVersion.h"
31 35
32 36 #include <QFile>
33 37 #include <QFileInfo>
@@ -93,10 +97,18 @@ ResolverAccountFactory::createFromPath( const QString& path, const QString& fact
93 97 uniqueName,
94 98 MANUALRESOLVERS_DIR ) );
95 99 if ( !( dir.exists() && dir.isReadable() ) ) //decompression fubar
  100 + {
  101 + JobStatusView::instance()->model()->addJob( new ErrorStatusMessage(
  102 + tr( "Resolver installation error: cannot open bundle." ) ) );
96 103 return 0;
  104 + }
97 105
98 106 if ( !dir.cd( "content" ) ) //more fubar
  107 + {
  108 + JobStatusView::instance()->model()->addJob( new ErrorStatusMessage(
  109 + tr( "Resolver installation error: incomplete bundle." ) ) );
99 110 return 0;
  111 + }
100 112
101 113 QString metadataFilePath = dir.absoluteFilePath( "metadata.json" );
102 114 configuration = metadataFromJsonFile( metadataFilePath );
@@ -131,7 +143,11 @@ ResolverAccountFactory::createFromPath( const QString& path, const QString& fact
131 143
132 144 realPath = configuration[ "path" ].toString();
133 145 if ( realPath.isEmpty() )
  146 + {
  147 + JobStatusView::instance()->model()->addJob( new ErrorStatusMessage(
  148 + tr( "Resolver installation error: bad metadata in bundle." ) ) );
134 149 return 0;
  150 + }
135 151 }
136 152 else //either legacy resolver or uncompressed bundle, so we look for a metadata file
137 153 {
@@ -146,6 +162,46 @@ ResolverAccountFactory::createFromPath( const QString& path, const QString& fact
146 162 //else we just have empty metadata (legacy resolver without desktop file)
147 163 }
148 164
  165 + //check if the bundle specifies a platform, and if so, reject the resolver if the platform is wrong
  166 + if ( !configuration[ "platform" ].isNull() && configuration[ "platform" ].toString() != "any" )
  167 + {
  168 + QString platform( configuration[ "platform" ].toString() );
  169 + QString myPlatform( "any" );
  170 +
  171 +#if defined( Q_OS_WIN )
  172 + myPlatform = "win";
  173 +#elif defined( Q_OS_MAC )
  174 + myPlatform = "osx";
  175 +#elif defined( Q_OS_LINUX )
  176 + if ( __WORDSIZE == 32 )
  177 + myPlatform = "linux-x86";
  178 + else if ( __WORDSIZE == 64 )
  179 + myPlatform = "linux-x64";
  180 +#endif
  181 +
  182 + if ( !myPlatform.contains( platform ) )
  183 + {
  184 + tDebug() << "Wrong resolver platform.";
  185 + JobStatusView::instance()->model()->addJob( new ErrorStatusMessage(
  186 + tr( "Resolver installation error: platform mismatch." ) ) );
  187 + return 0;
  188 + }
  189 + }
  190 +
  191 + if ( !configuration[ "tomahawkVersion" ].isNull() )
  192 + {
  193 + QString thVer = TOMAHAWK_VERSION;
  194 + QString requiredVer = configuration[ "tomahawkVersion" ].toString();
  195 +
  196 + if ( TomahawkUtils::compareVersionStrings( thVer, requiredVer ) < 0 )
  197 + {
  198 + JobStatusView::instance()->model()->addJob( new ErrorStatusMessage(
  199 + tr( "Resolver installation error: Tomahawk %1 or newer is required." )
  200 + .arg( requiredVer ) ) );
  201 + return 0;
  202 + }
  203 + }
  204 +
149 205 //TODO: handle multi-account resolvers
150 206
151 207 return new ResolverAccount( generateId( factory ), realPath, configuration );
@@ -187,6 +243,10 @@ ResolverAccountFactory::metadataFromJsonFile( const QString& path )
187 243 result[ "revision" ] = variant[ "revision" ];
188 244 if ( !variant[ "timestamp" ].isNull() )
189 245 result[ "timestamp" ] = variant[ "timestamp" ];
  246 + if ( !variant[ "tomahawkVersion" ].isNull() )
  247 + result[ "tomahawkVersion" ] = variant[ "tomahawkVersion" ];
  248 + if ( !variant[ "platform" ].isNull() )
  249 + result[ "platform" ] = variant[ "platform" ];
190 250 }
191 251 }
192 252 return result;
48 src/libtomahawk/utils/TomahawkUtils.cpp
@@ -45,6 +45,7 @@
45 45 #include <QMutex>
46 46 #include <QCryptographicHash>
47 47 #include <QProcess>
  48 +#include <QStringList>
48 49 #include <QTranslator>
49 50
50 51 #if QT_VERSION >= QT_VERSION_CHECK( 5, 0, 0 )
@@ -1013,6 +1014,53 @@ whitelistedHttpResultHint( const QString& url )
1013 1014 }
1014 1015
1015 1016
  1017 +int
  1018 +compareVersionStrings( const QString& first, const QString& second )
  1019 +{
  1020 + QStringList a = first.split( '.', QString::SkipEmptyParts );
  1021 + QStringList b = second.split( '.', QString::SkipEmptyParts );
  1022 +
  1023 + const int depth = qMax( a.count(), b.count() );
  1024 +
  1025 + while ( a.count() < depth )
  1026 + a.append( "0" );
  1027 +
  1028 + while ( b.count() < depth )
  1029 + b.append( "0" );
  1030 +
  1031 + int verdict = 0;
  1032 + for ( int i = 0; i < depth; ++i )
  1033 + {
  1034 + bool aOk;
  1035 + int aNumber = a.at( i ).toInt( &aOk );
  1036 + bool bOk;
  1037 + int bNumber = b.at( i ).toInt( &bOk );
  1038 +
  1039 + if ( aOk && bOk )
  1040 + {
  1041 + if ( aNumber < bNumber )
  1042 + {
  1043 + verdict = -1;
  1044 + break;
  1045 + }
  1046 + if ( aNumber > bNumber )
  1047 + {
  1048 + verdict = 1;
  1049 + break;
  1050 + }
  1051 + }
  1052 + else //fallback: string comparison
  1053 + {
  1054 + verdict = a.at( i ).compare( b.at( i ) );
  1055 + if ( verdict != 0 )
  1056 + break;
  1057 + }
  1058 + }
  1059 +
  1060 + return verdict;
  1061 +}
  1062 +
  1063 +
1016 1064 void
1017 1065 urlAddQueryItem( QUrl& url, const QString& key, const QString& value )
1018 1066 {
2  src/libtomahawk/utils/TomahawkUtils.h
@@ -206,6 +206,8 @@ namespace TomahawkUtils
206 206
207 207 DLLEXPORT bool whitelistedHttpResultHint( const QString& url );
208 208
  209 + DLLEXPORT int compareVersionStrings( const QString& first, const QString& second );
  210 +
209 211 /**
210 212 * This helper is designed to help "update" an existing playlist with a newer revision of itself.
211 213 * To avoid re-loading the whole playlist and re-resolving tracks that are the same in the old playlist,

0 comments on commit 8285857

Please sign in to comment.
Something went wrong with that request. Please try again.