mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-06 14:16:32 +02:00
Merge pull request #58 from rotzbouw/master
Enhance resolver version comparison to a third point
This commit is contained in:
@@ -286,46 +286,50 @@ AtticaManager::syncServerData()
|
|||||||
bool
|
bool
|
||||||
AtticaManager::newerVersion( const QString& older, const QString& newer ) const
|
AtticaManager::newerVersion( const QString& older, const QString& newer ) const
|
||||||
{
|
{
|
||||||
// Dumb version comparison. Expects two strings, X.Y and Z.V. Returns true if Z > v || Z == V && V > Y
|
// Version comparison: turns X.Y.Z into XYZ (adding 0 to X.Y. and 00 to X respectively)
|
||||||
// DOES NOT support X.Y.Z version strings
|
|
||||||
if ( older.isEmpty() || newer.isEmpty() )
|
if ( older.isEmpty() || newer.isEmpty() )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
QPair<int, int> oldVer, newVer;
|
QString oldDigits = older;
|
||||||
QStringList parts = older.split( "." );
|
oldDigits = oldDigits.replace( ".", "" );
|
||||||
|
int oldDigitsInt;
|
||||||
|
|
||||||
if ( parts.size() == 1 )
|
if ( oldDigits.size() == 1 )
|
||||||
{
|
{
|
||||||
oldVer.first = parts[ 0 ].toInt();
|
oldDigitsInt = oldDigits.append("00").toInt();
|
||||||
oldVer.second = 0;
|
|
||||||
}
|
}
|
||||||
else if ( parts.size() == 2 )
|
else if ( oldDigits.size() == 2 )
|
||||||
{
|
{
|
||||||
oldVer.first = parts[ 0 ].toInt();
|
oldDigitsInt = oldDigits.append("0").toInt();
|
||||||
oldVer.second = parts[ 1 ].toInt();;
|
}
|
||||||
|
else if ( oldDigits.size() == 3 )
|
||||||
|
{
|
||||||
|
oldDigitsInt = oldDigits.toInt();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
parts = newer.split( "." );
|
QString newDigits = newer;
|
||||||
if ( parts.size() == 1 )
|
newDigits = newDigits.replace( ".", "");
|
||||||
|
int newDigitsInt;
|
||||||
|
|
||||||
|
if ( newDigits.size() == 1 )
|
||||||
{
|
{
|
||||||
newVer.first = parts[ 0 ].toInt();
|
newDigitsInt = newDigits.append("00").toInt();
|
||||||
newVer.second = 0;
|
|
||||||
}
|
}
|
||||||
else if ( parts.size() == 2 )
|
else if ( newDigits.size() == 2 )
|
||||||
{
|
{
|
||||||
newVer.first = parts[ 0 ].toInt();
|
newDigitsInt = newDigits.append("0").toInt();
|
||||||
newVer.second = parts[ 1 ].toInt();;
|
}
|
||||||
|
else if ( newDigits.size() == 3 )
|
||||||
|
{
|
||||||
|
newDigitsInt = newDigits.toInt();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Do the comparison
|
// Do the comparison
|
||||||
if ( newVer.first > oldVer.first )
|
if ( newDigitsInt > oldDigitsInt )
|
||||||
return true;
|
|
||||||
if ( newVer.first == oldVer.first &&
|
|
||||||
newVer.second > oldVer.second )
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
Reference in New Issue
Block a user