PROJECT::configCreate() logic changes.

This commit is contained in:
Dick Hollenbeck 2014-04-15 00:34:28 -05:00
parent c39385a5cd
commit 4a7ba86996
2 changed files with 41 additions and 30 deletions

View File

@ -23,18 +23,19 @@
*/
#include <wx/stdpaths.h>
#include <fctsys.h>
#include <macros.h>
#include <gr_basic.h>
#include <pgm_base.h>
#include <project.h>
#include <wx/stdpaths.h>
#include <confirm.h>
#include <kicad_string.h>
#include <config_params.h>
#include <wildcards_and_files_ext.h>
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 <kicad.pro> not found." ) );
wxLogDebug( wxT( "Template file <kicad.pro> 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<wxConfigBase> 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<wxConfigBase> 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" ) );

View File

@ -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; }