mirror of
https://github.com/ModOrganizer2/modorganizer-plugin_python.git
synced 2026-07-27 14:03:33 -07:00
Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7deee938d3 | ||
|
|
5d51b2bcc6 | ||
|
|
0566a968e8 | ||
|
|
14fc674d72 | ||
|
|
b7cbdaad1e |
@@ -22,6 +22,9 @@ CONFIG(release, debug|release) {
|
|||||||
|
|
||||||
DEFINES += PROXYPYTHON_LIBRARY
|
DEFINES += PROXYPYTHON_LIBRARY
|
||||||
|
|
||||||
|
# suppress a few warnings caused by boost vs vc++ paranoia
|
||||||
|
DEFINES += _SCL_SECURE_NO_WARNINGS
|
||||||
|
|
||||||
SOURCES += proxypython.cpp
|
SOURCES += proxypython.cpp
|
||||||
HEADERS += proxypython.h \
|
HEADERS += proxypython.h \
|
||||||
resource.h
|
resource.h
|
||||||
@@ -35,15 +38,14 @@ RC_FILE += \
|
|||||||
|
|
||||||
include(../plugin_template.pri)
|
include(../plugin_template.pri)
|
||||||
|
|
||||||
INCLUDEPATH += "../../pythonRunner"
|
INCLUDEPATH += "../../pythonRunner" "$(BOOSTPATH)"
|
||||||
|
|
||||||
WINPWD = $$PWD
|
WINPWD = $$PWD
|
||||||
WINPWD ~= s,/,$$QMAKE_DIR_SEP,g
|
WINPWD ~= s,/,$$QMAKE_DIR_SEP,g
|
||||||
|
|
||||||
|
|
||||||
//QMAKE_POST_LINK += SET VS90COMNTOOLS=%VS100COMNTOOLS% $$escape_expand(\\n)
|
//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\\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\\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)
|
//QMAKE_POST_LINK += copy $$(PYTHONPATH)\\lib\\site-packages\\PyQt4\\QtGui.pyd $$quote($$DSTDIR)\\plugins\\data\\PyQt4\\ $$escape_expand(\\n)
|
||||||
|
|||||||
@@ -1,11 +1,24 @@
|
|||||||
#pragma warning( push )
|
/*
|
||||||
#pragma warning( disable : 4100 ) // a lot of unreferenced formal parameters from boost libraries
|
Copyright (C) 2013 Sebastian Herbord. All rights reserved.
|
||||||
#pragma warning( disable : 4996 ) // strncpy claimed to be unsafe
|
|
||||||
|
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"
|
#include "proxypython.h"
|
||||||
|
|
||||||
#pragma warning( pop )
|
|
||||||
|
|
||||||
#include <utility.h>
|
#include <utility.h>
|
||||||
#include <versioninfo.h>
|
#include <versioninfo.h>
|
||||||
#include <QtPlugin>
|
#include <QtPlugin>
|
||||||
@@ -34,8 +47,6 @@ HMODULE GetOwnModuleHandle()
|
|||||||
|
|
||||||
QString ExtractResource(WORD resourceID, const QString &szFilename)
|
QString ExtractResource(WORD resourceID, const QString &szFilename)
|
||||||
{
|
{
|
||||||
bool success = false;
|
|
||||||
|
|
||||||
HMODULE mod = GetOwnModuleHandle();
|
HMODULE mod = GetOwnModuleHandle();
|
||||||
|
|
||||||
HRSRC hResource = FindResourceW(mod, MAKEINTRESOURCE(resourceID), L"BINARY");
|
HRSRC hResource = FindResourceW(mod, MAKEINTRESOURCE(resourceID), L"BINARY");
|
||||||
|
|||||||
@@ -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
|
#ifndef PROXYPYTHON_H
|
||||||
#define PROXYPYTHON_H
|
#define PROXYPYTHON_H
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,9 @@ CONFIG += warn_on
|
|||||||
|
|
||||||
DEFINES += PYTHONRUNNER_LIBRARY
|
DEFINES += PYTHONRUNNER_LIBRARY
|
||||||
|
|
||||||
|
# suppress a few warnings caused by boost vs vc++ paranoia
|
||||||
|
DEFINES += _SCL_SECURE_NO_WARNINGS
|
||||||
|
|
||||||
SOURCES += pythonrunner.cpp \
|
SOURCES += pythonrunner.cpp \
|
||||||
gilock.cpp \
|
gilock.cpp \
|
||||||
error.cpp \
|
error.cpp \
|
||||||
@@ -31,6 +34,8 @@ CONFIG(debug, debug|release) {
|
|||||||
LIBS += -L$$OUT_PWD/../uibase/debug
|
LIBS += -L$$OUT_PWD/../uibase/debug
|
||||||
} else {
|
} else {
|
||||||
LIBS += -L$$OUT_PWD/../uibase/release
|
LIBS += -L$$OUT_PWD/../uibase/release
|
||||||
|
QMAKE_CXXFLAGS += /Zi
|
||||||
|
QMAKE_LFLAGS += /DEBUG
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+41
-19
@@ -11,6 +11,7 @@
|
|||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
#include <utility.h>
|
#include <utility.h>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
|
#include <QCoreApplication>
|
||||||
|
|
||||||
// sip and qt slots seems to conflict
|
// sip and qt slots seems to conflict
|
||||||
#include <sip.h>
|
#include <sip.h>
|
||||||
@@ -36,15 +37,15 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
void initPath(boost::python::object &moduleNamespace);
|
||||||
|
|
||||||
|
private:
|
||||||
std::map<QString, boost::python::object> m_PythonObjects;
|
std::map<QString, boost::python::object> m_PythonObjects;
|
||||||
const MOBase::IOrganizer *m_MOInfo;
|
const MOBase::IOrganizer *m_MOInfo;
|
||||||
char *m_PythonHome;
|
char *m_PythonHome;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
IPythonRunner *CreatePythonRunner(const MOBase::IOrganizer *moInfo, const QString &pythonDir)
|
IPythonRunner *CreatePythonRunner(const MOBase::IOrganizer *moInfo, const QString &pythonDir)
|
||||||
{
|
{
|
||||||
PythonRunner *result = new PythonRunner(moInfo);
|
PythonRunner *result = new PythonRunner(moInfo);
|
||||||
@@ -581,6 +582,7 @@ BOOST_PYTHON_MODULE(mobase)
|
|||||||
.def("pluginList", bpy::pure_virtual(&IOrganizer::pluginList), bpy::return_value_policy<bpy::reference_existing_object>())
|
.def("pluginList", bpy::pure_virtual(&IOrganizer::pluginList), bpy::return_value_policy<bpy::reference_existing_object>())
|
||||||
.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("onAboutToRun", bpy::pure_virtual(&IOrganizer::onAboutToRun))
|
.def("onAboutToRun", bpy::pure_virtual(&IOrganizer::onAboutToRun))
|
||||||
|
.def("refreshModList", bpy::pure_virtual(&IOrganizer::refreshModList))
|
||||||
;
|
;
|
||||||
|
|
||||||
bpy::class_<ModRepositoryBridgeWrapper, boost::noncopyable>("ModRepositoryBridge")
|
bpy::class_<ModRepositoryBridgeWrapper, boost::noncopyable>("ModRepositoryBridge")
|
||||||
@@ -636,6 +638,7 @@ PythonRunner::PythonRunner(const MOBase::IOrganizer *moInfo)
|
|||||||
|
|
||||||
static char* argv0 = "ModOrganizer.exe";
|
static char* argv0 = "ModOrganizer.exe";
|
||||||
|
|
||||||
|
|
||||||
bool PythonRunner::initPython(const QString &pythonPath)
|
bool PythonRunner::initPython(const QString &pythonPath)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
@@ -649,21 +652,25 @@ bool PythonRunner::initPython(const QString &pythonPath)
|
|||||||
|
|
||||||
Py_SetProgramName(argv0);
|
Py_SetProgramName(argv0);
|
||||||
PyImport_AppendInittab("mobase", &initmobase);
|
PyImport_AppendInittab("mobase", &initmobase);
|
||||||
|
Py_OptimizeFlag = 2;
|
||||||
|
Py_NoSiteFlag = 1;
|
||||||
Py_InitializeEx(0);
|
Py_InitializeEx(0);
|
||||||
|
|
||||||
if (!Py_IsInitialized()) {
|
if (!Py_IsInitialized()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
PySys_SetArgv(0, &argv0);
|
PySys_SetArgv(0, &argv0);
|
||||||
|
|
||||||
bpy::object main_module = bpy::import("__main__");
|
bpy::object mainModule = bpy::import("__main__");
|
||||||
bpy::object main_namespace = main_module.attr("__dict__");
|
bpy::object mainNamespace = mainModule.attr("__dict__");
|
||||||
main_namespace["cStringIO"] = bpy::import("cStringIO");
|
mainNamespace["sys"] = bpy::import("sys");
|
||||||
main_namespace["sys"] = bpy::import("sys");
|
initPath(mainNamespace);
|
||||||
|
bpy::import("site");
|
||||||
|
mainNamespace["cStringIO"] = bpy::import("cStringIO");
|
||||||
bpy::exec("s_ErrIO = cStringIO.StringIO()\n"
|
bpy::exec("s_ErrIO = cStringIO.StringIO()\n"
|
||||||
"sys.stderr = s_ErrIO",
|
"sys.stderr = s_ErrIO",
|
||||||
main_namespace);
|
mainNamespace);
|
||||||
return true;
|
return true;
|
||||||
} catch (const bpy::error_already_set&) {
|
} catch (const bpy::error_already_set&) {
|
||||||
qDebug("failed to init python");
|
qDebug("failed to init python");
|
||||||
@@ -693,26 +700,41 @@ bool handled_exec_file(bpy::str filename, bpy::object globals = bpy::object(), b
|
|||||||
} while (false)
|
} 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)
|
QObject *PythonRunner::instantiate(const QString &pluginName)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
GILock lock;
|
GILock lock;
|
||||||
bpy::object main_module = bpy::import("__main__");
|
bpy::object mainModule = bpy::import("__main__");
|
||||||
bpy::object main_namespace = main_module.attr("__dict__");
|
bpy::object moduleNamespace = mainModule.attr("__dict__");
|
||||||
|
|
||||||
bpy::object mobase_module((bpy::handle<>(PyImport_ImportModule("mobase"))));
|
bpy::object sys = bpy::import("sys");
|
||||||
main_namespace["sys"] = bpy::import("sys");
|
moduleNamespace["sys"] = sys;
|
||||||
main_namespace["mobase"] = mobase_module;
|
moduleNamespace["mobase"] = bpy::import("mobase");
|
||||||
QString appendDataPath = QString("sys.path.insert(0, \"%1\")").arg(m_MOInfo->pluginDataPath());
|
|
||||||
|
|
||||||
bpy::eval(appendDataPath.toUtf8().constData(), main_namespace);
|
|
||||||
|
|
||||||
std::string temp = ToString(pluginName);
|
std::string temp = ToString(pluginName);
|
||||||
if (handled_exec_file(temp.c_str(), main_namespace)) {
|
if (handled_exec_file(temp.c_str(), moduleNamespace)) {
|
||||||
reportPythonError();
|
reportPythonError();
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
m_PythonObjects[pluginName] = main_namespace["createPlugin"]();
|
m_PythonObjects[pluginName] = moduleNamespace["createPlugin"]();
|
||||||
|
|
||||||
bpy::object pluginObj = m_PythonObjects[pluginName];
|
bpy::object pluginObj = m_PythonObjects[pluginName];
|
||||||
TRY_PLUGIN_TYPE(IPluginInstallerCustom, pluginObj);
|
TRY_PLUGIN_TYPE(IPluginInstallerCustom, pluginObj);
|
||||||
|
|||||||
@@ -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
|
|
||||||
@@ -136,12 +136,14 @@ struct IOrganizerWrapper: MOBase::IOrganizer, boost::python::wrapper<MOBase::IOr
|
|||||||
virtual void installMod(const QString &fileName) { this->get_override("installMod")(fileName); }
|
virtual void installMod(const QString &fileName) { this->get_override("installMod")(fileName); }
|
||||||
virtual MOBase::IDownloadManager *downloadManager() { return this->get_override("downloadManager")(); }
|
virtual MOBase::IDownloadManager *downloadManager() { return this->get_override("downloadManager")(); }
|
||||||
virtual MOBase::IPluginList *pluginList() { return this->get_override("pluginList")(); }
|
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 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 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 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 void refreshModList(bool saveChanges = true) { this->get_override("refreshModList")(saveChanges); }
|
||||||
};
|
};
|
||||||
|
|
||||||
struct IDownloadManagerWrapper: MOBase::IDownloadManager, boost::python::wrapper<MOBase::IDownloadManager>
|
struct IDownloadManagerWrapper: MOBase::IDownloadManager, boost::python::wrapper<MOBase::IDownloadManager>
|
||||||
|
|||||||
Reference in New Issue
Block a user