2018-09-28 21:08:31 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2021-06-30 21:28:46 +00:00
|
|
|
* Copyright (C) 2018-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
2018-09-28 21:08:31 +00:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation, either version 3 of the License, or (at your
|
|
|
|
* option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <env_vars.h>
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
|
2020-10-24 00:50:09 +00:00
|
|
|
#include <wx/translation.h>
|
2019-03-22 21:15:26 +00:00
|
|
|
#include <wx/utils.h>
|
|
|
|
|
2018-09-28 21:08:31 +00:00
|
|
|
using STRING_MAP = std::map<wxString, wxString>;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* List of pre-defined environment variables
|
|
|
|
*
|
|
|
|
* TODO - Instead of defining these values here,
|
|
|
|
* extract them from elsewhere in the program
|
|
|
|
* (where they are originally defined)
|
|
|
|
*/
|
2021-06-22 00:35:11 +00:00
|
|
|
static const ENV_VAR::ENV_VAR_LIST predefinedEnvVars = {
|
2018-09-28 21:08:31 +00:00
|
|
|
"KIPRJMOD",
|
2020-12-31 21:22:44 +00:00
|
|
|
"KICAD6_SYMBOL_DIR",
|
|
|
|
"KICAD6_3DMODEL_DIR",
|
|
|
|
"KICAD6_FOOTPRINT_DIR",
|
|
|
|
"KICAD6_TEMPLATE_DIR",
|
2018-09-28 21:08:31 +00:00
|
|
|
"KICAD_USER_TEMPLATE_DIR",
|
|
|
|
"KICAD_PTEMPLATES",
|
2020-12-08 18:39:45 +00:00
|
|
|
"KICAD6_3RD_PARTY",
|
2018-09-28 21:08:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2021-06-22 00:35:11 +00:00
|
|
|
bool ENV_VAR::IsEnvVarImmutable( const wxString& aEnvVar )
|
2018-09-28 21:08:31 +00:00
|
|
|
{
|
2021-06-22 00:35:11 +00:00
|
|
|
for( const auto& s : predefinedEnvVars )
|
2018-09-28 21:08:31 +00:00
|
|
|
{
|
|
|
|
if( s == aEnvVar )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-22 00:35:11 +00:00
|
|
|
const ENV_VAR::ENV_VAR_LIST& ENV_VAR::GetPredefinedEnvVars()
|
2018-09-28 21:08:31 +00:00
|
|
|
{
|
2021-06-22 00:35:11 +00:00
|
|
|
return predefinedEnvVars;
|
2018-09-28 21:08:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-22 00:35:11 +00:00
|
|
|
static void initialiseEnvVarHelp( STRING_MAP& aMap )
|
2018-09-28 21:08:31 +00:00
|
|
|
{
|
|
|
|
// Set up dynamically, as we want to be able to use _() translations,
|
|
|
|
// which can't be done statically
|
2020-12-31 21:22:44 +00:00
|
|
|
aMap["KICAD6_FOOTPRINT_DIR"] =
|
2018-09-28 21:08:31 +00:00
|
|
|
_( "The base path of locally installed system "
|
|
|
|
"footprint libraries (.pretty folders).");
|
2020-12-31 21:22:44 +00:00
|
|
|
aMap["KICAD6_3DMODEL_DIR"] =
|
2018-09-28 21:08:31 +00:00
|
|
|
_( "The base path of system footprint 3D shapes (.3Dshapes folders).");
|
2020-12-31 21:22:44 +00:00
|
|
|
aMap["KICAD6_SYMBOL_DIR"] =
|
2018-09-28 21:08:31 +00:00
|
|
|
_( "The base path of the locally installed symbol libraries.");
|
2020-12-31 21:22:44 +00:00
|
|
|
aMap["KICAD6_TEMPLATE_DIR"] =
|
2018-09-28 21:08:31 +00:00
|
|
|
_( "A directory containing project templates installed with KiCad.");
|
|
|
|
aMap["KICAD_USER_TEMPLATE_DIR"] =
|
|
|
|
_( "Optional. Can be defined if you want to create your own project "
|
|
|
|
"templates folder.");
|
2020-12-08 18:39:45 +00:00
|
|
|
aMap["KICAD6_3RD_PARTY"] =
|
|
|
|
_( "A directory containing 3rd party plugins, libraries and other "
|
|
|
|
"downloadable content.");
|
2018-09-28 21:08:31 +00:00
|
|
|
aMap["KIPRJMOD"] =
|
|
|
|
_("Internally defined by KiCad (cannot be edited) and is set "
|
|
|
|
"to the absolute path of the currently loaded project file. This environment "
|
|
|
|
"variable can be used to define files and paths relative to the currently loaded "
|
|
|
|
"project. For instance, ${KIPRJMOD}/libs/footprints.pretty can be defined as a "
|
|
|
|
"folder containing a project specific footprint library named footprints.pretty." );
|
2020-12-31 21:22:44 +00:00
|
|
|
aMap["KICAD6_SCRIPTING_DIR"] =
|
|
|
|
_( "A directory containing system-wide scripts installed with KiCad" );
|
|
|
|
aMap["KICAD6_USER_SCRIPTING_DIR"] =
|
|
|
|
_( "A directory containing user-specific scripts installed with KiCad" );
|
2018-09-28 21:08:31 +00:00
|
|
|
|
|
|
|
// Deprecated vars
|
|
|
|
aMap["KICAD_PTEMPLATES"] =
|
|
|
|
_( "Deprecated version of KICAD_TEMPLATE_DIR.");
|
2020-12-31 21:22:44 +00:00
|
|
|
aMap["KISYS3DMOD"] =
|
|
|
|
_( "Deprecated version of KICAD6_3DMODEL_DIR." );
|
|
|
|
aMap["KISYSMOD"] =
|
|
|
|
_( "Deprecated version of KICAD6_FOOTPRINT_DIR." );
|
|
|
|
aMap["KICAD_SYMBOL_DIR"] =
|
|
|
|
_( "Deprecated version of KICAD_SYMBOL_DIR.");
|
2018-09-28 21:08:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-22 00:35:11 +00:00
|
|
|
wxString ENV_VAR::LookUpEnvVarHelp( const wxString& aEnvVar )
|
2018-09-28 21:08:31 +00:00
|
|
|
{
|
2021-06-22 00:35:11 +00:00
|
|
|
static STRING_MAP envVarHelpText;
|
2018-09-28 21:08:31 +00:00
|
|
|
|
2021-06-22 00:35:11 +00:00
|
|
|
if( envVarHelpText.size() == 0 )
|
|
|
|
initialiseEnvVarHelp( envVarHelpText );
|
2018-09-28 21:08:31 +00:00
|
|
|
|
2021-06-22 00:35:11 +00:00
|
|
|
return envVarHelpText[ aEnvVar ];
|
2019-03-22 21:15:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<>
|
2021-06-22 00:35:11 +00:00
|
|
|
OPT<double> ENV_VAR::GetEnvVar( const wxString& aEnvVarName )
|
2019-03-22 21:15:26 +00:00
|
|
|
{
|
|
|
|
wxString env;
|
2021-06-30 21:28:46 +00:00
|
|
|
|
2019-03-22 21:15:26 +00:00
|
|
|
if( wxGetEnv( aEnvVarName, &env ) )
|
|
|
|
{
|
|
|
|
double value;
|
2021-06-30 21:28:46 +00:00
|
|
|
|
2019-03-22 21:15:26 +00:00
|
|
|
if( env.ToDouble( &value ) )
|
2021-07-06 17:32:34 +00:00
|
|
|
return value;
|
2019-03-22 21:15:26 +00:00
|
|
|
}
|
|
|
|
|
2021-07-06 17:32:34 +00:00
|
|
|
return NULLOPT;
|
2019-03-22 21:15:26 +00:00
|
|
|
}
|
|
|
|
|
2021-06-30 21:28:46 +00:00
|
|
|
|
2019-03-22 21:15:26 +00:00
|
|
|
template<>
|
2021-06-22 00:35:11 +00:00
|
|
|
OPT<wxString> ENV_VAR::GetEnvVar( const wxString& aEnvVarName )
|
2019-03-22 21:15:26 +00:00
|
|
|
{
|
2021-06-22 00:35:11 +00:00
|
|
|
OPT<wxString> optValue;
|
2019-03-22 21:15:26 +00:00
|
|
|
|
|
|
|
wxString env;
|
2021-06-30 21:28:46 +00:00
|
|
|
|
2019-03-22 21:15:26 +00:00
|
|
|
if( wxGetEnv( aEnvVarName, &env ) )
|
|
|
|
{
|
2021-06-22 00:35:11 +00:00
|
|
|
optValue = env;
|
2019-03-22 21:15:26 +00:00
|
|
|
}
|
|
|
|
|
2021-06-22 00:35:11 +00:00
|
|
|
return optValue;
|
2020-10-29 23:43:34 +00:00
|
|
|
}
|