fix: ImHex not starting on some platforms
This commit is contained in:
parent
65e2f1b5af
commit
9066891ce2
@ -41,8 +41,8 @@ namespace hex {
|
|||||||
|
|
||||||
class Plugin {
|
class Plugin {
|
||||||
public:
|
public:
|
||||||
explicit Plugin(const std::fs::path &path, bool libraryPlugin);
|
explicit Plugin(const std::fs::path &path);
|
||||||
explicit Plugin(PluginFunctions functions, bool libraryPlugin);
|
explicit Plugin(PluginFunctions functions);
|
||||||
|
|
||||||
Plugin(const Plugin &) = delete;
|
Plugin(const Plugin &) = delete;
|
||||||
Plugin(Plugin &&other) noexcept;
|
Plugin(Plugin &&other) noexcept;
|
||||||
@ -66,12 +66,11 @@ namespace hex {
|
|||||||
|
|
||||||
[[nodiscard]] std::span<SubCommand> getSubCommands() const;
|
[[nodiscard]] std::span<SubCommand> getSubCommands() const;
|
||||||
|
|
||||||
[[nodiscard]] bool isLibraryPlugin() const { return m_libraryPlugin; }
|
[[nodiscard]] bool isLibraryPlugin() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uintptr_t m_handle = 0;
|
uintptr_t m_handle = 0;
|
||||||
std::fs::path m_path;
|
std::fs::path m_path;
|
||||||
bool m_libraryPlugin;
|
|
||||||
|
|
||||||
mutable bool m_initialized = false;
|
mutable bool m_initialized = false;
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
namespace hex {
|
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)
|
#if defined(OS_WINDOWS)
|
||||||
m_handle = uintptr_t(LoadLibraryW(path.c_str()));
|
m_handle = uintptr_t(LoadLibraryW(path.c_str()));
|
||||||
|
|
||||||
@ -46,10 +46,9 @@ namespace hex {
|
|||||||
m_functions.getSubCommandsFunction = getPluginFunction<PluginFunctions::GetSubCommandsFunc>("getSubCommands");
|
m_functions.getSubCommandsFunction = getPluginFunction<PluginFunctions::GetSubCommandsFunc>("getSubCommands");
|
||||||
}
|
}
|
||||||
|
|
||||||
Plugin::Plugin(hex::PluginFunctions functions, bool libraryPlugin) {
|
Plugin::Plugin(hex::PluginFunctions functions) {
|
||||||
m_handle = 0;
|
m_handle = 0;
|
||||||
m_functions = functions;
|
m_functions = functions;
|
||||||
m_libraryPlugin = libraryPlugin;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -57,7 +56,6 @@ namespace hex {
|
|||||||
m_handle = other.m_handle;
|
m_handle = other.m_handle;
|
||||||
other.m_handle = 0;
|
other.m_handle = 0;
|
||||||
|
|
||||||
m_libraryPlugin = other.m_libraryPlugin;
|
|
||||||
m_path = std::move(other.m_path);
|
m_path = std::move(other.m_path);
|
||||||
|
|
||||||
m_functions = other.m_functions;
|
m_functions = other.m_functions;
|
||||||
@ -68,7 +66,6 @@ namespace hex {
|
|||||||
m_handle = other.m_handle;
|
m_handle = other.m_handle;
|
||||||
other.m_handle = 0;
|
other.m_handle = 0;
|
||||||
|
|
||||||
m_libraryPlugin = other.m_libraryPlugin;
|
|
||||||
m_path = std::move(other.m_path);
|
m_path = std::move(other.m_path);
|
||||||
|
|
||||||
m_functions = other.m_functions;
|
m_functions = other.m_functions;
|
||||||
@ -90,7 +87,7 @@ namespace hex {
|
|||||||
bool Plugin::initializePlugin() const {
|
bool Plugin::initializePlugin() const {
|
||||||
const auto pluginName = wolv::util::toUTF8String(m_path.filename());
|
const auto pluginName = wolv::util::toUTF8String(m_path.filename());
|
||||||
|
|
||||||
if (m_functions.initializeLibraryFunction != nullptr) {
|
if (this->isLibraryPlugin()) {
|
||||||
m_functions.initializeLibraryFunction();
|
m_functions.initializeLibraryFunction();
|
||||||
log::info("Library plugin '{}' initialized successfully", pluginName);
|
log::info("Library plugin '{}' initialized successfully", pluginName);
|
||||||
return true;
|
return true;
|
||||||
@ -192,6 +189,12 @@ namespace hex {
|
|||||||
return { };
|
return { };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Plugin::isLibraryPlugin() const {
|
||||||
|
return m_functions.initializeLibraryFunction != nullptr &&
|
||||||
|
m_functions.initializePluginFunction == nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void *Plugin::getPluginFunction(const std::string &symbol) const {
|
void *Plugin::getPluginFunction(const std::string &symbol) const {
|
||||||
#if defined(OS_WINDOWS)
|
#if defined(OS_WINDOWS)
|
||||||
@ -210,13 +213,13 @@ namespace hex {
|
|||||||
// Load library plugins first
|
// Load library plugins first
|
||||||
for (auto &pluginPath : std::fs::directory_iterator(pluginFolder)) {
|
for (auto &pluginPath : std::fs::directory_iterator(pluginFolder)) {
|
||||||
if (pluginPath.is_regular_file() && pluginPath.path().extension() == ".hexpluglib")
|
if (pluginPath.is_regular_file() && pluginPath.path().extension() == ".hexpluglib")
|
||||||
getPlugins().emplace_back(pluginPath.path(), true);
|
getPlugins().emplace_back(pluginPath.path());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load regular plugins afterwards
|
// Load regular plugins afterwards
|
||||||
for (auto &pluginPath : std::fs::directory_iterator(pluginFolder)) {
|
for (auto &pluginPath : std::fs::directory_iterator(pluginFolder)) {
|
||||||
if (pluginPath.is_regular_file() && pluginPath.path().extension() == ".hexplug")
|
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) {
|
std::erase_if(getPlugins(), [](const Plugin &plugin) {
|
||||||
@ -243,7 +246,7 @@ namespace hex {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PluginManager::addPlugin(hex::PluginFunctions functions) {
|
void PluginManager::addPlugin(hex::PluginFunctions functions) {
|
||||||
getPlugins().emplace_back(functions, false);
|
getPlugins().emplace_back(functions);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Plugin> &PluginManager::getPlugins() {
|
std::vector<Plugin> &PluginManager::getPlugins() {
|
||||||
|
@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 3.16)
|
|||||||
include(ImHexPlugin)
|
include(ImHexPlugin)
|
||||||
|
|
||||||
add_subdirectory(${THIRD_PARTY_LIBS_FOLDER}/HashLibPlus ${CMAKE_CURRENT_BINARY_DIR}/HashLibPlus)
|
add_subdirectory(${THIRD_PARTY_LIBS_FOLDER}/HashLibPlus ${CMAKE_CURRENT_BINARY_DIR}/HashLibPlus)
|
||||||
|
set_target_properties(hashplus PROPERTIES POSITION_INDEPENDENT_CODE ON)
|
||||||
|
|
||||||
add_imhex_plugin(
|
add_imhex_plugin(
|
||||||
NAME
|
NAME
|
||||||
|
Loading…
Reference in New Issue
Block a user