21#include <wx/filename.h> 
   22#include <wx/stdpaths.h> 
   38    if( wxGetEnv( wxT( 
"KICAD_DOCUMENTS_HOME" ), &envPath ) )
 
   39        aPath.AssignDir( envPath );
 
 
   53    tmp.AppendDir( wxT( 
"plugins" ) );
 
 
   64    tmp.AppendDir( wxT( 
"scripting" ) );
 
 
   75    tmp.AppendDir( wxT( 
"template" ) );
 
   77    return tmp.GetPathWithSep();
 
 
   86    tmp.AppendDir( wxT( 
"symbols" ) );
 
 
   97    tmp.AppendDir( wxT( 
"footprints" ) );
 
 
  108    tmp.AppendDir( wxT( 
"blocks" ) );
 
  110    return tmp.GetPath();
 
 
  119    tmp.AppendDir( wxT( 
"3dmodels" ) );
 
  121    return tmp.GetPath();
 
 
  130    tmp.AppendDir( wxT( 
"3rdparty" ) );
 
  132    return tmp.GetAbsolutePath();
 
 
  141    tmp.AppendDir( wxT( 
"projects" ) );
 
  143    return tmp.GetPath();
 
 
  147#if !defined( __WXMAC__ ) && !defined( __WXMSW__ ) 
  160    const auto looksLikeBuildDir = []( 
const wxFileName& aPath ) -> 
bool 
  162        const wxDir schema_dir( aPath.GetPathWithSep() + wxT( 
"schemas" ) );
 
  164        if( !schema_dir.IsOpened() )
 
  168        const bool found = schema_dir.GetFirst( &filename, wxT( 
"*.json" ), wxDIR_FILES );
 
  173    wxFileName     fn = execPath;
 
  177    while( fn.GetDirCount() > 0 && !looksLikeBuildDir( fn ) )
 
  183            fn.GetDirCount() > 0,
 
  184            wxString::Format( wxT( 
"Could not find build root directory above %s" ), execPath ) );
 
 
  195    if( aRespectRunFromBuildDir && wxGetEnv( wxT( 
"KICAD_RUN_FROM_BUILD_DIR" ), 
nullptr ) )
 
  198#if defined( __WXMAC__ ) 
  199        wxFileName fn = wxStandardPaths::Get().GetExecutablePath();
 
  206#elif defined( __WXMSW__ ) 
  207        path = getWindowsKiCadRoot();
 
  212    else if( wxGetEnv( wxT( 
"KICAD_STOCK_DATA_HOME" ), &
path ) && !
path.IsEmpty() )
 
  218#if defined( __WXMAC__ ) 
  219        path = GetOSXKicadDataDir();
 
  220#elif defined( __WXMSW__ ) 
  221        path = getWindowsKiCadRoot() + wxT( 
"share/kicad" );
 
  223        path = wxString::FromUTF8Unchecked( KICAD_DATA );
 
 
  233wxString PATHS::GetWindowsBaseSharePath()
 
  235    return getWindowsKiCadRoot() + wxT( 
"share\\" );
 
  245#if defined( __WXMAC__ ) 
  246    path = GetOSXKicadMachineDataDir();
 
  247#elif defined( __WXMSW__ ) 
  250    path = wxString::FromUTF8Unchecked( KICAD_LIBRARY_DATA );
 
 
  331#if defined( __WXMSW__ ) 
  333    fn.AppendDir( wxT( 
"scripting" ) );
 
  337    fn.AppendDir( wxT( 
"plugins" ) );
 
  339    return fn.GetPathWithSep();
 
 
  347#if defined( __WXMSW__ ) 
  348    if( wxGetEnv( wxT( 
"KICAD_RUN_FROM_BUILD_DIR" ), 
nullptr ) )
 
  350        fn.AssignDir( getWindowsKiCadRoot() );
 
  357    fn.AppendDir( wxT( 
"plugins" ) );
 
  358#elif defined( __WXMAC__ ) 
  359    fn.Assign( wxStandardPaths::Get().GetPluginsDir(), wxEmptyString );
 
  362    const wxArrayString dirs = fn.GetDirs();
 
  368    if( dirs.GetCount() >= 6 &&
 
  369        dirs[dirs.GetCount() - 4] == wxT( 
"Applications" ) &&
 
  370        dirs[dirs.GetCount() - 6].Lower().EndsWith( wxT( 
"app" ) ) )
 
  376        fn.AppendDir( wxT( 
"PlugIns" ) );
 
  383    if( wxGetEnv( wxT( 
"APPDIR" ), &envPath ) )
 
  385        fn.Assign( envPath, wxEmptyString );
 
  386        fn.AppendDir( wxT( 
"usr" ) );
 
  387        fn.AppendDir( wxT( 
"lib" ) );
 
  388        fn.AppendDir( wxT( 
"x86_64-linux-gnu" ) );
 
  394        wxString tfname = wxString::FromUTF8Unchecked( KICAD_PLUGINDIR );
 
  395        fn.Assign( tfname, 
"" );
 
  398    fn.AppendDir( wxT( 
"kicad" ) );
 
  399    fn.AppendDir( wxT( 
"plugins" ) );
 
  402    fn.AppendDir( wxT( 
"3d" ) );
 
  404    return fn.GetPathWithSep();
 
 
  413    fn.AppendDir( wxT( 
"demos" ) );
 
  415    return fn.GetPathWithSep();
 
 
  427    if( wxGetEnv( wxT( 
"KICAD_CACHE_HOME" ), &envPath ) && !envPath.IsEmpty() )
 
  430        tmp.AssignDir( envPath );
 
  436    return tmp.GetPathWithSep();
 
 
  444#if defined( __WXMAC__ ) 
  445    path = GetOSXKicadDataDir();
 
  446#elif defined( __WXMSW__ ) 
  447    path = getWindowsKiCadRoot() + wxT( 
"share/doc/kicad" );
 
  449    path = wxString::FromUTF8Unchecked( KICAD_DOCS );
 
 
  459    path.AssignDir( wxStandardPaths::Get().GetTempDir() );
 
  460    path.AppendDir( 
"org.kicad.kicad" );
 
  461    path.AppendDir( 
"instances" );
 
  462    return path.GetPathWithSep();
 
 
  471    tmp.AppendDir( wxT( 
"logs" ) );
 
  473    return tmp.GetPath();
 
 
  479    wxString   pathString = aPath;
 
  483        pathString += wxFileName::GetPathSeparator();
 
  486    wxFileName 
