Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/platform/android/export/godot_plugin_config.cpp
10278 views
1
/**************************************************************************/
2
/* godot_plugin_config.cpp */
3
/**************************************************************************/
4
/* This file is part of: */
5
/* GODOT ENGINE */
6
/* https://godotengine.org */
7
/**************************************************************************/
8
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10
/* */
11
/* Permission is hereby granted, free of charge, to any person obtaining */
12
/* a copy of this software and associated documentation files (the */
13
/* "Software"), to deal in the Software without restriction, including */
14
/* without limitation the rights to use, copy, modify, merge, publish, */
15
/* distribute, sublicense, and/or sell copies of the Software, and to */
16
/* permit persons to whom the Software is furnished to do so, subject to */
17
/* the following conditions: */
18
/* */
19
/* The above copyright notice and this permission notice shall be */
20
/* included in all copies or substantial portions of the Software. */
21
/* */
22
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29
/**************************************************************************/
30
31
#include "godot_plugin_config.h"
32
33
#ifndef DISABLE_DEPRECATED
34
35
/*
36
* Set of prebuilt plugins.
37
* Currently unused, this is just for future reference:
38
*/
39
// static const PluginConfigAndroid MY_PREBUILT_PLUGIN = {
40
// /*.valid_config =*/true,
41
// /*.last_updated =*/0,
42
// /*.name =*/"GodotPayment",
43
// /*.binary_type =*/"local",
44
// /*.binary =*/"res://android/build/libs/plugins/GodotPayment.release.aar",
45
// /*.local_dependencies =*/{},
46
// /*.remote_dependencies =*/String("com.android.billingclient:billing:2.2.1").split("|"),
47
// /*.custom_maven_repos =*/{}
48
// };
49
50
String PluginConfigAndroid::resolve_local_dependency_path(String plugin_config_dir, String dependency_path) {
51
String absolute_path;
52
if (!dependency_path.is_empty()) {
53
if (dependency_path.is_absolute_path()) {
54
absolute_path = ProjectSettings::get_singleton()->globalize_path(dependency_path);
55
} else {
56
absolute_path = plugin_config_dir.path_join(dependency_path);
57
}
58
}
59
60
return absolute_path;
61
}
62
63
PluginConfigAndroid PluginConfigAndroid::resolve_prebuilt_plugin(PluginConfigAndroid prebuilt_plugin, String plugin_config_dir) {
64
PluginConfigAndroid resolved = prebuilt_plugin;
65
resolved.binary = resolved.binary_type == PluginConfigAndroid::BINARY_TYPE_LOCAL ? resolve_local_dependency_path(plugin_config_dir, prebuilt_plugin.binary) : prebuilt_plugin.binary;
66
if (!prebuilt_plugin.local_dependencies.is_empty()) {
67
resolved.local_dependencies.clear();
68
for (int i = 0; i < prebuilt_plugin.local_dependencies.size(); i++) {
69
resolved.local_dependencies.push_back(resolve_local_dependency_path(plugin_config_dir, prebuilt_plugin.local_dependencies[i]));
70
}
71
}
72
return resolved;
73
}
74
75
Vector<PluginConfigAndroid> PluginConfigAndroid::get_prebuilt_plugins(String plugins_base_dir) {
76
Vector<PluginConfigAndroid> prebuilt_plugins;
77
return prebuilt_plugins;
78
}
79
80
bool PluginConfigAndroid::is_plugin_config_valid(PluginConfigAndroid plugin_config) {
81
bool valid_name = !plugin_config.name.is_empty();
82
bool valid_binary_type = plugin_config.binary_type == PluginConfigAndroid::BINARY_TYPE_LOCAL ||
83
plugin_config.binary_type == PluginConfigAndroid::BINARY_TYPE_REMOTE;
84
85
bool valid_binary = false;
86
if (valid_binary_type) {
87
valid_binary = !plugin_config.binary.is_empty() &&
88
(plugin_config.binary_type == PluginConfigAndroid::BINARY_TYPE_REMOTE ||
89
FileAccess::exists(plugin_config.binary));
90
}
91
92
bool valid_local_dependencies = true;
93
if (!plugin_config.local_dependencies.is_empty()) {
94
for (int i = 0; i < plugin_config.local_dependencies.size(); i++) {
95
if (!FileAccess::exists(plugin_config.local_dependencies[i])) {
96
valid_local_dependencies = false;
97
break;
98
}
99
}
100
}
101
return valid_name && valid_binary && valid_binary_type && valid_local_dependencies;
102
}
103
104
uint64_t PluginConfigAndroid::get_plugin_modification_time(const PluginConfigAndroid &plugin_config, const String &config_path) {
105
uint64_t last_updated = FileAccess::get_modified_time(config_path);
106
last_updated = MAX(last_updated, FileAccess::get_modified_time(plugin_config.binary));
107
108
for (int i = 0; i < plugin_config.local_dependencies.size(); i++) {
109
String binary = plugin_config.local_dependencies.get(i);
110
last_updated = MAX(last_updated, FileAccess::get_modified_time(binary));
111
}
112
113
return last_updated;
114
}
115
116
PluginConfigAndroid PluginConfigAndroid::load_plugin_config(Ref<ConfigFile> config_file, const String &path) {
117
PluginConfigAndroid plugin_config = {};
118
119
if (config_file.is_valid()) {
120
Error err = config_file->load(path);
121
if (err == OK) {
122
String config_base_dir = path.get_base_dir();
123
124
plugin_config.name = config_file->get_value(PluginConfigAndroid::CONFIG_SECTION, PluginConfigAndroid::CONFIG_NAME_KEY, String());
125
plugin_config.binary_type = config_file->get_value(PluginConfigAndroid::CONFIG_SECTION, PluginConfigAndroid::CONFIG_BINARY_TYPE_KEY, String());
126
127
String binary_path = config_file->get_value(PluginConfigAndroid::CONFIG_SECTION, PluginConfigAndroid::CONFIG_BINARY_KEY, String());
128
plugin_config.binary = plugin_config.binary_type == PluginConfigAndroid::BINARY_TYPE_LOCAL ? resolve_local_dependency_path(config_base_dir, binary_path) : binary_path;
129
130
if (config_file->has_section(PluginConfigAndroid::DEPENDENCIES_SECTION)) {
131
Vector<String> local_dependencies_paths = config_file->get_value(PluginConfigAndroid::DEPENDENCIES_SECTION, PluginConfigAndroid::DEPENDENCIES_LOCAL_KEY, Vector<String>());
132
if (!local_dependencies_paths.is_empty()) {
133
for (int i = 0; i < local_dependencies_paths.size(); i++) {
134
plugin_config.local_dependencies.push_back(resolve_local_dependency_path(config_base_dir, local_dependencies_paths[i]));
135
}
136
}
137
138
plugin_config.remote_dependencies = config_file->get_value(PluginConfigAndroid::DEPENDENCIES_SECTION, PluginConfigAndroid::DEPENDENCIES_REMOTE_KEY, Vector<String>());
139
plugin_config.custom_maven_repos = config_file->get_value(PluginConfigAndroid::DEPENDENCIES_SECTION, PluginConfigAndroid::DEPENDENCIES_CUSTOM_MAVEN_REPOS_KEY, Vector<String>());
140
}
141
142
plugin_config.valid_config = is_plugin_config_valid(plugin_config);
143
plugin_config.last_updated = get_plugin_modification_time(plugin_config, path);
144
}
145
}
146
147
return plugin_config;
148
}
149
150
void PluginConfigAndroid::get_plugins_binaries(String binary_type, Vector<PluginConfigAndroid> plugins_configs, Vector<String> &r_result) {
151
if (!plugins_configs.is_empty()) {
152
for (int i = 0; i < plugins_configs.size(); i++) {
153
PluginConfigAndroid config = plugins_configs[i];
154
if (!config.valid_config) {
155
continue;
156
}
157
158
if (config.binary_type == binary_type) {
159
r_result.push_back(config.binary);
160
}
161
162
if (binary_type == PluginConfigAndroid::BINARY_TYPE_LOCAL) {
163
r_result.append_array(config.local_dependencies);
164
}
165
166
if (binary_type == PluginConfigAndroid::BINARY_TYPE_REMOTE) {
167
r_result.append_array(config.remote_dependencies);
168
}
169
}
170
}
171
}
172
173
void PluginConfigAndroid::get_plugins_custom_maven_repos(Vector<PluginConfigAndroid> plugins_configs, Vector<String> &r_result) {
174
if (!plugins_configs.is_empty()) {
175
for (int i = 0; i < plugins_configs.size(); i++) {
176
PluginConfigAndroid config = plugins_configs[i];
177
if (!config.valid_config) {
178
continue;
179
}
180
181
r_result.append_array(config.custom_maven_repos);
182
}
183
}
184
}
185
186
void PluginConfigAndroid::get_plugins_names(Vector<PluginConfigAndroid> plugins_configs, Vector<String> &r_result) {
187
if (!plugins_configs.is_empty()) {
188
for (int i = 0; i < plugins_configs.size(); i++) {
189
PluginConfigAndroid config = plugins_configs[i];
190
if (!config.valid_config) {
191
continue;
192
}
193
194
r_result.push_back(config.name);
195
}
196
}
197
}
198
199
#endif // DISABLE_DEPRECATED
200
201