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(
"3dmodels" ) );
116 return tmp.GetPath();
124 tmp.AppendDir( wxT(
"3rdparty" ) );
126 return tmp.GetPath();
134 tmp.AppendDir( wxT(
"projects" ) );
136 return tmp.GetPath();
144 if( aRespectRunFromBuildDir && wxGetEnv( wxT(
"KICAD_RUN_FROM_BUILD_DIR" ),
nullptr ) )
147#if defined( __WXMAC__ )
148 wxFileName fn = wxStandardPaths::Get().GetExecutablePath();
155#elif defined( __WXMSW__ )
156 path = getWindowsKiCadRoot();
161 else if( wxGetEnv( wxT(
"KICAD_STOCK_DATA_HOME" ), &
path ) && !
path.IsEmpty() )
167#if defined( __WXMAC__ )
168 path = GetOSXKicadDataDir();
169#elif defined( __WXMSW__ )
170 path = getWindowsKiCadRoot() + wxT(
"share/kicad" );
172 path = wxString::FromUTF8Unchecked( KICAD_DATA );
184wxString PATHS::GetWindowsBaseSharePath()
186 return getWindowsKiCadRoot() + wxT(
"share\\" );
195#if defined( __WXMAC__ )
196 path = GetOSXKicadMachineDataDir();
197#elif defined( __WXMSW__ )
200 path = wxString::FromUTF8Unchecked( KICAD_LIBRARY_DATA );
271#if defined( __WXMSW__ )
273 fn.AppendDir( wxT(
"scripting" ) );
277 fn.AppendDir( wxT(
"plugins" ) );
279 return fn.GetPathWithSep();
287#if defined( __WXMSW__ )
288 if( wxGetEnv( wxT(
"KICAD_RUN_FROM_BUILD_DIR" ),
nullptr ) )
290 fn.AssignDir( getWindowsKiCadRoot() );
297 fn.AppendDir( wxT(
"plugins" ) );
298#elif defined( __WXMAC__ )
299 fn.Assign( wxStandardPaths::Get().GetPluginsDir(), wxEmptyString );
302 const wxArrayString dirs = fn.GetDirs();
308 if( dirs.GetCount() >= 6 &&
309 dirs[dirs.GetCount() - 4] == wxT(
"Applications" ) &&
310 dirs[dirs.GetCount() - 6].Lower().EndsWith( wxT(
"app" ) ) )
316 fn.AppendDir( wxT(
"PlugIns" ) );
321 wxString tfname = wxString::FromUTF8Unchecked( KICAD_PLUGINDIR );
322 fn.Assign( tfname,
"" );
323 fn.AppendDir( wxT(
"kicad" ) );
324 fn.AppendDir( wxT(
"plugins" ) );
327 fn.AppendDir( wxT(
"3d" ) );
329 return fn.GetPathWithSep();
338 fn.AppendDir( wxT(
"demos" ) );
340 return fn.GetPathWithSep();
352 if( wxGetEnv( wxT(
"KICAD_CACHE_HOME" ), &envPath ) && !envPath.IsEmpty() )
355 tmp.AssignDir( envPath );
361 return tmp.GetPathWithSep();
369#if defined( __WXMAC__ )
370 path = GetOSXKicadDataDir();
371#elif defined( __WXMSW__ )
372 path = getWindowsKiCadRoot() + wxT(
"share/doc/kicad" );
374 path = wxString::FromUTF8Unchecked( KICAD_DOCS );
384 path.AssignDir( wxStandardPaths::Get().GetTempDir() );
385 path.AppendDir(
"org.kicad.kicad" );
386 path.AppendDir(
"instances" );
387 return path.GetPathWithSep();
396 tmp.AppendDir( wxT(
"logs" ) );
398 return tmp.GetPath();
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 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 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