Skip to content

Commit c8433b6

Browse files
authored
Merge pull request #3855 from pljones/update-notification-for-old-devs
Use mapped version for update notification check
2 parents c27bd61 + eb3ce27 commit c8433b6

5 files changed

Lines changed: 101 additions & 65 deletions

File tree

‎src/clientdlg.cpp‎

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -855,18 +855,19 @@ void CClientDlg::OnCLVersionAndOSReceived ( CHostAddress InetAddr, COSUtil::EOpS
855855
{
856856
// update check
857857
#if ( QT_VERSION >= QT_VERSION_CHECK( 5, 6, 0 ) ) && !defined( DISABLE_VERSION_CHECK )
858-
int mySuffixIndex;
859-
QVersionNumber myVersion = QVersionNumber::fromString ( VERSION, &mySuffixIndex );
858+
const QString mappedServerVersion = MapVersionStrForCompare ( strVersion );
860859

861-
int serverSuffixIndex;
862-
QVersionNumber serverVersion = QVersionNumber::fromString ( strVersion, &serverSuffixIndex );
863-
864-
// only compare if the server version has no suffix (such as dev or beta)
865-
if ( strVersion.size() == serverSuffixIndex && QVersionNumber::compare ( serverVersion, myVersion ) > 0 )
860+
// Ignore non-release remote versions when deciding whether to notify.
861+
if ( IsMappedReleaseVersion ( mappedServerVersion ) )
866862
{
867-
// show the label and hide it after one minute again
868-
lblUpdateCheck->show();
869-
QTimer::singleShot ( 60000, this, [this]() { lblUpdateCheck->hide(); } );
863+
const QString mappedCurrentVersion = MapVersionStrForCompare ( VERSION );
864+
865+
if ( mappedServerVersion.compare ( mappedCurrentVersion ) > 0 )
866+
{
867+
// show the label and hide it after one minute again
868+
lblUpdateCheck->show();
869+
QTimer::singleShot ( 60000, this, [this]() { lblUpdateCheck->hide(); } );
870+
}
870871
}
871872
#endif
872873
}

‎src/connectdlg.cpp‎

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -53,52 +53,6 @@
5353

5454
/* Implementation *************************************************************/
5555

56-
// mapVersionStr - converts a version number to a sortable string
57-
static QString mapVersionStr ( const QString& versionStr )
58-
{
59-
QString key;
60-
QString x = ">"; // default suffix is later (git, dev, nightly, etc)
61-
62-
// Regex for SemVer: major.minor.patch-suffix
63-
QRegularExpression semVerRegex ( R"(^(\d+)\.(\d+)\.(\d+)-?(.*):?(.*)$)" );
64-
QRegularExpressionMatch match = semVerRegex.match ( versionStr );
65-
66-
if ( !match.hasMatch() )
67-
{
68-
return versionStr; // fallback: plain text
69-
}
70-
71-
int major = match.captured ( 1 ).toInt();
72-
int minor = match.captured ( 2 ).toInt();
73-
int patch = match.captured ( 3 ).toInt();
74-
QString suffix = match.captured ( 4 ); // may be empty
75-
QString tstamp = match.captured ( 5 ); // may be empty
76-
77-
if ( suffix.isEmpty() )
78-
{
79-
x = "="; // bare version number
80-
}
81-
else if ( suffix.startsWith ( "rc" ) || suffix.startsWith ( "beta" ) || suffix.startsWith ( "alpha" ) )
82-
{
83-
x = "<"; // pre-release version
84-
}
85-
86-
// construct a sortable key mmmnnnpppksuffix, where:
87-
// mmm = major
88-
// nnn = minor
89-
// ppp = patch
90-
// k = sort key to sort alpha, beta, rc before bare version number, and other suffixes after (<, =, >)
91-
// suffix = supplied suffix
92-
key = QString ( "%1%2%3%4%5" )
93-
.arg ( major, 3, 10, QLatin1Char ( '0' ) )
94-
.arg ( minor, 3, 10, QLatin1Char ( '0' ) )
95-
.arg ( patch, 3, 10, QLatin1Char ( '0' ) )
96-
.arg ( x )
97-
.arg ( tstamp.isEmpty() ? suffix : tstamp );
98-
99-
return key;
100-
}
101-
10256
// Subclass of QTreeWidgetItem that allows LVC_VERSION to sort by the UserRole data value
10357
CMappedTreeWidgetItem::CMappedTreeWidgetItem ( QTreeWidget* owner ) : QTreeWidgetItem ( owner ), owner ( owner ) {}
10458

@@ -1078,7 +1032,7 @@ void CConnectDlg::SetServerVersionResult ( const CHostAddress& InetAddr, const Q
10781032
pCurListViewItem->setText ( LVC_VERSION, GetDisplayVersion ( strVersion ) );
10791033

10801034
// and store sortable mapped version number
1081-
pCurListViewItem->setData ( LVC_VERSION, Qt::UserRole, mapVersionStr ( strVersion ) );
1035+
pCurListViewItem->setData ( LVC_VERSION, Qt::UserRole, MapVersionStrForCompare ( strVersion ) );
10821036

10831037
if ( pCurListViewItem == lvwServers->currentItem() )
10841038
{

‎src/serverdlg.cpp‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -689,16 +689,17 @@ void CServerDlg::OnCLVersionAndOSReceived ( CHostAddress, COSUtil::EOpSystemType
689689
{
690690
// update check
691691
#if QT_VERSION >= QT_VERSION_CHECK( 5, 6, 0 )
692-
int mySuffixIndex;
693-
QVersionNumber myVersion = QVersionNumber::fromString ( VERSION, &mySuffixIndex );
692+
const QString mappedServerVersion = MapVersionStrForCompare ( strVersion );
694693

695-
int serverSuffixIndex;
696-
QVersionNumber serverVersion = QVersionNumber::fromString ( strVersion, &serverSuffixIndex );
697-
698-
// only compare if the server version has no suffix (such as dev or beta)
699-
if ( strVersion.size() == serverSuffixIndex && QVersionNumber::compare ( serverVersion, myVersion ) > 0 )
694+
// Ignore non-release remote versions when deciding whether to notify.
695+
if ( IsMappedReleaseVersion ( mappedServerVersion ) )
700696
{
701-
lblUpdateCheck->show();
697+
const QString mappedCurrentVersion = MapVersionStrForCompare ( VERSION );
698+
699+
if ( mappedServerVersion.compare ( mappedCurrentVersion ) > 0 )
700+
{
701+
lblUpdateCheck->show();
702+
}
702703
}
703704
#endif
704705
}

‎src/util.cpp‎

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,84 @@
4646

4747
#include "util.h"
4848

49+
namespace
50+
{
51+
// Capture layout:
52+
// (1)=major, (2)=minor, (3)=patch,
53+
// (4)=suffix (may include dev-<sha>), (5)=timestamp.
54+
// Examples:
55+
// 3.10.1 -> (3,10,1,"","")
56+
// 3.10.1dev-2f2d2a1:1756656363 -> (3,10,1,"dev-2f2d2a1","1756656363")
57+
// 3.10.1dev-2f2d2a1 -> (3,10,1,"dev-2f2d2a1","")
58+
// 3.10.2rc1 -> (3,10,2,"rc1","")
59+
// v3.10.1 -> no match
60+
const QRegularExpression& GetSemVerRegex()
61+
{
62+
static const QRegularExpression semVerRegex ( R"(^(\d+)\.(\d+)\.(\d+)-?([^:]*):?(.*)$)" );
63+
return semVerRegex;
64+
}
65+
} // namespace
66+
67+
bool IsMappedReleaseVersion ( const QString& mappedVersion )
68+
{
69+
// Mapped release keys are exactly "mmmnnnppp=" and contain no dot placeholders.
70+
return ( mappedVersion.size() == 10 ) && ( mappedVersion.at ( 9 ) == QLatin1Char ( '=' ) ) && ( !mappedVersion.contains ( QLatin1Char ( '.' ) ) );
71+
}
72+
73+
QString MapVersionStrForCompare ( const QString& versionStr )
74+
{
75+
QString key;
76+
QString x = ">"; // default suffix is later (git, dev, nightly, etc)
77+
78+
// Build a lexicographically sortable key from regex captures so ordering is:
79+
// pre-release (alpha/beta/rc) < release (x.y.z) < post-release/dev/homebrew.
80+
// If capture (5) timestamp exists, it is used as the tie-break payload.
81+
QRegularExpressionMatch match = GetSemVerRegex().match ( versionStr );
82+
83+
if ( !match.hasMatch() )
84+
{
85+
return QString ( "..." ) + versionStr;
86+
}
87+
88+
bool majorOk = false;
89+
bool minorOk = false;
90+
bool patchOk = false;
91+
int major = match.captured ( 1 ).toInt ( &majorOk );
92+
int minor = match.captured ( 2 ).toInt ( &minorOk );
93+
int patch = match.captured ( 3 ).toInt ( &patchOk );
94+
95+
if ( !majorOk || !minorOk || !patchOk )
96+
{
97+
return QString ( "..." ) + versionStr;
98+
}
99+
100+
QString suffix = match.captured ( 4 ); // suffix, if present
101+
QString tstamp = match.captured ( 5 ); // timestamp, if present
102+
103+
if ( suffix.isEmpty() )
104+
{
105+
x = "="; // bare version number
106+
}
107+
else if ( suffix.startsWith ( "rc" ) || suffix.startsWith ( "beta" ) || suffix.startsWith ( "alpha" ) )
108+
{
109+
x = "<"; // pre-release version
110+
}
111+
112+
// construct a sortable key mmmnnnpppksuffix, where:
113+
// mmm = major
114+
// nnn = minor
115+
// ppp = patch
116+
// k = sort key to sort alpha, beta, rc before bare version number, and other suffixes after (<, =, >)
117+
// suffix = supplied suffix
118+
const QString majorPart = QString ( "%1" ).arg ( major, 3, 10, QLatin1Char ( '0' ) );
119+
const QString minorPart = QString ( "%1" ).arg ( minor, 3, 10, QLatin1Char ( '0' ) );
120+
const QString patchPart = QString ( "%1" ).arg ( patch, 3, 10, QLatin1Char ( '0' ) );
121+
122+
key = QString ( "%1%2%3%4%5" ).arg ( majorPart ).arg ( minorPart ).arg ( patchPart ).arg ( x ).arg ( tstamp.isEmpty() ? suffix : tstamp );
123+
124+
return key;
125+
}
126+
49127
/* Implementation *************************************************************/
50128
// Input level meter implementation --------------------------------------------
51129
void CStereoSignalLevelMeter::Update ( const CVector<short>& vecsAudio, const int iMonoBlockSizeSam, const bool bIsStereoIn )

‎src/util.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ inline int CalcBitRateBitsPerSecFromCodedBytes ( const int iCeltNumCodedBytes, c
138138

139139
QString GetVersionAndNameStr ( const bool bDisplayInGui = true );
140140
QString MakeClientNameTitle ( QString win, QString client );
141+
bool IsMappedReleaseVersion ( const QString& mappedVersion );
142+
QString MapVersionStrForCompare ( const QString& versionStr );
141143
QString TruncateString ( QString str, int position );
142144

143145
/******************************************************************************\

0 commit comments

Comments
 (0)