2012-04-16 12:56:01 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2015-09-23 09:26:50 +00:00
|
|
|
* Copyright (C) 2004-2015 Jean-Pierre Charras
|
2020-03-21 14:31:26 +00:00
|
|
|
* Copyright (C) 2004-2020 KiCad Developers, see AUTHORS.txt for contributors.
|
2012-04-16 12:56:01 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2016-02-24 21:36:52 +00:00
|
|
|
/**
|
|
|
|
* @file kicad/files-io.cpp
|
|
|
|
*/
|
|
|
|
|
2021-03-20 15:35:37 +00:00
|
|
|
#include <wx/dir.h>
|
2021-05-01 07:50:29 +00:00
|
|
|
#include <wx/filedlg.h>
|
|
|
|
#include <wx/dirdlg.h>
|
2021-03-20 15:35:37 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <confirm.h>
|
2021-02-13 03:37:39 +00:00
|
|
|
#include <dialogs/panel_kicad_launcher.h>
|
2016-02-24 21:36:52 +00:00
|
|
|
#include <kiway.h>
|
2020-07-03 13:40:31 +00:00
|
|
|
#include <project/project_archiver.h>
|
|
|
|
#include <reporter.h>
|
|
|
|
#include <settings/settings_manager.h>
|
|
|
|
#include <wildcards_and_files_ext.h>
|
2016-02-24 21:36:52 +00:00
|
|
|
|
2019-06-09 10:10:19 +00:00
|
|
|
#include "kicad_manager_frame.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
2011-04-17 13:54:17 +00:00
|
|
|
void KICAD_MANAGER_FRAME::OnFileHistory( wxCommandEvent& event )
|
2009-01-17 20:31:19 +00:00
|
|
|
{
|
2020-05-16 21:47:01 +00:00
|
|
|
wxFileName projFileName = GetFileFromHistory( event.GetId(), _( "KiCad project file" ) );
|
2017-08-31 15:15:20 +00:00
|
|
|
if( !projFileName.FileExists() )
|
|
|
|
return;
|
2009-01-17 20:31:19 +00:00
|
|
|
|
2017-08-31 15:15:20 +00:00
|
|
|
LoadProject( projFileName );
|
2009-01-17 20:31:19 +00:00
|
|
|
}
|
|
|
|
|
2014-07-07 19:49:14 +00:00
|
|
|
|
2020-02-25 15:46:56 +00:00
|
|
|
void KICAD_MANAGER_FRAME::OnClearFileHistory( wxCommandEvent& aEvent )
|
|
|
|
{
|
2020-05-16 21:47:01 +00:00
|
|
|
ClearFileHistory();
|
2020-02-25 15:46:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-17 13:54:17 +00:00
|
|
|
void KICAD_MANAGER_FRAME::OnUnarchiveFiles( wxCommandEvent& event )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2020-07-03 13:40:31 +00:00
|
|
|
wxFileName fn = Prj().GetProjectFullName();
|
2014-07-07 19:49:14 +00:00
|
|
|
|
2020-07-03 13:40:31 +00:00
|
|
|
fn.SetExt( ArchiveFileExtension );
|
2008-12-08 15:27:13 +00:00
|
|
|
|
2015-09-25 18:45:45 +00:00
|
|
|
wxFileDialog zipfiledlg( this, _( "Unzip Project" ), fn.GetPath(),
|
2017-11-12 00:31:38 +00:00
|
|
|
fn.GetFullName(), ZipFileWildcard(),
|
2017-08-31 15:15:20 +00:00
|
|
|
wxFD_OPEN | wxFD_FILE_MUST_EXIST );
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2015-09-25 18:45:45 +00:00
|
|
|
if( zipfiledlg.ShowModal() == wxID_CANCEL )
|
2007-09-13 11:55:46 +00:00
|
|
|
return;
|
|
|
|
|
2021-11-04 00:02:14 +00:00
|
|
|
wxString msg = wxString::Format( _( "\nOpen '%s'\n" ), zipfiledlg.GetPath() );
|
2013-04-09 17:49:01 +00:00
|
|
|
PrintMsg( msg );
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2020-05-16 15:43:14 +00:00
|
|
|
wxDirDialog dirDlg( this, _( "Target Directory" ), fn.GetPath(), wxDD_DEFAULT_STYLE );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
if( dirDlg.ShowModal() == wxID_CANCEL )
|
2007-09-13 11:55:46 +00:00
|
|
|
return;
|
|
|
|
|
2015-09-25 18:45:45 +00:00
|
|
|
wxString unzipDir = dirDlg.GetPath() + wxT( "/" );
|
2021-06-16 22:35:00 +00:00
|
|
|
msg.Printf( _( "Unzipping project in '%s'.\n" ), unzipDir );
|
2013-04-09 17:49:01 +00:00
|
|
|
PrintMsg( msg );
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2020-07-03 13:40:31 +00:00
|
|
|
if( unzipDir == Prj().GetProjectPath() )
|
|
|
|
{
|
|
|
|
if( !Kiway().PlayersClose( false ) )
|
|
|
|
return;
|
|
|
|
}
|
2014-07-07 19:49:14 +00:00
|
|
|
|
2021-02-13 23:58:02 +00:00
|
|
|
STATUSBAR_REPORTER reporter( GetStatusBar(), 1 );
|
2020-07-03 13:40:31 +00:00
|
|
|
|
|
|
|
PROJECT_ARCHIVER archiver;
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2020-07-03 13:40:31 +00:00
|
|
|
archiver.Unarchive( zipfiledlg.GetPath(), unzipDir, reporter );
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2020-07-03 13:40:31 +00:00
|
|
|
if( unzipDir == Prj().GetProjectPath() )
|
2007-09-13 11:55:46 +00:00
|
|
|
{
|
2020-07-03 13:40:31 +00:00
|
|
|
wxString prjPath = Prj().GetProjectFullName();
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2021-06-06 22:36:31 +00:00
|
|
|
SETTINGS_MANAGER* mgr = GetSettingsManager();
|
2020-07-03 13:40:31 +00:00
|
|
|
|
2021-06-06 22:36:31 +00:00
|
|
|
mgr->UnloadProject( &Prj(), false );
|
|
|
|
mgr->LoadProject( prjPath );
|
2018-02-16 14:20:14 +00:00
|
|
|
|
2019-06-09 13:12:44 +00:00
|
|
|
RefreshProjectTree();
|
2020-07-03 13:40:31 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2011-04-17 13:54:17 +00:00
|
|
|
void KICAD_MANAGER_FRAME::OnArchiveFiles( wxCommandEvent& event )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2014-07-07 19:49:14 +00:00
|
|
|
wxFileName fileName = GetProjectFileName();
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2020-07-03 13:40:31 +00:00
|
|
|
fileName.SetExt( ArchiveFileExtension );
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
wxFileDialog dlg( this, _( "Archive Project Files" ),
|
|
|
|
fileName.GetPath(), fileName.GetFullName(),
|
2017-11-12 00:31:38 +00:00
|
|
|
ZipFileWildcard(), wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
if( dlg.ShowModal() == wxID_CANCEL )
|
|
|
|
return;
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2020-07-03 13:40:31 +00:00
|
|
|
wxFileName zipFile = dlg.GetPath();
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2014-10-17 12:52:11 +00:00
|
|
|
wxString currdirname = fileName.GetPathWithSep();
|
2009-04-13 05:58:11 +00:00
|
|
|
wxDir dir( currdirname );
|
2008-12-08 15:27:13 +00:00
|
|
|
|
2017-07-24 07:20:44 +00:00
|
|
|
if( !dir.IsOpened() ) // wxWidgets display a error message on issue.
|
2009-04-05 20:49:15 +00:00
|
|
|
return;
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2021-02-13 23:58:02 +00:00
|
|
|
STATUSBAR_REPORTER reporter( GetStatusBar(), 1 );
|
2020-07-03 13:40:31 +00:00
|
|
|
PROJECT_ARCHIVER archiver;
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2021-02-04 22:24:02 +00:00
|
|
|
archiver.Archive( currdirname, zipFile.GetFullPath(), reporter, true, true );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|