mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-04-21 16:43:44 +00:00
Fix path processing for odb job
This commit is contained in:
parent
6beeabd5d2
commit
97787778eb
pcbnew
@ -24,6 +24,7 @@
|
||||
#include <footprint.h>
|
||||
#include <kidialog.h>
|
||||
#include <kiway_holder.h>
|
||||
#include <paths.h>
|
||||
#include <pcb_edit_frame.h>
|
||||
#include <pcbnew_settings.h>
|
||||
#include <pgm_base.h>
|
||||
@ -249,6 +250,7 @@ bool DIALOG_EXPORT_ODBPP::Init()
|
||||
m_choiceUnits->SetSelection( static_cast<int>( m_job->m_units ) );
|
||||
m_precision->SetValue( m_job->m_precision );
|
||||
m_choiceCompress->SetSelection( static_cast<int>( m_job->m_compressionMode ) );
|
||||
m_outputFileName->SetValue( m_job->GetOutputPath() );
|
||||
}
|
||||
|
||||
// DIALOG_SHIM needs a unique hash_key because classname will be the same for both job and
|
||||
@ -291,46 +293,42 @@ void DIALOG_EXPORT_ODBPP::GenerateODBPPFiles( const JOB_EXPORT_PCB_ODB& aJob, BO
|
||||
REPORTER* aReporter )
|
||||
{
|
||||
wxCHECK( aBoard, /* void */ );
|
||||
wxString outputPath = aJob.GetOutputPath();
|
||||
wxString outputPath = aJob.GetFullOutputPath( NULL );
|
||||
|
||||
if( outputPath.IsEmpty() )
|
||||
outputPath = wxFileName( aJob.m_filename ).GetPath();
|
||||
|
||||
wxFileName pcbFileName( outputPath );
|
||||
wxFileName outputFn( outputPath );
|
||||
|
||||
// Write through symlinks, don't replace them
|
||||
WX_FILENAME::ResolvePossibleSymlinks( pcbFileName );
|
||||
WX_FILENAME::ResolvePossibleSymlinks( outputFn );
|
||||
|
||||
if( pcbFileName.GetPath().IsEmpty() && pcbFileName.HasName() )
|
||||
pcbFileName.MakeAbsolute();
|
||||
if( outputFn.GetPath().IsEmpty() && outputFn.HasName() )
|
||||
outputFn.MakeAbsolute();
|
||||
|
||||
wxString msg;
|
||||
|
||||
if( !wxFileName::DirExists( pcbFileName.GetPath() ) )
|
||||
if( !PATHS::EnsurePathExists( outputFn.GetPath(),
|
||||
aJob.m_compressionMode != JOB_EXPORT_PCB_ODB::ODB_COMPRESSION::NONE ) )
|
||||
{
|
||||
// Make every directory provided when the provided path doesn't exist
|
||||
if( !wxFileName::Mkdir( pcbFileName.GetPath(), wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ) )
|
||||
{
|
||||
msg.Printf( _( "Cannot create output directory '%s'." ), pcbFileName.GetFullPath() );
|
||||
msg.Printf( _( "Cannot create output directory '%s'." ), outputFn.GetFullPath() );
|
||||
|
||||
if( aReporter )
|
||||
aReporter->Report( msg, RPT_SEVERITY_ERROR );
|
||||
|
||||
return;
|
||||
}
|
||||
if( aReporter )
|
||||
aReporter->Report( msg, RPT_SEVERITY_ERROR );
|
||||
return;
|
||||
}
|
||||
|
||||
if( pcbFileName.IsDir() && !pcbFileName.IsDirWritable() )
|
||||
if( outputFn.IsDir() && !outputFn.IsDirWritable() )
|
||||
{
|
||||
msg.Printf( _( "Insufficient permissions to folder '%s'." ), pcbFileName.GetPath() );
|
||||
msg.Printf( _( "Insufficient permissions to folder '%s'." ), outputFn.GetPath() );
|
||||
}
|
||||
else if( !pcbFileName.FileExists() && !pcbFileName.IsDirWritable() )
|
||||
else if( !outputFn.FileExists() && !outputFn.IsDirWritable() )
|
||||
{
|
||||
msg.Printf( _( "Insufficient permissions to save file '%s'." ), pcbFileName.GetFullPath() );
|
||||
msg.Printf( _( "Insufficient permissions to save file '%s'." ), outputFn.GetFullPath() );
|
||||
}
|
||||
else if( pcbFileName.FileExists() && !pcbFileName.IsFileWritable() )
|
||||
else if( outputFn.FileExists() && !outputFn.IsFileWritable() )
|
||||
{
|
||||
msg.Printf( _( "Insufficient permissions to save file '%s'." ), pcbFileName.GetFullPath() );
|
||||
msg.Printf( _( "Insufficient permissions to save file '%s'." ), outputFn.GetFullPath() );
|
||||
}
|
||||
|
||||
if( !msg.IsEmpty() )
|
||||
@ -341,17 +339,17 @@ void DIALOG_EXPORT_ODBPP::GenerateODBPPFiles( const JOB_EXPORT_PCB_ODB& aJob, BO
|
||||
return;
|
||||
}
|
||||
|
||||
wxFileName tempFile( pcbFileName.GetFullPath() );
|
||||
wxFileName tempFile( outputFn.GetFullPath() );
|
||||
|
||||
if( aJob.m_compressionMode != JOB_EXPORT_PCB_ODB::ODB_COMPRESSION::NONE )
|
||||
{
|
||||
if( pcbFileName.Exists() )
|
||||
if( outputFn.Exists() )
|
||||
{
|
||||
if( aParentFrame )
|
||||
{
|
||||
msg = wxString::Format( _( "Output files '%s' already exists. "
|
||||
"Do you want to overwrite it?" ),
|
||||
pcbFileName.GetFullPath() );
|
||||
outputFn.GetFullPath() );
|
||||
|
||||
KIDIALOG errorDlg( aParentFrame, msg, _( "Confirmation" ),
|
||||
wxOK | wxCANCEL | wxICON_WARNING );
|
||||
@ -360,10 +358,10 @@ void DIALOG_EXPORT_ODBPP::GenerateODBPPFiles( const JOB_EXPORT_PCB_ODB& aJob, BO
|
||||
if( errorDlg.ShowModal() != wxID_OK )
|
||||
return;
|
||||
|
||||
if( !wxRemoveFile( pcbFileName.GetFullPath() ) )
|
||||
if( !wxRemoveFile( outputFn.GetFullPath() ) )
|
||||
{
|
||||
msg.Printf( _( "Cannot remove existing output file '%s'." ),
|
||||
pcbFileName.GetFullPath() );
|
||||
outputFn.GetFullPath() );
|
||||
DisplayErrorMessage( aParentFrame, msg );
|
||||
return;
|
||||
}
|
||||
@ -371,7 +369,7 @@ void DIALOG_EXPORT_ODBPP::GenerateODBPPFiles( const JOB_EXPORT_PCB_ODB& aJob, BO
|
||||
else
|
||||
{
|
||||
msg = wxString::Format( _( "Output file '%s' already exists." ),
|
||||
pcbFileName.GetFullPath() );
|
||||
outputFn.GetFullPath() );
|
||||
|
||||
if( aReporter )
|
||||
aReporter->Report( msg, RPT_SEVERITY_ERROR );
|
||||
@ -501,7 +499,7 @@ void DIALOG_EXPORT_ODBPP::GenerateODBPPFiles( const JOB_EXPORT_PCB_ODB& aJob, BO
|
||||
if( aProgressReporter )
|
||||
aProgressReporter->AdvancePhase( _( "Compressing output" ) );
|
||||
|
||||
wxFFileOutputStream fnout( pcbFileName.GetFullPath() );
|
||||
wxFFileOutputStream fnout( outputFn.GetFullPath() );
|
||||
wxZipOutputStream zipStream( fnout );
|
||||
|
||||
std::function<void( const wxString&, const wxString& )> addDirToZip =
|
||||
@ -545,7 +543,7 @@ void DIALOG_EXPORT_ODBPP::GenerateODBPPFiles( const JOB_EXPORT_PCB_ODB& aJob, BO
|
||||
}
|
||||
else if( aJob.m_compressionMode == JOB_EXPORT_PCB_ODB::ODB_COMPRESSION::TGZ )
|
||||
{
|
||||
wxFFileOutputStream fnout( pcbFileName.GetFullPath() );
|
||||
wxFFileOutputStream fnout( outputFn.GetFullPath() );
|
||||
wxZlibOutputStream zlibStream( fnout, -1, wxZLIB_GZIP );
|
||||
wxTarOutputStream tarStream( zlibStream );
|
||||
|
||||
|
@ -1855,7 +1855,7 @@ int PCBNEW_JOBS_HANDLER::JobExportIpc2581( JOB* aJob )
|
||||
|
||||
aJob->SetTitleBlock( brd->GetTitleBlock() );
|
||||
|
||||
if( job->OutputPathFullSpecified() )
|
||||
if( !job->OutputPathFullSpecified() )
|
||||
{
|
||||
wxFileName fn = brd->GetFileName();
|
||||
fn.SetName( fn.GetName() );
|
||||
@ -1950,39 +1950,35 @@ int PCBNEW_JOBS_HANDLER::JobExportOdb( JOB* aJob )
|
||||
|
||||
aJob->SetTitleBlock( brd->GetTitleBlock() );
|
||||
|
||||
wxFileName fn( brd->GetFileName() );
|
||||
wxString path = job->GetOutputPath();
|
||||
|
||||
if( path.IsEmpty() )
|
||||
if( !job->OutputPathFullSpecified() )
|
||||
{
|
||||
wxFileName outputfn( fn.GetPath(), wxString::Format( wxS( "%s-odb" ), fn.GetName() ) );
|
||||
path = outputfn.GetFullPath();
|
||||
if( job->m_compressionMode == JOB_EXPORT_PCB_ODB::ODB_COMPRESSION::NONE )
|
||||
{
|
||||
// just basic folder name
|
||||
job->SetOutputPath( "odb" );
|
||||
}
|
||||
else
|
||||
{
|
||||
wxFileName fn( brd->GetFileName() );
|
||||
fn.SetName( fn.GetName() + wxS( "-odb" ) );
|
||||
|
||||
switch( job->m_compressionMode )
|
||||
{
|
||||
case JOB_EXPORT_PCB_ODB::ODB_COMPRESSION::ZIP:
|
||||
fn.SetExt( FILEEXT::ArchiveFileExtension );
|
||||
break;
|
||||
case JOB_EXPORT_PCB_ODB::ODB_COMPRESSION::TGZ:
|
||||
fn.SetExt( "tgz" );
|
||||
break;
|
||||
default: break;
|
||||
};
|
||||
|
||||
job->SetOutputPath( fn.GetFullName() );
|
||||
}
|
||||
}
|
||||
|
||||
wxFileName fileName( path );
|
||||
|
||||
int sepIdx = std::max( path.Find( '/', true ), path.Find( '\\', true ) );
|
||||
int dotIdx = path.Find( '.', true );
|
||||
|
||||
if( fileName.IsDir() && path.EndsWith( wxFileName::GetPathSeparator() ) )
|
||||
path = path.Mid( 0, sepIdx );
|
||||
else if( sepIdx < dotIdx )
|
||||
path = path.Mid( 0, dotIdx );
|
||||
|
||||
switch( job->m_compressionMode )
|
||||
{
|
||||
case JOB_EXPORT_PCB_ODB::ODB_COMPRESSION::ZIP:
|
||||
path = path + '.' + FILEEXT::ArchiveFileExtension;
|
||||
break;
|
||||
case JOB_EXPORT_PCB_ODB::ODB_COMPRESSION::TGZ: path += ".tgz"; break;
|
||||
case JOB_EXPORT_PCB_ODB::ODB_COMPRESSION::NONE:
|
||||
path = wxFileName( path, "" ).GetFullPath();
|
||||
break;
|
||||
default: break;
|
||||
};
|
||||
|
||||
job->SetOutputPath( path );
|
||||
|
||||
DIALOG_EXPORT_ODBPP::GenerateODBPPFiles( *job, brd, nullptr, m_progressReporter, m_reporter );
|
||||
|
||||
return CLI::EXIT_CODES::SUCCESS;
|
||||
|
Loading…
Reference in New Issue
Block a user