mirror of
https://github.com/ModOrganizer2/modorganizer-plugin_python.git
synced 2026-07-27 14:03:33 -07:00
- install plugins now get a chance to update name, version and modid of mods
- NCC now makes name, version and modid from the info.xml file available to the installer - integrated fomod installer also uses version and modid from the info.xml - mods can now be renamed during installation - configurator plugin now highlights changed keys and saves changes
This commit is contained in:
@@ -10,6 +10,7 @@ TEMPLATE = lib
|
||||
|
||||
CONFIG += plugins
|
||||
CONFIG += dll
|
||||
CONFIG += warn_on
|
||||
|
||||
DEFINES += PROXYPYTHON_LIBRARY
|
||||
|
||||
|
||||
@@ -1,27 +1,13 @@
|
||||
#include "proxypluginwrappers.h"
|
||||
#include <boost/python.hpp>
|
||||
#include <utility.h>
|
||||
#include "error.h"
|
||||
#include "gilock.h"
|
||||
|
||||
namespace bpy = boost::python;
|
||||
|
||||
using namespace MOBase;
|
||||
|
||||
static void reportPythonError()
|
||||
{
|
||||
if (PyErr_Occurred()) {
|
||||
// prints to s_ErrIO buffer
|
||||
PyErr_Print();
|
||||
// extract data from python buffer
|
||||
bpy::object mainModule = bpy::import("__main__");
|
||||
bpy::object mainNamespace = mainModule.attr("__dict__");
|
||||
bpy::object errMsgObj = bpy::eval("s_ErrIO.getvalue()", mainNamespace);
|
||||
QString errMsg = bpy::extract<QString>(errMsgObj.ptr());
|
||||
bpy::eval("s_ErrIO.truncate(0)", mainNamespace);
|
||||
throw MyException(errMsg);
|
||||
} else {
|
||||
throw MyException("An unexpected C++ exception was thrown in python code");
|
||||
}
|
||||
}
|
||||
|
||||
#define PYCATCH catch (const bpy::error_already_set &) { reportPythonError(); throw MyException("unhandled exception"); }\
|
||||
catch (...) { throw MyException("An unknown exception was thrown in python code"); }
|
||||
@@ -111,6 +97,8 @@ void IPluginToolWrapper::setParentWidget(QWidget *parent)
|
||||
void IPluginToolWrapper::display() const
|
||||
{
|
||||
try {
|
||||
GILock lock;
|
||||
|
||||
this->get_override("display")();
|
||||
} PYCATCH;
|
||||
}
|
||||
@@ -205,10 +193,11 @@ std::set<QString> IPluginInstallerCustomWrapper::supportedExtensions() const
|
||||
}
|
||||
|
||||
|
||||
IPluginInstaller::EInstallResult IPluginInstallerCustomWrapper::install(GuessedValue<QString> &modName, const QString &archiveName)
|
||||
IPluginInstaller::EInstallResult IPluginInstallerCustomWrapper::install(GuessedValue<QString> &modName, const QString &archiveName,
|
||||
const QString &version, int modID)
|
||||
{
|
||||
try {
|
||||
return this->get_override("install")(modName, archiveName);
|
||||
return this->get_override("install")(modName, archiveName, version, modID);
|
||||
} PYCATCH;
|
||||
}
|
||||
|
||||
|
||||
@@ -68,7 +68,8 @@ public:
|
||||
virtual bool isArchiveSupported(const MOBase::DirectoryTree &tree) const;
|
||||
virtual bool isArchiveSupported(const QString &archiveName) const;
|
||||
virtual std::set<QString> supportedExtensions() const;
|
||||
virtual EInstallResult install(MOBase::GuessedValue<QString> &modName, const QString &archiveName);
|
||||
virtual EInstallResult install(MOBase::GuessedValue<QString> &modName, const QString &archiveName,
|
||||
const QString &version, int modID);
|
||||
virtual void setParentWidget(QWidget *parent);
|
||||
|
||||
};
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
// sip and qt slots seems to conflict
|
||||
#include <sip.h>
|
||||
|
||||
|
||||
using namespace MOBase;
|
||||
namespace bpy = boost::python;
|
||||
|
||||
@@ -137,7 +136,6 @@ struct QVariant_to_python_obj
|
||||
case QVariant::Bool: return PyBool_FromLong(var.toBool());
|
||||
case QVariant::String: return bpy::incref(bpy::object(var.toString().toUtf8().constData()).ptr());
|
||||
case QVariant::List: {
|
||||
qDebug("to list convert");
|
||||
QVariantList list = var.toList();
|
||||
PyObject *result = PyList_New(list.count());
|
||||
foreach (QVariant var, list) {
|
||||
@@ -321,7 +319,6 @@ template <> struct MetaData<QObject> { static const char *className() { return "
|
||||
template <> struct MetaData<QWidget> { static const char *className() { return "QWidget"; } };
|
||||
template <> struct MetaData<QIcon> { static const char *className() { return "QIcon"; } };
|
||||
template <> struct MetaData<QVariant> { static const char *className() { return "QVariant"; } };
|
||||
//template <> struct MetaData<QList<MOBase::NexusFileInfo> > { static const char *className() { return "QList<NexusFileInfo>"; } };
|
||||
|
||||
|
||||
template <typename T>
|
||||
@@ -347,7 +344,6 @@ PyObject *toPyQt(T *objPtr)
|
||||
return bpy::incref(sipObj);
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
struct QClass_converters
|
||||
{
|
||||
@@ -402,7 +398,6 @@ struct QClass_converters
|
||||
sipSimpleWrapper *wrapper = reinterpret_cast<sipSimpleWrapper*>(objPtr);
|
||||
return wrapper->data;
|
||||
}
|
||||
|
||||
QClass_converters()
|
||||
{
|
||||
bpy::converter::registry::insert(&QClass_from_PyQt, bpy::type_id<T>());
|
||||
@@ -579,13 +574,6 @@ BOOST_PYTHON_MODULE(mobase)
|
||||
bpy::class_<IPluginInstallerCustomWrapper, boost::noncopyable>("IPluginInstallerCustom")
|
||||
.def("setParentWidget", bpy::pure_virtual(&MOBase::IPluginInstallerCustom::setParentWidget));
|
||||
|
||||
/* bpy::class_<MOBase::ModRepositoryFileInfo, boost::noncopyable>("ModRepositoryFileInfo")
|
||||
.def_readonly("name", &ModRepositoryFileInfo::name)
|
||||
.def_readonly("uri", &ModRepositoryFileInfo::uri)
|
||||
.def_readonly("version", &ModRepositoryFileInfo::version)
|
||||
.def_readonly("categoryID", &ModRepositoryFileInfo::categoryID);
|
||||
int fileID;*/
|
||||
|
||||
GuessedValue_converters<QString>();
|
||||
|
||||
bpy::to_python_converter<ModRepositoryFileInfo, ModRepositoryFileInfo_to_python_dict>();
|
||||
@@ -598,6 +586,8 @@ BOOST_PYTHON_MODULE(mobase)
|
||||
}
|
||||
|
||||
|
||||
static char* argv0 = "ModOrganizer.exe";
|
||||
|
||||
ProxyPython::ProxyPython()
|
||||
: m_MOInfo(NULL)
|
||||
{
|
||||
@@ -606,7 +596,6 @@ ProxyPython::ProxyPython()
|
||||
Py_Initialize();
|
||||
qDebug("Python: %s", Py_GetVersion());
|
||||
|
||||
static char* argv0 = "Banana?";
|
||||
PySys_SetArgv(0, &argv0);
|
||||
|
||||
bpy::object main_module = bpy::import("__main__");
|
||||
@@ -700,12 +689,12 @@ QObject *ProxyPython::instantiate(const QString &pluginName)
|
||||
bpy::object main_namespace = main_module.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.append(\"%1\")").arg(m_MOInfo->pluginDataPath());
|
||||
|
||||
bpy::eval(appendDataPath.toUtf8().constData(), main_namespace);
|
||||
|
||||
main_namespace["interfaces"] = bpy::import("interfaces");
|
||||
|
||||
std::string temp = ToString(pluginName);
|
||||
@@ -718,8 +707,6 @@ QObject *ProxyPython::instantiate(const QString &pluginName)
|
||||
bpy::object pluginObj = m_PythonObjects[pluginName];
|
||||
TRY_PLUGIN_TYPE(IPluginInstallerCustom, pluginObj);
|
||||
TRY_PLUGIN_TYPE(IPluginTool, pluginObj);
|
||||
} catch (const std::exception &e) {
|
||||
qWarning("failed to run python script \"%s\": %s", qPrintable(pluginName), e.what());
|
||||
} catch (const bpy::error_already_set&) {
|
||||
qWarning("failed to run python script \"%s\"", qPrintable(pluginName));
|
||||
reportPythonError();
|
||||
|
||||
@@ -131,7 +131,7 @@ struct IOrganizerWrapper: MOBase::IOrganizer, boost::python::wrapper<MOBase::IOr
|
||||
virtual QString downloadsPath() const { return this->get_override("downloadsPath")(); }
|
||||
virtual MOBase::VersionInfo appVersion() const { return this->get_override("appVersion")(); }
|
||||
virtual MOBase::IModInterface *getMod(const QString &name) { return this->get_override("getMod")(name); }
|
||||
virtual MOBase::IModInterface *createMod(const QString &name) { return this->get_override("createMod")(name); }
|
||||
virtual MOBase::IModInterface *createMod(MOBase::GuessedValue<QString> &name) { return this->get_override("createMod")(name); }
|
||||
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); }
|
||||
|
||||
Reference in New Issue
Block a user