KiCad: do not attempt to load non-project files.

Fixes https://gitlab.com/kicad/code/kicad/issues/7456
This commit is contained in:
Wayne Stambaugh 2021-02-10 15:10:44 -05:00
parent 19d786852a
commit 286a364ad4
1 changed files with 39 additions and 18 deletions

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2004-2015 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2004-2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2004-2018 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 2004-2021 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -24,7 +24,7 @@
/** /**
* @file kicad.cpp * @file kicad.cpp
* @brief Main KiCad Project manager file * Main KiCad project manager file.
*/ */
@ -39,6 +39,7 @@
#include <kiway.h> #include <kiway.h>
#include <settings/settings_manager.h> #include <settings/settings_manager.h>
#include <systemdirsappend.h> #include <systemdirsappend.h>
#include <wildcards_and_files_ext.h>
#include <stdexcept> #include <stdexcept>
@ -79,6 +80,7 @@ PGM_BASE* PgmOrNull()
return &program; return &program;
} }
PGM_KICAD& PgmTop() PGM_KICAD& PgmTop()
{ {
return program; return program;
@ -149,7 +151,23 @@ bool PGM_KICAD::OnPgmInit()
wxString projToLoad; wxString projToLoad;
if( App().argc > 1 ) if( App().argc > 1 )
projToLoad = App().argv[1]; {
wxFileName tmp = App().argv[1];
if( tmp.GetExt() != ProjectFileExtension && tmp.GetExt() != LegacyProjectFileExtension )
{
wxString msg;
msg.Printf( _( "File '%s'\ndoes not appear to be a valid KiCad project file." ),
tmp.GetFullPath() );
wxMessageDialog dlg( nullptr, msg, _( "Error" ), wxOK | wxICON_EXCLAMATION );
dlg.ShowModal();
}
else
{
projToLoad = tmp.GetFullPath();
}
}
// If no file was given as an argument, check that there was a file open. // If no file was given as an argument, check that there was a file open.
if( projToLoad.IsEmpty() && settings->m_OpenProjects.size() ) if( projToLoad.IsEmpty() && settings->m_OpenProjects.size() )
@ -229,8 +247,7 @@ KIWAY Kiway( &Pgm(), KFCTL_CPP_PROJECT_SUITE );
/** /**
* Struct APP_KICAD * Not publicly visible because most of the action is in #PGM_KICAD these days.
* is not publicly visible because most of the action is in PGM_KICAD these days.
*/ */
struct APP_KICAD : public wxApp struct APP_KICAD : public wxApp
{ {
@ -247,15 +264,17 @@ struct APP_KICAD : public wxApp
wxSetEnv ( wxT("UBUNTU_MENUPROXY" ), wxT( "0" ) ); wxSetEnv ( wxT("UBUNTU_MENUPROXY" ), wxT( "0" ) );
} }
// Force the use of X11 backend (or wayland-x11 compatibilty layer). This is required until wxWidgets // Force the use of X11 backend (or wayland-x11 compatibilty layer). This is
// supports the Wayland compositors // required until wxWidgets supports the Wayland compositors
wxSetEnv( wxT( "GDK_BACKEND" ), wxT( "x11" ) ); wxSetEnv( wxT( "GDK_BACKEND" ), wxT( "x11" ) );
// Disable overlay scrollbars as they mess up wxWidgets window sizing and cause excessive redraw requests // Disable overlay scrollbars as they mess up wxWidgets window sizing and cause
// excessive redraw requests.
wxSetEnv( wxT( "GTK_OVERLAY_SCROLLING" ), wxT( "0" ) ); wxSetEnv( wxT( "GTK_OVERLAY_SCROLLING" ), wxT( "0" ) );
// Set GTK2-style input instead of xinput2. This disables touchscreen and smooth scrolling // Set GTK2-style input instead of xinput2. This disables touchscreen and smooth
// Needed to ensure that we are not getting multiple mouse scroll events // scrolling. It's needed to ensure that we are not getting multiple mouse scroll
// events.
wxSetEnv( wxT( "GDK_CORE_DEVICE_EVENTS" ), wxT( "1" ) ); wxSetEnv( wxT( "GDK_CORE_DEVICE_EVENTS" ), wxT( "1" ) );
} }
#endif #endif
@ -263,8 +282,8 @@ struct APP_KICAD : public wxApp
bool OnInit() override bool OnInit() override
{ {
#if defined( _MSC_VER ) && defined( DEBUG ) #if defined( _MSC_VER ) && defined( DEBUG )
// wxWidgets turns on leak dumping in debug but its "flawed" and will falsely dump for half a hour // wxWidgets turns on leak dumping in debug but its "flawed" and will falsely dump
// _CRTDBG_ALLOC_MEM_DF is the usual default for MSVC // for half a hour _CRTDBG_ALLOC_MEM_DF is the usual default for MSVC.
_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF ); _CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF );
#endif #endif
@ -272,12 +291,14 @@ struct APP_KICAD : public wxApp
&& ( ( PYTHON_VERSION_MAJOR == 3 && PYTHON_VERSION_MINOR >= 8 ) \ && ( ( PYTHON_VERSION_MAJOR == 3 && PYTHON_VERSION_MINOR >= 8 ) \
|| PYTHON_VERSION_MAJOR > 3 ) || PYTHON_VERSION_MAJOR > 3 )
// Python 3.8 switched to Windows 8+ API, we do not support Windows 7 and will not attempt to hack around it // Python 3.8 switched to Windows 8+ API, we do not support Windows 7 and will not
// Gracefully inform the user and refuse to start (because python will crash us if we continue) // attempt to hack around it. Gracefully inform the user and refuse to start (because
// python will crash us if we continue).
if( !IsWindows8OrGreater() ) if( !IsWindows8OrGreater() )
{ {
wxMessageBox( _( "Windows 7 and older is no longer supported by KiCad and its dependencies." ), wxMessageBox( _( "Windows 7 and older is no longer supported by KiCad and its "
_( "Unsupported Operating System" ), wxOK | wxICON_ERROR ); "dependencies." ), _( "Unsupported Operating System" ),
wxOK | wxICON_ERROR );
return false; return false;
} }
#endif #endif
@ -296,7 +317,7 @@ struct APP_KICAD : public wxApp
program.OnPgmExit(); program.OnPgmExit();
#if defined(__FreeBSD__) #if defined(__FreeBSD__)
/* Avoid wxLog crashing when used in destructors. */ // Avoid wxLog crashing when used in destructors.
wxLog::EnableLogging( false ); wxLog::EnableLogging( false );
#endif #endif
@ -312,7 +333,7 @@ struct APP_KICAD : public wxApp
catch( const std::exception& e ) catch( const std::exception& e )
{ {
wxLogError( wxT( "Unhandled exception class: %s what: %s" ), wxLogError( wxT( "Unhandled exception class: %s what: %s" ),
FROM_UTF8( typeid( e ).name() ), FROM_UTF8( e.what() ) ); FROM_UTF8( typeid( e ).name() ), FROM_UTF8( e.what() ) );
} }
catch( const IO_ERROR& ioe ) catch( const IO_ERROR& ioe )
{ {