Avoid crashing due to empty lib tables in cli

Fixes https://gitlab.com/kicad/code/kicad/-/issues/13097
This commit is contained in:
Marek Roszko 2022-12-07 23:55:47 -05:00
parent 4277b25a0b
commit 2fc0cd68ed
5 changed files with 39 additions and 11 deletions

View File

@ -26,6 +26,7 @@
#include <wx/stockitem.h>
#include <wx/richmsgdlg.h>
#include <wx/choicdlg.h>
#include <wx/crt.h>
#include <confirm.h>
#include <dialogs/html_message_box.h>
#include <functional>
@ -285,6 +286,12 @@ void DisplayError( wxWindow* aParent, const wxString& aText, int aDisplayTime )
return;
}
if( !wxTheApp->IsGUI() )
{
wxFprintf( stderr, aText );
return;
}
wxMessageDialog* dlg;
int icon = aDisplayTime > 0 ? wxICON_INFORMATION : wxICON_ERROR;
@ -304,6 +311,12 @@ void DisplayErrorMessage( wxWindow* aParent, const wxString& aText, const wxStri
return;
}
if( !wxTheApp->IsGUI() )
{
wxFprintf( stderr, aText );
return;
}
wxMessageDialog* dlg;
dlg = new wxMessageDialog( aParent, aText, _( "Error" ),
@ -325,6 +338,12 @@ void DisplayInfoMessage( wxWindow* aParent, const wxString& aMessage, const wxSt
return;
}
if( !wxTheApp->IsGUI() )
{
wxFprintf( stdout, "%s %s", aMessage, aExtraInfo );
return;
}
wxMessageDialog* dlg;
int icon = wxICON_INFORMATION;

View File

@ -61,6 +61,8 @@
#include <panel_sym_display_options.h>
#include <sim/sim_plot_frame.h>
#include <wx/crt.h>
// The main sheet of the project
SCH_SHEET* g_RootSheet = nullptr;
@ -340,11 +342,14 @@ bool IFACE::OnKifaceStart( PGM_BASE* aProgram, int aCtlBits )
wxFileName fn = SYMBOL_LIB_TABLE::GetGlobalTableFileName();
if( !fn.FileExists() )
{
if( !( aCtlBits & KFCTL_CLI ) )
{
DIALOG_GLOBAL_SYM_LIB_TABLE_CONFIG fpDialog( nullptr );
fpDialog.ShowModal();
}
}
else
{
try
@ -360,10 +365,9 @@ bool IFACE::OnKifaceStart( PGM_BASE* aProgram, int aCtlBits )
// if we are here, a incorrect global symbol library table was found.
// Incorrect global symbol library table is not a fatal error:
// the user just has to edit the (partially) loaded table.
wxString msg = _(
"An error occurred attempting to load the global symbol library table.\n"
"Please edit this global symbol library table in Preferences menu."
);
wxString msg =
_( "An error occurred attempting to load the global symbol library table.\n"
"Please edit this global symbol library table in Preferences menu." );
DisplayErrorMessage( nullptr, msg, ioe.What() );
}

View File

@ -157,6 +157,7 @@ struct KIFACE
#define KFCTL_STANDALONE ( 1 << 0 ) ///< Running as a standalone Top.
#define KFCTL_CPP_PROJECT_SUITE ( 1 << 1 ) ///< Running under C++ project mgr, possibly with others.
#define KFCTL_CLI ( 1 << 2 ) ///< Running as CLI app
/**

View File

@ -357,7 +357,7 @@ void PGM_KICAD::Destroy()
}
KIWAY Kiway( &Pgm(), KFCTL_CPP_PROJECT_SUITE );
KIWAY Kiway( &Pgm(), KFCTL_CPP_PROJECT_SUITE | KFCTL_CLI );
/**

View File

@ -62,6 +62,7 @@
#include <wildcards_and_files_ext.h>
#include "pcbnew_jobs_handler.h"
#include <wx/crt.h>
/* init functions defined by swig */
@ -349,11 +350,14 @@ bool IFACE::OnKifaceStart( PGM_BASE* aProgram, int aCtlBits )
wxFileName fn = FP_LIB_TABLE::GetGlobalTableFileName();
if( !fn.FileExists() )
{
if( !( aCtlBits & KFCTL_CLI ) )
{
DIALOG_GLOBAL_FP_LIB_TABLE_CONFIG fpDialog( nullptr );
fpDialog.ShowModal();
}
}
else
{
try