20#include <wx/filename.h>
21#include <wx/stdpaths.h>
33#if defined( __WXMAC__ ) || defined( __WXMSW__ )
34#define KICAD_PATH_STR wxT( "KiCad" )
36#define KICAD_PATH_STR wxT( "kicad" )
44 if( wxGetEnv( wxT(
"KICAD_DOCUMENTS_HOME" ), &envPath ) )
45 aPath.AssignDir( envPath );
59 tmp.AppendDir( wxT(
"plugins" ) );
70 tmp.AppendDir( wxT(
"scripting" ) );
81 tmp.AppendDir( wxT(
"template" ) );
83 return tmp.GetPathWithSep();
92 tmp.AppendDir( wxT(
"symbols" ) );
103 tmp.AppendDir( wxT(
"footprints" ) );
105 return tmp.GetPath();
114 tmp.AppendDir( wxT(
"blocks" ) );
116 return tmp.GetPath();
125 tmp.AppendDir( wxT(
"3dmodels" ) );
127 return tmp.GetPath();
135 tmp.AppendDir( wxT(
"3rdparty" ) );
137 return tmp.GetPath();
145 tmp.AppendDir( wxT(
"projects" ) );
147 return tmp.GetPath();
155 if( aRespectRunFromBuildDir && wxGetEnv( wxT(
"KICAD_RUN_FROM_BUILD_DIR" ),
nullptr ) )
158#if defined( __WXMAC__ )
159 wxFileName fn = wxStandardPaths::Get().GetExecutablePath();
166#elif defined( __WXMSW__ )
167 path = getWindowsKiCadRoot();
172 else if( wxGetEnv( wxT(
"KICAD_STOCK_DATA_HOME" ), &
path ) && !
path.IsEmpty() )
178#if defined( __WXMAC__ )
179 path = GetOSXKicadDataDir();
180#elif defined( __WXMSW__ )
181 path = getWindowsKiCadRoot() + wxT(
"share/kicad" );
183 path = wxString::FromUTF8Unchecked( KICAD_DATA );
195wxString PATHS::GetWindowsBaseSharePath()
197 return getWindowsKiCadRoot() + wxT(
"share\\" );
206#if defined( __WXMAC__ )
207 path = GetOSXKicadMachineDataDir();
208#elif defined( __WXMSW__ )
211 path = wxString::FromUTF8Unchecked( KICAD_LIBRARY_DATA );
292#if defined( __WXMSW__ )
294 fn.AppendDir( wxT(
"scripting" ) );
298 fn.AppendDir( wxT(
"plugins" ) );
300 return fn.GetPathWithSep();
308#if defined( __WXMSW__ )
309 if( wxGetEnv( wxT(
"KICAD_RUN_FROM_BUILD_DIR" ),
nullptr ) )
311 fn.AssignDir( getWindowsKiCadRoot() );
318 fn.AppendDir( wxT(
"plugins" ) );
319#elif defined( __WXMAC__ )
320 fn.Assign( wxStandardPaths::Get().GetPluginsDir(), wxEmptyString );
323 const wxArrayString dirs = fn.GetDirs();
329 if( dirs.GetCount() >= 6 &&
330 dirs[dirs.GetCount() - 4] == wxT(
"Applications" ) &&
331 dirs[dirs.GetCount() - 6].Lower().EndsWith( wxT(
"app" ) ) )
337 fn.AppendDir( wxT(
"PlugIns" ) );
342 wxString tfname = wxString::FromUTF8Unchecked( KICAD_PLUGINDIR );
343 fn.Assign( tfname,
"" );
344 fn.AppendDir( wxT(
"kicad" ) );
345 fn.AppendDir( wxT(
"plugins" ) );
348 fn.AppendDir( wxT(
"3d" ) );
350 return fn.GetPathWithSep();
359 fn.AppendDir( wxT(
"demos" ) );
361 return fn.GetPathWithSep();
373 if( wxGetEnv( wxT(
"KICAD_CACHE_HOME" ), &envPath ) && !envPath.IsEmpty() )
376 tmp.AssignDir( envPath );
382 return tmp.GetPathWithSep();
390#if defined( __WXMAC__ )
391 path = GetOSXKicadDataDir();
392#elif defined( __WXMSW__ )
393 path = getWindowsKiCadRoot() + wxT(
"share/doc/kicad" );
395 path = wxString::FromUTF8Unchecked( KICAD_DOCS );
405 path.AssignDir( wxStandardPaths::Get().GetTempDir() );
406 path.AppendDir(
"org.kicad.kicad" );
407 path.AppendDir(
"instances" );
408 return path.GetPathWithSep();
417 tmp.AppendDir( wxT(
"logs" ) );
419 return tmp.GetPath();
425 wxFileName
path( aPath );
426 if( !
path.MakeAbsolute() )
431 if( !wxFileName::DirExists( aPath ) )
433 if( !wxFileName::Mkdir( aPath, wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ) )
458wxString PATHS::GetOSXKicadUserDataDir()
462 wxFileName udir( wxStandardPaths::Get().GetUserDataDir(), wxEmptyString );
466 udir.RemoveLastDir();
467 udir.AppendDir( wxT(
"kicad" ) );
469 return udir.GetPath();
473wxString PATHS::GetOSXKicadMachineDataDir()
476 return GetOSXKicadDataDir();
480wxString PATHS::GetOSXKicadDataDir()
484 wxFileName ddir( wxStandardPaths::Get().GetDataDir(), wxEmptyString );
487 const wxArrayString dirs = ddir.GetDirs();
493 if( dirs.GetCount() >= 6 &&
494 dirs[dirs.GetCount() - 4] == wxT(
"Applications" ) &&
495 dirs[dirs.GetCount() - 6].Lower().EndsWith( wxT(
"app" ) ) )
497 ddir.RemoveLastDir();
498 ddir.RemoveLastDir();
499 ddir.RemoveLastDir();
500 ddir.RemoveLastDir();
501 ddir.AppendDir( wxT(
"SharedSupport" ) );
504 return ddir.GetPath();
510wxString PATHS::GetWindowsFontConfigDir()
513 fn.AssignDir( getWindowsKiCadRoot() );
514 fn.AppendDir( wxS(
"etc" ) );
515 fn.AppendDir( wxS(
"fonts" ) );
517 return fn.GetPathWithSep();
521wxString PATHS::getWindowsKiCadRoot()
526 return root.GetPathWithSep();
533 static wxString user_settings_path;
535 if( user_settings_path.empty() )
538 return user_settings_path;
549 if( aUseEnv && wxGetEnv( wxT(
"KICAD_CONFIG_HOME" ), &envstr ) && !envstr.IsEmpty() )
552 cfgpath.AssignDir( envstr );
558 cfgpath.AppendDir(
TO_STR( KICAD_CONFIG_DIR ) );
564 return cfgpath.GetPath();
570 static wxString exe_path;
572 if( exe_path.empty() )
574 wxString bin_dir = wxStandardPaths::Get().GetExecutablePath();
580 wxFileName fn( bin_dir );
583 if( fn.GetName() == wxT(
"kicad" ) || fn.GetName() == wxT(
"kicad-cli" ) )
599 bin_dir = fn.GetPath() + wxT(
"/" );
607 while( bin_dir.Last() !=
'/' && !bin_dir.IsEmpty() )
608 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 bool EnsurePathExists(const wxString &aPath)
Attempts to create a given path if it does not exist.
static wxString GetDefaultUserDesignBlocksPath()
Gets the default path we point users to create projects.
static wxString GetDefault3rdPartyPath()
Gets the default path for PCM packages.
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.
#define WIN_STRING_DIR_SEP
#define UNIX_STRING_DIR_SEP