Prefer later versions in import of previous settings

This commit is contained in:
Alex 2023-01-08 00:24:14 +05:00
parent c5ef51d688
commit 53dedb2c99
2 changed files with 25 additions and 3 deletions

View File

@ -663,6 +663,21 @@ bool SETTINGS_MANAGER::GetPreviousVersionPaths( std::vector<wxString>* aPaths )
}
}
std::sort( aPaths->begin(), aPaths->end(),
[&]( const wxString& a, const wxString& b ) -> bool
{
wxString verA = wxFileName::DirName( a ).GetDirs().back();
wxString verB = wxFileName::DirName( b ).GetDirs().back();
if( !extractVersion( verA.ToStdString() )
|| !extractVersion( verB.ToStdString() ) )
{
return false;
}
return compareVersions( verA.ToStdString(), verB.ToStdString() ) >= 0;
} );
return aPaths->size() > 0;
}
@ -793,8 +808,14 @@ bool SETTINGS_MANAGER::extractVersion( const std::string& aVersionString, int* a
{
try
{
*aMajor = std::stoi( match[1].str() );
*aMinor = std::stoi( match[2].str() );
int major = std::stoi( match[1].str() );
int minor = std::stoi( match[2].str() );
if( aMajor )
*aMajor = major;
if( aMinor )
*aMinor = minor;
}
catch( ... )
{

View File

@ -385,7 +385,8 @@ private:
* @param aMinor will store the second part
* @return true if extraction succeeded
*/
static bool extractVersion( const std::string& aVersionString, int* aMajor, int* aMinor );
static bool extractVersion( const std::string& aVersionString, int* aMajor = nullptr,
int* aMinor = nullptr );
/**
* Attempts to load a color theme by name (the color theme directory and .json ext are assumed)