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>

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 237 of file project.cpp.

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

Referenced by PROJECT::configCreate().

238 {
239  if( aDestination.IsEmpty() )
240  {
241  DBG( printf( "%s: destination is empty.\n", __func__ );)
242  return false;
243  }
244 
245  wxString templateFile = wxT( "kicad." ) + ProjectFileExtension;
246 
247  wxString kicad_pro_template = aSearchS.FindValidPath( templateFile );
248 
249  if( !kicad_pro_template )
250  {
251  DBG( printf( "%s: template file '%s' not found using search paths.\n", __func__, TO_UTF8( templateFile ) );)
252 
253  wxFileName templ( wxStandardPaths::Get().GetDocumentsDir(),
254  wxT( "kicad" ), ProjectFileExtension );
255 
256  if( !templ.IsFileReadable() )
257  {
258  wxString msg = wxString::Format( _(
259  "Unable to find '%s' template config file." ),
260  GetChars( templateFile ) );
261 
262  DisplayErrorMessage( nullptr, _( "Error copying project file template" ), msg );
263 
264  return false;
265  }
266 
267  kicad_pro_template = templ.GetFullPath();
268  }
269 
270  DBG( printf( "%s: using template file '%s' as project file.\n", __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 }
const wxString ProjectFileExtension
#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
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString aExtraInfo)
Function DisplayErrorMessage displays an error message with aMessage.
Definition: confirm.cpp:87
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
#define DBG(x)
Definition: fctsys.h:33
wxString FindValidPath(const wxString &aFileName) const
Definition: search_stack.h:71