Repository navigation
Expand file tree
/
Copy pathUEPyIPlugin.cpp
More file actions
331 lines (278 loc) · 10 KB
/
Copy pathUEPyIPlugin.cpp
File metadata and controls
331 lines (278 loc) · 10 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
#include "UEPyIPlugin.h"
#if WITH_EDITOR
#include "Runtime/Projects/Public/Interfaces/IPluginManager.h"
static PyObject *py_ue_iplugin_get_name(ue_PyIPlugin *self, PyObject * args)
{
return PyUnicode_FromString(TCHAR_TO_UTF8(*(self->plugin->GetName())));
}
static PyObject *py_ue_iplugin_get_base_dir(ue_PyIPlugin *self, PyObject * args)
{
return PyUnicode_FromString(TCHAR_TO_UTF8(*(self->plugin->GetBaseDir())));
}
static PyObject *py_ue_iplugin_get_content_dir(ue_PyIPlugin *self, PyObject * args)
{
return PyUnicode_FromString(TCHAR_TO_UTF8(*(self->plugin->GetContentDir())));
}
static PyObject *py_ue_iplugin_get_descriptor_file_name(ue_PyIPlugin *self, PyObject * args)
{
return PyUnicode_FromString(TCHAR_TO_UTF8(*(self->plugin->GetDescriptorFileName())));
}
static PyObject *py_ue_iplugin_get_mounted_asset_path(ue_PyIPlugin *self, PyObject * args)
{
return PyUnicode_FromString(TCHAR_TO_UTF8(*(self->plugin->GetMountedAssetPath())));
}
static PyObject *py_ue_iplugin_can_contain_content(ue_PyIPlugin *self, PyObject * args)
{
if (self->plugin->CanContainContent())
{
Py_INCREF(Py_True);
return Py_True;
}
Py_INCREF(Py_False);
return Py_False;
}
static PyObject *py_ue_iplugin_is_enabled(ue_PyIPlugin *self, PyObject * args)
{
if (self->plugin->IsEnabled())
{
Py_INCREF(Py_True);
return Py_True;
}
Py_INCREF(Py_False);
return Py_False;
}
static PyObject *py_ue_iplugin_to_json(ue_PyIPlugin *self, PyObject * args)
{
PyObject *py_bool;
if (!PyArg_ParseTuple(args, "O:to_json", &py_bool))
{
return NULL;
}
bool enabled_by_default = false;
if (PyObject_IsTrue(py_bool))
{
enabled_by_default = true;
}
FPluginDescriptor descriptor = self->plugin->GetDescriptor();
FString text;
#if ENGINE_MINOR_VERSION < 14
text = descriptor.ToString();
#elif ENGINE_MINOR_VERSION <= 17
descriptor.Write(text, enabled_by_default);
#else
descriptor.Write(text);
#endif
return PyUnicode_FromString(TCHAR_TO_UTF8(*text));
}
static PyObject *py_ue_iplugin_from_json(ue_PyIPlugin *self, PyObject * args)
{
char *json;
PyObject *py_bool;
if (!PyArg_ParseTuple(args, "sO:from_json", &json, &py_bool))
{
return NULL;
}
bool enabled_by_default = false;
if (PyObject_IsTrue(py_bool))
{
enabled_by_default = true;
}
FText error;
FString text = FString(UTF8_TO_TCHAR(json));
FPluginDescriptor descriptor = self->plugin->GetDescriptor();
#if ENGINE_MINOR_VERSION < 14
if (!descriptor.Read(text, error))
#elif ENGINE_MINOR_VERSION <= 17
if (!descriptor.Read(text, enabled_by_default, error))
#else
if (!descriptor.Read(text, error))
#endif
{
return PyErr_Format(PyExc_Exception, "unable to update descriptor from json");
}
Py_INCREF(Py_None);
return Py_None;
}
static PyMethodDef ue_PyIPlugin_methods[] = {
{ "get_name", (PyCFunction)py_ue_iplugin_get_name, METH_VARARGS, "" },
{ "get_base_dir", (PyCFunction)py_ue_iplugin_get_base_dir, METH_VARARGS, "" },
{ "get_content_dir", (PyCFunction)py_ue_iplugin_get_content_dir, METH_VARARGS, "" },
{ "get_descriptor_file_name", (PyCFunction)py_ue_iplugin_get_descriptor_file_name, METH_VARARGS, "" },
{ "get_mounted_asset_path", (PyCFunction)py_ue_iplugin_get_mounted_asset_path, METH_VARARGS, "" },
{ "can_contain_content", (PyCFunction)py_ue_iplugin_can_contain_content, METH_VARARGS, "" },
{ "is_enabled", (PyCFunction)py_ue_iplugin_is_enabled, METH_VARARGS, "" },
{ "to_json", (PyCFunction)py_ue_iplugin_to_json, METH_VARARGS, "" },
{ "from_json", (PyCFunction)py_ue_iplugin_from_json, METH_VARARGS, "" },
{ NULL } /* Sentinel */
};
static PyObject *py_ue_iplugin_get_category(ue_PyIPlugin *self, void *closure)
{
return PyUnicode_FromString(TCHAR_TO_UTF8(*(self->plugin->GetDescriptor().Category)));
}
static PyObject *py_ue_iplugin_get_can_contain_content(ue_PyIPlugin *self, void *closure)
{
if (self->plugin->GetDescriptor().bCanContainContent)
{
Py_INCREF(Py_True);
return Py_True;
}
Py_INCREF(Py_False);
return Py_False;
}
static PyObject *py_ue_iplugin_get_enabled_by_default(ue_PyIPlugin *self, void *closure)
{
#if ENGINE_MINOR_VERSION < 18
if (self->plugin->GetDescriptor().bEnabledByDefault)
#else
if (self->plugin->GetDescriptor().EnabledByDefault == EPluginEnabledByDefault::Enabled)
#endif
{
Py_INCREF(Py_True);
return Py_True;
}
Py_INCREF(Py_False);
return Py_False;
}
static PyObject *py_ue_iplugin_get_installed(ue_PyIPlugin *self, void *closure)
{
if (self->plugin->GetDescriptor().bInstalled)
{
Py_INCREF(Py_True);
return Py_True;
}
Py_INCREF(Py_False);
return Py_False;
}
static PyObject *py_ue_iplugin_get_is_beta_version(ue_PyIPlugin *self, void *closure)
{
if (self->plugin->GetDescriptor().bIsBetaVersion)
{
Py_INCREF(Py_True);
return Py_True;
}
Py_INCREF(Py_False);
return Py_False;
}
static PyObject *py_ue_iplugin_created_by(ue_PyIPlugin *self, void *closure)
{
return PyUnicode_FromString(TCHAR_TO_UTF8(*(self->plugin->GetDescriptor().CreatedBy)));
}
static PyObject *py_ue_iplugin_created_by_url(ue_PyIPlugin *self, void *closure)
{
return PyUnicode_FromString(TCHAR_TO_UTF8(*(self->plugin->GetDescriptor().CreatedByURL)));
}
static PyObject *py_ue_iplugin_description(ue_PyIPlugin *self, void *closure)
{
return PyUnicode_FromString(TCHAR_TO_UTF8(*(self->plugin->GetDescriptor().Description)));
}
static PyObject *py_ue_iplugin_docs_url(ue_PyIPlugin *self, void *closure)
{
return PyUnicode_FromString(TCHAR_TO_UTF8(*(self->plugin->GetDescriptor().DocsURL)));
}
static PyObject *py_ue_iplugin_friendly_name(ue_PyIPlugin *self, void *closure)
{
return PyUnicode_FromString(TCHAR_TO_UTF8(*(self->plugin->GetDescriptor().FriendlyName)));
}
static PyObject *py_ue_iplugin_marketplace_url(ue_PyIPlugin *self, void *closure)
{
return PyUnicode_FromString(TCHAR_TO_UTF8(*(self->plugin->GetDescriptor().MarketplaceURL)));
}
static PyObject *py_ue_iplugin_support_url(ue_PyIPlugin *self, void *closure)
{
return PyUnicode_FromString(TCHAR_TO_UTF8(*(self->plugin->GetDescriptor().SupportURL)));
}
static PyObject *py_ue_iplugin_version_name(ue_PyIPlugin *self, void *closure)
{
return PyUnicode_FromString(TCHAR_TO_UTF8(*(self->plugin->GetDescriptor().VersionName)));
}
static PyObject *py_ue_iplugin_file_version(ue_PyIPlugin *self, void *closure)
{
#if ENGINE_MINOR_VERSION < 18
return PyLong_FromLong(self->plugin->GetDescriptor().FileVersion);
#else
return PyLong_FromLong(self->plugin->GetDescriptor().Version);
#endif
}
static PyObject *py_ue_iplugin_version(ue_PyIPlugin *self, void *closure)
{
return PyLong_FromLong(self->plugin->GetDescriptor().Version);
}
static PyObject *py_ue_iplugin_get_requires_build_platform(ue_PyIPlugin *self, void *closure)
{
if (self->plugin->GetDescriptor().bRequiresBuildPlatform)
{
Py_RETURN_TRUE;
}
Py_RETURN_FALSE;
}
static PyGetSetDef ue_PyIPlugin_getseters[] = {
{ (char*)"category", (getter)py_ue_iplugin_get_category, NULL, (char *)"", NULL },
{ (char*)"can_contain_content", (getter)py_ue_iplugin_get_can_contain_content, NULL, (char *)"", NULL },
{ (char*)"enabled_by_default", (getter)py_ue_iplugin_get_enabled_by_default, NULL, (char *)"", NULL },
{ (char*)"installed", (getter)py_ue_iplugin_get_installed, NULL, (char *)"", NULL },
{ (char*)"is_beta_version", (getter)py_ue_iplugin_get_is_beta_version, NULL, (char *)"", NULL },
{ (char*)"requires_build_platform", (getter)py_ue_iplugin_get_requires_build_platform, NULL, (char *)"", NULL },
{ (char*)"created_by", (getter)py_ue_iplugin_created_by, NULL, (char *)"", NULL },
{ (char*)"created_by_url", (getter)py_ue_iplugin_created_by_url, NULL, (char *)"", NULL },
{ (char*)"description", (getter)py_ue_iplugin_description, NULL, (char *)"", NULL },
{ (char*)"docs_url", (getter)py_ue_iplugin_docs_url, NULL, (char *)"", NULL },
{ (char*)"file_version", (getter)py_ue_iplugin_file_version, NULL, (char *)"", NULL },
{ (char*)"friendly_name", (getter)py_ue_iplugin_friendly_name, NULL, (char *)"", NULL },
{ (char*)"marketplace_url", (getter)py_ue_iplugin_marketplace_url, NULL, (char *)"", NULL },
{ (char*)"support_url", (getter)py_ue_iplugin_support_url, NULL, (char *)"", NULL },
{ (char*)"version", (getter)py_ue_iplugin_version, NULL, (char *)"", NULL },
{ (char*)"version_name", (getter)py_ue_iplugin_version_name, NULL, (char *)"", NULL },
{ NULL } /* Sentinel */
};
static PyObject *ue_PyIPlugin_str(ue_PyIPlugin *self)
{
return PyUnicode_FromFormat("<unreal_engine.IPlugin {'name': '%s'}>",
TCHAR_TO_UTF8(*self->plugin->GetName()));
}
static PyTypeObject ue_PyIPluginType = {
PyVarObject_HEAD_INIT(NULL, 0)
"unreal_engine.IPlugin", /* tp_name */
sizeof(ue_PyIPlugin), /* tp_basicsize */
0, /* tp_itemsize */
0, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_reserved */
0, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash */
0, /* tp_call */
(reprfunc)ue_PyIPlugin_str, /* tp_str */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT, /* tp_flags */
"Unreal Engine Editor IPlugin", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
ue_PyIPlugin_methods, /* tp_methods */
0,
ue_PyIPlugin_getseters,
};
void ue_python_init_iplugin(PyObject *ue_module)
{
ue_PyIPluginType.tp_new = PyType_GenericNew;
if (PyType_Ready(&ue_PyIPluginType) < 0)
return;
Py_INCREF(&ue_PyIPluginType);
PyModule_AddObject(ue_module, "IPlugin", (PyObject *)&ue_PyIPluginType);
}
PyObject *py_ue_new_iplugin(IPlugin *plugin)
{
ue_PyIPlugin *ret = (ue_PyIPlugin *)PyObject_New(ue_PyIPlugin, &ue_PyIPluginType);
ret->plugin = plugin;
return (PyObject *)ret;
}
#endif