Simplify KICAD6_TEMPLATE_DIR default

The search_stack method is bugland

Fix https://gitlab.com/kicad/code/kicad/-/issues/10119
This commit is contained in:
Marek Roszko 2022-02-21 12:21:20 -05:00
parent e35c3f2b99
commit ad251b7b8c
3 changed files with 16 additions and 38 deletions

View File

@ -239,6 +239,16 @@ wxString PATHS::GetStockScriptingPath()
}
wxString PATHS::GetStockTemplatesPath()
{
wxString path;
path = GetStockDataPath() + wxT( "/template" );
return path;
}
wxString PATHS::GetStockPluginsPath()
{
wxFileName fn;

View File

@ -514,44 +514,7 @@ void COMMON_SETTINGS::InitializeEnvironment()
path.AppendDir( wxT( "3dmodels" ) );
addVar( wxT( "KICAD6_3DMODEL_DIR" ), path.GetFullPath() );
// We don't have just one default template path, so use this logic that originally was in
// PGM_BASE::InitPgm to determine the best default template path
{
// Attempt to find the best default template path.
SEARCH_STACK bases;
SEARCH_STACK templatePaths;
SystemDirsAppend( &bases );
for( unsigned i = 0; i < bases.GetCount(); ++i )
{
wxFileName fn( bases[i], wxEmptyString );
// Add KiCad template file path to search path list.
fn.AppendDir( "template" );
// Only add path if exists and can be read by the user.
if( fn.DirExists() && fn.IsDirReadable() )
{
wxLogTrace( tracePathsAndFiles, "Checking template path '%s' exists",
fn.GetPath() );
templatePaths.AddPaths( fn.GetPath() );
}
}
if( templatePaths.IsEmpty() )
{
path = basePath;
path.AppendDir( "template" );
}
else
{
// Take the first one. There may be more but this will likely be the best option.
path.AssignDir( templatePaths[0] );
}
addVar( wxT( "KICAD6_TEMPLATE_DIR" ), path.GetFullPath() );
}
addVar( wxT( "KICAD6_TEMPLATE_DIR" ), PATHS::GetStockTemplatesPath() );
addVar( wxT( "KICAD_USER_TEMPLATE_DIR" ), PATHS::GetUserTemplatesPath() );

View File

@ -121,6 +121,11 @@ public:
*/
static wxString GetStockDemosPath();
/**
* Gets the stock (install) templates path
*/
static wxString GetStockTemplatesPath();
/**
* Gets the stock (install) 3d viewer plugins path
*/