24 #include <wx/stdpaths.h> 68 wxFileName candidate_path( aFullPathAndName );
129 wxString path = fn.GetPath();
133 if( !fn.GetDirCount() || !fn.IsOk() || !wxFileName::IsDirWritable( path ) )
142 fn.AssignDir( wxStandardPaths::Get().GetUserConfigDir() );
145 fn.AssignDir( wxStandardPaths::Get().GetTempDir() );
148 #if defined( __WINDOWS__ ) 149 fn.AppendDir( wxT(
"kicad" ) );
158 fn.SetName(
"prj-" + aLibTableName );
162 fn.SetName( aLibTableName );
167 return fn.GetFullPath();
173 unsigned ndx = unsigned( aIndex );
188 unsigned ndx = unsigned( aIndex );
196 static wxString no_cookie_for_you;
200 return no_cookie_for_you;
223 #if defined(DEBUG) && 0 226 printf(
"%s: &m_elems[%i]:%p aElem:%p\n", __func__, aIndex, &
m_elems[aIndex], aElem );
237 if( aDestination.IsEmpty() )
245 wxString kicad_pro_template = aSearchS.
FindValidPath( templateFile );
247 if( !kicad_pro_template )
249 wxLogTrace(
tracePathsAndFiles,
"%s: template file '%s' not found using search paths.",
250 __func__,
TO_UTF8( templateFile ) );
252 wxFileName templ( wxStandardPaths::Get().GetDocumentsDir(),
255 if( !templ.IsFileReadable() )
258 "Unable to find \"%s\" template config file." ),
266 kicad_pro_template = templ.GetFullPath();
270 __func__,
TO_UTF8( kicad_pro_template ) );
275 wxFileName fn( aDestination );
278 if( fn.IsOk() && fn.IsDirWritable() )
279 success = wxCopyFile( kicad_pro_template, aDestination );
282 wxLogMessage(
_(
"Cannot create prj file \"%s\" (Directory not writable)" ),
292 const wxString& aGroupName,
const wxString& aProjectFileName )
294 wxConfigBase* cfg = 0;
299 if( cur_pro_fn.IsEmpty() )
302 if( wxFileName( cur_pro_fn ).IsFileReadable() )
309 cfg =
new wxFileConfig( wxEmptyString, wxEmptyString, cur_pro_fn, wxEmptyString );
317 cfg =
new wxFileConfig( wxEmptyString, wxEmptyString, cur_pro_fn, wxEmptyString );
326 std::unique_ptr<wxConfigBase> cfg(
configCreate( aSList, aGroupName, aFileName ) );
334 cfg->SetPath( wxT(
"/" ) );
339 cfg->Write( wxT(
"last_client" ),
Pgm().App().GetAppName() );
342 cfg->DeleteGroup( aGroupName );
345 cfg->SetPath( aGroupName );
348 cfg->SetPath( wxT(
"/" ) );
352 cfg->SetPath( wxT(
"/" ) );
359 const PARAM_CFG_ARRAY& aParams,
const wxString& aForeignProjectFileName )
361 std::unique_ptr<wxConfigBase> cfg(
configCreate( aSList, aGroupName,
362 aForeignProjectFileName ) );
371 cfg.get()->SetExpandEnvVars(
false );
373 cfg->SetPath( wxCONFIG_PATH_SEPARATOR );
375 wxString timestamp = cfg->Read( wxT(
"update" ) );
387 wxFileName fn = aFileName;
389 if( !fn.IsAbsolute() )
392 fn.Normalize( wxPATH_NORM_ALL, pro_dir );
395 return fn.GetFullPath();
426 tbl->
Load( projectFpLibTableFileName );
wxConfigBase * configCreate(const SEARCH_STACK &aSList, const wxString &aGroupName, const wxString &aProjectFileName=wxEmptyString)
Function configCreate loads a *.pro file and returns a wxConfigBase.
_ELEM * m_elems[ELEM_COUNT]
A list of parameters type.
void Clear()
Function Clear clears the _ELEMs and RSTRINGs.
VTBL_ENTRY void ConfigSave(const SEARCH_STACK &aSList, const wxString &aGroupName, const PARAM_CFG_ARRAY &aParams, const wxString &aFileName=wxEmptyString)
Function ConfigSave saves the current "project" parameters into the wxConfigBase* derivative.
wxString FindValidPath(const wxString &aFileName) const
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
This file is part of the common library.
const std::string ProjectFileExtension
#define PROJECT_VAR_NAME
A variable name whose value holds the current project directory.
const wxChar *const tracePathsAndFiles
Flag to enable path and file name debug output.
PGM_BASE & Pgm()
The global Program "get" accessor.
void wxConfigSaveParams(wxConfigBase *aCfg, const PARAM_CFG_ARRAY &aList, const wxString &aGroup)
Function wxConfigSaveParams writes aList of PARAM_CFG_ARRAY elements to save configuration values to ...
Class SEARCH_STACK looks for files in a number of places.
VTBL_ENTRY _ELEM * GetElem(ELEM_T aIndex)
Typically wrapped somewhere else in a more meaningful function wrapper.
VTBL_ENTRY const wxString GetProjectPath() const
Function GetProjectPath returns the full path of the project.
void wxConfigLoadParams(wxConfigBase *aCfg, const PARAM_CFG_ARRAY &aList, const wxString &aGroup)
Function wxConfigLoadParams uses aList of PARAM_CFG_ARRAY elements to load configuration values from ...
VTBL_ENTRY const wxString AbsolutePath(const wxString &aFileName) const
Function AbsolutePath fixes up aFileName if it is relative to the project's directory to be an absolu...
This file contains miscellaneous commonly used macros and functions.
VTBL_ENTRY void SetElem(ELEM_T aIndex, _ELEM *aElem)
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
virtual const wxString What() const
A composite of Problem() and Where()
wxFileName m_project_name
<fullpath>/<basename>.pro
Definition of file extensions used in Kicad.
Class KIWAY is a minimalistic software bus for communications between various DLLs/DSOs (DSOs) within...
Return a new FP_LIB_TABLE with the global table installed as a fallback.
wxLogTrace helper definitions.
VTBL_ENTRY const wxString GetProjectFullName() const
Function GetProjectFullName returns the full path and name of the project.
VTBL_ENTRY KIFACE * KiFACE(FACE_T aFaceId, bool doLoad=true)
Function KiFACE returns the KIFACE* given a FACE_T.
void Load(const wxString &aFileName)
Load the library table using the path defined by aFileName aFallBackTable.
VTBL_ENTRY void SetProjectFullName(const wxString &aFullPathAndName)
Function SetProjectFullName sets the: 1) full directory, 2) basename, and 3) extension of the project...
VTBL_ENTRY void ElemsClear()
Function ElemsClear deletes all the _ELEMs and set their pointers to NULL.
static bool copy_pro_file_template(const SEARCH_STACK &aSearchS, const wxString &aDestination)
VTBL_ENTRY const wxString SymbolLibTableName() const
Return the path and file name of this projects symbol library table.
VTBL_ENTRY void SetRString(RSTRING_T aStringId, const wxString &aString)
Function SetRString stores a "retained string", which is any session and project specific string iden...
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
VTBL_ENTRY FP_LIB_TABLE * PcbFootprintLibs(KIWAY &aKiway)
Return the table of footprint libraries.
VTBL_ENTRY const wxString & GetRString(RSTRING_T aStringId)
Function GetRString returns a "retained string", which is any session and project specific string ide...
ELEM_T
Enum ELEM_T is the set of _ELEMs that a PROJECT can hold.
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
RSTRING_T
Retain a number of project specific wxStrings, enumerated here:
wxString m_rstrings[RSTRING_COUNT]
Class KIFACE is used by a participant in the KIWAY alchemy.
A PROJECT can hold stuff it knows nothing about, in the form of _ELEM derivatives.
VTBL_ENTRY const wxString GetProjectName() const
Function GetProjectName returns the short name of the project.
VTBL_ENTRY bool ConfigLoad(const SEARCH_STACK &aSearchS, const wxString &aGroupName, const PARAM_CFG_ARRAY &aParams, const wxString &aForeignConfigFileName=wxEmptyString)
Function ConfigLoad reads a subset of parameters from the "project" file.
wxString m_pro_date_and_time
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
VTBL_ENTRY const wxString FootprintLibTblName() const
Function FootprintLibTblName returns the path and filename of this project's fp-lib-table,...
const wxString libTableName(const wxString &aLibTableName) const
Return the full path and file name of the project specific library table aLibTableName.