export_template_manager.cpp 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152
  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/separator.h"
  47. #include "scene/gui/tree.h"
  48. #include "scene/main/http_request.h"
  49. enum DownloadsAvailability {
  50. DOWNLOADS_AVAILABLE,
  51. DOWNLOADS_NOT_AVAILABLE_IN_OFFLINE_MODE,
  52. DOWNLOADS_NOT_AVAILABLE_FOR_DEV_BUILDS,
  53. };
  54. static DownloadsAvailability _get_downloads_availability() {
  55. const int network_mode = EDITOR_GET("network/connection/network_mode");
  56. // Downloadable export templates are only available for stable and official alpha/beta/RC builds
  57. // (which always have a number following their status, e.g. "alpha1").
  58. // Therefore, don't display download-related features when using a development version
  59. // (whose builds aren't numbered).
  60. if (String(GODOT_VERSION_STATUS) == String("dev") ||
  61. String(GODOT_VERSION_STATUS) == String("alpha") ||
  62. String(GODOT_VERSION_STATUS) == String("beta") ||
  63. String(GODOT_VERSION_STATUS) == String("rc")) {
  64. return DOWNLOADS_NOT_AVAILABLE_FOR_DEV_BUILDS;
  65. }
  66. if (network_mode == EditorSettings::NETWORK_OFFLINE) {
  67. return DOWNLOADS_NOT_AVAILABLE_IN_OFFLINE_MODE;
  68. }
  69. return DOWNLOADS_AVAILABLE;
  70. }
  71. void ExportTemplateManager::_update_template_status() {
  72. // Fetch installed templates from the file system.
  73. Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  74. const String &templates_dir = EditorPaths::get_singleton()->get_export_templates_dir();
  75. Error err = da->change_dir(templates_dir);
  76. ERR_FAIL_COND_MSG(err != OK, "Could not access templates directory at '" + templates_dir + "'.");
  77. RBSet<String> templates;
  78. da->list_dir_begin();
  79. if (err == OK) {
  80. String c = da->get_next();
  81. while (!c.is_empty()) {
  82. if (da->current_is_dir() && !c.begins_with(".")) {
  83. templates.insert(c);
  84. }
  85. c = da->get_next();
  86. }
  87. }
  88. da->list_dir_end();
  89. // Update the state of the current version.
  90. String current_version = GODOT_VERSION_FULL_CONFIG;
  91. current_value->set_text(current_version);
  92. if (templates.has(current_version)) {
  93. current_missing_label->hide();
  94. current_installed_label->show();
  95. current_installed_hb->show();
  96. current_version_exists = true;
  97. } else {
  98. current_installed_label->hide();
  99. current_missing_label->show();
  100. current_installed_hb->hide();
  101. current_version_exists = false;
  102. }
  103. if (is_downloading_templates) {
  104. install_options_vb->hide();
  105. download_progress_hb->show();
  106. } else {
  107. download_progress_hb->hide();
  108. install_options_vb->show();
  109. if (templates.has(current_version)) {
  110. current_installed_path->set_text(templates_dir.path_join(current_version));
  111. }
  112. }
  113. // Update the list of other installed versions.
  114. installed_table->clear();
  115. TreeItem *installed_root = installed_table->create_item();
  116. for (RBSet<String>::Element *E = templates.back(); E; E = E->prev()) {
  117. String version_string = E->get();
  118. if (version_string == current_version) {
  119. continue;
  120. }
  121. TreeItem *ti = installed_table->create_item(installed_root);
  122. ti->set_text(0, version_string);
  123. #ifndef ANDROID_ENABLED
  124. ti->add_button(0, get_editor_theme_icon(SNAME("Folder")), OPEN_TEMPLATE_FOLDER, false, TTR("Open the folder containing these templates."));
  125. #endif
  126. ti->add_button(0, get_editor_theme_icon(SNAME("Remove")), UNINSTALL_TEMPLATE, false, TTR("Uninstall these templates."));
  127. }
  128. }
  129. void ExportTemplateManager::_download_current() {
  130. if (is_downloading_templates) {
  131. return;
  132. }
  133. is_downloading_templates = true;
  134. install_options_vb->hide();
  135. download_progress_hb->show();
  136. if (mirrors_available) {
  137. String mirror_url = _get_selected_mirror();
  138. if (mirror_url.is_empty()) {
  139. _set_current_progress_status(TTR("There are no mirrors available."), true);
  140. return;
  141. }
  142. _download_template(mirror_url, true);
  143. } else if (!is_refreshing_mirrors) {
  144. _set_current_progress_status(TTR("Retrieving the mirror list..."));
  145. _refresh_mirrors();
  146. }
  147. }
  148. void ExportTemplateManager::_download_template(const String &p_url, bool p_skip_check) {
  149. if (!p_skip_check && is_downloading_templates) {
  150. return;
  151. }
  152. is_downloading_templates = true;
  153. install_options_vb->hide();
  154. download_progress_hb->show();
  155. download_progress_bar->show();
  156. download_progress_bar->set_indeterminate(true);
  157. _set_current_progress_status(TTR("Starting the download..."));
  158. download_templates->set_download_file(EditorPaths::get_singleton()->get_cache_dir().path_join("tmp_templates.tpz"));
  159. download_templates->set_use_threads(true);
  160. const String proxy_host = EDITOR_GET("network/http_proxy/host");
  161. const int proxy_port = EDITOR_GET("network/http_proxy/port");
  162. download_templates->set_http_proxy(proxy_host, proxy_port);
  163. download_templates->set_https_proxy(proxy_host, proxy_port);
  164. Error err = download_templates->request(p_url);
  165. if (err != OK) {
  166. _set_current_progress_status(TTR("Error requesting URL:") + " " + p_url, true);
  167. download_progress_hb->hide();
  168. return;
  169. }
  170. set_process(true);
  171. _set_current_progress_status(TTR("Connecting to the mirror..."));
  172. }
  173. void ExportTemplateManager::_download_template_completed(int p_status, int p_code, const PackedStringArray &headers, const PackedByteArray &p_data) {
  174. switch (p_status) {
  175. case HTTPRequest::RESULT_CANT_RESOLVE: {
  176. _set_current_progress_status(TTR("Can't resolve the requested address."), true);
  177. } break;
  178. case HTTPRequest::RESULT_BODY_SIZE_LIMIT_EXCEEDED:
  179. case HTTPRequest::RESULT_CONNECTION_ERROR:
  180. case HTTPRequest::RESULT_CHUNKED_BODY_SIZE_MISMATCH:
  181. case HTTPRequest::RESULT_TLS_HANDSHAKE_ERROR:
  182. case HTTPRequest::RESULT_CANT_CONNECT: {
  183. _set_current_progress_status(TTR("Can't connect to the mirror."), true);
  184. } break;
  185. case HTTPRequest::RESULT_NO_RESPONSE: {
  186. _set_current_progress_status(TTR("No response from the mirror."), true);
  187. } break;
  188. case HTTPRequest::RESULT_REQUEST_FAILED: {
  189. _set_current_progress_status(TTR("Request failed."), true);
  190. } break;
  191. case HTTPRequest::RESULT_REDIRECT_LIMIT_REACHED: {
  192. _set_current_progress_status(TTR("Request ended up in a redirect loop."), true);
  193. } break;
  194. default: {
  195. if (p_code != 200) {
  196. _set_current_progress_status(TTR("Request failed:") + " " + itos(p_code), true);
  197. } else {
  198. _set_current_progress_status(TTR("Download complete; extracting templates..."));
  199. String path = download_templates->get_download_file();
  200. is_downloading_templates = false;
  201. bool ret = _install_file_selected(path, true);
  202. if (ret) {
  203. // Clean up downloaded file.
  204. Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  205. Error err = da->remove(path);
  206. if (err != OK) {
  207. EditorNode::get_singleton()->add_io_error(TTR("Cannot remove temporary file:") + "\n" + path + "\n");
  208. }
  209. } else {
  210. EditorNode::get_singleton()->add_io_error(vformat(TTR("Templates installation failed.\nThe problematic templates archives can be found at '%s'."), path));
  211. }
  212. }
  213. } break;
  214. }
  215. set_process(false);
  216. }
  217. void ExportTemplateManager::_cancel_template_download() {
  218. if (!is_downloading_templates) {
  219. return;
  220. }
  221. download_templates->cancel_request();
  222. download_progress_hb->hide();
  223. install_options_vb->show();
  224. is_downloading_templates = false;
  225. }
  226. void ExportTemplateManager::_refresh_mirrors() {
  227. if (is_refreshing_mirrors) {
  228. return;
  229. }
  230. is_refreshing_mirrors = true;
  231. String current_version = GODOT_VERSION_FULL_CONFIG;
  232. const String mirrors_metadata_url = "https://godotengine.org/mirrorlist/" + current_version + ".json";
  233. request_mirrors->request(mirrors_metadata_url);
  234. }
  235. void ExportTemplateManager::_refresh_mirrors_completed(int p_status, int p_code, const PackedStringArray &headers, const PackedByteArray &p_data) {
  236. if (p_status != HTTPRequest::RESULT_SUCCESS || p_code != 200) {
  237. EditorNode::get_singleton()->show_warning(TTR("Error getting the list of mirrors."));
  238. is_refreshing_mirrors = false;
  239. if (is_downloading_templates) {
  240. _cancel_template_download();
  241. }
  242. return;
  243. }
  244. String response_json;
  245. {
  246. const uint8_t *r = p_data.ptr();
  247. response_json.parse_utf8((const char *)r, p_data.size());
  248. }
  249. JSON json;
  250. Error err = json.parse(response_json);
  251. if (err != OK) {
  252. EditorNode::get_singleton()->show_warning(TTR("Error parsing JSON with the list of mirrors. Please report this issue!"));
  253. is_refreshing_mirrors = false;
  254. if (is_downloading_templates) {
  255. _cancel_template_download();
  256. }
  257. return;
  258. }
  259. mirrors_list->clear();
  260. mirrors_list->add_item(TTR("Best available mirror"), 0);
  261. mirrors_available = false;
  262. Dictionary mirror_data = json.get_data();
  263. if (mirror_data.has("mirrors")) {
  264. Array mirrors = mirror_data["mirrors"];
  265. for (int i = 0; i < mirrors.size(); i++) {
  266. Dictionary m = mirrors[i];
  267. ERR_CONTINUE(!m.has("url") || !m.has("name"));
  268. mirrors_list->add_item(m["name"]);
  269. mirrors_list->set_item_metadata(i + 1, m["url"]);
  270. mirrors_available = true;
  271. }
  272. }
  273. if (!mirrors_available) {
  274. EditorNode::get_singleton()->show_warning(TTR("No download links found for this version. Direct download is only available for official releases."));
  275. if (is_downloading_templates) {
  276. _cancel_template_download();
  277. }
  278. }
  279. is_refreshing_mirrors = false;
  280. if (is_downloading_templates) {
  281. String mirror_url = _get_selected_mirror();
  282. if (mirror_url.is_empty()) {
  283. _set_current_progress_status(TTR("There are no mirrors available."), true);
  284. return;
  285. }
  286. _download_template(mirror_url, true);
  287. }
  288. }
  289. void ExportTemplateManager::_force_online_mode() {
  290. EditorSettings::get_singleton()->set_setting("network/connection/network_mode", EditorSettings::NETWORK_ONLINE);
  291. EditorSettings::get_singleton()->notify_changes();
  292. EditorSettings::get_singleton()->save();
  293. popup_manager();
  294. }
  295. bool ExportTemplateManager::_humanize_http_status(HTTPRequest *p_request, String *r_status, int *r_downloaded_bytes, int *r_total_bytes) {
  296. *r_status = "";
  297. *r_downloaded_bytes = -1;
  298. *r_total_bytes = -1;
  299. bool success = true;
  300. switch (p_request->get_http_client_status()) {
  301. case HTTPClient::STATUS_DISCONNECTED:
  302. *r_status = TTR("Disconnected");
  303. success = false;
  304. break;
  305. case HTTPClient::STATUS_RESOLVING:
  306. *r_status = TTR("Resolving");
  307. break;
  308. case HTTPClient::STATUS_CANT_RESOLVE:
  309. *r_status = TTR("Can't Resolve");
  310. success = false;
  311. break;
  312. case HTTPClient::STATUS_CONNECTING:
  313. *r_status = TTR("Connecting...");
  314. break;
  315. case HTTPClient::STATUS_CANT_CONNECT:
  316. *r_status = TTR("Can't Connect");
  317. success = false;
  318. break;
  319. case HTTPClient::STATUS_CONNECTED:
  320. *r_status = TTR("Connected");
  321. break;
  322. case HTTPClient::STATUS_REQUESTING:
  323. *r_status = TTR("Requesting...");
  324. break;
  325. case HTTPClient::STATUS_BODY:
  326. *r_status = TTR("Downloading");
  327. *r_downloaded_bytes = p_request->get_downloaded_bytes();
  328. *r_total_bytes = p_request->get_body_size();
  329. if (p_request->get_body_size() > 0) {
  330. *r_status += " " + String::humanize_size(p_request->get_downloaded_bytes()) + "/" + String::humanize_size(p_request->get_body_size());
  331. } else {
  332. *r_status += " " + String::humanize_size(p_request->get_downloaded_bytes());
  333. }
  334. break;
  335. case HTTPClient::STATUS_CONNECTION_ERROR:
  336. *r_status = TTR("Connection Error");
  337. success = false;
  338. break;
  339. case HTTPClient::STATUS_TLS_HANDSHAKE_ERROR:
  340. *r_status = TTR("TLS Handshake Error");
  341. success = false;
  342. break;
  343. }
  344. return success;
  345. }
  346. void ExportTemplateManager::_set_current_progress_status(const String &p_status, bool p_error) {
  347. download_progress_label->set_text(p_status);
  348. if (p_error) {
  349. download_progress_bar->hide();
  350. download_progress_label->add_theme_color_override(SceneStringName(font_color), get_theme_color(SNAME("error_color"), EditorStringName(Editor)));
  351. } else {
  352. download_progress_label->add_theme_color_override(SceneStringName(font_color), get_theme_color(SceneStringName(font_color), SNAME("Label")));
  353. }
  354. }
  355. void ExportTemplateManager::_set_current_progress_value(float p_value, const String &p_status) {
  356. download_progress_bar->show();
  357. download_progress_bar->set_indeterminate(false);
  358. download_progress_bar->set_value(p_value);
  359. download_progress_label->set_text(p_status);
  360. }
  361. void ExportTemplateManager::_install_file() {
  362. install_file_dialog->popup_file_dialog();
  363. }
  364. bool ExportTemplateManager::_install_file_selected(const String &p_file, bool p_skip_progress) {
  365. Ref<FileAccess> io_fa;
  366. zlib_filefunc_def io = zipio_create_io(&io_fa);
  367. unzFile pkg = unzOpen2(p_file.utf8().get_data(), &io);
  368. if (!pkg) {
  369. EditorNode::get_singleton()->show_warning(TTR("Can't open the export templates file."));
  370. return false;
  371. }
  372. int ret = unzGoToFirstFile(pkg);
  373. // Count them and find version.
  374. int fc = 0;
  375. String version;
  376. String contents_dir;
  377. while (ret == UNZ_OK) {
  378. unz_file_info info;
  379. char fname[16384];
  380. ret = unzGetCurrentFileInfo(pkg, &info, fname, 16384, nullptr, 0, nullptr, 0);
  381. if (ret != UNZ_OK) {
  382. break;
  383. }
  384. String file = String::utf8(fname);
  385. // Skip the __MACOSX directory created by macOS's built-in file zipper.
  386. if (file.begins_with("__MACOSX")) {
  387. ret = unzGoToNextFile(pkg);
  388. continue;
  389. }
  390. if (file.ends_with("version.txt")) {
  391. Vector<uint8_t> uncomp_data;
  392. uncomp_data.resize(info.uncompressed_size);
  393. // Read.
  394. unzOpenCurrentFile(pkg);
  395. ret = unzReadCurrentFile(pkg, uncomp_data.ptrw(), uncomp_data.size());
  396. ERR_BREAK_MSG(ret < 0, vformat("An error occurred while attempting to read from file: %s. This file will not be used.", file));
  397. unzCloseCurrentFile(pkg);
  398. String data_str;
  399. data_str.parse_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. }
  614. popup_centered(Size2(720, 280) * EDSCALE);
  615. }
  616. void ExportTemplateManager::ok_pressed() {
  617. if (!is_downloading_templates) {
  618. hide();
  619. return;
  620. }
  621. hide_dialog_accept->popup_centered();
  622. }
  623. void ExportTemplateManager::_hide_dialog() {
  624. hide();
  625. }
  626. String ExportTemplateManager::get_android_build_directory(const Ref<EditorExportPreset> &p_preset) {
  627. if (p_preset.is_valid()) {
  628. String gradle_build_dir = p_preset->get("gradle_build/gradle_build_directory");
  629. if (!gradle_build_dir.is_empty()) {
  630. return gradle_build_dir.path_join("build");
  631. }
  632. }
  633. return "res://android/build";
  634. }
  635. String ExportTemplateManager::get_android_source_zip(const Ref<EditorExportPreset> &p_preset) {
  636. if (p_preset.is_valid()) {
  637. String android_source_zip = p_preset->get("gradle_build/android_source_template");
  638. if (!android_source_zip.is_empty()) {
  639. return android_source_zip;
  640. }
  641. }
  642. const String templates_dir = EditorPaths::get_singleton()->get_export_templates_dir().path_join(GODOT_VERSION_FULL_CONFIG);
  643. return templates_dir.path_join("android_source.zip");
  644. }
  645. String ExportTemplateManager::get_android_template_identifier(const Ref<EditorExportPreset> &p_preset) {
  646. // The template identifier is the Godot version for the default template, and the full path plus md5 hash for custom templates.
  647. if (p_preset.is_valid()) {
  648. String android_source_zip = p_preset->get("gradle_build/android_source_template");
  649. if (!android_source_zip.is_empty()) {
  650. return android_source_zip + String(" [") + FileAccess::get_md5(android_source_zip) + String("]");
  651. }
  652. }
  653. return GODOT_VERSION_FULL_CONFIG;
  654. }
  655. bool ExportTemplateManager::is_android_template_installed(const Ref<EditorExportPreset> &p_preset) {
  656. return DirAccess::exists(get_android_build_directory(p_preset));
  657. }
  658. bool ExportTemplateManager::can_install_android_template(const Ref<EditorExportPreset> &p_preset) {
  659. return FileAccess::exists(get_android_source_zip(p_preset));
  660. }
  661. Error ExportTemplateManager::install_android_template(const Ref<EditorExportPreset> &p_preset) {
  662. const String source_zip = get_android_source_zip(p_preset);
  663. ERR_FAIL_COND_V(!FileAccess::exists(source_zip), ERR_CANT_OPEN);
  664. return install_android_template_from_file(source_zip, p_preset);
  665. }
  666. Error ExportTemplateManager::install_android_template_from_file(const String &p_file, const Ref<EditorExportPreset> &p_preset) {
  667. // To support custom Android builds, we install the Java source code and buildsystem
  668. // from android_source.zip to the project's res://android folder.
  669. Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
  670. ERR_FAIL_COND_V(da.is_null(), ERR_CANT_CREATE);
  671. String build_dir = get_android_build_directory(p_preset);
  672. String parent_dir = build_dir.get_base_dir();
  673. // Make parent of the build dir (if it does not exist).
  674. da->make_dir_recursive(parent_dir);
  675. {
  676. // Add identifier, to ensure building won't work if the current template doesn't match.
  677. Ref<FileAccess> f = FileAccess::open(parent_dir.path_join(".build_version"), FileAccess::WRITE);
  678. ERR_FAIL_COND_V(f.is_null(), ERR_CANT_CREATE);
  679. f->store_line(get_android_template_identifier(p_preset));
  680. }
  681. // Create the android build directory.
  682. Error err = da->make_dir_recursive(build_dir);
  683. ERR_FAIL_COND_V(err != OK, err);
  684. {
  685. // Add an empty .gdignore file to avoid scan.
  686. Ref<FileAccess> f = FileAccess::open(build_dir.path_join(".gdignore"), FileAccess::WRITE);
  687. ERR_FAIL_COND_V(f.is_null(), ERR_CANT_CREATE);
  688. f->store_line("");
  689. }
  690. // Uncompress source template.
  691. Ref<FileAccess> io_fa;
  692. zlib_filefunc_def io = zipio_create_io(&io_fa);
  693. unzFile pkg = unzOpen2(p_file.utf8().get_data(), &io);
  694. ERR_FAIL_NULL_V_MSG(pkg, ERR_CANT_OPEN, "Android sources not in ZIP format.");
  695. int ret = unzGoToFirstFile(pkg);
  696. int total_files = 0;
  697. // Count files to unzip.
  698. while (ret == UNZ_OK) {
  699. total_files++;
  700. ret = unzGoToNextFile(pkg);
  701. }
  702. ret = unzGoToFirstFile(pkg);
  703. ProgressDialog::get_singleton()->add_task("uncompress_src", TTR("Uncompressing Android Build Sources"), total_files);
  704. HashSet<String> dirs_tested;
  705. int idx = 0;
  706. while (ret == UNZ_OK) {
  707. // Get file path.
  708. unz_file_info info;
  709. char fpath[16384];
  710. ret = unzGetCurrentFileInfo(pkg, &info, fpath, 16384, nullptr, 0, nullptr, 0);
  711. if (ret != UNZ_OK) {
  712. break;
  713. }
  714. String path = String::utf8(fpath);
  715. String base_dir = path.get_base_dir();
  716. if (!path.ends_with("/")) {
  717. Vector<uint8_t> uncomp_data;
  718. uncomp_data.resize(info.uncompressed_size);
  719. // Read.
  720. unzOpenCurrentFile(pkg);
  721. unzReadCurrentFile(pkg, uncomp_data.ptrw(), uncomp_data.size());
  722. unzCloseCurrentFile(pkg);
  723. if (!dirs_tested.has(base_dir)) {
  724. da->make_dir_recursive(build_dir.path_join(base_dir));
  725. dirs_tested.insert(base_dir);
  726. }
  727. String to_write = build_dir.path_join(path);
  728. Ref<FileAccess> f = FileAccess::open(to_write, FileAccess::WRITE);
  729. if (f.is_valid()) {
  730. f->store_buffer(uncomp_data.ptr(), uncomp_data.size());
  731. f.unref(); // close file.
  732. #ifndef WINDOWS_ENABLED
  733. FileAccess::set_unix_permissions(to_write, (info.external_fa >> 16) & 0x01FF);
  734. #endif
  735. } else {
  736. ERR_PRINT("Can't uncompress file: " + to_write);
  737. }
  738. }
  739. ProgressDialog::get_singleton()->task_step("uncompress_src", path, idx);
  740. idx++;
  741. ret = unzGoToNextFile(pkg);
  742. }
  743. ProgressDialog::get_singleton()->end_task("uncompress_src");
  744. unzClose(pkg);
  745. EditorFileSystem::get_singleton()->scan_changes();
  746. return OK;
  747. }
  748. void ExportTemplateManager::_notification(int p_what) {
  749. switch (p_what) {
  750. case NOTIFICATION_ENTER_TREE:
  751. case NOTIFICATION_THEME_CHANGED: {
  752. current_value->add_theme_font_override(SceneStringName(font), get_theme_font(SNAME("main"), EditorStringName(EditorFonts)));
  753. current_missing_label->add_theme_color_override(SceneStringName(font_color), get_theme_color(SNAME("error_color"), EditorStringName(Editor)));
  754. current_installed_label->add_theme_color_override(SceneStringName(font_color), get_theme_color(SNAME("font_disabled_color"), EditorStringName(Editor)));
  755. mirror_options_button->set_button_icon(get_editor_theme_icon(SNAME("GuiTabMenuHl")));
  756. } break;
  757. case NOTIFICATION_VISIBILITY_CHANGED: {
  758. if (!is_visible()) {
  759. set_process(false);
  760. } else if (is_visible() && is_downloading_templates) {
  761. set_process(true);
  762. }
  763. } break;
  764. case NOTIFICATION_PROCESS: {
  765. update_countdown -= get_process_delta_time();
  766. if (update_countdown > 0) {
  767. return;
  768. }
  769. update_countdown = 0.5;
  770. String status;
  771. int downloaded_bytes;
  772. int total_bytes;
  773. bool success = _humanize_http_status(download_templates, &status, &downloaded_bytes, &total_bytes);
  774. if (downloaded_bytes >= 0) {
  775. if (total_bytes > 0) {
  776. _set_current_progress_value(float(downloaded_bytes) / total_bytes, status);
  777. } else {
  778. _set_current_progress_value(0, status);
  779. }
  780. } else {
  781. _set_current_progress_status(status);
  782. }
  783. if (!success) {
  784. set_process(false);
  785. }
  786. } break;
  787. case NOTIFICATION_WM_CLOSE_REQUEST: {
  788. // This won't stop the window from closing, but will show the alert if the download is active.
  789. ok_pressed();
  790. } break;
  791. }
  792. }
  793. ExportTemplateManager::ExportTemplateManager() {
  794. set_title(TTR("Export Template Manager"));
  795. set_hide_on_ok(false);
  796. set_ok_button_text(TTR("Close"));
  797. VBoxContainer *main_vb = memnew(VBoxContainer);
  798. add_child(main_vb);
  799. // Current version controls.
  800. HBoxContainer *current_hb = memnew(HBoxContainer);
  801. main_vb->add_child(current_hb);
  802. Label *current_label = memnew(Label);
  803. current_label->set_theme_type_variation("HeaderSmall");
  804. current_label->set_text(TTR("Current Version:"));
  805. current_hb->add_child(current_label);
  806. current_value = memnew(Label);
  807. current_hb->add_child(current_value);
  808. // Current version statuses.
  809. // Status: Current version is missing.
  810. current_missing_label = memnew(Label);
  811. current_missing_label->set_theme_type_variation("HeaderSmall");
  812. current_missing_label->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  813. current_missing_label->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_RIGHT);
  814. current_hb->add_child(current_missing_label);
  815. // Status: Current version is installed.
  816. current_installed_label = memnew(Label);
  817. current_installed_label->set_theme_type_variation("HeaderSmall");
  818. current_installed_label->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  819. current_installed_label->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_RIGHT);
  820. current_installed_label->set_text(TTR("Export templates are installed and ready to be used."));
  821. current_hb->add_child(current_installed_label);
  822. current_installed_label->hide();
  823. // Currently installed template.
  824. current_installed_hb = memnew(HBoxContainer);
  825. main_vb->add_child(current_installed_hb);
  826. current_installed_path = memnew(LineEdit);
  827. current_installed_path->set_editable(false);
  828. current_installed_path->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  829. current_installed_hb->add_child(current_installed_path);
  830. #ifndef ANDROID_ENABLED
  831. Button *current_open_button = memnew(Button);
  832. current_open_button->set_text(TTR("Open Folder"));
  833. current_open_button->set_tooltip_text(TTR("Open the folder containing installed templates for the current version."));
  834. current_installed_hb->add_child(current_open_button);
  835. current_open_button->connect(SceneStringName(pressed), callable_mp(this, &ExportTemplateManager::_open_template_folder).bind(GODOT_VERSION_FULL_CONFIG));
  836. #endif
  837. current_uninstall_button = memnew(Button);
  838. current_uninstall_button->set_text(TTR("Uninstall"));
  839. current_uninstall_button->set_tooltip_text(TTR("Uninstall templates for the current version."));
  840. current_installed_hb->add_child(current_uninstall_button);
  841. current_uninstall_button->connect(SceneStringName(pressed), callable_mp(this, &ExportTemplateManager::_uninstall_template).bind(GODOT_VERSION_FULL_CONFIG));
  842. main_vb->add_child(memnew(HSeparator));
  843. // Download and install section.
  844. HBoxContainer *install_templates_hb = memnew(HBoxContainer);
  845. main_vb->add_child(install_templates_hb);
  846. // Download and install buttons are available.
  847. install_options_vb = memnew(VBoxContainer);
  848. install_options_vb->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  849. install_templates_hb->add_child(install_options_vb);
  850. HBoxContainer *download_install_hb = memnew(HBoxContainer);
  851. install_options_vb->add_child(download_install_hb);
  852. Label *mirrors_label = memnew(Label);
  853. mirrors_label->set_text(TTR("Download from:"));
  854. download_install_hb->add_child(mirrors_label);
  855. mirrors_list = memnew(OptionButton);
  856. mirrors_list->set_custom_minimum_size(Size2(280, 0) * EDSCALE);
  857. download_install_hb->add_child(mirrors_list);
  858. request_mirrors = memnew(HTTPRequest);
  859. mirrors_list->add_child(request_mirrors);
  860. request_mirrors->connect("request_completed", callable_mp(this, &ExportTemplateManager::_refresh_mirrors_completed));
  861. mirror_options_button = memnew(MenuButton);
  862. mirror_options_button->get_popup()->add_item(TTR("Open in Web Browser"), VISIT_WEB_MIRROR);
  863. mirror_options_button->get_popup()->add_item(TTR("Copy Mirror URL"), COPY_MIRROR_URL);
  864. download_install_hb->add_child(mirror_options_button);
  865. mirror_options_button->get_popup()->connect(SceneStringName(id_pressed), callable_mp(this, &ExportTemplateManager::_mirror_options_button_cbk));
  866. download_install_hb->add_spacer();
  867. download_current_button = memnew(Button);
  868. download_current_button->set_text(TTR("Download and Install"));
  869. download_current_button->set_tooltip_text(TTR("Download and install templates for the current version from the best possible mirror."));
  870. download_install_hb->add_child(download_current_button);
  871. download_current_button->connect(SceneStringName(pressed), callable_mp(this, &ExportTemplateManager::_download_current));
  872. HBoxContainer *install_file_hb = memnew(HBoxContainer);
  873. install_file_hb->set_alignment(BoxContainer::ALIGNMENT_END);
  874. install_options_vb->add_child(install_file_hb);
  875. install_file_button = memnew(Button);
  876. install_file_button->set_text(TTR("Install from File"));
  877. install_file_button->set_tooltip_text(TTR("Install templates from a local file."));
  878. install_file_hb->add_child(install_file_button);
  879. install_file_button->connect(SceneStringName(pressed), callable_mp(this, &ExportTemplateManager::_install_file));
  880. enable_online_hb = memnew(HBoxContainer);
  881. install_options_vb->add_child(enable_online_hb);
  882. Label *enable_online_label = memnew(Label);
  883. enable_online_label->set_text(TTR("Online mode is needed to download the templates."));
  884. enable_online_hb->add_child(enable_online_label);
  885. LinkButton *enable_online_button = memnew(LinkButton);
  886. enable_online_button->set_v_size_flags(Control::SIZE_SHRINK_CENTER);
  887. enable_online_button->set_text(TTR("Go Online"));
  888. enable_online_hb->add_child(enable_online_button);
  889. enable_online_button->connect(SceneStringName(pressed), callable_mp(this, &ExportTemplateManager::_force_online_mode));
  890. // Templates are being downloaded; buttons unavailable.
  891. download_progress_hb = memnew(HBoxContainer);
  892. download_progress_hb->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  893. install_templates_hb->add_child(download_progress_hb);
  894. download_progress_hb->hide();
  895. download_progress_bar = memnew(ProgressBar);
  896. download_progress_bar->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  897. download_progress_bar->set_v_size_flags(Control::SIZE_SHRINK_CENTER);
  898. download_progress_bar->set_min(0);
  899. download_progress_bar->set_max(1);
  900. download_progress_bar->set_value(0);
  901. download_progress_bar->set_step(0.01);
  902. download_progress_bar->set_editor_preview_indeterminate(true);
  903. download_progress_hb->add_child(download_progress_bar);
  904. download_progress_label = memnew(Label);
  905. download_progress_label->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  906. download_progress_hb->add_child(download_progress_label);
  907. Button *download_cancel_button = memnew(Button);
  908. download_cancel_button->set_text(TTR("Cancel"));
  909. download_cancel_button->set_tooltip_text(TTR("Cancel the download of the templates."));
  910. download_progress_hb->add_child(download_cancel_button);
  911. download_cancel_button->connect(SceneStringName(pressed), callable_mp(this, &ExportTemplateManager::_cancel_template_download));
  912. download_templates = memnew(HTTPRequest);
  913. install_templates_hb->add_child(download_templates);
  914. download_templates->connect("request_completed", callable_mp(this, &ExportTemplateManager::_download_template_completed));
  915. main_vb->add_child(memnew(HSeparator));
  916. // Other installed templates table.
  917. HBoxContainer *installed_versions_hb = memnew(HBoxContainer);
  918. main_vb->add_child(installed_versions_hb);
  919. Label *installed_label = memnew(Label);
  920. installed_label->set_theme_type_variation("HeaderSmall");
  921. installed_label->set_text(TTR("Other Installed Versions:"));
  922. installed_versions_hb->add_child(installed_label);
  923. installed_table = memnew(Tree);
  924. installed_table->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
  925. installed_table->set_hide_root(true);
  926. installed_table->set_custom_minimum_size(Size2(0, 100) * EDSCALE);
  927. installed_table->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  928. main_vb->add_child(installed_table);
  929. installed_table->connect("button_clicked", callable_mp(this, &ExportTemplateManager::_installed_table_button_cbk));
  930. // Dialogs.
  931. uninstall_confirm = memnew(ConfirmationDialog);
  932. uninstall_confirm->set_title(TTR("Uninstall Template"));
  933. add_child(uninstall_confirm);
  934. uninstall_confirm->connect(SceneStringName(confirmed), callable_mp(this, &ExportTemplateManager::_uninstall_template_confirmed));
  935. install_file_dialog = memnew(FileDialog);
  936. install_file_dialog->set_title(TTR("Select Template File"));
  937. install_file_dialog->set_access(FileDialog::ACCESS_FILESYSTEM);
  938. install_file_dialog->set_file_mode(FileDialog::FILE_MODE_OPEN_FILE);
  939. install_file_dialog->set_current_dir(EDITOR_DEF("_export_template_download_directory", ""));
  940. install_file_dialog->add_filter("*.tpz", TTR("Godot Export Templates"));
  941. install_file_dialog->connect("file_selected", callable_mp(this, &ExportTemplateManager::_install_file_selected).bind(false));
  942. add_child(install_file_dialog);
  943. hide_dialog_accept = memnew(AcceptDialog);
  944. hide_dialog_accept->set_text(TTR("The templates will continue to download.\nYou may experience a short editor freeze when they finish."));
  945. add_child(hide_dialog_accept);
  946. hide_dialog_accept->connect(SceneStringName(confirmed), callable_mp(this, &ExportTemplateManager::_hide_dialog));
  947. }