mirror of
https://github.com/ModOrganizer2/modorganizer-plugin_python.git
synced 2026-07-27 14:03:33 -07:00
Merge pull request #4 from ThosRTanner/issue/356
Refactor gameinfo & 'shared' library to use game plugins (7 of 17)
This commit is contained in:
@@ -2,7 +2,7 @@ Import('qt_env')
|
||||
|
||||
env = qt_env.Clone()
|
||||
|
||||
env.EnableQtModules('Core', 'Gui')
|
||||
env.EnableQtModules('Core', 'Gui', 'Widgets')
|
||||
|
||||
env.AppendUnique(CPPDEFINES = 'PYTHONRUNNER_LIBRARY')
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <utility.h>
|
||||
#include "error.h"
|
||||
#include "gilock.h"
|
||||
#include <QWidget>
|
||||
|
||||
namespace bpy = boost::python;
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ TEMPLATE = lib
|
||||
|
||||
CONFIG += dll
|
||||
CONFIG += warn_on
|
||||
QT += widgets
|
||||
|
||||
DEFINES += PYTHONRUNNER_LIBRARY
|
||||
|
||||
@@ -61,4 +62,5 @@ QMAKE_POST_LINK += xcopy /y /s /i $$quote($$SRCDIR\\$${TARGET}*.dll) $$quote($$D
|
||||
QMAKE_POST_LINK += xcopy /y /I $$quote($$SRCDIR\\$${TARGET}*.pdb) $$quote($$DSTDIR)\\plugins $$escape_expand(\\n)
|
||||
|
||||
OTHER_FILES += \
|
||||
SConscript
|
||||
SConscript\
|
||||
CMakeLists.txt
|
||||
|
||||
+64
-19
@@ -3,14 +3,17 @@
|
||||
#pragma warning( disable : 4100 )
|
||||
#pragma warning( disable : 4996 )
|
||||
|
||||
#include "iplugingame.h"
|
||||
#include <iplugininstaller.h>
|
||||
#include "uibasewrappers.h"
|
||||
#include "pythonpluginwrapper.h"
|
||||
#include "proxypluginwrappers.h"
|
||||
|
||||
#include <Windows.h>
|
||||
#include <utility.h>
|
||||
#include <QFile>
|
||||
#include <QCoreApplication>
|
||||
#include <QWidget>
|
||||
|
||||
// sip and qt slots seems to conflict
|
||||
#include <sip.h>
|
||||
@@ -242,7 +245,9 @@ struct QVariant_from_python_obj
|
||||
} else if (PyBool_Check(objPtr)) {
|
||||
result = (objPtr == Py_True);
|
||||
} else if (PyInt_Check(objPtr)) {
|
||||
result = PyInt_AsLong(objPtr);
|
||||
//QVariant doesn't have long. It has int or long long. Given that on m/s,
|
||||
//long is 32 bits for 32- and 64- bit code...
|
||||
result = static_cast<int>(PyInt_AsLong(objPtr));
|
||||
} else {
|
||||
PyErr_SetString(PyExc_TypeError, "type unsupported");
|
||||
throw bpy::error_already_set();
|
||||
@@ -266,7 +271,9 @@ struct QVariant_from_python_obj
|
||||
bool value = (objPtr == Py_True);
|
||||
constructVariant(value, data);
|
||||
} else if (PyInt_Check(objPtr)) {
|
||||
long value = PyInt_AsLong(objPtr);
|
||||
//QVariant doesn't have long. It has int or long long. Given that on m/s,
|
||||
//long is 32 bits for 32- and 64- bit code...
|
||||
int value = static_cast<int>(PyInt_AsLong(objPtr));
|
||||
constructVariant(value, data);
|
||||
} else {
|
||||
PyErr_SetString(PyExc_TypeError, "type unsupported");
|
||||
@@ -680,14 +687,6 @@ BOOST_PYTHON_MODULE(mobase)
|
||||
.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("fallout4", MOBase::IGameInfo::TYPE_FALLOUT4)
|
||||
.value("falloutnv", MOBase::IGameInfo::TYPE_FALLOUTNV)
|
||||
.value("skyrim", MOBase::IGameInfo::TYPE_SKYRIM)
|
||||
;
|
||||
|
||||
bpy::class_<VersionInfo>("VersionInfo")
|
||||
.def(bpy::init<QString>())
|
||||
.def(bpy::init<QString, VersionInfo::VersionScheme>())
|
||||
@@ -699,14 +698,7 @@ BOOST_PYTHON_MODULE(mobase)
|
||||
|
||||
bpy::class_<PluginSetting>("PluginSetting", bpy::init<const QString&, const QString&, const QVariant&>());
|
||||
|
||||
bpy::class_<IGameInfoWrapper, boost::noncopyable>("GameInfo")
|
||||
.def("type", bpy::pure_virtual(&IGameInfo::type))
|
||||
.def("path", bpy::pure_virtual(&IGameInfo::path))
|
||||
.def("binaryName", bpy::pure_virtual(&IGameInfo::binaryName))
|
||||
;
|
||||
|
||||
bpy::class_<IOrganizerWrapper, boost::noncopyable>("IOrganizer")
|
||||
.def("gameInfo", bpy::pure_virtual(&IOrganizer::gameInfo), bpy::return_value_policy<bpy::reference_existing_object>())
|
||||
.def("createNexusBridge", bpy::pure_virtual(&IOrganizer::createNexusBridge), bpy::return_value_policy<bpy::reference_existing_object>())
|
||||
.def("profileName", bpy::pure_virtual(&IOrganizer::profileName))
|
||||
.def("profilePath", bpy::pure_virtual(&IOrganizer::profilePath))
|
||||
@@ -731,6 +723,7 @@ BOOST_PYTHON_MODULE(mobase)
|
||||
.def("onFinishedRun", bpy::pure_virtual(&IOrganizer::onFinishedRun))
|
||||
.def("onModInstalled", bpy::pure_virtual(&IOrganizer::onModInstalled))
|
||||
.def("refreshModList", bpy::pure_virtual(&IOrganizer::refreshModList))
|
||||
.def("managedGame", bpy::pure_virtual(&IOrganizer::managedGame), bpy::return_value_policy<bpy::reference_existing_object>())
|
||||
;
|
||||
|
||||
bpy::class_<ModRepositoryBridgeWrapper, boost::noncopyable>("ModRepositoryBridge")
|
||||
@@ -756,7 +749,8 @@ BOOST_PYTHON_MODULE(mobase)
|
||||
|
||||
bpy::class_<IDownloadManagerWrapper, boost::noncopyable>("IDownloadManager")
|
||||
.def("startDownloadURLs", bpy::pure_virtual(&IDownloadManager::startDownloadURLs))
|
||||
.def("startDownloadNexusFile", bpy::pure_virtual(&IDownloadManager::startDownloadNexusFile))
|
||||
//not used?
|
||||
//.def("startDownloadNexusFile", bpy::pure_virtual(&IDownloadManager::startDownloadNexusFile))
|
||||
.def("downloadPath", bpy::pure_virtual(&IDownloadManager::downloadPath))
|
||||
;
|
||||
|
||||
@@ -805,6 +799,7 @@ BOOST_PYTHON_MODULE(mobase)
|
||||
;
|
||||
|
||||
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))
|
||||
@@ -818,6 +813,7 @@ BOOST_PYTHON_MODULE(mobase)
|
||||
|
||||
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("displayName", bpy::pure_virtual(&MOBase::IModList::displayName))
|
||||
.def("allMods", bpy::pure_virtual(&MOBase::IModList::allMods))
|
||||
@@ -829,6 +825,55 @@ BOOST_PYTHON_MODULE(mobase)
|
||||
.def("onModMoved", bpy::pure_virtual(&MOBase::IModList::onModMoved))
|
||||
;
|
||||
|
||||
bpy::enum_<MOBase::IPluginGame::LoadOrderMechanism>("LoadOrderMechanism")
|
||||
.value("FileTime", MOBase::IPluginGame::LoadOrderMechanism::FileTime)
|
||||
.value("PluginsTxt", MOBase::IPluginGame::LoadOrderMechanism::PluginsTxt)
|
||||
;
|
||||
|
||||
bpy::enum_<MOBase::IPluginGame::ProfileSetting>("ProfileSetting")
|
||||
.value("mods", MOBase::IPluginGame::MODS)
|
||||
.value("configuration", MOBase::IPluginGame::CONFIGURATION)
|
||||
.value("savegames", MOBase::IPluginGame::SAVEGAMES)
|
||||
.value("preferDefaults", MOBase::IPluginGame::PREFER_DEFAULTS)
|
||||
;
|
||||
|
||||
|
||||
bpy::class_<IPluginGameWrapper, boost::noncopyable>("IPluginGame")
|
||||
.def("gameName", bpy::pure_virtual(&MOBase::IPluginGame::gameName))
|
||||
.def("initializeProfile", bpy::pure_virtual(&MOBase::IPluginGame::initializeProfile))
|
||||
.def("savegameExtension", bpy::pure_virtual(&MOBase::IPluginGame::savegameExtension))
|
||||
.def("isInstalled", bpy::pure_virtual(&MOBase::IPluginGame::isInstalled))
|
||||
.def("gameIcon", bpy::pure_virtual(&MOBase::IPluginGame::gameIcon))
|
||||
.def("gameDirectory", bpy::pure_virtual(&MOBase::IPluginGame::gameDirectory))
|
||||
.def("dataDirectory", bpy::pure_virtual(&MOBase::IPluginGame::dataDirectory))
|
||||
.def("setGamePath", bpy::pure_virtual(&MOBase::IPluginGame::setGamePath))
|
||||
.def("documentsDirectory", bpy::pure_virtual(&MOBase::IPluginGame::documentsDirectory))
|
||||
.def("savesDirectory", bpy::pure_virtual(&MOBase::IPluginGame::savesDirectory))
|
||||
.def("executables", bpy::pure_virtual(&MOBase::IPluginGame::executables))
|
||||
.def("steamAPPId", bpy::pure_virtual(&MOBase::IPluginGame::steamAPPId))
|
||||
.def("getPrimaryPlugins", bpy::pure_virtual(&MOBase::IPluginGame::getPrimaryPlugins))
|
||||
.def("gameVariants", bpy::pure_virtual(&MOBase::IPluginGame::gameVariants))
|
||||
.def("setGameVariant", bpy::pure_virtual(&MOBase::IPluginGame::setGameVariant))
|
||||
.def("getBinaryName", bpy::pure_virtual(&MOBase::IPluginGame::getBinaryName))
|
||||
.def("getGameShortName", bpy::pure_virtual(&MOBase::IPluginGame::getGameShortName))
|
||||
.def("getIniFiles", bpy::pure_virtual(&MOBase::IPluginGame::getIniFiles))
|
||||
.def("getDLCPlugins", bpy::pure_virtual(&MOBase::IPluginGame::getDLCPlugins))
|
||||
.def("getLoadOrderMechanism", bpy::pure_virtual(&MOBase::IPluginGame::getLoadOrderMechanism))
|
||||
.def("getNexusModOrganizerID", bpy::pure_virtual(&MOBase::IPluginGame::getNexusModOrganizerID))
|
||||
.def("getNexusGameID", bpy::pure_virtual(&MOBase::IPluginGame::getNexusGameID))
|
||||
.def("looksValid", bpy::pure_virtual(&MOBase::IPluginGame::looksValid))
|
||||
|
||||
//Plugin interface.
|
||||
.def("init", bpy::pure_virtual(&MOBase::IPluginGame::init))
|
||||
.def("name", bpy::pure_virtual(&MOBase::IPluginGame::name))
|
||||
.def("author", bpy::pure_virtual(&MOBase::IPluginGame::author))
|
||||
.def("description", bpy::pure_virtual(&MOBase::IPluginGame::description))
|
||||
.def("version", bpy::pure_virtual(&MOBase::IPluginGame::version))
|
||||
.def("isActive", bpy::pure_virtual(&MOBase::IPluginGame::isActive))
|
||||
.def("settings", bpy::pure_virtual(&MOBase::IPluginGame::settings))
|
||||
|
||||
;
|
||||
|
||||
GuessedValue_converters<QString>();
|
||||
|
||||
bpy::to_python_converter<ModRepositoryFileInfo, ModRepositoryFileInfo_to_python_dict>();
|
||||
@@ -906,7 +951,7 @@ bool handled_exec_file(bpy::str filename, bpy::object globals = bpy::object(), b
|
||||
|
||||
|
||||
#define TRY_PLUGIN_TYPE(type, var) do { \
|
||||
bpy::extract<type ## *> extr(var); \
|
||||
bpy::extract<type *> extr(var); \
|
||||
if (extr.check()) { \
|
||||
QObject *res = extr; \
|
||||
return res; \
|
||||
|
||||
+53
-19
@@ -8,10 +8,12 @@
|
||||
#pragma warning (pop)
|
||||
#endif
|
||||
|
||||
#include <QIcon>
|
||||
#include <QString>
|
||||
#include <QUrl>
|
||||
|
||||
#include "iplugingame.h"
|
||||
#include <imoinfo.h>
|
||||
#include <igameinfo.h>
|
||||
#include <imodrepositorybridge.h>
|
||||
#include <imodinterface.h>
|
||||
#include <iinstallationmanager.h>
|
||||
@@ -21,8 +23,6 @@
|
||||
#include "error.h"
|
||||
#include "gilock.h"
|
||||
|
||||
|
||||
|
||||
extern MOBase::IOrganizer *s_Organizer;
|
||||
|
||||
using MOBase::ModRepositoryFileInfo;
|
||||
@@ -198,17 +198,13 @@ private:
|
||||
|
||||
struct IOrganizerWrapper: MOBase::IOrganizer, boost::python::wrapper<MOBase::IOrganizer>
|
||||
{
|
||||
virtual MOBase::IGameInfo &gameInfo() const {
|
||||
MOBase::IGameInfo *result = this->get_override("gameInfo")();
|
||||
return *result;
|
||||
}
|
||||
virtual MOBase::IModRepositoryBridge *createNexusBridge() const { return this->get_override("createNexusBridge")(); }
|
||||
virtual QString profileName() const { return this->get_override("profileName")(); }
|
||||
virtual QString profilePath() const { return this->get_override("profilePath")(); }
|
||||
virtual QString downloadsPath() const { return this->get_override("downloadsPath")(); }
|
||||
virtual QString overwritePath() const { return this->get_override("overwritePath")(); }
|
||||
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 *getMod(const QString &name) const { return this->get_override("getMod")(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); }
|
||||
@@ -218,9 +214,9 @@ struct IOrganizerWrapper: MOBase::IOrganizer, boost::python::wrapper<MOBase::IOr
|
||||
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, 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 MOBase::IDownloadManager *downloadManager() const { return this->get_override("downloadManager")(); }
|
||||
virtual MOBase::IPluginList *pluginList() const { return this->get_override("pluginList")(); }
|
||||
virtual MOBase::IModList *modList() const { 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); }
|
||||
@@ -232,12 +228,14 @@ struct IOrganizerWrapper: MOBase::IOrganizer, boost::python::wrapper<MOBase::IOr
|
||||
virtual bool onAboutToRun(const std::function<bool(const QString&)> &func) { return this->get_override("onAboutToRun")(func); }
|
||||
virtual bool onFinishedRun(const std::function<void(const QString&, unsigned int)> &func) { return this->get_override("onFinishedRun")(func); }
|
||||
virtual bool onModInstalled(const std::function<void(const QString&)> &func) { return this->get_override("onModInstalled")(func); }
|
||||
virtual MOBase::IPluginGame const *managedGame() const { return this->get_override("managedGame")(); }
|
||||
};
|
||||
|
||||
struct IDownloadManagerWrapper: MOBase::IDownloadManager, boost::python::wrapper<MOBase::IDownloadManager>
|
||||
{
|
||||
virtual int startDownloadURLs(const QStringList &urls) { return this->get_override("downloadURLs")(urls); }
|
||||
virtual int startDownloadNexusFile(int modID, int fileID) { return this->get_override("downloadNexusFile")(modID, fileID); }
|
||||
//not used
|
||||
//virtual int startDownloadNexusFile(int modID, int fileID) { return this->get_override("downloadNexusFile")(modID, fileID); }
|
||||
virtual QString downloadPath(int id) { return this->get_override("downloadPath")(id); }
|
||||
};
|
||||
|
||||
@@ -257,13 +255,6 @@ struct IInstallationManagerWrapper: MOBase::IInstallationManager, boost::python:
|
||||
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")(); }
|
||||
virtual QString path() const { return this->get_override("path")(); }
|
||||
virtual QString binaryName() const { return this->get_override("binaryName")(); }
|
||||
};
|
||||
|
||||
struct IModInterfaceWrapper: MOBase::IModInterface, boost::python::wrapper<MOBase::IModInterface>
|
||||
{
|
||||
virtual QString name() const override { return this->get_override("name")(); }
|
||||
@@ -306,4 +297,47 @@ struct IModListWrapper: MOBase::IModList, boost::python::wrapper<MOBase::IModLis
|
||||
virtual bool onModMoved(const std::function<void (const QString &, int, int)> &func) override { return this->get_override("onModMoved")(func); }
|
||||
};
|
||||
|
||||
|
||||
struct IPluginGameWrapper: MOBase::IPluginGame, boost::python::wrapper<MOBase::IPluginGame> {
|
||||
virtual QString gameName() const override { return this->get_override("gameName")(); }
|
||||
virtual void initializeProfile(const QDir &directory, ProfileSettings settings) const override {
|
||||
this->get_override("initializeProfile")(directory, settings);
|
||||
}
|
||||
virtual QString savegameExtension() const override { return this->get_override("savegameExtension")(); }
|
||||
virtual bool isInstalled() const override { return this->get_override("isInstalled")(); }
|
||||
virtual QIcon gameIcon() const override { return this->get_override("gameIcon")(); }
|
||||
virtual QDir gameDirectory() const override { return this->get_override("gameDirectory")(); }
|
||||
virtual QDir dataDirectory() const override { return this->get_override("dataDirectory")(); }
|
||||
virtual void setGamePath(const QString &path) override { this->get_override("setGamePath")(path); }
|
||||
virtual QDir documentsDirectory() const override { return this->get_override("documentsDirectory")(); }
|
||||
virtual QDir savesDirectory() const override { return this->get_override("savesDirectory")(); }
|
||||
virtual QList<MOBase::ExecutableInfo> executables() const override { return this->get_override("executables")(); }
|
||||
virtual QString steamAPPId() const override { return this->get_override("steamAPPId")(); }
|
||||
virtual QStringList getPrimaryPlugins() const override { return this->get_override("getPrimaryPlugins")(); }
|
||||
virtual QStringList gameVariants() const override { return this->get_override("gameVariants")(); }
|
||||
virtual void setGameVariant(const QString &variant) override { this->get_override("setGameVariant")(variant); }
|
||||
virtual QString getBinaryName() const override { return this->get_override("getBinaryName")(); }
|
||||
virtual QString getGameShortName() const override { return this->get_override("getGameShortName")(); }
|
||||
virtual QStringList getIniFiles() const override { return this->get_override("getIniFiles")(); }
|
||||
virtual QStringList getDLCPlugins() const override { return this->get_override("getDLCPlugins")(); }
|
||||
virtual LoadOrderMechanism getLoadOrderMechanism() const override { return this->get_override("getLoadorderMechanism")(); }
|
||||
virtual int getNexusModOrganizerID() const override { return this->get_override("getNexusModOrganizerID")(); }
|
||||
virtual int getNexusGameID() const override { return this->get_override("getNexusGameID")(); }
|
||||
virtual bool looksValid(QDir const &dir) const override { return this->get_override("looksValid")(dir); }
|
||||
|
||||
//Plugin interface. Could this bit be implemented just once?
|
||||
virtual bool init(MOBase::IOrganizer *moInfo) override { return this->get_override("init")(moInfo); }
|
||||
virtual QString name() const override { return this->get_override("name")(); }
|
||||
virtual QString author() const override { return this->get_override("author")(); }
|
||||
virtual QString description() const override { return this->get_override("description")(); }
|
||||
virtual MOBase::VersionInfo version() const override { return this->get_override("version")(); }
|
||||
virtual bool isActive() const override { return this->get_override("isActive")(); }
|
||||
virtual QList<MOBase::PluginSetting> settings() const override { return this->get_override("settings")(); }
|
||||
|
||||
protected:
|
||||
|
||||
virtual std::map<std::type_index, boost::any> featureList() const override { return this->get_override("featureList")(); }
|
||||
|
||||
};
|
||||
|
||||
#endif // UIBASEWRAPPERS_H
|
||||
|
||||
Reference in New Issue
Block a user