| 1 | /**************************************************************************/ |
| 2 | /* editor_export_platform_extension.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 "editor_export_platform_extension.h" |
| 32 | |
| 33 | #include "scene/resources/image_texture.h" |
| 34 | |
| 35 | void EditorExportPlatformExtension::_bind_methods() { |
| 36 | ClassDB::bind_method(D_METHOD("set_config_error", "error_text"), &EditorExportPlatformExtension::set_config_error); |
| 37 | ClassDB::bind_method(D_METHOD("get_config_error"), &EditorExportPlatformExtension::get_config_error); |
| 38 | |
| 39 | ClassDB::bind_method(D_METHOD("set_config_missing_templates", "missing_templates"), &EditorExportPlatformExtension::set_config_missing_templates); |
| 40 | ClassDB::bind_method(D_METHOD("get_config_missing_templates"), &EditorExportPlatformExtension::get_config_missing_templates); |
| 41 | |
| 42 | GDVIRTUAL_BIND(_get_preset_features, "preset"); |
| 43 | GDVIRTUAL_BIND(_is_executable, "path"); |
| 44 | GDVIRTUAL_BIND(_get_export_options); |
| 45 | GDVIRTUAL_BIND(_should_update_export_options); |
| 46 | GDVIRTUAL_BIND(_get_export_option_visibility, "preset", "option"); |
| 47 | GDVIRTUAL_BIND(_get_export_option_warning, "preset", "option"); |
| 48 | |
| 49 | GDVIRTUAL_BIND(_get_os_name); |
| 50 | GDVIRTUAL_BIND(_get_name); |
| 51 | GDVIRTUAL_BIND(_get_logo); |
| 52 | |
| 53 | GDVIRTUAL_BIND(_poll_export); |
| 54 | GDVIRTUAL_BIND(_get_options_count); |
| 55 | GDVIRTUAL_BIND(_get_options_tooltip); |
| 56 | |
| 57 | GDVIRTUAL_BIND(_get_option_icon, "device"); |
| 58 | #ifndef DISABLE_DEPRECATED |
| 59 | GDVIRTUAL_BIND_COMPAT(_get_option_icon_bind_compat_108825, "device"); |
| 60 | #endif |
| 61 | |
| 62 | GDVIRTUAL_BIND(_get_option_label, "device"); |
| 63 | GDVIRTUAL_BIND(_get_option_tooltip, "device"); |
| 64 | GDVIRTUAL_BIND(_get_device_architecture, "device"); |
| 65 | |
| 66 | GDVIRTUAL_BIND(_cleanup); |
| 67 | |
| 68 | GDVIRTUAL_BIND(_run, "preset", "device", "debug_flags"); |
| 69 | GDVIRTUAL_BIND(_get_run_icon); |
| 70 | |
| 71 | GDVIRTUAL_BIND(_can_export, "preset", "debug"); |
| 72 | GDVIRTUAL_BIND(_has_valid_export_configuration, "preset", "debug"); |
| 73 | GDVIRTUAL_BIND(_has_valid_project_configuration, "preset"); |
| 74 | |
| 75 | GDVIRTUAL_BIND(_get_binary_extensions, "preset"); |
| 76 | |
| 77 | GDVIRTUAL_BIND(_export_project, "preset", "debug", "path", "flags"); |
| 78 | GDVIRTUAL_BIND(_export_pack, "preset", "debug", "path", "flags"); |
| 79 | GDVIRTUAL_BIND(_export_zip, "preset", "debug", "path", "flags"); |
| 80 | GDVIRTUAL_BIND(_export_pack_patch, "preset", "debug", "path", "patches", "flags"); |
| 81 | GDVIRTUAL_BIND(_export_zip_patch, "preset", "debug", "path", "patches", "flags"); |
| 82 | |
| 83 | GDVIRTUAL_BIND(_get_platform_features); |
| 84 | |
| 85 | GDVIRTUAL_BIND(_get_debug_protocol); |
| 86 | |
| 87 | GDVIRTUAL_BIND(_initialize); |
| 88 | } |
| 89 | |
| 90 | void EditorExportPlatformExtension::get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features) const { |
| 91 | Vector<String> ret; |
| 92 | if (GDVIRTUAL_CALL(_get_preset_features, p_preset, ret) && r_features) { |
| 93 | for (const String &E : ret) { |
| 94 | r_features->push_back(E); |
| 95 | } |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | bool EditorExportPlatformExtension::is_executable(const String &p_path) const { |
| 100 | bool ret = false; |
| 101 | GDVIRTUAL_CALL(_is_executable, p_path, ret); |
| 102 | return ret; |
| 103 | } |
| 104 | |
| 105 | void EditorExportPlatformExtension::get_export_options(List<ExportOption> *r_options) const { |
| 106 | TypedArray<Dictionary> ret; |
| 107 | if (GDVIRTUAL_CALL(_get_export_options, ret) && r_options) { |
| 108 | for (const Variant &var : ret) { |
| 109 | const Dictionary &d = var; |
| 110 | ERR_CONTINUE(!d.has("name")); |
| 111 | ERR_CONTINUE(!d.has("type")); |
| 112 | |
| 113 | PropertyInfo pinfo = PropertyInfo::from_dict(d); |
| 114 | ERR_CONTINUE(pinfo.name.is_empty() && (pinfo.usage & PROPERTY_USAGE_STORAGE)); |
| 115 | ERR_CONTINUE(pinfo.type < 0 || pinfo.type >= Variant::VARIANT_MAX); |
| 116 | |
| 117 | Variant default_value; |
| 118 | if (d.has("default_value")) { |
| 119 | default_value = d["default_value"]; |
| 120 | } |
| 121 | bool update_visibility = false; |
| 122 | if (d.has("update_visibility")) { |
| 123 | update_visibility = d["update_visibility"]; |
| 124 | } |
| 125 | bool required = false; |
| 126 | if (d.has("required")) { |
| 127 | required = d["required"]; |
| 128 | } |
| 129 | |
| 130 | r_options->push_back(ExportOption(pinfo, default_value, update_visibility, required)); |
| 131 | } |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | bool EditorExportPlatformExtension::should_update_export_options() { |
| 136 | bool ret = false; |
| 137 | GDVIRTUAL_CALL(_should_update_export_options, ret); |
| 138 | return ret; |
| 139 | } |
| 140 | |
| 141 | bool EditorExportPlatformExtension::get_export_option_visibility(const EditorExportPreset *p_preset, const String &p_option) const { |
| 142 | bool ret = true; |
| 143 | GDVIRTUAL_CALL(_get_export_option_visibility, Ref<EditorExportPreset>(p_preset), p_option, ret); |
| 144 | return ret; |
| 145 | } |
| 146 | |
| 147 | String EditorExportPlatformExtension::get_export_option_warning(const EditorExportPreset *p_preset, const StringName &p_name) const { |
| 148 | String ret; |
| 149 | GDVIRTUAL_CALL(_get_export_option_warning, Ref<EditorExportPreset>(p_preset), p_name, ret); |
| 150 | return ret; |
| 151 | } |
| 152 | |
| 153 | String EditorExportPlatformExtension::get_os_name() const { |
| 154 | String ret; |
| 155 | GDVIRTUAL_CALL(_get_os_name, ret); |
| 156 | return ret; |
| 157 | } |
| 158 | |
| 159 | String EditorExportPlatformExtension::get_name() const { |
| 160 | String ret; |
| 161 | GDVIRTUAL_CALL(_get_name, ret); |
| 162 | return ret; |
| 163 | } |
| 164 | |
| 165 | Ref<Texture2D> EditorExportPlatformExtension::get_logo() const { |
| 166 | Ref<Texture2D> ret; |
| 167 | GDVIRTUAL_CALL(_get_logo, ret); |
| 168 | return ret; |
| 169 | } |
| 170 | |
| 171 | bool EditorExportPlatformExtension::poll_export() { |
| 172 | bool ret = false; |
| 173 | GDVIRTUAL_CALL(_poll_export, ret); |
| 174 | return ret; |
| 175 | } |
| 176 | |
| 177 | int EditorExportPlatformExtension::get_options_count() const { |
| 178 | int ret = 0; |
| 179 | GDVIRTUAL_CALL(_get_options_count, ret); |
| 180 | return ret; |
| 181 | } |
| 182 | |
| 183 | String EditorExportPlatformExtension::get_options_tooltip() const { |
| 184 | String ret; |
| 185 | GDVIRTUAL_CALL(_get_options_tooltip, ret); |
| 186 | return ret; |
| 187 | } |
| 188 | |
| 189 | Ref<Texture2D> EditorExportPlatformExtension::get_option_icon(int p_index) const { |
| 190 | Ref<Texture2D> ret; |
| 191 | if (GDVIRTUAL_CALL(_get_option_icon, p_index, ret)) { |
| 192 | return ret; |
| 193 | } |
| 194 | #ifndef DISABLE_DEPRECATED |
| 195 | Ref<ImageTexture> comp_ret; |
| 196 | if (GDVIRTUAL_CALL(_get_option_icon_bind_compat_108825, p_index, comp_ret)) { |
| 197 | return comp_ret; |
| 198 | } |
| 199 | #endif |
| 200 | return EditorExportPlatform::get_option_icon(p_index); |
| 201 | } |
| 202 | |
| 203 | String EditorExportPlatformExtension::get_option_label(int p_device) const { |
| 204 | String ret; |
| 205 | GDVIRTUAL_CALL(_get_option_label, p_device, ret); |
| 206 | return ret; |
| 207 | } |
| 208 | |
| 209 | String EditorExportPlatformExtension::get_option_tooltip(int p_device) const { |
| 210 | String ret; |
| 211 | GDVIRTUAL_CALL(_get_option_tooltip, p_device, ret); |
| 212 | return ret; |
| 213 | } |
| 214 | |
| 215 | String EditorExportPlatformExtension::get_device_architecture(int p_device) const { |
| 216 | String ret; |
| 217 | GDVIRTUAL_CALL(_get_device_architecture, p_device, ret); |
| 218 | return ret; |
| 219 | } |
| 220 | |
| 221 | void EditorExportPlatformExtension::cleanup() { |
| 222 | GDVIRTUAL_CALL(_cleanup); |
| 223 | } |
| 224 | |
| 225 | Error EditorExportPlatformExtension::run(const Ref<EditorExportPreset> &p_preset, int p_device, BitField<EditorExportPlatform::DebugFlags> p_debug_flags) { |
| 226 | Error ret = OK; |
| 227 | GDVIRTUAL_CALL(_run, p_preset, p_device, p_debug_flags, ret); |
| 228 | return ret; |
| 229 | } |
| 230 | |
| 231 | Ref<Texture2D> EditorExportPlatformExtension::get_run_icon() const { |
| 232 | Ref<Texture2D> ret; |
| 233 | if (GDVIRTUAL_CALL(_get_run_icon, ret)) { |
| 234 | return ret; |
| 235 | } |
| 236 | return EditorExportPlatform::get_run_icon(); |
| 237 | } |
| 238 | |
| 239 | bool EditorExportPlatformExtension::can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates, bool p_debug) const { |
| 240 | bool ret = false; |
| 241 | config_error = r_error; |
| 242 | config_missing_templates = r_missing_templates; |
| 243 | if (GDVIRTUAL_CALL(_can_export, p_preset, p_debug, ret)) { |
| 244 | r_error = config_error; |
| 245 | r_missing_templates = config_missing_templates; |
| 246 | return ret; |
| 247 | } |
| 248 | return EditorExportPlatform::can_export(p_preset, r_error, r_missing_templates, p_debug); |
| 249 | } |
| 250 | |
| 251 | bool EditorExportPlatformExtension::has_valid_export_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates, bool p_debug) const { |
| 252 | bool ret = false; |
| 253 | config_error = r_error; |
| 254 | config_missing_templates = r_missing_templates; |
| 255 | if (GDVIRTUAL_CALL(_has_valid_export_configuration, p_preset, p_debug, ret)) { |
| 256 | r_error = config_error; |
| 257 | r_missing_templates = config_missing_templates; |
| 258 | } |
| 259 | return ret; |
| 260 | } |
| 261 | |
| 262 | bool EditorExportPlatformExtension::has_valid_project_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error) const { |
| 263 | bool ret = false; |
| 264 | config_error = r_error; |
| 265 | if (GDVIRTUAL_CALL(_has_valid_project_configuration, p_preset, ret)) { |
| 266 | r_error = config_error; |
| 267 | } |
| 268 | return ret; |
| 269 | } |
| 270 | |
| 271 | List<String> EditorExportPlatformExtension::get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const { |
| 272 | List<String> ret_list; |
| 273 | Vector<String> ret; |
| 274 | if (GDVIRTUAL_CALL(_get_binary_extensions, p_preset, ret)) { |
| 275 | for (const String &E : ret) { |
| 276 | ret_list.push_back(E); |
| 277 | } |
| 278 | } |
| 279 | return ret_list; |
| 280 | } |
| 281 | |
| 282 | Error EditorExportPlatformExtension::export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, BitField<EditorExportPlatform::DebugFlags> p_flags) { |
| 283 | ExportNotifier notifier(*this, p_preset, p_debug, p_path, p_flags); |
| 284 | |
| 285 | Error ret = FAILED; |
| 286 | GDVIRTUAL_CALL(_export_project, p_preset, p_debug, p_path, p_flags, ret); |
| 287 | return ret; |
| 288 | } |
| 289 | |
| 290 | Error EditorExportPlatformExtension::export_pack(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, BitField<EditorExportPlatform::DebugFlags> p_flags) { |
| 291 | ExportNotifier notifier(*this, p_preset, p_debug, p_path, p_flags); |
| 292 | |
| 293 | Error ret = FAILED; |
| 294 | if (GDVIRTUAL_CALL(_export_pack, p_preset, p_debug, p_path, p_flags, ret)) { |
| 295 | return ret; |
| 296 | } |
| 297 | return save_pack(p_preset, p_debug, p_path); |
| 298 | } |
| 299 | |
| 300 | Error EditorExportPlatformExtension::export_zip(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, BitField<EditorExportPlatform::DebugFlags> p_flags) { |
| 301 | ExportNotifier notifier(*this, p_preset, p_debug, p_path, p_flags); |
| 302 | |
| 303 | Error ret = FAILED; |
| 304 | if (GDVIRTUAL_CALL(_export_zip, p_preset, p_debug, p_path, p_flags, ret)) { |
| 305 | return ret; |
| 306 | } |
| 307 | return save_zip(p_preset, p_debug, p_path); |
| 308 | } |
| 309 | |
| 310 | Error EditorExportPlatformExtension::export_pack_patch(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, const Vector<String> &p_patches, BitField<EditorExportPlatform::DebugFlags> p_flags) { |
| 311 | ExportNotifier notifier(*this, p_preset, p_debug, p_path, p_flags); |
| 312 | |
| 313 | Error err = _load_patches(p_patches.is_empty() ? p_preset->get_patches() : p_patches); |
| 314 | if (err != OK) { |
| 315 | return err; |
| 316 | } |
| 317 | |
| 318 | Error ret = FAILED; |
| 319 | if (GDVIRTUAL_CALL(_export_pack_patch, p_preset, p_debug, p_path, p_patches, p_flags, ret)) { |
| 320 | _unload_patches(); |
| 321 | return ret; |
| 322 | } |
| 323 | |
| 324 | err = save_pack_patch(p_preset, p_debug, p_path); |
| 325 | _unload_patches(); |
| 326 | return err; |
| 327 | } |
| 328 | |
| 329 | Error EditorExportPlatformExtension::export_zip_patch(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, const Vector<String> &p_patches, BitField<EditorExportPlatform::DebugFlags> p_flags) { |
| 330 | ExportNotifier notifier(*this, p_preset, p_debug, p_path, p_flags); |
| 331 | |
| 332 | Error err = _load_patches(p_patches.is_empty() ? p_preset->get_patches() : p_patches); |
| 333 | if (err != OK) { |
| 334 | return err; |
| 335 | } |
| 336 | |
| 337 | Error ret = FAILED; |
| 338 | if (GDVIRTUAL_CALL(_export_zip_patch, p_preset, p_debug, p_path, p_patches, p_flags, ret)) { |
| 339 | _unload_patches(); |
| 340 | return ret; |
| 341 | } |
| 342 | |
| 343 | err = save_zip_patch(p_preset, p_debug, p_path); |
| 344 | _unload_patches(); |
| 345 | return err; |
| 346 | } |
| 347 | |
| 348 | void EditorExportPlatformExtension::get_platform_features(List<String> *r_features) const { |
| 349 | Vector<String> ret; |
| 350 | if (GDVIRTUAL_CALL(_get_platform_features, ret) && r_features) { |
| 351 | for (const String &E : ret) { |
| 352 | r_features->push_back(E); |
| 353 | } |
| 354 | } |
| 355 | } |
| 356 | |
| 357 | String EditorExportPlatformExtension::get_debug_protocol() const { |
| 358 | String ret; |
| 359 | if (GDVIRTUAL_CALL(_get_debug_protocol, ret)) { |
| 360 | return ret; |
| 361 | } |
| 362 | return EditorExportPlatform::get_debug_protocol(); |
| 363 | } |
| 364 | |
| 365 | void EditorExportPlatformExtension::initialize() { |
| 366 | GDVIRTUAL_CALL(_initialize); |
| 367 | } |
| 368 | |
| 369 | EditorExportPlatformExtension::EditorExportPlatformExtension() { |
| 370 | //NOP |
| 371 | } |
| 372 | |
| 373 | EditorExportPlatformExtension::~EditorExportPlatformExtension() { |
| 374 | //NOP |
| 375 | } |