mirror of
https://github.com/ModOrganizer2/modorganizer-plugin_python.git
synced 2026-07-27 14:03:33 -07:00
Back to a shared library for the runner.
This commit is contained in:
@@ -15,6 +15,12 @@ target_link_libraries(proxy PRIVATE runner)
|
||||
set_target_properties(proxy PROPERTIES OUTPUT_NAME ${PLUGIN_NAME})
|
||||
mo2_install_target(proxy FOLDER)
|
||||
|
||||
set(PLUGIN_PYTHON_DIR ${MO2_INSTALL_PATH}/bin/plugins/${PLUGIN_NAME})
|
||||
|
||||
# install runner
|
||||
target_link_options(proxy PRIVATE "/DELAYLOAD:runner.dll")
|
||||
mo2_install_target(runner INSTALLDIR ${PLUGIN_PYTHON_DIR}/dlls)
|
||||
|
||||
# translations (custom location)
|
||||
mo2_add_translations(proxy
|
||||
TS_FILE ${CMAKE_CURRENT_SOURCE_DIR}/../${PLUGIN_NAME}_en.ts
|
||||
@@ -25,14 +31,14 @@ mo2_add_translations(proxy
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../pybind11-qt)
|
||||
|
||||
# install DLLs files needed
|
||||
set(DLL_DIRS ${MO2_INSTALL_PATH}/bin/plugins/${PLUGIN_NAME}/dlls)
|
||||
set(DLL_DIRS ${PLUGIN_PYTHON_DIR}/dlls)
|
||||
file(GLOB dlls_to_install
|
||||
${PYTHON_BUILD_PATH}/libffi*.dll
|
||||
${PYTHON_BUILD_PATH}/python${Python_VERSION_SHORT}.dll)
|
||||
install(FILES ${dlls_to_install} DESTINATION ${DLL_DIRS})
|
||||
|
||||
# install Python files
|
||||
set(PYLIB_DIR ${MO2_INSTALL_PATH}/bin/plugins/${PLUGIN_NAME}/libs)
|
||||
set(PYLIB_DIR ${PLUGIN_PYTHON_DIR}/libs)
|
||||
file(GLOB libs_to_install ${PYTHON_BUILD_PATH}/pythoncore/*.pyd)
|
||||
install(FILES ${libs_to_install} DESTINATION ${PYLIB_DIR})
|
||||
install(FILES ${PYTHON_BUILD_PATH}/pythoncore/python${Python_VERSION_SHORT}.zip
|
||||
|
||||
+21
-11
@@ -54,7 +54,8 @@ fs::path getPluginFolder()
|
||||
}
|
||||
|
||||
ProxyPython::ProxyPython()
|
||||
: m_MOInfo{nullptr}, m_Runner{nullptr}, m_LoadFailure(FailureType::NONE)
|
||||
: m_MOInfo{nullptr}, m_RunnerLib{nullptr}, m_Runner{nullptr},
|
||||
m_LoadFailure(FailureType::NONE)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -81,16 +82,6 @@ bool ProxyPython::init(IOrganizer* moInfo)
|
||||
return false;
|
||||
}
|
||||
|
||||
// load the pythonrunner library
|
||||
const auto dllPaths = pluginFolder / "dlls";
|
||||
if (SetDllDirectoryW(dllPaths.c_str()) == 0) {
|
||||
DWORD error = ::GetLastError();
|
||||
m_LoadFailure = FailureType::DLL_NOT_FOUND;
|
||||
log::error("failed to add python DLL directory ({}): {}", error,
|
||||
qUtf8Printable(windowsErrorString(::GetLastError())));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_MOInfo && m_MOInfo->persistent(name(), "tryInit", false).toBool()) {
|
||||
m_LoadFailure = FailureType::INITIALIZATION;
|
||||
if (QMessageBox::question(
|
||||
@@ -115,6 +106,25 @@ bool ProxyPython::init(IOrganizer* moInfo)
|
||||
m_MOInfo->setPersistent(name(), "tryInit", true);
|
||||
}
|
||||
|
||||
// load the pythonrunner library, this is done in multiple steps:
|
||||
//
|
||||
// 1. we set the dlls/ subfolder (from the plugin) as the DLL directory so Windows
|
||||
// will look for DLLs in it, this is required to find the Python and libffi DLL, but
|
||||
// also the runner DLL
|
||||
//
|
||||
const auto dllPaths = pluginFolder / "dlls";
|
||||
if (SetDllDirectoryW(dllPaths.c_str()) == 0) {
|
||||
DWORD error = ::GetLastError();
|
||||
m_LoadFailure = FailureType::DLL_NOT_FOUND;
|
||||
log::error("failed to add python DLL directory ({}): {}", error,
|
||||
qUtf8Printable(windowsErrorString(::GetLastError())));
|
||||
return false;
|
||||
}
|
||||
|
||||
// 2. we create the Python runner, we do not need to use ::LinkLibrary and
|
||||
// ::GetProcAddress because we use delayed load for the runner DLL (see the
|
||||
// CMakeLists.txt)
|
||||
//
|
||||
m_Runner = mo2::python::createPythonRunner();
|
||||
|
||||
if (m_Runner) {
|
||||
|
||||
@@ -59,6 +59,7 @@ public: // IPluginDiagnose
|
||||
|
||||
private:
|
||||
MOBase::IOrganizer* m_MOInfo;
|
||||
HMODULE m_RunnerLib;
|
||||
std::unique_ptr<mo2::python::IPythonRunner> m_Runner;
|
||||
|
||||
enum class FailureType : unsigned int {
|
||||
|
||||
Reference in New Issue
Block a user