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 16:22:39 +00:00
|
|
|
#include <config.h>
|
2023-09-23 23:53:22 +00:00
|
|
|
#include <build_version.h>
|
|
|
|
#include <macros.h>
|
2023-11-15 14:25:38 +00:00
|
|
|
#include <wx_filename.h>
|
2021-01-23 02:23:37 +00:00
|
|
|
|
2021-01-24 03:41:58 +00:00
|
|
|
// lowercase or pretty case depending on platform
|
2022-01-31 23:57:56 +00:00
|
|
|
#if defined( __WXMAC__ ) || defined( __WXMSW__ )
|
2022-02-21 23:49:36 +00:00
|
|
|
#define KICAD_PATH_STR wxT( "KiCad" )
|
2021-01-24 03:41:58 +00:00
|
|
|
#else
|
2022-02-21 23:49:36 +00:00
|
|
|
#define KICAD_PATH_STR wxT( "kicad" )
|
2021-01-24 03:41:58 +00:00
|
|
|
#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 );
|
2023-09-23 23:53:22 +00:00
|
|
|
aPath.AppendDir( GetMajorMinorVersion().ToStdString() );
|
2021-01-28 02:06:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2022-02-21 23:49:36 +00:00
|
|
|
tmp.AppendDir( wxT( "plugins" ) );
|
2021-01-23 15:46:48 +00:00
|
|
|
|
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() );
|
2022-02-21 23:49:36 +00:00
|
|
|
tmp.AppendDir( wxT( "3d" ) );
|
2021-01-23 15:46:48 +00:00
|
|
|
|
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
|
|
|
|
2022-02-21 23:49:36 +00:00
|
|
|
tmp.AppendDir( wxT( "scripting" ) );
|
2021-01-23 02:23:37 +00:00
|
|
|
|
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
|
|
|
|
2022-02-21 23:49:36 +00:00
|
|
|
tmp.AppendDir( wxT( "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 );
|
|
|
|
|
2022-02-21 23:49:36 +00:00
|
|
|
tmp.AppendDir( wxT( "symbols" ) );
|
2021-01-28 02:06:13 +00:00
|
|
|
|
|
|
|
return tmp.GetPath();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString PATHS::GetDefaultUserFootprintsPath()
|
|
|
|
{
|
|
|
|
wxFileName tmp;
|
|
|
|
getUserDocumentPath( tmp );
|
|
|
|
|
2022-02-21 23:49:36 +00:00
|
|
|
tmp.AppendDir( wxT( "footprints" ) );
|
2021-01-28 02:06:13 +00:00
|
|
|
|
|
|
|
return tmp.GetPath();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString PATHS::GetDefaultUser3DModelsPath()
|
|
|
|
{
|
|
|
|
wxFileName tmp;
|
|
|
|
getUserDocumentPath( tmp );
|
|
|
|
|
2022-02-21 23:49:36 +00:00
|
|
|
tmp.AppendDir( wxT( "3dmodels" ) );
|
2021-01-28 02:06:13 +00:00
|
|
|
|
|
|
|
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 );
|
|
|
|
|
2022-02-21 23:49:36 +00:00
|
|
|
tmp.AppendDir( wxT( "3rdparty" ) );
|
2020-12-08 18:39:45 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
2022-02-21 23:49:36 +00:00
|
|
|
tmp.AppendDir( wxT( "projects" ) );
|
2021-01-23 04:17:32 +00:00
|
|
|
|
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
|
2022-01-31 23:57:56 +00:00
|
|
|
#if defined( __WXMAC__ )
|
2021-04-29 03:21:19 +00:00
|
|
|
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
|
2023-09-24 00:21:37 +00:00
|
|
|
path = GetExecutablePath() + wxT( ".." );
|
2021-04-29 03:21:19 +00:00
|
|
|
#endif
|
2021-01-23 04:27:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-01-31 23:57:56 +00:00
|
|
|
#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
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-01-16 03:08:17 +00:00
|
|
|
#ifdef __WXMSW__
|
|
|
|
/**
|
|
|
|
* Gets the stock (install) data path, which is the base path for things like scripting, etc
|
|
|
|
*/
|
|
|
|
wxString PATHS::GetWindowsBaseSharePath()
|
|
|
|
{
|
|
|
|
return getWindowsKiCadRoot() + wxT( "share\\" );
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2021-03-29 13:37:11 +00:00
|
|
|
wxString PATHS::GetStockEDALibraryPath()
|
|
|
|
{
|
|
|
|
wxString path;
|
|
|
|
|
2022-01-31 23:57:56 +00:00
|
|
|
#if defined( __WXMAC__ )
|
2021-03-29 13:37:11 +00:00
|
|
|
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;
|
|
|
|
|
2022-03-24 21:02:05 +00:00
|
|
|
path = GetStockEDALibraryPath() + wxT( "/symbols" );
|
2021-12-02 01:23:34 +00:00
|
|
|
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString PATHS::GetStockFootprintsPath()
|
|
|
|
{
|
|
|
|
wxString path;
|
|
|
|
|
2022-03-24 21:02:05 +00:00
|
|
|
path = GetStockEDALibraryPath() + wxT( "/footprints" );
|
2021-12-02 01:23:34 +00:00
|
|
|
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString PATHS::GetStock3dmodelsPath()
|
|
|
|
{
|
|
|
|
wxString path;
|
|
|
|
|
2022-03-24 21:02:05 +00:00
|
|
|
path = GetStockEDALibraryPath() + wxT( "/3dmodels" );
|
2021-12-02 01:23:34 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-02-21 17:21:20 +00:00
|
|
|
wxString PATHS::GetStockTemplatesPath()
|
|
|
|
{
|
|
|
|
wxString path;
|
|
|
|
|
2022-03-24 21:02:05 +00:00
|
|
|
path = GetStockEDALibraryPath() + wxT( "/template" );
|
2022-02-21 17:21:20 +00:00
|
|
|
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-02-21 18:04:08 +00:00
|
|
|
wxString PATHS::GetLocaleDataPath()
|
|
|
|
{
|
|
|
|
wxString path;
|
|
|
|
|
|
|
|
path = GetStockDataPath() + wxT( "/internat" );
|
|
|
|
|
|
|
|
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__ )
|
2023-09-24 00:21:37 +00:00
|
|
|
fn.AssignDir( 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" ) );
|
2022-01-31 23:57:56 +00:00
|
|
|
#elif defined( __WXMAC__ )
|
2021-03-29 21:07:37 +00:00
|
|
|
fn.Assign( wxStandardPaths::Get().GetPluginsDir(), wxEmptyString );
|
2023-09-25 17:02:54 +00:00
|
|
|
|
|
|
|
// This must be mapped to main bundle for everything but kicad.app
|
|
|
|
const wxArrayString dirs = fn.GetDirs();
|
|
|
|
|
|
|
|
// Check if we are the main kicad binary. in this case, the path will be
|
|
|
|
// /path/to/bundlename.app/Contents/PlugIns
|
|
|
|
// If we are an aux binary, the path will be something like
|
|
|
|
// /path/to/bundlename.app/Contents/Applications/<standalone>.app/Contents/PlugIns
|
|
|
|
if( dirs.GetCount() >= 6 &&
|
|
|
|
dirs[dirs.GetCount() - 4] == wxT( "Applications" ) &&
|
|
|
|
dirs[dirs.GetCount() - 6].Lower().EndsWith( wxT( "app" ) ) )
|
|
|
|
{
|
|
|
|
fn.RemoveLastDir();
|
|
|
|
fn.RemoveLastDir();
|
|
|
|
fn.RemoveLastDir();
|
|
|
|
fn.RemoveLastDir();
|
|
|
|
fn.AppendDir( wxT( "PlugIns" ) );
|
|
|
|
}
|
2021-03-01 20:02:47 +00:00
|
|
|
#else
|
2022-09-09 01:44:02 +00:00
|
|
|
if( wxGetEnv( wxT( "KICAD_RUN_FROM_BUILD_DIR" ), nullptr ) )
|
|
|
|
{
|
|
|
|
fn.AssignDir( getWindowsKiCadRoot() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-09-24 00:21:37 +00:00
|
|
|
fn.AssignDir( GetExecutablePath() );
|
2022-09-09 01:44:02 +00:00
|
|
|
}
|
|
|
|
|
2021-04-09 02:16:20 +00:00
|
|
|
fn.AppendDir( wxT( "plugins" ) );
|
2021-03-01 20:02:47 +00:00
|
|
|
#endif
|
|
|
|
|
2022-02-21 23:49:36 +00:00
|
|
|
fn.AppendDir( wxT( "3d" ) );
|
2021-01-23 15:46:48 +00:00
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
2023-06-22 13:35:48 +00:00
|
|
|
wxString envPath;
|
2021-01-23 16:59:19 +00:00
|
|
|
wxFileName tmp;
|
|
|
|
|
2021-01-28 00:11:39 +00:00
|
|
|
tmp.AssignDir( KIPLATFORM::ENV::GetUserCachePath() );
|
2023-06-22 13:35:48 +00:00
|
|
|
|
|
|
|
// Use KICAD_CACHE_HOME to allow the user to force a specific cache path.
|
|
|
|
if( wxGetEnv( wxT( "KICAD_CACHE_HOME" ), &envPath ) && !envPath.IsEmpty() )
|
|
|
|
{
|
|
|
|
// Override the assignment above with KICAD_CACHE_HOME
|
|
|
|
tmp.AssignDir( envPath );
|
|
|
|
}
|
|
|
|
|
2021-01-24 03:41:58 +00:00
|
|
|
tmp.AppendDir( KICAD_PATH_STR );
|
2023-09-23 23:53:22 +00:00
|
|
|
tmp.AppendDir( GetMajorMinorVersion().ToStdString() );
|
2021-01-23 16:59:19 +00:00
|
|
|
|
|
|
|
return tmp.GetPathWithSep();
|
2021-01-28 02:06:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-04-05 17:05:42 +00:00
|
|
|
wxString PATHS::GetDocumentationPath()
|
|
|
|
{
|
|
|
|
wxString path;
|
|
|
|
|
2022-01-31 23:57:56 +00:00
|
|
|
#if defined( __WXMAC__ )
|
2021-04-05 17:05:42 +00:00
|
|
|
path = GetOSXKicadDataDir();
|
|
|
|
#elif defined( __WXMSW__ )
|
2022-02-21 23:49:36 +00:00
|
|
|
path = getWindowsKiCadRoot() + wxT( "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 );
|
2022-07-06 00:47:29 +00:00
|
|
|
if( !path.MakeAbsolute() )
|
2021-01-28 02:06:13 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !wxFileName::DirExists( aPath ) )
|
|
|
|
{
|
|
|
|
if( !wxFileName::Mkdir( aPath, wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ) )
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PATHS::EnsureUserPathsExist()
|
|
|
|
{
|
2022-07-06 00:47:29 +00:00
|
|
|
EnsurePathExists( GetUserCachePath() );
|
2021-01-28 02:06:13 +00:00
|
|
|
EnsurePathExists( GetUserPluginsPath() );
|
|
|
|
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();
|
2022-02-21 23:49:36 +00:00
|
|
|
udir.AppendDir( wxT( "kicad" ) );
|
2021-02-17 04:26:46 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
2023-12-21 17:54:34 +00:00
|
|
|
#ifdef __WXMSW__
|
2023-08-26 17:42:20 +00:00
|
|
|
wxString PATHS::GetWindowsFontConfigDir()
|
|
|
|
{
|
|
|
|
wxFileName fn;
|
|
|
|
fn.AssignDir( getWindowsKiCadRoot() );
|
|
|
|
fn.AppendDir( wxS( "etc" ) );
|
|
|
|
fn.AppendDir( wxS( "fonts" ) );
|
|
|
|
|
|
|
|
return fn.GetPathWithSep();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-21 22:03:44 +00:00
|
|
|
wxString PATHS::getWindowsKiCadRoot()
|
|
|
|
{
|
2023-09-24 00:21:37 +00:00
|
|
|
wxFileName root( GetExecutablePath() + wxT( "/../" ) );
|
2022-07-06 00:47:29 +00:00
|
|
|
root.MakeAbsolute();
|
2021-06-21 22:03:44 +00:00
|
|
|
|
|
|
|
return root.GetPathWithSep();
|
|
|
|
}
|
|
|
|
#endif
|
2023-09-23 23:53:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
wxString PATHS::GetUserSettingsPath()
|
|
|
|
{
|
|
|
|
static wxString user_settings_path;
|
|
|
|
|
|
|
|
if( user_settings_path.empty() )
|
|
|
|
user_settings_path = CalculateUserSettingsPath();
|
|
|
|
|
|
|
|
return user_settings_path;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString PATHS::CalculateUserSettingsPath( bool aIncludeVer, bool aUseEnv )
|
|
|
|
{
|
|
|
|
wxFileName cfgpath;
|
|
|
|
|
|
|
|
// http://docs.wxwidgets.org/3.0/classwx_standard_paths.html#a7c7cf595d94d29147360d031647476b0
|
|
|
|
|
|
|
|
wxString envstr;
|
|
|
|
if( aUseEnv && wxGetEnv( wxT( "KICAD_CONFIG_HOME" ), &envstr ) && !envstr.IsEmpty() )
|
|
|
|
{
|
|
|
|
// Override the assignment above with KICAD_CONFIG_HOME
|
|
|
|
cfgpath.AssignDir( envstr );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cfgpath.AssignDir( KIPLATFORM::ENV::GetUserConfigPath() );
|
|
|
|
|
|
|
|
cfgpath.AppendDir( TO_STR( KICAD_CONFIG_DIR ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( aIncludeVer )
|
|
|
|
cfgpath.AppendDir( GetMajorMinorVersion().ToStdString() );
|
|
|
|
|
|
|
|
return cfgpath.GetPath();
|
2023-09-24 00:21:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const wxString& PATHS::GetExecutablePath()
|
|
|
|
{
|
|
|
|
static wxString exe_path;
|
|
|
|
|
|
|
|
if( exe_path.empty() )
|
|
|
|
{
|
|
|
|
wxString bin_dir = wxStandardPaths::Get().GetExecutablePath();
|
|
|
|
|
|
|
|
#ifdef __WXMAC__
|
|
|
|
// On OSX GetExecutablePath() will always point to main
|
|
|
|
// bundle directory, e.g., /Applications/kicad.app/
|
|
|
|
|
|
|
|
wxFileName fn( bin_dir );
|
2023-11-15 14:25:38 +00:00
|
|
|
WX_FILENAME::ResolvePossibleSymlinks( fn );
|
2023-09-24 00:21:37 +00:00
|
|
|
|
|
|
|
if( fn.GetName() == wxT( "kicad" ) || fn.GetName() == wxT( "kicad-cli" ) )
|
|
|
|
{
|
|
|
|
// kicad launcher, so just remove the Contents/MacOS part
|
|
|
|
fn.RemoveLastDir();
|
|
|
|
fn.RemoveLastDir();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// standalone binaries live in Contents/Applications/<standalone>.app/Contents/MacOS
|
|
|
|
fn.RemoveLastDir();
|
|
|
|
fn.RemoveLastDir();
|
|
|
|
fn.RemoveLastDir();
|
|
|
|
fn.RemoveLastDir();
|
|
|
|
fn.RemoveLastDir();
|
|
|
|
}
|
|
|
|
|
|
|
|
bin_dir = fn.GetPath() + wxT( "/" );
|
|
|
|
#else
|
|
|
|
// Use unix notation for paths. I am not sure this is a good idea,
|
|
|
|
// but it simplifies compatibility between Windows and Unices.
|
|
|
|
// However it is a potential problem in path handling under Windows.
|
|
|
|
bin_dir.Replace( WIN_STRING_DIR_SEP, UNIX_STRING_DIR_SEP );
|
|
|
|
|
|
|
|
// Remove file name form command line:
|
|
|
|
while( bin_dir.Last() != '/' && !bin_dir.IsEmpty() )
|
|
|
|
bin_dir.RemoveLast();
|
|
|
|
#endif
|
|
|
|
exe_path = bin_dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
return exe_path;
|
2023-09-23 23:53:22 +00:00
|
|
|
}
|