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 if( wxGetEnv( wxT(
"APPDIR" ), &
path ) )
291 path += wxT(
"/share/kicad" );
293 path = wxString::FromUTF8Unchecked( KICAD_LIBRARY_DATA );
305 fn.AppendDir(
"symbols" );
307 return fn.GetPathWithSep();
316 fn.AppendDir(
"footprints" );
318 return fn.GetPathWithSep();
327 fn.AppendDir(
"blocks" );
329 return fn.GetPathWithSep();
338 fn.AppendDir(
"3dmodels" );
340 return fn.GetPathWithSep();
349 fn.AppendDir(
"scripting" );
351 return fn.GetPathWithSep();
360 fn.AppendDir(
"template" );
362 return fn.GetPathWithSep();
371 fn.AppendDir(
"internat" );
373 return fn.GetPathWithSep();
381#if defined( __WXMSW__ )
383 fn.AppendDir( wxT(
"scripting" ) );
387 fn.AppendDir( wxT(
"plugins" ) );
389 return fn.GetPathWithSep();
397#if defined( __WXMSW__ )
398 if( wxGetEnv( wxT(
"KICAD_RUN_FROM_BUILD_DIR" ),
nullptr ) )
400 fn.AssignDir( getWindowsKiCadRoot() );
407 fn.AppendDir( wxT(
"plugins" ) );
408#elif defined( __WXMAC__ )
409 fn.AssignDir( getOSXBundleRoot() );
410 fn.AppendDir( wxT(
"Contents" ) );
411 fn.AppendDir( wxT(
"PlugIns" ) );
415 if( wxGetEnv( wxT(
"KICAD_RUN_FROM_BUILD_DIR" ),
nullptr ) )
418 fn.AppendDir( wxT(
".." ) );
419 fn.AppendDir( wxT(
"plugins" ) );
423 else if( wxGetEnv( wxT(
"APPDIR" ), &envPath ) )
425 fn.Assign( envPath, wxEmptyString );
426 fn.AppendDir( wxT(
"usr" ) );
427 fn.AppendDir( wxT(
"lib" ) );
428 fn.AppendDir( wxT(
"x86_64-linux-gnu" ) );
429 fn.AppendDir( wxT(
"kicad" ) );
430 fn.AppendDir( wxT(
"plugins" ) );
436 wxString tfname = wxString::FromUTF8Unchecked( KICAD_PLUGINDIR );
437 fn.Assign( tfname,
"" );
438 fn.AppendDir( wxT(
"kicad" ) );
439 fn.AppendDir( wxT(
"plugins" ) );
443 fn.AppendDir( wxT(
"3d" ) );
445 return fn.GetPathWithSep();
454 fn.AppendDir( wxT(
"demos" ) );
456 return fn.GetPathWithSep();
468 if( wxGetEnv( wxT(
"KICAD_CACHE_HOME" ), &envPath ) && !envPath.IsEmpty() )
471 tmp.AssignDir( envPath );
477 return tmp.GetPathWithSep();
485#if defined( __WXMAC__ )
486 path = GetOSXKicadDataDir();
487#elif defined( __WXMSW__ )
488 path = getWindowsKiCadRoot() + wxT(
"share/doc/kicad" );
490 path = wxString::FromUTF8Unchecked( KICAD_DOCS );
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(
"/" );
676 if( wxGetEnv( wxT(
"APPDIR" ), &envPath ) )
680 if( !envPath.EndsWith( wxT(
"/" ) ) )
681 envPath += wxT(
"/" );
683 exe_path = envPath + wxT(
"usr/bin/" );
687 wxString bin_dir = wxStandardPaths::Get().GetExecutablePath();
695 while( bin_dir.Last() !=
'/' && !bin_dir.IsEmpty() )
696 bin_dir.RemoveLast();
712 wxFileName sibling( wxFileName( wxStandardPaths::Get().
GetExecutablePath() ).GetPath(), aBaseName );
718 sibling.SetExt( wxT(
"exe" ) );
721 if( !sibling.FileExists() )
722 return wxEmptyString;
724 return sibling.GetFullPath();
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 ResolveSiblingExecutable(const wxString &aBaseName)
Resolve a sibling executable alongside the running process.
static wxString GetDefaultUser3DModelsPath()
Gets the default path we point users to create projects.
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)
static std::string ToStdString(const wxString &aStr)
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