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(
"3d" ) );
81 tmp.AppendDir( wxT(
"scripting" ) );
92 tmp.AppendDir( wxT(
"template" ) );
94 return tmp.GetPathWithSep();
103 tmp.AppendDir( wxT(
"symbols" ) );
105 return tmp.GetPath();
114 tmp.AppendDir( wxT(
"footprints" ) );
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 );
282#if defined( __WXMSW__ )
284 fn.AppendDir( wxT(
"scripting" ) );
288 fn.AppendDir( wxT(
"plugins" ) );
290 return fn.GetPathWithSep();
298#if defined( __WXMSW__ )
299 if( wxGetEnv( wxT(
"KICAD_RUN_FROM_BUILD_DIR" ),
nullptr ) )
301 fn.AssignDir( getWindowsKiCadRoot() );
308 fn.AppendDir( wxT(
"plugins" ) );
309#elif defined( __WXMAC__ )
310 fn.Assign( wxStandardPaths::Get().GetPluginsDir(), wxEmptyString );
313 const wxArrayString dirs = fn.GetDirs();
319 if( dirs.GetCount() >= 6 &&
320 dirs[dirs.GetCount() - 4] == wxT(
"Applications" ) &&
321 dirs[dirs.GetCount() - 6].Lower().EndsWith( wxT(
"app" ) ) )
327 fn.AppendDir( wxT(
"PlugIns" ) );
332 wxString tfname = wxString::FromUTF8Unchecked( KICAD_PLUGINDIR );
333 fn.Assign( tfname,
"" );
334 fn.AppendDir( wxT(
"kicad" ) );
335 fn.AppendDir( wxT(
"plugins" ) );
338 fn.AppendDir( wxT(
"3d" ) );
340 return fn.GetPathWithSep();
349 fn.AppendDir( wxT(
"demos" ) );
351 return fn.GetPathWithSep();
363 if( wxGetEnv( wxT(
"KICAD_CACHE_HOME" ), &envPath ) && !envPath.IsEmpty() )
366 tmp.AssignDir( envPath );
372 return tmp.GetPathWithSep();
380#if defined( __WXMAC__ )
381 path = GetOSXKicadDataDir();
382#elif defined( __WXMSW__ )
383 path = getWindowsKiCadRoot() + wxT(
"share/doc/kicad" );
385 path = wxString::FromUTF8Unchecked( KICAD_DOCS );
395 path.AssignDir( wxStandardPaths::Get().GetTempDir() );
396 path.AppendDir(
"org.kicad.kicad" );
397 path.AppendDir(
"instances" );
398 return path.GetPathWithSep();
404 wxFileName
path( aPath );
405 if( !
path.MakeAbsolute() )
410 if( !wxFileName::DirExists( aPath ) )
412 if( !wxFileName::Mkdir( aPath, wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ) )
437wxString PATHS::GetOSXKicadUserDataDir()
441 wxFileName udir( wxStandardPaths::Get().GetUserDataDir(), wxEmptyString );
445 udir.RemoveLastDir();
446 udir.AppendDir( wxT(
"kicad" ) );
448 return udir.GetPath();
452wxString PATHS::GetOSXKicadMachineDataDir()
455 return GetOSXKicadDataDir();
459wxString PATHS::GetOSXKicadDataDir()
463 wxFileName ddir( wxStandardPaths::Get().GetDataDir(), wxEmptyString );
466 const wxArrayString dirs = ddir.GetDirs();
472 if( dirs.GetCount() >= 6 &&
473 dirs[dirs.GetCount() - 4] == wxT(
"Applications" ) &&
474 dirs[dirs.GetCount() - 6].Lower().EndsWith( wxT(
"app" ) ) )
476 ddir.RemoveLastDir();
477 ddir.RemoveLastDir();
478 ddir.RemoveLastDir();
479 ddir.RemoveLastDir();
480 ddir.AppendDir( wxT(
"SharedSupport" ) );
483 return ddir.GetPath();
489wxString PATHS::GetWindowsFontConfigDir()
492 fn.AssignDir( getWindowsKiCadRoot() );
493 fn.AppendDir( wxS(
"etc" ) );
494 fn.AppendDir( wxS(
"fonts" ) );
496 return fn.GetPathWithSep();
500wxString PATHS::getWindowsKiCadRoot()
505 return root.GetPathWithSep();
512 static wxString user_settings_path;
514 if( user_settings_path.empty() )
517 return user_settings_path;
528 if( aUseEnv && wxGetEnv( wxT(
"KICAD_CONFIG_HOME" ), &envstr ) && !envstr.IsEmpty() )
531 cfgpath.AssignDir( envstr );
537 cfgpath.AppendDir(
TO_STR( KICAD_CONFIG_DIR ) );
543 return cfgpath.GetPath();
549 static wxString exe_path;
551 if( exe_path.empty() )
553 wxString bin_dir = wxStandardPaths::Get().GetExecutablePath();
559 wxFileName fn( bin_dir );
562 if( fn.GetName() == wxT(
"kicad" ) || fn.GetName() == wxT(
"kicad-cli" ) )
578 bin_dir = fn.GetPath() + wxT(
"/" );
586 while( bin_dir.Last() !=
'/' && !bin_dir.IsEmpty() )
587 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 GetUserPlugins3DPath()
Gets the user path for 3d viewer plugin.
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 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 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