editor_export.cpp 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796
  1. /*************************************************************************/
  2. /* editor_export.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
  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. #include "editor_export.h"
  31. #include "core/crypto/crypto_core.h"
  32. #include "core/io/config_file.h"
  33. #include "core/io/file_access_pack.h" // PACK_HEADER_MAGIC, PACK_FORMAT_VERSION
  34. #include "core/io/resource_loader.h"
  35. #include "core/io/resource_saver.h"
  36. #include "core/io/zip_io.h"
  37. #include "core/os/dir_access.h"
  38. #include "core/os/file_access.h"
  39. #include "core/project_settings.h"
  40. #include "core/script_language.h"
  41. #include "core/version.h"
  42. #include "editor/editor_file_system.h"
  43. #include "editor/plugins/script_editor_plugin.h"
  44. #include "editor_node.h"
  45. #include "editor_settings.h"
  46. #include "scene/resources/resource_format_text.h"
  47. static int _get_pad(int p_alignment, int p_n) {
  48. int rest = p_n % p_alignment;
  49. int pad = 0;
  50. if (rest > 0) {
  51. pad = p_alignment - rest;
  52. };
  53. return pad;
  54. }
  55. #define PCK_PADDING 16
  56. bool EditorExportPreset::_set(const StringName &p_name, const Variant &p_value) {
  57. if (values.has(p_name)) {
  58. values[p_name] = p_value;
  59. EditorExport::singleton->save_presets();
  60. return true;
  61. }
  62. return false;
  63. }
  64. bool EditorExportPreset::_get(const StringName &p_name, Variant &r_ret) const {
  65. if (values.has(p_name)) {
  66. r_ret = values[p_name];
  67. return true;
  68. }
  69. return false;
  70. }
  71. void EditorExportPreset::_get_property_list(List<PropertyInfo> *p_list) const {
  72. for (const List<PropertyInfo>::Element *E = properties.front(); E; E = E->next()) {
  73. if (platform->get_option_visibility(E->get().name, values)) {
  74. p_list->push_back(E->get());
  75. }
  76. }
  77. }
  78. Ref<EditorExportPlatform> EditorExportPreset::get_platform() const {
  79. return platform;
  80. }
  81. void EditorExportPreset::update_files_to_export() {
  82. Vector<String> to_remove;
  83. for (Set<String>::Element *E = selected_files.front(); E; E = E->next()) {
  84. if (!FileAccess::exists(E->get())) {
  85. to_remove.push_back(E->get());
  86. }
  87. }
  88. for (int i = 0; i < to_remove.size(); ++i) {
  89. selected_files.erase(to_remove[i]);
  90. }
  91. }
  92. Vector<String> EditorExportPreset::get_files_to_export() const {
  93. Vector<String> files;
  94. for (Set<String>::Element *E = selected_files.front(); E; E = E->next()) {
  95. files.push_back(E->get());
  96. }
  97. return files;
  98. }
  99. void EditorExportPreset::set_name(const String &p_name) {
  100. name = p_name;
  101. EditorExport::singleton->save_presets();
  102. }
  103. String EditorExportPreset::get_name() const {
  104. return name;
  105. }
  106. void EditorExportPreset::set_runnable(bool p_enable) {
  107. runnable = p_enable;
  108. EditorExport::singleton->save_presets();
  109. }
  110. bool EditorExportPreset::is_runnable() const {
  111. return runnable;
  112. }
  113. void EditorExportPreset::set_export_filter(ExportFilter p_filter) {
  114. export_filter = p_filter;
  115. EditorExport::singleton->save_presets();
  116. }
  117. EditorExportPreset::ExportFilter EditorExportPreset::get_export_filter() const {
  118. return export_filter;
  119. }
  120. void EditorExportPreset::set_include_filter(const String &p_include) {
  121. include_filter = p_include;
  122. EditorExport::singleton->save_presets();
  123. }
  124. String EditorExportPreset::get_include_filter() const {
  125. return include_filter;
  126. }
  127. void EditorExportPreset::set_export_path(const String &p_path) {
  128. export_path = p_path;
  129. /* NOTE(SonerSound): if there is a need to implement a PropertyHint that specifically indicates a relative path,
  130. * this should be removed. */
  131. if (export_path.is_abs_path()) {
  132. String res_path = OS::get_singleton()->get_resource_dir();
  133. export_path = res_path.path_to_file(export_path);
  134. }
  135. EditorExport::singleton->save_presets();
  136. }
  137. String EditorExportPreset::get_export_path() const {
  138. return export_path;
  139. }
  140. void EditorExportPreset::set_exclude_filter(const String &p_exclude) {
  141. exclude_filter = p_exclude;
  142. EditorExport::singleton->save_presets();
  143. }
  144. String EditorExportPreset::get_exclude_filter() const {
  145. return exclude_filter;
  146. }
  147. void EditorExportPreset::add_export_file(const String &p_path) {
  148. selected_files.insert(p_path);
  149. EditorExport::singleton->save_presets();
  150. }
  151. void EditorExportPreset::remove_export_file(const String &p_path) {
  152. selected_files.erase(p_path);
  153. EditorExport::singleton->save_presets();
  154. }
  155. bool EditorExportPreset::has_export_file(const String &p_path) {
  156. return selected_files.has(p_path);
  157. }
  158. void EditorExportPreset::set_custom_features(const String &p_custom_features) {
  159. custom_features = p_custom_features;
  160. EditorExport::singleton->save_presets();
  161. }
  162. String EditorExportPreset::get_custom_features() const {
  163. return custom_features;
  164. }
  165. void EditorExportPreset::set_script_export_mode(int p_mode) {
  166. script_mode = p_mode;
  167. EditorExport::singleton->save_presets();
  168. }
  169. int EditorExportPreset::get_script_export_mode() const {
  170. return script_mode;
  171. }
  172. void EditorExportPreset::set_script_encryption_key(const String &p_key) {
  173. script_key = p_key;
  174. EditorExport::singleton->save_presets();
  175. }
  176. String EditorExportPreset::get_script_encryption_key() const {
  177. return script_key;
  178. }
  179. EditorExportPreset::EditorExportPreset() :
  180. export_filter(EXPORT_ALL_RESOURCES),
  181. export_path(""),
  182. runnable(false),
  183. script_mode(MODE_SCRIPT_COMPILED) {
  184. }
  185. ///////////////////////////////////
  186. void EditorExportPlatform::gen_debug_flags(Vector<String> &r_flags, int p_flags) {
  187. String host = EditorSettings::get_singleton()->get("network/debug/remote_host");
  188. int remote_port = (int)EditorSettings::get_singleton()->get("network/debug/remote_port");
  189. if (p_flags & DEBUG_FLAG_REMOTE_DEBUG_LOCALHOST) {
  190. host = "localhost";
  191. }
  192. if (p_flags & DEBUG_FLAG_DUMB_CLIENT) {
  193. int port = EditorSettings::get_singleton()->get("filesystem/file_server/port");
  194. String passwd = EditorSettings::get_singleton()->get("filesystem/file_server/password");
  195. r_flags.push_back("--remote-fs");
  196. r_flags.push_back(host + ":" + itos(port));
  197. if (passwd != "") {
  198. r_flags.push_back("--remote-fs-password");
  199. r_flags.push_back(passwd);
  200. }
  201. }
  202. if (p_flags & DEBUG_FLAG_REMOTE_DEBUG) {
  203. r_flags.push_back("--remote-debug");
  204. r_flags.push_back(host + ":" + String::num(remote_port));
  205. List<String> breakpoints;
  206. ScriptEditor::get_singleton()->get_breakpoints(&breakpoints);
  207. if (breakpoints.size()) {
  208. r_flags.push_back("--breakpoints");
  209. String bpoints;
  210. for (const List<String>::Element *E = breakpoints.front(); E; E = E->next()) {
  211. bpoints += E->get().replace(" ", "%20");
  212. if (E->next()) {
  213. bpoints += ",";
  214. }
  215. }
  216. r_flags.push_back(bpoints);
  217. }
  218. }
  219. if (p_flags & DEBUG_FLAG_VIEW_COLLISONS) {
  220. r_flags.push_back("--debug-collisions");
  221. }
  222. if (p_flags & DEBUG_FLAG_VIEW_NAVIGATION) {
  223. r_flags.push_back("--debug-navigation");
  224. }
  225. }
  226. Error EditorExportPlatform::_save_pack_file(void *p_userdata, const String &p_path, const Vector<uint8_t> &p_data, int p_file, int p_total) {
  227. ERR_FAIL_COND_V_MSG(p_total < 1, ERR_PARAMETER_RANGE_ERROR, "Must select at least one file to export.");
  228. PackData *pd = (PackData *)p_userdata;
  229. SavedData sd;
  230. sd.path_utf8 = p_path.utf8();
  231. sd.ofs = pd->f->get_position();
  232. sd.size = p_data.size();
  233. pd->f->store_buffer(p_data.ptr(), p_data.size());
  234. int pad = _get_pad(PCK_PADDING, sd.size);
  235. for (int i = 0; i < pad; i++) {
  236. pd->f->store_8(0);
  237. }
  238. {
  239. unsigned char hash[16];
  240. CryptoCore::md5(p_data.ptr(), p_data.size(), hash);
  241. sd.md5.resize(16);
  242. for (int i = 0; i < 16; i++) {
  243. sd.md5.write[i] = hash[i];
  244. }
  245. }
  246. pd->file_ofs.push_back(sd);
  247. if (pd->ep->step(TTR("Storing File:") + " " + p_path, 2 + p_file * 100 / p_total, false)) {
  248. return ERR_SKIP;
  249. }
  250. return OK;
  251. }
  252. Error EditorExportPlatform::_save_zip_file(void *p_userdata, const String &p_path, const Vector<uint8_t> &p_data, int p_file, int p_total) {
  253. ERR_FAIL_COND_V_MSG(p_total < 1, ERR_PARAMETER_RANGE_ERROR, "Must select at least one file to export.");
  254. String path = p_path.replace_first("res://", "");
  255. ZipData *zd = (ZipData *)p_userdata;
  256. zipFile zip = (zipFile)zd->zip;
  257. zipOpenNewFileInZip(zip,
  258. path.utf8().get_data(),
  259. nullptr,
  260. nullptr,
  261. 0,
  262. nullptr,
  263. 0,
  264. nullptr,
  265. Z_DEFLATED,
  266. Z_DEFAULT_COMPRESSION);
  267. zipWriteInFileInZip(zip, p_data.ptr(), p_data.size());
  268. zipCloseFileInZip(zip);
  269. if (zd->ep->step(TTR("Storing File:") + " " + p_path, 2 + p_file * 100 / p_total, false)) {
  270. return ERR_SKIP;
  271. }
  272. return OK;
  273. }
  274. Ref<ImageTexture> EditorExportPlatform::get_option_icon(int p_index) const {
  275. Ref<Theme> theme = EditorNode::get_singleton()->get_editor_theme();
  276. ERR_FAIL_COND_V(theme.is_null(), Ref<ImageTexture>());
  277. return theme->get_icon("Play", "EditorIcons");
  278. }
  279. String EditorExportPlatform::find_export_template(String template_file_name, String *err) const {
  280. String current_version = VERSION_FULL_CONFIG;
  281. String template_path = EditorSettings::get_singleton()->get_templates_dir().plus_file(current_version).plus_file(template_file_name);
  282. if (FileAccess::exists(template_path)) {
  283. return template_path;
  284. }
  285. // Not found
  286. if (err) {
  287. *err += TTR("No export template found at the expected path:") + "\n" + template_path + "\n";
  288. }
  289. return String();
  290. }
  291. bool EditorExportPlatform::exists_export_template(String template_file_name, String *err) const {
  292. return find_export_template(template_file_name, err) != "";
  293. }
  294. Ref<EditorExportPreset> EditorExportPlatform::create_preset() {
  295. Ref<EditorExportPreset> preset;
  296. preset.instance();
  297. preset->platform = Ref<EditorExportPlatform>(this);
  298. List<ExportOption> options;
  299. get_export_options(&options);
  300. for (List<ExportOption>::Element *E = options.front(); E; E = E->next()) {
  301. preset->properties.push_back(E->get().option);
  302. preset->values[E->get().option.name] = E->get().default_value;
  303. }
  304. return preset;
  305. }
  306. void EditorExportPlatform::_export_find_resources(EditorFileSystemDirectory *p_dir, Set<String> &p_paths) {
  307. for (int i = 0; i < p_dir->get_subdir_count(); i++) {
  308. _export_find_resources(p_dir->get_subdir(i), p_paths);
  309. }
  310. for (int i = 0; i < p_dir->get_file_count(); i++) {
  311. p_paths.insert(p_dir->get_file_path(i));
  312. }
  313. }
  314. void EditorExportPlatform::_export_find_dependencies(const String &p_path, Set<String> &p_paths) {
  315. if (p_paths.has(p_path)) {
  316. return;
  317. }
  318. p_paths.insert(p_path);
  319. EditorFileSystemDirectory *dir;
  320. int file_idx;
  321. dir = EditorFileSystem::get_singleton()->find_file(p_path, &file_idx);
  322. if (!dir) {
  323. return;
  324. }
  325. Vector<String> deps = dir->get_file_deps(file_idx);
  326. for (int i = 0; i < deps.size(); i++) {
  327. _export_find_dependencies(deps[i], p_paths);
  328. }
  329. }
  330. void EditorExportPlatform::_edit_files_with_filter(DirAccess *da, const Vector<String> &p_filters, Set<String> &r_list, bool exclude) {
  331. da->list_dir_begin();
  332. String cur_dir = da->get_current_dir().replace("\\", "/");
  333. if (!cur_dir.ends_with("/")) {
  334. cur_dir += "/";
  335. }
  336. String cur_dir_no_prefix = cur_dir.replace("res://", "");
  337. Vector<String> dirs;
  338. String f;
  339. while ((f = da->get_next()) != "") {
  340. if (da->current_is_dir()) {
  341. dirs.push_back(f);
  342. } else {
  343. String fullpath = cur_dir + f;
  344. // Test also against path without res:// so that filters like `file.txt` can work.
  345. String fullpath_no_prefix = cur_dir_no_prefix + f;
  346. for (int i = 0; i < p_filters.size(); ++i) {
  347. if (fullpath.matchn(p_filters[i]) || fullpath_no_prefix.matchn(p_filters[i])) {
  348. if (!exclude) {
  349. r_list.insert(fullpath);
  350. } else {
  351. r_list.erase(fullpath);
  352. }
  353. }
  354. }
  355. }
  356. }
  357. da->list_dir_end();
  358. for (int i = 0; i < dirs.size(); ++i) {
  359. String dir = dirs[i];
  360. if (dir.begins_with(".")) {
  361. continue;
  362. }
  363. if (EditorFileSystem::_should_skip_directory(cur_dir + dir)) {
  364. continue;
  365. }
  366. da->change_dir(dir);
  367. _edit_files_with_filter(da, p_filters, r_list, exclude);
  368. da->change_dir("..");
  369. }
  370. }
  371. void EditorExportPlatform::_edit_filter_list(Set<String> &r_list, const String &p_filter, bool exclude) {
  372. if (p_filter == "") {
  373. return;
  374. }
  375. Vector<String> split = p_filter.split(",");
  376. Vector<String> filters;
  377. for (int i = 0; i < split.size(); i++) {
  378. String f = split[i].strip_edges();
  379. if (f.empty()) {
  380. continue;
  381. }
  382. filters.push_back(f);
  383. }
  384. DirAccess *da = DirAccess::open("res://");
  385. ERR_FAIL_NULL(da);
  386. _edit_files_with_filter(da, filters, r_list, exclude);
  387. memdelete(da);
  388. }
  389. void EditorExportPlugin::set_export_preset(const Ref<EditorExportPreset> &p_preset) {
  390. if (p_preset.is_valid()) {
  391. export_preset = p_preset;
  392. }
  393. }
  394. Ref<EditorExportPreset> EditorExportPlugin::get_export_preset() const {
  395. return export_preset;
  396. }
  397. void EditorExportPlugin::add_file(const String &p_path, const Vector<uint8_t> &p_file, bool p_remap) {
  398. ExtraFile ef;
  399. ef.data = p_file;
  400. ef.path = p_path;
  401. ef.remap = p_remap;
  402. extra_files.push_back(ef);
  403. }
  404. void EditorExportPlugin::add_shared_object(const String &p_path, const Vector<String> &tags) {
  405. shared_objects.push_back(SharedObject(p_path, tags));
  406. }
  407. void EditorExportPlugin::add_ios_framework(const String &p_path) {
  408. ios_frameworks.push_back(p_path);
  409. }
  410. void EditorExportPlugin::add_ios_embedded_framework(const String &p_path) {
  411. ios_embedded_frameworks.push_back(p_path);
  412. }
  413. Vector<String> EditorExportPlugin::get_ios_frameworks() const {
  414. return ios_frameworks;
  415. }
  416. Vector<String> EditorExportPlugin::get_ios_embedded_frameworks() const {
  417. return ios_embedded_frameworks;
  418. }
  419. void EditorExportPlugin::add_ios_plist_content(const String &p_plist_content) {
  420. ios_plist_content += p_plist_content + "\n";
  421. }
  422. String EditorExportPlugin::get_ios_plist_content() const {
  423. return ios_plist_content;
  424. }
  425. void EditorExportPlugin::add_ios_linker_flags(const String &p_flags) {
  426. if (ios_linker_flags.length() > 0) {
  427. ios_linker_flags += ' ';
  428. }
  429. ios_linker_flags += p_flags;
  430. }
  431. String EditorExportPlugin::get_ios_linker_flags() const {
  432. return ios_linker_flags;
  433. }
  434. void EditorExportPlugin::add_ios_bundle_file(const String &p_path) {
  435. ios_bundle_files.push_back(p_path);
  436. }
  437. Vector<String> EditorExportPlugin::get_ios_bundle_files() const {
  438. return ios_bundle_files;
  439. }
  440. void EditorExportPlugin::add_ios_cpp_code(const String &p_code) {
  441. ios_cpp_code += p_code;
  442. }
  443. String EditorExportPlugin::get_ios_cpp_code() const {
  444. return ios_cpp_code;
  445. }
  446. void EditorExportPlugin::add_ios_project_static_lib(const String &p_path) {
  447. ios_project_static_libs.push_back(p_path);
  448. }
  449. Vector<String> EditorExportPlugin::get_ios_project_static_libs() const {
  450. return ios_project_static_libs;
  451. }
  452. void EditorExportPlugin::_export_file_script(const String &p_path, const String &p_type, const PoolVector<String> &p_features) {
  453. if (get_script_instance()) {
  454. get_script_instance()->call("_export_file", p_path, p_type, p_features);
  455. }
  456. }
  457. void EditorExportPlugin::_export_begin_script(const PoolVector<String> &p_features, bool p_debug, const String &p_path, int p_flags) {
  458. if (get_script_instance()) {
  459. get_script_instance()->call("_export_begin", p_features, p_debug, p_path, p_flags);
  460. }
  461. }
  462. void EditorExportPlugin::_export_end_script() {
  463. if (get_script_instance()) {
  464. get_script_instance()->call("_export_end");
  465. }
  466. }
  467. void EditorExportPlugin::_export_file(const String &p_path, const String &p_type, const Set<String> &p_features) {
  468. }
  469. void EditorExportPlugin::_export_begin(const Set<String> &p_features, bool p_debug, const String &p_path, int p_flags) {
  470. }
  471. void EditorExportPlugin::skip() {
  472. skipped = true;
  473. }
  474. void EditorExportPlugin::_bind_methods() {
  475. ClassDB::bind_method(D_METHOD("add_shared_object", "path", "tags"), &EditorExportPlugin::add_shared_object);
  476. ClassDB::bind_method(D_METHOD("add_ios_project_static_lib", "path"), &EditorExportPlugin::add_ios_project_static_lib);
  477. ClassDB::bind_method(D_METHOD("add_file", "path", "file", "remap"), &EditorExportPlugin::add_file);
  478. ClassDB::bind_method(D_METHOD("add_ios_framework", "path"), &EditorExportPlugin::add_ios_framework);
  479. ClassDB::bind_method(D_METHOD("add_ios_embedded_framework", "path"), &EditorExportPlugin::add_ios_embedded_framework);
  480. ClassDB::bind_method(D_METHOD("add_ios_plist_content", "plist_content"), &EditorExportPlugin::add_ios_plist_content);
  481. ClassDB::bind_method(D_METHOD("add_ios_linker_flags", "flags"), &EditorExportPlugin::add_ios_linker_flags);
  482. ClassDB::bind_method(D_METHOD("add_ios_bundle_file", "path"), &EditorExportPlugin::add_ios_bundle_file);
  483. ClassDB::bind_method(D_METHOD("add_ios_cpp_code", "code"), &EditorExportPlugin::add_ios_cpp_code);
  484. ClassDB::bind_method(D_METHOD("skip"), &EditorExportPlugin::skip);
  485. BIND_VMETHOD(MethodInfo("_export_file", PropertyInfo(Variant::STRING, "path"), PropertyInfo(Variant::STRING, "type"), PropertyInfo(Variant::POOL_STRING_ARRAY, "features")));
  486. BIND_VMETHOD(MethodInfo("_export_begin", PropertyInfo(Variant::POOL_STRING_ARRAY, "features"), PropertyInfo(Variant::BOOL, "is_debug"), PropertyInfo(Variant::STRING, "path"), PropertyInfo(Variant::INT, "flags")));
  487. BIND_VMETHOD(MethodInfo("_export_end"));
  488. }
  489. EditorExportPlugin::EditorExportPlugin() {
  490. skipped = false;
  491. }
  492. EditorExportPlatform::FeatureContainers EditorExportPlatform::get_feature_containers(const Ref<EditorExportPreset> &p_preset) {
  493. Ref<EditorExportPlatform> platform = p_preset->get_platform();
  494. List<String> feature_list;
  495. platform->get_platform_features(&feature_list);
  496. platform->get_preset_features(p_preset, &feature_list);
  497. FeatureContainers result;
  498. for (List<String>::Element *E = feature_list.front(); E; E = E->next()) {
  499. result.features.insert(E->get());
  500. result.features_pv.push_back(E->get());
  501. }
  502. if (p_preset->get_custom_features() != String()) {
  503. Vector<String> tmp_custom_list = p_preset->get_custom_features().split(",");
  504. for (int i = 0; i < tmp_custom_list.size(); i++) {
  505. String f = tmp_custom_list[i].strip_edges();
  506. if (f != String()) {
  507. result.features.insert(f);
  508. result.features_pv.push_back(f);
  509. }
  510. }
  511. }
  512. return result;
  513. }
  514. EditorExportPlatform::ExportNotifier::ExportNotifier(EditorExportPlatform &p_platform, const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags) {
  515. FeatureContainers features = p_platform.get_feature_containers(p_preset);
  516. Vector<Ref<EditorExportPlugin>> export_plugins = EditorExport::get_singleton()->get_export_plugins();
  517. //initial export plugin callback
  518. for (int i = 0; i < export_plugins.size(); i++) {
  519. if (export_plugins[i]->get_script_instance()) { //script based
  520. export_plugins.write[i]->_export_begin_script(features.features_pv, p_debug, p_path, p_flags);
  521. } else {
  522. export_plugins.write[i]->_export_begin(features.features, p_debug, p_path, p_flags);
  523. }
  524. }
  525. }
  526. EditorExportPlatform::ExportNotifier::~ExportNotifier() {
  527. Vector<Ref<EditorExportPlugin>> export_plugins = EditorExport::get_singleton()->get_export_plugins();
  528. for (int i = 0; i < export_plugins.size(); i++) {
  529. if (export_plugins[i]->get_script_instance()) {
  530. export_plugins.write[i]->_export_end_script();
  531. }
  532. export_plugins.write[i]->_export_end();
  533. }
  534. }
  535. Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> &p_preset, EditorExportSaveFunction p_func, void *p_udata, EditorExportSaveSharedObject p_so_func) {
  536. //figure out paths of files that will be exported
  537. Set<String> paths;
  538. Vector<String> path_remaps;
  539. if (p_preset->get_export_filter() == EditorExportPreset::EXPORT_ALL_RESOURCES) {
  540. //find stuff
  541. _export_find_resources(EditorFileSystem::get_singleton()->get_filesystem(), paths);
  542. } else {
  543. bool scenes_only = p_preset->get_export_filter() == EditorExportPreset::EXPORT_SELECTED_SCENES;
  544. Vector<String> files = p_preset->get_files_to_export();
  545. for (int i = 0; i < files.size(); i++) {
  546. if (scenes_only && ResourceLoader::get_resource_type(files[i]) != "PackedScene") {
  547. continue;
  548. }
  549. _export_find_dependencies(files[i], paths);
  550. }
  551. // Add autoload resources and their dependencies
  552. List<PropertyInfo> props;
  553. ProjectSettings::get_singleton()->get_property_list(&props);
  554. for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) {
  555. const PropertyInfo &pi = E->get();
  556. if (!pi.name.begins_with("autoload/")) {
  557. continue;
  558. }
  559. String autoload_path = ProjectSettings::get_singleton()->get(pi.name);
  560. if (autoload_path.begins_with("*")) {
  561. autoload_path = autoload_path.substr(1);
  562. }
  563. _export_find_dependencies(autoload_path, paths);
  564. }
  565. }
  566. //add native icons to non-resource include list
  567. _edit_filter_list(paths, String("*.icns"), false);
  568. _edit_filter_list(paths, String("*.ico"), false);
  569. _edit_filter_list(paths, p_preset->get_include_filter(), false);
  570. _edit_filter_list(paths, p_preset->get_exclude_filter(), true);
  571. // Ignore import files, since these are automatically added to the jar later with the resources
  572. _edit_filter_list(paths, String("*.import"), true);
  573. Error err = OK;
  574. Vector<Ref<EditorExportPlugin>> export_plugins = EditorExport::get_singleton()->get_export_plugins();
  575. for (int i = 0; i < export_plugins.size(); i++) {
  576. export_plugins.write[i]->set_export_preset(p_preset);
  577. if (p_so_func) {
  578. for (int j = 0; j < export_plugins[i]->shared_objects.size(); j++) {
  579. err = p_so_func(p_udata, export_plugins[i]->shared_objects[j]);
  580. if (err != OK) {
  581. return err;
  582. }
  583. }
  584. }
  585. for (int j = 0; j < export_plugins[i]->extra_files.size(); j++) {
  586. err = p_func(p_udata, export_plugins[i]->extra_files[j].path, export_plugins[i]->extra_files[j].data, 0, paths.size());
  587. if (err != OK) {
  588. return err;
  589. }
  590. }
  591. export_plugins.write[i]->_clear();
  592. }
  593. FeatureContainers feature_containers = get_feature_containers(p_preset);
  594. Set<String> &features = feature_containers.features;
  595. PoolVector<String> &features_pv = feature_containers.features_pv;
  596. //store everything in the export medium
  597. int idx = 0;
  598. int total = paths.size();
  599. for (Set<String>::Element *E = paths.front(); E; E = E->next()) {
  600. String path = E->get();
  601. String type = ResourceLoader::get_resource_type(path);
  602. if (FileAccess::exists(path + ".import")) {
  603. //file is imported, replace by what it imports
  604. Ref<ConfigFile> config;
  605. config.instance();
  606. err = config->load(path + ".import");
  607. if (err != OK) {
  608. ERR_PRINT("Could not parse: '" + path + "', not exported.");
  609. continue;
  610. }
  611. String importer_type = config->get_value("remap", "importer");
  612. if (importer_type == "keep") {
  613. //just keep file as-is
  614. Vector<uint8_t> array = FileAccess::get_file_as_array(path);
  615. err = p_func(p_udata, path, array, idx, total);
  616. if (err != OK) {
  617. return err;
  618. }
  619. continue;
  620. }
  621. List<String> remaps;
  622. config->get_section_keys("remap", &remaps);
  623. Set<String> remap_features;
  624. for (List<String>::Element *F = remaps.front(); F; F = F->next()) {
  625. String remap = F->get();
  626. String feature = remap.get_slice(".", 1);
  627. if (features.has(feature)) {
  628. remap_features.insert(feature);
  629. }
  630. }
  631. if (remap_features.size() > 1) {
  632. this->resolve_platform_feature_priorities(p_preset, remap_features);
  633. }
  634. err = OK;
  635. for (List<String>::Element *F = remaps.front(); F; F = F->next()) {
  636. String remap = F->get();
  637. if (remap == "path") {
  638. String remapped_path = config->get_value("remap", remap);
  639. Vector<uint8_t> array = FileAccess::get_file_as_array(remapped_path);
  640. err = p_func(p_udata, remapped_path, array, idx, total);
  641. } else if (remap.begins_with("path.")) {
  642. String feature = remap.get_slice(".", 1);
  643. if (remap_features.has(feature)) {
  644. String remapped_path = config->get_value("remap", remap);
  645. Vector<uint8_t> array = FileAccess::get_file_as_array(remapped_path);
  646. err = p_func(p_udata, remapped_path, array, idx, total);
  647. }
  648. }
  649. }
  650. if (err != OK) {
  651. return err;
  652. }
  653. //also save the .import file
  654. Vector<uint8_t> array = FileAccess::get_file_as_array(path + ".import");
  655. err = p_func(p_udata, path + ".import", array, idx, total);
  656. if (err != OK) {
  657. return err;
  658. }
  659. } else {
  660. bool do_export = true;
  661. for (int i = 0; i < export_plugins.size(); i++) {
  662. if (export_plugins[i]->get_script_instance()) { //script based
  663. export_plugins.write[i]->_export_file_script(path, type, features_pv);
  664. } else {
  665. export_plugins.write[i]->_export_file(path, type, features);
  666. }
  667. if (p_so_func) {
  668. for (int j = 0; j < export_plugins[i]->shared_objects.size(); j++) {
  669. err = p_so_func(p_udata, export_plugins[i]->shared_objects[j]);
  670. if (err != OK) {
  671. return err;
  672. }
  673. }
  674. }
  675. for (int j = 0; j < export_plugins[i]->extra_files.size(); j++) {
  676. err = p_func(p_udata, export_plugins[i]->extra_files[j].path, export_plugins[i]->extra_files[j].data, idx, total);
  677. if (err != OK) {
  678. return err;
  679. }
  680. if (export_plugins[i]->extra_files[j].remap) {
  681. do_export = false; //if remap, do not
  682. path_remaps.push_back(path);
  683. path_remaps.push_back(export_plugins[i]->extra_files[j].path);
  684. }
  685. }
  686. if (export_plugins[i]->skipped) {
  687. do_export = false;
  688. }
  689. export_plugins.write[i]->_clear();
  690. if (!do_export) {
  691. break; //apologies, not exporting
  692. }
  693. }
  694. //just store it as it comes
  695. if (do_export) {
  696. Vector<uint8_t> array = FileAccess::get_file_as_array(path);
  697. err = p_func(p_udata, path, array, idx, total);
  698. if (err != OK) {
  699. return err;
  700. }
  701. }
  702. }
  703. idx++;
  704. }
  705. //save config!
  706. Vector<String> custom_list;
  707. if (p_preset->get_custom_features() != String()) {
  708. Vector<String> tmp_custom_list = p_preset->get_custom_features().split(",");
  709. for (int i = 0; i < tmp_custom_list.size(); i++) {
  710. String f = tmp_custom_list[i].strip_edges();
  711. if (f != String()) {
  712. custom_list.push_back(f);
  713. }
  714. }
  715. }
  716. ProjectSettings::CustomMap custom_map;
  717. if (path_remaps.size()) {
  718. if (true) { //new remap mode, use always as it's friendlier with multiple .pck exports
  719. for (int i = 0; i < path_remaps.size(); i += 2) {
  720. String from = path_remaps[i];
  721. String to = path_remaps[i + 1];
  722. String remap_file = "[remap]\n\npath=\"" + to.c_escape() + "\"\n";
  723. CharString utf8 = remap_file.utf8();
  724. Vector<uint8_t> new_file;
  725. new_file.resize(utf8.length());
  726. for (int j = 0; j < utf8.length(); j++) {
  727. new_file.write[j] = utf8[j];
  728. }
  729. err = p_func(p_udata, from + ".remap", new_file, idx, total);
  730. if (err != OK) {
  731. return err;
  732. }
  733. }
  734. } else {
  735. //old remap mode, will still work, but it's unused because it's not multiple pck export friendly
  736. custom_map["path_remap/remapped_paths"] = path_remaps;
  737. }
  738. }
  739. // Store icon and splash images directly, they need to bypass the import system and be loaded as images
  740. String icon = ProjectSettings::get_singleton()->get("application/config/icon");
  741. String splash = ProjectSettings::get_singleton()->get("application/boot_splash/image");
  742. if (icon != String() && FileAccess::exists(icon)) {
  743. Vector<uint8_t> array = FileAccess::get_file_as_array(icon);
  744. err = p_func(p_udata, icon, array, idx, total);
  745. if (err != OK) {
  746. return err;
  747. }
  748. }
  749. if (splash != String() && FileAccess::exists(splash) && icon != splash) {
  750. Vector<uint8_t> array = FileAccess::get_file_as_array(splash);
  751. err = p_func(p_udata, splash, array, idx, total);
  752. if (err != OK) {
  753. return err;
  754. }
  755. }
  756. String config_file = "project.binary";
  757. String engine_cfb = EditorSettings::get_singleton()->get_cache_dir().plus_file("tmp" + config_file);
  758. ProjectSettings::get_singleton()->save_custom(engine_cfb, custom_map, custom_list);
  759. Vector<uint8_t> data = FileAccess::get_file_as_array(engine_cfb);
  760. DirAccess::remove_file_or_error(engine_cfb);
  761. return p_func(p_udata, "res://" + config_file, data, idx, total);
  762. }
  763. Error EditorExportPlatform::_add_shared_object(void *p_userdata, const SharedObject &p_so) {
  764. PackData *pack_data = (PackData *)p_userdata;
  765. if (pack_data->so_files) {
  766. pack_data->so_files->push_back(p_so);
  767. }
  768. return OK;
  769. }
  770. 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) {
  771. EditorProgress ep("savepack", TTR("Packing"), 102, true);
  772. // Create the temporary export directory if it doesn't exist.
  773. DirAccessRef da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  774. da->make_dir_recursive(EditorSettings::get_singleton()->get_cache_dir());
  775. String tmppath = EditorSettings::get_singleton()->get_cache_dir().plus_file("packtmp");
  776. FileAccess *ftmp = FileAccess::open(tmppath, FileAccess::WRITE);
  777. ERR_FAIL_COND_V_MSG(!ftmp, ERR_CANT_CREATE, "Cannot create file '" + tmppath + "'.");
  778. PackData pd;
  779. pd.ep = &ep;
  780. pd.f = ftmp;
  781. pd.so_files = p_so_files;
  782. Error err = export_project_files(p_preset, _save_pack_file, &pd, _add_shared_object);
  783. memdelete(ftmp); //close tmp file
  784. if (err != OK) {
  785. DirAccess::remove_file_or_error(tmppath);
  786. ERR_PRINT("Failed to export project files");
  787. return err;
  788. }
  789. pd.file_ofs.sort(); //do sort, so we can do binary search later
  790. FileAccess *f;
  791. int64_t embed_pos = 0;
  792. if (!p_embed) {
  793. // Regular output to separate PCK file
  794. f = FileAccess::open(p_path, FileAccess::WRITE);
  795. if (!f) {
  796. DirAccess::remove_file_or_error(tmppath);
  797. ERR_FAIL_V(ERR_CANT_CREATE);
  798. }
  799. } else {
  800. // Append to executable
  801. f = FileAccess::open(p_path, FileAccess::READ_WRITE);
  802. if (!f) {
  803. DirAccess::remove_file_or_error(tmppath);
  804. ERR_FAIL_V(ERR_FILE_CANT_OPEN);
  805. }
  806. f->seek_end();
  807. embed_pos = f->get_position();
  808. if (r_embedded_start) {
  809. *r_embedded_start = embed_pos;
  810. }
  811. // Ensure embedded PCK starts at a 64-bit multiple
  812. int pad = f->get_position() % 8;
  813. for (int i = 0; i < pad; i++) {
  814. f->store_8(0);
  815. }
  816. }
  817. int64_t pck_start_pos = f->get_position();
  818. f->store_32(PACK_HEADER_MAGIC);
  819. f->store_32(PACK_FORMAT_VERSION);
  820. f->store_32(VERSION_MAJOR);
  821. f->store_32(VERSION_MINOR);
  822. f->store_32(VERSION_PATCH);
  823. for (int i = 0; i < 16; i++) {
  824. //reserved
  825. f->store_32(0);
  826. }
  827. f->store_32(pd.file_ofs.size()); //amount of files
  828. int64_t header_size = f->get_position();
  829. //precalculate header size
  830. for (int i = 0; i < pd.file_ofs.size(); i++) {
  831. header_size += 4; // size of path string (32 bits is enough)
  832. int string_len = pd.file_ofs[i].path_utf8.length();
  833. header_size += string_len + _get_pad(4, string_len); ///size of path string
  834. header_size += 8; // offset to file _with_ header size included
  835. header_size += 8; // size of file
  836. header_size += 16; // md5
  837. }
  838. int header_padding = _get_pad(PCK_PADDING, header_size);
  839. for (int i = 0; i < pd.file_ofs.size(); i++) {
  840. uint32_t string_len = pd.file_ofs[i].path_utf8.length();
  841. uint32_t pad = _get_pad(4, string_len);
  842. f->store_32(string_len + pad);
  843. f->store_buffer((const uint8_t *)pd.file_ofs[i].path_utf8.get_data(), string_len);
  844. for (uint32_t j = 0; j < pad; j++) {
  845. f->store_8(0);
  846. }
  847. f->store_64(pd.file_ofs[i].ofs + header_padding + header_size);
  848. f->store_64(pd.file_ofs[i].size); // pay attention here, this is where file is
  849. f->store_buffer(pd.file_ofs[i].md5.ptr(), 16); //also save md5 for file
  850. }
  851. for (int i = 0; i < header_padding; i++) {
  852. f->store_8(0);
  853. }
  854. // Save the rest of the data.
  855. ftmp = FileAccess::open(tmppath, FileAccess::READ);
  856. if (!ftmp) {
  857. memdelete(f);
  858. DirAccess::remove_file_or_error(tmppath);
  859. ERR_FAIL_V_MSG(ERR_CANT_CREATE, "Can't open file to read from path '" + String(tmppath) + "'.");
  860. }
  861. const int bufsize = 16384;
  862. uint8_t buf[bufsize];
  863. while (true) {
  864. uint64_t got = ftmp->get_buffer(buf, bufsize);
  865. if (got == 0) {
  866. break;
  867. }
  868. f->store_buffer(buf, got);
  869. }
  870. memdelete(ftmp);
  871. if (p_embed) {
  872. // Ensure embedded data ends at a 64-bit multiple
  873. uint64_t embed_end = f->get_position() - embed_pos + 12;
  874. uint64_t pad = embed_end % 8;
  875. for (uint64_t i = 0; i < pad; i++) {
  876. f->store_8(0);
  877. }
  878. uint64_t pck_size = f->get_position() - pck_start_pos;
  879. f->store_64(pck_size);
  880. f->store_32(PACK_HEADER_MAGIC);
  881. if (r_embedded_size) {
  882. *r_embedded_size = f->get_position() - embed_pos;
  883. }
  884. }
  885. memdelete(f);
  886. DirAccess::remove_file_or_error(tmppath);
  887. return OK;
  888. }
  889. Error EditorExportPlatform::save_zip(const Ref<EditorExportPreset> &p_preset, const String &p_path) {
  890. EditorProgress ep("savezip", TTR("Packing"), 102, true);
  891. FileAccess *src_f;
  892. zlib_filefunc_def io = zipio_create_io_from_file(&src_f);
  893. zipFile zip = zipOpen2(p_path.utf8().get_data(), APPEND_STATUS_CREATE, nullptr, &io);
  894. ZipData zd;
  895. zd.ep = &ep;
  896. zd.zip = zip;
  897. Error err = export_project_files(p_preset, _save_zip_file, &zd);
  898. if (err != OK && err != ERR_SKIP)
  899. ERR_PRINT("Failed to export project files");
  900. zipClose(zip, nullptr);
  901. return OK;
  902. }
  903. Error EditorExportPlatform::export_pack(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags) {
  904. ExportNotifier notifier(*this, p_preset, p_debug, p_path, p_flags);
  905. return save_pack(p_preset, p_path);
  906. }
  907. Error EditorExportPlatform::export_zip(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags) {
  908. ExportNotifier notifier(*this, p_preset, p_debug, p_path, p_flags);
  909. return save_zip(p_preset, p_path);
  910. }
  911. void EditorExportPlatform::gen_export_flags(Vector<String> &r_flags, int p_flags) {
  912. String host = EditorSettings::get_singleton()->get("network/debug/remote_host");
  913. int remote_port = (int)EditorSettings::get_singleton()->get("network/debug/remote_port");
  914. if (p_flags & DEBUG_FLAG_REMOTE_DEBUG_LOCALHOST) {
  915. host = "localhost";
  916. }
  917. if (p_flags & DEBUG_FLAG_DUMB_CLIENT) {
  918. int port = EditorSettings::get_singleton()->get("filesystem/file_server/port");
  919. String passwd = EditorSettings::get_singleton()->get("filesystem/file_server/password");
  920. r_flags.push_back("--remote-fs");
  921. r_flags.push_back(host + ":" + itos(port));
  922. if (passwd != "") {
  923. r_flags.push_back("--remote-fs-password");
  924. r_flags.push_back(passwd);
  925. }
  926. }
  927. if (p_flags & DEBUG_FLAG_REMOTE_DEBUG) {
  928. r_flags.push_back("--remote-debug");
  929. r_flags.push_back(host + ":" + String::num(remote_port));
  930. List<String> breakpoints;
  931. ScriptEditor::get_singleton()->get_breakpoints(&breakpoints);
  932. if (breakpoints.size()) {
  933. r_flags.push_back("--breakpoints");
  934. String bpoints;
  935. for (const List<String>::Element *E = breakpoints.front(); E; E = E->next()) {
  936. bpoints += E->get().replace(" ", "%20");
  937. if (E->next()) {
  938. bpoints += ",";
  939. }
  940. }
  941. r_flags.push_back(bpoints);
  942. }
  943. }
  944. if (p_flags & DEBUG_FLAG_VIEW_COLLISONS) {
  945. r_flags.push_back("--debug-collisions");
  946. }
  947. if (p_flags & DEBUG_FLAG_VIEW_NAVIGATION) {
  948. r_flags.push_back("--debug-navigation");
  949. }
  950. }
  951. EditorExportPlatform::EditorExportPlatform() {
  952. }
  953. ////
  954. EditorExport *EditorExport::singleton = nullptr;
  955. void EditorExport::_save() {
  956. Ref<ConfigFile> config;
  957. config.instance();
  958. for (int i = 0; i < export_presets.size(); i++) {
  959. Ref<EditorExportPreset> preset = export_presets[i];
  960. String section = "preset." + itos(i);
  961. config->set_value(section, "name", preset->get_name());
  962. config->set_value(section, "platform", preset->get_platform()->get_name());
  963. config->set_value(section, "runnable", preset->is_runnable());
  964. config->set_value(section, "custom_features", preset->get_custom_features());
  965. bool save_files = false;
  966. switch (preset->get_export_filter()) {
  967. case EditorExportPreset::EXPORT_ALL_RESOURCES: {
  968. config->set_value(section, "export_filter", "all_resources");
  969. } break;
  970. case EditorExportPreset::EXPORT_SELECTED_SCENES: {
  971. config->set_value(section, "export_filter", "scenes");
  972. save_files = true;
  973. } break;
  974. case EditorExportPreset::EXPORT_SELECTED_RESOURCES: {
  975. config->set_value(section, "export_filter", "resources");
  976. save_files = true;
  977. } break;
  978. }
  979. if (save_files) {
  980. Vector<String> export_files = preset->get_files_to_export();
  981. config->set_value(section, "export_files", export_files);
  982. }
  983. config->set_value(section, "include_filter", preset->get_include_filter());
  984. config->set_value(section, "exclude_filter", preset->get_exclude_filter());
  985. config->set_value(section, "export_path", preset->get_export_path());
  986. config->set_value(section, "script_export_mode", preset->get_script_export_mode());
  987. config->set_value(section, "script_encryption_key", preset->get_script_encryption_key());
  988. String option_section = "preset." + itos(i) + ".options";
  989. for (const List<PropertyInfo>::Element *E = preset->get_properties().front(); E; E = E->next()) {
  990. config->set_value(option_section, E->get().name, preset->get(E->get().name));
  991. }
  992. }
  993. config->save("res://export_presets.cfg");
  994. }
  995. void EditorExport::save_presets() {
  996. if (block_save) {
  997. return;
  998. }
  999. save_timer->start();
  1000. }
  1001. void EditorExport::_bind_methods() {
  1002. ClassDB::bind_method("_save", &EditorExport::_save);
  1003. ADD_SIGNAL(MethodInfo("export_presets_updated"));
  1004. }
  1005. void EditorExport::add_export_platform(const Ref<EditorExportPlatform> &p_platform) {
  1006. export_platforms.push_back(p_platform);
  1007. }
  1008. int EditorExport::get_export_platform_count() {
  1009. return export_platforms.size();
  1010. }
  1011. Ref<EditorExportPlatform> EditorExport::get_export_platform(int p_idx) {
  1012. ERR_FAIL_INDEX_V(p_idx, export_platforms.size(), Ref<EditorExportPlatform>());
  1013. return export_platforms[p_idx];
  1014. }
  1015. void EditorExport::add_export_preset(const Ref<EditorExportPreset> &p_preset, int p_at_pos) {
  1016. if (p_at_pos < 0) {
  1017. export_presets.push_back(p_preset);
  1018. } else {
  1019. export_presets.insert(p_at_pos, p_preset);
  1020. }
  1021. }
  1022. String EditorExportPlatform::test_etc2() const {
  1023. String driver = ProjectSettings::get_singleton()->get("rendering/quality/driver/driver_name");
  1024. bool driver_fallback = ProjectSettings::get_singleton()->get("rendering/quality/driver/fallback_to_gles2");
  1025. bool etc_supported = ProjectSettings::get_singleton()->get("rendering/vram_compression/import_etc");
  1026. bool etc2_supported = ProjectSettings::get_singleton()->get("rendering/vram_compression/import_etc2");
  1027. if (driver == "GLES2" && !etc_supported) {
  1028. return TTR("Target platform requires 'ETC' texture compression for GLES2. Enable 'Import Etc' in Project Settings.");
  1029. } else if (driver == "GLES3") {
  1030. String err;
  1031. if (!etc2_supported) {
  1032. err += TTR("Target platform requires 'ETC2' texture compression for GLES3. Enable 'Import Etc 2' in Project Settings.");
  1033. }
  1034. if (driver_fallback && !etc_supported) {
  1035. if (err != String()) {
  1036. err += "\n";
  1037. }
  1038. err += TTR("Target platform requires 'ETC' texture compression for the driver fallback to GLES2.\nEnable 'Import Etc' in Project Settings, or disable 'Driver Fallback Enabled'.");
  1039. }
  1040. return err;
  1041. }
  1042. return String();
  1043. }
  1044. String EditorExportPlatform::test_etc2_or_pvrtc() const {
  1045. String driver = ProjectSettings::get_singleton()->get("rendering/quality/driver/driver_name");
  1046. bool driver_fallback = ProjectSettings::get_singleton()->get("rendering/quality/driver/fallback_to_gles2");
  1047. bool etc2_supported = ProjectSettings::get_singleton()->get("rendering/vram_compression/import_etc2");
  1048. bool pvrtc_supported = ProjectSettings::get_singleton()->get("rendering/vram_compression/import_pvrtc");
  1049. if (driver == "GLES2" && !pvrtc_supported) {
  1050. return TTR("Target platform requires 'PVRTC' texture compression for GLES2. Enable 'Import Pvrtc' in Project Settings.");
  1051. } else if (driver == "GLES3") {
  1052. String err;
  1053. if (!etc2_supported && !pvrtc_supported) {
  1054. err += TTR("Target platform requires 'ETC2' or 'PVRTC' texture compression for GLES3. Enable 'Import Etc 2' or 'Import Pvrtc' in Project Settings.");
  1055. }
  1056. if (driver_fallback && !pvrtc_supported) {
  1057. if (err != String()) {
  1058. err += "\n";
  1059. }
  1060. err += TTR("Target platform requires 'PVRTC' texture compression for the driver fallback to GLES2.\nEnable 'Import Pvrtc' in Project Settings, or disable 'Driver Fallback Enabled'.");
  1061. }
  1062. return err;
  1063. }
  1064. return String();
  1065. }
  1066. int EditorExport::get_export_preset_count() const {
  1067. return export_presets.size();
  1068. }
  1069. Ref<EditorExportPreset> EditorExport::get_export_preset(int p_idx) {
  1070. ERR_FAIL_INDEX_V(p_idx, export_presets.size(), Ref<EditorExportPreset>());
  1071. return export_presets[p_idx];
  1072. }
  1073. void EditorExport::remove_export_preset(int p_idx) {
  1074. export_presets.remove(p_idx);
  1075. save_presets();
  1076. }
  1077. void EditorExport::add_export_plugin(const Ref<EditorExportPlugin> &p_plugin) {
  1078. if (export_plugins.find(p_plugin) == -1) {
  1079. export_plugins.push_back(p_plugin);
  1080. }
  1081. }
  1082. void EditorExport::remove_export_plugin(const Ref<EditorExportPlugin> &p_plugin) {
  1083. export_plugins.erase(p_plugin);
  1084. }
  1085. Vector<Ref<EditorExportPlugin>> EditorExport::get_export_plugins() {
  1086. return export_plugins;
  1087. }
  1088. void EditorExport::_notification(int p_what) {
  1089. switch (p_what) {
  1090. case NOTIFICATION_ENTER_TREE: {
  1091. load_config();
  1092. } break;
  1093. case NOTIFICATION_PROCESS: {
  1094. update_export_presets();
  1095. } break;
  1096. }
  1097. }
  1098. void EditorExport::load_config() {
  1099. Ref<ConfigFile> config;
  1100. config.instance();
  1101. Error err = config->load("res://export_presets.cfg");
  1102. if (err != OK) {
  1103. return;
  1104. }
  1105. block_save = true;
  1106. int index = 0;
  1107. while (true) {
  1108. String section = "preset." + itos(index);
  1109. if (!config->has_section(section)) {
  1110. break;
  1111. }
  1112. String platform = config->get_value(section, "platform");
  1113. Ref<EditorExportPreset> preset;
  1114. for (int i = 0; i < export_platforms.size(); i++) {
  1115. if (export_platforms[i]->get_name() == platform) {
  1116. preset = export_platforms.write[i]->create_preset();
  1117. break;
  1118. }
  1119. }
  1120. if (!preset.is_valid()) {
  1121. index++;
  1122. ERR_CONTINUE(!preset.is_valid());
  1123. }
  1124. preset->set_name(config->get_value(section, "name"));
  1125. preset->set_runnable(config->get_value(section, "runnable"));
  1126. if (config->has_section_key(section, "custom_features")) {
  1127. preset->set_custom_features(config->get_value(section, "custom_features"));
  1128. }
  1129. String export_filter = config->get_value(section, "export_filter");
  1130. bool get_files = false;
  1131. if (export_filter == "all_resources") {
  1132. preset->set_export_filter(EditorExportPreset::EXPORT_ALL_RESOURCES);
  1133. } else if (export_filter == "scenes") {
  1134. preset->set_export_filter(EditorExportPreset::EXPORT_SELECTED_SCENES);
  1135. get_files = true;
  1136. } else if (export_filter == "resources") {
  1137. preset->set_export_filter(EditorExportPreset::EXPORT_SELECTED_RESOURCES);
  1138. get_files = true;
  1139. }
  1140. if (get_files) {
  1141. Vector<String> files = config->get_value(section, "export_files");
  1142. for (int i = 0; i < files.size(); i++) {
  1143. if (!FileAccess::exists(files[i])) {
  1144. preset->remove_export_file(files[i]);
  1145. } else {
  1146. preset->add_export_file(files[i]);
  1147. }
  1148. }
  1149. }
  1150. preset->set_include_filter(config->get_value(section, "include_filter"));
  1151. preset->set_exclude_filter(config->get_value(section, "exclude_filter"));
  1152. preset->set_export_path(config->get_value(section, "export_path", ""));
  1153. if (config->has_section_key(section, "script_export_mode")) {
  1154. preset->set_script_export_mode(config->get_value(section, "script_export_mode"));
  1155. }
  1156. if (config->has_section_key(section, "script_encryption_key")) {
  1157. preset->set_script_encryption_key(config->get_value(section, "script_encryption_key"));
  1158. }
  1159. String option_section = "preset." + itos(index) + ".options";
  1160. List<String> options;
  1161. config->get_section_keys(option_section, &options);
  1162. for (List<String>::Element *E = options.front(); E; E = E->next()) {
  1163. Variant value = config->get_value(option_section, E->get());
  1164. preset->set(E->get(), value);
  1165. }
  1166. add_export_preset(preset);
  1167. index++;
  1168. }
  1169. block_save = false;
  1170. }
  1171. void EditorExport::update_export_presets() {
  1172. Map<StringName, List<EditorExportPlatform::ExportOption>> platform_options;
  1173. for (int i = 0; i < export_platforms.size(); i++) {
  1174. Ref<EditorExportPlatform> platform = export_platforms[i];
  1175. if (platform->should_update_export_options()) {
  1176. List<EditorExportPlatform::ExportOption> options;
  1177. platform->get_export_options(&options);
  1178. platform_options[platform->get_name()] = options;
  1179. }
  1180. }
  1181. bool export_presets_updated = false;
  1182. for (int i = 0; i < export_presets.size(); i++) {
  1183. Ref<EditorExportPreset> preset = export_presets[i];
  1184. if (platform_options.has(preset->get_platform()->get_name())) {
  1185. export_presets_updated = true;
  1186. List<EditorExportPlatform::ExportOption> options = platform_options[preset->get_platform()->get_name()];
  1187. // Copy the previous preset values
  1188. Map<StringName, Variant> previous_values = preset->values;
  1189. // Clear the preset properties and values prior to reloading
  1190. preset->properties.clear();
  1191. preset->values.clear();
  1192. for (List<EditorExportPlatform::ExportOption>::Element *E = options.front(); E; E = E->next()) {
  1193. preset->properties.push_back(E->get().option);
  1194. StringName option_name = E->get().option.name;
  1195. preset->values[option_name] = previous_values.has(option_name) ? previous_values[option_name] : E->get().default_value;
  1196. }
  1197. }
  1198. }
  1199. if (export_presets_updated) {
  1200. emit_signal(_export_presets_updated);
  1201. }
  1202. }
  1203. bool EditorExport::poll_export_platforms() {
  1204. bool changed = false;
  1205. for (int i = 0; i < export_platforms.size(); i++) {
  1206. if (export_platforms.write[i]->poll_export()) {
  1207. changed = true;
  1208. }
  1209. }
  1210. return changed;
  1211. }
  1212. EditorExport::EditorExport() {
  1213. save_timer = memnew(Timer);
  1214. add_child(save_timer);
  1215. save_timer->set_wait_time(0.8);
  1216. save_timer->set_one_shot(true);
  1217. save_timer->connect("timeout", this, "_save");
  1218. block_save = false;
  1219. _export_presets_updated = "export_presets_updated";
  1220. singleton = this;
  1221. set_process(true);
  1222. }
  1223. EditorExport::~EditorExport() {
  1224. }
  1225. //////////
  1226. void EditorExportPlatformPC::get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features) {
  1227. if (p_preset->get("texture_format/s3tc")) {
  1228. r_features->push_back("s3tc");
  1229. }
  1230. if (p_preset->get("texture_format/etc")) {
  1231. r_features->push_back("etc");
  1232. }
  1233. if (p_preset->get("texture_format/etc2")) {
  1234. r_features->push_back("etc2");
  1235. }
  1236. if (p_preset->get("binary_format/64_bits")) {
  1237. r_features->push_back("64");
  1238. } else {
  1239. r_features->push_back("32");
  1240. }
  1241. }
  1242. void EditorExportPlatformPC::get_export_options(List<ExportOption> *r_options) {
  1243. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_template/debug", PROPERTY_HINT_GLOBAL_FILE), ""));
  1244. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_template/release", PROPERTY_HINT_GLOBAL_FILE), ""));
  1245. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "binary_format/64_bits"), true));
  1246. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "binary_format/embed_pck"), false));
  1247. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "texture_format/bptc"), false));
  1248. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "texture_format/s3tc"), true));
  1249. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "texture_format/etc"), false));
  1250. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "texture_format/etc2"), false));
  1251. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "texture_format/no_bptc_fallbacks"), true));
  1252. }
  1253. String EditorExportPlatformPC::get_name() const {
  1254. return name;
  1255. }
  1256. String EditorExportPlatformPC::get_os_name() const {
  1257. return os_name;
  1258. }
  1259. Ref<Texture> EditorExportPlatformPC::get_logo() const {
  1260. return logo;
  1261. }
  1262. bool EditorExportPlatformPC::can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const {
  1263. String err;
  1264. bool valid = false;
  1265. // Look for export templates (first official, and if defined custom templates).
  1266. bool use64 = p_preset->get("binary_format/64_bits");
  1267. bool dvalid = exists_export_template(use64 ? debug_file_64 : debug_file_32, &err);
  1268. bool rvalid = exists_export_template(use64 ? release_file_64 : release_file_32, &err);
  1269. if (p_preset->get("custom_template/debug") != "") {
  1270. dvalid = FileAccess::exists(p_preset->get("custom_template/debug"));
  1271. if (!dvalid) {
  1272. err += TTR("Custom debug template not found.") + "\n";
  1273. }
  1274. }
  1275. if (p_preset->get("custom_template/release") != "") {
  1276. rvalid = FileAccess::exists(p_preset->get("custom_template/release"));
  1277. if (!rvalid) {
  1278. err += TTR("Custom release template not found.") + "\n";
  1279. }
  1280. }
  1281. valid = dvalid || rvalid;
  1282. r_missing_templates = !valid;
  1283. if (!err.empty()) {
  1284. r_error = err;
  1285. }
  1286. return valid;
  1287. }
  1288. List<String> EditorExportPlatformPC::get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const {
  1289. List<String> list;
  1290. for (Map<String, String>::Element *E = extensions.front(); E; E = E->next()) {
  1291. if (p_preset->get(E->key())) {
  1292. list.push_back(extensions[E->key()]);
  1293. return list;
  1294. }
  1295. }
  1296. if (extensions.has("default")) {
  1297. list.push_back(extensions["default"]);
  1298. return list;
  1299. }
  1300. return list;
  1301. }
  1302. Error EditorExportPlatformPC::export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags) {
  1303. ExportNotifier notifier(*this, p_preset, p_debug, p_path, p_flags);
  1304. if (!DirAccess::exists(p_path.get_base_dir())) {
  1305. return ERR_FILE_BAD_PATH;
  1306. }
  1307. String custom_debug = p_preset->get("custom_template/debug");
  1308. String custom_release = p_preset->get("custom_template/release");
  1309. String template_path = p_debug ? custom_debug : custom_release;
  1310. template_path = template_path.strip_edges();
  1311. if (template_path == String()) {
  1312. if (p_preset->get("binary_format/64_bits")) {
  1313. if (p_debug) {
  1314. template_path = find_export_template(debug_file_64);
  1315. } else {
  1316. template_path = find_export_template(release_file_64);
  1317. }
  1318. } else {
  1319. if (p_debug) {
  1320. template_path = find_export_template(debug_file_32);
  1321. } else {
  1322. template_path = find_export_template(release_file_32);
  1323. }
  1324. }
  1325. }
  1326. if (template_path != String() && !FileAccess::exists(template_path)) {
  1327. EditorNode::get_singleton()->show_warning(TTR("Template file not found:") + "\n" + template_path);
  1328. return ERR_FILE_NOT_FOUND;
  1329. }
  1330. DirAccess *da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  1331. Error err = da->copy(template_path, p_path, get_chmod_flags());
  1332. memdelete(da);
  1333. if (err == OK) {
  1334. String pck_path;
  1335. if (p_preset->get("binary_format/embed_pck")) {
  1336. pck_path = p_path;
  1337. } else {
  1338. pck_path = p_path.get_basename() + ".pck";
  1339. }
  1340. Vector<SharedObject> so_files;
  1341. int64_t embedded_pos;
  1342. int64_t embedded_size;
  1343. err = save_pack(p_preset, pck_path, &so_files, p_preset->get("binary_format/embed_pck"), &embedded_pos, &embedded_size);
  1344. if (err == OK && p_preset->get("binary_format/embed_pck")) {
  1345. if (embedded_size >= 0x100000000 && !p_preset->get("binary_format/64_bits")) {
  1346. EditorNode::get_singleton()->show_warning(TTR("On 32-bit exports the embedded PCK cannot be bigger than 4 GiB."));
  1347. return ERR_INVALID_PARAMETER;
  1348. }
  1349. FixUpEmbeddedPckFunc fixup_func = get_fixup_embedded_pck_func();
  1350. if (fixup_func) {
  1351. err = fixup_func(p_path, embedded_pos, embedded_size);
  1352. }
  1353. }
  1354. if (err == OK && !so_files.empty()) {
  1355. //if shared object files, copy them
  1356. da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  1357. for (int i = 0; i < so_files.size() && err == OK; i++) {
  1358. err = da->copy(so_files[i].path, p_path.get_base_dir().plus_file(so_files[i].path.get_file()));
  1359. if (err == OK) {
  1360. err = sign_shared_object(p_preset, p_debug, p_path.get_base_dir().plus_file(so_files[i].path.get_file()));
  1361. }
  1362. }
  1363. memdelete(da);
  1364. }
  1365. }
  1366. return err;
  1367. }
  1368. Error EditorExportPlatformPC::sign_shared_object(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path) {
  1369. return OK;
  1370. }
  1371. void EditorExportPlatformPC::set_extension(const String &p_extension, const String &p_feature_key) {
  1372. extensions[p_feature_key] = p_extension;
  1373. }
  1374. void EditorExportPlatformPC::set_name(const String &p_name) {
  1375. name = p_name;
  1376. }
  1377. void EditorExportPlatformPC::set_os_name(const String &p_name) {
  1378. os_name = p_name;
  1379. }
  1380. void EditorExportPlatformPC::set_logo(const Ref<Texture> &p_logo) {
  1381. logo = p_logo;
  1382. }
  1383. void EditorExportPlatformPC::set_release_64(const String &p_file) {
  1384. release_file_64 = p_file;
  1385. }
  1386. void EditorExportPlatformPC::set_release_32(const String &p_file) {
  1387. release_file_32 = p_file;
  1388. }
  1389. void EditorExportPlatformPC::set_debug_64(const String &p_file) {
  1390. debug_file_64 = p_file;
  1391. }
  1392. void EditorExportPlatformPC::set_debug_32(const String &p_file) {
  1393. debug_file_32 = p_file;
  1394. }
  1395. void EditorExportPlatformPC::add_platform_feature(const String &p_feature) {
  1396. extra_features.insert(p_feature);
  1397. }
  1398. void EditorExportPlatformPC::get_platform_features(List<String> *r_features) {
  1399. r_features->push_back("pc"); //all pcs support "pc"
  1400. r_features->push_back("s3tc"); //all pcs support "s3tc" compression
  1401. r_features->push_back(get_os_name()); //OS name is a feature
  1402. for (Set<String>::Element *E = extra_features.front(); E; E = E->next()) {
  1403. r_features->push_back(E->get());
  1404. }
  1405. }
  1406. void EditorExportPlatformPC::resolve_platform_feature_priorities(const Ref<EditorExportPreset> &p_preset, Set<String> &p_features) {
  1407. if (p_features.has("bptc")) {
  1408. if (p_preset->has("texture_format/no_bptc_fallbacks")) {
  1409. p_features.erase("s3tc");
  1410. }
  1411. }
  1412. }
  1413. int EditorExportPlatformPC::get_chmod_flags() const {
  1414. return chmod_flags;
  1415. }
  1416. void EditorExportPlatformPC::set_chmod_flags(int p_flags) {
  1417. chmod_flags = p_flags;
  1418. }
  1419. EditorExportPlatformPC::FixUpEmbeddedPckFunc EditorExportPlatformPC::get_fixup_embedded_pck_func() const {
  1420. return fixup_embedded_pck_func;
  1421. }
  1422. void EditorExportPlatformPC::set_fixup_embedded_pck_func(FixUpEmbeddedPckFunc p_fixup_embedded_pck_func) {
  1423. fixup_embedded_pck_func = p_fixup_embedded_pck_func;
  1424. }
  1425. EditorExportPlatformPC::EditorExportPlatformPC() {
  1426. chmod_flags = -1;
  1427. fixup_embedded_pck_func = nullptr;
  1428. }
  1429. ///////////////////////
  1430. void EditorExportTextSceneToBinaryPlugin::_export_file(const String &p_path, const String &p_type, const Set<String> &p_features) {
  1431. String extension = p_path.get_extension().to_lower();
  1432. if (extension != "tres" && extension != "tscn") {
  1433. return;
  1434. }
  1435. bool convert = GLOBAL_GET("editor/convert_text_resources_to_binary_on_export");
  1436. if (!convert) {
  1437. return;
  1438. }
  1439. String tmp_path = EditorSettings::get_singleton()->get_cache_dir().plus_file("tmpfile.res");
  1440. Error err = ResourceFormatLoaderText::convert_file_to_binary(p_path, tmp_path);
  1441. if (err != OK) {
  1442. DirAccess::remove_file_or_error(tmp_path);
  1443. ERR_FAIL();
  1444. }
  1445. Vector<uint8_t> data = FileAccess::get_file_as_array(tmp_path);
  1446. if (data.size() == 0) {
  1447. DirAccess::remove_file_or_error(tmp_path);
  1448. ERR_FAIL();
  1449. }
  1450. DirAccess::remove_file_or_error(tmp_path);
  1451. add_file(p_path + ".converted.res", data, true);
  1452. }
  1453. EditorExportTextSceneToBinaryPlugin::EditorExportTextSceneToBinaryPlugin() {
  1454. GLOBAL_DEF("editor/convert_text_resources_to_binary_on_export", false);
  1455. }