editor_export_platform.cpp 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199
  1. /*************************************************************************/
  2. /* editor_export_platform.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 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_platform.h"
  31. #include "core/config/project_settings.h"
  32. #include "core/crypto/crypto_core.h"
  33. #include "core/extension/native_extension.h"
  34. #include "core/io/file_access_encrypted.h"
  35. #include "core/io/file_access_pack.h" // PACK_HEADER_MAGIC, PACK_FORMAT_VERSION
  36. #include "core/io/zip_io.h"
  37. #include "core/version.h"
  38. #include "editor/editor_file_system.h"
  39. #include "editor/editor_node.h"
  40. #include "editor/editor_paths.h"
  41. #include "editor/editor_scale.h"
  42. #include "editor/editor_settings.h"
  43. #include "editor/plugins/script_editor_plugin.h"
  44. #include "editor_export_plugin.h"
  45. static int _get_pad(int p_alignment, int p_n) {
  46. int rest = p_n % p_alignment;
  47. int pad = 0;
  48. if (rest > 0) {
  49. pad = p_alignment - rest;
  50. };
  51. return pad;
  52. }
  53. #define PCK_PADDING 16
  54. bool EditorExportPlatform::fill_log_messages(RichTextLabel *p_log, Error p_err) {
  55. bool has_messages = false;
  56. int msg_count = get_message_count();
  57. p_log->add_text(TTR("Project export for platform:") + " ");
  58. p_log->add_image(get_logo(), 16 * EDSCALE, 16 * EDSCALE, Color(1.0, 1.0, 1.0), INLINE_ALIGNMENT_CENTER);
  59. p_log->add_text(" ");
  60. p_log->add_text(get_name());
  61. p_log->add_text(" - ");
  62. if (p_err == OK) {
  63. if (get_worst_message_type() >= EditorExportPlatform::EXPORT_MESSAGE_WARNING) {
  64. p_log->add_image(EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("StatusWarning"), SNAME("EditorIcons")), 16 * EDSCALE, 16 * EDSCALE, Color(1.0, 1.0, 1.0), INLINE_ALIGNMENT_CENTER);
  65. p_log->add_text(" ");
  66. p_log->add_text(TTR("Completed with warnings."));
  67. has_messages = true;
  68. } else {
  69. p_log->add_image(EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("StatusSuccess"), SNAME("EditorIcons")), 16 * EDSCALE, 16 * EDSCALE, Color(1.0, 1.0, 1.0), INLINE_ALIGNMENT_CENTER);
  70. p_log->add_text(" ");
  71. p_log->add_text(TTR("Completed sucessfully."));
  72. if (msg_count > 0) {
  73. has_messages = true;
  74. }
  75. }
  76. } else {
  77. p_log->add_image(EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("StatusError"), SNAME("EditorIcons")), 16 * EDSCALE, 16 * EDSCALE, Color(1.0, 1.0, 1.0), INLINE_ALIGNMENT_CENTER);
  78. p_log->add_text(" ");
  79. p_log->add_text(TTR("Failed."));
  80. has_messages = true;
  81. }
  82. p_log->add_newline();
  83. if (msg_count) {
  84. p_log->push_table(2);
  85. p_log->set_table_column_expand(0, false);
  86. p_log->set_table_column_expand(1, true);
  87. for (int m = 0; m < msg_count; m++) {
  88. EditorExportPlatform::ExportMessage msg = get_message(m);
  89. Color color = EditorNode::get_singleton()->get_gui_base()->get_theme_color(SNAME("font_color"), SNAME("Label"));
  90. Ref<Texture> icon;
  91. switch (msg.msg_type) {
  92. case EditorExportPlatform::EXPORT_MESSAGE_INFO: {
  93. color = EditorNode::get_singleton()->get_gui_base()->get_theme_color(SNAME("font_color"), SNAME("Editor")) * Color(1, 1, 1, 0.6);
  94. } break;
  95. case EditorExportPlatform::EXPORT_MESSAGE_WARNING: {
  96. icon = EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("Warning"), SNAME("EditorIcons"));
  97. color = EditorNode::get_singleton()->get_gui_base()->get_theme_color(SNAME("warning_color"), SNAME("Editor"));
  98. } break;
  99. case EditorExportPlatform::EXPORT_MESSAGE_ERROR: {
  100. icon = EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("Error"), SNAME("EditorIcons"));
  101. color = EditorNode::get_singleton()->get_gui_base()->get_theme_color(SNAME("error_color"), SNAME("Editor"));
  102. } break;
  103. default:
  104. break;
  105. }
  106. p_log->push_cell();
  107. p_log->add_text("\t");
  108. if (icon.is_valid()) {
  109. p_log->add_image(icon);
  110. }
  111. p_log->pop();
  112. p_log->push_cell();
  113. p_log->push_color(color);
  114. p_log->add_text(vformat("[%s]: %s", msg.category, msg.text));
  115. p_log->pop();
  116. p_log->pop();
  117. }
  118. p_log->pop();
  119. p_log->add_newline();
  120. }
  121. p_log->add_newline();
  122. return has_messages;
  123. }
  124. void EditorExportPlatform::gen_debug_flags(Vector<String> &r_flags, int p_flags) {
  125. String host = EditorSettings::get_singleton()->get("network/debug/remote_host");
  126. int remote_port = (int)EditorSettings::get_singleton()->get("network/debug/remote_port");
  127. if (p_flags & DEBUG_FLAG_REMOTE_DEBUG_LOCALHOST) {
  128. host = "localhost";
  129. }
  130. if (p_flags & DEBUG_FLAG_DUMB_CLIENT) {
  131. int port = EditorSettings::get_singleton()->get("filesystem/file_server/port");
  132. String passwd = EditorSettings::get_singleton()->get("filesystem/file_server/password");
  133. r_flags.push_back("--remote-fs");
  134. r_flags.push_back(host + ":" + itos(port));
  135. if (!passwd.is_empty()) {
  136. r_flags.push_back("--remote-fs-password");
  137. r_flags.push_back(passwd);
  138. }
  139. }
  140. if (p_flags & DEBUG_FLAG_REMOTE_DEBUG) {
  141. r_flags.push_back("--remote-debug");
  142. r_flags.push_back(get_debug_protocol() + host + ":" + String::num(remote_port));
  143. List<String> breakpoints;
  144. ScriptEditor::get_singleton()->get_breakpoints(&breakpoints);
  145. if (breakpoints.size()) {
  146. r_flags.push_back("--breakpoints");
  147. String bpoints;
  148. for (const List<String>::Element *E = breakpoints.front(); E; E = E->next()) {
  149. bpoints += E->get().replace(" ", "%20");
  150. if (E->next()) {
  151. bpoints += ",";
  152. }
  153. }
  154. r_flags.push_back(bpoints);
  155. }
  156. }
  157. if (p_flags & DEBUG_FLAG_VIEW_COLLISONS) {
  158. r_flags.push_back("--debug-collisions");
  159. }
  160. if (p_flags & DEBUG_FLAG_VIEW_NAVIGATION) {
  161. r_flags.push_back("--debug-navigation");
  162. }
  163. }
  164. 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) {
  165. ERR_FAIL_COND_V_MSG(p_total < 1, ERR_PARAMETER_RANGE_ERROR, "Must select at least one file to export.");
  166. PackData *pd = (PackData *)p_userdata;
  167. SavedData sd;
  168. sd.path_utf8 = p_path.utf8();
  169. sd.ofs = pd->f->get_position();
  170. sd.size = p_data.size();
  171. sd.encrypted = false;
  172. for (int i = 0; i < p_enc_in_filters.size(); ++i) {
  173. if (p_path.matchn(p_enc_in_filters[i]) || p_path.replace("res://", "").matchn(p_enc_in_filters[i])) {
  174. sd.encrypted = true;
  175. break;
  176. }
  177. }
  178. for (int i = 0; i < p_enc_ex_filters.size(); ++i) {
  179. if (p_path.matchn(p_enc_ex_filters[i]) || p_path.replace("res://", "").matchn(p_enc_ex_filters[i])) {
  180. sd.encrypted = false;
  181. break;
  182. }
  183. }
  184. Ref<FileAccessEncrypted> fae;
  185. Ref<FileAccess> ftmp = pd->f;
  186. if (sd.encrypted) {
  187. fae.instantiate();
  188. ERR_FAIL_COND_V(fae.is_null(), ERR_SKIP);
  189. Error err = fae->open_and_parse(ftmp, p_key, FileAccessEncrypted::MODE_WRITE_AES256, false);
  190. ERR_FAIL_COND_V(err != OK, ERR_SKIP);
  191. ftmp = fae;
  192. }
  193. // Store file content.
  194. ftmp->store_buffer(p_data.ptr(), p_data.size());
  195. if (fae.is_valid()) {
  196. ftmp.unref();
  197. fae.unref();
  198. }
  199. int pad = _get_pad(PCK_PADDING, pd->f->get_position());
  200. for (int i = 0; i < pad; i++) {
  201. pd->f->store_8(Math::rand() % 256);
  202. }
  203. // Store MD5 of original file.
  204. {
  205. unsigned char hash[16];
  206. CryptoCore::md5(p_data.ptr(), p_data.size(), hash);
  207. sd.md5.resize(16);
  208. for (int i = 0; i < 16; i++) {
  209. sd.md5.write[i] = hash[i];
  210. }
  211. }
  212. pd->file_ofs.push_back(sd);
  213. if (pd->ep->step(TTR("Storing File:") + " " + p_path, 2 + p_file * 100 / p_total, false)) {
  214. return ERR_SKIP;
  215. }
  216. return OK;
  217. }
  218. 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) {
  219. ERR_FAIL_COND_V_MSG(p_total < 1, ERR_PARAMETER_RANGE_ERROR, "Must select at least one file to export.");
  220. String path = p_path.replace_first("res://", "");
  221. ZipData *zd = (ZipData *)p_userdata;
  222. zipFile zip = (zipFile)zd->zip;
  223. zipOpenNewFileInZip(zip,
  224. path.utf8().get_data(),
  225. nullptr,
  226. nullptr,
  227. 0,
  228. nullptr,
  229. 0,
  230. nullptr,
  231. Z_DEFLATED,
  232. Z_DEFAULT_COMPRESSION);
  233. zipWriteInFileInZip(zip, p_data.ptr(), p_data.size());
  234. zipCloseFileInZip(zip);
  235. if (zd->ep->step(TTR("Storing File:") + " " + p_path, 2 + p_file * 100 / p_total, false)) {
  236. return ERR_SKIP;
  237. }
  238. return OK;
  239. }
  240. Ref<ImageTexture> EditorExportPlatform::get_option_icon(int p_index) const {
  241. Ref<Theme> theme = EditorNode::get_singleton()->get_editor_theme();
  242. ERR_FAIL_COND_V(theme.is_null(), Ref<ImageTexture>());
  243. if (EditorNode::get_singleton()->get_main_control()->is_layout_rtl()) {
  244. return theme->get_icon(SNAME("PlayBackwards"), SNAME("EditorIcons"));
  245. } else {
  246. return theme->get_icon(SNAME("Play"), SNAME("EditorIcons"));
  247. }
  248. }
  249. String EditorExportPlatform::find_export_template(String template_file_name, String *err) const {
  250. String current_version = VERSION_FULL_CONFIG;
  251. String template_path = EditorPaths::get_singleton()->get_export_templates_dir().path_join(current_version).path_join(template_file_name);
  252. if (FileAccess::exists(template_path)) {
  253. return template_path;
  254. }
  255. // Not found
  256. if (err) {
  257. *err += TTR("No export template found at the expected path:") + "\n" + template_path + "\n";
  258. }
  259. return String();
  260. }
  261. bool EditorExportPlatform::exists_export_template(String template_file_name, String *err) const {
  262. return find_export_template(template_file_name, err) != "";
  263. }
  264. Ref<EditorExportPreset> EditorExportPlatform::create_preset() {
  265. Ref<EditorExportPreset> preset;
  266. preset.instantiate();
  267. preset->platform = Ref<EditorExportPlatform>(this);
  268. List<ExportOption> options;
  269. get_export_options(&options);
  270. for (const ExportOption &E : options) {
  271. preset->properties.push_back(E.option);
  272. preset->values[E.option.name] = E.default_value;
  273. preset->update_visibility[E.option.name] = E.update_visibility;
  274. }
  275. return preset;
  276. }
  277. void EditorExportPlatform::_export_find_resources(EditorFileSystemDirectory *p_dir, HashSet<String> &p_paths) {
  278. for (int i = 0; i < p_dir->get_subdir_count(); i++) {
  279. _export_find_resources(p_dir->get_subdir(i), p_paths);
  280. }
  281. for (int i = 0; i < p_dir->get_file_count(); i++) {
  282. if (p_dir->get_file_type(i) == "TextFile") {
  283. continue;
  284. }
  285. p_paths.insert(p_dir->get_file_path(i));
  286. }
  287. }
  288. void EditorExportPlatform::_export_find_dependencies(const String &p_path, HashSet<String> &p_paths) {
  289. if (p_paths.has(p_path)) {
  290. return;
  291. }
  292. p_paths.insert(p_path);
  293. EditorFileSystemDirectory *dir;
  294. int file_idx;
  295. dir = EditorFileSystem::get_singleton()->find_file(p_path, &file_idx);
  296. if (!dir) {
  297. return;
  298. }
  299. Vector<String> deps = dir->get_file_deps(file_idx);
  300. for (int i = 0; i < deps.size(); i++) {
  301. _export_find_dependencies(deps[i], p_paths);
  302. }
  303. }
  304. void EditorExportPlatform::_edit_files_with_filter(Ref<DirAccess> &da, const Vector<String> &p_filters, HashSet<String> &r_list, bool exclude) {
  305. da->list_dir_begin();
  306. String cur_dir = da->get_current_dir().replace("\\", "/");
  307. if (!cur_dir.ends_with("/")) {
  308. cur_dir += "/";
  309. }
  310. String cur_dir_no_prefix = cur_dir.replace("res://", "");
  311. Vector<String> dirs;
  312. String f = da->get_next();
  313. while (!f.is_empty()) {
  314. if (da->current_is_dir()) {
  315. dirs.push_back(f);
  316. } else {
  317. String fullpath = cur_dir + f;
  318. // Test also against path without res:// so that filters like `file.txt` can work.
  319. String fullpath_no_prefix = cur_dir_no_prefix + f;
  320. for (int i = 0; i < p_filters.size(); ++i) {
  321. if (fullpath.matchn(p_filters[i]) || fullpath_no_prefix.matchn(p_filters[i])) {
  322. if (!exclude) {
  323. r_list.insert(fullpath);
  324. } else {
  325. r_list.erase(fullpath);
  326. }
  327. }
  328. }
  329. }
  330. f = da->get_next();
  331. }
  332. da->list_dir_end();
  333. for (int i = 0; i < dirs.size(); ++i) {
  334. String dir = dirs[i];
  335. if (dir.begins_with(".")) {
  336. continue;
  337. }
  338. if (EditorFileSystem::_should_skip_directory(cur_dir + dir)) {
  339. continue;
  340. }
  341. da->change_dir(dir);
  342. _edit_files_with_filter(da, p_filters, r_list, exclude);
  343. da->change_dir("..");
  344. }
  345. }
  346. void EditorExportPlatform::_edit_filter_list(HashSet<String> &r_list, const String &p_filter, bool exclude) {
  347. if (p_filter.is_empty()) {
  348. return;
  349. }
  350. Vector<String> split = p_filter.split(",");
  351. Vector<String> filters;
  352. for (int i = 0; i < split.size(); i++) {
  353. String f = split[i].strip_edges();
  354. if (f.is_empty()) {
  355. continue;
  356. }
  357. filters.push_back(f);
  358. }
  359. Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
  360. ERR_FAIL_COND(da.is_null());
  361. _edit_files_with_filter(da, filters, r_list, exclude);
  362. }
  363. HashSet<String> EditorExportPlatform::get_features(const Ref<EditorExportPreset> &p_preset, bool p_debug) const {
  364. Ref<EditorExportPlatform> platform = p_preset->get_platform();
  365. List<String> feature_list;
  366. platform->get_platform_features(&feature_list);
  367. platform->get_preset_features(p_preset, &feature_list);
  368. HashSet<String> result;
  369. for (const String &E : feature_list) {
  370. result.insert(E);
  371. }
  372. if (p_debug) {
  373. result.insert("debug");
  374. } else {
  375. result.insert("release");
  376. }
  377. if (!p_preset->get_custom_features().is_empty()) {
  378. Vector<String> tmp_custom_list = p_preset->get_custom_features().split(",");
  379. for (int i = 0; i < tmp_custom_list.size(); i++) {
  380. String f = tmp_custom_list[i].strip_edges();
  381. if (!f.is_empty()) {
  382. result.insert(f);
  383. }
  384. }
  385. }
  386. return result;
  387. }
  388. EditorExportPlatform::ExportNotifier::ExportNotifier(EditorExportPlatform &p_platform, const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags) {
  389. HashSet<String> features = p_platform.get_features(p_preset, p_debug);
  390. Vector<Ref<EditorExportPlugin>> export_plugins = EditorExport::get_singleton()->get_export_plugins();
  391. //initial export plugin callback
  392. for (int i = 0; i < export_plugins.size(); i++) {
  393. if (export_plugins[i]->get_script_instance()) { //script based
  394. PackedStringArray features_psa;
  395. for (const String &feature : features) {
  396. features_psa.push_back(feature);
  397. }
  398. export_plugins.write[i]->_export_begin_script(features_psa, p_debug, p_path, p_flags);
  399. } else {
  400. export_plugins.write[i]->_export_begin(features, p_debug, p_path, p_flags);
  401. }
  402. }
  403. }
  404. EditorExportPlatform::ExportNotifier::~ExportNotifier() {
  405. Vector<Ref<EditorExportPlugin>> export_plugins = EditorExport::get_singleton()->get_export_plugins();
  406. for (int i = 0; i < export_plugins.size(); i++) {
  407. if (export_plugins[i]->get_script_instance()) {
  408. export_plugins.write[i]->_export_end_script();
  409. }
  410. export_plugins.write[i]->_export_end();
  411. }
  412. }
  413. Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> &p_preset, bool p_debug, EditorExportSaveFunction p_func, void *p_udata, EditorExportSaveSharedObject p_so_func) {
  414. //figure out paths of files that will be exported
  415. HashSet<String> paths;
  416. Vector<String> path_remaps;
  417. if (p_preset->get_export_filter() == EditorExportPreset::EXPORT_ALL_RESOURCES) {
  418. //find stuff
  419. _export_find_resources(EditorFileSystem::get_singleton()->get_filesystem(), paths);
  420. } else if (p_preset->get_export_filter() == EditorExportPreset::EXCLUDE_SELECTED_RESOURCES) {
  421. _export_find_resources(EditorFileSystem::get_singleton()->get_filesystem(), paths);
  422. Vector<String> files = p_preset->get_files_to_export();
  423. for (int i = 0; i < files.size(); i++) {
  424. paths.erase(files[i]);
  425. }
  426. } else {
  427. bool scenes_only = p_preset->get_export_filter() == EditorExportPreset::EXPORT_SELECTED_SCENES;
  428. Vector<String> files = p_preset->get_files_to_export();
  429. for (int i = 0; i < files.size(); i++) {
  430. if (scenes_only && ResourceLoader::get_resource_type(files[i]) != "PackedScene") {
  431. continue;
  432. }
  433. _export_find_dependencies(files[i], paths);
  434. }
  435. // Add autoload resources and their dependencies
  436. List<PropertyInfo> props;
  437. ProjectSettings::get_singleton()->get_property_list(&props);
  438. for (const PropertyInfo &pi : props) {
  439. if (!pi.name.begins_with("autoload/")) {
  440. continue;
  441. }
  442. String autoload_path = ProjectSettings::get_singleton()->get(pi.name);
  443. if (autoload_path.begins_with("*")) {
  444. autoload_path = autoload_path.substr(1);
  445. }
  446. _export_find_dependencies(autoload_path, paths);
  447. }
  448. }
  449. //add native icons to non-resource include list
  450. _edit_filter_list(paths, String("*.icns"), false);
  451. _edit_filter_list(paths, String("*.ico"), false);
  452. _edit_filter_list(paths, p_preset->get_include_filter(), false);
  453. _edit_filter_list(paths, p_preset->get_exclude_filter(), true);
  454. // Ignore import files, since these are automatically added to the jar later with the resources
  455. _edit_filter_list(paths, String("*.import"), true);
  456. // Get encryption filters.
  457. bool enc_pck = p_preset->get_enc_pck();
  458. Vector<String> enc_in_filters;
  459. Vector<String> enc_ex_filters;
  460. Vector<uint8_t> key;
  461. if (enc_pck) {
  462. Vector<String> enc_in_split = p_preset->get_enc_in_filter().split(",");
  463. for (int i = 0; i < enc_in_split.size(); i++) {
  464. String f = enc_in_split[i].strip_edges();
  465. if (f.is_empty()) {
  466. continue;
  467. }
  468. enc_in_filters.push_back(f);
  469. }
  470. Vector<String> enc_ex_split = p_preset->get_enc_ex_filter().split(",");
  471. for (int i = 0; i < enc_ex_split.size(); i++) {
  472. String f = enc_ex_split[i].strip_edges();
  473. if (f.is_empty()) {
  474. continue;
  475. }
  476. enc_ex_filters.push_back(f);
  477. }
  478. // Get encryption key.
  479. String script_key = p_preset->get_script_encryption_key().to_lower();
  480. key.resize(32);
  481. if (script_key.length() == 64) {
  482. for (int i = 0; i < 32; i++) {
  483. int v = 0;
  484. if (i * 2 < script_key.length()) {
  485. char32_t ct = script_key[i * 2];
  486. if (is_digit(ct)) {
  487. ct = ct - '0';
  488. } else if (ct >= 'a' && ct <= 'f') {
  489. ct = 10 + ct - 'a';
  490. }
  491. v |= ct << 4;
  492. }
  493. if (i * 2 + 1 < script_key.length()) {
  494. char32_t ct = script_key[i * 2 + 1];
  495. if (is_digit(ct)) {
  496. ct = ct - '0';
  497. } else if (ct >= 'a' && ct <= 'f') {
  498. ct = 10 + ct - 'a';
  499. }
  500. v |= ct;
  501. }
  502. key.write[i] = v;
  503. }
  504. }
  505. }
  506. Error err = OK;
  507. Vector<Ref<EditorExportPlugin>> export_plugins = EditorExport::get_singleton()->get_export_plugins();
  508. for (int i = 0; i < export_plugins.size(); i++) {
  509. export_plugins.write[i]->set_export_preset(p_preset);
  510. if (p_so_func) {
  511. for (int j = 0; j < export_plugins[i]->shared_objects.size(); j++) {
  512. err = p_so_func(p_udata, export_plugins[i]->shared_objects[j]);
  513. if (err != OK) {
  514. return err;
  515. }
  516. }
  517. }
  518. for (int j = 0; j < export_plugins[i]->extra_files.size(); j++) {
  519. 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);
  520. if (err != OK) {
  521. return err;
  522. }
  523. }
  524. export_plugins.write[i]->_clear();
  525. }
  526. HashSet<String> features = get_features(p_preset, p_debug);
  527. //store everything in the export medium
  528. int idx = 0;
  529. int total = paths.size();
  530. for (const String &E : paths) {
  531. String path = E;
  532. String type = ResourceLoader::get_resource_type(path);
  533. if (FileAccess::exists(path + ".import")) {
  534. //file is imported, replace by what it imports
  535. Ref<ConfigFile> config;
  536. config.instantiate();
  537. err = config->load(path + ".import");
  538. if (err != OK) {
  539. ERR_PRINT("Could not parse: '" + path + "', not exported.");
  540. continue;
  541. }
  542. String importer_type = config->get_value("remap", "importer");
  543. if (importer_type == "keep") {
  544. //just keep file as-is
  545. Vector<uint8_t> array = FileAccess::get_file_as_array(path);
  546. err = p_func(p_udata, path, array, idx, total, enc_in_filters, enc_ex_filters, key);
  547. if (err != OK) {
  548. return err;
  549. }
  550. continue;
  551. }
  552. List<String> remaps;
  553. config->get_section_keys("remap", &remaps);
  554. HashSet<String> remap_features;
  555. for (const String &F : remaps) {
  556. String remap = F;
  557. String feature = remap.get_slice(".", 1);
  558. if (features.has(feature)) {
  559. remap_features.insert(feature);
  560. }
  561. }
  562. if (remap_features.size() > 1) {
  563. this->resolve_platform_feature_priorities(p_preset, remap_features);
  564. }
  565. err = OK;
  566. for (const String &F : remaps) {
  567. String remap = F;
  568. if (remap == "path") {
  569. String remapped_path = config->get_value("remap", remap);
  570. Vector<uint8_t> array = FileAccess::get_file_as_array(remapped_path);
  571. err = p_func(p_udata, remapped_path, array, idx, total, enc_in_filters, enc_ex_filters, key);
  572. } else if (remap.begins_with("path.")) {
  573. String feature = remap.get_slice(".", 1);
  574. if (remap_features.has(feature)) {
  575. String remapped_path = config->get_value("remap", remap);
  576. Vector<uint8_t> array = FileAccess::get_file_as_array(remapped_path);
  577. err = p_func(p_udata, remapped_path, array, idx, total, enc_in_filters, enc_ex_filters, key);
  578. }
  579. }
  580. }
  581. if (err != OK) {
  582. return err;
  583. }
  584. //also save the .import file
  585. Vector<uint8_t> array = FileAccess::get_file_as_array(path + ".import");
  586. err = p_func(p_udata, path + ".import", array, idx, total, enc_in_filters, enc_ex_filters, key);
  587. if (err != OK) {
  588. return err;
  589. }
  590. } else {
  591. bool do_export = true;
  592. for (int i = 0; i < export_plugins.size(); i++) {
  593. if (export_plugins[i]->get_script_instance()) { //script based
  594. PackedStringArray features_psa;
  595. for (const String &feature : features) {
  596. features_psa.push_back(feature);
  597. }
  598. export_plugins.write[i]->_export_file_script(path, type, features_psa);
  599. } else {
  600. export_plugins.write[i]->_export_file(path, type, features);
  601. }
  602. if (p_so_func) {
  603. for (int j = 0; j < export_plugins[i]->shared_objects.size(); j++) {
  604. err = p_so_func(p_udata, export_plugins[i]->shared_objects[j]);
  605. if (err != OK) {
  606. return err;
  607. }
  608. }
  609. }
  610. for (int j = 0; j < export_plugins[i]->extra_files.size(); j++) {
  611. 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);
  612. if (err != OK) {
  613. return err;
  614. }
  615. if (export_plugins[i]->extra_files[j].remap) {
  616. do_export = false; //if remap, do not
  617. path_remaps.push_back(path);
  618. path_remaps.push_back(export_plugins[i]->extra_files[j].path);
  619. }
  620. }
  621. if (export_plugins[i]->skipped) {
  622. do_export = false;
  623. }
  624. export_plugins.write[i]->_clear();
  625. if (!do_export) {
  626. break; //apologies, not exporting
  627. }
  628. }
  629. //just store it as it comes
  630. if (do_export) {
  631. Vector<uint8_t> array = FileAccess::get_file_as_array(path);
  632. err = p_func(p_udata, path, array, idx, total, enc_in_filters, enc_ex_filters, key);
  633. if (err != OK) {
  634. return err;
  635. }
  636. }
  637. }
  638. idx++;
  639. }
  640. //save config!
  641. Vector<String> custom_list;
  642. if (!p_preset->get_custom_features().is_empty()) {
  643. Vector<String> tmp_custom_list = p_preset->get_custom_features().split(",");
  644. for (int i = 0; i < tmp_custom_list.size(); i++) {
  645. String f = tmp_custom_list[i].strip_edges();
  646. if (!f.is_empty()) {
  647. custom_list.push_back(f);
  648. }
  649. }
  650. }
  651. ProjectSettings::CustomMap custom_map;
  652. if (path_remaps.size()) {
  653. if (true) { //new remap mode, use always as it's friendlier with multiple .pck exports
  654. for (int i = 0; i < path_remaps.size(); i += 2) {
  655. String from = path_remaps[i];
  656. String to = path_remaps[i + 1];
  657. String remap_file = "[remap]\n\npath=\"" + to.c_escape() + "\"\n";
  658. CharString utf8 = remap_file.utf8();
  659. Vector<uint8_t> new_file;
  660. new_file.resize(utf8.length());
  661. for (int j = 0; j < utf8.length(); j++) {
  662. new_file.write[j] = utf8[j];
  663. }
  664. err = p_func(p_udata, from + ".remap", new_file, idx, total, enc_in_filters, enc_ex_filters, key);
  665. if (err != OK) {
  666. return err;
  667. }
  668. }
  669. } else {
  670. //old remap mode, will still work, but it's unused because it's not multiple pck export friendly
  671. custom_map["path_remap/remapped_paths"] = path_remaps;
  672. }
  673. }
  674. // Store icon and splash images directly, they need to bypass the import system and be loaded as images
  675. String icon = ProjectSettings::get_singleton()->get("application/config/icon");
  676. String splash = ProjectSettings::get_singleton()->get("application/boot_splash/image");
  677. if (!icon.is_empty() && FileAccess::exists(icon)) {
  678. Vector<uint8_t> array = FileAccess::get_file_as_array(icon);
  679. err = p_func(p_udata, icon, array, idx, total, enc_in_filters, enc_ex_filters, key);
  680. if (err != OK) {
  681. return err;
  682. }
  683. }
  684. if (!splash.is_empty() && FileAccess::exists(splash) && icon != splash) {
  685. Vector<uint8_t> array = FileAccess::get_file_as_array(splash);
  686. err = p_func(p_udata, splash, array, idx, total, enc_in_filters, enc_ex_filters, key);
  687. if (err != OK) {
  688. return err;
  689. }
  690. }
  691. String resource_cache_file = ResourceUID::get_cache_file();
  692. if (FileAccess::exists(resource_cache_file)) {
  693. Vector<uint8_t> array = FileAccess::get_file_as_array(resource_cache_file);
  694. err = p_func(p_udata, resource_cache_file, array, idx, total, enc_in_filters, enc_ex_filters, key);
  695. if (err != OK) {
  696. return err;
  697. }
  698. }
  699. String extension_list_config_file = NativeExtension::get_extension_list_config_file();
  700. if (FileAccess::exists(extension_list_config_file)) {
  701. Vector<uint8_t> array = FileAccess::get_file_as_array(extension_list_config_file);
  702. err = p_func(p_udata, extension_list_config_file, array, idx, total, enc_in_filters, enc_ex_filters, key);
  703. if (err != OK) {
  704. return err;
  705. }
  706. }
  707. // Store text server data if it is supported.
  708. if (TS->has_feature(TextServer::FEATURE_USE_SUPPORT_DATA)) {
  709. bool use_data = ProjectSettings::get_singleton()->get("internationalization/locale/include_text_server_data");
  710. if (use_data) {
  711. // Try using user provided data file.
  712. String ts_data = "res://" + TS->get_support_data_filename();
  713. if (FileAccess::exists(ts_data)) {
  714. Vector<uint8_t> array = FileAccess::get_file_as_array(ts_data);
  715. err = p_func(p_udata, ts_data, array, idx, total, enc_in_filters, enc_ex_filters, key);
  716. if (err != OK) {
  717. return err;
  718. }
  719. } else {
  720. // Use default text server data.
  721. String icu_data_file = EditorPaths::get_singleton()->get_cache_dir().path_join("tmp_icu_data");
  722. TS->save_support_data(icu_data_file);
  723. Vector<uint8_t> array = FileAccess::get_file_as_array(icu_data_file);
  724. err = p_func(p_udata, ts_data, array, idx, total, enc_in_filters, enc_ex_filters, key);
  725. DirAccess::remove_file_or_error(icu_data_file);
  726. if (err != OK) {
  727. return err;
  728. }
  729. }
  730. }
  731. }
  732. String config_file = "project.binary";
  733. String engine_cfb = EditorPaths::get_singleton()->get_cache_dir().path_join("tmp" + config_file);
  734. ProjectSettings::get_singleton()->save_custom(engine_cfb, custom_map, custom_list);
  735. Vector<uint8_t> data = FileAccess::get_file_as_array(engine_cfb);
  736. DirAccess::remove_file_or_error(engine_cfb);
  737. return p_func(p_udata, "res://" + config_file, data, idx, total, enc_in_filters, enc_ex_filters, key);
  738. }
  739. Error EditorExportPlatform::_add_shared_object(void *p_userdata, const SharedObject &p_so) {
  740. PackData *pack_data = (PackData *)p_userdata;
  741. if (pack_data->so_files) {
  742. pack_data->so_files->push_back(p_so);
  743. }
  744. return OK;
  745. }
  746. Error EditorExportPlatform::save_pack(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, Vector<SharedObject> *p_so_files, bool p_embed, int64_t *r_embedded_start, int64_t *r_embedded_size) {
  747. EditorProgress ep("savepack", TTR("Packing"), 102, true);
  748. // Create the temporary export directory if it doesn't exist.
  749. Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  750. da->make_dir_recursive(EditorPaths::get_singleton()->get_cache_dir());
  751. String tmppath = EditorPaths::get_singleton()->get_cache_dir().path_join("packtmp");
  752. Ref<FileAccess> ftmp = FileAccess::open(tmppath, FileAccess::WRITE);
  753. if (ftmp.is_null()) {
  754. add_message(EXPORT_MESSAGE_ERROR, TTR("Save PCK"), vformat(TTR("Cannot create file \"%s\"."), tmppath));
  755. return ERR_CANT_CREATE;
  756. }
  757. PackData pd;
  758. pd.ep = &ep;
  759. pd.f = ftmp;
  760. pd.so_files = p_so_files;
  761. Error err = export_project_files(p_preset, p_debug, _save_pack_file, &pd, _add_shared_object);
  762. // Close temp file.
  763. pd.f.unref();
  764. ftmp.unref();
  765. if (err != OK) {
  766. DirAccess::remove_file_or_error(tmppath);
  767. add_message(EXPORT_MESSAGE_ERROR, TTR("Save PCK"), TTR("Failed to export project files."));
  768. return err;
  769. }
  770. pd.file_ofs.sort(); //do sort, so we can do binary search later
  771. Ref<FileAccess> f;
  772. int64_t embed_pos = 0;
  773. if (!p_embed) {
  774. // Regular output to separate PCK file
  775. f = FileAccess::open(p_path, FileAccess::WRITE);
  776. if (f.is_null()) {
  777. DirAccess::remove_file_or_error(tmppath);
  778. add_message(EXPORT_MESSAGE_ERROR, TTR("Save PCK"), vformat(TTR("Can't open file to read from path \"%s\"."), tmppath));
  779. return ERR_CANT_CREATE;
  780. }
  781. } else {
  782. // Append to executable
  783. f = FileAccess::open(p_path, FileAccess::READ_WRITE);
  784. if (f.is_null()) {
  785. DirAccess::remove_file_or_error(tmppath);
  786. add_message(EXPORT_MESSAGE_ERROR, TTR("Save PCK"), vformat(TTR("Can't open executable file from path \"%s\"."), tmppath));
  787. return ERR_FILE_CANT_OPEN;
  788. }
  789. f->seek_end();
  790. embed_pos = f->get_position();
  791. if (r_embedded_start) {
  792. *r_embedded_start = embed_pos;
  793. }
  794. // Ensure embedded PCK starts at a 64-bit multiple
  795. int pad = f->get_position() % 8;
  796. for (int i = 0; i < pad; i++) {
  797. f->store_8(0);
  798. }
  799. }
  800. int64_t pck_start_pos = f->get_position();
  801. f->store_32(PACK_HEADER_MAGIC);
  802. f->store_32(PACK_FORMAT_VERSION);
  803. f->store_32(VERSION_MAJOR);
  804. f->store_32(VERSION_MINOR);
  805. f->store_32(VERSION_PATCH);
  806. uint32_t pack_flags = 0;
  807. bool enc_pck = p_preset->get_enc_pck();
  808. bool enc_directory = p_preset->get_enc_directory();
  809. if (enc_pck && enc_directory) {
  810. pack_flags |= PACK_DIR_ENCRYPTED;
  811. }
  812. f->store_32(pack_flags); // flags
  813. uint64_t file_base_ofs = f->get_position();
  814. f->store_64(0); // files base
  815. for (int i = 0; i < 16; i++) {
  816. //reserved
  817. f->store_32(0);
  818. }
  819. f->store_32(pd.file_ofs.size()); //amount of files
  820. Ref<FileAccessEncrypted> fae;
  821. Ref<FileAccess> fhead = f;
  822. if (enc_pck && enc_directory) {
  823. String script_key = p_preset->get_script_encryption_key().to_lower();
  824. Vector<uint8_t> key;
  825. key.resize(32);
  826. if (script_key.length() == 64) {
  827. for (int i = 0; i < 32; i++) {
  828. int v = 0;
  829. if (i * 2 < script_key.length()) {
  830. char32_t ct = script_key[i * 2];
  831. if (is_digit(ct)) {
  832. ct = ct - '0';
  833. } else if (ct >= 'a' && ct <= 'f') {
  834. ct = 10 + ct - 'a';
  835. }
  836. v |= ct << 4;
  837. }
  838. if (i * 2 + 1 < script_key.length()) {
  839. char32_t ct = script_key[i * 2 + 1];
  840. if (is_digit(ct)) {
  841. ct = ct - '0';
  842. } else if (ct >= 'a' && ct <= 'f') {
  843. ct = 10 + ct - 'a';
  844. }
  845. v |= ct;
  846. }
  847. key.write[i] = v;
  848. }
  849. }
  850. fae.instantiate();
  851. if (fae.is_null()) {
  852. add_message(EXPORT_MESSAGE_ERROR, TTR("Save PCK"), TTR("Can't create encrypted file."));
  853. return ERR_CANT_CREATE;
  854. }
  855. err = fae->open_and_parse(f, key, FileAccessEncrypted::MODE_WRITE_AES256, false);
  856. if (err != OK) {
  857. add_message(EXPORT_MESSAGE_ERROR, TTR("Save PCK"), TTR("Can't open encrypted file to write."));
  858. return ERR_CANT_CREATE;
  859. }
  860. fhead = fae;
  861. }
  862. for (int i = 0; i < pd.file_ofs.size(); i++) {
  863. uint32_t string_len = pd.file_ofs[i].path_utf8.length();
  864. uint32_t pad = _get_pad(4, string_len);
  865. fhead->store_32(string_len + pad);
  866. fhead->store_buffer((const uint8_t *)pd.file_ofs[i].path_utf8.get_data(), string_len);
  867. for (uint32_t j = 0; j < pad; j++) {
  868. fhead->store_8(0);
  869. }
  870. fhead->store_64(pd.file_ofs[i].ofs);
  871. fhead->store_64(pd.file_ofs[i].size); // pay attention here, this is where file is
  872. fhead->store_buffer(pd.file_ofs[i].md5.ptr(), 16); //also save md5 for file
  873. uint32_t flags = 0;
  874. if (pd.file_ofs[i].encrypted) {
  875. flags |= PACK_FILE_ENCRYPTED;
  876. }
  877. fhead->store_32(flags);
  878. }
  879. if (fae.is_valid()) {
  880. fhead.unref();
  881. fae.unref();
  882. }
  883. int header_padding = _get_pad(PCK_PADDING, f->get_position());
  884. for (int i = 0; i < header_padding; i++) {
  885. f->store_8(Math::rand() % 256);
  886. }
  887. uint64_t file_base = f->get_position();
  888. f->seek(file_base_ofs);
  889. f->store_64(file_base); // update files base
  890. f->seek(file_base);
  891. // Save the rest of the data.
  892. ftmp = FileAccess::open(tmppath, FileAccess::READ);
  893. if (ftmp.is_null()) {
  894. DirAccess::remove_file_or_error(tmppath);
  895. add_message(EXPORT_MESSAGE_ERROR, TTR("Save PCK"), vformat(TTR("Can't open file to read from path \"%s\"."), tmppath));
  896. return ERR_CANT_CREATE;
  897. }
  898. const int bufsize = 16384;
  899. uint8_t buf[bufsize];
  900. while (true) {
  901. uint64_t got = ftmp->get_buffer(buf, bufsize);
  902. if (got == 0) {
  903. break;
  904. }
  905. f->store_buffer(buf, got);
  906. }
  907. ftmp.unref(); // Close temp file.
  908. if (p_embed) {
  909. // Ensure embedded data ends at a 64-bit multiple
  910. uint64_t embed_end = f->get_position() - embed_pos + 12;
  911. uint64_t pad = embed_end % 8;
  912. for (uint64_t i = 0; i < pad; i++) {
  913. f->store_8(0);
  914. }
  915. uint64_t pck_size = f->get_position() - pck_start_pos;
  916. f->store_64(pck_size);
  917. f->store_32(PACK_HEADER_MAGIC);
  918. if (r_embedded_size) {
  919. *r_embedded_size = f->get_position() - embed_pos;
  920. }
  921. }
  922. DirAccess::remove_file_or_error(tmppath);
  923. return OK;
  924. }
  925. Error EditorExportPlatform::save_zip(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path) {
  926. EditorProgress ep("savezip", TTR("Packing"), 102, true);
  927. Ref<FileAccess> io_fa;
  928. zlib_filefunc_def io = zipio_create_io(&io_fa);
  929. zipFile zip = zipOpen2(p_path.utf8().get_data(), APPEND_STATUS_CREATE, nullptr, &io);
  930. ZipData zd;
  931. zd.ep = &ep;
  932. zd.zip = zip;
  933. Error err = export_project_files(p_preset, p_debug, _save_zip_file, &zd);
  934. if (err != OK && err != ERR_SKIP) {
  935. add_message(EXPORT_MESSAGE_ERROR, TTR("Save ZIP"), TTR("Failed to export project files."));
  936. }
  937. zipClose(zip, nullptr);
  938. return OK;
  939. }
  940. Error EditorExportPlatform::export_pack(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags) {
  941. ExportNotifier notifier(*this, p_preset, p_debug, p_path, p_flags);
  942. return save_pack(p_preset, p_debug, p_path);
  943. }
  944. Error EditorExportPlatform::export_zip(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags) {
  945. ExportNotifier notifier(*this, p_preset, p_debug, p_path, p_flags);
  946. return save_zip(p_preset, p_debug, p_path);
  947. }
  948. void EditorExportPlatform::gen_export_flags(Vector<String> &r_flags, int p_flags) {
  949. String host = EditorSettings::get_singleton()->get("network/debug/remote_host");
  950. int remote_port = (int)EditorSettings::get_singleton()->get("network/debug/remote_port");
  951. if (p_flags & DEBUG_FLAG_REMOTE_DEBUG_LOCALHOST) {
  952. host = "localhost";
  953. }
  954. if (p_flags & DEBUG_FLAG_DUMB_CLIENT) {
  955. int port = EditorSettings::get_singleton()->get("filesystem/file_server/port");
  956. String passwd = EditorSettings::get_singleton()->get("filesystem/file_server/password");
  957. r_flags.push_back("--remote-fs");
  958. r_flags.push_back(host + ":" + itos(port));
  959. if (!passwd.is_empty()) {
  960. r_flags.push_back("--remote-fs-password");
  961. r_flags.push_back(passwd);
  962. }
  963. }
  964. if (p_flags & DEBUG_FLAG_REMOTE_DEBUG) {
  965. r_flags.push_back("--remote-debug");
  966. r_flags.push_back(get_debug_protocol() + host + ":" + String::num(remote_port));
  967. List<String> breakpoints;
  968. ScriptEditor::get_singleton()->get_breakpoints(&breakpoints);
  969. if (breakpoints.size()) {
  970. r_flags.push_back("--breakpoints");
  971. String bpoints;
  972. for (List<String>::Element *E = breakpoints.front(); E; E = E->next()) {
  973. bpoints += E->get().replace(" ", "%20");
  974. if (E->next()) {
  975. bpoints += ",";
  976. }
  977. }
  978. r_flags.push_back(bpoints);
  979. }
  980. }
  981. if (p_flags & DEBUG_FLAG_VIEW_COLLISONS) {
  982. r_flags.push_back("--debug-collisions");
  983. }
  984. if (p_flags & DEBUG_FLAG_VIEW_NAVIGATION) {
  985. r_flags.push_back("--debug-navigation");
  986. }
  987. }
  988. bool EditorExportPlatform::can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const {
  989. String templates_error;
  990. bool valid_export_configuration = has_valid_export_configuration(p_preset, templates_error, r_missing_templates);
  991. String project_configuration_error;
  992. bool valid_project_configuration = has_valid_project_configuration(p_preset, project_configuration_error);
  993. if (!templates_error.is_empty()) {
  994. r_error += templates_error;
  995. }
  996. if (!project_configuration_error.is_empty()) {
  997. r_error += project_configuration_error;
  998. }
  999. return valid_export_configuration && valid_project_configuration;
  1000. }
  1001. EditorExportPlatform::EditorExportPlatform() {
  1002. }