21#include <wx/filename.h>
22#include <wx/stdpaths.h>
34#if defined( __WXMAC__ ) || defined( __WXMSW__ )
35#define KICAD_PATH_STR wxT( "KiCad" )
37#define KICAD_PATH_STR wxT( "kicad" )
45 if( wxGetEnv( wxT(
"KICAD_DOCUMENTS_HOME" ), &envPath ) )
46 aPath.AssignDir( envPath );
60 tmp.AppendDir( wxT(
"plugins" ) );
71 tmp.AppendDir( wxT(
"scripting" ) );
82 tmp.AppendDir( wxT(
"template" ) );
84 return tmp.GetPathWithSep();
93 tmp.AppendDir( wxT(
"symbols" ) );
104 tmp.AppendDir( wxT(
"footprints" ) );
106 return tmp.GetPath();
115 tmp.AppendDir( wxT(
"blocks" ) );
117 return tmp.GetPath();
126 tmp.AppendDir( wxT(
"3dmodels" ) );
128 return tmp.GetPath();
137 tmp.AppendDir( wxT(
"3rdparty" ) );
139 return tmp.GetPath();
148 tmp.AppendDir( wxT(
"projects" ) );
150 return tmp.GetPath();
166 const auto looksLikeBuildDir = [](
const wxFileName& aPath ) ->
bool
168 const wxDir schema_dir( aPath.GetPathWithSep() + wxT(
"schemas" ) );
170 if( !schema_dir.IsOpened() )
174 const bool found = schema_dir.GetFirst( &filename, wxT(
"*.json" ), wxDIR_FILES );
179 wxFileName fn = execPath;
183 while( fn.GetDirCount() > 0 && !looksLikeBuildDir( fn ) )
189 fn.GetDirCount() > 0,
190 wxString::Format( wxT(
"Could not find build root directory above %s" ), execPath ) );
200 if( aRespectRunFromBuildDir && wxGetEnv( wxT(
"KICAD_RUN_FROM_BUILD_DIR" ),
nullptr ) )
203#if defined( __WXMAC__ )
204 wxFileName fn = wxStandardPaths::Get().GetExecutablePath();
211#elif defined( __WXMSW__ )
212 path = getWindowsKiCadRoot();
217 else if( wxGetEnv( wxT(
"KICAD_STOCK_DATA_HOME" ), &
path ) && !
path.IsEmpty() )
223#if defined( __WXMAC__ )
224 path = GetOSXKicadDataDir();
225#elif defined( __WXMSW__ )
226 path = getWindowsKiCadRoot() + wxT(
"share/kicad" );
228 path = wxString::FromUTF8Unchecked( KICAD_DATA );
238wxString PATHS::GetWindowsBaseSharePath()
240 return getWindowsKiCadRoot() + wxT(
"share\\" );
250#if defined( __WXMAC__ )
251 path = GetOSXKicadMachineDataDir();
252#elif defined( __WXMSW__ )
255 path = wxString::FromUTF8Unchecked( KICAD_LIBRARY_DATA );
336#if defined( __WXMSW__ )
338 fn.AppendDir( wxT(
"scripting" ) );
342 fn.AppendDir( wxT(
"plugins" ) );
344 return fn.GetPathWithSep();
352#if defined( __WXMSW__ )
353 if( wxGetEnv( wxT(
"KICAD_RUN_FROM_BUILD_DIR" ),
nullptr ) )
355 fn.AssignDir( getWindowsKiCadRoot() );
362 fn.AppendDir( wxT(
"plugins" ) );
363#elif defined( __WXMAC__ )
364 fn.Assign( wxStandardPaths::Get().GetPluginsDir(), wxEmptyString );
367 const wxArrayString dirs = fn.GetDirs();
373 if( dirs.GetCount() >= 6 &&
374 dirs[dirs.GetCount() - 4] == wxT(
"Applications" ) &&
375 dirs[dirs.GetCount() - 6].Lower().EndsWith( wxT(
"app" ) ) )
381 fn.AppendDir( wxT(
"PlugIns" ) );
386 wxString tfname = wxString::FromUTF8Unchecked( KICAD_PLUGINDIR );
387 fn.Assign( tfname,
"" );
388 fn.AppendDir( wxT(
"kicad" ) );
389 fn.AppendDir( wxT(
"plugins" ) );
392 fn.AppendDir( wxT(
"3d" ) );
394 return fn.GetPathWithSep();
403 fn.AppendDir( wxT(
"demos" ) );
405 return fn.GetPathWithSep();
417 if( wxGetEnv( wxT(
"KICAD_CACHE_HOME" ), &envPath ) && !envPath.IsEmpty() )
420 tmp.AssignDir( envPath );
426 return tmp.GetPathWithSep();
434#if defined( __WXMAC__ )
435 path = GetOSXKicadDataDir();
436#elif defined( __WXMSW__ )
437 path = getWindowsKiCadRoot() + wxT(
"share/doc/kicad" );
439 path = wxString::FromUTF8Unchecked( KICAD_DOCS );
449 path.AssignDir( wxStandardPaths::Get().GetTempDir() );
450 path.AppendDir(
"org.kicad.kicad" );
451 path.AppendDir(
"instances" );
452 return path.GetPathWithSep();
461 tmp.AppendDir( wxT(
"logs" ) );
463 return tmp.GetPath();
469 wxString pathString = aPath;
473 pathString += wxFileName::GetPathSeparator();
476 wxFileName
path( pathString );
477 if( !
path.MakeAbsolute() )
482 if( !wxFileName::DirExists(
path.GetPath() ) )
484 if( !wxFileName::Mkdir(
path.GetPath(), wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ) )
509wxString PATHS::GetOSXKicadUserDataDir()
513 wxFileName udir( wxStandardPaths::Get().GetUserDataDir(), wxEmptyString );
517 udir.RemoveLastDir();
518 udir.AppendDir( wxT(
"kicad" ) );
520 return udir.GetPath();
524wxString PATHS::GetOSXKicadMachineDataDir()
527 return GetOSXKicadDataDir();
531wxString PATHS::GetOSXKicadDataDir()
535 wxFileName ddir( wxStandardPaths::Get().GetDataDir(), wxEmptyString );
538 const wxArrayString dirs = ddir.GetDirs();
544 if( dirs.GetCount() >= 6 &&
545 dirs[dirs.GetCount() - 4] == wxT(
"Applications" ) &&
546 dirs[dirs.GetCount() - 6].Lower().EndsWith( wxT(
"app" ) ) )
548 ddir.RemoveLastDir();
549 ddir.RemoveLastDir();
550 ddir.RemoveLastDir();
551 ddir.RemoveLastDir();
552 ddir.AppendDir( wxT(
"SharedSupport" ) );
555 return ddir.GetPath();
561wxString PATHS::GetWindowsFontConfigDir()
564 fn.AssignDir( getWindowsKiCadRoot() );
565 fn.AppendDir( wxS(
"etc" ) );
566 fn.AppendDir( wxS(
"fonts" ) );
568 return fn.GetPathWithSep();
572wxString PATHS::getWindowsKiCadRoot()
577 return root.GetPathWithSep();
584 static wxString user_settings_path;
586 if( user_settings_path.empty() )
589 return user_settings_path;
600 if( aUseEnv && wxGetEnv( wxT(
"KICAD_CONFIG_HOME" ), &envstr ) && !envstr.IsEmpty() )
603 cfgpath.AssignDir( envstr );
609 cfgpath.AppendDir(
TO_STR( KICAD_CONFIG_DIR ) );
615 return cfgpath.GetPath();
621 static wxString exe_path;
623 if( exe_path.empty() )
625 wxString bin_dir = wxStandardPaths::Get().GetExecutablePath();
631 wxFileName fn( bin_dir );
634 if( fn.GetName() == wxT(
"kicad" ) || fn.GetName() == wxT(
"kicad-cli" ) )
650 bin_dir = fn.GetPath() + wxT(
"/" );
658 while( bin_dir.Last() !=
'/' && !bin_dir.IsEmpty() )
659 bin_dir.RemoveLast();
wxString GetMajorMinorVersion()
Get only the major and minor version in a string major.minor.
static wxString GetUserPluginsPath()
Gets the user path for plugins.
static wxString GetStockSymbolsPath()
Gets the stock (install) symbols path.
static wxString GetDefaultUser3DModelsPath()
Gets the default path we point users to create projects.
static wxString GetInstanceCheckerPath()
Gets the path used for wxSingleInstanceChecker lock files.
static wxString GetUserTemplatesPath()
Gets the user path for custom templates.
static void getUserDocumentPath(wxFileName &aPath)
Gets the user path for the current kicad version which acts as the root for other user paths.
static wxString GetStockEDALibraryPath()
Gets the stock (install) EDA library data path, which is the base path for templates,...
static wxString CalculateUserSettingsPath(bool aIncludeVer=true, bool aUseEnv=true)
Determines the base path for user settings files.
static wxString GetDefaultUserProjectsPath()
Gets the default path we point users to create projects.
static wxString GetStockPluginsPath()
Gets the stock (install) plugins path.
static wxString GetLogsPath()
Gets a path to use for user-visible log files.
static void EnsureUserPathsExist()
Ensures/creates user default paths.
static wxString GetDocumentationPath()
Gets the documentation path, which is the base path for help files.
static wxString GetDefaultUserDesignBlocksPath()
Gets the default path we point users to create projects.
static wxString GetDefault3rdPartyPath()
Gets the default path for PCM packages.
static bool EnsurePathExists(const wxString &aPath, bool aPathToFile=false)
Attempts to create a given path if it does not exist.
static wxString GetStockPlugins3DPath()
Gets the stock (install) 3d viewer plugins path.
static wxString GetStockDataPath(bool aRespectRunFromBuildDir=true)
Gets the stock (install) data path, which is the base path for things like scripting,...
static wxString GetDefaultUserFootprintsPath()
Gets the default path we point users to create projects.
static wxString GetStock3dmodelsPath()
Gets the stock (install) 3dmodels path.
static wxString GetStockTemplatesPath()
Gets the stock (install) templates path.
static wxString GetUserCachePath()
Gets the stock (install) 3d viewer plugins path.
static wxString GetUserScriptingPath()
Gets the user path for python scripts.
static wxString GetDefaultUserSymbolsPath()
Gets the default path we point users to create projects.
static wxString GetStockDemosPath()
Gets the stock (install) demos path.
static wxString GetLocaleDataPath()
Gets the locales translation data path.
static wxString GetUserSettingsPath()
Return the user configuration path used to store KiCad's configuration files.
static wxString GetStockDesignBlocksPath()
Gets the stock (install) footprints path.
static wxString GetStockFootprintsPath()
Gets the stock (install) footprints path.
static const wxString & GetExecutablePath()
static wxString GetStockScriptingPath()
Gets the stock (install) scripting path.
static void ResolvePossibleSymlinks(wxFileName &aFilename)
This file contains miscellaneous commonly used macros and functions.
static wxString getBuildDirectoryRoot()
Get the CMake build root directory for the current executable (which assumes the executable is in a b...
#define WIN_STRING_DIR_SEP
#define UNIX_STRING_DIR_SEP