| 1 | /**************************************************************************/ |
| 2 | /* editor_export_preset.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_preset.h" |
| 32 | #include "editor_export_preset.compat.inc" |
| 33 | |
| 34 | #include "core/config/project_settings.h" |
| 35 | #include "core/io/dir_access.h" |
| 36 | #include "editor/export/editor_export.h" |
| 37 | #include "editor/settings/editor_settings.h" |
| 38 | |
| 39 | bool EditorExportPreset::_set(const StringName &p_name, const Variant &p_value) { |
| 40 | values[p_name] = p_value; |
| 41 | EditorExport::singleton->save_presets(); |
| 42 | if (update_visibility.has(p_name)) { |
| 43 | if (update_visibility[p_name]) { |
| 44 | update_value_overrides(); |
| 45 | notify_property_list_changed(); |
| 46 | } |
| 47 | return true; |
| 48 | } |
| 49 | |
| 50 | return false; |
| 51 | } |
| 52 | |
| 53 | bool EditorExportPreset::_get(const StringName &p_name, Variant &r_ret) const { |
| 54 | if (value_overrides.has(p_name)) { |
| 55 | r_ret = value_overrides[p_name]; |
| 56 | return true; |
| 57 | } |
| 58 | |
| 59 | if (values.has(p_name)) { |
| 60 | r_ret = values[p_name]; |
| 61 | return true; |
| 62 | } |
| 63 | |
| 64 | return false; |
| 65 | } |
| 66 | |
| 67 | Variant EditorExportPreset::get_project_setting(const StringName &p_name) { |
| 68 | List<String> ftr_list; |
| 69 | platform->get_platform_features(&ftr_list); |
| 70 | platform->get_preset_features(this, &ftr_list); |
| 71 | |
| 72 | Vector<String> features; |
| 73 | for (const String &E : ftr_list) { |
| 74 | features.push_back(E); |
| 75 | } |
| 76 | |
| 77 | if (!get_custom_features().is_empty()) { |
| 78 | Vector<String> tmp_custom_list = get_custom_features().split(","); |
| 79 | |
| 80 | for (int i = 0; i < tmp_custom_list.size(); i++) { |
| 81 | String f = tmp_custom_list[i].strip_edges(); |
| 82 | if (!f.is_empty()) { |
| 83 | features.push_back(f); |
| 84 | } |
| 85 | } |
| 86 | } |
| 87 | return ProjectSettings::get_singleton()->get_setting_with_override_and_custom_features(p_name, features); |
| 88 | } |
| 89 | |
| 90 | void EditorExportPreset::_bind_methods() { |
| 91 | ClassDB::bind_method(D_METHOD("_get_property_warning", "name"), &EditorExportPreset::_get_property_warning); |
| 92 | |
| 93 | ClassDB::bind_method(D_METHOD("has", "property"), &EditorExportPreset::has); |
| 94 | |
| 95 | ClassDB::bind_method(D_METHOD("get_files_to_export"), &EditorExportPreset::get_files_to_export); |
| 96 | ClassDB::bind_method(D_METHOD("get_customized_files"), &EditorExportPreset::get_customized_files); |
| 97 | ClassDB::bind_method(D_METHOD("get_customized_files_count"), &EditorExportPreset::get_customized_files_count); |
| 98 | ClassDB::bind_method(D_METHOD("has_export_file", "path"), &EditorExportPreset::has_export_file); |
| 99 | ClassDB::bind_method(D_METHOD("get_file_export_mode", "path", "default"), &EditorExportPreset::get_file_export_mode, DEFVAL(MODE_FILE_NOT_CUSTOMIZED)); |
| 100 | ClassDB::bind_method(D_METHOD("get_project_setting", "name"), &EditorExportPreset::get_project_setting); |
| 101 | |
| 102 | ClassDB::bind_method(D_METHOD("get_preset_name"), &EditorExportPreset::get_name); |
| 103 | ClassDB::bind_method(D_METHOD("is_runnable"), &EditorExportPreset::is_runnable); |
| 104 | ClassDB::bind_method(D_METHOD("are_advanced_options_enabled"), &EditorExportPreset::are_advanced_options_enabled); |
| 105 | ClassDB::bind_method(D_METHOD("is_dedicated_server"), &EditorExportPreset::is_dedicated_server); |
| 106 | ClassDB::bind_method(D_METHOD("get_export_filter"), &EditorExportPreset::get_export_filter); |
| 107 | ClassDB::bind_method(D_METHOD("get_include_filter"), &EditorExportPreset::get_include_filter); |
| 108 | ClassDB::bind_method(D_METHOD("get_exclude_filter"), &EditorExportPreset::get_exclude_filter); |
| 109 | ClassDB::bind_method(D_METHOD("get_custom_features"), &EditorExportPreset::get_custom_features); |
| 110 | ClassDB::bind_method(D_METHOD("get_patches"), &EditorExportPreset::get_patches); |
| 111 | ClassDB::bind_method(D_METHOD("get_export_path"), &EditorExportPreset::get_export_path); |
| 112 | ClassDB::bind_method(D_METHOD("get_encryption_in_filter"), &EditorExportPreset::get_enc_in_filter); |
| 113 | ClassDB::bind_method(D_METHOD("get_encryption_ex_filter"), &EditorExportPreset::get_enc_ex_filter); |
| 114 | ClassDB::bind_method(D_METHOD("get_encrypt_pck"), &EditorExportPreset::get_enc_pck); |
| 115 | ClassDB::bind_method(D_METHOD("get_encrypt_directory"), &EditorExportPreset::get_enc_directory); |
| 116 | ClassDB::bind_method(D_METHOD("get_encryption_key"), &EditorExportPreset::get_script_encryption_key); |
| 117 | ClassDB::bind_method(D_METHOD("get_script_export_mode"), &EditorExportPreset::get_script_export_mode); |
| 118 | |
| 119 | ClassDB::bind_method(D_METHOD("get_or_env", "name", "env_var"), &EditorExportPreset::_get_or_env); |
| 120 | ClassDB::bind_method(D_METHOD("get_version", "name", "windows_version"), &EditorExportPreset::get_version); |
| 121 | |
| 122 | BIND_ENUM_CONSTANT(EXPORT_ALL_RESOURCES); |
| 123 | BIND_ENUM_CONSTANT(EXPORT_SELECTED_SCENES); |
| 124 | BIND_ENUM_CONSTANT(EXPORT_SELECTED_RESOURCES); |
| 125 | BIND_ENUM_CONSTANT(EXCLUDE_SELECTED_RESOURCES); |
| 126 | BIND_ENUM_CONSTANT(EXPORT_CUSTOMIZED); |
| 127 | |
| 128 | BIND_ENUM_CONSTANT(MODE_FILE_NOT_CUSTOMIZED); |
| 129 | BIND_ENUM_CONSTANT(MODE_FILE_STRIP); |
| 130 | BIND_ENUM_CONSTANT(MODE_FILE_KEEP); |
| 131 | BIND_ENUM_CONSTANT(MODE_FILE_REMOVE); |
| 132 | |
| 133 | BIND_ENUM_CONSTANT(MODE_SCRIPT_TEXT); |
| 134 | BIND_ENUM_CONSTANT(MODE_SCRIPT_BINARY_TOKENS); |
| 135 | BIND_ENUM_CONSTANT(MODE_SCRIPT_BINARY_TOKENS_COMPRESSED); |
| 136 | } |
| 137 | |
| 138 | String EditorExportPreset::_get_property_warning(const StringName &p_name) const { |
| 139 | if (value_overrides.has(p_name)) { |
| 140 | return String(); |
| 141 | } |
| 142 | |
| 143 | String warning = platform->get_export_option_warning(this, p_name); |
| 144 | if (!warning.is_empty()) { |
| 145 | warning += "\n"; |
| 146 | } |
| 147 | |
| 148 | // Get property warning from editor export plugins. |
| 149 | Vector<Ref<EditorExportPlugin>> export_plugins = EditorExport::get_singleton()->get_export_plugins(); |
| 150 | for (int i = 0; i < export_plugins.size(); i++) { |
| 151 | if (!export_plugins[i]->supports_platform(platform)) { |
| 152 | continue; |
| 153 | } |
| 154 | |
| 155 | export_plugins.write[i]->set_export_preset(Ref<EditorExportPreset>(this)); |
| 156 | String plugin_warning = export_plugins[i]->_get_export_option_warning(platform, p_name); |
| 157 | if (!plugin_warning.is_empty()) { |
| 158 | warning += plugin_warning + "\n"; |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | return warning; |
| 163 | } |
| 164 | |
| 165 | void EditorExportPreset::_get_property_list(List<PropertyInfo> *p_list) const { |
| 166 | for (const KeyValue<StringName, PropertyInfo> &E : properties) { |
| 167 | if (!value_overrides.has(E.key)) { |
| 168 | bool property_visible = platform->get_export_option_visibility(this, E.key); |
| 169 | if (!property_visible) { |
| 170 | continue; |
| 171 | } |
| 172 | |
| 173 | // Get option visibility from editor export plugins. |
| 174 | Vector<Ref<EditorExportPlugin>> export_plugins = EditorExport::get_singleton()->get_export_plugins(); |
| 175 | for (int i = 0; i < export_plugins.size(); i++) { |
| 176 | if (!export_plugins[i]->supports_platform(platform)) { |
| 177 | continue; |
| 178 | } |
| 179 | |
| 180 | export_plugins.write[i]->set_export_preset(Ref<EditorExportPreset>(this)); |
| 181 | property_visible = export_plugins[i]->_get_export_option_visibility(platform, E.key); |
| 182 | if (!property_visible) { |
| 183 | break; |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | if (property_visible) { |
| 188 | p_list->push_back(E.value); |
| 189 | } |
| 190 | } |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | Ref<EditorExportPlatform> EditorExportPreset::get_platform() const { |
| 195 | return platform; |
| 196 | } |
| 197 | |
| 198 | void EditorExportPreset::update_files() { |
| 199 | { |
| 200 | Vector<String> to_remove; |
| 201 | for (const String &E : selected_files) { |
| 202 | if (!FileAccess::exists(E)) { |
| 203 | to_remove.push_back(E); |
| 204 | } |
| 205 | } |
| 206 | for (int i = 0; i < to_remove.size(); ++i) { |
| 207 | selected_files.erase(to_remove[i]); |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | { |
| 212 | Vector<String> to_remove; |
| 213 | for (const KeyValue<String, FileExportMode> &E : customized_files) { |
| 214 | if (!FileAccess::exists(E.key) && !DirAccess::exists(E.key)) { |
| 215 | to_remove.push_back(E.key); |
| 216 | } |
| 217 | } |
| 218 | for (int i = 0; i < to_remove.size(); ++i) { |
| 219 | customized_files.erase(to_remove[i]); |
| 220 | } |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | void EditorExportPreset::update_value_overrides() { |
| 225 | Vector<Ref<EditorExportPlugin>> export_plugins = EditorExport::get_singleton()->get_export_plugins(); |
| 226 | HashMap<StringName, Variant> new_value_overrides; |
| 227 | |
| 228 | value_overrides.clear(); |
| 229 | |
| 230 | for (int i = 0; i < export_plugins.size(); i++) { |
| 231 | if (!export_plugins[i]->supports_platform(platform)) { |
| 232 | continue; |
| 233 | } |
| 234 | |
| 235 | export_plugins.write[i]->set_export_preset(Ref<EditorExportPreset>(this)); |
| 236 | |
| 237 | Dictionary plugin_overrides = export_plugins[i]->_get_export_options_overrides(platform); |
| 238 | if (!plugin_overrides.is_empty()) { |
| 239 | for (const KeyValue<Variant, Variant> &kv : plugin_overrides) { |
| 240 | const StringName &key = kv.key; |
| 241 | const Variant &value = kv.value; |
| 242 | if (new_value_overrides.has(key) && new_value_overrides[key] != value) { |
| 243 | WARN_PRINT_ED(vformat("Editor export plugin '%s' overrides pre-existing export option override '%s' with new value.", export_plugins[i]->get_name(), key)); |
| 244 | } |
| 245 | new_value_overrides[key] = value; |
| 246 | } |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | value_overrides = new_value_overrides; |
| 251 | notify_property_list_changed(); |
| 252 | } |
| 253 | |
| 254 | Vector<String> EditorExportPreset::get_files_to_export() const { |
| 255 | Vector<String> files; |
| 256 | for (const String &E : selected_files) { |
| 257 | files.push_back(E); |
| 258 | } |
| 259 | return files; |
| 260 | } |
| 261 | |
| 262 | HashSet<String> EditorExportPreset::get_selected_files() const { |
| 263 | return selected_files; |
| 264 | } |
| 265 | |
| 266 | void EditorExportPreset::set_selected_files(const HashSet<String> &p_files) { |
| 267 | selected_files = p_files; |
| 268 | } |
| 269 | |
| 270 | Dictionary EditorExportPreset::get_customized_files() const { |
| 271 | Dictionary files; |
| 272 | for (const KeyValue<String, FileExportMode> &E : customized_files) { |
| 273 | String mode; |
| 274 | switch (E.value) { |
| 275 | case MODE_FILE_NOT_CUSTOMIZED: { |
| 276 | continue; |
| 277 | } break; |
| 278 | case MODE_FILE_STRIP: { |
| 279 | mode = "strip"; |
| 280 | } break; |
| 281 | case MODE_FILE_KEEP: { |
| 282 | mode = "keep"; |
| 283 | } break; |
| 284 | case MODE_FILE_REMOVE: { |
| 285 | mode = "remove"; |
| 286 | } |
| 287 | } |
| 288 | files[E.key] = mode; |
| 289 | } |
| 290 | return files; |
| 291 | } |
| 292 | |
| 293 | int EditorExportPreset::get_customized_files_count() const { |
| 294 | return customized_files.size(); |
| 295 | } |
| 296 | |
| 297 | void EditorExportPreset::set_customized_files(const Dictionary &p_files) { |
| 298 | for (const Variant *key = p_files.next(nullptr); key; key = p_files.next(key)) { |
| 299 | EditorExportPreset::FileExportMode mode = EditorExportPreset::MODE_FILE_NOT_CUSTOMIZED; |
| 300 | String value = p_files[*key]; |
| 301 | if (value == "strip") { |
| 302 | mode = EditorExportPreset::MODE_FILE_STRIP; |
| 303 | } else if (value == "keep") { |
| 304 | mode = EditorExportPreset::MODE_FILE_KEEP; |
| 305 | } else if (value == "remove") { |
| 306 | mode = EditorExportPreset::MODE_FILE_REMOVE; |
| 307 | } |
| 308 | set_file_export_mode(*key, mode); |
| 309 | } |
| 310 | } |
| 311 | |
| 312 | void EditorExportPreset::set_name(const String &p_name) { |
| 313 | name = p_name; |
| 314 | EditorExport::singleton->save_presets(); |
| 315 | } |
| 316 | |
| 317 | String EditorExportPreset::get_name() const { |
| 318 | return name; |
| 319 | } |
| 320 | |
| 321 | void EditorExportPreset::set_runnable(bool p_enable) { |
| 322 | runnable = p_enable; |
| 323 | EditorExport::singleton->emit_presets_runnable_changed(); |
| 324 | EditorExport::singleton->save_presets(); |
| 325 | } |
| 326 | |
| 327 | bool EditorExportPreset::is_runnable() const { |
| 328 | return runnable; |
| 329 | } |
| 330 | |
| 331 | bool EditorExportPreset::are_advanced_options_enabled() const { |
| 332 | return EDITOR_GET("_export_preset_advanced_mode"); |
| 333 | } |
| 334 | |
| 335 | void EditorExportPreset::set_dedicated_server(bool p_enable) { |
| 336 | dedicated_server = p_enable; |
| 337 | EditorExport::singleton->save_presets(); |
| 338 | } |
| 339 | |
| 340 | bool EditorExportPreset::is_dedicated_server() const { |
| 341 | return dedicated_server; |
| 342 | } |
| 343 | |
| 344 | void EditorExportPreset::set_export_filter(ExportFilter p_filter) { |
| 345 | export_filter = p_filter; |
| 346 | EditorExport::singleton->save_presets(); |
| 347 | } |
| 348 | |
| 349 | EditorExportPreset::ExportFilter EditorExportPreset::get_export_filter() const { |
| 350 | return export_filter; |
| 351 | } |
| 352 | |
| 353 | void EditorExportPreset::set_include_filter(const String &p_include) { |
| 354 | include_filter = p_include; |
| 355 | EditorExport::singleton->save_presets(); |
| 356 | } |
| 357 | |
| 358 | String EditorExportPreset::get_include_filter() const { |
| 359 | return include_filter; |
| 360 | } |
| 361 | |
| 362 | void EditorExportPreset::set_export_path(const String &p_path) { |
| 363 | export_path = p_path; |
| 364 | /* NOTE(SonerSound): if there is a need to implement a PropertyHint that specifically indicates a relative path, |
| 365 | * this should be removed. */ |
| 366 | if (export_path.is_absolute_path()) { |
| 367 | String res_path = OS::get_singleton()->get_resource_dir(); |
| 368 | export_path = res_path.path_to_file(export_path); |
| 369 | } |
| 370 | EditorExport::singleton->save_presets(); |
| 371 | } |
| 372 | |
| 373 | String EditorExportPreset::get_export_path() const { |
| 374 | return export_path; |
| 375 | } |
| 376 | |
| 377 | void EditorExportPreset::set_exclude_filter(const String &p_exclude) { |
| 378 | exclude_filter = p_exclude; |
| 379 | EditorExport::singleton->save_presets(); |
| 380 | } |
| 381 | |
| 382 | String EditorExportPreset::get_exclude_filter() const { |
| 383 | return exclude_filter; |
| 384 | } |
| 385 | |
| 386 | void EditorExportPreset::add_export_file(const String &p_path) { |
| 387 | selected_files.insert(p_path); |
| 388 | EditorExport::singleton->save_presets(); |
| 389 | } |
| 390 | |
| 391 | void EditorExportPreset::remove_export_file(const String &p_path) { |
| 392 | selected_files.erase(p_path); |
| 393 | EditorExport::singleton->save_presets(); |
| 394 | } |
| 395 | |
| 396 | bool EditorExportPreset::has_export_file(const String &p_path) { |
| 397 | return selected_files.has(p_path); |
| 398 | } |
| 399 | |
| 400 | void EditorExportPreset::set_file_export_mode(const String &p_path, EditorExportPreset::FileExportMode p_mode) { |
| 401 | if (p_mode == FileExportMode::MODE_FILE_NOT_CUSTOMIZED) { |
| 402 | customized_files.erase(p_path); |
| 403 | } else { |
| 404 | customized_files.insert(p_path, p_mode); |
| 405 | } |
| 406 | EditorExport::singleton->save_presets(); |
| 407 | } |
| 408 | |
| 409 | EditorExportPreset::FileExportMode EditorExportPreset::get_file_export_mode(const String &p_path, EditorExportPreset::FileExportMode p_default) const { |
| 410 | HashMap<String, FileExportMode>::ConstIterator i = customized_files.find(p_path); |
| 411 | if (i) { |
| 412 | return i->value; |
| 413 | } |
| 414 | return p_default; |
| 415 | } |
| 416 | |
| 417 | void EditorExportPreset::add_patch(const String &p_path, int p_at_pos) { |
| 418 | ERR_FAIL_COND_EDMSG(patches.has(p_path), vformat("Failed to add patch \"%s\". Patches must be unique.", p_path)); |
| 419 | |
| 420 | if (p_at_pos < 0) { |
| 421 | patches.push_back(p_path); |
| 422 | } else { |
| 423 | patches.insert(p_at_pos, p_path); |
| 424 | } |
| 425 | |
| 426 | EditorExport::singleton->save_presets(); |
| 427 | } |
| 428 | |
| 429 | void EditorExportPreset::set_patch(int p_index, const String &p_path) { |
| 430 | remove_patch(p_index); |
| 431 | add_patch(p_path, p_index); |
| 432 | } |
| 433 | |
| 434 | String EditorExportPreset::get_patch(int p_index) { |
| 435 | ERR_FAIL_INDEX_V(p_index, patches.size(), String()); |
| 436 | return patches[p_index]; |
| 437 | } |
| 438 | |
| 439 | void EditorExportPreset::remove_patch(int p_index) { |
| 440 | ERR_FAIL_INDEX(p_index, patches.size()); |
| 441 | patches.remove_at(p_index); |
| 442 | EditorExport::singleton->save_presets(); |
| 443 | } |
| 444 | |
| 445 | void EditorExportPreset::set_patches(const Vector<String> &p_patches) { |
| 446 | patches = p_patches; |
| 447 | } |
| 448 | |
| 449 | Vector<String> EditorExportPreset::get_patches() const { |
| 450 | return patches; |
| 451 | } |
| 452 | |
| 453 | void EditorExportPreset::set_patch_delta_encoding_enabled(bool p_enable) { |
| 454 | patch_delta_encoding_enabled = p_enable; |
| 455 | EditorExport::singleton->save_presets(); |
| 456 | } |
| 457 | |
| 458 | bool EditorExportPreset::is_patch_delta_encoding_enabled() const { |
| 459 | return patch_delta_encoding_enabled; |
| 460 | } |
| 461 | |
| 462 | void EditorExportPreset::set_patch_delta_zstd_level(int p_level) { |
| 463 | patch_delta_zstd_level = p_level; |
| 464 | EditorExport::singleton->save_presets(); |
| 465 | } |
| 466 | |
| 467 | int EditorExportPreset::get_patch_delta_zstd_level() const { |
| 468 | return patch_delta_zstd_level; |
| 469 | } |
| 470 | |
| 471 | void EditorExportPreset::set_patch_delta_min_reduction(double p_ratio) { |
| 472 | patch_delta_min_reduction = p_ratio; |
| 473 | EditorExport::singleton->save_presets(); |
| 474 | } |
| 475 | |
| 476 | double EditorExportPreset::get_patch_delta_min_reduction() const { |
| 477 | return patch_delta_min_reduction; |
| 478 | } |
| 479 | |
| 480 | void EditorExportPreset::set_patch_delta_include_filter(const String &p_filter) { |
| 481 | patch_delta_include_filter = p_filter; |
| 482 | EditorExport::singleton->save_presets(); |
| 483 | } |
| 484 | |
| 485 | String EditorExportPreset::get_patch_delta_include_filter() const { |
| 486 | return patch_delta_include_filter; |
| 487 | } |
| 488 | |
| 489 | void EditorExportPreset::set_patch_delta_exclude_filter(const String &p_filter) { |
| 490 | patch_delta_exclude_filter = p_filter; |
| 491 | EditorExport::singleton->save_presets(); |
| 492 | } |
| 493 | |
| 494 | String EditorExportPreset::get_patch_delta_exclude_filter() const { |
| 495 | return patch_delta_exclude_filter; |
| 496 | } |
| 497 | |
| 498 | void EditorExportPreset::set_custom_features(const String &p_custom_features) { |
| 499 | custom_features = p_custom_features; |
| 500 | EditorExport::singleton->save_presets(); |
| 501 | } |
| 502 | |
| 503 | String EditorExportPreset::get_custom_features() const { |
| 504 | return custom_features; |
| 505 | } |
| 506 | |
| 507 | void EditorExportPreset::set_enc_in_filter(const String &p_filter) { |
| 508 | enc_in_filters = p_filter; |
| 509 | EditorExport::singleton->save_presets(); |
| 510 | } |
| 511 | |
| 512 | String EditorExportPreset::get_enc_in_filter() const { |
| 513 | return enc_in_filters; |
| 514 | } |
| 515 | |
| 516 | void EditorExportPreset::set_enc_ex_filter(const String &p_filter) { |
| 517 | enc_ex_filters = p_filter; |
| 518 | EditorExport::singleton->save_presets(); |
| 519 | } |
| 520 | |
| 521 | String EditorExportPreset::get_enc_ex_filter() const { |
| 522 | return enc_ex_filters; |
| 523 | } |
| 524 | |
| 525 | void EditorExportPreset::set_seed(uint64_t p_seed) { |
| 526 | seed = p_seed; |
| 527 | EditorExport::singleton->save_presets(); |
| 528 | } |
| 529 | |
| 530 | uint64_t EditorExportPreset::get_seed() const { |
| 531 | return seed; |
| 532 | } |
| 533 | |
| 534 | void EditorExportPreset::set_enc_pck(bool p_enabled) { |
| 535 | enc_pck = p_enabled; |
| 536 | EditorExport::singleton->save_presets(); |
| 537 | } |
| 538 | |
| 539 | bool EditorExportPreset::get_enc_pck() const { |
| 540 | return enc_pck; |
| 541 | } |
| 542 | |
| 543 | void EditorExportPreset::set_enc_directory(bool p_enabled) { |
| 544 | enc_directory = p_enabled; |
| 545 | EditorExport::singleton->save_presets(); |
| 546 | } |
| 547 | |
| 548 | bool EditorExportPreset::get_enc_directory() const { |
| 549 | return enc_directory; |
| 550 | } |
| 551 | |
| 552 | void EditorExportPreset::set_script_encryption_key(const String &p_key) { |
| 553 | script_key = p_key; |
| 554 | EditorExport::singleton->save_presets(); |
| 555 | } |
| 556 | |
| 557 | String EditorExportPreset::get_script_encryption_key() const { |
| 558 | return script_key; |
| 559 | } |
| 560 | |
| 561 | void EditorExportPreset::set_script_export_mode(ScriptExportMode p_mode) { |
| 562 | script_mode = p_mode; |
| 563 | EditorExport::singleton->save_presets(); |
| 564 | } |
| 565 | |
| 566 | EditorExportPreset::ScriptExportMode EditorExportPreset::get_script_export_mode() const { |
| 567 | return script_mode; |
| 568 | } |
| 569 | |
| 570 | Variant EditorExportPreset::get_or_env(const StringName &p_name, const String &p_env_var, bool *r_valid) const { |
| 571 | const String from_env = OS::get_singleton()->get_environment(p_env_var); |
| 572 | if (!from_env.is_empty()) { |
| 573 | if (r_valid) { |
| 574 | *r_valid = true; |
| 575 | } |
| 576 | return from_env; |
| 577 | } |
| 578 | return get(p_name, r_valid); |
| 579 | } |
| 580 | |
| 581 | _FORCE_INLINE_ bool _check_digits(const String &p_str) { |
| 582 | for (int i = 0; i < p_str.length(); i++) { |
| 583 | char32_t c = p_str.operator[](i); |
| 584 | if (!is_digit(c)) { |
| 585 | return false; |
| 586 | } |
| 587 | } |
| 588 | return true; |
| 589 | } |
| 590 | |
| 591 | String EditorExportPreset::get_version(const StringName &p_preset_string, bool p_windows_version) const { |
| 592 | String result = get(p_preset_string); |
| 593 | if (result.is_empty()) { |
| 594 | result = GLOBAL_GET("application/config/version"); |
| 595 | |
| 596 | // Split and validate version number components. |
| 597 | const PackedStringArray result_split = result.split(".", false); |
| 598 | bool valid_version = !result_split.is_empty(); |
| 599 | for (const String &E : result_split) { |
| 600 | if (!_check_digits(E)) { |
| 601 | valid_version = false; |
| 602 | break; |
| 603 | } |
| 604 | } |
| 605 | |
| 606 | if (valid_version) { |
| 607 | if (p_windows_version) { |
| 608 | // Modify version number to match Windows constraints (version numbers must have 4 components). |
| 609 | if (result_split.size() == 1) { |
| 610 | result = result + ".0.0.0"; |
| 611 | } else if (result_split.size() == 2) { |
| 612 | result = result + ".0.0"; |
| 613 | } else if (result_split.size() == 3) { |
| 614 | result = result + ".0"; |
| 615 | } else { |
| 616 | result = vformat("%s.%s.%s.%s", result_split[0], result_split[1], result_split[2], result_split[3]); |
| 617 | } |
| 618 | } else { |
| 619 | result = String(".").join(result_split); |
| 620 | } |
| 621 | } else { |
| 622 | if (!result.is_empty()) { |
| 623 | WARN_PRINT(vformat("Invalid version number \"%s\". The version number can only contain numeric characters (0-9) and non-consecutive periods (.).", result)); |
| 624 | } |
| 625 | if (p_windows_version) { |
| 626 | result = "1.0.0.0"; |
| 627 | } else { |
| 628 | result = "1.0.0"; |
| 629 | } |
| 630 | } |
| 631 | } |
| 632 | |
| 633 | return result; |
| 634 | } |