1
0
mirror of synced 2024-11-27 17:10:51 +01:00

fix: ImHex not starting on some platforms

This commit is contained in:
WerWolv 2023-12-24 12:20:51 +01:00
parent 65e2f1b5af
commit 9066891ce2
3 changed files with 16 additions and 13 deletions

View File

@ -41,8 +41,8 @@ namespace hex {
class Plugin {
public:
explicit Plugin(const std::fs::path &path, bool libraryPlugin);
explicit Plugin(PluginFunctions functions, bool libraryPlugin);
explicit Plugin(const std::fs::path &path);
explicit Plugin(PluginFunctions functions);
Plugin(const Plugin &) = delete;
Plugin(Plugin &&other) noexcept;
@ -66,12 +66,11 @@ namespace hex {
[[nodiscard]] std::span<SubCommand> getSubCommands() const;
[[nodiscard]] bool isLibraryPlugin() const { return m_libraryPlugin; }
[[nodiscard]] bool isLibraryPlugin() const;
private:
uintptr_t m_handle = 0;
std::fs::path m_path;
bool m_libraryPlugin;
mutable bool m_initialized = false;

View File

@ -16,7 +16,7 @@
namespace hex {
Plugin::Plugin(const std::fs::path &path, bool libraryPlugin) : m_path(path), m_libraryPlugin(libraryPlugin) {
Plugin::Plugin(const std::fs::path &path) : m_path(path) {
#if defined(OS_WINDOWS)
m_handle = uintptr_t(LoadLibraryW(path.c_str()));
@ -46,10 +46,9 @@ namespace hex {
m_functions.getSubCommandsFunction = getPluginFunction<PluginFunctions::GetSubCommandsFunc>("getSubCommands");
}
Plugin::Plugin(hex::PluginFunctions functions, bool libraryPlugin) {
Plugin::Plugin(hex::PluginFunctions functions) {
m_handle = 0;
m_functions = functions;
m_libraryPlugin = libraryPlugin;
}
@ -57,7 +56,6 @@ namespace hex {
m_handle = other.m_handle;
other.m_handle = 0;
m_libraryPlugin = other.m_libraryPlugin;
m_path = std::move(other.m_path);
m_functions = other.m_functions;
@ -68,7 +66,6 @@ namespace hex {
m_handle = other.m_handle;
other.m_handle = 0;
m_libraryPlugin = other.m_libraryPlugin;
m_path = std::move(other.m_path);
m_functions = other.m_functions;
@ -90,7 +87,7 @@ namespace hex {
bool Plugin::initializePlugin() const {
const auto pluginName = wolv::util::toUTF8String(m_path.filename());
if (m_functions.initializeLibraryFunction != nullptr) {
if (this->isLibraryPlugin()) {
m_functions.initializeLibraryFunction();
log::info("Library plugin '{}' initialized successfully", pluginName);
return true;
@ -192,6 +189,12 @@ namespace hex {
return { };
}
bool Plugin::isLibraryPlugin() const {
return m_functions.initializeLibraryFunction != nullptr &&
m_functions.initializePluginFunction == nullptr;
}
void *Plugin::getPluginFunction(const std::string &symbol) const {
#if defined(OS_WINDOWS)
@ -210,13 +213,13 @@ namespace hex {
// Load library plugins first
for (auto &pluginPath : std::fs::directory_iterator(pluginFolder)) {
if (pluginPath.is_regular_file() && pluginPath.path().extension() == ".hexpluglib")
getPlugins().emplace_back(pluginPath.path(), true);
getPlugins().emplace_back(pluginPath.path());
}
// Load regular plugins afterwards
for (auto &pluginPath : std::fs::directory_iterator(pluginFolder)) {
if (pluginPath.is_regular_file() && pluginPath.path().extension() == ".hexplug")
getPlugins().emplace_back(pluginPath.path(), false);
getPlugins().emplace_back(pluginPath.path());
}
std::erase_if(getPlugins(), [](const Plugin &plugin) {
@ -243,7 +246,7 @@ namespace hex {
}
void PluginManager::addPlugin(hex::PluginFunctions functions) {
getPlugins().emplace_back(functions, false);
getPlugins().emplace_back(functions);
}
std::vector<Plugin> &PluginManager::getPlugins() {

View File

@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 3.16)
include(ImHexPlugin)
add_subdirectory(${THIRD_PARTY_LIBS_FOLDER}/HashLibPlus ${CMAKE_CURRENT_BINARY_DIR}/HashLibPlus)
set_target_properties(hashplus PROPERTIES POSITION_INDEPENDENT_CODE ON)
add_imhex_plugin(
NAME