mirror of
https://github.com/ModOrganizer2/modorganizer-plugin_python.git
synced 2026-07-27 14:03:33 -07:00
Compare commits
21
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f56c605479 | ||
|
|
617c76e9f8 | ||
|
|
96081888f1 | ||
|
|
af5958b0af | ||
|
|
b33293e49a | ||
|
|
dc3b60e578 | ||
|
|
d591bc017a | ||
|
|
aad5864192 | ||
|
|
7deee938d3 | ||
|
|
5d51b2bcc6 | ||
|
|
0566a968e8 | ||
|
|
14fc674d72 | ||
|
|
b7cbdaad1e | ||
|
|
25cdcdd2fe | ||
|
|
f06a6d4e55 | ||
|
|
ceab36e5f0 | ||
|
|
e158038cfc | ||
|
|
d4c424911a | ||
|
|
fee774db45 | ||
|
|
b9c2a18f86 | ||
|
|
224627515a |
@@ -1,3 +1,7 @@
|
||||
#include "resource.h"
|
||||
|
||||
#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
|
||||
|
||||
@@ -14,7 +14,6 @@ contains(QT_VERSION, "^5.*") {
|
||||
|
||||
CONFIG += plugins
|
||||
CONFIG += dll
|
||||
CONFIG += warn_on
|
||||
|
||||
CONFIG(release, debug|release) {
|
||||
QMAKE_CXXFLAGS += /Zi
|
||||
@@ -23,6 +22,9 @@ CONFIG(release, debug|release) {
|
||||
|
||||
DEFINES += PROXYPYTHON_LIBRARY
|
||||
|
||||
# suppress a few warnings caused by boost vs vc++ paranoia
|
||||
DEFINES += _SCL_SECURE_NO_WARNINGS
|
||||
|
||||
SOURCES += proxypython.cpp
|
||||
HEADERS += proxypython.h \
|
||||
resource.h
|
||||
@@ -36,15 +38,14 @@ RC_FILE += \
|
||||
|
||||
include(../plugin_template.pri)
|
||||
|
||||
INCLUDEPATH += "../../pythonRunner"
|
||||
INCLUDEPATH += "../../pythonRunner" "$(BOOSTPATH)"
|
||||
|
||||
WINPWD = $$PWD
|
||||
WINPWD ~= s,/,$$QMAKE_DIR_SEP,g
|
||||
|
||||
|
||||
//QMAKE_POST_LINK += SET VS90COMNTOOLS=%VS100COMNTOOLS% $$escape_expand(\\n)
|
||||
|
||||
|
||||
QMAKE_POST_LINK += copy $$(PYTHONPATH)\\lib\\site-packages\\sip.pyd $$quote($$DSTDIR)\\plugins\\data\\ $$escape_expand(\\n)
|
||||
QMAKE_POST_LINK += copy $$(PYTHONPATH)\\lib\\site-packages\\PyQt4\\QtCore.pyd $$quote($$DSTDIR)\\plugins\\data\\ $$escape_expand(\\n)
|
||||
QMAKE_POST_LINK += copy $$(PYTHONPATH)\\lib\\site-packages\\PyQt4\\QtGui.pyd $$quote($$DSTDIR)\\plugins\\data\\ $$escape_expand(\\n)
|
||||
//QMAKE_POST_LINK += copy $$(PYTHONPATH)\\lib\\site-packages\\sip.pyd $$quote($$DSTDIR)\\plugins\\data\\ $$escape_expand(\\n)
|
||||
//QMAKE_POST_LINK += copy $$(PYTHONPATH)\\lib\\site-packages\\PyQt4\\QtCore.pyd $$quote($$DSTDIR)\\plugins\\data\\PyQt4\\ $$escape_expand(\\n)
|
||||
//QMAKE_POST_LINK += copy $$(PYTHONPATH)\\lib\\site-packages\\PyQt4\\QtGui.pyd $$quote($$DSTDIR)\\plugins\\data\\PyQt4\\ $$escape_expand(\\n)
|
||||
|
||||
+126
-30
@@ -1,16 +1,31 @@
|
||||
#pragma warning( push )
|
||||
#pragma warning( disable : 4100 ) // a lot of unreferenced formal parameters from boost libraries
|
||||
#pragma warning( disable : 4996 ) // strncpy claimed to be unsafe
|
||||
/*
|
||||
Copyright (C) 2013 Sebastian Herbord. All rights reserved.
|
||||
|
||||
This file is part of python proxy plugin for MO
|
||||
|
||||
python proxy plugin is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Python proxy plugin is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with python proxy plugin. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include "proxypython.h"
|
||||
|
||||
#pragma warning( pop )
|
||||
|
||||
#include <utility.h>
|
||||
#include <versioninfo.h>
|
||||
#include <QtPlugin>
|
||||
#include <QDirIterator>
|
||||
#include <QWidget>
|
||||
#include <QMessageBox>
|
||||
#include <QCoreApplication>
|
||||
#include "resource.h"
|
||||
|
||||
|
||||
@@ -32,8 +47,6 @@ HMODULE GetOwnModuleHandle()
|
||||
|
||||
QString ExtractResource(WORD resourceID, const QString &szFilename)
|
||||
{
|
||||
bool success = false;
|
||||
|
||||
HMODULE mod = GetOwnModuleHandle();
|
||||
|
||||
HRSRC hResource = FindResourceW(mod, MAKEINTRESOURCE(resourceID), L"BINARY");
|
||||
@@ -85,8 +98,23 @@ typedef IPythonRunner* (*CreatePythonRunner_func)(const MOBase::IOrganizer *moIn
|
||||
bool ProxyPython::init(IOrganizer *moInfo)
|
||||
{
|
||||
m_MOInfo = moInfo;
|
||||
if (!m_MOInfo->pluginSetting(name(), "enabled").toBool()) {
|
||||
m_LoadFailure = FAIL_NONE;
|
||||
return false;
|
||||
}
|
||||
|
||||
m_LoadFailure = FAIL_OTHER;
|
||||
if (QCoreApplication::applicationDirPath().contains(';')) {
|
||||
m_LoadFailure = FAIL_SEMICOLON;
|
||||
return true;
|
||||
}
|
||||
|
||||
QString pythonPath = m_MOInfo->pluginSetting(name(), "python_dir").toString();
|
||||
|
||||
if (!pythonPath.isEmpty() && !QFile::exists(pythonPath + "/python.exe")) {
|
||||
m_LoadFailure = FAIL_WRONGPYTHONPATH;
|
||||
return true;
|
||||
}
|
||||
|
||||
m_TempRunnerFile = ExtractResource(IDR_LOADER_DLL, "__pythonRunner.dll");
|
||||
m_RunnerLib = ::LoadLibraryW(ToWString(m_TempRunnerFile).c_str());
|
||||
@@ -95,8 +123,33 @@ bool ProxyPython::init(IOrganizer *moInfo)
|
||||
if (CreatePythonRunner == NULL) {
|
||||
throw MyException("embedded dll is invalid: " + windowsErrorString(::GetLastError()));
|
||||
}
|
||||
m_Runner = CreatePythonRunner(moInfo, m_MOInfo->pluginSetting(name(), "python_dir").toString());
|
||||
m_LoadFailure = FAIL_NONE;
|
||||
if (m_MOInfo->persistent(name(), "tryInit", false).toBool()) {
|
||||
if (pythonPath.isEmpty()) {
|
||||
m_LoadFailure = FAIL_PYTHONDETECTION;
|
||||
} else {
|
||||
m_LoadFailure = FAIL_WRONGPYTHONPATH;
|
||||
}
|
||||
if (QMessageBox::question(parentWidget(), tr("Python Initialization failed"),
|
||||
tr("On a previous start the Python Plugin failed to initialize.\n"
|
||||
"Either the value in Settings->Plugins->ProxyPython->plugin_dir is set incorrectly or it is empty and auto-detection doesn't work "
|
||||
"for whatever reason.\n"
|
||||
"Do you want to try initializing python again (at the risk of another crash)?\n"
|
||||
"Suggestion: Select \"no\", and click the warning sign for further help. Afterwards you have to re-enable the python plugin."),
|
||||
QMessageBox::Yes | QMessageBox::No, QMessageBox::No) == QMessageBox::No) {
|
||||
m_MOInfo->setPluginSetting(name(), "enabled", false);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
m_MOInfo->setPersistent(name(), "tryInit", true);
|
||||
m_Runner = CreatePythonRunner(moInfo, pythonPath);
|
||||
m_MOInfo->setPersistent(name(), "tryInit", false);
|
||||
|
||||
if (m_Runner != NULL) {
|
||||
m_LoadFailure = FAIL_NONE;
|
||||
} else {
|
||||
m_LoadFailure = FAIL_INITFAIL;
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
DWORD error = ::GetLastError();
|
||||
@@ -125,7 +178,7 @@ QString ProxyPython::description() const
|
||||
|
||||
VersionInfo ProxyPython::version() const
|
||||
{
|
||||
return VersionInfo(1, 1, 0, VersionInfo::RELEASE_FINAL);
|
||||
return VersionInfo(1, 3, 0, VersionInfo::RELEASE_FINAL);
|
||||
}
|
||||
|
||||
bool ProxyPython::isActive() const
|
||||
@@ -137,6 +190,7 @@ QList<PluginSetting> ProxyPython::settings() const
|
||||
{
|
||||
QList<PluginSetting> result;
|
||||
result.push_back(PluginSetting("python_dir", "Path to your python installation. Leave empty for auto-detection", ""));
|
||||
result.push_back(PluginSetting("enabled", "Set to true to enable support for python plugins", true));
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -156,7 +210,8 @@ QStringList ProxyPython::pluginList(const QString &pluginPath) const
|
||||
QObject *ProxyPython::instantiate(const QString &pluginName)
|
||||
{
|
||||
if (m_Runner != NULL) {
|
||||
return m_Runner->instantiate(pluginName);
|
||||
QObject *result = m_Runner->instantiate(pluginName);
|
||||
return result;
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
@@ -168,6 +223,14 @@ std::vector<unsigned int> ProxyPython::activeProblems() const
|
||||
std::vector<unsigned int> result;
|
||||
if (m_LoadFailure == FAIL_MISSINGDEPENDENCIES) {
|
||||
result.push_back(PROBLEM_PYTHONMISSING);
|
||||
} else if (m_LoadFailure == FAIL_WRONGPYTHONPATH) {
|
||||
result.push_back(PROBLEM_WRONGPYTHONPATH);
|
||||
} else if (m_LoadFailure == FAIL_PYTHONDETECTION) {
|
||||
result.push_back(PROBLEM_PYTHONDETECTION);
|
||||
} else if (m_LoadFailure == FAIL_INITFAIL) {
|
||||
result.push_back(PROBLEM_INITFAIL);
|
||||
} else if (m_LoadFailure == FAIL_SEMICOLON) {
|
||||
result.push_back(PROBLEM_SEMICOLON);
|
||||
} else if (m_Runner != NULL) {
|
||||
if (!m_Runner->isPythonInstalled()) {
|
||||
// don't know how this could happen but wth
|
||||
@@ -185,11 +248,23 @@ QString ProxyPython::shortDescription(unsigned int key) const
|
||||
{
|
||||
switch (key) {
|
||||
case PROBLEM_PYTHONMISSING: {
|
||||
return tr("Python not installed or not found");
|
||||
} break;
|
||||
return tr("Python not installed or not found");
|
||||
} break;
|
||||
case PROBLEM_PYTHONWRONGVERSION: {
|
||||
return tr("Python version is incompatible");
|
||||
} break;
|
||||
return tr("Python version is incompatible");
|
||||
} break;
|
||||
case PROBLEM_WRONGPYTHONPATH: {
|
||||
return tr("Invalid python path");
|
||||
} break;
|
||||
case PROBLEM_INITFAIL: {
|
||||
return tr("Initializing Python failed");
|
||||
} break;
|
||||
case PROBLEM_PYTHONDETECTION: {
|
||||
return tr("Python auto-detection failed");
|
||||
} break;
|
||||
case PROBLEM_SEMICOLON: {
|
||||
return tr("ModOrganizer path contains a semicolon");
|
||||
} break;
|
||||
default:
|
||||
throw MyException(tr("invalid problem key %1").arg(key));
|
||||
}
|
||||
@@ -200,29 +275,50 @@ QString ProxyPython::fullDescription(unsigned int key) const
|
||||
{
|
||||
switch (key) {
|
||||
case PROBLEM_PYTHONMISSING: {
|
||||
return tr("Some plugins require the python interpreter to be installed. "
|
||||
"These plugins will not even show up in settings->plugins.<br>"
|
||||
"If you want to use those plugins, please install the 32-bit version of Python 2.7.x from <a href=\"%1\">%1</a>.").arg(s_DownloadPythonURL);
|
||||
} break;
|
||||
return tr("Some MO plugins require the python interpreter to be installed. "
|
||||
"These plugins will not even show up in settings->plugins.<br>"
|
||||
"If you want to use those plugins, please install the 32-bit version of Python 2.7.x from <a href=\"%1\">%1</a>.<br>"
|
||||
"This is only required to use some extended functionality in MO, you do not need Python to play the game.").arg(s_DownloadPythonURL);
|
||||
} break;
|
||||
case PROBLEM_PYTHONWRONGVERSION: {
|
||||
return tr("Your installed python version has a different version than 2.7. "
|
||||
"Some plugins may not work.<br>"
|
||||
"If you have multiple versions of python installed you may have to configure the path to 2.7 "
|
||||
"in the settings dialog.");
|
||||
} break;
|
||||
return tr("Your installed python version has a different version than 2.7. "
|
||||
"Some MO plugins may not work.<br>"
|
||||
"If you have multiple versions of python installed you may have to configure the path to 2.7 (32 bit) "
|
||||
"in the settings dialog.<br>"
|
||||
"This is only required to use some extended functionality in MO, you do not need Python to play the game.");
|
||||
} break;
|
||||
case PROBLEM_WRONGPYTHONPATH: {
|
||||
return tr("Please set python_dir in Settings->Plugins->ProxyPython to the path of your python 2.7 (32 bit) installation.");
|
||||
} break;
|
||||
case PROBLEM_PYTHONDETECTION: {
|
||||
return tr("The auto-detection of the python path failed. I don't know why this would happen but you can try to fix it "
|
||||
"by setting python_dir in Settings->Plugins->ProxyPython to the path of your python 2.7 (32 bit) installation.");
|
||||
} break;
|
||||
case PROBLEM_INITFAIL: {
|
||||
return tr("Sorry, I don't know any details. Most likely your python installation is not supported.");
|
||||
} break;
|
||||
case PROBLEM_SEMICOLON: {
|
||||
return tr("The path to Mod Organizer (%1) contains a semicolon. <br>"
|
||||
"While this is legal on NTFS drives there is a lot of software that doesn't handle it correctly.<br>"
|
||||
"Unfortunately MO depends on libraries that seem to fall into that group.<br>"
|
||||
"As a result the python plugin can't be loaded.<br>"
|
||||
"The only solution I can offer is to remove the semicolon / move MO to a path without a semicolon.").arg(QCoreApplication::applicationDirPath());
|
||||
} break;
|
||||
default:
|
||||
throw MyException(tr("invalid problem key %1").arg(key));
|
||||
throw MyException(QString("invalid problem key %1").arg(key));
|
||||
}
|
||||
}
|
||||
|
||||
bool ProxyPython::hasGuidedFix(unsigned int) const
|
||||
bool ProxyPython::hasGuidedFix(unsigned int key) const
|
||||
{
|
||||
return true;
|
||||
return (key == PROBLEM_PYTHONMISSING) || (key == PROBLEM_PYTHONWRONGVERSION);
|
||||
}
|
||||
|
||||
void ProxyPython::startGuidedFix(unsigned int) const
|
||||
void ProxyPython::startGuidedFix(unsigned int key) const
|
||||
{
|
||||
::ShellExecuteA(NULL, "open", s_DownloadPythonURL, NULL, NULL, SW_SHOWNORMAL);
|
||||
if ((key == PROBLEM_PYTHONMISSING) || (key == PROBLEM_PYTHONWRONGVERSION)) {
|
||||
::ShellExecuteA(NULL, "open", s_DownloadPythonURL, NULL, NULL, SW_SHOWNORMAL);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
+28
-1
@@ -1,3 +1,22 @@
|
||||
/*
|
||||
Copyright (C) 2013 Sebastian Herbord. All rights reserved.
|
||||
|
||||
This file is part of python proxy plugin for MO
|
||||
|
||||
python proxy plugin is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Python proxy plugin is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with python proxy plugin. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PROXYPYTHON_H
|
||||
#define PROXYPYTHON_H
|
||||
|
||||
@@ -50,17 +69,25 @@ private:
|
||||
|
||||
static const unsigned int PROBLEM_PYTHONMISSING = 1;
|
||||
static const unsigned int PROBLEM_PYTHONWRONGVERSION = 2;
|
||||
static const unsigned int PROBLEM_WRONGPYTHONPATH = 3;
|
||||
static const unsigned int PROBLEM_INITFAIL = 4;
|
||||
static const unsigned int PROBLEM_PYTHONDETECTION = 5;
|
||||
static const unsigned int PROBLEM_SEMICOLON = 6;
|
||||
static const char *s_DownloadPythonURL;
|
||||
|
||||
const MOBase::IOrganizer *m_MOInfo;
|
||||
MOBase::IOrganizer *m_MOInfo;
|
||||
QString m_TempRunnerFile;
|
||||
HMODULE m_RunnerLib;
|
||||
IPythonRunner *m_Runner;
|
||||
|
||||
enum {
|
||||
FAIL_NONE,
|
||||
FAIL_SEMICOLON,
|
||||
FAIL_NOTINIT,
|
||||
FAIL_MISSINGDEPENDENCIES,
|
||||
FAIL_INITFAIL,
|
||||
FAIL_WRONGPYTHONPATH,
|
||||
FAIL_PYTHONDETECTION,
|
||||
FAIL_OTHER
|
||||
} m_LoadFailure;
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#include "proxypluginwrappers.h"
|
||||
#include <boost/python.hpp>
|
||||
#include <utility.h>
|
||||
#include "error.h"
|
||||
#include "gilock.h"
|
||||
@@ -171,7 +170,7 @@ bool IPluginInstallerCustomWrapper::isManualInstaller() const
|
||||
} PYCATCH;
|
||||
}
|
||||
|
||||
bool IPluginInstallerCustomWrapper::isArchiveSupported(const DirectoryTree &tree) const
|
||||
bool IPluginInstallerCustomWrapper::isArchiveSupported(const DirectoryTree &) const
|
||||
{
|
||||
try {
|
||||
//return this->get_override("isArchiveSupported")(tree);
|
||||
|
||||
@@ -12,6 +12,9 @@ CONFIG += warn_on
|
||||
|
||||
DEFINES += PYTHONRUNNER_LIBRARY
|
||||
|
||||
# suppress a few warnings caused by boost vs vc++ paranoia
|
||||
DEFINES += _SCL_SECURE_NO_WARNINGS
|
||||
|
||||
SOURCES += pythonrunner.cpp \
|
||||
gilock.cpp \
|
||||
error.cpp \
|
||||
@@ -28,15 +31,26 @@ HEADERS += pythonrunner.h \
|
||||
|
||||
|
||||
CONFIG(debug, debug|release) {
|
||||
SRCDIR = $$OUT_PWD/debug
|
||||
DSTDIR = $$PWD/../../outputd
|
||||
LIBS += -L$$OUT_PWD/../uibase/debug
|
||||
} else {
|
||||
SRCDIR = $$OUT_PWD/release
|
||||
DSTDIR = $$PWD/../../output
|
||||
LIBS += -L$$OUT_PWD/../uibase/release
|
||||
QMAKE_CXXFLAGS += /Zi
|
||||
QMAKE_LFLAGS += /DEBUG
|
||||
}
|
||||
|
||||
|
||||
SRCDIR ~= s,/,$$QMAKE_DIR_SEP,g
|
||||
DSTDIR ~= s,/,$$QMAKE_DIR_SEP,g
|
||||
|
||||
INCLUDEPATH += "$(BOOSTPATH)" "$$(PYTHONPATH)/include" "$$(PYTHONPATH)/Lib/site-packages/PyQt4/include"
|
||||
LIBS += -L"$$(PYTHONPATH)/libs" -L"$(BOOSTPATH)/stage/lib"
|
||||
LIBS += -lpython27
|
||||
|
||||
INCLUDEPATH += ../uibase
|
||||
LIBS += -luibase
|
||||
|
||||
QMAKE_POST_LINK += xcopy /y /I $$quote($$SRCDIR\\$${TARGET}*.pdb) $$quote($$DSTDIR)\\plugins $$escape_expand(\\n)
|
||||
|
||||
@@ -99,7 +99,6 @@ QList<MOBase::PluginSetting> PythonPluginWrapper::settings() const
|
||||
try {
|
||||
boost::python::object l = m_SettingsFunction();
|
||||
if (!l.is_none()) {
|
||||
// boost::python::list l = extract<boost::python::list>(temp);
|
||||
for (int i = 0; i < boost::python::len(l); ++i) {
|
||||
result.append(extract<MOBase::PluginSetting>(l[i]));
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ public:
|
||||
virtual QList<MOBase::PluginSetting> settings() const;
|
||||
|
||||
protected:
|
||||
|
||||
void reportPythonError() const;
|
||||
|
||||
private:
|
||||
|
||||
+233
-38
@@ -1,5 +1,7 @@
|
||||
#include "pythonrunner.h"
|
||||
|
||||
#pragma warning( disable : 4100 )
|
||||
#pragma warning( disable : 4996 )
|
||||
|
||||
#include <boost/python.hpp>
|
||||
#include <iplugininstaller.h>
|
||||
@@ -8,6 +10,8 @@
|
||||
#include "proxypluginwrappers.h"
|
||||
#include <Windows.h>
|
||||
#include <utility.h>
|
||||
#include <QFile>
|
||||
#include <QCoreApplication>
|
||||
|
||||
// sip and qt slots seems to conflict
|
||||
#include <sip.h>
|
||||
@@ -16,6 +20,7 @@
|
||||
#include <boost/python.hpp>
|
||||
#endif
|
||||
|
||||
|
||||
MOBase::IOrganizer *s_Organizer = NULL;
|
||||
|
||||
|
||||
@@ -32,20 +37,25 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
void initPath(boost::python::object &moduleNamespace);
|
||||
|
||||
private:
|
||||
std::map<QString, boost::python::object> m_PythonObjects;
|
||||
const MOBase::IOrganizer *m_MOInfo;
|
||||
char *m_PythonHome;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
IPythonRunner *CreatePythonRunner(const MOBase::IOrganizer *moInfo, const QString &pythonDir)
|
||||
IPythonRunner *CreatePythonRunner(MOBase::IOrganizer *moInfo, const QString &pythonDir)
|
||||
{
|
||||
s_Organizer = moInfo;
|
||||
PythonRunner *result = new PythonRunner(moInfo);
|
||||
result->initPython(pythonDir);
|
||||
return result;
|
||||
if (result->initPython(pythonDir)) {
|
||||
return result;
|
||||
} else {
|
||||
delete result;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -76,6 +86,15 @@ struct QString_to_python_str
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct QFlags_to_int
|
||||
{
|
||||
static PyObject *convert(const QFlags<T> &flags) {
|
||||
return bpy::incref(bpy::object(static_cast<int>(flags)).ptr());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
struct QString_from_python_str
|
||||
{
|
||||
QString_from_python_str() {
|
||||
@@ -101,7 +120,6 @@ struct QString_from_python_str
|
||||
};
|
||||
|
||||
|
||||
|
||||
template <typename T>
|
||||
struct GuessedValue_converters
|
||||
{
|
||||
@@ -131,7 +149,6 @@ struct GuessedValue_converters
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void construct(PyObject *objPtr, bpy::converter::rvalue_from_python_stage1_data* data) {
|
||||
void *storage = ((bpy::converter::rvalue_from_python_storage<GuessedValue<T> >*)data)->storage.bytes;
|
||||
GuessedValue<T> *result = new (storage) GuessedValue<T>();
|
||||
@@ -248,6 +265,7 @@ struct QVariant_from_python_obj
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <typename T>
|
||||
struct QList_to_python_list
|
||||
{
|
||||
@@ -371,6 +389,7 @@ PyObject *toPyQt(T *objPtr)
|
||||
return bpy::incref(sipObj);
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
struct QClass_converters
|
||||
{
|
||||
@@ -498,6 +517,101 @@ struct QInterface_converters
|
||||
};
|
||||
|
||||
|
||||
int getArgCount(PyObject *object) {
|
||||
int result = 0;
|
||||
PyObject *funcCode = PyObject_GetAttrString(object, "func_code");
|
||||
if (funcCode) {
|
||||
PyObject *argCount = PyObject_GetAttrString(funcCode, "co_argcount");
|
||||
if(argCount) {
|
||||
result = PyInt_AsLong(argCount);
|
||||
Py_DECREF(argCount);
|
||||
}
|
||||
Py_DECREF(funcCode);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
struct Functor0_converter
|
||||
{
|
||||
|
||||
struct FunctorWrapper
|
||||
{
|
||||
FunctorWrapper(boost::python::object callable) : m_Callable(callable) {
|
||||
}
|
||||
|
||||
void operator()() {
|
||||
GILock lock;
|
||||
m_Callable();
|
||||
}
|
||||
|
||||
boost::python::object m_Callable;
|
||||
};
|
||||
|
||||
Functor0_converter()
|
||||
{
|
||||
bpy::converter::registry::push_back(&convertible, &construct, bpy::type_id<std::function<void()>>());
|
||||
}
|
||||
|
||||
static void *convertible(PyObject *object)
|
||||
{
|
||||
if (!PyCallable_Check(object)
|
||||
|| (getArgCount(object) != 0)) {
|
||||
return NULL;
|
||||
}
|
||||
return object;
|
||||
}
|
||||
|
||||
static void construct(PyObject *object, bpy::converter::rvalue_from_python_stage1_data *data)
|
||||
{
|
||||
bpy::object callable(bpy::handle<>(bpy::borrowed(object)));
|
||||
void *storage = ((bpy::converter::rvalue_from_python_storage<std::function<void()>>*)data)->storage.bytes;
|
||||
new (storage) std::function<void()>(FunctorWrapper(callable));
|
||||
data->convertible = storage;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <typename PAR1, typename PAR2>
|
||||
struct Functor2_converter
|
||||
{
|
||||
|
||||
struct FunctorWrapper
|
||||
{
|
||||
FunctorWrapper(boost::python::object callable) : m_Callable(callable) {
|
||||
}
|
||||
|
||||
void operator()(const PAR1 ¶m1, const PAR2 ¶m2) {
|
||||
GILock lock;
|
||||
m_Callable(param1, param2);
|
||||
}
|
||||
|
||||
boost::python::object m_Callable;
|
||||
};
|
||||
|
||||
Functor2_converter()
|
||||
{
|
||||
bpy::converter::registry::push_back(&convertible, &construct, bpy::type_id<std::function<void(PAR1, PAR2)>>());
|
||||
}
|
||||
|
||||
static void *convertible(PyObject *object)
|
||||
{
|
||||
if (!PyCallable_Check(object)
|
||||
|| (getArgCount(object) != 2)) {
|
||||
return NULL;
|
||||
}
|
||||
return object;
|
||||
}
|
||||
|
||||
static void construct(PyObject *object, bpy::converter::rvalue_from_python_stage1_data *data)
|
||||
{
|
||||
bpy::object callable(bpy::handle<>(bpy::borrowed(object)));
|
||||
void *storage = ((bpy::converter::rvalue_from_python_storage<std::function<void(PAR1, PAR2)>>*)data)->storage.bytes;
|
||||
new (storage) std::function<void(PAR1, PAR2)>(FunctorWrapper(callable));
|
||||
data->convertible = storage;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(updateWithQuality, MOBase::GuessedValue<QString>::update, 2, 2)
|
||||
|
||||
|
||||
@@ -525,32 +639,37 @@ BOOST_PYTHON_MODULE(mobase)
|
||||
.value("candidate", MOBase::VersionInfo::RELEASE_CANDIDATE)
|
||||
.value("beta", MOBase::VersionInfo::RELEASE_BETA)
|
||||
.value("alpha", MOBase::VersionInfo::RELEASE_ALPHA)
|
||||
.value("prealpha", MOBase::VersionInfo::RELEASE_PREALPHA);
|
||||
.value("prealpha", MOBase::VersionInfo::RELEASE_PREALPHA)
|
||||
;
|
||||
|
||||
bpy::enum_<MOBase::IPluginInstaller::EInstallResult>("InstallResult")
|
||||
.value("success", MOBase::IPluginInstaller::RESULT_SUCCESS)
|
||||
.value("failed", MOBase::IPluginInstaller::RESULT_FAILED)
|
||||
.value("canceled", MOBase::IPluginInstaller::RESULT_CANCELED)
|
||||
.value("manualRequested", MOBase::IPluginInstaller::RESULT_MANUALREQUESTED)
|
||||
.value("notAttempted", MOBase::IPluginInstaller::RESULT_NOTATTEMPTED);
|
||||
.value("notAttempted", MOBase::IPluginInstaller::RESULT_NOTATTEMPTED)
|
||||
;
|
||||
|
||||
bpy::enum_<MOBase::IGameInfo::Type>("GameType")
|
||||
.value("oblivion", MOBase::IGameInfo::TYPE_OBLIVION)
|
||||
.value("fallout3", MOBase::IGameInfo::TYPE_FALLOUT3)
|
||||
.value("falloutnv", MOBase::IGameInfo::TYPE_FALLOUTNV)
|
||||
.value("skyrim", MOBase::IGameInfo::TYPE_SKYRIM);
|
||||
.value("skyrim", MOBase::IGameInfo::TYPE_SKYRIM)
|
||||
;
|
||||
|
||||
bpy::class_<MOBase::VersionInfo>("VersionInfo")
|
||||
.def(bpy::init<int, int, int, MOBase::VersionInfo::ReleaseType>())
|
||||
.def("parse", &MOBase::VersionInfo::parse)
|
||||
.def("canonicalString", &MOBase::VersionInfo::canonicalString);
|
||||
.def("canonicalString", &MOBase::VersionInfo::canonicalString)
|
||||
;
|
||||
|
||||
bpy::class_<MOBase::PluginSetting>("PluginSetting", bpy::init<const QString&, const QString&, const QVariant&>());
|
||||
|
||||
bpy::class_<IGameInfoWrapper, boost::noncopyable>("GameInfo")
|
||||
.def("type", bpy::pure_virtual(&MOBase::IGameInfo::type))
|
||||
.def("path", bpy::pure_virtual(&MOBase::IGameInfo::path))
|
||||
.def("binaryName", bpy::pure_virtual(&MOBase::IGameInfo::binaryName));
|
||||
.def("binaryName", bpy::pure_virtual(&MOBase::IGameInfo::binaryName))
|
||||
;
|
||||
|
||||
bpy::class_<IOrganizerWrapper, boost::noncopyable>("IOrganizer")
|
||||
.def("gameInfo", bpy::pure_virtual(&MOBase::IOrganizer::gameInfo), bpy::return_value_policy<bpy::reference_existing_object>())
|
||||
@@ -564,9 +683,18 @@ BOOST_PYTHON_MODULE(mobase)
|
||||
.def("removeMod", bpy::pure_virtual(&MOBase::IOrganizer::removeMod))
|
||||
.def("modDataChanged", bpy::pure_virtual(&MOBase::IOrganizer::modDataChanged))
|
||||
.def("pluginSetting", bpy::pure_virtual(&IOrganizer::pluginSetting))
|
||||
.def("setPluginSetting", bpy::pure_virtual(&IOrganizer::pluginSetting))
|
||||
.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))
|
||||
.def("downloadManager", bpy::pure_virtual(&IOrganizer::downloadManager), bpy::return_value_policy<bpy::reference_existing_object>());
|
||||
.def("installMod", bpy::pure_virtual(&IOrganizer::installMod), 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("onAboutToRun", bpy::pure_virtual(&IOrganizer::onAboutToRun))
|
||||
.def("refreshModList", bpy::pure_virtual(&IOrganizer::refreshModList))
|
||||
;
|
||||
|
||||
bpy::class_<ModRepositoryBridgeWrapper, boost::noncopyable>("ModRepositoryBridge")
|
||||
.def("requestDescription", &ModRepositoryBridgeWrapper::requestDescription)
|
||||
@@ -575,12 +703,32 @@ BOOST_PYTHON_MODULE(mobase)
|
||||
.def("requestDownloadURL", &ModRepositoryBridgeWrapper::requestDownloadURL)
|
||||
.def("requestToggleEndorsement", &ModRepositoryBridgeWrapper::requestToggleEndorsement)
|
||||
.def("onFilesAvailable", &ModRepositoryBridgeWrapper::onFilesAvailable)
|
||||
.def("onRequestFailed", &ModRepositoryBridgeWrapper::onRequestFailed);
|
||||
.def("onRequestFailed", &ModRepositoryBridgeWrapper::onRequestFailed)
|
||||
;
|
||||
|
||||
bpy::class_<IDownloadManagerWrapper, boost::noncopyable>("IDownloadManager")
|
||||
.def("startDownloadURLs", bpy::pure_virtual(&IDownloadManager::startDownloadURLs))
|
||||
.def("startDownloadNexusFile", bpy::pure_virtual(&IDownloadManager::startDownloadNexusFile))
|
||||
.def("downloadPath", bpy::pure_virtual(&IDownloadManager::downloadPath));
|
||||
.def("downloadPath", bpy::pure_virtual(&IDownloadManager::downloadPath))
|
||||
;
|
||||
|
||||
bpy::class_<IInstallationManagerWrapper, boost::noncopyable>("IInstallationManager")
|
||||
.def("extractFile", bpy::pure_virtual(&IInstallationManager::extractFile))
|
||||
.def("extractFiles", bpy::pure_virtual(&IInstallationManager::extractFiles))
|
||||
.def("installArchive", bpy::pure_virtual(&IInstallationManager::installArchive))
|
||||
;
|
||||
|
||||
bpy::class_<IModInterfaceWrapper, boost::noncopyable>("IModInterface")
|
||||
.def("name", bpy::pure_virtual(&IModInterface::name))
|
||||
.def("absolutePath", bpy::pure_virtual(&IModInterface::absolutePath))
|
||||
.def("setVersion", bpy::pure_virtual(&IModInterface::setVersion))
|
||||
.def("setNewestVersion", bpy::pure_virtual(&IModInterface::setNewestVersion))
|
||||
.def("setIsEndorsed", bpy::pure_virtual(&IModInterface::setIsEndorsed))
|
||||
.def("setNexusID", bpy::pure_virtual(&IModInterface::setNexusID))
|
||||
.def("addNexusCategory", bpy::pure_virtual(&IModInterface::addNexusCategory))
|
||||
.def("setName", bpy::pure_virtual(&IModInterface::setName))
|
||||
.def("remove", bpy::pure_virtual(&IModInterface::remove))
|
||||
;
|
||||
|
||||
bpy::enum_<MOBase::EGuessQuality>("GuessQuality")
|
||||
.value("invalid", MOBase::GUESS_INVALID)
|
||||
@@ -588,18 +736,41 @@ BOOST_PYTHON_MODULE(mobase)
|
||||
.value("good", MOBase::GUESS_GOOD)
|
||||
.value("meta", MOBase::GUESS_META)
|
||||
.value("preset", MOBase::GUESS_PRESET)
|
||||
.value("user", MOBase::GUESS_USER);
|
||||
.value("user", MOBase::GUESS_USER)
|
||||
;
|
||||
|
||||
bpy::class_<MOBase::GuessedValue<QString>, boost::noncopyable>("GuessedString")
|
||||
.def("update",
|
||||
static_cast<GuessedValue<QString> &(GuessedValue<QString>::*)(const QString&, EGuessQuality)>(&GuessedValue<QString>::update),
|
||||
bpy::return_value_policy<bpy::reference_existing_object>(), updateWithQuality())
|
||||
.def("variants", &MOBase::GuessedValue<QString>::variants, bpy::return_value_policy<bpy::copy_const_reference>());
|
||||
.def("variants", &MOBase::GuessedValue<QString>::variants, bpy::return_value_policy<bpy::copy_const_reference>())
|
||||
;
|
||||
|
||||
bpy::class_<IPluginToolWrapper, boost::noncopyable>("IPluginTool")
|
||||
.def("setParentWidget", bpy::pure_virtual(&MOBase::IPluginTool::setParentWidget));
|
||||
.def("setParentWidget", bpy::pure_virtual(&MOBase::IPluginTool::setParentWidget))
|
||||
;
|
||||
bpy::class_<IPluginInstallerCustomWrapper, boost::noncopyable>("IPluginInstallerCustom")
|
||||
.def("setParentWidget", bpy::pure_virtual(&MOBase::IPluginInstallerCustom::setParentWidget));
|
||||
.def("setParentWidget", bpy::pure_virtual(&MOBase::IPluginInstallerCustom::setParentWidget))
|
||||
;
|
||||
|
||||
Functor0_converter(); // converter for the onRefreshed-callback
|
||||
bpy::class_<IPluginListWrapper, boost::noncopyable>("IPluginList")
|
||||
.def("state", bpy::pure_virtual(&MOBase::IPluginList::state))
|
||||
.def("priority", bpy::pure_virtual(&MOBase::IPluginList::priority))
|
||||
.def("loadOrder", bpy::pure_virtual(&MOBase::IPluginList::loadOrder))
|
||||
.def("isMaster", bpy::pure_virtual(&MOBase::IPluginList::isMaster))
|
||||
.def("origin", bpy::pure_virtual(&MOBase::IPluginList::origin))
|
||||
.def("onRefreshed", bpy::pure_virtual(&MOBase::IPluginList::onRefreshed))
|
||||
;
|
||||
|
||||
bpy::to_python_converter<IModList::ModStates, QFlags_to_int<IModList::ModState>>();
|
||||
Functor2_converter<const QString&, IModList::ModStates>(); // converter for the onModStateChanged-callback
|
||||
bpy::class_<IModListWrapper, boost::noncopyable>("IModList")
|
||||
.def("state", bpy::pure_virtual(&MOBase::IModList::state))
|
||||
.def("priority", bpy::pure_virtual(&MOBase::IModList::priority))
|
||||
.def("setPriority", bpy::pure_virtual(&MOBase::IModList::setPriority))
|
||||
.def("onModStateChanged", bpy::pure_virtual(&MOBase::IModList::onModStateChanged))
|
||||
;
|
||||
|
||||
GuessedValue_converters<QString>();
|
||||
|
||||
@@ -621,10 +792,13 @@ PythonRunner::PythonRunner(const MOBase::IOrganizer *moInfo)
|
||||
|
||||
static char* argv0 = "ModOrganizer.exe";
|
||||
|
||||
|
||||
bool PythonRunner::initPython(const QString &pythonPath)
|
||||
{
|
||||
try {
|
||||
//QString pythonPath = m_MOInfo->pluginSetting(name(), "python_dir").toString();
|
||||
if (!pythonPath.isEmpty() && !QFile::exists(pythonPath + "/python.exe")) {
|
||||
return false;
|
||||
}
|
||||
strncpy(m_PythonHome, pythonPath.toUtf8().constData(), MAX_PATH);
|
||||
if (!pythonPath.isEmpty()) {
|
||||
Py_SetPythonHome(m_PythonHome);
|
||||
@@ -632,19 +806,25 @@ bool PythonRunner::initPython(const QString &pythonPath)
|
||||
|
||||
Py_SetProgramName(argv0);
|
||||
PyImport_AppendInittab("mobase", &initmobase);
|
||||
Py_Initialize();
|
||||
Py_OptimizeFlag = 2;
|
||||
Py_NoSiteFlag = 1;
|
||||
Py_InitializeEx(0);
|
||||
|
||||
if (!Py_IsInitialized()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
PySys_SetArgv(0, &argv0);
|
||||
|
||||
bpy::object main_module = bpy::import("__main__");
|
||||
bpy::object main_namespace = main_module.attr("__dict__");
|
||||
main_namespace["cStringIO"] = bpy::import("cStringIO");
|
||||
main_namespace["sys"] = bpy::import("sys");
|
||||
bpy::object mainModule = bpy::import("__main__");
|
||||
bpy::object mainNamespace = mainModule.attr("__dict__");
|
||||
mainNamespace["sys"] = bpy::import("sys");
|
||||
initPath(mainNamespace);
|
||||
bpy::import("site");
|
||||
mainNamespace["cStringIO"] = bpy::import("cStringIO");
|
||||
bpy::exec("s_ErrIO = cStringIO.StringIO()\n"
|
||||
"sys.stderr = s_ErrIO",
|
||||
main_namespace);
|
||||
mainNamespace);
|
||||
return true;
|
||||
} catch (const bpy::error_already_set&) {
|
||||
qDebug("failed to init python");
|
||||
@@ -674,26 +854,41 @@ bool handled_exec_file(bpy::str filename, bpy::object globals = bpy::object(), b
|
||||
} while (false)
|
||||
|
||||
|
||||
void PythonRunner::initPath(bpy::object &moduleNamespace)
|
||||
{
|
||||
static QString paths[] = {
|
||||
m_MOInfo->pluginDataPath(),
|
||||
QCoreApplication::applicationDirPath(),
|
||||
QCoreApplication::applicationDirPath() + "/python27.zip",
|
||||
QCoreApplication::applicationDirPath() + "/python27.zip/Lib",
|
||||
QCoreApplication::applicationDirPath() + "/python27.zip/DLLs",
|
||||
QCoreApplication::applicationDirPath() + "/python27.zip/Lib/site-packages",
|
||||
};
|
||||
|
||||
for (int i = 0; i < sizeof(paths) / sizeof(QString); ++i) {
|
||||
QString expr = QString("sys.path.insert(%1, \"%2\")").arg(i).arg(paths[i]);
|
||||
bpy::eval(expr.toUtf8().constData(), moduleNamespace);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
QObject *PythonRunner::instantiate(const QString &pluginName)
|
||||
{
|
||||
try {
|
||||
GILock lock;
|
||||
bpy::object main_module = bpy::import("__main__");
|
||||
bpy::object main_namespace = main_module.attr("__dict__");
|
||||
bpy::object mainModule = bpy::import("__main__");
|
||||
bpy::object moduleNamespace = mainModule.attr("__dict__");
|
||||
|
||||
bpy::object mobase_module((bpy::handle<>(PyImport_ImportModule("mobase"))));
|
||||
main_namespace["sys"] = bpy::import("sys");
|
||||
main_namespace["mobase"] = mobase_module;
|
||||
QString appendDataPath = QString("sys.path.insert(0, \"%1\")").arg(m_MOInfo->pluginDataPath());
|
||||
|
||||
bpy::eval(appendDataPath.toUtf8().constData(), main_namespace);
|
||||
bpy::object sys = bpy::import("sys");
|
||||
moduleNamespace["sys"] = sys;
|
||||
moduleNamespace["mobase"] = bpy::import("mobase");
|
||||
|
||||
std::string temp = ToString(pluginName);
|
||||
if (handled_exec_file(temp.c_str(), main_namespace)) {
|
||||
if (handled_exec_file(temp.c_str(), moduleNamespace)) {
|
||||
reportPythonError();
|
||||
return NULL;
|
||||
}
|
||||
m_PythonObjects[pluginName] = main_namespace["createPlugin"]();
|
||||
m_PythonObjects[pluginName] = moduleNamespace["createPlugin"]();
|
||||
|
||||
bpy::object pluginObj = m_PythonObjects[pluginName];
|
||||
TRY_PLUGIN_TYPE(IPluginInstallerCustom, pluginObj);
|
||||
|
||||
@@ -15,7 +15,15 @@ public:
|
||||
virtual bool isPythonVersionSupported() const = 0;
|
||||
};
|
||||
|
||||
extern "C" QDLLEXPORT IPythonRunner *CreatePythonRunner(const MOBase::IOrganizer *moInfo, const QString &pythonDir);
|
||||
|
||||
#ifdef PYTHONRUNNER_LIBRARY
|
||||
#define PYDLLEXPORT Q_DECL_EXPORT
|
||||
#else // PYTHONRUNNER_LIBRARY
|
||||
#define PYDLLEXPORT Q_DECL_IMPORT
|
||||
#endif // PYTHONRUNNER_LIBRARY
|
||||
|
||||
extern "C" PYDLLEXPORT IPythonRunner *CreatePythonRunner(MOBase::IOrganizer *moInfo, const QString &pythonDir);
|
||||
|
||||
|
||||
|
||||
#endif // PYTHONRUNNER_H
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
#ifndef PYTHONRUNNER_GLOBAL_H
|
||||
#define PYTHONRUNNER_GLOBAL_H
|
||||
|
||||
#include <QtCore/qglobal.h>
|
||||
|
||||
#if defined(PYTHONRUNNER_LIBRARY)
|
||||
# define PYTHONRUNNERSHARED_EXPORT Q_DECL_EXPORT
|
||||
#else
|
||||
# define PYTHONRUNNERSHARED_EXPORT Q_DECL_IMPORT
|
||||
#endif
|
||||
|
||||
#endif // PYTHONRUNNER_GLOBAL_H
|
||||
+61
-13
@@ -3,7 +3,9 @@
|
||||
|
||||
|
||||
#ifndef Q_MOC_RUN
|
||||
#pragma warning (push, 0)
|
||||
#include <boost/python.hpp>
|
||||
#pragma warning (pop)
|
||||
#endif
|
||||
|
||||
#include <QString>
|
||||
@@ -11,6 +13,8 @@
|
||||
#include <imoinfo.h>
|
||||
#include <igameinfo.h>
|
||||
#include <imodrepositorybridge.h>
|
||||
#include <imodinterface.h>
|
||||
#include <iinstallationmanager.h>
|
||||
#include "error.h"
|
||||
#include "gilock.h"
|
||||
|
||||
@@ -65,8 +69,8 @@ public:
|
||||
|
||||
void onRequestFailed(boost::python::object callback) {
|
||||
m_FailedHandler = callback;
|
||||
connect(m_Wrapped, SIGNAL(requestFailed(int,QVariant,QString)),
|
||||
this, SLOT(requestFailed(int,QVariant,QString)),
|
||||
connect(m_Wrapped, SIGNAL(requestFailed(int,int,QVariant,QString)),
|
||||
this, SLOT(requestFailed(int,int,QVariant,QString)),
|
||||
Qt::UniqueConnection);
|
||||
}
|
||||
|
||||
@@ -82,20 +86,20 @@ private slots:
|
||||
qCritical("no handler connected");
|
||||
return;
|
||||
}
|
||||
// try {
|
||||
try {
|
||||
GILock lock;
|
||||
m_FilesAvailableHandler(modID, userData, resultData);
|
||||
// } catch (const boost::python::error_already_set&) {
|
||||
} catch (const boost::python::error_already_set&) {
|
||||
// qDebug("error");
|
||||
//reportPythonError();
|
||||
// }
|
||||
reportPythonError();
|
||||
}
|
||||
}
|
||||
|
||||
void requestFailed(int modID, QVariant userData, const QString &errorMessage)
|
||||
void requestFailed(int modID, int fileID, QVariant userData, const QString &errorMessage)
|
||||
{
|
||||
try {
|
||||
GILock lock;
|
||||
m_FailedHandler(modID, userData, errorMessage);
|
||||
m_FailedHandler(modID, fileID, userData, errorMessage);
|
||||
} catch (const boost::python::error_already_set&) {
|
||||
reportPythonError();
|
||||
}
|
||||
@@ -119,10 +123,6 @@ struct IOrganizerWrapper: MOBase::IOrganizer, boost::python::wrapper<MOBase::IOr
|
||||
virtual MOBase::IModRepositoryBridge *createNexusBridge() const {
|
||||
return this->get_override("createNexusBridge")();
|
||||
}
|
||||
/*
|
||||
static ModRepositoryBridgeWrapper newNexusBridge(IOrganizerWrapper *self) {
|
||||
return ModRepositoryBridgeWrapper(self->createNexusBridge());
|
||||
}*/
|
||||
|
||||
virtual QString profileName() const { return this->get_override("profileName")(); }
|
||||
virtual QString profilePath() const { return this->get_override("profilePath")(); }
|
||||
@@ -133,10 +133,21 @@ struct IOrganizerWrapper: MOBase::IOrganizer, boost::python::wrapper<MOBase::IOr
|
||||
virtual bool removeMod(MOBase::IModInterface *mod) { return this->get_override("removeMod")(mod); }
|
||||
virtual void modDataChanged(MOBase::IModInterface *mod) { this->get_override("modDataChanged")(mod); }
|
||||
virtual QVariant pluginSetting(const QString &pluginName, const QString &key) const { return this->get_override("pluginSetting")(pluginName, key); }
|
||||
virtual void setPluginSetting(const QString &pluginName, const QString &key, const QVariant &value) { this->get_override("setPluginSetting")(pluginName, key, value); }
|
||||
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 void installMod(const QString &fileName) { this->get_override("installMod")(fileName); }
|
||||
virtual MOBase::IModInterface *installMod(const QString &fileName) { return this->get_override("installMod")(fileName); }
|
||||
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 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 onAboutToRun(const std::function<bool(const QString&)> &func) { return this->get_override("onAboutToRun")(func); }
|
||||
virtual void refreshModList(bool saveChanges = true) { this->get_override("refreshModList")(saveChanges); }
|
||||
};
|
||||
|
||||
struct IDownloadManagerWrapper: MOBase::IDownloadManager, boost::python::wrapper<MOBase::IDownloadManager>
|
||||
@@ -148,6 +159,13 @@ private:
|
||||
boost::python::object m_DownloadCompleteHandler;
|
||||
};
|
||||
|
||||
struct IInstallationManagerWrapper: MOBase::IInstallationManager, boost::python::wrapper<MOBase::IInstallationManager>
|
||||
{
|
||||
virtual QString extractFile(const QString &fileName) { return this->get_override("extractFile")(fileName); }
|
||||
virtual QStringList extractFiles(const QStringList &files, bool flatten) { return this->get_override("extractFiles")(files, flatten); }
|
||||
virtual MOBase::IPluginInstaller::EInstallResult installArchive(MOBase::GuessedValue<QString> &modName, const QString &archiveFile) { return this->get_override("installArchive")(modName, archiveFile); }
|
||||
};
|
||||
|
||||
struct IGameInfoWrapper: MOBase::IGameInfo, boost::python::wrapper<MOBase::IGameInfo>
|
||||
{
|
||||
virtual Type type() const { return this->get_override("type")(); }
|
||||
@@ -155,5 +173,35 @@ struct IGameInfoWrapper: MOBase::IGameInfo, boost::python::wrapper<MOBase::IGame
|
||||
virtual QString binaryName() const { return this->get_override("binaryName")(); }
|
||||
};
|
||||
|
||||
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 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")(); }
|
||||
};
|
||||
|
||||
|
||||
struct IPluginListWrapper: MOBase::IPluginList, boost::python::wrapper<MOBase::IPluginList> {
|
||||
virtual PluginState 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); }
|
||||
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); }
|
||||
};
|
||||
|
||||
|
||||
struct IModListWrapper: MOBase::IModList, boost::python::wrapper<MOBase::IModList> {
|
||||
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); }
|
||||
};
|
||||
|
||||
#endif // UIBASEWRAPPERS_H
|
||||
|
||||
Reference in New Issue
Block a user