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

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

Referenced by PROJECT::configCreate().

236 {
237  if( aDestination.IsEmpty() )
238  {
239  DBG( printf( "%s: destination is empty.\n", __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  DBG( printf( "%s: template file '%s' not found using search paths.\n", __func__, TO_UTF8( templateFile ) );)
250 
251  wxFileName templ( wxStandardPaths::Get().GetDocumentsDir(),
252  wxT( "kicad" ), ProjectFileExtension );
253 
254  if( !templ.IsFileReadable() )
255  {
256  wxString msg = wxString::Format( _(
257  "Unable to find \"%s\" template config file." ),
258  GetChars( templateFile ) );
259 
260  DisplayErrorMessage( nullptr, _( "Error copying project file template" ), msg );
261 
262  return false;
263  }
264 
265  kicad_pro_template = templ.GetFullPath();
266  }
267 
268  DBG( printf( "%s: using template file '%s' as project file.\n", __func__, TO_UTF8( kicad_pro_template ) );)
269 
270  // Verify aDestination can be created. if this is not the case, wxCopyFile
271  // will generate a crappy log error message, and we *do not want* this kind
272  // of stupid message
273  wxFileName fn( aDestination );
274  bool success = true;
275 
276  if( fn.IsOk() && fn.IsDirWritable() )
277  success = wxCopyFile( kicad_pro_template, aDestination );
278  else
279  {
280  wxLogMessage( _( "Cannot create prj file \"%s\" (Directory not writable)" ),
281  GetChars( aDestination) );
282  success = false;
283  }
284 
285  return success;
286 }
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Function DisplayErrorMessage displays an error message with aMessage.
Definition: confirm.cpp:199
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
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