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

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

Referenced by PROJECT::configCreate().

227 {
228  if( aDestination.IsEmpty() )
229  {
230  DBG( printf( "%s: destination is empty.\n", __func__ );)
231  return false;
232  }
233 
234  wxString templateFile = wxT( "kicad." ) + ProjectFileExtension;
235 
236  wxString kicad_pro_template = aSearchS.FindValidPath( templateFile );
237 
238  if( !kicad_pro_template )
239  {
240  DBG( printf( "%s: template file '%s' not found using search paths.\n", __func__, TO_UTF8( templateFile ) );)
241 
242  wxFileName templ( wxStandardPaths::Get().GetDocumentsDir(),
243  wxT( "kicad" ), ProjectFileExtension );
244 
245  if( !templ.IsFileReadable() )
246  {
247  wxString msg = wxString::Format( _(
248  "Unable to find '%s' template config file." ),
249  GetChars( templateFile ) );
250 
251  DisplayErrorMessage( nullptr, _( "Error copying project file template" ), msg );
252 
253  return false;
254  }
255 
256  kicad_pro_template = templ.GetFullPath();
257  }
258 
259  DBG( printf( "%s: using template file '%s' as project file.\n", __func__, TO_UTF8( kicad_pro_template ) );)
260 
261  // Verify aDestination can be created. if this is not the case, wxCopyFile
262  // will generate a crappy log error message, and we *do not want* this kind
263  // of stupid message
264  wxFileName fn( aDestination );
265  bool success = true;
266 
267  if( fn.IsOk() && fn.IsDirWritable() )
268  success = wxCopyFile( kicad_pro_template, aDestination );
269  else
270  {
271  wxLogMessage( _( "Cannot create prj file '%s' (Directory not writable)" ),
272  GetChars( aDestination) );
273  success = false;
274  }
275 
276  return success;
277 }
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:85
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