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 <build_version.h> #include <eda_shape.h> #include <eda_text.h> +#include <gestfich.h> #include <geometry/shape_compound.h> #include <google/protobuf/empty.pb.h> #include <paths.h> @@ -43,7 +44,9 @@ using google::protobuf::Empty; API_HANDLER_COMMON::API_HANDLER_COMMON() : API_HANDLER() { - registerHandler<commands::GetVersion, GetVersionResponse>( &API_HANDLER_COMMON::handleGetVersion ); + registerHandler<GetVersion, GetVersionResponse>( &API_HANDLER_COMMON::handleGetVersion ); + registerHandler<GetKiCadBinaryPath, PathResponse>( + &API_HANDLER_COMMON::handleGetKiCadBinaryPath ); registerHandler<GetNetClasses, NetClassesResponse>( &API_HANDLER_COMMON::handleGetNetClasses ); registerHandler<SetNetClasses, Empty>( &API_HANDLER_COMMON::handleSetNetClasses ); registerHandler<Ping, Empty>( &API_HANDLER_COMMON::handlePing ); @@ -78,6 +81,21 @@ HANDLER_RESULT<GetVersionResponse> API_HANDLER_COMMON::handleGetVersion( } +HANDLER_RESULT<PathResponse> API_HANDLER_COMMON::handleGetKiCadBinaryPath( + const HANDLER_CONTEXT<GetKiCadBinaryPath>& 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<NetClassesResponse> API_HANDLER_COMMON::handleGetNetClasses( const HANDLER_CONTEXT<GetNetClasses>& 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<commands::GetVersionResponse> handleGetVersion( const HANDLER_CONTEXT<commands::GetVersion>& aCtx ); + HANDLER_RESULT<commands::PathResponse> handleGetKiCadBinaryPath( + const HANDLER_CONTEXT<commands::GetKiCadBinaryPath>& aCtx ); + HANDLER_RESULT<commands::NetClassesResponse> handleGetNetClasses( const HANDLER_CONTEXT<commands::GetNetClasses>& aCtx );