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 );
371#if defined( __WXMSW__ )
373 fn.AppendDir( wxT(
"scripting" ) );
377 fn.AppendDir( wxT(
"plugins" ) );
379 return fn.GetPathWithSep();
387#if defined( __WXMSW__ )
388 if( wxGetEnv( wxT(
"KICAD_RUN_FROM_BUILD_DIR" ),
nullptr ) )
390 fn.AssignDir( getWindowsKiCadRoot() );
397 fn.AppendDir( wxT(
"plugins" ) );
398#elif defined( __WXMAC__ )
399 fn.AssignDir( getOSXBundleRoot() );
400 fn.AppendDir( wxT(
"Contents" ) );
401 fn.AppendDir( wxT(
"PlugIns" ) );
405 if( wxGetEnv( wxT(
"KICAD_RUN_FROM_BUILD_DIR" ),
nullptr ) )
408 fn.AppendDir( wxT(
".." ) );
409 fn.AppendDir( wxT(
"plugins" ) );
413 else if( wxGetEnv( wxT(
"APPDIR" ), &envPath ) )
415 fn.Assign( envPath, wxEmptyString );
416 fn.AppendDir( wxT(
"usr" ) );
417 fn.AppendDir( wxT(
"lib" ) );
418 fn.AppendDir( wxT(
"x86_64-linux-gnu" ) );
419 fn.AppendDir( wxT(
"kicad" ) );
420 fn.AppendDir( wxT(
"plugins" ) );
426 wxString tfname = wxString::FromUTF8Unchecked( KICAD_PLUGINDIR );
427 fn.Assign( tfname,
"" );
428 fn.AppendDir( wxT(
"kicad" ) );
429 fn.AppendDir( wxT(
"plugins" ) );
433 fn.AppendDir( wxT(
"3d" ) );
435 return fn.GetPathWithSep();
444 fn.AppendDir( wxT(
"demos" ) );
446 return fn.GetPathWithSep();
458 if( wxGetEnv( wxT(
"KICAD_CACHE_HOME" ), &envPath ) && !envPath.IsEmpty() )
461 tmp.AssignDir( envPath );
467 return tmp.GetPathWithSep();
475#if defined( __WXMAC__ )
476 path = GetOSXKicadDataDir();
477#elif defined( __WXMSW__ )
478 path = getWindowsKiCadRoot() + wxT(
"share/doc/kicad" );
480 path = wxString::FromUTF8Unchecked( KICAD_DOCS );
490 path.AssignDir( wxStandardPaths::Get().GetTempDir() );
491 path.AppendDir(
"org.kicad.kicad" );
492 path.AppendDir(
"instances" );
493 return path.GetPathWithSep();
502 tmp.AppendDir( wxT(
"logs" ) );
504 return tmp.GetPath();
510 wxString pathString = aPath;
514 pathString += wxFileName::GetPathSeparator();
517 wxFileName
path( pathString );
518 if( !
path.MakeAbsolute() )
523 if( !wxFileName::DirExists(
path.GetPath() ) )
525 if( !wxFileName::Mkdir(
path.GetPath(), wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ) )
552 if( !tmp.DirExists() )
554 wxString msg = wxString::Format(
555 _(
"KiCad was unable to use '%s'.\n"
557 "1. Disable 'Controlled folder access' in Windows settings or Group Policy\n"
558 "2. Make sure no other antivirus software interferes with KiCad\n"
559 "3. Make sure you have correct permissions set up" ),
562 wxMessageBox( msg,
_(
"Warning" ), wxICON_WARNING );
569wxString PATHS::GetOSXKicadUserDataDir()
573 wxFileName udir( wxStandardPaths::Get().GetUserDataDir(), wxEmptyString );
577 udir.RemoveLastDir();
578 udir.AppendDir( wxT(
"kicad" ) );
580 return udir.GetPath();
584wxString PATHS::GetOSXKicadMachineDataDir()
587 return GetOSXKicadDataDir();
591wxString PATHS::GetOSXKicadDataDir()
594 ddir.AssignDir( getOSXBundleRoot() );
595 ddir.AppendDir( wxT(
"Contents" ) );
596 ddir.AppendDir( wxT(
"SharedSupport" ) );
597 return ddir.GetPath();
603wxString PATHS::GetWindowsFontConfigDir()
606 fn.AssignDir( getWindowsKiCadRoot() );
607 fn.AppendDir( wxS(
"etc" ) );
608 fn.AppendDir( wxS(
"fonts" ) );
610 return fn.GetPathWithSep();
614wxString PATHS::getWindowsKiCadRoot()
619 return root.GetPathWithSep();
626 static wxString user_settings_path;
628 if( user_settings_path.empty() )
631 return user_settings_path;
642 if( aUseEnv && wxGetEnv( wxT(
"KICAD_CONFIG_HOME" ), &envstr ) && !envstr.IsEmpty() )
645 cfgpath.AssignDir( envstr );
651 cfgpath.AppendDir(
TO_STR( KICAD_CONFIG_DIR ) );
657 return cfgpath.GetPath();
663 static wxString exe_path;
665 if( exe_path.empty() )
669 exe_path = getOSXBundleRoot() + wxT(
"/" );
671 wxString bin_dir = wxStandardPaths::Get().GetExecutablePath();
679 while( bin_dir.Last() !=
'/' && !bin_dir.IsEmpty() )
680 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