mirror of
https://github.com/ModOrganizer2/modorganizer-plugin_python.git
synced 2026-07-27 14:03:33 -07:00
Compare commits
12
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c7203bf9de | ||
|
|
a7d626c83c | ||
|
|
bbea63e7af | ||
|
|
9f607a5fcb | ||
|
|
868ab93a1f | ||
|
|
dec620b5b7 | ||
|
|
5da6a9d3bd | ||
|
|
573be8c6b5 | ||
|
|
2c661da2da | ||
|
|
fa09fd7635 | ||
|
|
84fe2b0307 | ||
|
|
e7e686c361 |
+15
-14
@@ -37,7 +37,7 @@ const char *ProxyPython::s_DownloadPythonURL = "http://www.python.org/download/r
|
|||||||
|
|
||||||
HMODULE GetOwnModuleHandle()
|
HMODULE GetOwnModuleHandle()
|
||||||
{
|
{
|
||||||
HMODULE hMod = NULL;
|
HMODULE hMod = nullptr;
|
||||||
GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
|
GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
|
||||||
reinterpret_cast<LPCWSTR>(&GetOwnModuleHandle), &hMod);
|
reinterpret_cast<LPCWSTR>(&GetOwnModuleHandle), &hMod);
|
||||||
|
|
||||||
@@ -50,12 +50,12 @@ QString ExtractResource(WORD resourceID, const QString &szFilename)
|
|||||||
HMODULE mod = GetOwnModuleHandle();
|
HMODULE mod = GetOwnModuleHandle();
|
||||||
|
|
||||||
HRSRC hResource = FindResourceW(mod, MAKEINTRESOURCE(resourceID), L"BINARY");
|
HRSRC hResource = FindResourceW(mod, MAKEINTRESOURCE(resourceID), L"BINARY");
|
||||||
if (hResource == NULL) {
|
if (hResource == nullptr) {
|
||||||
throw MyException("embedded dll not available: " + windowsErrorString(::GetLastError()));
|
throw MyException("embedded dll not available: " + windowsErrorString(::GetLastError()));
|
||||||
}
|
}
|
||||||
|
|
||||||
HGLOBAL hFileResource = LoadResource(mod, hResource);
|
HGLOBAL hFileResource = LoadResource(mod, hResource);
|
||||||
if (hFileResource == NULL) {
|
if (hFileResource == nullptr) {
|
||||||
throw MyException("failed to load embedded dll resource: " + windowsErrorString(::GetLastError()));
|
throw MyException("failed to load embedded dll resource: " + windowsErrorString(::GetLastError()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,8 +64,8 @@ QString ExtractResource(WORD resourceID, const QString &szFilename)
|
|||||||
|
|
||||||
QString outFile = QDir::tempPath() + "/" + szFilename;
|
QString outFile = QDir::tempPath() + "/" + szFilename;
|
||||||
|
|
||||||
HANDLE hFile = CreateFileW(ToWString(outFile).c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
|
HANDLE hFile = CreateFileW(outFile.toStdWString().c_str(), GENERIC_READ | GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
|
||||||
HANDLE hFileMap = CreateFileMapping(hFile, NULL, PAGE_READWRITE, 0, dwSize, NULL);
|
HANDLE hFileMap = CreateFileMapping(hFile, nullptr, PAGE_READWRITE, 0, dwSize, nullptr);
|
||||||
LPVOID lpAddress = MapViewOfFile(hFileMap, FILE_MAP_WRITE, 0, 0, 0);
|
LPVOID lpAddress = MapViewOfFile(hFileMap, FILE_MAP_WRITE, 0, 0, 0);
|
||||||
|
|
||||||
CopyMemory(lpAddress, lpFile, dwSize);
|
CopyMemory(lpAddress, lpFile, dwSize);
|
||||||
@@ -73,6 +73,7 @@ QString ExtractResource(WORD resourceID, const QString &szFilename)
|
|||||||
UnmapViewOfFile(lpAddress);
|
UnmapViewOfFile(lpAddress);
|
||||||
|
|
||||||
CloseHandle(hFileMap);
|
CloseHandle(hFileMap);
|
||||||
|
::FlushFileBuffers(hFile);
|
||||||
CloseHandle(hFile);
|
CloseHandle(hFile);
|
||||||
|
|
||||||
return outFile;
|
return outFile;
|
||||||
@@ -80,7 +81,7 @@ QString ExtractResource(WORD resourceID, const QString &szFilename)
|
|||||||
|
|
||||||
|
|
||||||
ProxyPython::ProxyPython()
|
ProxyPython::ProxyPython()
|
||||||
: m_MOInfo(NULL), m_Runner(NULL), m_LoadFailure(FAIL_NOTINIT)
|
: m_MOInfo(nullptr), m_Runner(nullptr), m_LoadFailure(FAIL_NOTINIT)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,9 +119,9 @@ bool ProxyPython::init(IOrganizer *moInfo)
|
|||||||
|
|
||||||
m_TempRunnerFile = ExtractResource(IDR_LOADER_DLL, "__pythonRunner.dll");
|
m_TempRunnerFile = ExtractResource(IDR_LOADER_DLL, "__pythonRunner.dll");
|
||||||
m_RunnerLib = ::LoadLibraryW(ToWString(m_TempRunnerFile).c_str());
|
m_RunnerLib = ::LoadLibraryW(ToWString(m_TempRunnerFile).c_str());
|
||||||
if (m_RunnerLib != NULL) {
|
if (m_RunnerLib != nullptr) {
|
||||||
CreatePythonRunner_func CreatePythonRunner = (CreatePythonRunner_func)::GetProcAddress(m_RunnerLib, "CreatePythonRunner");
|
CreatePythonRunner_func CreatePythonRunner = (CreatePythonRunner_func)::GetProcAddress(m_RunnerLib, "CreatePythonRunner");
|
||||||
if (CreatePythonRunner == NULL) {
|
if (CreatePythonRunner == nullptr) {
|
||||||
throw MyException("embedded dll is invalid: " + windowsErrorString(::GetLastError()));
|
throw MyException("embedded dll is invalid: " + windowsErrorString(::GetLastError()));
|
||||||
}
|
}
|
||||||
if (m_MOInfo->persistent(name(), "tryInit", false).toBool()) {
|
if (m_MOInfo->persistent(name(), "tryInit", false).toBool()) {
|
||||||
@@ -145,7 +146,7 @@ bool ProxyPython::init(IOrganizer *moInfo)
|
|||||||
m_Runner = CreatePythonRunner(moInfo, pythonPath);
|
m_Runner = CreatePythonRunner(moInfo, pythonPath);
|
||||||
m_MOInfo->setPersistent(name(), "tryInit", false);
|
m_MOInfo->setPersistent(name(), "tryInit", false);
|
||||||
|
|
||||||
if (m_Runner != NULL) {
|
if (m_Runner != nullptr) {
|
||||||
m_LoadFailure = FAIL_NONE;
|
m_LoadFailure = FAIL_NONE;
|
||||||
} else {
|
} else {
|
||||||
m_LoadFailure = FAIL_INITFAIL;
|
m_LoadFailure = FAIL_INITFAIL;
|
||||||
@@ -153,7 +154,7 @@ bool ProxyPython::init(IOrganizer *moInfo)
|
|||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
DWORD error = ::GetLastError();
|
DWORD error = ::GetLastError();
|
||||||
qCritical("Failed to load python runner: %s", qPrintable(windowsErrorString(error)));
|
qCritical("Failed to load python runner (%s): %s", qPrintable(m_TempRunnerFile), qPrintable(windowsErrorString(error)));
|
||||||
if (error == ERROR_MOD_NOT_FOUND) {
|
if (error == ERROR_MOD_NOT_FOUND) {
|
||||||
m_LoadFailure = FAIL_MISSINGDEPENDENCIES;
|
m_LoadFailure = FAIL_MISSINGDEPENDENCIES;
|
||||||
}
|
}
|
||||||
@@ -209,11 +210,11 @@ QStringList ProxyPython::pluginList(const QString &pluginPath) const
|
|||||||
|
|
||||||
QObject *ProxyPython::instantiate(const QString &pluginName)
|
QObject *ProxyPython::instantiate(const QString &pluginName)
|
||||||
{
|
{
|
||||||
if (m_Runner != NULL) {
|
if (m_Runner != nullptr) {
|
||||||
QObject *result = m_Runner->instantiate(pluginName);
|
QObject *result = m_Runner->instantiate(pluginName);
|
||||||
return result;
|
return result;
|
||||||
} else {
|
} else {
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -231,7 +232,7 @@ std::vector<unsigned int> ProxyPython::activeProblems() const
|
|||||||
result.push_back(PROBLEM_INITFAIL);
|
result.push_back(PROBLEM_INITFAIL);
|
||||||
} else if (m_LoadFailure == FAIL_SEMICOLON) {
|
} else if (m_LoadFailure == FAIL_SEMICOLON) {
|
||||||
result.push_back(PROBLEM_SEMICOLON);
|
result.push_back(PROBLEM_SEMICOLON);
|
||||||
} else if (m_Runner != NULL) {
|
} else if (m_Runner != nullptr) {
|
||||||
if (!m_Runner->isPythonInstalled()) {
|
if (!m_Runner->isPythonInstalled()) {
|
||||||
// don't know how this could happen but wth
|
// don't know how this could happen but wth
|
||||||
result.push_back(PROBLEM_PYTHONMISSING);
|
result.push_back(PROBLEM_PYTHONMISSING);
|
||||||
@@ -317,7 +318,7 @@ bool ProxyPython::hasGuidedFix(unsigned int key) const
|
|||||||
void ProxyPython::startGuidedFix(unsigned int key) const
|
void ProxyPython::startGuidedFix(unsigned int key) const
|
||||||
{
|
{
|
||||||
if ((key == PROBLEM_PYTHONMISSING) || (key == PROBLEM_PYTHONWRONGVERSION)) {
|
if ((key == PROBLEM_PYTHONMISSING) || (key == PROBLEM_PYTHONWRONGVERSION)) {
|
||||||
::ShellExecuteA(NULL, "open", s_DownloadPythonURL, NULL, NULL, SW_SHOWNORMAL);
|
::ShellExecuteA(nullptr, "open", s_DownloadPythonURL, nullptr, nullptr, SW_SHOWNORMAL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
//#define HAVE_ROUND
|
|
||||||
#include "proxypluginwrappers.h"
|
#include "proxypluginwrappers.h"
|
||||||
#include <utility.h>
|
#include <utility.h>
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
|
|||||||
@@ -13,14 +13,13 @@ CONFIG += warn_on
|
|||||||
DEFINES += PYTHONRUNNER_LIBRARY
|
DEFINES += PYTHONRUNNER_LIBRARY
|
||||||
|
|
||||||
# suppress a few warnings caused by boost vs vc++ paranoia
|
# suppress a few warnings caused by boost vs vc++ paranoia
|
||||||
DEFINES += _SCL_SECURE_NO_WARNINGS -DHAVE_ROUND
|
DEFINES += _SCL_SECURE_NO_WARNINGS HAVE_ROUND
|
||||||
|
|
||||||
|
|
||||||
!include(../LocalPaths.pri) {
|
!include(../LocalPaths.pri) {
|
||||||
message("paths to required libraries need to be set up in LocalPaths.pri")
|
message("paths to required libraries need to be set up in LocalPaths.pri")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
SOURCES += pythonrunner.cpp \
|
SOURCES += pythonrunner.cpp \
|
||||||
gilock.cpp \
|
gilock.cpp \
|
||||||
error.cpp \
|
error.cpp \
|
||||||
|
|||||||
+34
-32
@@ -1,5 +1,3 @@
|
|||||||
#define HAVE_ROUND
|
|
||||||
|
|
||||||
#include "pythonrunner.h"
|
#include "pythonrunner.h"
|
||||||
|
|
||||||
#pragma warning( disable : 4100 )
|
#pragma warning( disable : 4100 )
|
||||||
@@ -22,7 +20,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
MOBase::IOrganizer *s_Organizer = NULL;
|
MOBase::IOrganizer *s_Organizer = nullptr;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -55,7 +53,7 @@ IPythonRunner *CreatePythonRunner(MOBase::IOrganizer *moInfo, const QString &pyt
|
|||||||
return result;
|
return result;
|
||||||
} else {
|
} else {
|
||||||
delete result;
|
delete result;
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,13 +101,13 @@ struct QString_from_python_str
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void *convertible(PyObject *objPtr) {
|
static void *convertible(PyObject *objPtr) {
|
||||||
return PyString_Check(objPtr) ? objPtr : NULL;
|
return PyString_Check(objPtr) ? objPtr : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void construct(PyObject *objPtr, bpy::converter::rvalue_from_python_stage1_data *data) {
|
static void construct(PyObject *objPtr, bpy::converter::rvalue_from_python_stage1_data *data) {
|
||||||
// Extract the character data from the python string
|
// Extract the character data from the python string
|
||||||
const char* value = PyString_AsString(objPtr);
|
const char* value = PyString_AsString(objPtr);
|
||||||
assert(value != NULL);
|
assert(value != nullptr);
|
||||||
|
|
||||||
// allocate storage
|
// allocate storage
|
||||||
void *storage = ((bpy::converter::rvalue_from_python_storage<QString>*)data)->storage.bytes;
|
void *storage = ((bpy::converter::rvalue_from_python_storage<QString>*)data)->storage.bytes;
|
||||||
@@ -146,7 +144,7 @@ struct GuessedValue_converters
|
|||||||
if PyList_Check(objPtr) {
|
if PyList_Check(objPtr) {
|
||||||
return objPtr;
|
return objPtr;
|
||||||
} else {
|
} else {
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -217,7 +215,7 @@ struct QVariant_from_python_obj
|
|||||||
static void *convertible(PyObject *objPtr) {
|
static void *convertible(PyObject *objPtr) {
|
||||||
if (!PyString_Check(objPtr) && !PyInt_Check(objPtr) &&
|
if (!PyString_Check(objPtr) && !PyInt_Check(objPtr) &&
|
||||||
!PyBool_Check(objPtr) && !PyList_Check(objPtr)) {
|
!PyBool_Check(objPtr) && !PyList_Check(objPtr)) {
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
return objPtr;
|
return objPtr;
|
||||||
}
|
}
|
||||||
@@ -310,7 +308,7 @@ struct QList_from_python_obj
|
|||||||
|
|
||||||
static void* convertible(PyObject *objPtr) {
|
static void* convertible(PyObject *objPtr) {
|
||||||
if (PyList_Check(objPtr)) return objPtr;
|
if (PyList_Check(objPtr)) return objPtr;
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void construct(PyObject *objPtr, bpy::converter::rvalue_from_python_stage1_data *data) {
|
static void construct(PyObject *objPtr, bpy::converter::rvalue_from_python_stage1_data *data) {
|
||||||
@@ -339,7 +337,7 @@ struct stdset_from_python_list
|
|||||||
|
|
||||||
static void* convertible(PyObject *objPtr) {
|
static void* convertible(PyObject *objPtr) {
|
||||||
if (PyList_Check(objPtr)) return objPtr;
|
if (PyList_Check(objPtr)) return objPtr;
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void construct(PyObject *objPtr, bpy::converter::rvalue_from_python_stage1_data *data) {
|
static void construct(PyObject *objPtr, bpy::converter::rvalue_from_python_stage1_data *data) {
|
||||||
@@ -359,8 +357,8 @@ struct stdset_from_python_list
|
|||||||
|
|
||||||
static const sipAPIDef *sipAPI()
|
static const sipAPIDef *sipAPI()
|
||||||
{
|
{
|
||||||
static const sipAPIDef *sipApi = NULL;
|
static const sipAPIDef *sipApi = nullptr;
|
||||||
if (sipApi == NULL) {
|
if (sipApi == nullptr) {
|
||||||
sipApi = (const sipAPIDef *)PyCapsule_Import("sip._C_API", 0);
|
sipApi = (const sipAPIDef *)PyCapsule_Import("sip._C_API", 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -393,19 +391,19 @@ template <> struct MetaData<QVariant> { static const char *className() { return
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
PyObject *toPyQt(T *objPtr)
|
PyObject *toPyQt(T *objPtr)
|
||||||
{
|
{
|
||||||
if (objPtr == NULL) {
|
if (objPtr == nullptr) {
|
||||||
qDebug("no input object");
|
qDebug("no input object");
|
||||||
return bpy::incref(Py_None);
|
return bpy::incref(Py_None);
|
||||||
}
|
}
|
||||||
const sipTypeDef *type = sipAPI()->api_find_type(MetaData<T>::className());
|
const sipTypeDef *type = sipAPI()->api_find_type(MetaData<T>::className());
|
||||||
|
|
||||||
if (type == NULL) {
|
if (type == nullptr) {
|
||||||
qDebug("failed to determine type: %s", MetaData<T>::className());
|
qDebug("failed to determine type: %s", MetaData<T>::className());
|
||||||
return bpy::incref(Py_None);
|
return bpy::incref(Py_None);
|
||||||
}
|
}
|
||||||
|
|
||||||
PyObject *sipObj = sipAPI()->api_convert_from_type(objPtr, type, 0);
|
PyObject *sipObj = sipAPI()->api_convert_from_type(objPtr, type, 0);
|
||||||
if (sipObj == NULL) {
|
if (sipObj == nullptr) {
|
||||||
qDebug("failed to convert");
|
qDebug("failed to convert");
|
||||||
return bpy::incref(Py_None);
|
return bpy::incref(Py_None);
|
||||||
}
|
}
|
||||||
@@ -420,12 +418,12 @@ struct QClass_converters
|
|||||||
{
|
{
|
||||||
static PyObject *convert(const T &object) {
|
static PyObject *convert(const T &object) {
|
||||||
const sipTypeDef *type = sipAPI()->api_find_type(MetaData<T>::className());
|
const sipTypeDef *type = sipAPI()->api_find_type(MetaData<T>::className());
|
||||||
if (type == NULL) {
|
if (type == nullptr) {
|
||||||
return bpy::incref(Py_None);
|
return bpy::incref(Py_None);
|
||||||
}
|
}
|
||||||
|
|
||||||
PyObject *sipObj = sipAPI()->api_convert_from_type((void*)(&object), type, 0);
|
PyObject *sipObj = sipAPI()->api_convert_from_type((void*)(&object), type, 0);
|
||||||
if (sipObj == NULL) {
|
if (sipObj == nullptr) {
|
||||||
return bpy::incref(Py_None);
|
return bpy::incref(Py_None);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -433,17 +431,17 @@ struct QClass_converters
|
|||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *convert(T *object) {
|
static PyObject *convert(T *object) {
|
||||||
if (object == NULL) {
|
if (object == nullptr) {
|
||||||
return bpy::incref(Py_None);
|
return bpy::incref(Py_None);
|
||||||
}
|
}
|
||||||
|
|
||||||
const sipTypeDef *type = sipAPI()->api_find_type(MetaData<T>::className());
|
const sipTypeDef *type = sipAPI()->api_find_type(MetaData<T>::className());
|
||||||
if (type == NULL) {
|
if (type == nullptr) {
|
||||||
return bpy::incref(Py_None);
|
return bpy::incref(Py_None);
|
||||||
}
|
}
|
||||||
|
|
||||||
PyObject *sipObj = sipAPI()->api_convert_from_type(object, type, 0);
|
PyObject *sipObj = sipAPI()->api_convert_from_type(object, type, 0);
|
||||||
if (sipObj == NULL) {
|
if (sipObj == nullptr) {
|
||||||
return bpy::incref(Py_None);
|
return bpy::incref(Py_None);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -484,12 +482,12 @@ struct QInterface_converters
|
|||||||
{
|
{
|
||||||
static PyObject *convert(const T &object) {
|
static PyObject *convert(const T &object) {
|
||||||
const sipTypeDef *type = sipAPI()->api_find_type(MetaData<T>::className());
|
const sipTypeDef *type = sipAPI()->api_find_type(MetaData<T>::className());
|
||||||
if (type == NULL) {
|
if (type == nullptr) {
|
||||||
return bpy::incref(Py_None);
|
return bpy::incref(Py_None);
|
||||||
}
|
}
|
||||||
|
|
||||||
PyObject *sipObj = sipAPI()->api_convert_from_type((void*)(&object), type, 0);
|
PyObject *sipObj = sipAPI()->api_convert_from_type((void*)(&object), type, 0);
|
||||||
if (sipObj == NULL) {
|
if (sipObj == nullptr) {
|
||||||
return bpy::incref(Py_None);
|
return bpy::incref(Py_None);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -497,17 +495,17 @@ struct QInterface_converters
|
|||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *convert(T *object) {
|
static PyObject *convert(T *object) {
|
||||||
if (object == NULL) {
|
if (object == nullptr) {
|
||||||
return bpy::incref(Py_None);
|
return bpy::incref(Py_None);
|
||||||
}
|
}
|
||||||
|
|
||||||
const sipTypeDef *type = sipAPI()->api_find_type(MetaData<T>::className());
|
const sipTypeDef *type = sipAPI()->api_find_type(MetaData<T>::className());
|
||||||
if (type == NULL) {
|
if (type == nullptr) {
|
||||||
return bpy::incref(Py_None);
|
return bpy::incref(Py_None);
|
||||||
}
|
}
|
||||||
|
|
||||||
PyObject *sipObj = sipAPI()->api_convert_from_type(object, type, 0);
|
PyObject *sipObj = sipAPI()->api_convert_from_type(object, type, 0);
|
||||||
if (sipObj == NULL) {
|
if (sipObj == nullptr) {
|
||||||
return bpy::incref(Py_None);
|
return bpy::incref(Py_None);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -579,7 +577,7 @@ struct Functor0_converter
|
|||||||
{
|
{
|
||||||
if (!PyCallable_Check(object)
|
if (!PyCallable_Check(object)
|
||||||
|| (getArgCount(object) != 0)) {
|
|| (getArgCount(object) != 0)) {
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
@@ -620,7 +618,7 @@ struct Functor2_converter
|
|||||||
{
|
{
|
||||||
if (!PyCallable_Check(object)
|
if (!PyCallable_Check(object)
|
||||||
|| (getArgCount(object) != 2)) {
|
|| (getArgCount(object) != 2)) {
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
@@ -727,6 +725,7 @@ BOOST_PYTHON_MODULE(mobase)
|
|||||||
.def("startApplication", bpy::pure_virtual(&IOrganizer::startApplication), bpy::return_value_policy<bpy::return_by_value>())
|
.def("startApplication", bpy::pure_virtual(&IOrganizer::startApplication), bpy::return_value_policy<bpy::return_by_value>())
|
||||||
.def("waitForApplication", bpy::pure_virtual(&IOrganizer::waitForApplication), bpy::return_value_policy<bpy::return_by_value>())
|
.def("waitForApplication", bpy::pure_virtual(&IOrganizer::waitForApplication), bpy::return_value_policy<bpy::return_by_value>())
|
||||||
.def("onAboutToRun", bpy::pure_virtual(&IOrganizer::onAboutToRun))
|
.def("onAboutToRun", bpy::pure_virtual(&IOrganizer::onAboutToRun))
|
||||||
|
.def("onFinishedRun", bpy::pure_virtual(&IOrganizer::onFinishedRun))
|
||||||
.def("onModInstalled", bpy::pure_virtual(&IOrganizer::onModInstalled))
|
.def("onModInstalled", bpy::pure_virtual(&IOrganizer::onModInstalled))
|
||||||
.def("refreshModList", bpy::pure_virtual(&IOrganizer::refreshModList))
|
.def("refreshModList", bpy::pure_virtual(&IOrganizer::refreshModList))
|
||||||
;
|
;
|
||||||
@@ -840,7 +839,7 @@ PythonRunner::PythonRunner(const MOBase::IOrganizer *moInfo)
|
|||||||
m_PythonHome = new char[MAX_PATH + 1];
|
m_PythonHome = new char[MAX_PATH + 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
static char* argv0 = "ModOrganizer.exe";
|
static const char *argv0 = "ModOrganizer.exe";
|
||||||
|
|
||||||
|
|
||||||
bool PythonRunner::initPython(const QString &pythonPath)
|
bool PythonRunner::initPython(const QString &pythonPath)
|
||||||
@@ -854,7 +853,10 @@ bool PythonRunner::initPython(const QString &pythonPath)
|
|||||||
Py_SetPythonHome(m_PythonHome);
|
Py_SetPythonHome(m_PythonHome);
|
||||||
}
|
}
|
||||||
|
|
||||||
Py_SetProgramName(argv0);
|
char argBuffer[MAX_PATH];
|
||||||
|
strcpy(argBuffer, argv0);
|
||||||
|
|
||||||
|
Py_SetProgramName(argBuffer);
|
||||||
PyImport_AppendInittab("mobase", &initmobase);
|
PyImport_AppendInittab("mobase", &initmobase);
|
||||||
Py_OptimizeFlag = 2;
|
Py_OptimizeFlag = 2;
|
||||||
Py_NoSiteFlag = 1;
|
Py_NoSiteFlag = 1;
|
||||||
@@ -864,7 +866,7 @@ bool PythonRunner::initPython(const QString &pythonPath)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
PySys_SetArgv(0, &argv0);
|
PySys_SetArgv(0, (char**)&argBuffer);
|
||||||
|
|
||||||
bpy::object mainModule = bpy::import("__main__");
|
bpy::object mainModule = bpy::import("__main__");
|
||||||
bpy::object mainNamespace = mainModule.attr("__dict__");
|
bpy::object mainNamespace = mainModule.attr("__dict__");
|
||||||
@@ -936,7 +938,7 @@ QObject *PythonRunner::instantiate(const QString &pluginName)
|
|||||||
std::string temp = ToString(pluginName);
|
std::string temp = ToString(pluginName);
|
||||||
if (handled_exec_file(temp.c_str(), moduleNamespace)) {
|
if (handled_exec_file(temp.c_str(), moduleNamespace)) {
|
||||||
reportPythonError();
|
reportPythonError();
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
m_PythonObjects[pluginName] = moduleNamespace["createPlugin"]();
|
m_PythonObjects[pluginName] = moduleNamespace["createPlugin"]();
|
||||||
|
|
||||||
@@ -947,7 +949,7 @@ QObject *PythonRunner::instantiate(const QString &pluginName)
|
|||||||
qWarning("failed to run python script \"%s\"", qPrintable(pluginName));
|
qWarning("failed to run python script \"%s\"", qPrintable(pluginName));
|
||||||
reportPythonError();
|
reportPythonError();
|
||||||
}
|
}
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PythonRunner::isPythonInstalled() const
|
bool PythonRunner::isPythonInstalled() const
|
||||||
|
|||||||
@@ -221,12 +221,13 @@ struct IOrganizerWrapper: MOBase::IOrganizer, boost::python::wrapper<MOBase::IOr
|
|||||||
virtual QString resolvePath(const QString &fileName) const { return this->get_override("resolvePath")(fileName); }
|
virtual QString resolvePath(const QString &fileName) const { return this->get_override("resolvePath")(fileName); }
|
||||||
virtual QStringList listDirectories(const QString &directoryName) const { return this->get_override("listDirectories")(directoryName); }
|
virtual QStringList listDirectories(const QString &directoryName) const { return this->get_override("listDirectories")(directoryName); }
|
||||||
virtual QStringList findFiles(const QString &path, const std::function<bool(const QString&)> &filter) const { return this->get_override("findFiles")(path, filter); }
|
virtual QStringList findFiles(const QString &path, const std::function<bool(const QString&)> &filter) const { return this->get_override("findFiles")(path, filter); }
|
||||||
virtual QStringList getFileOrigins(const QString &fileName) const { return this->get_override("getFileOrigin")(fileName); }
|
virtual QStringList getFileOrigins(const QString &fileName) const { return this->get_override("getFileOrigins")(fileName); }
|
||||||
virtual QList<FileInfo> findFileInfos(const QString &path, const std::function<bool(const FileInfo&)> &filter) const { return this->get_override("findFileInfos")(path, filter); }
|
virtual QList<FileInfo> findFileInfos(const QString &path, const std::function<bool(const FileInfo&)> &filter) const { return this->get_override("findFileInfos")(path, filter); }
|
||||||
virtual HANDLE startApplication(const QString &executable, const QStringList &args = QStringList(), const QString &cwd = "", const QString &profile = "") { return this->get_override("startApplication")(executable, args, cwd, profile); }
|
virtual HANDLE startApplication(const QString &executable, const QStringList &args = QStringList(), const QString &cwd = "", const QString &profile = "") { return this->get_override("startApplication")(executable, args, cwd, profile); }
|
||||||
virtual bool waitForApplication(HANDLE handle, LPDWORD exitCode = NULL) const { return this->get_override("waitForApplication")(handle, exitCode); }
|
virtual bool waitForApplication(HANDLE handle, LPDWORD exitCode = nullptr) const { return this->get_override("waitForApplication")(handle, exitCode); }
|
||||||
virtual void refreshModList(bool saveChanges = true) { this->get_override("refreshModList")(saveChanges); }
|
virtual void refreshModList(bool saveChanges = true) { this->get_override("refreshModList")(saveChanges); }
|
||||||
virtual bool onAboutToRun(const std::function<bool(const QString&)> &func) { return this->get_override("onAboutToRun")(func); }
|
virtual bool onAboutToRun(const std::function<bool(const QString&)> &func) { return this->get_override("onAboutToRun")(func); }
|
||||||
|
virtual bool onFinishedRun(const std::function<void(const QString&, unsigned int)> &func) { return this->get_override("onFinishedRun")(func); }
|
||||||
virtual bool onModInstalled(const std::function<void(const QString&)> &func) { return this->get_override("onModInstalled")(func); }
|
virtual bool onModInstalled(const std::function<void(const QString&)> &func) { return this->get_override("onModInstalled")(func); }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user