Eeschema: fix remapping backup project with schematics in subfolders.
The backup code was designed for a project with all of the schematics in the project folder which is not always the case. Fix the schematic backup to keep the schematic folder structure in tact during backups. Fixes lp:1751662 https://bugs.launchpad.net/kicad/+bug/1751662
This commit is contained in:
parent
fef1ba9993
commit
ce1bd4c6b7
|
@ -312,17 +312,19 @@ bool DIALOG_SYMBOL_REMAP::remapSymbolToLibTable( SCH_COMPONENT* aSymbol )
|
||||||
|
|
||||||
bool DIALOG_SYMBOL_REMAP::backupProject( REPORTER& aReporter )
|
bool DIALOG_SYMBOL_REMAP::backupProject( REPORTER& aReporter )
|
||||||
{
|
{
|
||||||
static wxString backupPath = "rescue-backup";
|
static wxString backupFolder = "rescue-backup";
|
||||||
|
|
||||||
wxString tmp;
|
wxString tmp;
|
||||||
wxString errorMsg;
|
wxString errorMsg;
|
||||||
wxFileName srcFileName;
|
wxFileName srcFileName;
|
||||||
wxFileName destFileName;
|
wxFileName destFileName;
|
||||||
|
wxFileName backupPath;
|
||||||
SCH_SCREENS schematic;
|
SCH_SCREENS schematic;
|
||||||
|
|
||||||
// Copy backup files to different folder so as not to pollute the project folder.
|
// Copy backup files to different folder so as not to pollute the project folder.
|
||||||
destFileName.SetPath( Prj().GetProjectPath() );
|
destFileName.SetPath( Prj().GetProjectPath() );
|
||||||
destFileName.AppendDir( backupPath );
|
destFileName.AppendDir( backupFolder );
|
||||||
|
backupPath = destFileName;
|
||||||
|
|
||||||
if( !destFileName.DirExists() )
|
if( !destFileName.DirExists() )
|
||||||
{
|
{
|
||||||
|
@ -348,7 +350,7 @@ bool DIALOG_SYMBOL_REMAP::backupProject( REPORTER& aReporter )
|
||||||
srcFileName.SetPath( Prj().GetProjectPath() );
|
srcFileName.SetPath( Prj().GetProjectPath() );
|
||||||
srcFileName.SetName( SYMBOL_LIB_TABLE::GetSymbolLibTableFileName() );
|
srcFileName.SetName( SYMBOL_LIB_TABLE::GetSymbolLibTableFileName() );
|
||||||
destFileName = srcFileName;
|
destFileName = srcFileName;
|
||||||
destFileName.AppendDir( backupPath );
|
destFileName.AppendDir( backupFolder );
|
||||||
destFileName.SetName( destFileName.GetName() + timeStamp );
|
destFileName.SetName( destFileName.GetName() + timeStamp );
|
||||||
|
|
||||||
tmp.Printf( _( "Backing up file \"%s\" to file \"%s\"." ),
|
tmp.Printf( _( "Backing up file \"%s\" to file \"%s\"." ),
|
||||||
|
@ -367,12 +369,34 @@ bool DIALOG_SYMBOL_REMAP::backupProject( REPORTER& aReporter )
|
||||||
{
|
{
|
||||||
destFileName = screen->GetFileName();
|
destFileName = screen->GetFileName();
|
||||||
destFileName.SetName( destFileName.GetName() + timeStamp );
|
destFileName.SetName( destFileName.GetName() + timeStamp );
|
||||||
destFileName.AppendDir( backupPath );
|
|
||||||
|
// Check for nest hierarchical schematic paths.
|
||||||
|
if( destFileName.GetPath() != backupPath.GetPath() )
|
||||||
|
{
|
||||||
|
destFileName.SetPath( backupPath.GetPath() );
|
||||||
|
|
||||||
|
wxArrayString srcDirs = wxFileName( screen->GetFileName() ).GetDirs();
|
||||||
|
wxArrayString destDirs = wxFileName( Prj().GetProjectPath() ).GetDirs();
|
||||||
|
|
||||||
|
for( size_t i = destDirs.GetCount(); i < srcDirs.GetCount(); i++ )
|
||||||
|
destFileName.AppendDir( srcDirs[i] );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
destFileName.AppendDir( backupFolder );
|
||||||
|
}
|
||||||
|
|
||||||
tmp.Printf( _( "Backing up file \"%s\" to file \"%s\"." ),
|
tmp.Printf( _( "Backing up file \"%s\" to file \"%s\"." ),
|
||||||
screen->GetFileName(), destFileName.GetFullPath() );
|
screen->GetFileName(), destFileName.GetFullPath() );
|
||||||
aReporter.Report( tmp, REPORTER::RPT_INFO );
|
aReporter.Report( tmp, REPORTER::RPT_INFO );
|
||||||
|
|
||||||
|
if( !destFileName.DirExists() && !destFileName.Mkdir( wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ) )
|
||||||
|
{
|
||||||
|
tmp.Printf( _( "Failed to create backup folder \"%s\"\n" ), destFileName.GetPath() );
|
||||||
|
errorMsg += tmp;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if( wxFileName::Exists( screen->GetFileName() )
|
if( wxFileName::Exists( screen->GetFileName() )
|
||||||
&& !wxCopyFile( screen->GetFileName(), destFileName.GetFullPath() ) )
|
&& !wxCopyFile( screen->GetFileName(), destFileName.GetFullPath() ) )
|
||||||
{
|
{
|
||||||
|
@ -384,7 +408,7 @@ bool DIALOG_SYMBOL_REMAP::backupProject( REPORTER& aReporter )
|
||||||
// Back up the project file.
|
// Back up the project file.
|
||||||
destFileName = Prj().GetProjectFullName();
|
destFileName = Prj().GetProjectFullName();
|
||||||
destFileName.SetName( destFileName.GetName() + timeStamp );
|
destFileName.SetName( destFileName.GetName() + timeStamp );
|
||||||
destFileName.AppendDir( backupPath );
|
destFileName.AppendDir( backupFolder );
|
||||||
|
|
||||||
tmp.Printf( _( "Backing up file \"%s\" to file \"%s\"." ),
|
tmp.Printf( _( "Backing up file \"%s\" to file \"%s\"." ),
|
||||||
Prj().GetProjectFullName(), destFileName.GetFullPath() );
|
Prj().GetProjectFullName(), destFileName.GetFullPath() );
|
||||||
|
@ -404,7 +428,7 @@ bool DIALOG_SYMBOL_REMAP::backupProject( REPORTER& aReporter )
|
||||||
|
|
||||||
destFileName = srcFileName;
|
destFileName = srcFileName;
|
||||||
destFileName.SetName( destFileName.GetName() + timeStamp );
|
destFileName.SetName( destFileName.GetName() + timeStamp );
|
||||||
destFileName.AppendDir( backupPath );
|
destFileName.AppendDir( backupFolder );
|
||||||
|
|
||||||
tmp.Printf( _( "Backing up file \"%s\" to file \"%s\"." ),
|
tmp.Printf( _( "Backing up file \"%s\" to file \"%s\"." ),
|
||||||
srcFileName.GetFullPath(), destFileName.GetFullPath() );
|
srcFileName.GetFullPath(), destFileName.GetFullPath() );
|
||||||
|
|
Loading…
Reference in New Issue