diff --git a/common/project.cpp b/common/project.cpp index 3e3c9cdf84..f031bf4b9e 100644 --- a/common/project.cpp +++ b/common/project.cpp @@ -23,18 +23,19 @@ */ +#include + #include #include #include #include #include -#include +#include #include #include #include - PROJECT::PROJECT() { memset( m_elems, 0, sizeof(m_elems) ); @@ -198,24 +199,21 @@ wxConfigBase* PROJECT::configCreate( const SEARCH_STACK& aSList, const wxString& const wxString& aGroupName, bool aForceUseLocalConfig ) { wxConfigBase* cfg = 0; - wxFileName fn = aFileName; + wxFileName fn = aFileName; fn.SetExt( ProjectFileExtension ); + wxString cur_pro_fn = fn.GetFullPath(); + // is there an edge transition, a change in m_project_filename? - if( m_project_name != fn ) + if( m_project_name != cur_pro_fn ) { - m_pcb_search.Clear(); m_sch_search.Clear(); - SetProjectFullName( fn.GetFullPath() ); - // to the empty lists, add project dir as first - m_pcb_search.AddPaths( fn.GetPath() ); m_sch_search.AddPaths( fn.GetPath() ); // append all paths from aSList - add_search_paths( &m_pcb_search, aSList, -1 ); add_search_paths( &m_sch_search, aSList, -1 ); // addLibrarySearchPaths( SEARCH_STACK* aSP, wxConfigBase* aCfg ) @@ -231,8 +229,6 @@ wxConfigBase* PROJECT::configCreate( const SEARCH_STACK& aSList, const wxString& // Init local config filename if( aForceUseLocalConfig || fn.FileExists() ) { - wxString cur_pro_fn = fn.GetFullPath(); - cfg = new wxFileConfig( wxEmptyString, wxEmptyString, cur_pro_fn, wxEmptyString ); cfg->DontCreateOnDemand(); @@ -265,31 +261,43 @@ wxConfigBase* PROJECT::configCreate( const SEARCH_STACK& aSList, const wxString& } else // Version incorrect { + wxLogDebug( wxT( "Project file version is zero, not using this old project file, going with template.\n") ); delete cfg; cfg = 0; } } - // Search for the template kicad.pro file by using caller's SEARCH_STACK. + // No suitable pro file was found, either does not exist, or is too old. + // Use the template kicad.pro file. Find it by using caller's SEARCH_STACK. wxString kicad_pro_template = aSList.FindValidPath( wxT( "kicad.pro" ) ); if( !kicad_pro_template ) { - wxLogDebug( wxT( "Template file not found." ) ); + wxLogDebug( wxT( "Template file not found using search paths." ) ); - fn = wxFileName( wxStandardPaths::Get().GetDocumentsDir(), - wxT( "kicad" ), ProjectFileExtension ); - } - else - { - fn = kicad_pro_template; + wxFileName templ( wxStandardPaths::Get().GetDocumentsDir(), + wxT( "kicad" ), ProjectFileExtension ); + + if( !templ.IsFileReadable() ) + { + wxString msg = wxString::Format( _( "Unable to find kicad.pro template file." ) ); + + DisplayError( NULL, msg ); + + return NULL; + } + + kicad_pro_template = templ.GetFullPath(); } - cfg = new wxFileConfig( wxEmptyString, wxEmptyString, wxEmptyString, fn.GetFullPath() ); + // copy the template to cur_pro_fn, and open it at that destination. + wxCopyFile( kicad_pro_template, cur_pro_fn ); + cfg = new wxFileConfig( wxEmptyString, wxEmptyString, wxEmptyString, cur_pro_fn ); + cfg->DontCreateOnDemand(); - SetProjectFullName( fn.GetFullPath() ); + SetProjectFullName( cur_pro_fn ); return cfg; } @@ -299,6 +307,12 @@ void PROJECT::ConfigSave( const SEARCH_STACK& aSList, const wxString& aFileName { std::auto_ptr cfg( configCreate( aSList, aFileName, aGroupName, FORCE_LOCAL_CONFIG ) ); + if( !cfg.get() ) + { + // could not find template + return; + } + cfg->SetPath( wxCONFIG_PATH_SEPARATOR ); cfg->Write( wxT( "update" ), DateAndTime() ); @@ -329,6 +343,12 @@ bool PROJECT::ConfigLoad( const SEARCH_STACK& aSList, const wxString& aFileName, { std::auto_ptr cfg( configCreate( aSList, aFileName, aGroupName, false ) ); + if( !cfg.get() ) + { + // could not find template + return false; + } + cfg->SetPath( wxCONFIG_PATH_SEPARATOR ); wxString timestamp = cfg->Read( wxT( "update" ) ); diff --git a/include/project.h b/include/project.h index 202d957eb8..a4928f4e5c 100644 --- a/include/project.h +++ b/include/project.h @@ -131,15 +131,6 @@ public: /// Accessor for Eeschema search stack. VTBL_ENTRY SEARCH_STACK& SchSearchS() { return m_sch_search; } - /** - * Function PcbSearchS - * returns the obsolete footprint library search stack. - * Projects created before the FP_LIB_TABLE support will have footprint - * search paths in the *.pro files. Projects created after the FP_LIB_TABLE - * support will not. This stack is used for conversion from old to new only. - */ - VTBL_ENTRY SEARCH_STACK& PcbSearchS() { return m_pcb_search; } - VTBL_ENTRY wxString GetModuleLibraryNickname() { return m_module_library_nickname; } VTBL_ENTRY void SetModuleLibraryNickname( const wxString& aNickName ) { m_module_library_nickname = aNickName; }