Fix the download compareVersions to.

Signed-off-by: Adam Treat <treat.adam@gmail.com>
This commit is contained in:
Adam Treat 2024-07-28 11:30:48 -04:00
parent b4dc7deec1
commit 96526f3635

View File

@ -62,17 +62,24 @@ static bool operator==(const ReleaseInfo& lhs, const ReleaseInfo& rhs)
static bool compareVersions(const QString &a, const QString &b) static bool compareVersions(const QString &a, const QString &b)
{ {
QRegularExpression regex("(\\d+)");
QStringList aParts = a.split('.'); QStringList aParts = a.split('.');
QStringList bParts = b.split('.'); QStringList bParts = b.split('.');
Q_ASSERT(aParts.size() == 3);
Q_ASSERT(bParts.size() == 3);
for (int i = 0; i < std::min(aParts.size(), bParts.size()); ++i) { for (int i = 0; i < std::min(aParts.size(), bParts.size()); ++i) {
int aInt = aParts[i].toInt(); QRegularExpressionMatch aMatch = regex.match(aParts[i]);
int bInt = bParts[i].toInt(); QRegularExpressionMatch bMatch = regex.match(bParts[i]);
Q_ASSERT(aMatch.hasMatch() && bMatch.hasMatch());
if (aInt > bInt) { if (aMatch.hasMatch() && bMatch.hasMatch()) {
return true; int aInt = aMatch.captured(1).toInt();
} else if (aInt < bInt) { int bInt = bMatch.captured(1).toInt();
return false; if (aInt > bInt) {
return true;
} else if (aInt < bInt) {
return false;
}
} }
} }