From 1e61668ceedf1e95d24f080437b615b6c8ddd07f Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Sat, 7 Mar 2020 09:33:35 -0500 Subject: [PATCH] Make GetSettingsVersion handle extra version appends better Fixes #4015 --- common/settings/settings_manager.cpp | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/common/settings/settings_manager.cpp b/common/settings/settings_manager.cpp index 2dca095094..a532719466 100644 --- a/common/settings/settings_manager.cpp +++ b/common/settings/settings_manager.cpp @@ -567,13 +567,35 @@ std::string SETTINGS_MANAGER::calculateUserSettingsPath( bool aIncludeVer, bool std::string SETTINGS_MANAGER::GetSettingsVersion() { - wxString version = GetBuildVersion().BeforeLast( '.' ); - // A full build version looks like (x.y.z-nnn-g1234567) or x.y.z-xxx + // The string after the major.minor.patch can contain all sorts of other information // We want to extract the x.y portion here + wxString version = GetBuildVersion(); + if( version.StartsWith( '(' ) ) version = version.Mid( 1 ); + // Trim everything starting from the second '.' + + size_t mid = 0; + int found = 0; + + while( found < 2 && mid < version.size() ) + { + if( version[mid] == '.' ) + found++; + + if( found == 2 ) + { + version = version.SubString( 0, mid - 1 ); + break; + } + + mid++; + } + + wxASSERT( version.Find( '.' ) != wxNOT_FOUND ); + return version.ToStdString(); }