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" ) );
388 if( wxGetEnv( wxT(
"APPDIR" ), &envPath ) )
390 fn.Assign( envPath, wxEmptyString );
391 fn.AppendDir( wxT(
"usr" ) );
392 fn.AppendDir( wxT(
"lib" ) );
393 fn.AppendDir( wxT(
"x86_64-linux-gnu" ) );
399 wxString tfname = wxString::FromUTF8Unchecked( KICAD_PLUGINDIR );
400 fn.Assign( tfname,
"" );
403 fn.AppendDir( wxT(
"kicad" ) );
404 fn.AppendDir( wxT(
"plugins" ) );
407 fn.AppendDir( wxT(
"3d" ) );
409 return fn.GetPathWithSep();
418 fn.AppendDir( wxT(
"demos" ) );
420 return fn.GetPathWithSep();
432 if( wxGetEnv( wxT(
"KICAD_CACHE_HOME" ), &envPath ) && !envPath.IsEmpty() )
435 tmp.AssignDir( envPath );
441 return tmp.GetPathWithSep();
449#if defined( __WXMAC__ )
450 path = GetOSXKicadDataDir();
451#elif defined( __WXMSW__ )
452 path = getWindowsKiCadRoot() + wxT(
"share/doc/kicad" );
454 path = wxString::FromUTF8Unchecked( KICAD_DOCS );
464 path.AssignDir( wxStandardPaths::Get().GetTempDir() );
465 path.AppendDir(
"org.kicad.kicad" );
466 path.AppendDir(
"instances" );
467 return path.GetPathWithSep();
476 tmp.AppendDir( wxT(
"logs" ) );
478 return tmp.GetPath();
484 wxString pathString = aPath;
488 pathString += wxFileName::GetPathSeparator();
491 wxFileName
path( pathString );
492 if( !
path.MakeAbsolute() )
497 if( !wxFileName::DirExists(
path.GetPath() ) )
499 if( !wxFileName::Mkdir(
path.GetPath(), wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ) )
524wxString PATHS::GetOSXKicadUserDataDir()
528 wxFileName udir( wxStandardPaths::Get().GetUserDataDir(), wxEmptyString );
532 udir.RemoveLastDir();
533 udir.AppendDir( wxT(
"kicad" ) );
535 return udir.GetPath();
539wxString PATHS::GetOSXKicadMachineDataDir()
542 return GetOSXKicadDataDir();
546wxString PATHS::GetOSXKicadDataDir()
550 wxFileName ddir( wxStandardPaths::Get().GetDataDir(), wxEmptyString );
553 const wxArrayString dirs = ddir.GetDirs();
559 if( dirs.GetCount() >= 6 &&
560 dirs[dirs.GetCount() - 4] == wxT(
"Applications" ) &&
561 dirs[dirs.GetCount() - 6].Lower().EndsWith( wxT(
"app" ) ) )
563 ddir.RemoveLastDir();
564 ddir.RemoveLastDir();
565 ddir.RemoveLastDir();
566 ddir.RemoveLastDir();
567 ddir.AppendDir( wxT(
"SharedSupport" ) );
570 return ddir.GetPath();
576wxString PATHS::GetWindowsFontConfigDir()
579 fn.AssignDir( getWindowsKiCadRoot() );
580 fn.AppendDir( wxS(
"etc" ) );
581 fn.AppendDir( wxS(
"fonts" ) );
583 return fn.GetPathWithSep();
587wxString PATHS::getWindowsKiCadRoot()
592 return root.GetPathWithSep();
599 static wxString user_settings_path;
601 if( user_settings_path.empty() )
604 return user_settings_path;
615 if( aUseEnv && wxGetEnv( wxT(
"KICAD_CONFIG_HOME" ), &envstr ) && !envstr.IsEmpty() )
618 cfgpath.AssignDir( envstr );
624 cfgpath.AppendDir(
TO_STR( KICAD_CONFIG_DIR ) );
630 return cfgpath.GetPath();
636 static wxString exe_path;
638 if( exe_path.empty() )
640 wxString bin_dir = wxStandardPaths::Get().GetExecutablePath();
646 wxFileName fn( bin_dir );
649 if( fn.GetName() == wxT(
"kicad" ) || fn.GetName() == wxT(
"kicad-cli" ) )
665 bin_dir = fn.GetPath() + wxT(
"/" );
673 while( bin_dir.Last() !=
'/' && !bin_dir.IsEmpty() )
674 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