export_template_manager.cpp 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171
  1. /**************************************************************************/
  2. /* export_template_manager.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #include "export_template_manager.h"
  31. #include "core/io/dir_access.h"
  32. #include "core/io/json.h"
  33. #include "core/io/zip_io.h"
  34. #include "core/version.h"
  35. #include "editor/editor_file_system.h"
  36. #include "editor/editor_node.h"
  37. #include "editor/editor_paths.h"
  38. #include "editor/editor_settings.h"
  39. #include "editor/editor_string_names.h"
  40. #include "editor/export/editor_export_preset.h"
  41. #include "editor/progress_dialog.h"
  42. #include "editor/themes/editor_scale.h"
  43. #include "scene/gui/file_dialog.h"
  44. #include "scene/gui/link_button.h"
  45. #include "scene/gui/menu_button.h"
  46. #include "scene/gui/option_button.h"
  47. #include "scene/gui/separator.h"
  48. #include "scene/gui/tree.h"
  49. #include "scene/main/http_request.h"
  50. enum DownloadsAvailability {
  51. DOWNLOADS_AVAILABLE,
  52. DOWNLOADS_NOT_AVAILABLE_IN_OFFLINE_MODE,
  53. DOWNLOADS_NOT_AVAILABLE_FOR_DEV_BUILDS,
  54. DOWNLOADS_NOT_AVAILABLE_FOR_DOUBLE_BUILDS,
  55. };
  56. static DownloadsAvailability _get_downloads_availability() {
  57. const int network_mode = EDITOR_GET("network/connection/network_mode");
  58. // Downloadable export templates are only available for stable and official alpha/beta/RC builds
  59. // (which always have a number following their status, e.g. "alpha1").
  60. // Therefore, don't display download-related features when using a development version
  61. // (whose builds aren't numbered).
  62. if (String(GODOT_VERSION_STATUS) == String("dev") ||
  63. String(GODOT_VERSION_STATUS) == String("alpha") ||
  64. String(GODOT_VERSION_STATUS) == String("beta") ||
  65. String(GODOT_VERSION_STATUS) == String("rc")) {
  66. return DOWNLOADS_NOT_AVAILABLE_FOR_DEV_BUILDS;
  67. }
  68. #ifdef REAL_T_IS_DOUBLE
  69. return DOWNLOADS_NOT_AVAILABLE_FOR_DOUBLE_BUILDS;
  70. #endif
  71. if (network_mode == EditorSettings::NETWORK_OFFLINE) {
  72. return DOWNLOADS_NOT_AVAILABLE_IN_OFFLINE_MODE;
  73. }
  74. return DOWNLOADS_AVAILABLE;
  75. }
  76. void ExportTemplateManager::_update_template_status() {
  77. // Fetch installed templates from the file system.
  78. Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  79. const String &templates_dir = EditorPaths::get_singleton()->get_export_templates_dir();
  80. Error err = da->change_dir(templates_dir);
  81. ERR_FAIL_COND_MSG(err != OK, "Could not access templates directory at '" + templates_dir + "'.");
  82. RBSet<String> templates;
  83. da->list_dir_begin();
  84. if (err == OK) {
  85. String c = da->get_next();
  86. while (!c.is_empty()) {
  87. if (da->current_is_dir() && !c.begins_with(".")) {
  88. templates.insert(c);
  89. }
  90. c = da->get_next();
  91. }
  92. }
  93. da->list_dir_end();
  94. // Update the state of the current version.
  95. String current_version = GODOT_VERSION_FULL_CONFIG;
  96. current_value->set_text(current_version);
  97. if (templates.has(current_version)) {
  98. current_missing_label->hide();
  99. current_installed_label->show();
  100. current_installed_hb->show();
  101. current_version_exists = true;
  102. } else {
  103. current_installed_label->hide();
  104. current_missing_label->show();
  105. current_installed_hb->hide();
  106. current_version_exists = false;
  107. }
  108. if (is_downloading_templates) {
  109. install_options_vb->hide();
  110. download_progress_hb->show();
  111. } else {
  112. download_progress_hb->hide();
  113. install_options_vb->show();
  114. if (templates.has(current_version)) {
  115. current_installed_path->set_text(templates_dir.path_join(current_version));
  116. }
  117. }
  118. // Update the list of other installed versions.
  119. installed_table->clear();
  120. TreeItem *installed_root = installed_table->create_item();
  121. for (RBSet<String>::Element *E = templates.back(); E; E = E->prev()) {
  122. String version_string = E->get();
  123. if (version_string == current_version) {
  124. continue;
  125. }
  126. TreeItem *ti = installed_table->create_item(installed_root);
  127. ti->set_text(0, version_string);
  128. #ifndef ANDROID_ENABLED
  129. ti->add_button(0, get_editor_theme_icon(SNAME("Folder")), OPEN_TEMPLATE_FOLDER, false, TTR("Open the folder containing these templates."));
  130. #endif
  131. ti->add_button(0, get_editor_theme_icon(SNAME("Remove")), UNINSTALL_TEMPLATE, false, TTR("Uninstall these templates."));
  132. }
  133. }
  134. void ExportTemplateManager::_download_current() {
  135. if (is_downloading_templates) {
  136. return;
  137. }
  138. is_downloading_templates = true;
  139. install_options_vb->hide();
  140. download_progress_hb->show();
  141. if (mirrors_available) {
  142. String mirror_url = _get_selected_mirror();
  143. if (mirror_url.is_empty()) {
  144. _set_current_progress_status(TTR("There are no mirrors available."), true);
  145. return;
  146. }
  147. _download_template(mirror_url, true);
  148. } else if (!is_refreshing_mirrors) {
  149. _set_current_progress_status(TTR("Retrieving the mirror list..."));
  150. _refresh_mirrors();
  151. }
  152. }
  153. void ExportTemplateManager::_download_template(const String &p_url, bool p_skip_check) {
  154. if (!p_skip_check && is_downloading_templates) {
  155. return;
  156. }
  157. is_downloading_templates = true;
  158. install_options_vb->hide();
  159. download_progress_hb->show();
  160. download_progress_bar->show();
  161. download_progress_bar->set_indeterminate(true);
  162. _set_current_progress_status(TTR("Starting the download..."));
  163. download_templates->set_download_file(EditorPaths::get_singleton()->get_cache_dir().path_join("tmp_templates.tpz"));
  164. download_templates->set_use_threads(true);
  165. const String proxy_host = EDITOR_GET("network/http_proxy/host");
  166. const int proxy_port = EDITOR_GET("network/http_proxy/port");
  167. download_templates->set_http_proxy(proxy_host, proxy_port);
  168. download_templates->set_https_proxy(proxy_host, proxy_port);
  169. Error err = download_templates->request(p_url);
  170. if (err != OK) {
  171. _set_current_progress_status(TTR("Error requesting URL:") + " " + p_url, true);
  172. download_progress_hb->hide();
  173. return;
  174. }
  175. set_process(true);
  176. _set_current_progress_status(TTR("Connecting to the mirror..."));
  177. }
  178. void ExportTemplateManager::_download_template_completed(int p_status, int p_code, const PackedStringArray &headers, const PackedByteArray &p_data) {
  179. switch (p_status) {
  180. case HTTPRequest::RESULT_CANT_RESOLVE: {
  181. _set_current_progress_status(TTR("Can't resolve the requested address."), true);
  182. } break;
  183. case HTTPRequest::RESULT_BODY_SIZE_LIMIT_EXCEEDED:
  184. case HTTPRequest::RESULT_CONNECTION_ERROR:
  185. case HTTPRequest::RESULT_CHUNKED_BODY_SIZE_MISMATCH:
  186. case HTTPRequest::RESULT_TLS_HANDSHAKE_ERROR:
  187. case HTTPRequest::RESULT_CANT_CONNECT: {
  188. _set_current_progress_status(TTR("Can't connect to the mirror."), true);
  189. } break;
  190. case HTTPRequest::RESULT_NO_RESPONSE: {
  191. _set_current_progress_status(TTR("No response from the mirror."), true);
  192. } break;
  193. case HTTPRequest::RESULT_REQUEST_FAILED: {
  194. _set_current_progress_status(TTR("Request failed."), true);
  195. } break;
  196. case HTTPRequest::RESULT_REDIRECT_LIMIT_REACHED: {
  197. _set_current_progress_status(TTR("Request ended up in a redirect loop."), true);
  198. } break;
  199. default: {
  200. if (p_code != 200) {
  201. _set_current_progress_status(TTR("Request failed:") + " " + itos(p_code), true);
  202. } else {
  203. _set_current_progress_status(TTR("Download complete; extracting templates..."));
  204. String path = download_templates->get_download_file();
  205. is_downloading_templates = false;
  206. bool ret = _install_file_selected(path, true);
  207. if (ret) {
  208. // Clean up downloaded file.
  209. Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  210. Error err = da->remove(path);
  211. if (err != OK) {
  212. EditorNode::get_singleton()->add_io_error(TTR("Cannot remove temporary file:") + "\n" + path + "\n");
  213. }
  214. } else {
  215. EditorNode::get_singleton()->add_io_error(vformat(TTR("Templates installation failed.\nThe problematic templates archives can be found at '%s'."), path));
  216. }
  217. }
  218. } break;
  219. }
  220. set_process(false);
  221. }
  222. void ExportTemplateManager::_cancel_template_download() {
  223. if (!is_downloading_templates) {
  224. return;
  225. }
  226. download_templates->cancel_request();
  227. download_progress_hb->hide();
  228. install_options_vb->show();
  229. is_downloading_templates = false;
  230. }
  231. void ExportTemplateManager::_refresh_mirrors() {
  232. if (is_refreshing_mirrors) {
  233. return;
  234. }
  235. is_refreshing_mirrors = true;
  236. String current_version = GODOT_VERSION_FULL_CONFIG;
  237. const String mirrors_metadata_url = "https://godotengine.org/mirrorlist/" + current_version + ".json";
  238. request_mirrors->request(mirrors_metadata_url);
  239. }
  240. void ExportTemplateManager::_refresh_mirrors_completed(int p_status, int p_code, const PackedStringArray &headers, const PackedByteArray &p_data) {
  241. if (p_status != HTTPRequest::RESULT_SUCCESS || p_code != 200) {
  242. EditorNode::get_singleton()->show_warning(TTR("Error getting the list of mirrors."));
  243. is_refreshing_mirrors = false;
  244. if (is_downloading_templates) {
  245. _cancel_template_download();
  246. }
  247. return;
  248. }
  249. String response_json = String::utf8((const char *)p_data.ptr(), p_data.size());
  250. JSON json;
  251. Error err = json.parse(response_json);
  252. if (err != OK) {
  253. EditorNode::get_singleton()->show_warning(TTR("Error parsing JSON with the list of mirrors. Please report this issue!"));
  254. is_refreshing_mirrors = false;
  255. if (is_downloading_templates) {
  256. _cancel_template_download();
  257. }
  258. return;
  259. }
  260. mirrors_list->clear();
  261. mirrors_list->add_item(TTR("Best available mirror"), 0);
  262. mirrors_available = false;
  263. Dictionary mirror_data = json.get_data();
  264. if (mirror_data.has("mirrors")) {
  265. Array mirrors = mirror_data["mirrors"];
  266. for (int i = 0; i < mirrors.size(); i++) {
  267. Dictionary m = mirrors[i];
  268. ERR_CONTINUE(!m.has("url") || !m.has("name"));
  269. mirrors_list->add_item(m["name"]);
  270. mirrors_list->set_item_metadata(i + 1, m["url"]);
  271. mirrors_available = true;
  272. }
  273. }
  274. if (!mirrors_available) {
  275. EditorNode::get_singleton()->show_warning(TTR("No download links found for this version. Direct download is only available for official releases."));
  276. if (is_downloading_templates) {
  277. _cancel_template_download();
  278. }
  279. }
  280. is_refreshing_mirrors = false;
  281. if (is_downloading_templates) {
  282. String mirror_url = _get_selected_mirror();
  283. if (mirror_url.is_empty()) {
  284. _set_current_progress_status(TTR("There are no mirrors available."), true);
  285. return;
  286. }
  287. _download_template(mirror_url, true);
  288. }
  289. }
  290. void ExportTemplateManager::_force_online_mode() {
  291. EditorSettings::get_singleton()->set_setting("network/connection/network_mode", EditorSettings::NETWORK_ONLINE);
  292. EditorSettings::get_singleton()->notify_changes();
  293. EditorSettings::get_singleton()->save();
  294. popup_manager();
  295. }
  296. bool ExportTemplateManager::_humanize_http_status(HTTPRequest *p_request, String *r_status, int *r_downloaded_bytes, int *r_total_bytes) {
  297. *r_status = "";
  298. *r_downloaded_bytes = -1;
  299. *r_total_bytes = -1;
  300. bool success = true;
  301. switch (p_request->get_http_client_status()) {
  302. case HTTPClient::STATUS_DISCONNECTED:
  303. *r_status = TTR("Disconnected");
  304. success = false;
  305. break;
  306. case HTTPClient::STATUS_RESOLVING:
  307. *r_status = TTR("Resolving");
  308. break;
  309. case HTTPClient::STATUS_CANT_RESOLVE:
  310. *r_status = TTR("Can't Resolve");
  311. success = false;
  312. break;
  313. case HTTPClient::STATUS_CONNECTING:
  314. *r_status = TTR("Connecting...");
  315. break;
  316. case HTTPClient::STATUS_CANT_CONNECT:
  317. *r_status = TTR("Can't Connect");
  318. success = false;
  319. break;
  320. case HTTPClient::STATUS_CONNECTED:
  321. *r_status = TTR("Connected");
  322. break;
  323. case HTTPClient::STATUS_REQUESTING:
  324. *r_status = TTR("Requesting...");
  325. break;
  326. case HTTPClient::STATUS_BODY:
  327. *r_status = TTR("Downloading");
  328. *r_downloaded_bytes = p_request->get_downloaded_bytes();
  329. *r_total_bytes = p_request->get_body_size();
  330. if (p_request->get_body_size() > 0) {
  331. *r_status += " " + String::humanize_size(p_request->get_downloaded_bytes()) + "/" + String::humanize_size(p_request->get_body_size());
  332. } else {
  333. *r_status += " " + String::humanize_size(p_request->get_downloaded_bytes());
  334. }
  335. break;
  336. case HTTPClient::STATUS_CONNECTION_ERROR:
  337. *r_status = TTR("Connection Error");
  338. success = false;
  339. break;
  340. case HTTPClient::STATUS_TLS_HANDSHAKE_ERROR:
  341. *r_status = TTR("TLS Handshake Error");
  342. success = false;
  343. break;
  344. }
  345. return success;
  346. }
  347. void ExportTemplateManager::_set_current_progress_status(const String &p_status, bool p_error) {
  348. download_progress_label->set_text(p_status);
  349. if (p_error) {
  350. download_progress_bar->hide();
  351. download_progress_label->add_theme_color_override(SceneStringName(font_color), get_theme_color(SNAME("error_color"), EditorStringName(Editor)));
  352. } else {
  353. download_progress_label->add_theme_color_override(SceneStringName(font_color), get_theme_color(SceneStringName(font_color), SNAME("Label")));
  354. }
  355. }
  356. void ExportTemplateManager::_set_current_progress_value(float p_value, const String &p_status) {
  357. download_progress_bar->show();
  358. download_progress_bar->set_indeterminate(false);
  359. download_progress_bar->set_value(p_value);
  360. download_progress_label->set_text(p_status);
  361. }
  362. void ExportTemplateManager::_install_file() {
  363. install_file_dialog->popup_file_dialog();
  364. }
  365. bool ExportTemplateManager::_install_file_selected(const String &p_file, bool p_skip_progress) {
  366. Ref<FileAccess> io_fa;
  367. zlib_filefunc_def io = zipio_create_io(&io_fa);
  368. unzFile pkg = unzOpen2(p_file.utf8().get_data(), &io);
  369. if (!pkg) {
  370. EditorNode::get_singleton()->show_warning(TTR("Can't open the export templates file."));
  371. return false;
  372. }
  373. int ret = unzGoToFirstFile(pkg);
  374. // Count them and find version.
  375. int fc = 0;
  376. String version;
  377. String contents_dir;
  378. while (ret == UNZ_OK) {
  379. unz_file_info info;
  380. char fname[16384];
  381. ret = unzGetCurrentFileInfo(pkg, &info, fname, 16384, nullptr, 0, nullptr, 0);
  382. if (ret != UNZ_OK) {
  383. break;
  384. }
  385. String file = String::utf8(fname);
  386. // Skip the __MACOSX directory created by macOS's built-in file zipper.
  387. if (file.begins_with("__MACOSX")) {
  388. ret = unzGoToNextFile(pkg);
  389. continue;
  390. }
  391. if (file.ends_with("version.txt")) {
  392. Vector<uint8_t> uncomp_data;
  393. uncomp_data.resize(info.uncompressed_size);
  394. // Read.
  395. unzOpenCurrentFile(pkg);
  396. ret = unzReadCurrentFile(pkg, uncomp_data.ptrw(), uncomp_data.size());
  397. ERR_BREAK_MSG(ret < 0, vformat("An error occurred while attempting to read from file: %s. This file will not be used.", file));
  398. unzCloseCurrentFile(pkg);
  399. String data_str = String::utf8((const char *)uncomp_data.ptr(), uncomp_data.size());
  400. data_str = data_str.strip_edges();
  401. // Version number should be of the form major.minor[.patch].status[.module_config]
  402. // so it can in theory have 3 or more slices.
  403. if (data_str.get_slice_count(".") < 3) {
  404. EditorNode::get_singleton()->show_warning(vformat(TTR("Invalid version.txt format inside the export templates file: %s."), data_str));
  405. unzClose(pkg);
  406. return false;
  407. }
  408. version = data_str;
  409. contents_dir = file.get_base_dir().trim_suffix("/").trim_suffix("\\");
  410. }
  411. if (file.get_file().size() != 0) {
  412. fc++;
  413. }
  414. ret = unzGoToNextFile(pkg);
  415. }
  416. if (version.is_empty()) {
  417. EditorNode::get_singleton()->show_warning(TTR("No version.txt found inside the export templates file."));
  418. unzClose(pkg);
  419. return false;
  420. }
  421. Ref<DirAccess> d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  422. String template_path = EditorPaths::get_singleton()->get_export_templates_dir().path_join(version);
  423. Error err = d->make_dir_recursive(template_path);
  424. if (err != OK) {
  425. EditorNode::get_singleton()->show_warning(TTR("Error creating path for extracting templates:") + "\n" + template_path);
  426. unzClose(pkg);
  427. return false;
  428. }
  429. EditorProgress *p = nullptr;
  430. if (!p_skip_progress) {
  431. p = memnew(EditorProgress("ltask", TTR("Extracting Export Templates"), fc));
  432. }
  433. fc = 0;
  434. ret = unzGoToFirstFile(pkg);
  435. while (ret == UNZ_OK) {
  436. // Get filename.
  437. unz_file_info info;
  438. char fname[16384];
  439. ret = unzGetCurrentFileInfo(pkg, &info, fname, 16384, nullptr, 0, nullptr, 0);
  440. if (ret != UNZ_OK) {
  441. break;
  442. }
  443. if (String::utf8(fname).ends_with("/")) {
  444. // File is a directory, ignore it.
  445. // Directories will be created when extracting each file.
  446. ret = unzGoToNextFile(pkg);
  447. continue;
  448. }
  449. String file_path(String::utf8(fname).simplify_path());
  450. String file = file_path.get_file();
  451. // Skip the __MACOSX directory created by macOS's built-in file zipper.
  452. if (file.is_empty() || file.begins_with("__MACOSX")) {
  453. ret = unzGoToNextFile(pkg);
  454. continue;
  455. }
  456. Vector<uint8_t> uncomp_data;
  457. uncomp_data.resize(info.uncompressed_size);
  458. // Read
  459. unzOpenCurrentFile(pkg);
  460. ret = unzReadCurrentFile(pkg, uncomp_data.ptrw(), uncomp_data.size());
  461. ERR_BREAK_MSG(ret < 0, vformat("An error occurred while attempting to read from file: %s. This file will not be used.", file));
  462. unzCloseCurrentFile(pkg);
  463. String base_dir = file_path.get_base_dir().trim_suffix("/");
  464. if (base_dir != contents_dir && base_dir.begins_with(contents_dir)) {
  465. base_dir = base_dir.substr(contents_dir.length(), file_path.length()).trim_prefix("/");
  466. file = base_dir.path_join(file);
  467. Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  468. ERR_CONTINUE(da.is_null());
  469. String output_dir = template_path.path_join(base_dir);
  470. if (!DirAccess::exists(output_dir)) {
  471. Error mkdir_err = da->make_dir_recursive(output_dir);
  472. ERR_CONTINUE(mkdir_err != OK);
  473. }
  474. }
  475. if (p) {
  476. p->step(TTR("Importing:") + " " + file, fc);
  477. }
  478. String to_write = template_path.path_join(file);
  479. Ref<FileAccess> f = FileAccess::open(to_write, FileAccess::WRITE);
  480. if (f.is_null()) {
  481. ret = unzGoToNextFile(pkg);
  482. fc++;
  483. ERR_CONTINUE_MSG(true, "Can't open file from path '" + String(to_write) + "'.");
  484. }
  485. f->store_buffer(uncomp_data.ptr(), uncomp_data.size());
  486. f.unref(); // close file.
  487. #ifndef WINDOWS_ENABLED
  488. FileAccess::set_unix_permissions(to_write, (info.external_fa >> 16) & 0x01FF);
  489. #endif
  490. ret = unzGoToNextFile(pkg);
  491. fc++;
  492. }
  493. if (p) {
  494. memdelete(p);
  495. }
  496. unzClose(pkg);
  497. _update_template_status();
  498. EditorSettings::get_singleton()->set("_export_template_download_directory", p_file.get_base_dir());
  499. return true;
  500. }
  501. void ExportTemplateManager::_uninstall_template(const String &p_version) {
  502. uninstall_confirm->set_text(vformat(TTR("Remove templates for the version '%s'?"), p_version));
  503. uninstall_confirm->popup_centered();
  504. uninstall_version = p_version;
  505. }
  506. void ExportTemplateManager::_uninstall_template_confirmed() {
  507. Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  508. const String &templates_dir = EditorPaths::get_singleton()->get_export_templates_dir();
  509. Error err = da->change_dir(templates_dir);
  510. ERR_FAIL_COND_MSG(err != OK, "Could not access templates directory at '" + templates_dir + "'.");
  511. err = da->change_dir(uninstall_version);
  512. ERR_FAIL_COND_MSG(err != OK, "Could not access templates directory at '" + templates_dir.path_join(uninstall_version) + "'.");
  513. err = da->erase_contents_recursive();
  514. ERR_FAIL_COND_MSG(err != OK, "Could not remove all templates in '" + templates_dir.path_join(uninstall_version) + "'.");
  515. da->change_dir("..");
  516. err = da->remove(uninstall_version);
  517. ERR_FAIL_COND_MSG(err != OK, "Could not remove templates directory at '" + templates_dir.path_join(uninstall_version) + "'.");
  518. _update_template_status();
  519. }
  520. String ExportTemplateManager::_get_selected_mirror() const {
  521. if (mirrors_list->get_item_count() == 1) {
  522. return "";
  523. }
  524. int selected = mirrors_list->get_selected_id();
  525. if (selected == 0) {
  526. // This is a special "best available" value; so pick the first available mirror from the rest of the list.
  527. selected = 1;
  528. }
  529. return mirrors_list->get_item_metadata(selected);
  530. }
  531. void ExportTemplateManager::_mirror_options_button_cbk(int p_id) {
  532. switch (p_id) {
  533. case VISIT_WEB_MIRROR: {
  534. String mirror_url = _get_selected_mirror();
  535. if (mirror_url.is_empty()) {
  536. EditorNode::get_singleton()->show_warning(TTR("There are no mirrors available."));
  537. return;
  538. }
  539. OS::get_singleton()->shell_open(mirror_url);
  540. } break;
  541. case COPY_MIRROR_URL: {
  542. String mirror_url = _get_selected_mirror();
  543. if (mirror_url.is_empty()) {
  544. EditorNode::get_singleton()->show_warning(TTR("There are no mirrors available."));
  545. return;
  546. }
  547. DisplayServer::get_singleton()->clipboard_set(mirror_url);
  548. } break;
  549. }
  550. }
  551. void ExportTemplateManager::_installed_table_button_cbk(Object *p_item, int p_column, int p_id, MouseButton p_button) {
  552. if (p_button != MouseButton::LEFT) {
  553. return;
  554. }
  555. TreeItem *ti = Object::cast_to<TreeItem>(p_item);
  556. if (!ti) {
  557. return;
  558. }
  559. switch (p_id) {
  560. case OPEN_TEMPLATE_FOLDER: {
  561. String version_string = ti->get_text(0);
  562. _open_template_folder(version_string);
  563. } break;
  564. case UNINSTALL_TEMPLATE: {
  565. String version_string = ti->get_text(0);
  566. _uninstall_template(version_string);
  567. } break;
  568. }
  569. }
  570. void ExportTemplateManager::_open_template_folder(const String &p_version) {
  571. const String &templates_dir = EditorPaths::get_singleton()->get_export_templates_dir();
  572. OS::get_singleton()->shell_show_in_file_manager(templates_dir.path_join(p_version), true);
  573. }
  574. void ExportTemplateManager::popup_manager() {
  575. _update_template_status();
  576. switch (_get_downloads_availability()) {
  577. case DOWNLOADS_AVAILABLE: {
  578. current_missing_label->set_text(TTR("Export templates are missing. Download them or install from a file."));
  579. mirrors_list->clear();
  580. mirrors_list->add_item(TTR("Best available mirror"), 0);
  581. mirrors_list->set_disabled(false);
  582. mirrors_list->set_tooltip_text("");
  583. mirror_options_button->set_disabled(false);
  584. download_current_button->set_disabled(false);
  585. download_current_button->set_tooltip_text("");
  586. if (!is_downloading_templates) {
  587. _refresh_mirrors();
  588. }
  589. enable_online_hb->hide();
  590. } break;
  591. case DOWNLOADS_NOT_AVAILABLE_IN_OFFLINE_MODE: {
  592. current_missing_label->set_text(TTR("Export templates are missing. Install them from a file."));
  593. mirrors_list->clear();
  594. mirrors_list->add_item(TTR("Not available in offline mode"), 0);
  595. mirrors_list->set_disabled(true);
  596. mirrors_list->set_tooltip_text(TTR("Template downloading is disabled in offline mode."));
  597. mirror_options_button->set_disabled(true);
  598. download_current_button->set_disabled(true);
  599. download_current_button->set_tooltip_text(TTR("Template downloading is disabled in offline mode."));
  600. enable_online_hb->show();
  601. } break;
  602. case DOWNLOADS_NOT_AVAILABLE_FOR_DEV_BUILDS: {
  603. current_missing_label->set_text(TTR("Export templates are missing. Install them from a file."));
  604. mirrors_list->clear();
  605. mirrors_list->add_item(TTR("No templates for development builds"), 0);
  606. mirrors_list->set_disabled(true);
  607. mirrors_list->set_tooltip_text(TTR("Official export templates aren't available for development builds."));
  608. mirror_options_button->set_disabled(true);
  609. download_current_button->set_disabled(true);
  610. download_current_button->set_tooltip_text(TTR("Official export templates aren't available for development builds."));
  611. enable_online_hb->hide();
  612. } break;
  613. case DOWNLOADS_NOT_AVAILABLE_FOR_DOUBLE_BUILDS: {
  614. current_missing_label->set_text(TTR("Export templates are missing. Install them from a file."));
  615. mirrors_list->clear();
  616. mirrors_list->add_item(TTR("No templates for double-precision builds"), 0);
  617. mirrors_list->set_disabled(true);
  618. mirrors_list->set_tooltip_text(TTR("Official export templates aren't available for double-precision builds."));
  619. mirror_options_button->set_disabled(true);
  620. download_current_button->set_disabled(true);
  621. download_current_button->set_tooltip_text(TTR("Official export templates aren't available for double-precision builds."));
  622. }
  623. }
  624. popup_centered(Size2(720, 280) * EDSCALE);
  625. }
  626. void ExportTemplateManager::ok_pressed() {
  627. if (!is_downloading_templates) {
  628. hide();
  629. return;
  630. }
  631. hide_dialog_accept->popup_centered();
  632. }
  633. void ExportTemplateManager::_hide_dialog() {
  634. hide();
  635. }
  636. String ExportTemplateManager::get_android_build_directory(const Ref<EditorExportPreset> &p_preset) {
  637. if (p_preset.is_valid()) {
  638. String gradle_build_dir = p_preset->get("gradle_build/gradle_build_directory");
  639. if (!gradle_build_dir.is_empty()) {
  640. return gradle_build_dir.path_join("build");
  641. }
  642. }
  643. return "res://android/build";
  644. }
  645. String ExportTemplateManager::get_android_source_zip(const Ref<EditorExportPreset> &p_preset) {
  646. if (p_preset.is_valid()) {
  647. String android_source_zip = p_preset->get("gradle_build/android_source_template");
  648. if (!android_source_zip.is_empty()) {
  649. return android_source_zip;
  650. }
  651. }
  652. const String templates_dir = EditorPaths::get_singleton()->get_export_templates_dir().path_join(GODOT_VERSION_FULL_CONFIG);
  653. return templates_dir.path_join("android_source.zip");
  654. }
  655. String ExportTemplateManager::get_android_template_identifier(const Ref<EditorExportPreset> &p_preset) {
  656. // The template identifier is the Godot version for the default template, and the full path plus md5 hash for custom templates.
  657. if (p_preset.is_valid()) {
  658. String android_source_zip = p_preset->get("gradle_build/android_source_template");
  659. if (!android_source_zip.is_empty()) {
  660. return android_source_zip + String(" [") + FileAccess::get_md5(android_source_zip) + String("]");
  661. }
  662. }
  663. return GODOT_VERSION_FULL_CONFIG;
  664. }
  665. bool ExportTemplateManager::is_android_template_installed(const Ref<EditorExportPreset> &p_preset) {
  666. return DirAccess::exists(get_android_build_directory(p_preset));
  667. }
  668. bool ExportTemplateManager::can_install_android_template(const Ref<EditorExportPreset> &p_preset) {
  669. return FileAccess::exists(get_android_source_zip(p_preset));
  670. }
  671. Error ExportTemplateManager::install_android_template(const Ref<EditorExportPreset> &p_preset) {
  672. const String source_zip = get_android_source_zip(p_preset);
  673. ERR_FAIL_COND_V(!FileAccess::exists(source_zip), ERR_CANT_OPEN);
  674. return install_android_template_from_file(source_zip, p_preset);
  675. }
  676. Error ExportTemplateManager::install_android_template_from_file(const String &p_file, const Ref<EditorExportPreset> &p_preset) {
  677. // To support custom Android builds, we install the Java source code and buildsystem
  678. // from android_source.zip to the project's res://android folder.
  679. Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
  680. ERR_FAIL_COND_V(da.is_null(), ERR_CANT_CREATE);
  681. String build_dir = get_android_build_directory(p_preset);
  682. String parent_dir = build_dir.get_base_dir();
  683. // Make parent of the build dir (if it does not exist).
  684. da->make_dir_recursive(parent_dir);
  685. {
  686. // Add identifier, to ensure building won't work if the current template doesn't match.
  687. Ref<FileAccess> f = FileAccess::open(parent_dir.path_join(".build_version"), FileAccess::WRITE);
  688. ERR_FAIL_COND_V(f.is_null(), ERR_CANT_CREATE);
  689. f->store_line(get_android_template_identifier(p_preset));
  690. }
  691. // Create the android build directory.
  692. Error err = da->make_dir_recursive(build_dir);
  693. ERR_FAIL_COND_V(err != OK, err);
  694. {
  695. // Add an empty .gdignore file to avoid scan.
  696. Ref<FileAccess> f = FileAccess::open(build_dir.path_join(".gdignore"), FileAccess::WRITE);
  697. ERR_FAIL_COND_V(f.is_null(), ERR_CANT_CREATE);
  698. f->store_line("");
  699. }
  700. // Uncompress source template.
  701. Ref<FileAccess> io_fa;
  702. zlib_filefunc_def io = zipio_create_io(&io_fa);
  703. unzFile pkg = unzOpen2(p_file.utf8().get_data(), &io);
  704. ERR_FAIL_NULL_V_MSG(pkg, ERR_CANT_OPEN, "Android sources not in ZIP format.");
  705. int ret = unzGoToFirstFile(pkg);
  706. int total_files = 0;
  707. // Count files to unzip.
  708. while (ret == UNZ_OK) {
  709. total_files++;
  710. ret = unzGoToNextFile(pkg);
  711. }
  712. ret = unzGoToFirstFile(pkg);
  713. ProgressDialog::get_singleton()->add_task("uncompress_src", TTR("Uncompressing Android Build Sources"), total_files);
  714. HashSet<String> dirs_tested;
  715. int idx = 0;
  716. while (ret == UNZ_OK) {
  717. // Get file path.
  718. unz_file_info info;
  719. char fpath[16384];
  720. ret = unzGetCurrentFileInfo(pkg, &info, fpath, 16384, nullptr, 0, nullptr, 0);
  721. if (ret != UNZ_OK) {
  722. break;
  723. }
  724. String path = String::utf8(fpath);
  725. String base_dir = path.get_base_dir();
  726. if (!path.ends_with("/")) {
  727. Vector<uint8_t> uncomp_data;
  728. uncomp_data.resize(info.uncompressed_size);
  729. // Read.
  730. unzOpenCurrentFile(pkg);
  731. unzReadCurrentFile(pkg, uncomp_data.ptrw(), uncomp_data.size());
  732. unzCloseCurrentFile(pkg);
  733. if (!dirs_tested.has(base_dir)) {
  734. da->make_dir_recursive(build_dir.path_join(base_dir));
  735. dirs_tested.insert(base_dir);
  736. }
  737. String to_write = build_dir.path_join(path);
  738. Ref<FileAccess> f = FileAccess::open(to_write, FileAccess::WRITE);
  739. if (f.is_valid()) {
  740. f->store_buffer(uncomp_data.ptr(), uncomp_data.size());
  741. f.unref(); // close file.
  742. #ifndef WINDOWS_ENABLED
  743. FileAccess::set_unix_permissions(to_write, (info.external_fa >> 16) & 0x01FF);
  744. #endif
  745. } else {
  746. ERR_PRINT("Can't uncompress file: " + to_write);
  747. }
  748. }
  749. ProgressDialog::get_singleton()->task_step("uncompress_src", path, idx);
  750. idx++;
  751. ret = unzGoToNextFile(pkg);
  752. }
  753. ProgressDialog::get_singleton()->end_task("uncompress_src");
  754. unzClose(pkg);
  755. EditorFileSystem::get_singleton()->scan_changes();
  756. return OK;
  757. }
  758. void ExportTemplateManager::_notification(int p_what) {
  759. switch (p_what) {
  760. case NOTIFICATION_ENTER_TREE:
  761. case NOTIFICATION_THEME_CHANGED: {
  762. current_value->add_theme_font_override(SceneStringName(font), get_theme_font(SNAME("main"), EditorStringName(EditorFonts)));
  763. current_missing_label->add_theme_color_override(SceneStringName(font_color), get_theme_color(SNAME("error_color"), EditorStringName(Editor)));
  764. current_installed_label->add_theme_color_override(SceneStringName(font_color), get_theme_color(SNAME("font_disabled_color"), EditorStringName(Editor)));
  765. mirror_options_button->set_button_icon(get_editor_theme_icon(SNAME("GuiTabMenuHl")));
  766. } break;
  767. case NOTIFICATION_VISIBILITY_CHANGED: {
  768. if (!is_visible()) {
  769. set_process(false);
  770. } else if (is_visible() && is_downloading_templates) {
  771. set_process(true);
  772. }
  773. } break;
  774. case NOTIFICATION_PROCESS: {
  775. update_countdown -= get_process_delta_time();
  776. if (update_countdown > 0) {
  777. return;
  778. }
  779. update_countdown = 0.5;
  780. String status;
  781. int downloaded_bytes;
  782. int total_bytes;
  783. bool success = _humanize_http_status(download_templates, &status, &downloaded_bytes, &total_bytes);
  784. if (downloaded_bytes >= 0) {
  785. if (total_bytes > 0) {
  786. _set_current_progress_value(float(downloaded_bytes) / total_bytes, status);
  787. } else {
  788. _set_current_progress_value(0, status);
  789. }
  790. } else {
  791. _set_current_progress_status(status);
  792. }
  793. if (!success) {
  794. set_process(false);
  795. }
  796. } break;
  797. case NOTIFICATION_WM_CLOSE_REQUEST: {
  798. // This won't stop the window from closing, but will show the alert if the download is active.
  799. ok_pressed();
  800. } break;
  801. }
  802. }
  803. ExportTemplateManager::ExportTemplateManager() {
  804. set_title(TTR("Export Template Manager"));
  805. set_hide_on_ok(false);
  806. set_ok_button_text(TTR("Close"));
  807. VBoxContainer *main_vb = memnew(VBoxContainer);
  808. add_child(main_vb);
  809. // Current version controls.
  810. HBoxContainer *current_hb = memnew(HBoxContainer);
  811. main_vb->add_child(current_hb);
  812. Label *current_label = memnew(Label);
  813. current_label->set_theme_type_variation("HeaderSmall");
  814. current_label->set_text(TTR("Current Version:"));
  815. current_hb->add_child(current_label);
  816. current_value = memnew(Label);
  817. current_value->set_focus_mode(Control::FOCUS_ACCESSIBILITY);
  818. current_hb->add_child(current_value);
  819. // Current version statuses.
  820. // Status: Current version is missing.
  821. current_missing_label = memnew(Label);
  822. current_missing_label->set_theme_type_variation("HeaderSmall");
  823. current_missing_label->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  824. current_missing_label->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_RIGHT);
  825. current_hb->add_child(current_missing_label);
  826. // Status: Current version is installed.
  827. current_installed_label = memnew(Label);
  828. current_installed_label->set_theme_type_variation("HeaderSmall");
  829. current_installed_label->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  830. current_installed_label->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_RIGHT);
  831. current_installed_label->set_text(TTR("Export templates are installed and ready to be used."));
  832. current_hb->add_child(current_installed_label);
  833. current_installed_label->hide();
  834. // Currently installed template.
  835. current_installed_hb = memnew(HBoxContainer);
  836. main_vb->add_child(current_installed_hb);
  837. current_installed_path = memnew(LineEdit);
  838. current_installed_path->set_editable(false);
  839. current_installed_path->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  840. current_installed_path->set_accessibility_name(TTRC("Installed Path"));
  841. current_installed_hb->add_child(current_installed_path);
  842. #ifndef ANDROID_ENABLED
  843. Button *current_open_button = memnew(Button);
  844. current_open_button->set_text(TTR("Open Folder"));
  845. current_open_button->set_tooltip_text(TTR("Open the folder containing installed templates for the current version."));
  846. current_installed_hb->add_child(current_open_button);
  847. current_open_button->connect(SceneStringName(pressed), callable_mp(this, &ExportTemplateManager::_open_template_folder).bind(GODOT_VERSION_FULL_CONFIG));
  848. #endif
  849. current_uninstall_button = memnew(Button);
  850. current_uninstall_button->set_text(TTR("Uninstall"));
  851. current_uninstall_button->set_tooltip_text(TTR("Uninstall templates for the current version."));
  852. current_installed_hb->add_child(current_uninstall_button);
  853. current_uninstall_button->connect(SceneStringName(pressed), callable_mp(this, &ExportTemplateManager::_uninstall_template).bind(GODOT_VERSION_FULL_CONFIG));
  854. main_vb->add_child(memnew(HSeparator));
  855. // Download and install section.
  856. HBoxContainer *install_templates_hb = memnew(HBoxContainer);
  857. main_vb->add_child(install_templates_hb);
  858. // Download and install buttons are available.
  859. install_options_vb = memnew(VBoxContainer);
  860. install_options_vb->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  861. install_templates_hb->add_child(install_options_vb);
  862. HBoxContainer *download_install_hb = memnew(HBoxContainer);
  863. install_options_vb->add_child(download_install_hb);
  864. Label *mirrors_label = memnew(Label);
  865. mirrors_label->set_text(TTR("Download from:"));
  866. download_install_hb->add_child(mirrors_label);
  867. mirrors_list = memnew(OptionButton);
  868. mirrors_list->set_accessibility_name(TTRC("Mirror"));
  869. mirrors_list->set_custom_minimum_size(Size2(280, 0) * EDSCALE);
  870. download_install_hb->add_child(mirrors_list);
  871. request_mirrors = memnew(HTTPRequest);
  872. mirrors_list->add_child(request_mirrors);
  873. request_mirrors->connect("request_completed", callable_mp(this, &ExportTemplateManager::_refresh_mirrors_completed));
  874. mirror_options_button = memnew(MenuButton);
  875. mirror_options_button->set_accessibility_name(TTRC("Mirror Options"));
  876. mirror_options_button->get_popup()->add_item(TTR("Open in Web Browser"), VISIT_WEB_MIRROR);
  877. mirror_options_button->get_popup()->add_item(TTR("Copy Mirror URL"), COPY_MIRROR_URL);
  878. download_install_hb->add_child(mirror_options_button);
  879. mirror_options_button->get_popup()->connect(SceneStringName(id_pressed), callable_mp(this, &ExportTemplateManager::_mirror_options_button_cbk));
  880. download_install_hb->add_spacer();
  881. download_current_button = memnew(Button);
  882. download_current_button->set_text(TTR("Download and Install"));
  883. download_current_button->set_tooltip_text(TTR("Download and install templates for the current version from the best possible mirror."));
  884. download_install_hb->add_child(download_current_button);
  885. download_current_button->connect(SceneStringName(pressed), callable_mp(this, &ExportTemplateManager::_download_current));
  886. HBoxContainer *install_file_hb = memnew(HBoxContainer);
  887. install_file_hb->set_alignment(BoxContainer::ALIGNMENT_END);
  888. install_options_vb->add_child(install_file_hb);
  889. install_file_button = memnew(Button);
  890. install_file_button->set_text(TTR("Install from File"));
  891. install_file_button->set_tooltip_text(TTR("Install templates from a local file."));
  892. install_file_hb->add_child(install_file_button);
  893. install_file_button->connect(SceneStringName(pressed), callable_mp(this, &ExportTemplateManager::_install_file));
  894. enable_online_hb = memnew(HBoxContainer);
  895. install_options_vb->add_child(enable_online_hb);
  896. Label *enable_online_label = memnew(Label);
  897. enable_online_label->set_text(TTR("Online mode is needed to download the templates."));
  898. enable_online_hb->add_child(enable_online_label);
  899. LinkButton *enable_online_button = memnew(LinkButton);
  900. enable_online_button->set_v_size_flags(Control::SIZE_SHRINK_CENTER);
  901. enable_online_button->set_text(TTR("Go Online"));
  902. enable_online_hb->add_child(enable_online_button);
  903. enable_online_button->connect(SceneStringName(pressed), callable_mp(this, &ExportTemplateManager::_force_online_mode));
  904. // Templates are being downloaded; buttons unavailable.
  905. download_progress_hb = memnew(HBoxContainer);
  906. download_progress_hb->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  907. install_templates_hb->add_child(download_progress_hb);
  908. download_progress_hb->hide();
  909. download_progress_bar = memnew(ProgressBar);
  910. download_progress_bar->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  911. download_progress_bar->set_v_size_flags(Control::SIZE_SHRINK_CENTER);
  912. download_progress_bar->set_min(0);
  913. download_progress_bar->set_max(1);
  914. download_progress_bar->set_value(0);
  915. download_progress_bar->set_step(0.01);
  916. download_progress_bar->set_editor_preview_indeterminate(true);
  917. download_progress_hb->add_child(download_progress_bar);
  918. download_progress_label = memnew(Label);
  919. download_progress_label->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  920. download_progress_hb->add_child(download_progress_label);
  921. Button *download_cancel_button = memnew(Button);
  922. download_cancel_button->set_text(TTR("Cancel"));
  923. download_cancel_button->set_tooltip_text(TTR("Cancel the download of the templates."));
  924. download_progress_hb->add_child(download_cancel_button);
  925. download_cancel_button->connect(SceneStringName(pressed), callable_mp(this, &ExportTemplateManager::_cancel_template_download));
  926. download_templates = memnew(HTTPRequest);
  927. install_templates_hb->add_child(download_templates);
  928. download_templates->connect("request_completed", callable_mp(this, &ExportTemplateManager::_download_template_completed));
  929. main_vb->add_child(memnew(HSeparator));
  930. // Other installed templates table.
  931. HBoxContainer *installed_versions_hb = memnew(HBoxContainer);
  932. main_vb->add_child(installed_versions_hb);
  933. Label *installed_label = memnew(Label);
  934. installed_label->set_theme_type_variation("HeaderSmall");
  935. installed_label->set_text(TTR("Other Installed Versions:"));
  936. installed_versions_hb->add_child(installed_label);
  937. installed_table = memnew(Tree);
  938. installed_table->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
  939. installed_table->set_hide_root(true);
  940. installed_table->set_custom_minimum_size(Size2(0, 100) * EDSCALE);
  941. installed_table->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  942. main_vb->add_child(installed_table);
  943. installed_table->connect("button_clicked", callable_mp(this, &ExportTemplateManager::_installed_table_button_cbk));
  944. // Dialogs.
  945. uninstall_confirm = memnew(ConfirmationDialog);
  946. uninstall_confirm->set_title(TTR("Uninstall Template"));
  947. add_child(uninstall_confirm);
  948. uninstall_confirm->connect(SceneStringName(confirmed), callable_mp(this, &ExportTemplateManager::_uninstall_template_confirmed));
  949. install_file_dialog = memnew(FileDialog);
  950. install_file_dialog->set_title(TTR("Select Template File"));
  951. install_file_dialog->set_access(FileDialog::ACCESS_FILESYSTEM);
  952. install_file_dialog->set_file_mode(FileDialog::FILE_MODE_OPEN_FILE);
  953. install_file_dialog->set_current_dir(EDITOR_DEF("_export_template_download_directory", ""));
  954. install_file_dialog->add_filter("*.tpz", TTR("Godot Export Templates"));
  955. install_file_dialog->connect("file_selected", callable_mp(this, &ExportTemplateManager::_install_file_selected).bind(false));
  956. add_child(install_file_dialog);
  957. hide_dialog_accept = memnew(AcceptDialog);
  958. hide_dialog_accept->set_text(TTR("The templates will continue to download.\nYou may experience a short editor freeze when they finish."));
  959. add_child(hide_dialog_accept);
  960. hide_dialog_accept->connect(SceneStringName(confirmed), callable_mp(this, &ExportTemplateManager::_hide_dialog));
  961. }