2020-07-21 00:33:35 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2020 Mark Roszko <mark.roszko@gmail.com>
|
|
|
|
* Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
|
|
|
|
*
|
|
|
|
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <kiplatform/app.h>
|
|
|
|
|
2020-09-01 10:14:51 +00:00
|
|
|
#include <wx/log.h>
|
2020-07-21 00:33:35 +00:00
|
|
|
#include <wx/string.h>
|
2020-09-01 10:14:51 +00:00
|
|
|
#include <wx/window.h>
|
2021-03-20 14:28:35 +00:00
|
|
|
#include <wx/msgdlg.h>
|
2020-07-21 00:33:35 +00:00
|
|
|
|
|
|
|
#include <windows.h>
|
|
|
|
#include <strsafe.h>
|
2021-03-19 21:26:07 +00:00
|
|
|
#include <config.h>
|
|
|
|
#include <VersionHelpers.h>
|
|
|
|
|
|
|
|
|
2021-03-23 19:09:57 +00:00
|
|
|
bool KIPLATFORM::APP::Init()
|
2021-03-19 21:26:07 +00:00
|
|
|
{
|
|
|
|
#if defined( _MSC_VER ) && defined( DEBUG )
|
|
|
|
// wxWidgets turns on leak dumping in debug but its "flawed" and will falsely dump
|
|
|
|
// for half a hour _CRTDBG_ALLOC_MEM_DF is the usual default for MSVC.
|
|
|
|
_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF );
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined( PYTHON_VERSION_MAJOR ) && ( ( PYTHON_VERSION_MAJOR == 3 && PYTHON_VERSION_MINOR >= 8 ) \
|
|
|
|
|| 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. Gracefully inform the user and refuse to start (because
|
|
|
|
// python will crash us if we continue).
|
|
|
|
if( !IsWindows8OrGreater() )
|
|
|
|
{
|
|
|
|
wxMessageBox( _( "Windows 7 and older is no longer supported by KiCad and its "
|
|
|
|
"dependencies." ), _( "Unsupported Operating System" ),
|
|
|
|
wxOK | wxICON_ERROR );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2021-03-19 22:36:16 +00:00
|
|
|
return true;
|
2021-03-19 21:26:07 +00:00
|
|
|
}
|
2020-07-21 00:33:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
bool KIPLATFORM::APP::RegisterApplicationRestart( const wxString& aCommandLine )
|
|
|
|
{
|
2021-02-01 20:35:54 +00:00
|
|
|
// Ensure we don't exceed the maximum allowable size
|
|
|
|
if( aCommandLine.length() > RESTART_MAX_CMD_LINE - 1 )
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2020-07-21 00:33:35 +00:00
|
|
|
|
2021-02-01 20:35:54 +00:00
|
|
|
HRESULT hr = S_OK;
|
2020-07-21 00:33:35 +00:00
|
|
|
|
2021-02-01 20:35:54 +00:00
|
|
|
hr = ::RegisterApplicationRestart( aCommandLine.wc_str(), RESTART_NO_PATCH );
|
2020-07-21 00:33:35 +00:00
|
|
|
|
|
|
|
return SUCCEEDED( hr );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool KIPLATFORM::APP::UnregisterApplicationRestart()
|
|
|
|
{
|
|
|
|
// Note, this isn't required to be used on Windows if you are just closing the program
|
|
|
|
return SUCCEEDED( ::UnregisterApplicationRestart() );
|
2020-09-01 10:14:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool KIPLATFORM::APP::SupportsShutdownBlockReason()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void KIPLATFORM::APP::RemoveShutdownBlockReason( wxWindow* aWindow )
|
|
|
|
{
|
|
|
|
// Destroys any block reason that may have existed
|
|
|
|
ShutdownBlockReasonDestroy( aWindow->GetHandle() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void KIPLATFORM::APP::SetShutdownBlockReason( wxWindow* aWindow, const wxString& aReason )
|
|
|
|
{
|
|
|
|
// Sets up the pretty message on the shutdown page on why it's being "blocked"
|
|
|
|
// This is used in conjunction with handling WM_QUERYENDSESSION (wxCloseEvent)
|
|
|
|
// ShutdownBlockReasonCreate does not block by itself
|
|
|
|
|
|
|
|
ShutdownBlockReasonDestroy( aWindow->GetHandle() ); // Destroys any existing or nonexisting reason
|
|
|
|
|
|
|
|
ShutdownBlockReasonCreate( aWindow->GetHandle(), aReason.wc_str() );
|
2020-10-12 01:44:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void KIPLATFORM::APP::ForceTimerMessagesToBeCreatedIfNecessary()
|
|
|
|
{
|
|
|
|
// Taken from https://devblogs.microsoft.com/oldnewthing/20191108-00/?p=103080
|
|
|
|
MSG msg;
|
|
|
|
PeekMessage( &msg, nullptr, WM_TIMER, WM_TIMER, PM_NOREMOVE );
|
2021-03-19 21:26:07 +00:00
|
|
|
}
|
2021-03-21 13:16:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
void KIPLATFORM::APP::AddDynamicLibrarySearchPath( const wxString& aPath )
|
|
|
|
{
|
|
|
|
SetDllDirectoryA( aPath.c_str() );
|
|
|
|
}
|