path( pathString );
 
  487    if( !
path.MakeAbsolute() )
 
  492    if( !wxFileName::DirExists( 
path.GetPath() ) )
 
  494        if( !wxFileName::Mkdir( 
path.GetPath(), wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ) )
 
 
  519wxString PATHS::GetOSXKicadUserDataDir()
 
  523    wxFileName udir( wxStandardPaths::Get().GetUserDataDir(), wxEmptyString );
 
  527    udir.RemoveLastDir();
 
  528    udir.AppendDir(  wxT( 
"kicad" ) );
 
  530    return udir.GetPath();
 
  534wxString PATHS::GetOSXKicadMachineDataDir()
 
  537    return GetOSXKicadDataDir();
 
  541wxString PATHS::GetOSXKicadDataDir()
 
  545    wxFileName ddir( wxStandardPaths::Get().GetDataDir(), wxEmptyString );
 
  548    const wxArrayString dirs = ddir.GetDirs();
 
  554    if( dirs.GetCount() >= 6 &&
 
  555        dirs[dirs.GetCount() - 4] == wxT( 
"Applications" ) &&
 
  556        dirs[dirs.GetCount() - 6].Lower().EndsWith( wxT( 
"app" ) ) )
 
  558        ddir.RemoveLastDir();
 
  559        ddir.RemoveLastDir();
 
  560        ddir.RemoveLastDir();
 
  561        ddir.RemoveLastDir();
 
  562        ddir.AppendDir( wxT( 
"SharedSupport" ) );
 
  565    return ddir.GetPath();
 
  571wxString PATHS::GetWindowsFontConfigDir()
 
  574    fn.AssignDir( getWindowsKiCadRoot() );
 
  575    fn.AppendDir( wxS( 
"etc" ) );
 
  576    fn.AppendDir( wxS( 
"fonts" ) );
 
  578    return fn.GetPathWithSep();
 
  582wxString PATHS::getWindowsKiCadRoot()
 
  587    return root.GetPathWithSep();
 
  594    static wxString user_settings_path;
 
  596    if( user_settings_path.empty() )
 
  599    return user_settings_path;
 
 
  610    if( aUseEnv && wxGetEnv( wxT( 
"KICAD_CONFIG_HOME" ), &envstr ) && !envstr.IsEmpty() )
 
  613        cfgpath.AssignDir( envstr );
 
  619        cfgpath.AppendDir( 
TO_STR( KICAD_CONFIG_DIR ) );
 
  625    return cfgpath.GetPath();
 
 
  631    static wxString exe_path;
 
  633    if( exe_path.empty() )
 
  635        wxString bin_dir = wxStandardPaths::Get().GetExecutablePath();
 
  641        wxFileName fn( bin_dir );
 
  644        if( fn.GetName() == wxT( 
"kicad" ) || fn.GetName() == wxT( 
"kicad-cli" ) )
 
  660        bin_dir = fn.GetPath() + wxT( 
"/" );
 
  668        while( bin_dir.Last() != 
'/' && !bin_dir.IsEmpty() )
 
  669            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