From 3c9316957d0564dc5bf134906fe189349bafb1b8 Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Fri, 12 Jan 2018 10:13:41 -0500 Subject: [PATCH] Eeschema: allow remapping if a project symbol library table exists. Change the behavior of the remapping algorithm to remap even if a project symbol library table exists in the project file in case a previous attempt to remap failed. The existing symbol library table is backed up to the back folder and rebuilt. Fixes lp:1741983 https://bugs.launchpad.net/kicad/+bug/1741983 --- eeschema/dialogs/dialog_symbol_remap.cpp | 64 ++++++++++++++++++------ eeschema/dialogs/dialog_symbol_remap.h | 3 +- 2 files changed, 52 insertions(+), 15 deletions(-) diff --git a/eeschema/dialogs/dialog_symbol_remap.cpp b/eeschema/dialogs/dialog_symbol_remap.cpp index 9510f8eb13..f42e260da2 100644 --- a/eeschema/dialogs/dialog_symbol_remap.cpp +++ b/eeschema/dialogs/dialog_symbol_remap.cpp @@ -79,7 +79,8 @@ void DIALOG_SYMBOL_REMAP::OnRemapSymbols( wxCommandEvent& aEvent ) wxBusyCursor busy; - backupProject( m_messagePanel->Reporter() ); + if( !backupProject( m_messagePanel->Reporter() ) ) + return; // Ignore the never show rescue setting for one last rescue of legacy symbol // libraries before remapping to the symbol library table. This ensures the @@ -92,13 +93,16 @@ void DIALOG_SYMBOL_REMAP::OnRemapSymbols( wxCommandEvent& aEvent ) wxFileName prjSymLibTableFileName( Prj().GetProjectPath(), SYMBOL_LIB_TABLE::GetSymbolLibTableFileName() ); - if( !prjSymLibTableFileName.FileExists() ) + // Delete the existing project symbol library table. + if( prjSymLibTableFileName.FileExists() ) { - createProjectSymbolLibTable( m_messagePanel->Reporter() ); - Prj().SetElem( PROJECT::ELEM_SYMBOL_LIB_TABLE, NULL ); - Prj().SchSymbolLibTable(); + wxRemoveFile( prjSymLibTableFileName.GetFullPath() ); } + createProjectSymbolLibTable( m_messagePanel->Reporter() ); + Prj().SetElem( PROJECT::ELEM_SYMBOL_LIB_TABLE, NULL ); + Prj().SchSymbolLibTable(); + remapSymbolsToLibTable( m_messagePanel->Reporter() ); // Remove all of the libraries from the legacy library list. @@ -306,12 +310,13 @@ bool DIALOG_SYMBOL_REMAP::remapSymbolToLibTable( SCH_COMPONENT* aSymbol ) } -void DIALOG_SYMBOL_REMAP::backupProject( REPORTER& aReporter ) +bool DIALOG_SYMBOL_REMAP::backupProject( REPORTER& aReporter ) { static wxString backupPath = "rescue-backup"; wxString tmp; wxString errorMsg; + wxFileName srcFileName; wxFileName destFileName; SCH_SCREENS schematic; @@ -325,14 +330,38 @@ void DIALOG_SYMBOL_REMAP::backupProject( REPORTER& aReporter ) { errorMsg.Printf( _( "Cannot create project remap back up folder \"%s\"." ), destFileName.GetPath() ); - DisplayError( this, errorMsg ); - return; + + wxMessageDialog dlg( this, errorMsg, _( "Backup Error" ), + wxYES_NO | wxCENTRE | wxRESIZE_BORDER | wxICON_QUESTION ); + dlg.SetYesNoLabels( wxMessageDialog::ButtonLabel( _( "Continue with Rescue" ) ), + wxMessageDialog::ButtonLabel( _( "Abort Rescue" ) ) ); + + if( dlg.ShowModal() == wxID_NO ) + return false; } } // Time stamp to append to file name in case multiple remappings are performed. wxString timeStamp = wxDateTime::Now().Format( "-%Y-%m-%d-%H-%M-%S" ); + // Back up symbol library table. + srcFileName.SetPath( Prj().GetProjectPath() ); + srcFileName.SetName( SYMBOL_LIB_TABLE::GetSymbolLibTableFileName() ); + destFileName = srcFileName; + destFileName.AppendDir( backupPath ); + destFileName.SetName( destFileName.GetName() + timeStamp ); + + tmp.Printf( _( "Backing up file \"%s\" to file \"%s\"." ), + srcFileName.GetFullPath(), destFileName.GetFullPath() ); + aReporter.Report( tmp, REPORTER::RPT_INFO ); + + if( wxFileName::Exists( srcFileName.GetFullPath() ) + && !wxCopyFile( srcFileName.GetFullPath(), destFileName.GetFullPath() ) ) + { + tmp.Printf( _( "Failed to back up file \"%s\".\n" ), srcFileName.GetFullPath() ); + errorMsg += tmp; + } + // Back up the schematic files. for( SCH_SCREEN* screen = schematic.GetFirst(); screen; screen = schematic.GetNext() ) { @@ -368,8 +397,6 @@ void DIALOG_SYMBOL_REMAP::backupProject( REPORTER& aReporter ) errorMsg += tmp; } - wxFileName srcFileName; - // Back up the cache library. srcFileName.SetPath( Prj().GetProjectPath() ); srcFileName.SetName( Prj().GetProjectName() + "-cache" ); @@ -390,7 +417,7 @@ void DIALOG_SYMBOL_REMAP::backupProject( REPORTER& aReporter ) errorMsg += tmp; } - // Back up the rescue library if it exists. + // Back up the rescue symbol library if it exists. srcFileName.SetName( Prj().GetProjectName() + "-rescue" ); destFileName.SetName( srcFileName.GetName() + timeStamp ); @@ -405,7 +432,7 @@ void DIALOG_SYMBOL_REMAP::backupProject( REPORTER& aReporter ) errorMsg += tmp; } - // Back up the rescue library document file if it exists. + // Back up the rescue symbol library document file if it exists. srcFileName.SetExt( "dcm" ); destFileName.SetExt( srcFileName.GetExt() ); @@ -422,10 +449,19 @@ void DIALOG_SYMBOL_REMAP::backupProject( REPORTER& aReporter ) if( !errorMsg.IsEmpty() ) { + wxMessageDialog dlg( this, _( "Some of the project files could not be backed up." ), + _( "Backup Error" ), + wxYES_NO | wxCENTRE | wxRESIZE_BORDER | wxICON_QUESTION ); errorMsg.Trim(); - DisplayErrorMessage( this, _( "Some of the project files could not be backed up." ), - errorMsg ); + dlg.SetExtendedMessage( errorMsg ); + dlg.SetYesNoLabels( wxMessageDialog::ButtonLabel( _( "Continue with Rescue" ) ), + wxMessageDialog::ButtonLabel( _( "Abort Rescue" ) ) ); + + if( dlg.ShowModal() == wxID_NO ) + return false; } + + return true; } diff --git a/eeschema/dialogs/dialog_symbol_remap.h b/eeschema/dialogs/dialog_symbol_remap.h index 541af56ff8..c21bce6e55 100644 --- a/eeschema/dialogs/dialog_symbol_remap.h +++ b/eeschema/dialogs/dialog_symbol_remap.h @@ -82,8 +82,9 @@ private: * file. * * @param aReporter is the #REPORTER object in which to write information messages. + * @return true to continue rescue or false to abort rescue. */ - void backupProject( REPORTER& aReporter ); + bool backupProject( REPORTER& aReporter ); bool m_remapped; };