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>
|
|
|
|
|
|
|
|
#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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString PATHS::GetStockScriptingPath()
|
|
|
|
{
|
|
|
|
wxString path;
|
|
|
|
|
|
|
|
if( wxGetEnv( wxT( "KICAD_RUN_FROM_BUILD_DIR" ), nullptr ) )
|
|
|
|
{
|
|
|
|
// Allow debugging from build dir by placing a "scripting" folder in the build root
|
|
|
|
path = Pgm().GetExecutablePath() + wxT( "../scripting" );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//TODO(snh) break out the directory functions into KIPLATFORM
|
|
|
|
#if defined( __WXMAC__ )
|
|
|
|
path = GetOSXKicadDataDir() + wxT( "/scripting" );
|
|
|
|
#elif defined( __WXMSW__ )
|
|
|
|
path = Pgm().GetExecutablePath() + wxT( "../share/kicad/scripting" );
|
|
|
|
#else
|
|
|
|
path = wxString( KICAD_DATA ) + wxS( "/scripting" );
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
return path;
|
2021-01-23 15:46:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString PATHS::GetStockPluginsPath()
|
|
|
|
{
|
|
|
|
wxFileName fn;
|
|
|
|
|
|
|
|
#if defined( __WXMAC__ )
|
|
|
|
fn.Assign( Pgm().GetExecutablePath() );
|
|
|
|
fn.AppendDir( wxT( "Contents" ) );
|
|
|
|
fn.AppendDir( wxT( "PlugIns" ) );
|
|
|
|
#elif defined( __WXMSW__ )
|
2021-01-29 17:44:13 +00:00
|
|
|
fn.Assign( Pgm().GetExecutablePath() + wxT( "/plugins/" ) );
|
2021-01-23 15:46:48 +00:00
|
|
|
#else
|
|
|
|
// PLUGINDIR = CMAKE_INSTALL_FULL_LIBDIR path is the absolute path
|
|
|
|
// corresponding to the install path used for constructing KICAD_USER_PLUGIN
|
2021-01-23 16:22:39 +00:00
|
|
|
wxString tfname = wxString::FromUTF8Unchecked( KICAD_PLUGINDIR );
|
2021-01-23 15:46:48 +00:00
|
|
|
fn.Assign( tfname, "" );
|
2021-01-24 03:41:58 +00:00
|
|
|
fn.AppendDir( "kicad" ); // linux use lowercase
|
2021-01-23 15:46:48 +00:00
|
|
|
fn.AppendDir( wxT( "plugins" ) );
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return fn.GetPathWithSep();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString PATHS::GetStockPlugins3DPath()
|
|
|
|
{
|
|
|
|
wxFileName fn;
|
|
|
|
|
|
|
|
fn.Assign( PATHS::GetStockPluginsPath() );
|
|
|
|
fn.AppendDir( "3d" );
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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() );
|
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()
|
|
|
|
{
|
|
|
|
return wxT( "/Library/Application Support/kicad" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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-02-17 04:28:10 +00:00
|
|
|
if( dirs[dirs.GetCount() - 3].Lower() != wxT( "kicad.app" ) )
|
2021-02-17 04:26:46 +00:00
|
|
|
{
|
|
|
|
// Bundle structure resp. current path is
|
|
|
|
// kicad.app/Contents/Applications/<standalone>.app/Contents/SharedSupport
|
|
|
|
// and will be mapped to
|
|
|
|
// kicad.app/Contents/SharedSupprt
|
|
|
|
ddir.RemoveLastDir();
|
|
|
|
ddir.RemoveLastDir();
|
|
|
|
ddir.RemoveLastDir();
|
|
|
|
ddir.RemoveLastDir();
|
|
|
|
ddir.AppendDir( wxT( "SharedSupport" ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
return ddir.GetPath();
|
|
|
|
}
|
|
|
|
#endif
|