Non-KiCad Project Importers: Check files/directories exist before deleting/creating them
- Need to check that the path we are calling an "empty" directory doesn't exist before we start - Need to check that the location where we are storing the resultant imported design isn't the same as the source location. If it is the same, do not make a copy of the files as it will fail. Fixes https://gitlab.com/kicad/code/kicad/-/issues/6838
This commit is contained in:
parent
b168b74919
commit
3eec5f32ef
|
@ -98,12 +98,28 @@ void KICAD_MANAGER_FRAME::ImportNonKiCadProject( wxString aWindowTitle, wxString
|
||||||
if( dlg.ShowModal() == wxID_YES )
|
if( dlg.ShowModal() == wxID_YES )
|
||||||
{
|
{
|
||||||
// Append a new directory with the same name of the project file
|
// Append a new directory with the same name of the project file
|
||||||
// and try to create it
|
// Keep iterating until we find an empty directory
|
||||||
pro.AppendDir( pro.GetName() );
|
wxString newDir = pro.GetName();
|
||||||
|
int attempt = 0;
|
||||||
|
|
||||||
|
pro.AppendDir( newDir );
|
||||||
|
|
||||||
|
while( pro.DirExists() )
|
||||||
|
{
|
||||||
|
pro.RemoveLastDir();
|
||||||
|
wxString suffix = wxString::Format( "_%d", ++attempt );
|
||||||
|
pro.AppendDir( newDir + suffix );
|
||||||
|
}
|
||||||
|
|
||||||
if( !wxMkdir( pro.GetPath() ) )
|
if( !wxMkdir( pro.GetPath() ) )
|
||||||
// There was a problem, undo
|
{
|
||||||
pro.RemoveLastDir();
|
wxString msg = _( "Error creating new directory. Please try a different path. The "
|
||||||
|
"project was not imported." );
|
||||||
|
|
||||||
|
wxMessageDialog dlg( this, msg, _( "Error" ), wxOK_DEFAULT | wxICON_ERROR );
|
||||||
|
dlg.ShowModal();
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,13 +134,13 @@ void KICAD_MANAGER_FRAME::ImportNonKiCadProject( wxString aWindowTitle, wxString
|
||||||
wxFileName schCopy( pro );
|
wxFileName schCopy( pro );
|
||||||
schCopy.SetExt( aSchFileExtension );
|
schCopy.SetExt( aSchFileExtension );
|
||||||
|
|
||||||
if( sch.Exists() )
|
if( sch.Exists() && !schCopy.SameAs( sch ) )
|
||||||
wxCopyFile( sch.GetFullPath(), schCopy.GetFullPath(), true );
|
wxCopyFile( sch.GetFullPath(), schCopy.GetFullPath(), true );
|
||||||
|
|
||||||
wxFileName pcbCopy( pro );
|
wxFileName pcbCopy( pro );
|
||||||
pcbCopy.SetExt( aPcbFileExtension );
|
pcbCopy.SetExt( aPcbFileExtension );
|
||||||
|
|
||||||
if( pcb.Exists() )
|
if( pcb.Exists() && !pcbCopy.SameAs( pcb ) )
|
||||||
wxCopyFile( pcb.GetFullPath(), pcbCopy.GetFullPath(), true );
|
wxCopyFile( pcb.GetFullPath(), pcbCopy.GetFullPath(), true );
|
||||||
|
|
||||||
// Close the project and make the new one
|
// Close the project and make the new one
|
||||||
|
@ -148,6 +164,7 @@ void KICAD_MANAGER_FRAME::ImportNonKiCadProject( wxString aWindowTitle, wxString
|
||||||
|
|
||||||
schframe->Raise();
|
schframe->Raise();
|
||||||
|
|
||||||
|
if( !schCopy.SameAs( sch ) ) // Do not delete the original file!
|
||||||
wxRemoveFile( schCopy.GetFullPath() );
|
wxRemoveFile( schCopy.GetFullPath() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -167,6 +184,7 @@ void KICAD_MANAGER_FRAME::ImportNonKiCadProject( wxString aWindowTitle, wxString
|
||||||
|
|
||||||
pcbframe->Raise();
|
pcbframe->Raise();
|
||||||
|
|
||||||
|
if( !pcbCopy.SameAs( pcb ) ) // Do not delete the original file!
|
||||||
wxRemoveFile( pcbCopy.GetFullPath() );
|
wxRemoveFile( pcbCopy.GetFullPath() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue