123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004 |
- /*************************************************************************/
- /* editor_export.cpp */
- /*************************************************************************/
- /* This file is part of: */
- /* GODOT ENGINE */
- /* https://godotengine.org */
- /*************************************************************************/
- /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
- /* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
- /* */
- /* Permission is hereby granted, free of charge, to any person obtaining */
- /* a copy of this software and associated documentation files (the */
- /* "Software"), to deal in the Software without restriction, including */
- /* without limitation the rights to use, copy, modify, merge, publish, */
- /* distribute, sublicense, and/or sell copies of the Software, and to */
- /* permit persons to whom the Software is furnished to do so, subject to */
- /* the following conditions: */
- /* */
- /* The above copyright notice and this permission notice shall be */
- /* included in all copies or substantial portions of the Software. */
- /* */
- /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
- /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
- /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
- /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
- /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
- /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
- /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
- /*************************************************************************/
- #include "editor_export.h"
- #include "core/config/project_settings.h"
- #include "core/crypto/crypto_core.h"
- #include "core/io/config_file.h"
- #include "core/io/dir_access.h"
- #include "core/io/file_access.h"
- #include "core/io/file_access_encrypted.h"
- #include "core/io/file_access_pack.h" // PACK_HEADER_MAGIC, PACK_FORMAT_VERSION
- #include "core/io/resource_loader.h"
- #include "core/io/resource_saver.h"
- #include "core/io/zip_io.h"
- #include "core/object/script_language.h"
- #include "core/version.h"
- #include "editor/editor_file_system.h"
- #include "editor/plugins/script_editor_plugin.h"
- #include "editor_node.h"
- #include "editor_settings.h"
- #include "scene/resources/resource_format_text.h"
- static int _get_pad(int p_alignment, int p_n) {
- int rest = p_n % p_alignment;
- int pad = 0;
- if (rest > 0) {
- pad = p_alignment - rest;
- };
- return pad;
- }
- #define PCK_PADDING 16
- bool EditorExportPreset::_set(const StringName &p_name, const Variant &p_value) {
- if (values.has(p_name)) {
- values[p_name] = p_value;
- EditorExport::singleton->save_presets();
- return true;
- }
- return false;
- }
- bool EditorExportPreset::_get(const StringName &p_name, Variant &r_ret) const {
- if (values.has(p_name)) {
- r_ret = values[p_name];
- return true;
- }
- return false;
- }
- void EditorExportPreset::_get_property_list(List<PropertyInfo> *p_list) const {
- for (const List<PropertyInfo>::Element *E = properties.front(); E; E = E->next()) {
- if (platform->get_option_visibility(E->get().name, values)) {
- p_list->push_back(E->get());
- }
- }
- }
- Ref<EditorExportPlatform> EditorExportPreset::get_platform() const {
- return platform;
- }
- void EditorExportPreset::update_files_to_export() {
- Vector<String> to_remove;
- for (Set<String>::Element *E = selected_files.front(); E; E = E->next()) {
- if (!FileAccess::exists(E->get())) {
- to_remove.push_back(E->get());
- }
- }
- for (int i = 0; i < to_remove.size(); ++i) {
- selected_files.erase(to_remove[i]);
- }
- }
- Vector<String> EditorExportPreset::get_files_to_export() const {
- Vector<String> files;
- for (Set<String>::Element *E = selected_files.front(); E; E = E->next()) {
- files.push_back(E->get());
- }
- return files;
- }
- void EditorExportPreset::set_name(const String &p_name) {
- name = p_name;
- EditorExport::singleton->save_presets();
- }
- String EditorExportPreset::get_name() const {
- return name;
- }
- void EditorExportPreset::set_runnable(bool p_enable) {
- runnable = p_enable;
- EditorExport::singleton->save_presets();
- }
- bool EditorExportPreset::is_runnable() const {
- return runnable;
- }
- void EditorExportPreset::set_export_filter(ExportFilter p_filter) {
- export_filter = p_filter;
- EditorExport::singleton->save_presets();
- }
- EditorExportPreset::ExportFilter EditorExportPreset::get_export_filter() const {
- return export_filter;
- }
- void EditorExportPreset::set_include_filter(const String &p_include) {
- include_filter = p_include;
- EditorExport::singleton->save_presets();
- }
- String EditorExportPreset::get_include_filter() const {
- return include_filter;
- }
- void EditorExportPreset::set_export_path(const String &p_path) {
- export_path = p_path;
- /* NOTE(SonerSound): if there is a need to implement a PropertyHint that specifically indicates a relative path,
- * this should be removed. */
- if (export_path.is_abs_path()) {
- String res_path = OS::get_singleton()->get_resource_dir();
- export_path = res_path.path_to_file(export_path);
- }
- EditorExport::singleton->save_presets();
- }
- String EditorExportPreset::get_export_path() const {
- return export_path;
- }
- void EditorExportPreset::set_exclude_filter(const String &p_exclude) {
- exclude_filter = p_exclude;
- EditorExport::singleton->save_presets();
- }
- String EditorExportPreset::get_exclude_filter() const {
- return exclude_filter;
- }
- void EditorExportPreset::add_export_file(const String &p_path) {
- selected_files.insert(p_path);
- EditorExport::singleton->save_presets();
- }
- void EditorExportPreset::remove_export_file(const String &p_path) {
- selected_files.erase(p_path);
- EditorExport::singleton->save_presets();
- }
- bool EditorExportPreset::has_export_file(const String &p_path) {
- return selected_files.has(p_path);
- }
- void EditorExportPreset::set_custom_features(const String &p_custom_features) {
- custom_features = p_custom_features;
- EditorExport::singleton->save_presets();
- }
- String EditorExportPreset::get_custom_features() const {
- return custom_features;
- }
- void EditorExportPreset::set_enc_in_filter(const String &p_filter) {
- enc_in_filters = p_filter;
- EditorExport::singleton->save_presets();
- }
- String EditorExportPreset::get_enc_in_filter() const {
- return enc_in_filters;
- }
- void EditorExportPreset::set_enc_ex_filter(const String &p_filter) {
- enc_ex_filters = p_filter;
- EditorExport::singleton->save_presets();
- }
- String EditorExportPreset::get_enc_ex_filter() const {
- return enc_ex_filters;
- }
- void EditorExportPreset::set_enc_pck(bool p_enabled) {
- enc_pck = p_enabled;
- EditorExport::singleton->save_presets();
- }
- bool EditorExportPreset::get_enc_pck() const {
- return enc_pck;
- }
- void EditorExportPreset::set_enc_directory(bool p_enabled) {
- enc_directory = p_enabled;
- EditorExport::singleton->save_presets();
- }
- bool EditorExportPreset::get_enc_directory() const {
- return enc_directory;
- }
- void EditorExportPreset::set_script_export_mode(int p_mode) {
- script_mode = p_mode;
- EditorExport::singleton->save_presets();
- }
- int EditorExportPreset::get_script_export_mode() const {
- return script_mode;
- }
- void EditorExportPreset::set_script_encryption_key(const String &p_key) {
- script_key = p_key;
- EditorExport::singleton->save_presets();
- }
- String EditorExportPreset::get_script_encryption_key() const {
- return script_key;
- }
- ///////////////////////////////////
- void EditorExportPlatform::gen_debug_flags(Vector<String> &r_flags, int p_flags) {
- String host = EditorSettings::get_singleton()->get("network/debug/remote_host");
- int remote_port = (int)EditorSettings::get_singleton()->get("network/debug/remote_port");
- if (p_flags & DEBUG_FLAG_REMOTE_DEBUG_LOCALHOST) {
- host = "localhost";
- }
- if (p_flags & DEBUG_FLAG_DUMB_CLIENT) {
- int port = EditorSettings::get_singleton()->get("filesystem/file_server/port");
- String passwd = EditorSettings::get_singleton()->get("filesystem/file_server/password");
- r_flags.push_back("--remote-fs");
- r_flags.push_back(host + ":" + itos(port));
- if (passwd != "") {
- r_flags.push_back("--remote-fs-password");
- r_flags.push_back(passwd);
- }
- }
- if (p_flags & DEBUG_FLAG_REMOTE_DEBUG) {
- r_flags.push_back("--remote-debug");
- r_flags.push_back(get_debug_protocol() + host + ":" + String::num(remote_port));
- List<String> breakpoints;
- ScriptEditor::get_singleton()->get_breakpoints(&breakpoints);
- if (breakpoints.size()) {
- r_flags.push_back("--breakpoints");
- String bpoints;
- for (const List<String>::Element *E = breakpoints.front(); E; E = E->next()) {
- bpoints += E->get().replace(" ", "%20");
- if (E->next()) {
- bpoints += ",";
- }
- }
- r_flags.push_back(bpoints);
- }
- }
- if (p_flags & DEBUG_FLAG_VIEW_COLLISONS) {
- r_flags.push_back("--debug-collisions");
- }
- if (p_flags & DEBUG_FLAG_VIEW_NAVIGATION) {
- r_flags.push_back("--debug-navigation");
- }
- }
- Error EditorExportPlatform::_save_pack_file(void *p_userdata, const String &p_path, const Vector<uint8_t> &p_data, int p_file, int p_total, const Vector<String> &p_enc_in_filters, const Vector<String> &p_enc_ex_filters, const Vector<uint8_t> &p_key) {
- ERR_FAIL_COND_V_MSG(p_total < 1, ERR_PARAMETER_RANGE_ERROR, "Must select at least one file to export.");
- PackData *pd = (PackData *)p_userdata;
- SavedData sd;
- sd.path_utf8 = p_path.utf8();
- sd.ofs = pd->f->get_position();
- sd.size = p_data.size();
- sd.encrypted = false;
- for (int i = 0; i < p_enc_in_filters.size(); ++i) {
- if (p_path.matchn(p_enc_in_filters[i]) || p_path.replace("res://", "").matchn(p_enc_in_filters[i])) {
- sd.encrypted = true;
- break;
- }
- }
- for (int i = 0; i < p_enc_ex_filters.size(); ++i) {
- if (p_path.matchn(p_enc_ex_filters[i]) || p_path.replace("res://", "").matchn(p_enc_ex_filters[i])) {
- sd.encrypted = false;
- break;
- }
- }
- FileAccessEncrypted *fae = nullptr;
- FileAccess *ftmp = pd->f;
- if (sd.encrypted) {
- fae = memnew(FileAccessEncrypted);
- ERR_FAIL_COND_V(!fae, ERR_SKIP);
- Error err = fae->open_and_parse(ftmp, p_key, FileAccessEncrypted::MODE_WRITE_AES256, false);
- ERR_FAIL_COND_V(err != OK, ERR_SKIP);
- ftmp = fae;
- }
- // Store file content.
- ftmp->store_buffer(p_data.ptr(), p_data.size());
- if (fae) {
- fae->release();
- memdelete(fae);
- }
- int pad = _get_pad(PCK_PADDING, pd->f->get_position());
- for (int i = 0; i < pad; i++) {
- pd->f->store_8(Math::rand() % 256);
- }
- // Store MD5 of original file.
- {
- unsigned char hash[16];
- CryptoCore::md5(p_data.ptr(), p_data.size(), hash);
- sd.md5.resize(16);
- for (int i = 0; i < 16; i++) {
- sd.md5.write[i] = hash[i];
- }
- }
- pd->file_ofs.push_back(sd);
- if (pd->ep->step(TTR("Storing File:") + " " + p_path, 2 + p_file * 100 / p_total, false)) {
- return ERR_SKIP;
- }
- return OK;
- }
- Error EditorExportPlatform::_save_zip_file(void *p_userdata, const String &p_path, const Vector<uint8_t> &p_data, int p_file, int p_total, const Vector<String> &p_enc_in_filters, const Vector<String> &p_enc_ex_filters, const Vector<uint8_t> &p_key) {
- ERR_FAIL_COND_V_MSG(p_total < 1, ERR_PARAMETER_RANGE_ERROR, "Must select at least one file to export.");
- String path = p_path.replace_first("res://", "");
- ZipData *zd = (ZipData *)p_userdata;
- zipFile zip = (zipFile)zd->zip;
- zipOpenNewFileInZip(zip,
- path.utf8().get_data(),
- nullptr,
- nullptr,
- 0,
- nullptr,
- 0,
- nullptr,
- Z_DEFLATED,
- Z_DEFAULT_COMPRESSION);
- zipWriteInFileInZip(zip, p_data.ptr(), p_data.size());
- zipCloseFileInZip(zip);
- if (zd->ep->step(TTR("Storing File:") + " " + p_path, 2 + p_file * 100 / p_total, false)) {
- return ERR_SKIP;
- }
- return OK;
- }
- Ref<ImageTexture> EditorExportPlatform::get_option_icon(int p_index) const {
- Ref<Theme> theme = EditorNode::get_singleton()->get_editor_theme();
- ERR_FAIL_COND_V(theme.is_null(), Ref<ImageTexture>());
- if (EditorNode::get_singleton()->get_main_control()->is_layout_rtl()) {
- return theme->get_icon("PlayBackwards", "EditorIcons");
- } else {
- return theme->get_icon("Play", "EditorIcons");
- }
- }
- String EditorExportPlatform::find_export_template(String template_file_name, String *err) const {
- String current_version = VERSION_FULL_CONFIG;
- String template_path = EditorSettings::get_singleton()->get_templates_dir().plus_file(current_version).plus_file(template_file_name);
- if (FileAccess::exists(template_path)) {
- return template_path;
- }
- // Not found
- if (err) {
- *err += TTR("No export template found at the expected path:") + "\n" + template_path + "\n";
- }
- return String();
- }
- bool EditorExportPlatform::exists_export_template(String template_file_name, String *err) const {
- return find_export_template(template_file_name, err) != "";
- }
- Ref<EditorExportPreset> EditorExportPlatform::create_preset() {
- Ref<EditorExportPreset> preset;
- preset.instance();
- preset->platform = Ref<EditorExportPlatform>(this);
- List<ExportOption> options;
- get_export_options(&options);
- for (List<ExportOption>::Element *E = options.front(); E; E = E->next()) {
- preset->properties.push_back(E->get().option);
- preset->values[E->get().option.name] = E->get().default_value;
- }
- return preset;
- }
- void EditorExportPlatform::_export_find_resources(EditorFileSystemDirectory *p_dir, Set<String> &p_paths) {
- for (int i = 0; i < p_dir->get_subdir_count(); i++) {
- _export_find_resources(p_dir->get_subdir(i), p_paths);
- }
- for (int i = 0; i < p_dir->get_file_count(); i++) {
- p_paths.insert(p_dir->get_file_path(i));
- }
- }
- void EditorExportPlatform::_export_find_dependencies(const String &p_path, Set<String> &p_paths) {
- if (p_paths.has(p_path)) {
- return;
- }
- p_paths.insert(p_path);
- EditorFileSystemDirectory *dir;
- int file_idx;
- dir = EditorFileSystem::get_singleton()->find_file(p_path, &file_idx);
- if (!dir) {
- return;
- }
- Vector<String> deps = dir->get_file_deps(file_idx);
- for (int i = 0; i < deps.size(); i++) {
- _export_find_dependencies(deps[i], p_paths);
- }
- }
- void EditorExportPlatform::_edit_files_with_filter(DirAccess *da, const Vector<String> &p_filters, Set<String> &r_list, bool exclude) {
- da->list_dir_begin();
- String cur_dir = da->get_current_dir().replace("\\", "/");
- if (!cur_dir.ends_with("/")) {
- cur_dir += "/";
- }
- String cur_dir_no_prefix = cur_dir.replace("res://", "");
- Vector<String> dirs;
- String f;
- while ((f = da->get_next()) != "") {
- if (da->current_is_dir()) {
- dirs.push_back(f);
- } else {
- String fullpath = cur_dir + f;
- // Test also against path without res:// so that filters like `file.txt` can work.
- String fullpath_no_prefix = cur_dir_no_prefix + f;
- for (int i = 0; i < p_filters.size(); ++i) {
- if (fullpath.matchn(p_filters[i]) || fullpath_no_prefix.matchn(p_filters[i])) {
- if (!exclude) {
- r_list.insert(fullpath);
- } else {
- r_list.erase(fullpath);
- }
- }
- }
- }
- }
- da->list_dir_end();
- for (int i = 0; i < dirs.size(); ++i) {
- String dir = dirs[i];
- if (dir.begins_with(".")) {
- continue;
- }
- if (EditorFileSystem::_should_skip_directory(cur_dir + dir)) {
- continue;
- }
- da->change_dir(dir);
- _edit_files_with_filter(da, p_filters, r_list, exclude);
- da->change_dir("..");
- }
- }
- void EditorExportPlatform::_edit_filter_list(Set<String> &r_list, const String &p_filter, bool exclude) {
- if (p_filter == "") {
- return;
- }
- Vector<String> split = p_filter.split(",");
- Vector<String> filters;
- for (int i = 0; i < split.size(); i++) {
- String f = split[i].strip_edges();
- if (f.is_empty()) {
- continue;
- }
- filters.push_back(f);
- }
- DirAccess *da = DirAccess::open("res://");
- ERR_FAIL_NULL(da);
- _edit_files_with_filter(da, filters, r_list, exclude);
- memdelete(da);
- }
- void EditorExportPlugin::set_export_preset(const Ref<EditorExportPreset> &p_preset) {
- if (p_preset.is_valid()) {
- export_preset = p_preset;
- }
- }
- Ref<EditorExportPreset> EditorExportPlugin::get_export_preset() const {
- return export_preset;
- }
- void EditorExportPlugin::add_file(const String &p_path, const Vector<uint8_t> &p_file, bool p_remap) {
- ExtraFile ef;
- ef.data = p_file;
- ef.path = p_path;
- ef.remap = p_remap;
- extra_files.push_back(ef);
- }
- void EditorExportPlugin::add_shared_object(const String &p_path, const Vector<String> &tags) {
- shared_objects.push_back(SharedObject(p_path, tags));
- }
- void EditorExportPlugin::add_ios_framework(const String &p_path) {
- ios_frameworks.push_back(p_path);
- }
- void EditorExportPlugin::add_ios_embedded_framework(const String &p_path) {
- ios_embedded_frameworks.push_back(p_path);
- }
- Vector<String> EditorExportPlugin::get_ios_frameworks() const {
- return ios_frameworks;
- }
- Vector<String> EditorExportPlugin::get_ios_embedded_frameworks() const {
- return ios_embedded_frameworks;
- }
- void EditorExportPlugin::add_ios_plist_content(const String &p_plist_content) {
- ios_plist_content += p_plist_content + "\n";
- }
- String EditorExportPlugin::get_ios_plist_content() const {
- return ios_plist_content;
- }
- void EditorExportPlugin::add_ios_linker_flags(const String &p_flags) {
- if (ios_linker_flags.length() > 0) {
- ios_linker_flags += ' ';
- }
- ios_linker_flags += p_flags;
- }
- String EditorExportPlugin::get_ios_linker_flags() const {
- return ios_linker_flags;
- }
- void EditorExportPlugin::add_ios_bundle_file(const String &p_path) {
- ios_bundle_files.push_back(p_path);
- }
- Vector<String> EditorExportPlugin::get_ios_bundle_files() const {
- return ios_bundle_files;
- }
- void EditorExportPlugin::add_ios_cpp_code(const String &p_code) {
- ios_cpp_code += p_code;
- }
- String EditorExportPlugin::get_ios_cpp_code() const {
- return ios_cpp_code;
- }
- void EditorExportPlugin::add_ios_project_static_lib(const String &p_path) {
- ios_project_static_libs.push_back(p_path);
- }
- Vector<String> EditorExportPlugin::get_ios_project_static_libs() const {
- return ios_project_static_libs;
- }
- void EditorExportPlugin::_export_file_script(const String &p_path, const String &p_type, const Vector<String> &p_features) {
- if (get_script_instance()) {
- get_script_instance()->call("_export_file", p_path, p_type, p_features);
- }
- }
- void EditorExportPlugin::_export_begin_script(const Vector<String> &p_features, bool p_debug, const String &p_path, int p_flags) {
- if (get_script_instance()) {
- get_script_instance()->call("_export_begin", p_features, p_debug, p_path, p_flags);
- }
- }
- void EditorExportPlugin::_export_end_script() {
- if (get_script_instance()) {
- get_script_instance()->call("_export_end");
- }
- }
- void EditorExportPlugin::_export_file(const String &p_path, const String &p_type, const Set<String> &p_features) {
- }
- void EditorExportPlugin::_export_begin(const Set<String> &p_features, bool p_debug, const String &p_path, int p_flags) {
- }
- void EditorExportPlugin::skip() {
- skipped = true;
- }
- void EditorExportPlugin::_bind_methods() {
- ClassDB::bind_method(D_METHOD("add_shared_object", "path", "tags"), &EditorExportPlugin::add_shared_object);
- ClassDB::bind_method(D_METHOD("add_ios_project_static_lib", "path"), &EditorExportPlugin::add_ios_project_static_lib);
- ClassDB::bind_method(D_METHOD("add_file", "path", "file", "remap"), &EditorExportPlugin::add_file);
- ClassDB::bind_method(D_METHOD("add_ios_framework", "path"), &EditorExportPlugin::add_ios_framework);
- ClassDB::bind_method(D_METHOD("add_ios_embedded_framework", "path"), &EditorExportPlugin::add_ios_embedded_framework);
- ClassDB::bind_method(D_METHOD("add_ios_plist_content", "plist_content"), &EditorExportPlugin::add_ios_plist_content);
- ClassDB::bind_method(D_METHOD("add_ios_linker_flags", "flags"), &EditorExportPlugin::add_ios_linker_flags);
- ClassDB::bind_method(D_METHOD("add_ios_bundle_file", "path"), &EditorExportPlugin::add_ios_bundle_file);
- ClassDB::bind_method(D_METHOD("add_ios_cpp_code", "code"), &EditorExportPlugin::add_ios_cpp_code);
- ClassDB::bind_method(D_METHOD("skip"), &EditorExportPlugin::skip);
- BIND_VMETHOD(MethodInfo("_export_file", PropertyInfo(Variant::STRING, "path"), PropertyInfo(Variant::STRING, "type"), PropertyInfo(Variant::PACKED_STRING_ARRAY, "features")));
- BIND_VMETHOD(MethodInfo("_export_begin", PropertyInfo(Variant::PACKED_STRING_ARRAY, "features"), PropertyInfo(Variant::BOOL, "is_debug"), PropertyInfo(Variant::STRING, "path"), PropertyInfo(Variant::INT, "flags")));
- BIND_VMETHOD(MethodInfo("_export_end"));
- }
- EditorExportPlugin::EditorExportPlugin() {
- skipped = false;
- }
- EditorExportPlatform::FeatureContainers EditorExportPlatform::get_feature_containers(const Ref<EditorExportPreset> &p_preset) {
- Ref<EditorExportPlatform> platform = p_preset->get_platform();
- List<String> feature_list;
- platform->get_platform_features(&feature_list);
- platform->get_preset_features(p_preset, &feature_list);
- FeatureContainers result;
- for (List<String>::Element *E = feature_list.front(); E; E = E->next()) {
- result.features.insert(E->get());
- result.features_pv.push_back(E->get());
- }
- if (p_preset->get_custom_features() != String()) {
- Vector<String> tmp_custom_list = p_preset->get_custom_features().split(",");
- for (int i = 0; i < tmp_custom_list.size(); i++) {
- String f = tmp_custom_list[i].strip_edges();
- if (f != String()) {
- result.features.insert(f);
- result.features_pv.push_back(f);
- }
- }
- }
- return result;
- }
- EditorExportPlatform::ExportNotifier::ExportNotifier(EditorExportPlatform &p_platform, const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags) {
- FeatureContainers features = p_platform.get_feature_containers(p_preset);
- Vector<Ref<EditorExportPlugin>> export_plugins = EditorExport::get_singleton()->get_export_plugins();
- //initial export plugin callback
- for (int i = 0; i < export_plugins.size(); i++) {
- if (export_plugins[i]->get_script_instance()) { //script based
- export_plugins.write[i]->_export_begin_script(features.features_pv, p_debug, p_path, p_flags);
- } else {
- export_plugins.write[i]->_export_begin(features.features, p_debug, p_path, p_flags);
- }
- }
- }
- EditorExportPlatform::ExportNotifier::~ExportNotifier() {
- Vector<Ref<EditorExportPlugin>> export_plugins = EditorExport::get_singleton()->get_export_plugins();
- for (int i = 0; i < export_plugins.size(); i++) {
- if (export_plugins[i]->get_script_instance()) {
- export_plugins.write[i]->_export_end_script();
- }
- export_plugins.write[i]->_export_end();
- }
- }
- Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> &p_preset, EditorExportSaveFunction p_func, void *p_udata, EditorExportSaveSharedObject p_so_func) {
- //figure out paths of files that will be exported
- Set<String> paths;
- Vector<String> path_remaps;
- if (p_preset->get_export_filter() == EditorExportPreset::EXPORT_ALL_RESOURCES) {
- //find stuff
- _export_find_resources(EditorFileSystem::get_singleton()->get_filesystem(), paths);
- } else if (p_preset->get_export_filter() == EditorExportPreset::EXCLUDE_SELECTED_RESOURCES) {
- _export_find_resources(EditorFileSystem::get_singleton()->get_filesystem(), paths);
- Vector<String> files = p_preset->get_files_to_export();
- for (int i = 0; i < files.size(); i++) {
- paths.erase(files[i]);
- }
- } else {
- bool scenes_only = p_preset->get_export_filter() == EditorExportPreset::EXPORT_SELECTED_SCENES;
- Vector<String> files = p_preset->get_files_to_export();
- for (int i = 0; i < files.size(); i++) {
- if (scenes_only && ResourceLoader::get_resource_type(files[i]) != "PackedScene") {
- continue;
- }
- _export_find_dependencies(files[i], paths);
- }
- // Add autoload resources and their dependencies
- List<PropertyInfo> props;
- ProjectSettings::get_singleton()->get_property_list(&props);
- for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) {
- const PropertyInfo &pi = E->get();
- if (!pi.name.begins_with("autoload/")) {
- continue;
- }
- String autoload_path = ProjectSettings::get_singleton()->get(pi.name);
- if (autoload_path.begins_with("*")) {
- autoload_path = autoload_path.substr(1);
- }
- _export_find_dependencies(autoload_path, paths);
- }
- }
- //add native icons to non-resource include list
- _edit_filter_list(paths, String("*.icns"), false);
- _edit_filter_list(paths, String("*.ico"), false);
- _edit_filter_list(paths, p_preset->get_include_filter(), false);
- _edit_filter_list(paths, p_preset->get_exclude_filter(), true);
- // Ignore import files, since these are automatically added to the jar later with the resources
- _edit_filter_list(paths, String("*.import"), true);
- // Get encryption filters.
- bool enc_pck = p_preset->get_enc_pck();
- Vector<String> enc_in_filters;
- Vector<String> enc_ex_filters;
- Vector<uint8_t> key;
- if (enc_pck) {
- Vector<String> enc_in_split = p_preset->get_enc_in_filter().split(",");
- for (int i = 0; i < enc_in_split.size(); i++) {
- String f = enc_in_split[i].strip_edges();
- if (f.is_empty()) {
- continue;
- }
- enc_in_filters.push_back(f);
- }
- Vector<String> enc_ex_split = p_preset->get_enc_ex_filter().split(",");
- for (int i = 0; i < enc_ex_split.size(); i++) {
- String f = enc_ex_split[i].strip_edges();
- if (f.is_empty()) {
- continue;
- }
- enc_ex_filters.push_back(f);
- }
- // Get encryption key.
- String script_key = p_preset->get_script_encryption_key().to_lower();
- key.resize(32);
- if (script_key.length() == 64) {
- for (int i = 0; i < 32; i++) {
- int v = 0;
- if (i * 2 < script_key.length()) {
- char32_t ct = script_key[i * 2];
- if (ct >= '0' && ct <= '9') {
- ct = ct - '0';
- } else if (ct >= 'a' && ct <= 'f') {
- ct = 10 + ct - 'a';
- }
- v |= ct << 4;
- }
- if (i * 2 + 1 < script_key.length()) {
- char32_t ct = script_key[i * 2 + 1];
- if (ct >= '0' && ct <= '9') {
- ct = ct - '0';
- } else if (ct >= 'a' && ct <= 'f') {
- ct = 10 + ct - 'a';
- }
- v |= ct;
- }
- key.write[i] = v;
- }
- }
- }
- Error err = OK;
- Vector<Ref<EditorExportPlugin>> export_plugins = EditorExport::get_singleton()->get_export_plugins();
- for (int i = 0; i < export_plugins.size(); i++) {
- export_plugins.write[i]->set_export_preset(p_preset);
- if (p_so_func) {
- for (int j = 0; j < export_plugins[i]->shared_objects.size(); j++) {
- err = p_so_func(p_udata, export_plugins[i]->shared_objects[j]);
- if (err != OK) {
- return err;
- }
- }
- }
- for (int j = 0; j < export_plugins[i]->extra_files.size(); j++) {
- err = p_func(p_udata, export_plugins[i]->extra_files[j].path, export_plugins[i]->extra_files[j].data, 0, paths.size(), enc_in_filters, enc_ex_filters, key);
- if (err != OK) {
- return err;
- }
- }
- export_plugins.write[i]->_clear();
- }
- FeatureContainers feature_containers = get_feature_containers(p_preset);
- Set<String> &features = feature_containers.features;
- Vector<String> &features_pv = feature_containers.features_pv;
- //store everything in the export medium
- int idx = 0;
- int total = paths.size();
- for (Set<String>::Element *E = paths.front(); E; E = E->next()) {
- String path = E->get();
- String type = ResourceLoader::get_resource_type(path);
- if (FileAccess::exists(path + ".import")) {
- //file is imported, replace by what it imports
- Ref<ConfigFile> config;
- config.instance();
- err = config->load(path + ".import");
- if (err != OK) {
- ERR_PRINT("Could not parse: '" + path + "', not exported.");
- continue;
- }
- String importer_type = config->get_value("remap", "importer");
- if (importer_type == "keep") {
- //just keep file as-is
- Vector<uint8_t> array = FileAccess::get_file_as_array(path);
- err = p_func(p_udata, path, array, idx, total, enc_in_filters, enc_ex_filters, key);
- if (err != OK) {
- return err;
- }
- continue;
- }
- List<String> remaps;
- config->get_section_keys("remap", &remaps);
- Set<String> remap_features;
- for (List<String>::Element *F = remaps.front(); F; F = F->next()) {
- String remap = F->get();
- String feature = remap.get_slice(".", 1);
- if (features.has(feature)) {
- remap_features.insert(feature);
- }
- }
- if (remap_features.size() > 1) {
- this->resolve_platform_feature_priorities(p_preset, remap_features);
- }
- err = OK;
- for (List<String>::Element *F = remaps.front(); F; F = F->next()) {
- String remap = F->get();
- if (remap == "path") {
- String remapped_path = config->get_value("remap", remap);
- Vector<uint8_t> array = FileAccess::get_file_as_array(remapped_path);
- err = p_func(p_udata, remapped_path, array, idx, total, enc_in_filters, enc_ex_filters, key);
- } else if (remap.begins_with("path.")) {
- String feature = remap.get_slice(".", 1);
- if (remap_features.has(feature)) {
- String remapped_path = config->get_value("remap", remap);
- Vector<uint8_t> array = FileAccess::get_file_as_array(remapped_path);
- err = p_func(p_udata, remapped_path, array, idx, total, enc_in_filters, enc_ex_filters, key);
- }
- }
- }
- if (err != OK) {
- return err;
- }
- //also save the .import file
- Vector<uint8_t> array = FileAccess::get_file_as_array(path + ".import");
- err = p_func(p_udata, path + ".import", array, idx, total, enc_in_filters, enc_ex_filters, key);
- if (err != OK) {
- return err;
- }
- } else {
- bool do_export = true;
- for (int i = 0; i < export_plugins.size(); i++) {
- if (export_plugins[i]->get_script_instance()) { //script based
- export_plugins.write[i]->_export_file_script(path, type, features_pv);
- } else {
- export_plugins.write[i]->_export_file(path, type, features);
- }
- if (p_so_func) {
- for (int j = 0; j < export_plugins[i]->shared_objects.size(); j++) {
- err = p_so_func(p_udata, export_plugins[i]->shared_objects[j]);
- if (err != OK) {
- return err;
- }
- }
- }
- for (int j = 0; j < export_plugins[i]->extra_files.size(); j++) {
- err = p_func(p_udata, export_plugins[i]->extra_files[j].path, export_plugins[i]->extra_files[j].data, idx, total, enc_in_filters, enc_ex_filters, key);
- if (err != OK) {
- return err;
- }
- if (export_plugins[i]->extra_files[j].remap) {
- do_export = false; //if remap, do not
- path_remaps.push_back(path);
- path_remaps.push_back(export_plugins[i]->extra_files[j].path);
- }
- }
- if (export_plugins[i]->skipped) {
- do_export = false;
- }
- export_plugins.write[i]->_clear();
- if (!do_export) {
- break; //apologies, not exporting
- }
- }
- //just store it as it comes
- if (do_export) {
- Vector<uint8_t> array = FileAccess::get_file_as_array(path);
- err = p_func(p_udata, path, array, idx, total, enc_in_filters, enc_ex_filters, key);
- if (err != OK) {
- return err;
- }
- }
- }
- idx++;
- }
- //save config!
- Vector<String> custom_list;
- if (p_preset->get_custom_features() != String()) {
- Vector<String> tmp_custom_list = p_preset->get_custom_features().split(",");
- for (int i = 0; i < tmp_custom_list.size(); i++) {
- String f = tmp_custom_list[i].strip_edges();
- if (f != String()) {
- custom_list.push_back(f);
- }
- }
- }
- ProjectSettings::CustomMap custom_map;
- if (path_remaps.size()) {
- if (true) { //new remap mode, use always as it's friendlier with multiple .pck exports
- for (int i = 0; i < path_remaps.size(); i += 2) {
- String from = path_remaps[i];
- String to = path_remaps[i + 1];
- String remap_file = "[remap]\n\npath=\"" + to.c_escape() + "\"\n";
- CharString utf8 = remap_file.utf8();
- Vector<uint8_t> new_file;
- new_file.resize(utf8.length());
- for (int j = 0; j < utf8.length(); j++) {
- new_file.write[j] = utf8[j];
- }
- err = p_func(p_udata, from + ".remap", new_file, idx, total, enc_in_filters, enc_ex_filters, key);
- if (err != OK) {
- return err;
- }
- }
- } else {
- //old remap mode, will still work, but it's unused because it's not multiple pck export friendly
- custom_map["path_remap/remapped_paths"] = path_remaps;
- }
- }
- // Store icon and splash images directly, they need to bypass the import system and be loaded as images
- String icon = ProjectSettings::get_singleton()->get("application/config/icon");
- String splash = ProjectSettings::get_singleton()->get("application/boot_splash/image");
- if (icon != String() && FileAccess::exists(icon)) {
- Vector<uint8_t> array = FileAccess::get_file_as_array(icon);
- err = p_func(p_udata, icon, array, idx, total, enc_in_filters, enc_ex_filters, key);
- if (err != OK) {
- return err;
- }
- }
- if (splash != String() && FileAccess::exists(splash) && icon != splash) {
- Vector<uint8_t> array = FileAccess::get_file_as_array(splash);
- err = p_func(p_udata, splash, array, idx, total, enc_in_filters, enc_ex_filters, key);
- if (err != OK) {
- return err;
- }
- }
- // Store text server data if it is supported.
- if (TS->has_feature(TextServer::FEATURE_USE_SUPPORT_DATA)) {
- bool use_data = ProjectSettings::get_singleton()->get("internationalization/locale/include_text_server_data");
- if (use_data) {
- // Try using user provided data file.
- String ts_data = "res://" + TS->get_support_data_filename();
- if (FileAccess::exists(ts_data)) {
- Vector<uint8_t> array = FileAccess::get_file_as_array(ts_data);
- err = p_func(p_udata, ts_data, array, idx, total, enc_in_filters, enc_ex_filters, key);
- if (err != OK) {
- return err;
- }
- } else {
- // Use default text server data.
- String icu_data_file = EditorPaths::get_singleton()->get_cache_dir().plus_file("tmp_icu_data");
- TS->save_support_data(icu_data_file);
- Vector<uint8_t> array = FileAccess::get_file_as_array(icu_data_file);
- err = p_func(p_udata, ts_data, array, idx, total, enc_in_filters, enc_ex_filters, key);
- DirAccess::remove_file_or_error(icu_data_file);
- if (err != OK) {
- return err;
- }
- }
- }
- }
- String config_file = "project.binary";
- String engine_cfb = EditorPaths::get_singleton()->get_cache_dir().plus_file("tmp" + config_file);
- ProjectSettings::get_singleton()->save_custom(engine_cfb, custom_map, custom_list);
- Vector<uint8_t> data = FileAccess::get_file_as_array(engine_cfb);
- DirAccess::remove_file_or_error(engine_cfb);
- return p_func(p_udata, "res://" + config_file, data, idx, total, enc_in_filters, enc_ex_filters, key);
- }
- Error EditorExportPlatform::_add_shared_object(void *p_userdata, const SharedObject &p_so) {
- PackData *pack_data = (PackData *)p_userdata;
- if (pack_data->so_files) {
- pack_data->so_files->push_back(p_so);
- }
- return OK;
- }
- Error EditorExportPlatform::save_pack(const Ref<EditorExportPreset> &p_preset, const String &p_path, Vector<SharedObject> *p_so_files, bool p_embed, int64_t *r_embedded_start, int64_t *r_embedded_size) {
- EditorProgress ep("savepack", TTR("Packing"), 102, true);
- // Create the temporary export directory if it doesn't exist.
- DirAccessRef da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
- da->make_dir_recursive(EditorPaths::get_singleton()->get_cache_dir());
- String tmppath = EditorPaths::get_singleton()->get_cache_dir().plus_file("packtmp");
- FileAccess *ftmp = FileAccess::open(tmppath, FileAccess::WRITE);
- ERR_FAIL_COND_V_MSG(!ftmp, ERR_CANT_CREATE, "Cannot create file '" + tmppath + "'.");
- PackData pd;
- pd.ep = &ep;
- pd.f = ftmp;
- pd.so_files = p_so_files;
- Error err = export_project_files(p_preset, _save_pack_file, &pd, _add_shared_object);
- memdelete(ftmp); //close tmp file
- if (err != OK) {
- DirAccess::remove_file_or_error(tmppath);
- ERR_PRINT("Failed to export project files");
- return err;
- }
- pd.file_ofs.sort(); //do sort, so we can do binary search later
- FileAccess *f;
- int64_t embed_pos = 0;
- if (!p_embed) {
- // Regular output to separate PCK file
- f = FileAccess::open(p_path, FileAccess::WRITE);
- if (!f) {
- DirAccess::remove_file_or_error(tmppath);
- ERR_FAIL_V(ERR_CANT_CREATE);
- }
- } else {
- // Append to executable
- f = FileAccess::open(p_path, FileAccess::READ_WRITE);
- if (!f) {
- DirAccess::remove_file_or_error(tmppath);
- ERR_FAIL_V(ERR_FILE_CANT_OPEN);
- }
- f->seek_end();
- embed_pos = f->get_position();
- if (r_embedded_start) {
- *r_embedded_start = embed_pos;
- }
- // Ensure embedded PCK starts at a 64-bit multiple
- int pad = f->get_position() % 8;
- for (int i = 0; i < pad; i++) {
- f->store_8(0);
- }
- }
- int64_t pck_start_pos = f->get_position();
- f->store_32(PACK_HEADER_MAGIC);
- f->store_32(PACK_FORMAT_VERSION);
- f->store_32(VERSION_MAJOR);
- f->store_32(VERSION_MINOR);
- f->store_32(VERSION_PATCH);
- uint32_t pack_flags = 0;
- bool enc_pck = p_preset->get_enc_pck();
- bool enc_directory = p_preset->get_enc_directory();
- if (enc_pck && enc_directory) {
- pack_flags |= PACK_DIR_ENCRYPTED;
- }
- f->store_32(pack_flags); // flags
- uint64_t file_base_ofs = f->get_position();
- f->store_64(0); // files base
- for (int i = 0; i < 16; i++) {
- //reserved
- f->store_32(0);
- }
- f->store_32(pd.file_ofs.size()); //amount of files
- FileAccessEncrypted *fae = nullptr;
- FileAccess *fhead = f;
- if (enc_pck && enc_directory) {
- String script_key = p_preset->get_script_encryption_key().to_lower();
- Vector<uint8_t> key;
- key.resize(32);
- if (script_key.length() == 64) {
- for (int i = 0; i < 32; i++) {
- int v = 0;
- if (i * 2 < script_key.length()) {
- char32_t ct = script_key[i * 2];
- if (ct >= '0' && ct <= '9') {
- ct = ct - '0';
- } else if (ct >= 'a' && ct <= 'f') {
- ct = 10 + ct - 'a';
- }
- v |= ct << 4;
- }
- if (i * 2 + 1 < script_key.length()) {
- char32_t ct = script_key[i * 2 + 1];
- if (ct >= '0' && ct <= '9') {
- ct = ct - '0';
- } else if (ct >= 'a' && ct <= 'f') {
- ct = 10 + ct - 'a';
- }
- v |= ct;
- }
- key.write[i] = v;
- }
- }
- fae = memnew(FileAccessEncrypted);
- ERR_FAIL_COND_V(!fae, ERR_SKIP);
- err = fae->open_and_parse(f, key, FileAccessEncrypted::MODE_WRITE_AES256, false);
- ERR_FAIL_COND_V(err != OK, ERR_SKIP);
- fhead = fae;
- }
- for (int i = 0; i < pd.file_ofs.size(); i++) {
- uint32_t string_len = pd.file_ofs[i].path_utf8.length();
- uint32_t pad = _get_pad(4, string_len);
- fhead->store_32(string_len + pad);
- fhead->store_buffer((const uint8_t *)pd.file_ofs[i].path_utf8.get_data(), string_len);
- for (uint32_t j = 0; j < pad; j++) {
- fhead->store_8(0);
- }
- fhead->store_64(pd.file_ofs[i].ofs);
- fhead->store_64(pd.file_ofs[i].size); // pay attention here, this is where file is
- fhead->store_buffer(pd.file_ofs[i].md5.ptr(), 16); //also save md5 for file
- uint32_t flags = 0;
- if (pd.file_ofs[i].encrypted) {
- flags |= PACK_FILE_ENCRYPTED;
- }
- fhead->store_32(flags);
- }
- if (fae) {
- fae->release();
- memdelete(fae);
- }
- int header_padding = _get_pad(PCK_PADDING, f->get_position());
- for (int i = 0; i < header_padding; i++) {
- f->store_8(Math::rand() % 256);
- }
- uint64_t file_base = f->get_position();
- f->seek(file_base_ofs);
- f->store_64(file_base); // update files base
- f->seek(file_base);
- // Save the rest of the data.
- ftmp = FileAccess::open(tmppath, FileAccess::READ);
- if (!ftmp) {
- memdelete(f);
- DirAccess::remove_file_or_error(tmppath);
- ERR_FAIL_V_MSG(ERR_CANT_CREATE, "Can't open file to read from path '" + String(tmppath) + "'.");
- }
- const int bufsize = 16384;
- uint8_t buf[bufsize];
- while (true) {
- uint64_t got = ftmp->get_buffer(buf, bufsize);
- if (got == 0) {
- break;
- }
- f->store_buffer(buf, got);
- }
- memdelete(ftmp);
- if (p_embed) {
- // Ensure embedded data ends at a 64-bit multiple
- uint64_t embed_end = f->get_position() - embed_pos + 12;
- uint64_t pad = embed_end % 8;
- for (uint64_t i = 0; i < pad; i++) {
- f->store_8(0);
- }
- uint64_t pck_size = f->get_position() - pck_start_pos;
- f->store_64(pck_size);
- f->store_32(PACK_HEADER_MAGIC);
- if (r_embedded_size) {
- *r_embedded_size = f->get_position() - embed_pos;
- }
- }
- memdelete(f);
- DirAccess::remove_file_or_error(tmppath);
- return OK;
- }
- Error EditorExportPlatform::save_zip(const Ref<EditorExportPreset> &p_preset, const String &p_path) {
- EditorProgress ep("savezip", TTR("Packing"), 102, true);
- FileAccess *src_f;
- zlib_filefunc_def io = zipio_create_io_from_file(&src_f);
- zipFile zip = zipOpen2(p_path.utf8().get_data(), APPEND_STATUS_CREATE, nullptr, &io);
- ZipData zd;
- zd.ep = &ep;
- zd.zip = zip;
- Error err = export_project_files(p_preset, _save_zip_file, &zd);
- if (err != OK && err != ERR_SKIP) {
- ERR_PRINT("Failed to export project files");
- }
- zipClose(zip, nullptr);
- return OK;
- }
- Error EditorExportPlatform::export_pack(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags) {
- ExportNotifier notifier(*this, p_preset, p_debug, p_path, p_flags);
- return save_pack(p_preset, p_path);
- }
- Error EditorExportPlatform::export_zip(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags) {
- ExportNotifier notifier(*this, p_preset, p_debug, p_path, p_flags);
- return save_zip(p_preset, p_path);
- }
- void EditorExportPlatform::gen_export_flags(Vector<String> &r_flags, int p_flags) {
- String host = EditorSettings::get_singleton()->get("network/debug/remote_host");
- int remote_port = (int)EditorSettings::get_singleton()->get("network/debug/remote_port");
- if (p_flags & DEBUG_FLAG_REMOTE_DEBUG_LOCALHOST) {
- host = "localhost";
- }
- if (p_flags & DEBUG_FLAG_DUMB_CLIENT) {
- int port = EditorSettings::get_singleton()->get("filesystem/file_server/port");
- String passwd = EditorSettings::get_singleton()->get("filesystem/file_server/password");
- r_flags.push_back("--remote-fs");
- r_flags.push_back(host + ":" + itos(port));
- if (passwd != "") {
- r_flags.push_back("--remote-fs-password");
- r_flags.push_back(passwd);
- }
- }
- if (p_flags & DEBUG_FLAG_REMOTE_DEBUG) {
- r_flags.push_back("--remote-debug");
- r_flags.push_back(get_debug_protocol() + host + ":" + String::num(remote_port));
- List<String> breakpoints;
- ScriptEditor::get_singleton()->get_breakpoints(&breakpoints);
- if (breakpoints.size()) {
- r_flags.push_back("--breakpoints");
- String bpoints;
- for (const List<String>::Element *E = breakpoints.front(); E; E = E->next()) {
- bpoints += E->get().replace(" ", "%20");
- if (E->next()) {
- bpoints += ",";
- }
- }
- r_flags.push_back(bpoints);
- }
- }
- if (p_flags & DEBUG_FLAG_VIEW_COLLISONS) {
- r_flags.push_back("--debug-collisions");
- }
- if (p_flags & DEBUG_FLAG_VIEW_NAVIGATION) {
- r_flags.push_back("--debug-navigation");
- }
- }
- EditorExportPlatform::EditorExportPlatform() {
- }
- ////
- EditorExport *EditorExport::singleton = nullptr;
- void EditorExport::_save() {
- Ref<ConfigFile> config;
- config.instance();
- for (int i = 0; i < export_presets.size(); i++) {
- Ref<EditorExportPreset> preset = export_presets[i];
- String section = "preset." + itos(i);
- config->set_value(section, "name", preset->get_name());
- config->set_value(section, "platform", preset->get_platform()->get_name());
- config->set_value(section, "runnable", preset->is_runnable());
- config->set_value(section, "custom_features", preset->get_custom_features());
- bool save_files = false;
- switch (preset->get_export_filter()) {
- case EditorExportPreset::EXPORT_ALL_RESOURCES: {
- config->set_value(section, "export_filter", "all_resources");
- } break;
- case EditorExportPreset::EXPORT_SELECTED_SCENES: {
- config->set_value(section, "export_filter", "scenes");
- save_files = true;
- } break;
- case EditorExportPreset::EXPORT_SELECTED_RESOURCES: {
- config->set_value(section, "export_filter", "resources");
- save_files = true;
- } break;
- case EditorExportPreset::EXCLUDE_SELECTED_RESOURCES: {
- config->set_value(section, "export_filter", "exclude");
- save_files = true;
- } break;
- }
- if (save_files) {
- Vector<String> export_files = preset->get_files_to_export();
- config->set_value(section, "export_files", export_files);
- }
- config->set_value(section, "include_filter", preset->get_include_filter());
- config->set_value(section, "exclude_filter", preset->get_exclude_filter());
- config->set_value(section, "export_path", preset->get_export_path());
- config->set_value(section, "encryption_include_filters", preset->get_enc_in_filter());
- config->set_value(section, "encryption_exclude_filters", preset->get_enc_ex_filter());
- config->set_value(section, "encrypt_pck", preset->get_enc_pck());
- config->set_value(section, "encrypt_directory", preset->get_enc_directory());
- config->set_value(section, "script_export_mode", preset->get_script_export_mode());
- config->set_value(section, "script_encryption_key", preset->get_script_encryption_key());
- String option_section = "preset." + itos(i) + ".options";
- for (const List<PropertyInfo>::Element *E = preset->get_properties().front(); E; E = E->next()) {
- config->set_value(option_section, E->get().name, preset->get(E->get().name));
- }
- }
- config->save("res://export_presets.cfg");
- }
- void EditorExport::save_presets() {
- if (block_save) {
- return;
- }
- save_timer->start();
- }
- void EditorExport::_bind_methods() {
- ADD_SIGNAL(MethodInfo("export_presets_updated"));
- }
- void EditorExport::add_export_platform(const Ref<EditorExportPlatform> &p_platform) {
- export_platforms.push_back(p_platform);
- }
- int EditorExport::get_export_platform_count() {
- return export_platforms.size();
- }
- Ref<EditorExportPlatform> EditorExport::get_export_platform(int p_idx) {
- ERR_FAIL_INDEX_V(p_idx, export_platforms.size(), Ref<EditorExportPlatform>());
- return export_platforms[p_idx];
- }
- void EditorExport::add_export_preset(const Ref<EditorExportPreset> &p_preset, int p_at_pos) {
- if (p_at_pos < 0) {
- export_presets.push_back(p_preset);
- } else {
- export_presets.insert(p_at_pos, p_preset);
- }
- }
- String EditorExportPlatform::test_etc2() const {
- String driver = ProjectSettings::get_singleton()->get("rendering/driver/driver_name");
- bool etc_supported = ProjectSettings::get_singleton()->get("rendering/textures/vram_compression/import_etc");
- bool etc2_supported = ProjectSettings::get_singleton()->get("rendering/textures/vram_compression/import_etc2");
- if (driver == "GLES2" && !etc_supported) {
- return TTR("Target platform requires 'ETC' texture compression for GLES2. Enable 'Import Etc' in Project Settings.");
- } else if (driver == "Vulkan" && !etc2_supported) {
- // FIXME: Review if this is true for Vulkan.
- return TTR("Target platform requires 'ETC2' texture compression for Vulkan. Enable 'Import Etc 2' in Project Settings.");
- }
- return String();
- }
- String EditorExportPlatform::test_etc2_or_pvrtc() const {
- String driver = ProjectSettings::get_singleton()->get("rendering/driver/driver_name");
- bool etc2_supported = ProjectSettings::get_singleton()->get("rendering/textures/vram_compression/import_etc2");
- bool pvrtc_supported = ProjectSettings::get_singleton()->get("rendering/textures/vram_compression/import_pvrtc");
- if (driver == "GLES2" && !pvrtc_supported) {
- return TTR("Target platform requires 'PVRTC' texture compression for GLES2. Enable 'Import Pvrtc' in Project Settings.");
- } else if (driver == "Vulkan" && !etc2_supported && !pvrtc_supported) {
- // FIXME: Review if this is true for Vulkan.
- return TTR("Target platform requires 'ETC2' or 'PVRTC' texture compression for Vulkan. Enable 'Import Etc 2' or 'Import Pvrtc' in Project Settings.");
- }
- return String();
- }
- int EditorExport::get_export_preset_count() const {
- return export_presets.size();
- }
- Ref<EditorExportPreset> EditorExport::get_export_preset(int p_idx) {
- ERR_FAIL_INDEX_V(p_idx, export_presets.size(), Ref<EditorExportPreset>());
- return export_presets[p_idx];
- }
- void EditorExport::remove_export_preset(int p_idx) {
- export_presets.remove(p_idx);
- save_presets();
- }
- void EditorExport::add_export_plugin(const Ref<EditorExportPlugin> &p_plugin) {
- if (export_plugins.find(p_plugin) == -1) {
- export_plugins.push_back(p_plugin);
- }
- }
- void EditorExport::remove_export_plugin(const Ref<EditorExportPlugin> &p_plugin) {
- export_plugins.erase(p_plugin);
- }
- Vector<Ref<EditorExportPlugin>> EditorExport::get_export_plugins() {
- return export_plugins;
- }
- void EditorExport::_notification(int p_what) {
- switch (p_what) {
- case NOTIFICATION_ENTER_TREE: {
- load_config();
- } break;
- case NOTIFICATION_PROCESS: {
- update_export_presets();
- } break;
- }
- }
- void EditorExport::load_config() {
- Ref<ConfigFile> config;
- config.instance();
- Error err = config->load("res://export_presets.cfg");
- if (err != OK) {
- return;
- }
- block_save = true;
- int index = 0;
- while (true) {
- String section = "preset." + itos(index);
- if (!config->has_section(section)) {
- break;
- }
- String platform = config->get_value(section, "platform");
- Ref<EditorExportPreset> preset;
- for (int i = 0; i < export_platforms.size(); i++) {
- if (export_platforms[i]->get_name() == platform) {
- preset = export_platforms.write[i]->create_preset();
- break;
- }
- }
- if (!preset.is_valid()) {
- index++;
- ERR_CONTINUE(!preset.is_valid());
- }
- preset->set_name(config->get_value(section, "name"));
- preset->set_runnable(config->get_value(section, "runnable"));
- if (config->has_section_key(section, "custom_features")) {
- preset->set_custom_features(config->get_value(section, "custom_features"));
- }
- String export_filter = config->get_value(section, "export_filter");
- bool get_files = false;
- if (export_filter == "all_resources") {
- preset->set_export_filter(EditorExportPreset::EXPORT_ALL_RESOURCES);
- } else if (export_filter == "scenes") {
- preset->set_export_filter(EditorExportPreset::EXPORT_SELECTED_SCENES);
- get_files = true;
- } else if (export_filter == "resources") {
- preset->set_export_filter(EditorExportPreset::EXPORT_SELECTED_RESOURCES);
- get_files = true;
- } else if (export_filter == "exclude") {
- preset->set_export_filter(EditorExportPreset::EXCLUDE_SELECTED_RESOURCES);
- get_files = true;
- }
- if (get_files) {
- Vector<String> files = config->get_value(section, "export_files");
- for (int i = 0; i < files.size(); i++) {
- if (!FileAccess::exists(files[i])) {
- preset->remove_export_file(files[i]);
- } else {
- preset->add_export_file(files[i]);
- }
- }
- }
- preset->set_include_filter(config->get_value(section, "include_filter"));
- preset->set_exclude_filter(config->get_value(section, "exclude_filter"));
- preset->set_export_path(config->get_value(section, "export_path", ""));
- if (config->has_section_key(section, "encrypt_pck")) {
- preset->set_enc_pck(config->get_value(section, "encrypt_pck"));
- }
- if (config->has_section_key(section, "encrypt_directory")) {
- preset->set_enc_directory(config->get_value(section, "encrypt_directory"));
- }
- if (config->has_section_key(section, "encryption_include_filters")) {
- preset->set_enc_in_filter(config->get_value(section, "encryption_include_filters"));
- }
- if (config->has_section_key(section, "encryption_exclude_filters")) {
- preset->set_enc_ex_filter(config->get_value(section, "encryption_exclude_filters"));
- }
- if (config->has_section_key(section, "script_export_mode")) {
- preset->set_script_export_mode(config->get_value(section, "script_export_mode"));
- }
- if (config->has_section_key(section, "script_encryption_key")) {
- preset->set_script_encryption_key(config->get_value(section, "script_encryption_key"));
- }
- String option_section = "preset." + itos(index) + ".options";
- List<String> options;
- config->get_section_keys(option_section, &options);
- for (List<String>::Element *E = options.front(); E; E = E->next()) {
- Variant value = config->get_value(option_section, E->get());
- preset->set(E->get(), value);
- }
- add_export_preset(preset);
- index++;
- }
- block_save = false;
- }
- void EditorExport::update_export_presets() {
- Map<StringName, List<EditorExportPlatform::ExportOption>> platform_options;
- for (int i = 0; i < export_platforms.size(); i++) {
- Ref<EditorExportPlatform> platform = export_platforms[i];
- if (platform->should_update_export_options()) {
- List<EditorExportPlatform::ExportOption> options;
- platform->get_export_options(&options);
- platform_options[platform->get_name()] = options;
- }
- }
- bool export_presets_updated = false;
- for (int i = 0; i < export_presets.size(); i++) {
- Ref<EditorExportPreset> preset = export_presets[i];
- if (platform_options.has(preset->get_platform()->get_name())) {
- export_presets_updated = true;
- List<EditorExportPlatform::ExportOption> options = platform_options[preset->get_platform()->get_name()];
- // Copy the previous preset values
- Map<StringName, Variant> previous_values = preset->values;
- // Clear the preset properties and values prior to reloading
- preset->properties.clear();
- preset->values.clear();
- for (List<EditorExportPlatform::ExportOption>::Element *E = options.front(); E; E = E->next()) {
- preset->properties.push_back(E->get().option);
- StringName option_name = E->get().option.name;
- preset->values[option_name] = previous_values.has(option_name) ? previous_values[option_name] : E->get().default_value;
- }
- }
- }
- if (export_presets_updated) {
- emit_signal(_export_presets_updated);
- }
- }
- bool EditorExport::poll_export_platforms() {
- bool changed = false;
- for (int i = 0; i < export_platforms.size(); i++) {
- if (export_platforms.write[i]->poll_export()) {
- changed = true;
- }
- }
- return changed;
- }
- EditorExport::EditorExport() {
- save_timer = memnew(Timer);
- add_child(save_timer);
- save_timer->set_wait_time(0.8);
- save_timer->set_one_shot(true);
- save_timer->connect("timeout", callable_mp(this, &EditorExport::_save));
- block_save = false;
- _export_presets_updated = "export_presets_updated";
- singleton = this;
- set_process(true);
- }
- EditorExport::~EditorExport() {
- }
- //////////
- void EditorExportPlatformPC::get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features) {
- if (p_preset->get("texture_format/s3tc")) {
- r_features->push_back("s3tc");
- }
- if (p_preset->get("texture_format/etc")) {
- r_features->push_back("etc");
- }
- if (p_preset->get("texture_format/etc2")) {
- r_features->push_back("etc2");
- }
- if (p_preset->get("binary_format/64_bits")) {
- r_features->push_back("64");
- } else {
- r_features->push_back("32");
- }
- }
- void EditorExportPlatformPC::get_export_options(List<ExportOption> *r_options) {
- r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_template/debug", PROPERTY_HINT_GLOBAL_FILE), ""));
- r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_template/release", PROPERTY_HINT_GLOBAL_FILE), ""));
- r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "binary_format/64_bits"), true));
- r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "binary_format/embed_pck"), false));
- r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "texture_format/bptc"), false));
- r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "texture_format/s3tc"), true));
- r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "texture_format/etc"), false));
- r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "texture_format/etc2"), false));
- r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "texture_format/no_bptc_fallbacks"), true));
- }
- String EditorExportPlatformPC::get_name() const {
- return name;
- }
- String EditorExportPlatformPC::get_os_name() const {
- return os_name;
- }
- Ref<Texture2D> EditorExportPlatformPC::get_logo() const {
- return logo;
- }
- bool EditorExportPlatformPC::can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const {
- String err;
- bool valid = false;
- // Look for export templates (first official, and if defined custom templates).
- bool use64 = p_preset->get("binary_format/64_bits");
- bool dvalid = exists_export_template(use64 ? debug_file_64 : debug_file_32, &err);
- bool rvalid = exists_export_template(use64 ? release_file_64 : release_file_32, &err);
- if (p_preset->get("custom_template/debug") != "") {
- dvalid = FileAccess::exists(p_preset->get("custom_template/debug"));
- if (!dvalid) {
- err += TTR("Custom debug template not found.") + "\n";
- }
- }
- if (p_preset->get("custom_template/release") != "") {
- rvalid = FileAccess::exists(p_preset->get("custom_template/release"));
- if (!rvalid) {
- err += TTR("Custom release template not found.") + "\n";
- }
- }
- valid = dvalid || rvalid;
- r_missing_templates = !valid;
- if (!err.is_empty()) {
- r_error = err;
- }
- return valid;
- }
- List<String> EditorExportPlatformPC::get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const {
- List<String> list;
- for (Map<String, String>::Element *E = extensions.front(); E; E = E->next()) {
- if (p_preset->get(E->key())) {
- list.push_back(extensions[E->key()]);
- return list;
- }
- }
- if (extensions.has("default")) {
- list.push_back(extensions["default"]);
- return list;
- }
- return list;
- }
- Error EditorExportPlatformPC::export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags) {
- ExportNotifier notifier(*this, p_preset, p_debug, p_path, p_flags);
- if (!DirAccess::exists(p_path.get_base_dir())) {
- return ERR_FILE_BAD_PATH;
- }
- String custom_debug = p_preset->get("custom_template/debug");
- String custom_release = p_preset->get("custom_template/release");
- String template_path = p_debug ? custom_debug : custom_release;
- template_path = template_path.strip_edges();
- if (template_path == String()) {
- if (p_preset->get("binary_format/64_bits")) {
- if (p_debug) {
- template_path = find_export_template(debug_file_64);
- } else {
- template_path = find_export_template(release_file_64);
- }
- } else {
- if (p_debug) {
- template_path = find_export_template(debug_file_32);
- } else {
- template_path = find_export_template(release_file_32);
- }
- }
- }
- if (template_path != String() && !FileAccess::exists(template_path)) {
- EditorNode::get_singleton()->show_warning(TTR("Template file not found:") + "\n" + template_path);
- return ERR_FILE_NOT_FOUND;
- }
- DirAccess *da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
- Error err = da->copy(template_path, p_path, get_chmod_flags());
- memdelete(da);
- if (err == OK) {
- String pck_path;
- if (p_preset->get("binary_format/embed_pck")) {
- pck_path = p_path;
- } else {
- pck_path = p_path.get_basename() + ".pck";
- }
- Vector<SharedObject> so_files;
- int64_t embedded_pos;
- int64_t embedded_size;
- err = save_pack(p_preset, pck_path, &so_files, p_preset->get("binary_format/embed_pck"), &embedded_pos, &embedded_size);
- if (err == OK && p_preset->get("binary_format/embed_pck")) {
- if (embedded_size >= 0x100000000 && !p_preset->get("binary_format/64_bits")) {
- EditorNode::get_singleton()->show_warning(TTR("On 32-bit exports the embedded PCK cannot be bigger than 4 GiB."));
- return ERR_INVALID_PARAMETER;
- }
- FixUpEmbeddedPckFunc fixup_func = get_fixup_embedded_pck_func();
- if (fixup_func) {
- err = fixup_func(p_path, embedded_pos, embedded_size);
- }
- }
- if (err == OK && !so_files.is_empty()) {
- //if shared object files, copy them
- da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
- for (int i = 0; i < so_files.size() && err == OK; i++) {
- err = da->copy(so_files[i].path, p_path.get_base_dir().plus_file(so_files[i].path.get_file()));
- if (err == OK) {
- err = sign_shared_object(p_preset, p_debug, p_path.get_base_dir().plus_file(so_files[i].path.get_file()));
- }
- }
- memdelete(da);
- }
- }
- return err;
- }
- Error EditorExportPlatformPC::sign_shared_object(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path) {
- return OK;
- }
- void EditorExportPlatformPC::set_extension(const String &p_extension, const String &p_feature_key) {
- extensions[p_feature_key] = p_extension;
- }
- void EditorExportPlatformPC::set_name(const String &p_name) {
- name = p_name;
- }
- void EditorExportPlatformPC::set_os_name(const String &p_name) {
- os_name = p_name;
- }
- void EditorExportPlatformPC::set_logo(const Ref<Texture2D> &p_logo) {
- logo = p_logo;
- }
- void EditorExportPlatformPC::set_release_64(const String &p_file) {
- release_file_64 = p_file;
- }
- void EditorExportPlatformPC::set_release_32(const String &p_file) {
- release_file_32 = p_file;
- }
- void EditorExportPlatformPC::set_debug_64(const String &p_file) {
- debug_file_64 = p_file;
- }
- void EditorExportPlatformPC::set_debug_32(const String &p_file) {
- debug_file_32 = p_file;
- }
- void EditorExportPlatformPC::get_platform_features(List<String> *r_features) {
- r_features->push_back("pc"); //all pcs support "pc"
- r_features->push_back("s3tc"); //all pcs support "s3tc" compression
- r_features->push_back(get_os_name()); //OS name is a feature
- }
- void EditorExportPlatformPC::resolve_platform_feature_priorities(const Ref<EditorExportPreset> &p_preset, Set<String> &p_features) {
- if (p_features.has("bptc")) {
- if (p_preset->has("texture_format/no_bptc_fallbacks")) {
- p_features.erase("s3tc");
- }
- }
- }
- int EditorExportPlatformPC::get_chmod_flags() const {
- return chmod_flags;
- }
- void EditorExportPlatformPC::set_chmod_flags(int p_flags) {
- chmod_flags = p_flags;
- }
- EditorExportPlatformPC::FixUpEmbeddedPckFunc EditorExportPlatformPC::get_fixup_embedded_pck_func() const {
- return fixup_embedded_pck_func;
- }
- void EditorExportPlatformPC::set_fixup_embedded_pck_func(FixUpEmbeddedPckFunc p_fixup_embedded_pck_func) {
- fixup_embedded_pck_func = p_fixup_embedded_pck_func;
- }
- EditorExportPlatformPC::EditorExportPlatformPC() {
- chmod_flags = -1;
- fixup_embedded_pck_func = nullptr;
- }
- ///////////////////////
- void EditorExportTextSceneToBinaryPlugin::_export_file(const String &p_path, const String &p_type, const Set<String> &p_features) {
- String extension = p_path.get_extension().to_lower();
- if (extension != "tres" && extension != "tscn") {
- return;
- }
- bool convert = GLOBAL_GET("editor/export/convert_text_resources_to_binary");
- if (!convert) {
- return;
- }
- String tmp_path = EditorPaths::get_singleton()->get_cache_dir().plus_file("tmpfile.res");
- Error err = ResourceFormatLoaderText::convert_file_to_binary(p_path, tmp_path);
- if (err != OK) {
- DirAccess::remove_file_or_error(tmp_path);
- ERR_FAIL();
- }
- Vector<uint8_t> data = FileAccess::get_file_as_array(tmp_path);
- if (data.size() == 0) {
- DirAccess::remove_file_or_error(tmp_path);
- ERR_FAIL();
- }
- DirAccess::remove_file_or_error(tmp_path);
- add_file(p_path + ".converted.res", data, true);
- }
- EditorExportTextSceneToBinaryPlugin::EditorExportTextSceneToBinaryPlugin() {
- GLOBAL_DEF("editor/export/convert_text_resources_to_binary", false);
- }
|