2021-01-23 15:51:09 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation, either version 3 of the License, or (at your
|
|
|
|
* option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2021-01-23 02:23:37 +00:00
|
|
|
#include <wx/filename.h>
|
2021-01-23 16:59:19 +00:00
|
|
|
#include <wx/stdpaths.h>
|
2021-01-23 02:23:37 +00:00
|
|
|
#include <wx/string.h>
|
2021-04-02 23:29:47 +00:00
|
|
|
#include <wx/utils.h>
|
2021-01-23 02:23:37 +00:00
|
|
|
|
|
|
|
#include <kiplatform/environment.h>
|
|
|
|
#include <paths.h>
|
2021-01-23 04:27:39 +00:00
|
|
|
#include <pgm_base.h>
|
2021-01-23 02:23:37 +00:00
|
|
|
#include <settings/settings_manager.h>
|
2021-01-23 16:22:39 +00:00
|
|
|
#include <config.h>
|
2021-01-23 02:23:37 +00:00
|
|
|
|
2021-01-24 03:41:58 +00:00
|
|
|
// lowercase or pretty case depending on platform
|
|
|
|
#if defined( __WXMAC__ ) || defined( __WXMSW__ )
|
|
|
|
#define KICAD_PATH_STR "KiCad"
|
|
|
|
#else
|
|
|
|
#define KICAD_PATH_STR "kicad"
|
|
|
|
#endif
|
2021-01-23 04:35:09 +00:00
|
|
|
|
2021-01-28 02:06:13 +00:00
|
|
|
|
|
|
|
void PATHS::getUserDocumentPath( wxFileName& aPath )
|
|
|
|
{
|
2021-02-17 01:44:42 +00:00
|
|
|
wxString envPath;
|
|
|
|
|
|
|
|
if( wxGetEnv( wxT( "KICAD_DOCUMENTS_HOME" ), &envPath ) )
|
|
|
|
aPath.AssignDir( envPath );
|
|
|
|
else
|
|
|
|
aPath.AssignDir( KIPLATFORM::ENV::GetDocumentsPath() );
|
|
|
|
|
2021-01-28 02:06:13 +00:00
|
|
|
aPath.AppendDir( KICAD_PATH_STR );
|
|
|
|
aPath.AppendDir( SETTINGS_MANAGER::GetSettingsVersion() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-23 15:46:48 +00:00
|
|
|
wxString PATHS::GetUserPluginsPath()
|
|
|
|
{
|
|
|
|
wxFileName tmp;
|
2021-01-28 02:06:13 +00:00
|
|
|
getUserDocumentPath( tmp );
|
2021-01-23 15:46:48 +00:00
|
|
|
|
|
|
|
tmp.AppendDir( "plugins" );
|
|
|
|
|
2021-01-28 02:06:13 +00:00
|
|
|
return tmp.GetPath();
|
2021-01-23 15:46:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString PATHS::GetUserPlugins3DPath()
|
|
|
|
{
|
|
|
|
wxFileName tmp;
|
|
|
|
|
|
|
|
tmp.AssignDir( PATHS::GetUserPluginsPath() );
|
|
|
|
tmp.AppendDir( "3d" );
|
|
|
|
|
2021-01-28 02:06:13 +00:00
|
|
|
return tmp.GetPath();
|
2021-01-23 15:46:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-23 02:23:37 +00:00
|
|
|
wxString PATHS::GetUserScriptingPath()
|
|
|
|
{
|
|
|
|
wxFileName tmp;
|
2021-01-28 02:06:13 +00:00
|
|
|
getUserDocumentPath( tmp );
|
2021-01-23 02:23:37 +00:00
|
|
|
|
|
|
|
tmp.AppendDir( "scripting" );
|
|
|
|
|
2021-01-28 02:06:13 +00:00
|
|
|
return tmp.GetPath();
|
2021-01-23 02:23:37 +00:00
|
|
|
}
|
|
|
|
|
2021-01-23 04:17:32 +00:00
|
|
|
|
2021-01-23 02:23:37 +00:00
|
|
|
wxString PATHS::GetUserTemplatesPath()
|
|
|
|
{
|
|
|
|
wxFileName tmp;
|
2021-01-28 02:06:13 +00:00
|
|
|
getUserDocumentPath( tmp );
|
2021-01-23 02:23:37 +00:00
|
|
|
|
2021-01-23 21:46:09 +00:00
|
|
|
tmp.AppendDir( "template" );
|
2021-01-23 02:23:37 +00:00
|
|
|
|
2021-02-01 04:57:41 +00:00
|
|
|
return tmp.GetPathWithSep();
|
2021-01-28 02:06:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString PATHS::GetDefaultUserSymbolsPath()
|
|
|
|
{
|
|
|
|
wxFileName tmp;
|
|
|
|
getUserDocumentPath( tmp );
|
|
|
|
|
|
|
|
tmp.AppendDir( "symbols" );
|
|
|
|
|
|
|
|
return tmp.GetPath();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString PATHS::GetDefaultUserFootprintsPath()
|
|
|
|
{
|
|
|
|
wxFileName tmp;
|
|
|
|
getUserDocumentPath( tmp );
|
|
|
|
|
|
|
|
tmp.AppendDir( "footprints" );
|
|
|
|
|
|
|
|
return tmp.GetPath();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString PATHS::GetDefaultUser3DModelsPath()
|
|
|
|
{
|
|
|
|
wxFileName tmp;
|
|
|
|
getUserDocumentPath( tmp );
|
|
|
|
|
|
|
|
tmp.AppendDir( "3dmodels" );
|
|
|
|
|
|
|
|
return tmp.GetPath();
|
2021-01-23 04:17:32 +00:00
|
|
|
}
|
|
|
|
|
2020-12-08 18:39:45 +00:00
|
|
|
wxString PATHS::GetDefault3rdPartyPath()
|
|
|
|
{
|
|
|
|
wxFileName tmp;
|
|
|
|
getUserDocumentPath( tmp );
|
|
|
|
|
|
|
|
tmp.AppendDir( "3rdparty" );
|
|
|
|
|
|
|
|
return tmp.GetPath();
|
|
|
|
}
|
2021-01-23 04:17:32 +00:00
|
|
|
|
|
|
|
wxString PATHS::GetDefaultUserProjectsPath()
|
|
|
|
{
|
|
|
|
wxFileName tmp;
|
2021-01-28 02:06:13 +00:00
|
|
|
getUserDocumentPath( tmp );
|
2021-01-23 04:17:32 +00:00
|
|
|
|
|
|
|
tmp.AppendDir( "projects" );
|
|
|
|
|
2021-01-28 02:06:13 +00:00
|
|
|
return tmp.GetPath();
|
2021-01-23 04:27:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-20 15:41:34 +00:00
|
|
|
wxString PATHS::GetStockDataPath( bool aRespectRunFromBuildDir )
|
2021-01-23 04:27:39 +00:00
|
|
|
{
|
|
|
|
wxString path;
|
|
|
|
|
2021-03-20 15:41:34 +00:00
|
|
|
if( aRespectRunFromBuildDir && wxGetEnv( wxT( "KICAD_RUN_FROM_BUILD_DIR" ), nullptr ) )
|
2021-01-23 04:27:39 +00:00
|
|
|
{
|
2021-03-08 02:59:07 +00:00
|
|
|
// Allow debugging from build dir by placing relevant files/folders in the build root
|
2021-04-29 03:21:19 +00:00
|
|
|
#if defined( __WXMAC__ )
|
|
|
|
wxFileName fn = wxStandardPaths::Get().GetExecutablePath();
|
|
|
|
|
|
|
|
fn.RemoveLastDir();
|
|
|
|
fn.RemoveLastDir();
|
|
|
|
fn.RemoveLastDir();
|
|
|
|
fn.RemoveLastDir();
|
|
|
|
path = fn.GetPath();
|
2021-06-21 22:05:38 +00:00
|
|
|
#elif defined( __WXMSW__ )
|
2021-06-21 22:03:44 +00:00
|
|
|
path = getWindowsKiCadRoot();
|
2021-06-21 22:05:38 +00:00
|
|
|
#else
|
|
|
|
path = Pgm().GetExecutablePath() + wxT( ".." );
|
2021-04-29 03:21:19 +00:00
|
|
|
#endif
|
2021-01-23 04:27:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
#if defined( __WXMAC__ )
|
2021-03-08 02:59:07 +00:00
|
|
|
path = GetOSXKicadDataDir();
|
2021-01-23 04:27:39 +00:00
|
|
|
#elif defined( __WXMSW__ )
|
2021-06-21 22:03:44 +00:00
|
|
|
path = getWindowsKiCadRoot() + wxT( "share/kicad" );
|
2021-01-23 04:27:39 +00:00
|
|
|
#else
|
2021-03-08 02:59:07 +00:00
|
|
|
path = wxString::FromUTF8Unchecked( KICAD_DATA );
|
2021-01-23 04:27:39 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
return path;
|
2021-01-23 15:46:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-29 13:37:11 +00:00
|
|
|
wxString PATHS::GetStockEDALibraryPath()
|
|
|
|
{
|
|
|
|
wxString path;
|
|
|
|
|
|
|
|
#if defined( __WXMAC__ )
|
|
|
|
path = GetOSXKicadMachineDataDir();
|
|
|
|
#elif defined( __WXMSW__ )
|
|
|
|
path = GetStockDataPath( false );
|
|
|
|
#else
|
|
|
|
path = wxString::FromUTF8Unchecked( KICAD_LIBRARY_DATA );
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-12-02 01:23:34 +00:00
|
|
|
wxString PATHS::GetStockSymbolsPath()
|
|
|
|
{
|
|
|
|
wxString path;
|
|
|
|
|
|
|
|
path = GetStockDataPath() + wxT( "/symbols" );
|
|
|
|
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString PATHS::GetStockFootprintsPath()
|
|
|
|
{
|
|
|
|
wxString path;
|
|
|
|
|
|
|
|
path = GetStockDataPath() + wxT( "/footprints" );
|
|
|
|
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString PATHS::GetStock3dmodelsPath()
|
|
|
|
{
|
|
|
|
wxString path;
|
|
|
|
|
|
|
|
path = GetStockDataPath() + wxT( "/3dmodels" );
|
|
|
|
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-08 02:59:07 +00:00
|
|
|
wxString PATHS::GetStockScriptingPath()
|
|
|
|
{
|
|
|
|
wxString path;
|
|
|
|
|
2021-03-20 15:41:34 +00:00
|
|
|
path = GetStockDataPath() + wxT( "/scripting" );
|
2021-03-08 02:59:07 +00:00
|
|
|
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-23 15:46:48 +00:00
|
|
|
wxString PATHS::GetStockPluginsPath()
|
|
|
|
{
|
|
|
|
wxFileName fn;
|
|
|
|
|
2021-03-20 15:41:34 +00:00
|
|
|
#if defined( __WXMSW__ )
|
|
|
|
fn.AssignDir( Pgm().GetExecutablePath() );
|
2021-04-09 02:16:20 +00:00
|
|
|
fn.AppendDir( wxT( "scripting" ) );
|
2021-01-23 15:46:48 +00:00
|
|
|
#else
|
2021-03-20 15:41:34 +00:00
|
|
|
fn.AssignDir( PATHS::GetStockDataPath( false ) );
|
2021-01-23 15:46:48 +00:00
|
|
|
#endif
|
2021-03-20 15:41:34 +00:00
|
|
|
fn.AppendDir( wxT( "plugins" ) );
|
2021-01-23 15:46:48 +00:00
|
|
|
|
|
|
|
return fn.GetPathWithSep();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString PATHS::GetStockPlugins3DPath()
|
|
|
|
{
|
|
|
|
wxFileName fn;
|
|
|
|
|
2021-03-08 13:49:21 +00:00
|
|
|
#ifdef __WXGTK__
|
2021-03-01 20:02:47 +00:00
|
|
|
// KICAD_PLUGINDIR = CMAKE_INSTALL_FULL_LIBDIR path is the absolute path
|
|
|
|
// corresponding to the install path used for constructing KICAD_USER_PLUGIN
|
|
|
|
wxString tfname = wxString::FromUTF8Unchecked( KICAD_PLUGINDIR );
|
|
|
|
fn.Assign( tfname, "" );
|
|
|
|
fn.AppendDir( wxT( "kicad" ) );
|
|
|
|
fn.AppendDir( wxT( "plugins" ) );
|
2021-03-29 21:07:37 +00:00
|
|
|
#elif defined( __WXMAC__ )
|
|
|
|
fn.Assign( wxStandardPaths::Get().GetPluginsDir(), wxEmptyString );
|
2021-03-01 20:02:47 +00:00
|
|
|
#else
|
2021-04-09 02:16:20 +00:00
|
|
|
fn.AssignDir( Pgm().GetExecutablePath() );
|
|
|
|
fn.AppendDir( wxT( "plugins" ) );
|
2021-03-01 20:02:47 +00:00
|
|
|
#endif
|
|
|
|
|
2021-01-23 15:46:48 +00:00
|
|
|
fn.AppendDir( "3d" );
|
|
|
|
|
|
|
|
return fn.GetPathWithSep();
|
2021-01-23 16:59:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-26 01:58:44 +00:00
|
|
|
wxString PATHS::GetStockDemosPath()
|
|
|
|
{
|
|
|
|
wxFileName fn;
|
|
|
|
|
|
|
|
fn.AssignDir( PATHS::GetStockDataPath( false ) );
|
|
|
|
fn.AppendDir( wxT( "demos" ) );
|
|
|
|
|
|
|
|
return fn.GetPathWithSep();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-23 16:59:19 +00:00
|
|
|
wxString PATHS::GetUserCachePath()
|
|
|
|
{
|
|
|
|
wxFileName tmp;
|
|
|
|
|
2021-01-28 00:11:39 +00:00
|
|
|
tmp.AssignDir( KIPLATFORM::ENV::GetUserCachePath() );
|
2021-01-24 03:41:58 +00:00
|
|
|
tmp.AppendDir( KICAD_PATH_STR );
|
2021-01-23 16:59:19 +00:00
|
|
|
tmp.AppendDir( SETTINGS_MANAGER::GetSettingsVersion() );
|
|
|
|
|
|
|
|
return tmp.GetPathWithSep();
|
2021-01-28 02:06:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-04-05 17:05:42 +00:00
|
|
|
wxString PATHS::GetDocumentationPath()
|
|
|
|
{
|
|
|
|
wxString path;
|
|
|
|
|
|
|
|
#if defined( __WXMAC__ )
|
|
|
|
path = GetOSXKicadDataDir();
|
|
|
|
#elif defined( __WXMSW__ )
|
2021-06-21 22:03:44 +00:00
|
|
|
path = getWindowsKiCadRoot() + "share/doc/kicad";
|
2021-04-05 17:05:42 +00:00
|
|
|
#else
|
|
|
|
path = wxString::FromUTF8Unchecked( KICAD_DOCS );
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-28 02:06:13 +00:00
|
|
|
bool PATHS::EnsurePathExists( const wxString& aPath )
|
|
|
|
{
|
|
|
|
wxFileName path( aPath );
|
|
|
|
if( !path.Normalize() )
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !wxFileName::DirExists( aPath ) )
|
|
|
|
{
|
|
|
|
if( !wxFileName::Mkdir( aPath, wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ) )
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PATHS::EnsureUserPathsExist()
|
|
|
|
{
|
|
|
|
EnsurePathExists( GetUserPluginsPath() );
|
|
|
|
EnsurePathExists( GetUserPlugins3DPath() );
|
|
|
|
EnsurePathExists( GetUserScriptingPath() );
|
2021-02-01 04:57:41 +00:00
|
|
|
EnsurePathExists( GetUserTemplatesPath() );
|
2021-01-28 02:06:13 +00:00
|
|
|
EnsurePathExists( GetDefaultUserProjectsPath() );
|
|
|
|
EnsurePathExists( GetDefaultUserSymbolsPath() );
|
|
|
|
EnsurePathExists( GetDefaultUserFootprintsPath() );
|
|
|
|
EnsurePathExists( GetDefaultUser3DModelsPath() );
|
2020-12-08 18:39:45 +00:00
|
|
|
EnsurePathExists( GetDefault3rdPartyPath() );
|
2021-02-17 01:44:42 +00:00
|
|
|
}
|
2021-02-17 04:26:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
#ifdef __WXMAC__
|
|
|
|
wxString PATHS::GetOSXKicadUserDataDir()
|
|
|
|
{
|
|
|
|
// According to wxWidgets documentation for GetUserDataDir:
|
|
|
|
// Mac: ~/Library/Application Support/appname
|
|
|
|
wxFileName udir( wxStandardPaths::Get().GetUserDataDir(), wxEmptyString );
|
|
|
|
|
|
|
|
// Since appname is different if started via launcher or standalone binary
|
|
|
|
// map all to "kicad" here
|
|
|
|
udir.RemoveLastDir();
|
|
|
|
udir.AppendDir( "kicad" );
|
|
|
|
|
|
|
|
return udir.GetPath();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString PATHS::GetOSXKicadMachineDataDir()
|
|
|
|
{
|
2021-11-13 00:24:49 +00:00
|
|
|
// 6.0 forward: Same as the main data dir
|
|
|
|
return GetOSXKicadDataDir();
|
2021-02-17 04:26:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString PATHS::GetOSXKicadDataDir()
|
|
|
|
{
|
|
|
|
// According to wxWidgets documentation for GetDataDir:
|
|
|
|
// Mac: appname.app/Contents/SharedSupport bundle subdirectory
|
|
|
|
wxFileName ddir( wxStandardPaths::Get().GetDataDir(), wxEmptyString );
|
|
|
|
|
|
|
|
// This must be mapped to main bundle for everything but kicad.app
|
|
|
|
const wxArrayString dirs = ddir.GetDirs();
|
2021-08-13 20:37:15 +00:00
|
|
|
|
|
|
|
// Check if we are the main kicad binary. in this case, the path will be
|
|
|
|
// /path/to/bundlename.app/Contents/SharedSupport
|
|
|
|
// If we are an aux binary, the path will be something like
|
|
|
|
// /path/to/bundlename.app/Contents/Applications/<standalone>.app/Contents/SharedSupport
|
|
|
|
if( dirs.GetCount() >= 6 &&
|
|
|
|
dirs[dirs.GetCount() - 4] == wxT( "Applications" ) &&
|
|
|
|
dirs[dirs.GetCount() - 6].Lower().EndsWith( wxT( "app" ) ) )
|
2021-02-17 04:26:46 +00:00
|
|
|
{
|
|
|
|
ddir.RemoveLastDir();
|
|
|
|
ddir.RemoveLastDir();
|
|
|
|
ddir.RemoveLastDir();
|
|
|
|
ddir.RemoveLastDir();
|
|
|
|
ddir.AppendDir( wxT( "SharedSupport" ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
return ddir.GetPath();
|
|
|
|
}
|
2021-02-27 00:00:39 +00:00
|
|
|
#endif
|
2021-06-21 22:03:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
#ifdef __WXWINDOWS__
|
|
|
|
wxString PATHS::getWindowsKiCadRoot()
|
|
|
|
{
|
2021-06-21 22:05:38 +00:00
|
|
|
wxFileName root( Pgm().GetExecutablePath() + "/../" );
|
2021-06-21 22:07:07 +00:00
|
|
|
root.Normalize();
|
2021-06-21 22:03:44 +00:00
|
|
|
|
|
|
|
return root.GetPathWithSep();
|
|
|
|
}
|
|
|
|
#endif
|