Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix plugin filter on Windows #567

Merged
merged 9 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions include/gz/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,9 @@ target_link_libraries(${PROJECT_LIBRARY_TARGET_NAME}
TINYXML2::TINYXML2
)

target_compile_definitions(${PROJECT_LIBRARY_TARGET_NAME} PRIVATE
SHARED_LIBRARY_PREFIX=\"${CMAKE_SHARED_LIBRARY_PREFIX}\"
SHARED_LIBRARY_SUFFIX=\"${CMAKE_SHARED_LIBRARY_SUFFIX}\")

gz_install_all_headers()

15 changes: 12 additions & 3 deletions src/Application.cc
Original file line number Diff line number Diff line change
Expand Up @@ -837,10 +837,19 @@ std::vector<std::pair<std::string, std::vector<std::string>>>
{
auto plugin = common::basename(*dirIter);

// All we verify is that the file starts with "lib", any further
// checks would require loading the plugin.
// All we verify is that the file starts with shared library prefix and
// ends with shared library suffix, any further checks would require
// loading the plugin.

if (plugin.find("lib") == 0)
// TODO(anyone): Move this logic into gz-plugin to be reusable

// This computation could underflow the unsigned range, but that is okay
// as in such case we would check if the suffix is placed somewhere much
// further than allowed filename length.
const auto suffixPos = plugin.length() - strlen(SHARED_LIBRARY_SUFFIX);

if (plugin.find(SHARED_LIBRARY_PREFIX) == 0 &&
plugin.rfind(SHARED_LIBRARY_SUFFIX) == suffixPos)
ps.push_back(plugin);
}

Expand Down
9 changes: 7 additions & 2 deletions src/MainWindow.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,13 @@ QStringList MainWindow::PluginListModel() const
{
for (auto const &plugin : path.second)
{
// Remove lib and .so
auto pluginName = plugin.substr(3, plugin.find(".") - 3);
// TODO(anyone): Move this into gz-plugin to be reusable

// Remove shared library prefix and shared library suffix
auto pluginName = plugin.substr(
strlen(SHARED_LIBRARY_PREFIX),
plugin.length() - strlen(SHARED_LIBRARY_PREFIX) -
strlen(SHARED_LIBRARY_SUFFIX));

// Split WWWCamelCase3D -> WWW Camel Case 3D
std::regex reg("(\\B[A-Z][a-z])|(\\B[0-9])");
Expand Down