From ad251b7b8c86ea3c0153fe823c3716db3f6d63ed Mon Sep 17 00:00:00 2001 From: Marek Roszko Date: Mon, 21 Feb 2022 12:21:20 -0500 Subject: [PATCH] Simplify KICAD6_TEMPLATE_DIR default The search_stack method is bugland Fix https://gitlab.com/kicad/code/kicad/-/issues/10119 --- common/paths.cpp | 10 ++++++++ common/settings/common_settings.cpp | 39 +---------------------------- include/paths.h | 5 ++++ 3 files changed, 16 insertions(+), 38 deletions(-) diff --git a/common/paths.cpp b/common/paths.cpp index c2e37a557e..cd46f2a6c5 100644 --- a/common/paths.cpp +++ b/common/paths.cpp @@ -239,6 +239,16 @@ wxString PATHS::GetStockScriptingPath() } +wxString PATHS::GetStockTemplatesPath() +{ + wxString path; + + path = GetStockDataPath() + wxT( "/template" ); + + return path; +} + + wxString PATHS::GetStockPluginsPath() { wxFileName fn; diff --git a/common/settings/common_settings.cpp b/common/settings/common_settings.cpp index 9a621773df..c4e525ae64 100644 --- a/common/settings/common_settings.cpp +++ b/common/settings/common_settings.cpp @@ -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() ); diff --git a/include/paths.h b/include/paths.h index 4a2c72404e..25e2a0510f 100644 --- a/include/paths.h +++ b/include/paths.h @@ -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 */