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 );
500 path.AssignDir( wxStandardPaths::Get().GetTempDir() );
501 path.AppendDir(
"org.kicad.kicad" );
502 path.AppendDir(
"instances" );
503 return path.GetPathWithSep();
512 tmp.AppendDir( wxT(
"logs" ) );
514 return tmp.GetPath();
520 wxString pathString = aPath;
524 pathString += wxFileName::GetPathSeparator();
527 wxFileName
path( pathString );
528 if( !
path.MakeAbsolute() )
533 if( !wxFileName::DirExists(
path.GetPath() ) )
535 if( !wxFileName::Mkdir(
path.GetPath(), wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ) )
562 if( !tmp.DirExists() )
564 wxString msg = wxString::Format(
565 _(
"KiCad was unable to use '%s'.\n"
567 "1. Disable 'Controlled folder access' in Windows settings or Group Policy\n"
568 "2. Make sure no other antivirus software interferes with KiCad\n"
569 "3. Make sure you have correct permissions set up" ),
572 wxMessageBox( msg,
_(
"Warning" ), wxICON_WARNING );
579wxString PATHS::GetOSXKicadUserDataDir()
583 wxFileName udir( wxStandardPaths::Get().GetUserDataDir(), wxEmptyString );
587 udir.RemoveLastDir();
588 udir.AppendDir( wxT(
"kicad" ) );
590 return udir.GetPath();
594wxString PATHS::GetOSXKicadMachineDataDir()
597 return GetOSXKicadDataDir();
601wxString PATHS::GetOSXKicadDataDir()
604 ddir.AssignDir( getOSXBundleRoot() );
605 ddir.AppendDir( wxT(
"Contents" ) );
606 ddir.AppendDir( wxT(
"SharedSupport" ) );
607 return ddir.GetPath();
613wxString PATHS::GetWindowsFontConfigDir()
616 fn.AssignDir( getWindowsKiCadRoot() );
617 fn.AppendDir( wxS(
"etc" ) );
618 fn.AppendDir( wxS(
"fonts" ) );
620 return fn.GetPathWithSep();
624wxString PATHS::getWindowsKiCadRoot()
629 return root.GetPathWithSep();
636 static wxString user_settings_path;
638 if( user_settings_path.empty() )
641 return user_settings_path;
652 if( aUseEnv && wxGetEnv( wxT(
"KICAD_CONFIG_HOME" ), &envstr ) && !envstr.IsEmpty() )
655 cfgpath.AssignDir( envstr );
661 cfgpath.AppendDir(
TO_STR( KICAD_CONFIG_DIR ) );
667 return cfgpath.GetPath();
673 static wxString exe_path;
675 if( exe_path.empty() )
679 exe_path = getOSXBundleRoot() + wxT(
"/" );
686 if( wxGetEnv( wxT(
"APPDIR" ), &envPath ) )
690 if( !envPath.EndsWith( wxT(
"/" ) ) )
691 envPath += wxT(
"/" );
693 exe_path = envPath + wxT(
"usr/bin/" );
697 wxString bin_dir = wxStandardPaths::Get().GetExecutablePath();
705 while( bin_dir.Last() !=
'/' && !bin_dir.IsEmpty() )
706 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