Commit 41670806 authored by jean-pierre charras's avatar jean-pierre charras

Kicad manager: fix Bug #1380935 (Archive function for projects strange behavior.)

Archive function now recurses project sub directories.
parent 5a947e67
...@@ -134,14 +134,14 @@ void KICAD_MANAGER_FRAME::OnArchiveFiles( wxCommandEvent& event ) ...@@ -134,14 +134,14 @@ void KICAD_MANAGER_FRAME::OnArchiveFiles( wxCommandEvent& event )
// List of file extensions to save. // List of file extensions to save.
static const wxChar* extentionList[] = { static const wxChar* extentionList[] = {
wxT( "*.sch" ), wxT( "*.lib" ), wxT( "*.mod" ), wxT( "*.cmp" ), wxT( "*.sch" ), wxT( "*.lib" ), wxT( "*.mod" ), wxT( "*.cmp" ),
wxT( "*.brd" ), wxT( "*.kicad_pcb" ), wxT( "*.gbr" ), wxT( "*.brd" ), wxT( "*.kicad_pcb" ), wxT( "*.gbr" ), wxT( "*.pos" ),
wxT( "*.net" ), wxT( "*.pro" ), wxT( "*.pho" ), wxT( "*.py" ), wxT( "*.net" ), wxT( "*.pro" ), wxT( "*.drl" ), wxT( "*.py" ),
wxT( "*.pdf" ), wxT( "*.txt" ), wxT( "*.dcm" ), wxT( "*.kicad_wks" ), wxT( "*.pdf" ), wxT( "*.txt" ), wxT( "*.dcm" ), wxT( "*.kicad_wks" ),
}; };
wxString msg; wxString msg;
wxFileName fileName = GetProjectFileName(); wxFileName fileName = GetProjectFileName();
wxString oldPath = wxGetCwd(); wxString oldCwd = wxGetCwd();
fileName.SetExt( wxT( "zip" ) ); fileName.SetExt( wxT( "zip" ) );
...@@ -154,13 +154,14 @@ void KICAD_MANAGER_FRAME::OnArchiveFiles( wxCommandEvent& event ) ...@@ -154,13 +154,14 @@ void KICAD_MANAGER_FRAME::OnArchiveFiles( wxCommandEvent& event )
wxFileName zip = dlg.GetPath(); wxFileName zip = dlg.GetPath();
wxString currdirname = wxT( "." ); wxString currdirname = fileName.GetPathWithSep();
currdirname += zip.GetPathSeparator();
wxDir dir( currdirname ); wxDir dir( currdirname );
if( !dir.IsOpened() ) if( !dir.IsOpened() )
return; return;
wxSetWorkingDirectory( currdirname );
// Prepare the zip file // Prepare the zip file
wxString zipfilename = zip.GetFullPath(); wxString zipfilename = zip.GetFullPath();
...@@ -169,20 +170,28 @@ void KICAD_MANAGER_FRAME::OnArchiveFiles( wxCommandEvent& event ) ...@@ -169,20 +170,28 @@ void KICAD_MANAGER_FRAME::OnArchiveFiles( wxCommandEvent& event )
// Build list of filenames to put in zip archive // Build list of filenames to put in zip archive
wxString currFilename; wxString currFilename;
int zipBytesCnt = 0; // Size of the zip file
for( unsigned i = 0; i<DIM( extentionList ); i++ ) wxArrayString files;
{
bool cont = dir.GetFirst( &currFilename, extentionList[i] ); for( unsigned ii = 0; ii < DIM( extentionList ); ii++ )
wxDir::GetAllFiles( currdirname, &files, extentionList[ii] );
while( cont ) files.Sort();
int zipBytesCnt = 0;
for( unsigned ii = 0; ii < files.GetCount(); ii++ )
{ {
wxFileSystem fsfile; wxFileSystem fsfile;
wxFileName curr_fn( files[ii] );
curr_fn.MakeRelativeTo( currdirname );
currFilename = curr_fn.GetFullPath();
msg.Printf(_( "Archive file <%s>" ), GetChars( currFilename ) ); msg.Printf(_( "Archive file <%s>" ), GetChars( currFilename ) );
PrintMsg( msg ); PrintMsg( msg );
// Read input file and put it in zip file: // Read input file and add it to the zip file:
wxFSFile* infile = fsfile.OpenFile(currFilename); wxFSFile* infile = fsfile.OpenFile(currFilename);
if( infile ) if( infile )
...@@ -199,15 +208,11 @@ void KICAD_MANAGER_FRAME::OnArchiveFiles( wxCommandEvent& event ) ...@@ -199,15 +208,11 @@ void KICAD_MANAGER_FRAME::OnArchiveFiles( wxCommandEvent& event )
delete infile; delete infile;
} }
else else
{
PrintMsg( _(" >>Error\n") ); PrintMsg( _(" >>Error\n") );
} }
cont = dir.GetNext( &currFilename );
}
}
zipBytesCnt = ostream.GetSize(); zipBytesCnt = ostream.GetSize();
if( zipstream.Close() ) if( zipstream.Close() )
{ {
msg.Printf( _("\nZip archive <%s> created (%d bytes)" ), msg.Printf( _("\nZip archive <%s> created (%d bytes)" ),
...@@ -222,5 +227,5 @@ void KICAD_MANAGER_FRAME::OnArchiveFiles( wxCommandEvent& event ) ...@@ -222,5 +227,5 @@ void KICAD_MANAGER_FRAME::OnArchiveFiles( wxCommandEvent& event )
PrintMsg( msg ); PrintMsg( msg );
} }
wxSetWorkingDirectory( oldPath ); wxSetWorkingDirectory( oldCwd );
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment