Non-KiCad Project importers: Make a temporary copy of the files to project folder before importing
Delete thee temporary files after import. Fixes https://gitlab.com/kicad/code/kicad/-/issues/6596
This commit is contained in:
parent
a5118df44c
commit
6af4e57853
|
@ -29,6 +29,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <wx/filefn.h>
|
||||||
#include <wx/filename.h>
|
#include <wx/filename.h>
|
||||||
#include <wx/dir.h>
|
#include <wx/dir.h>
|
||||||
|
|
||||||
|
@ -62,11 +63,12 @@ void KICAD_MANAGER_FRAME::ImportNonKiCadProject( wxString aWindowTitle, wxString
|
||||||
|
|
||||||
|
|
||||||
wxFileName sch( schdlg.GetPath() );
|
wxFileName sch( schdlg.GetPath() );
|
||||||
|
|
||||||
sch.SetExt( aSchFileExtension );
|
sch.SetExt( aSchFileExtension );
|
||||||
|
|
||||||
wxFileName pro = sch;
|
wxFileName pcb( sch );
|
||||||
|
pcb.SetExt( aPcbFileExtension );
|
||||||
|
|
||||||
|
wxFileName pro( sch );
|
||||||
pro.SetExt( ProjectFileExtension );
|
pro.SetExt( ProjectFileExtension );
|
||||||
|
|
||||||
wxString protitle = _( "KiCad Project Destination" );
|
wxString protitle = _( "KiCad Project Destination" );
|
||||||
|
@ -105,25 +107,36 @@ void KICAD_MANAGER_FRAME::ImportNonKiCadProject( wxString aWindowTitle, wxString
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
wxFileName pcb( sch );
|
|
||||||
std::string packet;
|
std::string packet;
|
||||||
|
|
||||||
pro.SetExt( ProjectFileExtension );
|
pro.SetExt( ProjectFileExtension );
|
||||||
pcb.SetExt( aPcbFileExtension ); // enforce extension
|
|
||||||
|
|
||||||
if( !pro.IsAbsolute() )
|
if( !pro.IsAbsolute() )
|
||||||
pro.MakeAbsolute();
|
pro.MakeAbsolute();
|
||||||
|
|
||||||
|
wxFileName schCopy( pro );
|
||||||
|
schCopy.SetExt( aSchFileExtension );
|
||||||
|
|
||||||
|
if( sch.Exists() )
|
||||||
|
wxCopyFile( sch.GetFullPath(), schCopy.GetFullPath(), true );
|
||||||
|
|
||||||
|
wxFileName pcbCopy( pro );
|
||||||
|
pcbCopy.SetExt( aPcbFileExtension );
|
||||||
|
|
||||||
|
if( pcb.Exists() )
|
||||||
|
wxCopyFile( pcb.GetFullPath(), pcbCopy.GetFullPath(), true );
|
||||||
|
|
||||||
// Close the project and make the new one
|
// Close the project and make the new one
|
||||||
CloseProject( true );
|
CloseProject( true );
|
||||||
CreateNewProject( pro.GetFullPath(), false /* Don't create stub files */ );
|
CreateNewProject( pro.GetFullPath(), false /* Don't create stub files */ );
|
||||||
LoadProject( pro );
|
LoadProject( pro );
|
||||||
|
|
||||||
if( sch.FileExists() )
|
if( schCopy.FileExists() )
|
||||||
{
|
{
|
||||||
KIWAY_PLAYER* schframe = Kiway().Player( FRAME_SCH, true );
|
KIWAY_PLAYER* schframe = Kiway().Player( FRAME_SCH, true );
|
||||||
|
|
||||||
packet = StrPrintf( "%d\n%s", aSchFileType, TO_UTF8( sch.GetFullPath() ) );
|
packet = StrPrintf( "%d\n%s", aSchFileType, TO_UTF8( schCopy.GetFullPath() ) );
|
||||||
schframe->Kiway().ExpressMail( FRAME_SCH, MAIL_IMPORT_FILE, packet, this );
|
schframe->Kiway().ExpressMail( FRAME_SCH, MAIL_IMPORT_FILE, packet, this );
|
||||||
|
|
||||||
if( !schframe->IsShown() )
|
if( !schframe->IsShown() )
|
||||||
|
@ -134,16 +147,18 @@ void KICAD_MANAGER_FRAME::ImportNonKiCadProject( wxString aWindowTitle, wxString
|
||||||
schframe->Iconize( false );
|
schframe->Iconize( false );
|
||||||
|
|
||||||
schframe->Raise();
|
schframe->Raise();
|
||||||
|
|
||||||
|
wxRemoveFile( schCopy.GetFullPath() );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( pcb.FileExists() )
|
if( pcbCopy.FileExists() )
|
||||||
{
|
{
|
||||||
KIWAY_PLAYER* pcbframe = Kiway().Player( FRAME_PCB_EDITOR, true );
|
KIWAY_PLAYER* pcbframe = Kiway().Player( FRAME_PCB_EDITOR, true );
|
||||||
|
|
||||||
if( !pcbframe->IsVisible() )
|
if( !pcbframe->IsVisible() )
|
||||||
pcbframe->Show( true );
|
pcbframe->Show( true );
|
||||||
|
|
||||||
packet = StrPrintf( "%d\n%s", aPcbFileType, TO_UTF8( pcb.GetFullPath() ) );
|
packet = StrPrintf( "%d\n%s", aPcbFileType, TO_UTF8( pcbCopy.GetFullPath() ) );
|
||||||
pcbframe->Kiway().ExpressMail( FRAME_PCB_EDITOR, MAIL_IMPORT_FILE, packet, this );
|
pcbframe->Kiway().ExpressMail( FRAME_PCB_EDITOR, MAIL_IMPORT_FILE, packet, this );
|
||||||
|
|
||||||
// On Windows, Raise() does not bring the window on screen, when iconized
|
// On Windows, Raise() does not bring the window on screen, when iconized
|
||||||
|
@ -151,6 +166,8 @@ void KICAD_MANAGER_FRAME::ImportNonKiCadProject( wxString aWindowTitle, wxString
|
||||||
pcbframe->Iconize( false );
|
pcbframe->Iconize( false );
|
||||||
|
|
||||||
pcbframe->Raise();
|
pcbframe->Raise();
|
||||||
|
|
||||||
|
wxRemoveFile( pcbCopy.GetFullPath() );
|
||||||
}
|
}
|
||||||
|
|
||||||
ReCreateTreePrj();
|
ReCreateTreePrj();
|
||||||
|
|
Loading…
Reference in New Issue