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,45 +170,49 @@ void KICAD_MANAGER_FRAME::OnArchiveFiles( wxCommandEvent& event ) ...@@ -169,45 +170,49 @@ 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;
for( unsigned ii = 0; ii < DIM( extentionList ); ii++ )
wxDir::GetAllFiles( currdirname, &files, extentionList[ii] );
files.Sort();
int zipBytesCnt = 0;
for( unsigned ii = 0; ii < files.GetCount(); ii++ )
{ {
bool cont = dir.GetFirst( &currFilename, extentionList[i] ); wxFileSystem fsfile;
while( cont ) wxFileName curr_fn( files[ii] );
{ curr_fn.MakeRelativeTo( currdirname );
wxFileSystem fsfile; 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 add it to the zip file:
wxFSFile* infile = fsfile.OpenFile(currFilename);
// Read input file and put it in zip file: if( infile )
wxFSFile* infile = fsfile.OpenFile(currFilename); {
zipstream.PutNextEntry( currFilename, infile->GetModificationTime() );
if( infile ) infile->GetStream()->Read( zipstream );
{ zipstream.CloseEntry();
zipstream.PutNextEntry( currFilename, infile->GetModificationTime() ); int zippedsize = zipstream.GetSize() - zipBytesCnt;
infile->GetStream()->Read( zipstream ); zipBytesCnt = zipstream.GetSize();
zipstream.CloseEntry(); PrintMsg( wxT(" ") );
int zippedsize = zipstream.GetSize() - zipBytesCnt; msg.Printf( _( "(%d bytes, compressed %d bytes)\n"),
zipBytesCnt = zipstream.GetSize(); infile->GetStream()->GetSize(), zippedsize );
PrintMsg( wxT(" ") ); PrintMsg( msg );
msg.Printf( _( "(%d bytes, compressed %d bytes)\n"), delete infile;
infile->GetStream()->GetSize(), zippedsize );
PrintMsg( msg );
delete infile;
}
else
{
PrintMsg( _(" >>Error\n") );
}
cont = dir.GetNext( &currFilename );
} }
else
PrintMsg( _(" >>Error\n") );
} }
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