ui/api: Added loaded plugin information to welcome screen

This commit is contained in:
WerWolv
2021-02-19 13:22:12 +01:00
parent 89643d1538
commit 0da508594b
8 changed files with 125 additions and 22 deletions

View File

@@ -1,7 +1,5 @@
#include "helpers/plugin_handler.hpp"
#include <dlfcn.h>
#include <filesystem>
namespace hex {
@@ -9,24 +7,37 @@ namespace hex {
namespace fs = std::filesystem;
// hex::plugin::<pluginName>::internal::initializePlugin()
constexpr auto InitializePluginSymbol = "_ZN3hex6plugin%d%s8internal16initializePluginEv";
constexpr auto InitializePluginSymbol = "_ZN3hex6plugin%d%s8internal16initializePluginEv";
constexpr auto GetPluginNameSymbol = "_ZN3hex6plugin%d%s8internal13getPluginNameEv";
constexpr auto GetPluginAuthorSymbol = "_ZN3hex6plugin%d%s8internal15getPluginAuthorEv";
constexpr auto GetPluginDescriptionSymbol = "_ZN3hex6plugin%d%s8internal20getPluginDescriptionEv";
Plugin::Plugin(std::string_view path) {
auto fileName = fs::path(path).stem();
auto symbolName = hex::format(InitializePluginSymbol, fileName.string().length(), fileName.string().c_str());
this->m_handle = dlopen(path.data(), RTLD_LAZY);
if (this->m_handle == nullptr)
return;
this->m_initializePluginFunction = reinterpret_cast<InitializePluginFunc>(dlsym(this->m_handle, symbolName.c_str()));
auto pluginName = fs::path(path).stem().string();
this->m_initializePluginFunction = getPluginFunction<InitializePluginFunc>(pluginName, InitializePluginSymbol);
this->m_getPluginNameFunction = getPluginFunction<GetPluginNameFunc>(pluginName, GetPluginNameSymbol);
this->m_getPluginAuthorFunction = getPluginFunction<GetPluginAuthorFunc>(pluginName, GetPluginAuthorSymbol);
this->m_getPluginDescriptionFunction = getPluginFunction<GetPluginDescriptionFunc>(pluginName, GetPluginDescriptionSymbol);
}
Plugin::Plugin(Plugin &&other) {
Plugin::Plugin(Plugin &&other) noexcept {
this->m_handle = other.m_handle;
this->m_initializePluginFunction = other.m_initializePluginFunction;
this->m_initializePluginFunction = other.m_initializePluginFunction;
this->m_getPluginNameFunction = other.m_getPluginNameFunction;
this->m_getPluginAuthorFunction = other.m_getPluginAuthorFunction;
this->m_getPluginDescriptionFunction = other.m_getPluginDescriptionFunction;
other.m_handle = nullptr;
other.m_initializePluginFunction = nullptr;
other.m_initializePluginFunction = nullptr;
other.m_getPluginNameFunction = nullptr;
other.m_getPluginAuthorFunction = nullptr;
other.m_getPluginDescriptionFunction = nullptr;
}
Plugin::~Plugin() {
@@ -34,9 +45,29 @@ namespace hex {
}
void Plugin::initializePlugin() const {
if (this->m_initializePluginFunction != nullptr) {
if (this->m_initializePluginFunction != nullptr)
this->m_initializePluginFunction();
}
}
std::string Plugin::getPluginName() const {
if (this->m_getPluginNameFunction != nullptr)
return this->m_getPluginNameFunction();
else
return hex::format("Unknown Plugin @ 0x016llX", this->m_handle);
}
std::string Plugin::getPluginAuthor() const {
if (this->m_getPluginAuthorFunction != nullptr)
return this->m_getPluginAuthorFunction();
else
return "Unknown";
}
std::string Plugin::getPluginDescription() const {
if (this->m_getPluginDescriptionFunction != nullptr)
return this->m_getPluginDescriptionFunction();
else
return "";
}
void PluginHandler::load(std::string_view pluginFolder) {

View File

@@ -177,7 +177,7 @@ namespace hex {
if (this->m_averageEntropy > 0.83 && this->m_highestBlockEntropy > 0.9) {
ImGui::NewLine();
ImGui::TextColored(ImVec4(0.92F, 0.25F, 0.2F, 1.0F),"hex.view.information.encrypted"_lang);
ImGui::TextColored(ImVec4(0.92F, 0.25F, 0.2F, 1.0F), "hex.view.information.encrypted"_lang);
}
}

View File

@@ -364,6 +364,7 @@ namespace hex {
if (ImGui::BulletHyperlink("hex.welcome.start.open_project"_lang))
EventManager::post(Events::OpenWindow, "Open Project");
}
ImGui::TableNextRow(ImGuiTableRowFlags_None, rowHeight);
ImGui::TableNextColumn();
ImGui::TextUnformatted("hex.welcome.start.recent"_lang);
@@ -377,6 +378,7 @@ namespace hex {
}
}
}
ImGui::TableNextRow(ImGuiTableRowFlags_None, rowHeight);
ImGui::TableNextColumn();
ImGui::TextUnformatted("hex.welcome.header.help"_lang);
@@ -385,6 +387,49 @@ namespace hex {
if (ImGui::BulletHyperlink("hex.welcome.help.gethelp"_lang)) hex::openWebpage("hex.welcome.help.gethelp.link"_lang);
}
ImGui::TableNextRow(ImGuiTableRowFlags_None, rowHeight);
ImGui::TableNextColumn();
ImGui::TextUnformatted("hex.welcome.header.plugins"_lang);
{
const auto &plugins = PluginHandler::getPlugins();
if (plugins.empty()) {
// Intentionally left untranslated so it will be readable even if no plugin with translations is loaded
ImGui::TextColored(ImVec4(0.92F, 0.25F, 0.2F, 1.0F),
"No plugins loaded! To use ImHex properly, "
"make sure at least the builtin plugin is in the /plugins folder next to the executable");
} else {
if (ImGui::BeginTable("plugins", 3, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg | ImGuiTableFlags_ScrollY | ImGuiTableFlags_SizingFixedFit, ImVec2((ImGui::GetContentRegionAvail().x * 5) / 6, ImGui::GetTextLineHeightWithSpacing() * 4))) {
ImGui::TableSetupScrollFreeze(0, 1);
ImGui::TableSetupColumn("hex.welcome.plugins.plugin"_lang);
ImGui::TableSetupColumn("hex.welcome.plugins.author"_lang);
ImGui::TableSetupColumn("hex.welcome.plugins.desc"_lang);
ImGui::TableHeadersRow();
ImGuiListClipper clipper;
clipper.Begin(plugins.size());
while (clipper.Step()) {
for (u64 i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) {
ImGui::TableNextRow();
ImGui::TableNextColumn();
ImGui::TextUnformatted((plugins[i].getPluginName() + " ").c_str());
ImGui::TableNextColumn();
ImGui::TextUnformatted((plugins[i].getPluginAuthor() + " ").c_str());
ImGui::TableNextColumn();
ImGui::TextUnformatted(plugins[i].getPluginDescription().c_str());
}
}
clipper.End();
ImGui::EndTable();
}
}
}
ImGui::EndTable();
}
ImGui::SameLine();