mirror of
https://github.com/ModOrganizer2/modorganizer-plugin_python.git
synced 2026-07-27 14:03:33 -07:00
Compare commits
35
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f29d9ac993 | ||
|
|
d8f49b3906 | ||
|
|
25d9ad16c2 | ||
|
|
a5901d7975 | ||
|
|
a7b81418a5 | ||
|
|
560e1ce0c7 | ||
|
|
6edbec745d | ||
|
|
d6edcf4fa0 | ||
|
|
50a725a1b4 | ||
|
|
a1fdb54471 | ||
|
|
e602014dda | ||
|
|
90df417a8c | ||
|
|
cb9a7fcd2d | ||
|
|
9d2264aff8 | ||
|
|
0aeeb9365f | ||
|
|
3967d64437 | ||
|
|
a7e881869e | ||
|
|
3f66d206e8 | ||
|
|
9d48b75388 | ||
|
|
841b923751 | ||
|
|
23fd430605 | ||
|
|
1a89e42c0f | ||
|
|
42afc90c8d | ||
|
|
c7203bf9de | ||
|
|
a7d626c83c | ||
|
|
bbea63e7af | ||
|
|
9f607a5fcb | ||
|
|
868ab93a1f | ||
|
|
dec620b5b7 | ||
|
|
5da6a9d3bd | ||
|
|
573be8c6b5 | ||
|
|
2c661da2da | ||
|
|
fa09fd7635 | ||
|
|
84fe2b0307 | ||
|
|
e7e686c361 |
@@ -0,0 +1,32 @@
|
||||
import os
|
||||
|
||||
Import('qt_env')
|
||||
|
||||
env = qt_env.Clone()
|
||||
|
||||
env.AppendUnique(CPPDEFINES = [
|
||||
'PROXYPYTHON_LIBRARY',
|
||||
# suppress a few warnings caused by boost vs vc++ paranoia
|
||||
'_SCL_SECURE_NO_WARNINGS'
|
||||
])
|
||||
|
||||
env.AppendUnique(CPPPATH = [
|
||||
'${BOOSTPATH}',
|
||||
'..\\..\\pythonRunner'
|
||||
])
|
||||
|
||||
env.AppendUnique(LIBS = 'shell32')
|
||||
|
||||
runner = env.File(os.path.join('..', '..', 'pythonRunner', 'pythonRunner.dll'))
|
||||
|
||||
runner_env = env.Clone()
|
||||
runner_env.AppendUnique(CPPDEFINES = 'SCONS_BUILD')
|
||||
runner_env.AppendUnique(CPPPATH = runner.dir)
|
||||
|
||||
# There's a whole load of unused C++ files in here.
|
||||
lib = env.SharedLibrary('proxyPython', [ 'proxypython.cpp' ])
|
||||
|
||||
env.InstallModule(lib)
|
||||
|
||||
res = env['QT_USED_MODULES']
|
||||
Return('res')
|
||||
@@ -1,7 +1,11 @@
|
||||
#include "resource.h"
|
||||
|
||||
#ifdef SCONS_BUILD
|
||||
IDR_LOADER_DLL BINARY MOVEABLE PURE pythonRunner.dll
|
||||
#else
|
||||
#ifdef _DEBUG
|
||||
IDR_LOADER_DLL BINARY MOVEABLE PURE "..\\..\\pythonRunner\\debug\\pythonRunner.dll"
|
||||
#else // _DEBUG
|
||||
IDR_LOADER_DLL BINARY MOVEABLE PURE "..\\..\\pythonRunner\\release\\pythonRunner.dll"
|
||||
#endif // _DEBUG
|
||||
#endif
|
||||
|
||||
@@ -29,10 +29,9 @@ HEADERS += proxypython.h \
|
||||
|
||||
OTHER_FILES += \
|
||||
proxypython.json \
|
||||
embedrunner.rc
|
||||
SConscript
|
||||
|
||||
RC_FILE += \
|
||||
embedrunner.rc
|
||||
RC_FILE +=
|
||||
|
||||
include(../plugin_template.pri)
|
||||
|
||||
|
||||
+36
-16
@@ -37,7 +37,7 @@ const char *ProxyPython::s_DownloadPythonURL = "http://www.python.org/download/r
|
||||
|
||||
HMODULE GetOwnModuleHandle()
|
||||
{
|
||||
HMODULE hMod = NULL;
|
||||
HMODULE hMod = nullptr;
|
||||
GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
|
||||
reinterpret_cast<LPCWSTR>(&GetOwnModuleHandle), &hMod);
|
||||
|
||||
@@ -50,29 +50,48 @@ QString ExtractResource(WORD resourceID, const QString &szFilename)
|
||||
HMODULE mod = GetOwnModuleHandle();
|
||||
|
||||
HRSRC hResource = FindResourceW(mod, MAKEINTRESOURCE(resourceID), L"BINARY");
|
||||
if (hResource == NULL) {
|
||||
if (hResource == nullptr) {
|
||||
throw MyException("embedded dll not available: " + windowsErrorString(::GetLastError()));
|
||||
}
|
||||
|
||||
HGLOBAL hFileResource = LoadResource(mod, hResource);
|
||||
if (hFileResource == NULL) {
|
||||
if (hFileResource == nullptr) {
|
||||
throw MyException("failed to load embedded dll resource: " + windowsErrorString(::GetLastError()));
|
||||
}
|
||||
|
||||
LPVOID lpFile = LockResource(hFileResource);
|
||||
if (lpFile == nullptr) {
|
||||
throw MyException(QString("failed to lock resource: %1").arg(windowsErrorString(::GetLastError())));
|
||||
}
|
||||
|
||||
DWORD dwSize = SizeofResource(mod, hResource);
|
||||
|
||||
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 hFileMap = CreateFileMapping(hFile, NULL, PAGE_READWRITE, 0, dwSize, NULL);
|
||||
HANDLE hFile = CreateFileW(outFile.toStdWString().c_str(), GENERIC_READ | GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
|
||||
if (hFile == INVALID_HANDLE_VALUE) {
|
||||
if (::GetLastError() == ERROR_SHARING_VIOLATION) {
|
||||
// dll exists and is opened by another instance of MO, shouldn't be outdated then...
|
||||
return outFile;
|
||||
} else {
|
||||
throw MyException(QString("failed to open python runner: %1").arg(windowsErrorString(::GetLastError())));
|
||||
}
|
||||
}
|
||||
HANDLE hFileMap = CreateFileMapping(hFile, nullptr, PAGE_READWRITE, 0, dwSize, nullptr);
|
||||
if (hFileMap == NULL) {
|
||||
throw MyException(QString("failed to map python runner: %1").arg(windowsErrorString(::GetLastError())));
|
||||
}
|
||||
LPVOID lpAddress = MapViewOfFile(hFileMap, FILE_MAP_WRITE, 0, 0, 0);
|
||||
if (lpAddress == nullptr) {
|
||||
throw MyException(QString("failed to map view of file: %1").arg(windowsErrorString(::GetLastError())));
|
||||
}
|
||||
|
||||
CopyMemory(lpAddress, lpFile, dwSize);
|
||||
|
||||
UnmapViewOfFile(lpAddress);
|
||||
|
||||
CloseHandle(hFileMap);
|
||||
::FlushFileBuffers(hFile);
|
||||
CloseHandle(hFile);
|
||||
|
||||
return outFile;
|
||||
@@ -80,7 +99,7 @@ QString ExtractResource(WORD resourceID, const QString &szFilename)
|
||||
|
||||
|
||||
ProxyPython::ProxyPython()
|
||||
: m_MOInfo(NULL), m_Runner(NULL), m_LoadFailure(FAIL_NOTINIT)
|
||||
: m_MOInfo(nullptr), m_Runner(nullptr), m_LoadFailure(FAIL_NOTINIT)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -116,11 +135,12 @@ bool ProxyPython::init(IOrganizer *moInfo)
|
||||
return true;
|
||||
}
|
||||
|
||||
m_TempRunnerFile = ExtractResource(IDR_LOADER_DLL, "__pythonRunner.dll");
|
||||
m_RunnerLib = ::LoadLibraryW(ToWString(m_TempRunnerFile).c_str());
|
||||
if (m_RunnerLib != NULL) {
|
||||
//m_TempRunnerFile = ExtractResource(IDR_LOADER_DLL, "__pythonRunner.dll");
|
||||
//m_RunnerLib = ::LoadLibraryW(ToWString(m_TempRunnerFile).c_str());
|
||||
m_RunnerLib = ::LoadLibraryW(QDir::toNativeSeparators(m_MOInfo->pluginDataPath() + "/pythonRunner.dll").toStdWString().c_str());
|
||||
if (m_RunnerLib != nullptr) {
|
||||
CreatePythonRunner_func CreatePythonRunner = (CreatePythonRunner_func)::GetProcAddress(m_RunnerLib, "CreatePythonRunner");
|
||||
if (CreatePythonRunner == NULL) {
|
||||
if (CreatePythonRunner == nullptr) {
|
||||
throw MyException("embedded dll is invalid: " + windowsErrorString(::GetLastError()));
|
||||
}
|
||||
if (m_MOInfo->persistent(name(), "tryInit", false).toBool()) {
|
||||
@@ -145,7 +165,7 @@ bool ProxyPython::init(IOrganizer *moInfo)
|
||||
m_Runner = CreatePythonRunner(moInfo, pythonPath);
|
||||
m_MOInfo->setPersistent(name(), "tryInit", false);
|
||||
|
||||
if (m_Runner != NULL) {
|
||||
if (m_Runner != nullptr) {
|
||||
m_LoadFailure = FAIL_NONE;
|
||||
} else {
|
||||
m_LoadFailure = FAIL_INITFAIL;
|
||||
@@ -153,7 +173,7 @@ bool ProxyPython::init(IOrganizer *moInfo)
|
||||
return true;
|
||||
} else {
|
||||
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) {
|
||||
m_LoadFailure = FAIL_MISSINGDEPENDENCIES;
|
||||
}
|
||||
@@ -209,11 +229,11 @@ QStringList ProxyPython::pluginList(const QString &pluginPath) const
|
||||
|
||||
QObject *ProxyPython::instantiate(const QString &pluginName)
|
||||
{
|
||||
if (m_Runner != NULL) {
|
||||
if (m_Runner != nullptr) {
|
||||
QObject *result = m_Runner->instantiate(pluginName);
|
||||
return result;
|
||||
} else {
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -231,7 +251,7 @@ std::vector<unsigned int> ProxyPython::activeProblems() const
|
||||
result.push_back(PROBLEM_INITFAIL);
|
||||
} else if (m_LoadFailure == FAIL_SEMICOLON) {
|
||||
result.push_back(PROBLEM_SEMICOLON);
|
||||
} else if (m_Runner != NULL) {
|
||||
} else if (m_Runner != nullptr) {
|
||||
if (!m_Runner->isPythonInstalled()) {
|
||||
// don't know how this could happen but wth
|
||||
result.push_back(PROBLEM_PYTHONMISSING);
|
||||
@@ -317,7 +337,7 @@ bool ProxyPython::hasGuidedFix(unsigned int key) const
|
||||
void ProxyPython::startGuidedFix(unsigned int key) const
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
Import('qt_env')
|
||||
|
||||
env = qt_env.Clone()
|
||||
|
||||
env.EnableQtModules('Core', 'Gui')
|
||||
|
||||
env.AppendUnique(CPPDEFINES = 'PYTHONRUNNER_LIBRARY')
|
||||
|
||||
# suppress a few warnings caused by boost vs vc++ paranoia
|
||||
# NB HAVE_ROUND causes a warning because it's defined in pythonrunner.cpp
|
||||
env.AppendUnique(CPPDEFINES = [
|
||||
'_SCL_SECURE_NO_WARNINGS',
|
||||
'HAVE_ROUND'
|
||||
])
|
||||
|
||||
# QMAKE_CXXFLAGS += /Zi
|
||||
# QMAKE_LFLAGS += /DEBUG
|
||||
|
||||
env.RequireLibraries('uibase')
|
||||
|
||||
# AppendUnique appears not to work with QT4
|
||||
env['CPPPATH'] += [
|
||||
'${BOOSTPATH}',
|
||||
'${PYTHONPATH}\\include',
|
||||
]
|
||||
|
||||
env.AppendUnique(LIBS = [
|
||||
'python27', # Could be done better
|
||||
])
|
||||
|
||||
env.AppendUnique(LIBPATH = [
|
||||
'${PYTHONPATH}/libs', # Could be done better
|
||||
])
|
||||
|
||||
# We have to 'persuade' moc to generate certain other targets and inject them
|
||||
# into the list of cpps
|
||||
targets = env.AddExtraMoc(env.Glob('*.h'))
|
||||
|
||||
# pythontoolwrapper doesnt compile and isn't in the project file
|
||||
cpp_files = [
|
||||
x for x in Glob('*.cpp') if x.name != 'pythontoolwrapper.cpp'
|
||||
]
|
||||
|
||||
lib = env.SharedLibrary('pythonRunner', cpp_files + targets)
|
||||
|
||||
env.InstallModule(lib, 'plugins/data')
|
||||
|
||||
# However...
|
||||
# we do need boost-python and pythonvv.dll and pythonvv.zip (though the last
|
||||
# isn't needed to just bring up the module)
|
||||
#env.Pseudo('install')
|
||||
#env.Depends('install',
|
||||
# (env.Install('${INSTALL_PATH}', 'pyCfg.py'),
|
||||
# env.Install(os.path.join('${INSTALL_PATH}', 'data'),
|
||||
# ( ui, rc, 'settings.json' )),
|
||||
# ))
|
||||
|
||||
res = env['QT_USED_MODULES']
|
||||
Return('res')
|
||||
@@ -1,4 +1,3 @@
|
||||
//#define HAVE_ROUND
|
||||
#include "proxypluginwrappers.h"
|
||||
#include <utility.h>
|
||||
#include "error.h"
|
||||
|
||||
@@ -13,14 +13,13 @@ CONFIG += warn_on
|
||||
DEFINES += PYTHONRUNNER_LIBRARY
|
||||
|
||||
# suppress a few warnings caused by boost vs vc++ paranoia
|
||||
DEFINES += _SCL_SECURE_NO_WARNINGS -DHAVE_ROUND
|
||||
DEFINES += _SCL_SECURE_NO_WARNINGS HAVE_ROUND NOMINMAX
|
||||
|
||||
|
||||
!include(../LocalPaths.pri) {
|
||||
message("paths to required libraries need to be set up in LocalPaths.pri")
|
||||
}
|
||||
|
||||
|
||||
SOURCES += pythonrunner.cpp \
|
||||
gilock.cpp \
|
||||
error.cpp \
|
||||
@@ -38,8 +37,8 @@ CONFIG(debug, debug|release) {
|
||||
LIBS += -L$$OUT_PWD/../uibase/debug
|
||||
} else {
|
||||
LIBS += -L$$OUT_PWD/../uibase/release
|
||||
QMAKE_CXXFLAGS += /Zi
|
||||
QMAKE_LFLAGS += /DEBUG
|
||||
msvc:QMAKE_CXXFLAGS += /Zi
|
||||
msvc:QMAKE_LFLAGS += /DEBUG
|
||||
}
|
||||
|
||||
INCLUDEPATH += "$${BOOSTPATH}" "$${PYTHONPATH}/include" "$${PYTHONPATH}/Lib/site-packages/PyQt5/include" ../uibase
|
||||
@@ -58,4 +57,8 @@ CONFIG(debug, debug|release) {
|
||||
SRCDIR ~= s,/,$$QMAKE_DIR_SEP,g
|
||||
DSTDIR ~= s,/,$$QMAKE_DIR_SEP,g
|
||||
|
||||
QMAKE_POST_LINK += xcopy /y /s /i $$quote($$SRCDIR\\$${TARGET}*.dll) $$quote($$DSTDIR)\\plugins\\data $$escape_expand(\\n)
|
||||
QMAKE_POST_LINK += xcopy /y /I $$quote($$SRCDIR\\$${TARGET}*.pdb) $$quote($$DSTDIR)\\plugins $$escape_expand(\\n)
|
||||
|
||||
OTHER_FILES += \
|
||||
SConscript
|
||||
|
||||
+42
-33
@@ -1,5 +1,3 @@
|
||||
#define HAVE_ROUND
|
||||
|
||||
#include "pythonrunner.h"
|
||||
|
||||
#pragma warning( disable : 4100 )
|
||||
@@ -22,7 +20,7 @@
|
||||
#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;
|
||||
} else {
|
||||
delete result;
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,13 +101,13 @@ struct QString_from_python_str
|
||||
}
|
||||
|
||||
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) {
|
||||
// Extract the character data from the python string
|
||||
const char* value = PyString_AsString(objPtr);
|
||||
assert(value != NULL);
|
||||
assert(value != nullptr);
|
||||
|
||||
// allocate storage
|
||||
void *storage = ((bpy::converter::rvalue_from_python_storage<QString>*)data)->storage.bytes;
|
||||
@@ -146,7 +144,7 @@ struct GuessedValue_converters
|
||||
if PyList_Check(objPtr) {
|
||||
return objPtr;
|
||||
} else {
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -217,7 +215,7 @@ struct QVariant_from_python_obj
|
||||
static void *convertible(PyObject *objPtr) {
|
||||
if (!PyString_Check(objPtr) && !PyInt_Check(objPtr) &&
|
||||
!PyBool_Check(objPtr) && !PyList_Check(objPtr)) {
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
return objPtr;
|
||||
}
|
||||
@@ -310,7 +308,7 @@ struct QList_from_python_obj
|
||||
|
||||
static void* convertible(PyObject *objPtr) {
|
||||
if (PyList_Check(objPtr)) return objPtr;
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
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) {
|
||||
if (PyList_Check(objPtr)) return objPtr;
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
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 = NULL;
|
||||
if (sipApi == NULL) {
|
||||
static const sipAPIDef *sipApi = nullptr;
|
||||
if (sipApi == nullptr) {
|
||||
sipApi = (const sipAPIDef *)PyCapsule_Import("sip._C_API", 0);
|
||||
}
|
||||
|
||||
@@ -387,25 +385,26 @@ template <> struct MetaData<IDownloadManager> { static const char *className() {
|
||||
template <> struct MetaData<QObject> { static const char *className() { return "QObject"; } };
|
||||
template <> struct MetaData<QWidget> { static const char *className() { return "QWidget"; } };
|
||||
template <> struct MetaData<QIcon> { static const char *className() { return "QIcon"; } };
|
||||
template <> struct MetaData<QStringList> { static const char *className() { return "QStringList"; } };
|
||||
template <> struct MetaData<QVariant> { static const char *className() { return "QVariant"; } };
|
||||
|
||||
|
||||
template <typename T>
|
||||
PyObject *toPyQt(T *objPtr)
|
||||
{
|
||||
if (objPtr == NULL) {
|
||||
if (objPtr == nullptr) {
|
||||
qDebug("no input object");
|
||||
return bpy::incref(Py_None);
|
||||
}
|
||||
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());
|
||||
return bpy::incref(Py_None);
|
||||
}
|
||||
|
||||
PyObject *sipObj = sipAPI()->api_convert_from_type(objPtr, type, 0);
|
||||
if (sipObj == NULL) {
|
||||
if (sipObj == nullptr) {
|
||||
qDebug("failed to convert");
|
||||
return bpy::incref(Py_None);
|
||||
}
|
||||
@@ -420,12 +419,12 @@ struct QClass_converters
|
||||
{
|
||||
static PyObject *convert(const T &object) {
|
||||
const sipTypeDef *type = sipAPI()->api_find_type(MetaData<T>::className());
|
||||
if (type == NULL) {
|
||||
if (type == nullptr) {
|
||||
return bpy::incref(Py_None);
|
||||
}
|
||||
|
||||
PyObject *sipObj = sipAPI()->api_convert_from_type((void*)(&object), type, 0);
|
||||
if (sipObj == NULL) {
|
||||
if (sipObj == nullptr) {
|
||||
return bpy::incref(Py_None);
|
||||
}
|
||||
|
||||
@@ -433,17 +432,17 @@ struct QClass_converters
|
||||
}
|
||||
|
||||
static PyObject *convert(T *object) {
|
||||
if (object == NULL) {
|
||||
if (object == nullptr) {
|
||||
return bpy::incref(Py_None);
|
||||
}
|
||||
|
||||
const sipTypeDef *type = sipAPI()->api_find_type(MetaData<T>::className());
|
||||
if (type == NULL) {
|
||||
if (type == nullptr) {
|
||||
return bpy::incref(Py_None);
|
||||
}
|
||||
|
||||
PyObject *sipObj = sipAPI()->api_convert_from_type(object, type, 0);
|
||||
if (sipObj == NULL) {
|
||||
if (sipObj == nullptr) {
|
||||
return bpy::incref(Py_None);
|
||||
}
|
||||
|
||||
@@ -484,12 +483,12 @@ struct QInterface_converters
|
||||
{
|
||||
static PyObject *convert(const T &object) {
|
||||
const sipTypeDef *type = sipAPI()->api_find_type(MetaData<T>::className());
|
||||
if (type == NULL) {
|
||||
if (type == nullptr) {
|
||||
return bpy::incref(Py_None);
|
||||
}
|
||||
|
||||
PyObject *sipObj = sipAPI()->api_convert_from_type((void*)(&object), type, 0);
|
||||
if (sipObj == NULL) {
|
||||
if (sipObj == nullptr) {
|
||||
return bpy::incref(Py_None);
|
||||
}
|
||||
|
||||
@@ -497,17 +496,17 @@ struct QInterface_converters
|
||||
}
|
||||
|
||||
static PyObject *convert(T *object) {
|
||||
if (object == NULL) {
|
||||
if (object == nullptr) {
|
||||
return bpy::incref(Py_None);
|
||||
}
|
||||
|
||||
const sipTypeDef *type = sipAPI()->api_find_type(MetaData<T>::className());
|
||||
if (type == NULL) {
|
||||
if (type == nullptr) {
|
||||
return bpy::incref(Py_None);
|
||||
}
|
||||
|
||||
PyObject *sipObj = sipAPI()->api_convert_from_type(object, type, 0);
|
||||
if (sipObj == NULL) {
|
||||
if (sipObj == nullptr) {
|
||||
return bpy::incref(Py_None);
|
||||
}
|
||||
|
||||
@@ -579,7 +578,7 @@ struct Functor0_converter
|
||||
{
|
||||
if (!PyCallable_Check(object)
|
||||
|| (getArgCount(object) != 0)) {
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
return object;
|
||||
}
|
||||
@@ -620,7 +619,7 @@ struct Functor2_converter
|
||||
{
|
||||
if (!PyCallable_Check(object)
|
||||
|| (getArgCount(object) != 2)) {
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
return object;
|
||||
}
|
||||
@@ -650,6 +649,7 @@ BOOST_PYTHON_MODULE(mobase)
|
||||
//QClass_converters<QObject>();
|
||||
QClass_converters<QWidget>();
|
||||
QClass_converters<QIcon>();
|
||||
QClass_converters<QStringList>();
|
||||
QInterface_converters<IDownloadManager>();
|
||||
|
||||
|
||||
@@ -720,13 +720,14 @@ BOOST_PYTHON_MODULE(mobase)
|
||||
.def("persistent", bpy::pure_virtual(&IOrganizer::persistent))
|
||||
.def("setPersistent", bpy::pure_virtual(&IOrganizer::setPersistent))
|
||||
.def("pluginDataPath", bpy::pure_virtual(&IOrganizer::pluginDataPath))
|
||||
.def("installMod", bpy::pure_virtual(&IOrganizer::installMod), bpy::return_value_policy<bpy::reference_existing_object>())
|
||||
.def("installMod", bpy::pure_virtual(&IOrganizer::installMod),(bpy::arg("nameSuggestion")=""), bpy::return_value_policy<bpy::reference_existing_object>())
|
||||
.def("downloadManager", bpy::pure_virtual(&IOrganizer::downloadManager), bpy::return_value_policy<bpy::reference_existing_object>())
|
||||
.def("pluginList", bpy::pure_virtual(&IOrganizer::pluginList), bpy::return_value_policy<bpy::reference_existing_object>())
|
||||
.def("modList", bpy::pure_virtual(&IOrganizer::modList), bpy::return_value_policy<bpy::reference_existing_object>())
|
||||
.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("onAboutToRun", bpy::pure_virtual(&IOrganizer::onAboutToRun))
|
||||
.def("onFinishedRun", bpy::pure_virtual(&IOrganizer::onFinishedRun))
|
||||
.def("onModInstalled", bpy::pure_virtual(&IOrganizer::onModInstalled))
|
||||
.def("refreshModList", bpy::pure_virtual(&IOrganizer::refreshModList))
|
||||
;
|
||||
@@ -772,6 +773,9 @@ BOOST_PYTHON_MODULE(mobase)
|
||||
.def("setIsEndorsed", bpy::pure_virtual(&IModInterface::setIsEndorsed))
|
||||
.def("setNexusID", bpy::pure_virtual(&IModInterface::setNexusID))
|
||||
.def("addNexusCategory", bpy::pure_virtual(&IModInterface::addNexusCategory))
|
||||
.def("addCategory", bpy::pure_virtual(&IModInterface::addCategory))
|
||||
.def("removeCategory", bpy::pure_virtual(&IModInterface::removeCategory))
|
||||
.def("categories", bpy::pure_virtual(&IModInterface::categories))
|
||||
.def("setName", bpy::pure_virtual(&IModInterface::setName))
|
||||
.def("remove", bpy::pure_virtual(&IModInterface::remove))
|
||||
;
|
||||
@@ -815,7 +819,9 @@ BOOST_PYTHON_MODULE(mobase)
|
||||
Functor2_converter<const QString&, IModList::ModStates>(); // converter for the onModStateChanged-callback
|
||||
bpy::class_<IModListWrapper, boost::noncopyable>("IModList")
|
||||
.def("displayName", bpy::pure_virtual(&MOBase::IModList::displayName))
|
||||
.def("allMods", bpy::pure_virtual(&MOBase::IModList::allMods))
|
||||
.def("state", bpy::pure_virtual(&MOBase::IModList::state))
|
||||
.def("setActive", bpy::pure_virtual(&MOBase::IModList::setActive))
|
||||
.def("priority", bpy::pure_virtual(&MOBase::IModList::priority))
|
||||
.def("setPriority", bpy::pure_virtual(&MOBase::IModList::setPriority))
|
||||
.def("onModStateChanged", bpy::pure_virtual(&MOBase::IModList::onModStateChanged))
|
||||
@@ -840,7 +846,7 @@ PythonRunner::PythonRunner(const MOBase::IOrganizer *moInfo)
|
||||
m_PythonHome = new char[MAX_PATH + 1];
|
||||
}
|
||||
|
||||
static char* argv0 = "ModOrganizer.exe";
|
||||
static const char *argv0 = "ModOrganizer.exe";
|
||||
|
||||
|
||||
bool PythonRunner::initPython(const QString &pythonPath)
|
||||
@@ -854,7 +860,10 @@ bool PythonRunner::initPython(const QString &pythonPath)
|
||||
Py_SetPythonHome(m_PythonHome);
|
||||
}
|
||||
|
||||
Py_SetProgramName(argv0);
|
||||
char argBuffer[MAX_PATH];
|
||||
strcpy(argBuffer, argv0);
|
||||
|
||||
Py_SetProgramName(argBuffer);
|
||||
PyImport_AppendInittab("mobase", &initmobase);
|
||||
Py_OptimizeFlag = 2;
|
||||
Py_NoSiteFlag = 1;
|
||||
@@ -864,7 +873,7 @@ bool PythonRunner::initPython(const QString &pythonPath)
|
||||
return false;
|
||||
}
|
||||
|
||||
PySys_SetArgv(0, &argv0);
|
||||
PySys_SetArgv(0, (char**)&argBuffer);
|
||||
|
||||
bpy::object mainModule = bpy::import("__main__");
|
||||
bpy::object mainNamespace = mainModule.attr("__dict__");
|
||||
@@ -936,7 +945,7 @@ QObject *PythonRunner::instantiate(const QString &pluginName)
|
||||
std::string temp = ToString(pluginName);
|
||||
if (handled_exec_file(temp.c_str(), moduleNamespace)) {
|
||||
reportPythonError();
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
m_PythonObjects[pluginName] = moduleNamespace["createPlugin"]();
|
||||
|
||||
@@ -947,7 +956,7 @@ QObject *PythonRunner::instantiate(const QString &pluginName)
|
||||
qWarning("failed to run python script \"%s\"", qPrintable(pluginName));
|
||||
reportPythonError();
|
||||
}
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool PythonRunner::isPythonInstalled() const
|
||||
|
||||
+30
-20
@@ -15,6 +15,9 @@
|
||||
#include <imodrepositorybridge.h>
|
||||
#include <imodinterface.h>
|
||||
#include <iinstallationmanager.h>
|
||||
#include <idownloadmanager.h>
|
||||
#include <ipluginlist.h>
|
||||
#include <imodlist.h>
|
||||
#include "error.h"
|
||||
#include "gilock.h"
|
||||
|
||||
@@ -214,19 +217,20 @@ struct IOrganizerWrapper: MOBase::IOrganizer, boost::python::wrapper<MOBase::IOr
|
||||
virtual QVariant persistent(const QString &pluginName, const QString &key, const QVariant &def = QVariant()) const { return this->get_override("persistent")(pluginName, key, def); }
|
||||
virtual void setPersistent(const QString &pluginName, const QString &key, const QVariant &value, bool sync = true) { this->get_override("setPersistent")(pluginName, key, value, sync); }
|
||||
virtual QString pluginDataPath() const { return this->get_override("pluginDataPath")(); }
|
||||
virtual MOBase::IModInterface *installMod(const QString &fileName) { return this->get_override("installMod")(fileName); }
|
||||
virtual MOBase::IModInterface *installMod(const QString &fileName, const QString &nameSuggestion = QString()) { return this->get_override("installMod")(fileName, nameSuggestion); }
|
||||
virtual MOBase::IDownloadManager *downloadManager() { return this->get_override("downloadManager")(); }
|
||||
virtual MOBase::IPluginList *pluginList() { return this->get_override("pluginList")(); }
|
||||
virtual MOBase::IModList *modList() { return this->get_override("modList")(); }
|
||||
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 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 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 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); }
|
||||
};
|
||||
|
||||
@@ -262,21 +266,24 @@ struct IGameInfoWrapper: MOBase::IGameInfo, boost::python::wrapper<MOBase::IGame
|
||||
|
||||
struct IModInterfaceWrapper: MOBase::IModInterface, boost::python::wrapper<MOBase::IModInterface>
|
||||
{
|
||||
virtual QString name() const { return this->get_override("name")(); }
|
||||
virtual QString absolutePath() const { return this->get_override("absolutePath")(); }
|
||||
virtual void setVersion(const MOBase::VersionInfo &version) { this->get_override("setVersion")(version); }
|
||||
virtual void setNewestVersion(const MOBase::VersionInfo &version) { this->get_override("setNewestVersion")(version); }
|
||||
virtual void setIsEndorsed(bool endorsed) { this->get_override("setIsEndorsed")(endorsed); }
|
||||
virtual void setNexusID(int nexusID) { this->get_override("setNexusID")(nexusID); }
|
||||
virtual void setInstallationFile(const QString &fileName) { this->get_override("setInstallationFile")(fileName); }
|
||||
virtual void addNexusCategory(int categoryID) { this->get_override("addNexusCategory")(categoryID); }
|
||||
virtual bool setName(const QString &name) { return this->get_override("setName")(name); }
|
||||
virtual bool remove() { return this->get_override("remove")(); }
|
||||
virtual QString name() const override { return this->get_override("name")(); }
|
||||
virtual QString absolutePath() const override { return this->get_override("absolutePath")(); }
|
||||
virtual void setVersion(const MOBase::VersionInfo &version) override { this->get_override("setVersion")(version); }
|
||||
virtual void setNewestVersion(const MOBase::VersionInfo &version) override { this->get_override("setNewestVersion")(version); }
|
||||
virtual void setIsEndorsed(bool endorsed) override { this->get_override("setIsEndorsed")(endorsed); }
|
||||
virtual void setNexusID(int nexusID) override { this->get_override("setNexusID")(nexusID); }
|
||||
virtual void setInstallationFile(const QString &fileName) override { this->get_override("setInstallationFile")(fileName); }
|
||||
virtual void addNexusCategory(int categoryID) override { this->get_override("addNexusCategory")(categoryID); }
|
||||
virtual bool setName(const QString &name) override { return this->get_override("setName")(name); }
|
||||
virtual bool remove() override { return this->get_override("remove")(); }
|
||||
virtual void addCategory(const QString &categoryName) override { this->get_override("addCategory")(categoryName); }
|
||||
virtual bool removeCategory(const QString &categoryName) override { return this->get_override("removeCategory")(categoryName); }
|
||||
virtual QStringList categories() override { return this->get_override("categories")(); }
|
||||
};
|
||||
|
||||
|
||||
struct IPluginListWrapper: MOBase::IPluginList, boost::python::wrapper<MOBase::IPluginList> {
|
||||
virtual PluginState state(const QString &name) const { return this->get_override("state")(name); }
|
||||
virtual PluginStates state(const QString &name) const { return this->get_override("state")(name); }
|
||||
virtual int priority(const QString &name) const { return this->get_override("priority")(name); }
|
||||
virtual int loadOrder(const QString &name) const { return this->get_override("loadOrder")(name); }
|
||||
virtual bool isMaster(const QString &name) const { return this->get_override("isMaster")(name); }
|
||||
@@ -284,16 +291,19 @@ struct IPluginListWrapper: MOBase::IPluginList, boost::python::wrapper<MOBase::I
|
||||
virtual QString origin(const QString &name) const { return this->get_override("origin")(name); }
|
||||
virtual bool onRefreshed(const std::function<void ()> &callback) { return this->get_override("onRefreshed")(callback); }
|
||||
virtual bool onPluginMoved(const std::function<void (const QString &, int, int)> &callback) { return this->get_override("onPluginMoved")(callback); }
|
||||
virtual bool onPluginStateChanged(const std::function<void (const QString &, PluginStates)> &callback) override { return this->get_override("onPluginStateChanged")(callback); }
|
||||
};
|
||||
|
||||
|
||||
struct IModListWrapper: MOBase::IModList, boost::python::wrapper<MOBase::IModList> {
|
||||
virtual QString displayName(const QString &internalName) const { return this->get_override("displayName")(internalName); }
|
||||
virtual ModStates state(const QString &name) const { return this->get_override("state")(name); }
|
||||
virtual int priority(const QString &name) const { return this->get_override("priority")(name); }
|
||||
virtual bool setPriority(const QString &name, int newPriority) { return this->get_override("setPriority")(name, newPriority); }
|
||||
virtual bool onModStateChanged(const std::function<void (const QString &, ModStates)> &func) { return this->get_override("onModStateChanged")(func); }
|
||||
virtual bool onModMoved(const std::function<void (const QString &, int, int)> &func) { return this->get_override("onModMoved")(func); }
|
||||
virtual QString displayName(const QString &internalName) const override { return this->get_override("displayName")(internalName); }
|
||||
virtual QStringList allMods() const override { return this->get_override("allMods")(); }
|
||||
virtual ModStates state(const QString &name) const override { return this->get_override("state")(name); }
|
||||
virtual int priority(const QString &name) const override { return this->get_override("priority")(name); }
|
||||
virtual bool setActive(const QString &name, bool active) override { return this->get_override("setActive")(name, active); }
|
||||
virtual bool setPriority(const QString &name, int newPriority) override { return this->get_override("setPriority")(name, newPriority); }
|
||||
virtual bool onModStateChanged(const std::function<void (const QString &, ModStates)> &func) override { return this->get_override("onModStateChanged")(func); }
|
||||
virtual bool onModMoved(const std::function<void (const QString &, int, int)> &func) override { return this->get_override("onModMoved")(func); }
|
||||
};
|
||||
|
||||
#endif // UIBASEWRAPPERS_H
|
||||
|
||||
Reference in New Issue
Block a user