diff --git a/api/proto/common/commands/base_commands.proto b/api/proto/common/commands/base_commands.proto index e0fd5880c6..39d36981e8 100644 --- a/api/proto/common/commands/base_commands.proto +++ b/api/proto/common/commands/base_commands.proto @@ -37,6 +37,19 @@ message Ping { } +// Returns the full path to the given KiCad binary +message GetKiCadBinaryPath +{ + // The short name of the binary, such as `kicad-cli` or `kicad-cli.exe`. If on Windows, an `.exe` + // extension will be assumed if not present. + string binary_name = 1; +} + +message PathResponse +{ + string path = 1; +} + // returns kiapi.common.types.Box2 message GetTextExtents { diff --git a/common/api/api_handler_common.cpp b/common/api/api_handler_common.cpp index 8ef3d3d7b2..ab0e9df85d 100644 --- a/common/api/api_handler_common.cpp +++ b/common/api/api_handler_common.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -43,7 +44,9 @@ using google::protobuf::Empty; API_HANDLER_COMMON::API_HANDLER_COMMON() : API_HANDLER() { - registerHandler( &API_HANDLER_COMMON::handleGetVersion ); + registerHandler( &API_HANDLER_COMMON::handleGetVersion ); + registerHandler( + &API_HANDLER_COMMON::handleGetKiCadBinaryPath ); registerHandler( &API_HANDLER_COMMON::handleGetNetClasses ); registerHandler( &API_HANDLER_COMMON::handleSetNetClasses ); registerHandler( &API_HANDLER_COMMON::handlePing ); @@ -78,6 +81,21 @@ HANDLER_RESULT API_HANDLER_COMMON::handleGetVersion( } +HANDLER_RESULT API_HANDLER_COMMON::handleGetKiCadBinaryPath( + const HANDLER_CONTEXT& aCtx ) +{ + wxFileName fn( wxEmptyString, wxString::FromUTF8( aCtx.Request.binary_name() ) ); +#ifdef _WIN32 + fn.SetExt( wxT( "exe" ) ); +#endif + + wxString path = FindKicadFile( fn.GetFullName() ); + PathResponse reply; + reply.set_path( path.ToUTF8() ); + return reply; +} + + HANDLER_RESULT API_HANDLER_COMMON::handleGetNetClasses( const HANDLER_CONTEXT& aCtx ) { diff --git a/include/api/api_handler_common.h b/include/api/api_handler_common.h index c1ace3fa0b..01ac0f0e8f 100644 --- a/include/api/api_handler_common.h +++ b/include/api/api_handler_common.h @@ -41,6 +41,9 @@ private: HANDLER_RESULT handleGetVersion( const HANDLER_CONTEXT& aCtx ); + HANDLER_RESULT handleGetKiCadBinaryPath( + const HANDLER_CONTEXT& aCtx ); + HANDLER_RESULT handleGetNetClasses( const HANDLER_CONTEXT& aCtx );