KiCad PCB EDA Suite
project.cpp File Reference
#include <wx/stdpaths.h>
#include <fctsys.h>
#include <macros.h>
#include <pgm_base.h>
#include <project.h>
#include <common.h>
#include <confirm.h>
#include <kicad_string.h>
#include <config_params.h>
#include <wildcards_and_files_ext.h>
#include <fp_lib_table.h>
#include <kiway.h>
#include <kiface_ids.h>
#include <trace_helpers.h>

Go to the source code of this file.

Functions

static bool copy_pro_file_template (const SEARCH_STACK &aSearchS, const wxString &aDestination)
 

Function Documentation

static bool copy_pro_file_template ( const SEARCH_STACK aSearchS,
const wxString &  aDestination 
)
static

Definition at line 235 of file project.cpp.

References DisplayErrorMessage(), SEARCH_STACK::FindValidPath(), Format(), GetChars(), ProjectFileExtension, TO_UTF8, and tracePathsAndFiles.

Referenced by PROJECT::configCreate().

236 {
237  if( aDestination.IsEmpty() )
238  {
239  wxLogTrace( tracePathsAndFiles, "%s: destination is empty.", __func__ );
240  return false;
241  }
242 
243  wxString templateFile = wxT( "kicad." ) + ProjectFileExtension;
244 
245  wxString kicad_pro_template = aSearchS.FindValidPath( templateFile );
246 
247  if( !kicad_pro_template )
248  {
249  wxLogTrace( tracePathsAndFiles, "%s: template file '%s' not found using search paths.",
250  __func__, TO_UTF8( templateFile ) );
251 
252  wxFileName templ( wxStandardPaths::Get().GetDocumentsDir(),
253  wxT( "kicad" ), ProjectFileExtension );
254 
255  if( !templ.IsFileReadable() )
256  {
257  wxString msg = wxString::Format( _(
258  "Unable to find \"%s\" template config file." ),
259  GetChars( templateFile ) );
260 
261  DisplayErrorMessage( nullptr, _( "Error copying project file template" ), msg );
262 
263  return false;
264  }
265 
266  kicad_pro_template = templ.GetFullPath();
267  }
268 
269  wxLogTrace( tracePathsAndFiles, "%s: using template file '%s' as project file.",
270  __func__, TO_UTF8( kicad_pro_template ) );
271 
272  // Verify aDestination can be created. if this is not the case, wxCopyFile
273  // will generate a crappy log error message, and we *do not want* this kind
274  // of stupid message
275  wxFileName fn( aDestination );
276  bool success = true;
277 
278  if( fn.IsOk() && fn.IsDirWritable() )
279  success = wxCopyFile( kicad_pro_template, aDestination );
280  else
281  {
282  wxLogMessage( _( "Cannot create prj file \"%s\" (Directory not writable)" ),
283  GetChars( aDestination) );
284  success = false;
285  }
286 
287  return success;
288 }
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Function DisplayErrorMessage displays an error message with aMessage.
Definition: confirm.cpp:259
const std::string ProjectFileExtension
const wxChar *const tracePathsAndFiles
Flag to enable path and file name debug output.
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes...
Definition: macros.h:47
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
wxString FindValidPath(const wxString &aFileName) const
Definition: search_stack.h:73