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 ) );
196 if( aRespectRunFromBuildDir && wxGetEnv( wxT(
"KICAD_RUN_FROM_BUILD_DIR" ),
nullptr ) )
199#if defined( __WXMAC__ )
200 wxFileName fn = wxStandardPaths::Get().GetExecutablePath();
207#elif defined( __WXMSW__ )
208 path = getWindowsKiCadRoot();
213 else if( wxGetEnv( wxT(
"KICAD_STOCK_DATA_HOME" ), &
path ) && !
path.IsEmpty() )
219#if defined( __WXMAC__ )
220 path = GetOSXKicadDataDir();
221#elif defined( __WXMSW__ )
222 path = getWindowsKiCadRoot() + wxT(
"share/kicad" );
224 path = wxString::FromUTF8Unchecked( KICAD_DATA );
234wxString PATHS::GetWindowsBaseSharePath()
236 return getWindowsKiCadRoot() + wxT(
"share\\" );
246#if defined( __WXMAC__ )
247 path = GetOSXKicadMachineDataDir();
248#elif defined( __WXMSW__ )
251 path = wxString::FromUTF8Unchecked( KICAD_LIBRARY_DATA );
332#if defined( __WXMSW__ )
334 fn.AppendDir( wxT(
"scripting" ) );
338 fn.AppendDir( wxT(
"plugins" ) );
340 return fn.GetPathWithSep();
348#if defined( __WXMSW__ )
349 if( wxGetEnv( wxT(
"KICAD_RUN_FROM_BUILD_DIR" ),
nullptr ) )
351 fn.AssignDir( getWindowsKiCadRoot() );
358 fn.AppendDir( wxT(
"plugins" ) );
359#elif defined( __WXMAC__ )
360 fn.Assign( wxStandardPaths::Get().GetPluginsDir(), wxEmptyString );
363 const wxArrayString dirs = fn.GetDirs();
369 if( dirs.GetCount() >= 6 &&
370 dirs[dirs.GetCount() - 4] == wxT(
"Applications" ) &&
371 dirs[dirs.GetCount() - 6].Lower().EndsWith( wxT(
"app" ) ) )
377 fn.AppendDir( wxT(
"PlugIns" ) );
384 if( wxGetEnv( wxT(
"APPDIR" ), &envPath ) )
386 fn.Assign( envPath, wxEmptyString );
387 fn.AppendDir( wxT(
"usr" ) );
388 fn.AppendDir( wxT(
"lib" ) );
389 fn.AppendDir( wxT(
"x86_64-linux-gnu" ) );
395 wxString tfname = wxString::FromUTF8Unchecked( KICAD_PLUGINDIR );
396 fn.Assign( tfname,
"" );
399 fn.AppendDir( wxT(
"kicad" ) );
400 fn.AppendDir( wxT(
"plugins" ) );
403 fn.AppendDir( wxT(
"3d" ) );
405 return fn.GetPathWithSep();
414 fn.AppendDir( wxT(
"demos" ) );
416 return fn.GetPathWithSep();
428 if( wxGetEnv( wxT(
"KICAD_CACHE_HOME" ), &envPath ) && !envPath.IsEmpty() )
431 tmp.AssignDir( envPath );
437 return tmp.GetPathWithSep();
445#if defined( __WXMAC__ )
446 path = GetOSXKicadDataDir();
447#elif defined( __WXMSW__ )
448 path = getWindowsKiCadRoot() + wxT(
"share/doc/kicad" );
450 path = wxString::FromUTF8Unchecked( KICAD_DOCS );
460 path.AssignDir( wxStandardPaths::Get().GetTempDir() );
461 path.AppendDir(
"org.kicad.kicad" );
462 path.AppendDir(
"instances" );
463 return path.GetPathWithSep();
472 tmp.AppendDir( wxT(
"logs" ) );
474 return tmp.GetPath();
480 wxString pathString = aPath;
484 pathString += wxFileName::GetPathSeparator();
487 wxFileName
path( pathString );
488 if( !
path.MakeAbsolute() )
493 if( !wxFileName::DirExists(
path.GetPath() ) )
495 if( !wxFileName::Mkdir(
path.GetPath(), wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ) )
522 if( !tmp.DirExists() )
524 wxString msg = wxString::Format(
525 _(
"KiCad was unable to use '%s'.\n"
527 "1. Disable 'Controlled folder access' in Windows settings or Group Policy\n"
528 "2. Make sure no other antivirus software interferes with KiCad\n"
529 "3. Make sure you have correct permissions set up" ),
532 wxMessageBox( msg,
_(
"Warning" ), wxICON_WARNING );
539wxString PATHS::GetOSXKicadUserDataDir()
543 wxFileName udir( wxStandardPaths::Get().GetUserDataDir(), wxEmptyString );
547 udir.RemoveLastDir();
548 udir.AppendDir( wxT(
"kicad" ) );
550 return udir.GetPath();
554wxString PATHS::GetOSXKicadMachineDataDir()
557 return GetOSXKicadDataDir();
561wxString PATHS::GetOSXKicadDataDir()
565 wxFileName ddir( wxStandardPaths::Get().GetDataDir(), wxEmptyString );
568 const wxArrayString dirs = ddir.GetDirs();
574 if( dirs.GetCount() >= 6 &&
575 dirs[dirs.GetCount() - 4] == wxT(
"Applications" ) &&
576 dirs[dirs.GetCount() - 6].Lower().EndsWith( wxT(
"app" ) ) )
578 ddir.RemoveLastDir();
579 ddir.RemoveLastDir();
580 ddir.RemoveLastDir();
581 ddir.RemoveLastDir();
582 ddir.AppendDir( wxT(
"SharedSupport" ) );
585 return ddir.GetPath();
591wxString PATHS::GetWindowsFontConfigDir()
594 fn.AssignDir( getWindowsKiCadRoot() );
595 fn.AppendDir( wxS(
"etc" ) );
596 fn.AppendDir( wxS(
"fonts" ) );
598 return fn.GetPathWithSep();
602wxString PATHS::getWindowsKiCadRoot()
607 return root.GetPathWithSep();
614 static wxString user_settings_path;
616 if( user_settings_path.empty() )
619 return user_settings_path;
630 if( aUseEnv && wxGetEnv( wxT(
"KICAD_CONFIG_HOME" ), &envstr ) && !envstr.IsEmpty() )
633 cfgpath.AssignDir( envstr );
639 cfgpath.AppendDir(
TO_STR( KICAD_CONFIG_DIR ) );
645 return cfgpath.GetPath();
651 static wxString exe_path;
653 if( exe_path.empty() )
655 wxString bin_dir = wxStandardPaths::Get().GetExecutablePath();
661 wxFileName fn( bin_dir );
664 if( fn.GetName() == wxT(
"kicad" ) || fn.GetName() == wxT(
"kicad-cli" ) )
680 bin_dir = fn.GetPath() + wxT(
"/" );
688 while( bin_dir.Last() !=
'/' && !bin_dir.IsEmpty() )
689 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