From 14327f37082e371c63cdb50126f1c3f07601bf62 Mon Sep 17 00:00:00 2001 From: Marek Roszko Date: Sat, 23 Jan 2021 10:46:48 -0500 Subject: [PATCH] Cleanup the 3d plugins paths a little bit --- 3d-viewer/3d_cache/3d_plugin_manager.cpp | 36 +++------------ common/paths.cpp | 58 ++++++++++++++++++++++++ include/paths.h | 4 ++ 3 files changed, 68 insertions(+), 30 deletions(-) diff --git a/3d-viewer/3d_cache/3d_plugin_manager.cpp b/3d-viewer/3d_cache/3d_plugin_manager.cpp index 27f37557dd..0ed6cb58d1 100644 --- a/3d-viewer/3d_cache/3d_plugin_manager.cpp +++ b/3d-viewer/3d_cache/3d_plugin_manager.cpp @@ -34,8 +34,9 @@ #include #include -#include "common.h" -#include "pgm_base.h" +#include +#include +#include #include "3d_plugin_dir.h" #include "3d_plugin_manager.h" #include "plugins/3d/3d_plugin.h" @@ -152,34 +153,12 @@ void S3D_PLUGIN_MANAGER::loadPlugins( void ) } #endif -#ifndef _WIN32 - // PLUGINDIR = CMAKE_INSTALL_FULL_LIBDIR path is the absolute path - // corresponding to the install path used for constructing KICAD_USER_PLUGIN - wxString tfname = wxString::FromUTF8Unchecked( PLUGINDIR ); - fn.Assign( tfname, "" ); - fn.AppendDir( "kicad" ); -#else - // on windows the plugins directory is within the executable's directory - fn.Assign( wxStandardPaths::Get().GetExecutablePath() ); -#endif - - fn.AppendDir( wxT( "plugins" ) ); - fn.AppendDir( wxT( "3d" ) ); - - // checks plugin directory relative to executable path + fn.AssignDir( PATHS::GetStockPlugins3DPath() ); checkPluginPath( std::string( fn.GetPathWithSep().ToUTF8() ), searchpaths ); // check for per-user third party plugins // note: GetUserDataDir() gives '.pcbnew' rather than '.kicad' since it uses the exe name; - fn.Assign( wxStandardPaths::Get().GetUserDataDir(), "" ); - fn.RemoveLastDir(); -#ifdef _WIN32 - fn.AppendDir( wxT( "kicad" ) ); -#else - fn.AppendDir( wxT( ".kicad" ) ); -#endif - fn.AppendDir( wxT( "plugins" ) ); - fn.AppendDir( wxT( "3d" ) ); + fn.AssignDir( PATHS::GetUserPlugins3DPath() ); checkPluginPath( fn.GetPathWithSep(), searchpaths ); #else @@ -191,10 +170,7 @@ void S3D_PLUGIN_MANAGER::loadPlugins( void ) checkPluginPath( GetOSXKicadMachineDataDir() + wxT( "/PlugIns/3d" ), searchpaths ); // (3) Bundle kicad.app/Contents/PlugIns/3d - fn.Assign( Pgm().GetExecutablePath() ); - fn.AppendDir( wxT( "Contents" ) ); - fn.AppendDir( wxT( "PlugIns" ) ); - fn.AppendDir( wxT( "3d" ) ); + fn.AssignDir( PATHS::GetStockPluginsPath() ); checkPluginPath( fn.GetPathWithSep(), searchpaths ); #endif diff --git a/common/paths.cpp b/common/paths.cpp index d6ae06c316..a9a4afd5cb 100644 --- a/common/paths.cpp +++ b/common/paths.cpp @@ -7,6 +7,30 @@ #include +wxString PATHS::GetUserPluginsPath() +{ + wxFileName tmp; + + tmp.AssignDir( KIPLATFORM::ENV::GetDocumentsDir() ); + tmp.AppendDir( "kicad" ); + tmp.AppendDir( SETTINGS_MANAGER::GetSettingsVersion() ); + tmp.AppendDir( "plugins" ); + + return tmp.GetFullPath(); +} + + +wxString PATHS::GetUserPlugins3DPath() +{ + wxFileName tmp; + + tmp.AssignDir( PATHS::GetUserPluginsPath() ); + tmp.AppendDir( "3d" ); + + return tmp.GetFullPath(); +} + + wxString PATHS::GetUserScriptingPath() { wxFileName tmp; @@ -68,4 +92,38 @@ wxString PATHS::GetStockScriptingPath() } return path; +} + + +wxString PATHS::GetStockPluginsPath() +{ + wxFileName fn; + +#if defined( __WXMAC__ ) + fn.Assign( Pgm().GetExecutablePath() ); + fn.AppendDir( wxT( "Contents" ) ); + fn.AppendDir( wxT( "PlugIns" ) ); +#elif defined( __WXMSW__ ) + fn.Assign( Pgm().GetExecutablePath() + wxT( "../plugins/" ) ); +#else + // PLUGINDIR = CMAKE_INSTALL_FULL_LIBDIR path is the absolute path + // corresponding to the install path used for constructing KICAD_USER_PLUGIN + wxString tfname = wxString::FromUTF8Unchecked( PLUGINDIR ); + fn.Assign( tfname, "" ); + fn.AppendDir( "kicad" ); + fn.AppendDir( wxT( "plugins" ) ); +#endif + + return fn.GetPathWithSep(); +} + + +wxString PATHS::GetStockPlugins3DPath() +{ + wxFileName fn; + + fn.Assign( PATHS::GetStockPluginsPath() ); + fn.AppendDir( "3d" ); + + return fn.GetPathWithSep(); } \ No newline at end of file diff --git a/include/paths.h b/include/paths.h index dfdc2d3ce7..6765d51e23 100644 --- a/include/paths.h +++ b/include/paths.h @@ -7,8 +7,12 @@ class PATHS public: static wxString GetUserScriptingPath(); static wxString GetUserTemplatesPath(); + static wxString GetUserPluginsPath(); + static wxString GetUserPlugins3DPath(); static wxString GetDefaultUserProjectsPath(); static wxString GetStockScriptingPath(); + static wxString GetStockPluginsPath(); + static wxString GetStockPlugins3DPath(); }; #endif \ No newline at end of file