Repository navigation
Expand file tree
/
Copy pathUEPyAssetUserData.cpp
More file actions
92 lines (73 loc) · 2.89 KB
/
Copy pathUEPyAssetUserData.cpp
File metadata and controls
92 lines (73 loc) · 2.89 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
#include "UEPyAssetUserData.h"
#if WITH_EDITOR
PyObject *py_ue_asset_import_data(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
UStruct *u_struct = (UStruct *)self->ue_object->GetClass();
UClassProperty *u_property = (UClassProperty *)u_struct->FindPropertyByName(TEXT("AssetImportData"));
if (!u_property)
{
return PyErr_Format(PyExc_Exception, "UObject does not have asset import data.");
}
UAssetImportData *import_data = (UAssetImportData *)u_property->GetPropertyValue_InContainer(self->ue_object);
FAssetImportInfo *import_info = &import_data->SourceData;
PyObject *ret = PyList_New(import_info->SourceFiles.Num());
for (int i = 0; i < import_info->SourceFiles.Num(); i++)
{
PyObject *py_source_file = PyDict_New();
PyDict_SetItemString(py_source_file, "absolute_filepath", PyUnicode_FromString(TCHAR_TO_UTF8(*import_data->ResolveImportFilename(import_info->SourceFiles[i].RelativeFilename, NULL))));
PyDict_SetItemString(py_source_file, "relative_filepath", PyUnicode_FromString(TCHAR_TO_UTF8(*import_info->SourceFiles[i].RelativeFilename)));
PyDict_SetItemString(py_source_file, "timestamp", PyLong_FromLong(import_info->SourceFiles[i].Timestamp.ToUnixTimestamp()));
PyDict_SetItemString(py_source_file, "filehash", PyUnicode_FromString(TCHAR_TO_UTF8(*LexicalConversion::ToString(import_info->SourceFiles[i].FileHash))));
PyList_SetItem(ret, i, py_source_file);
}
return ret;
}
PyObject *py_ue_asset_import_data_set_sources(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
PyObject *py_files;
if (!PyArg_ParseTuple(args, "O:asset_import_data_set_sources", &py_files))
{
return nullptr;
}
TArray<FString> filenames;
UStruct *u_struct = (UStruct *)self->ue_object->GetClass();
UClassProperty *u_property = (UClassProperty *)u_struct->FindPropertyByName(TEXT("AssetImportData"));
if (!u_property)
{
return PyErr_Format(PyExc_Exception, "UObject does not have asset import data.");
}
if (PyUnicode_Check(py_files))
{
filenames.Add(FString(UTF8_TO_TCHAR(PyUnicode_AsUTF8(py_files))));
}
else
{
PyObject *py_iter = PyObject_GetIter(py_files);
if (!py_iter)
{
return PyErr_Format(PyExc_Exception, "argument is not a string or an interable of strings");
}
while (PyObject *py_item = PyIter_Next(py_iter))
{
if (!PyUnicode_Check(py_item))
{
Py_DECREF(py_iter);
return PyErr_Format(PyExc_Exception, "argument is not a string or an interable of strings");
}
filenames.Add(FString(UTF8_TO_TCHAR(PyUnicode_AsUTF8(py_item))));
}
Py_DECREF(py_iter);
}
UAssetImportData *import_data = (UAssetImportData *)u_property->GetPropertyValue_InContainer(self->ue_object);
FAssetImportInfo *import_info = &import_data->SourceData;
TArray<FAssetImportInfo::FSourceFile> sources;
for (FString filename : filenames)
{
sources.Add(FAssetImportInfo::FSourceFile(filename));
}
import_info->SourceFiles = sources;
Py_RETURN_NONE;
}
#endif