21#include <wx/filename.h>
22#include <wx/stdpaths.h>
39 if( wxGetEnv( wxT(
"KICAD_DOCUMENTS_HOME" ), &envPath ) )
40 aPath.AssignDir( envPath );
54 tmp.AppendDir( wxT(
"plugins" ) );
65 tmp.AppendDir( wxT(
"scripting" ) );
76 tmp.AppendDir( wxT(
"template" ) );
78 return tmp.GetPathWithSep();
87 tmp.AppendDir( wxT(
"symbols" ) );
98 tmp.AppendDir( wxT(
"footprints" ) );
100 return tmp.GetPath();
109 tmp.AppendDir( wxT(
"blocks" ) );
111 return tmp.GetPath();
120 tmp.AppendDir( wxT(
"3dmodels" ) );
122 return tmp.GetPath();
131 tmp.AppendDir( wxT(
"3rdparty" ) );
133 return tmp.GetAbsolutePath();
142 tmp.AppendDir( wxT(
"projects" ) );
144 return tmp.GetPath();
148#if !defined( __WXMAC__ ) && !defined( __WXMSW__ )
161 const auto looksLikeBuildDir = [](
const wxFileName& aPath ) ->
bool
163 const wxDir schema_dir( aPath.GetPathWithSep() + wxT(
"schemas" ) );
165 if( !schema_dir.IsOpened() )
169 const bool found = schema_dir.GetFirst( &filename, wxT(
"*.json" ), wxDIR_FILES );
174 wxFileName fn = execPath;
178 while( fn.GetDirCount() > 0 && !looksLikeBuildDir( fn ) )
184 fn.GetDirCount() > 0,
185 wxString::Format( wxT(
"Could not find build root directory above %s" ), execPath ) );
189#elif defined( __WXMAC__ )
195static wxString getOSXBundleRoot()
197 static wxString bundleRoot;
199 if( bundleRoot.empty() )
201 wxFileName fn( wxStandardPaths::Get().GetExecutablePath() );
203 fn.SetFullName( wxEmptyString );
207 if( fn.GetDirCount() >= 2 && fn.GetDirs().Last() == wxT(
"MacOS" ) )
216 const wxArrayString dirs = fn.GetDirs();
217 if( dirs.GetCount() >= 4 && dirs[dirs.GetCount() - 2] == wxT(
"Applications" )
218 && dirs[dirs.GetCount() - 4].Lower().EndsWith( wxT(
"app" ) ) )
225 bundleRoot = fn.GetPath();
237 if( aRespectRunFromBuildDir && wxGetEnv( wxT(
"KICAD_RUN_FROM_BUILD_DIR" ),
nullptr ) )
240#if defined( __WXMAC__ )
242 fn.AssignDir( getOSXBundleRoot() );
246#elif defined( __WXMSW__ )
247 path = getWindowsKiCadRoot();
252 else if( wxGetEnv( wxT(
"KICAD_STOCK_DATA_HOME" ), &
path ) && !
path.IsEmpty() )
258#if defined( __WXMAC__ )
259 path = GetOSXKicadDataDir();
260#elif defined( __WXMSW__ )
261 path = getWindowsKiCadRoot() + wxT(
"share/kicad" );
263 path = wxString::FromUTF8Unchecked( KICAD_DATA );
273wxString PATHS::GetWindowsBaseSharePath()
275 return getWindowsKiCadRoot() + wxT(
"share\\" );
285#if defined( __WXMAC__ )
286 path = GetOSXKicadMachineDataDir();
287#elif defined( __WXMSW__ )
290 path = wxString::FromUTF8Unchecked( KICAD_LIBRARY_DATA );
302 fn.AppendDir(
"symbols" );
304 return fn.GetPathWithSep();
313 fn.AppendDir(
"footprints" );
315 return fn.GetPathWithSep();
324 fn.AppendDir(
"blocks" );
326 return fn.GetPathWithSep();
335 fn.AppendDir(
"3dmodels" );
337 return fn.GetPathWithSep();
346 fn.AppendDir(
"scripting" );
348 return fn.GetPathWithSep();
357 fn.AppendDir(
"template" );
359 return fn.GetPathWithSep();
368 fn.AppendDir(
"internat" );
370 return fn.GetPathWithSep();
378#if defined( __WXMSW__ )
380 fn.AppendDir( wxT(
"scripting" ) );
384 fn.AppendDir( wxT(
"plugins" ) );
386 return fn.GetPathWithSep();
394#if defined( __WXMSW__ )
395 if( wxGetEnv( wxT(
"KICAD_RUN_FROM_BUILD_DIR" ),
nullptr ) )
397 fn.AssignDir( getWindowsKiCadRoot() );
404 fn.AppendDir( wxT(
"plugins" ) );
405#elif defined( __WXMAC__ )
406 fn.AssignDir( getOSXBundleRoot() );
407 fn.AppendDir( wxT(
"Contents" ) );
408 fn.AppendDir( wxT(
"PlugIns" ) );
412 if( wxGetEnv( wxT(
"KICAD_RUN_FROM_BUILD_DIR" ),
nullptr ) )
415 fn.AppendDir( wxT(
".." ) );
416 fn.AppendDir( wxT(
"plugins" ) );
420 else if( wxGetEnv( wxT(
"APPDIR" ), &envPath ) )
422 fn.Assign( envPath, wxEmptyString );
423 fn.AppendDir( wxT(
"usr" ) );
424 fn.AppendDir( wxT(
"lib" ) );
425 fn.AppendDir( wxT(
"x86_64-linux-gnu" ) );
426 fn.AppendDir( wxT(
"kicad" ) );
427 fn.AppendDir( wxT(
"plugins" ) );
433 wxString tfname = wxString::FromUTF8Unchecked( KICAD_PLUGINDIR );
434 fn.Assign( tfname,
"" );
435 fn.AppendDir( wxT(
"kicad" ) );
436 fn.AppendDir( wxT(
"plugins" ) );
440 fn.AppendDir( wxT(
"3d" ) );
442 return fn.GetPathWithSep();
451 fn.AppendDir( wxT(
"demos" ) );
453 return fn.GetPathWithSep();
465 if( wxGetEnv( wxT(
"KICAD_CACHE_HOME" ), &envPath ) && !envPath.IsEmpty() )
468 tmp.AssignDir( envPath );
474 return tmp.GetPathWithSep();
482#if defined( __WXMAC__ )
483 path = GetOSXKicadDataDir();
484#elif defined( __WXMSW__ )
485 path = getWindowsKiCadRoot() + wxT(
"share/doc/kicad" );
487 path = wxString::FromUTF8Unchecked( KICAD_DOCS );
497 path.AssignDir( wxStandardPaths::Get().GetTempDir() );
498 path.AppendDir(
"org.kicad.kicad" );
499 path.AppendDir(
"instances" );
500 return path.GetPathWithSep();
509 tmp.AppendDir( wxT(
"logs" ) );
511 return tmp.GetPath();
517 wxString pathString = aPath;
521 pathString += wxFileName::GetPathSeparator();
524 wxFileName
path( pathString );
525 if( !
path.MakeAbsolute() )
530 if( !wxFileName::DirExists(
path.GetPath() ) )
532 if( !wxFileName::Mkdir(
path.GetPath(), wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ) )
559 if( !tmp.DirExists() )
561 wxString msg = wxString::Format(
562 _(
"KiCad was unable to use '%s'.\n"
564 "1. Disable 'Controlled folder access' in Windows settings or Group Policy\n"
565 "2. Make sure no other antivirus software interferes with KiCad\n"
566 "3. Make sure you have correct permissions set up" ),
569 wxMessageBox( msg,
_(
"Warning" ), wxICON_WARNING );
576wxString PATHS::GetOSXKicadUserDataDir()
580 wxFileName udir( wxStandardPaths::Get().GetUserDataDir(), wxEmptyString );
584 udir.RemoveLastDir();
585 udir.AppendDir( wxT(
"kicad" ) );
587 return udir.GetPath();
591wxString PATHS::GetOSXKicadMachineDataDir()
594 return GetOSXKicadDataDir();
598wxString PATHS::GetOSXKicadDataDir()
601 ddir.AssignDir( getOSXBundleRoot() );
602 ddir.AppendDir( wxT(
"Contents" ) );
603 ddir.AppendDir( wxT(
"SharedSupport" ) );
604 return ddir.GetPath();
610wxString PATHS::GetWindowsFontConfigDir()
613 fn.AssignDir( getWindowsKiCadRoot() );
614 fn.AppendDir( wxS(
"etc" ) );
615 fn.AppendDir( wxS(
"fonts" ) );
617 return fn.GetPathWithSep();
621wxString PATHS::getWindowsKiCadRoot()
626 return root.GetPathWithSep();
633 static wxString user_settings_path;
635 if( user_settings_path.empty() )
638 return user_settings_path;
649 if( aUseEnv && wxGetEnv( wxT(
"KICAD_CONFIG_HOME" ), &envstr ) && !envstr.IsEmpty() )
652 cfgpath.AssignDir( envstr );
658 cfgpath.AppendDir(
TO_STR( KICAD_CONFIG_DIR ) );
664 return cfgpath.GetPath();
670 static wxString exe_path;
672 if( exe_path.empty() )
676 exe_path = getOSXBundleRoot() + wxT(
"/" );
683 if( wxGetEnv( wxT(
"APPDIR" ), &envPath ) )
687 if( !envPath.EndsWith( wxT(
"/" ) ) )
688 envPath += wxT(
"/" );
690 exe_path = envPath + wxT(
"usr/bin/" );
694 wxString bin_dir = wxStandardPaths::Get().GetExecutablePath();
702 while( bin_dir.Last() !=
'/' && !bin_dir.IsEmpty() )
703 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