From 944a3d7962a1f17cbe6fd0e4f43b1f5999b5d409 Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Wed, 14 Feb 2024 16:58:39 -0500 Subject: [PATCH] Transparently support old versioned env vars for symbol and footprint libs --- common/common.cpp | 49 +++++++++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/common/common.cpp b/common/common.cpp index 4a23b2ca15..cbe636b03d 100644 --- a/common/common.cpp +++ b/common/common.cpp @@ -147,6 +147,25 @@ wxString KIwxExpandEnvVars( const wxString& str, const PROJECT* aProject, std::s wxString strResult; strResult.Alloc( strlen ); // best guess (improves performance) + auto getVersionedEnvVar = []( const wxString& aMatch, wxString& aResult ) -> bool + { + for ( const wxString& var : ENV_VAR::GetPredefinedEnvVars() ) + { + if( var.Matches( aMatch ) ) + { + const auto value = ENV_VAR::GetEnvVar( var ); + + if( !value ) + continue; + + aResult += *value; + return true; + } + } + + return false; + }; + for( size_t n = 0; n < strlen; n++ ) { wxUniChar str_n = str[n]; @@ -222,26 +241,24 @@ wxString KIwxExpandEnvVars( const wxString& str, const PROJECT* aProject, std::s strResult += tmp; expanded = true; } - // Replace unmatched older variables with current 3d model locations - // If the user has the older model location defined, that will be matched + // Replace unmatched older variables with current locations + // If the user has the older location defined, that will be matched // first above. But if they do not, this will ensure that their board still // displays correctly else if( strVarName.Contains( "KISYS3DMOD") || strVarName.Matches( "KICAD*_3DMODEL_DIR" ) ) { - for( auto& var : ENV_VAR::GetPredefinedEnvVars() ) - { - if( var.Matches( "KICAD*_3DMODEL_DIR" ) ) - { - const auto value = ENV_VAR::GetEnvVar( var ); - - if( !value ) - continue; - - strResult += *value; - expanded = true; - break; - } - } + if( getVersionedEnvVar( "KICAD*_3DMODEL_DIR", strResult ) ) + expanded = true; + } + else if( strVarName.Matches( "KICAD*_SYMBOL_DIR" ) ) + { + if( getVersionedEnvVar( "KICAD*_SYMBOL_DIR", strResult ) ) + expanded = true; + } + else if( strVarName.Matches( "KICAD*_FOOTPRINT_DIR" ) ) + { + if( getVersionedEnvVar( "KICAD*_FOOTPRINT_DIR", strResult ) ) + expanded = true; } else {