export_plugin.cpp 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018
  1. /**************************************************************************/
  2. /* export_plugin.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_plugin.h"
  31. #include "core/config/project_settings.h"
  32. #include "core/io/image_loader.h"
  33. #include "editor/editor_node.h"
  34. #include "editor/editor_paths.h"
  35. #include "editor/editor_scale.h"
  36. #include "platform/windows/logo_svg.gen.h"
  37. #include "platform/windows/run_icon_svg.gen.h"
  38. #include "modules/modules_enabled.gen.h" // For svg.
  39. #ifdef MODULE_SVG_ENABLED
  40. #include "modules/svg/image_loader_svg.h"
  41. #endif
  42. Error EditorExportPlatformWindows::_process_icon(const Ref<EditorExportPreset> &p_preset, const String &p_src_path, const String &p_dst_path) {
  43. static const uint8_t icon_size[] = { 16, 32, 48, 64, 128, 0 /*256*/ };
  44. struct IconData {
  45. Vector<uint8_t> data;
  46. uint8_t pal_colors = 0;
  47. uint16_t planes = 0;
  48. uint16_t bpp = 32;
  49. };
  50. HashMap<uint8_t, IconData> images;
  51. Error err;
  52. if (p_src_path.get_extension() == "ico") {
  53. Ref<FileAccess> f = FileAccess::open(p_src_path, FileAccess::READ, &err);
  54. if (err != OK) {
  55. return err;
  56. }
  57. // Read ICONDIR.
  58. f->get_16(); // Reserved.
  59. uint16_t icon_type = f->get_16(); // Image type: 1 - ICO.
  60. uint16_t icon_count = f->get_16(); // Number of images.
  61. ERR_FAIL_COND_V(icon_type != 1, ERR_CANT_OPEN);
  62. for (uint16_t i = 0; i < icon_count; i++) {
  63. // Read ICONDIRENTRY.
  64. uint16_t w = f->get_8(); // Width in pixels.
  65. uint16_t h = f->get_8(); // Height in pixels.
  66. uint8_t pal_colors = f->get_8(); // Number of colors in the palette (0 - no palette).
  67. f->get_8(); // Reserved.
  68. uint16_t planes = f->get_16(); // Number of color planes.
  69. uint16_t bpp = f->get_16(); // Bits per pixel.
  70. uint32_t img_size = f->get_32(); // Image data size in bytes.
  71. uint32_t img_offset = f->get_32(); // Image data offset.
  72. if (w != h) {
  73. continue;
  74. }
  75. // Read image data.
  76. uint64_t prev_offset = f->get_position();
  77. images[w].pal_colors = pal_colors;
  78. images[w].planes = planes;
  79. images[w].bpp = bpp;
  80. images[w].data.resize(img_size);
  81. f->seek(img_offset);
  82. f->get_buffer(images[w].data.ptrw(), img_size);
  83. f->seek(prev_offset);
  84. }
  85. } else {
  86. Ref<Image> src_image;
  87. src_image.instantiate();
  88. err = ImageLoader::load_image(p_src_path, src_image);
  89. ERR_FAIL_COND_V(err != OK || src_image->is_empty(), ERR_CANT_OPEN);
  90. for (size_t i = 0; i < sizeof(icon_size) / sizeof(icon_size[0]); ++i) {
  91. int size = (icon_size[i] == 0) ? 256 : icon_size[i];
  92. Ref<Image> res_image = src_image->duplicate();
  93. ERR_FAIL_COND_V(res_image.is_null() || res_image->is_empty(), ERR_CANT_OPEN);
  94. res_image->resize(size, size, (Image::Interpolation)(p_preset->get("application/icon_interpolation").operator int()));
  95. images[icon_size[i]].data = res_image->save_png_to_buffer();
  96. }
  97. }
  98. uint16_t valid_icon_count = 0;
  99. for (size_t i = 0; i < sizeof(icon_size) / sizeof(icon_size[0]); ++i) {
  100. if (images.has(icon_size[i])) {
  101. valid_icon_count++;
  102. } else {
  103. int size = (icon_size[i] == 0) ? 256 : icon_size[i];
  104. add_message(EXPORT_MESSAGE_WARNING, TTR("Resources Modification"), vformat(TTR("Icon size \"%d\" is missing."), size));
  105. }
  106. }
  107. ERR_FAIL_COND_V(valid_icon_count == 0, ERR_CANT_OPEN);
  108. Ref<FileAccess> fw = FileAccess::open(p_dst_path, FileAccess::WRITE, &err);
  109. if (err != OK) {
  110. return err;
  111. }
  112. // Write ICONDIR.
  113. fw->store_16(0); // Reserved.
  114. fw->store_16(1); // Image type: 1 - ICO.
  115. fw->store_16(valid_icon_count); // Number of images.
  116. // Write ICONDIRENTRY.
  117. uint32_t img_offset = 6 + 16 * valid_icon_count;
  118. for (size_t i = 0; i < sizeof(icon_size) / sizeof(icon_size[0]); ++i) {
  119. if (images.has(icon_size[i])) {
  120. const IconData &di = images[icon_size[i]];
  121. fw->store_8(icon_size[i]); // Width in pixels.
  122. fw->store_8(icon_size[i]); // Height in pixels.
  123. fw->store_8(di.pal_colors); // Number of colors in the palette (0 - no palette).
  124. fw->store_8(0); // Reserved.
  125. fw->store_16(di.planes); // Number of color planes.
  126. fw->store_16(di.bpp); // Bits per pixel.
  127. fw->store_32(di.data.size()); // Image data size in bytes.
  128. fw->store_32(img_offset); // Image data offset.
  129. img_offset += di.data.size();
  130. }
  131. }
  132. // Write image data.
  133. for (size_t i = 0; i < sizeof(icon_size) / sizeof(icon_size[0]); ++i) {
  134. if (images.has(icon_size[i])) {
  135. const IconData &di = images[icon_size[i]];
  136. fw->store_buffer(di.data.ptr(), di.data.size());
  137. }
  138. }
  139. return OK;
  140. }
  141. Error EditorExportPlatformWindows::sign_shared_object(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path) {
  142. if (p_preset->get("codesign/enable")) {
  143. return _code_sign(p_preset, p_path);
  144. } else {
  145. return OK;
  146. }
  147. }
  148. Error EditorExportPlatformWindows::modify_template(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags) {
  149. if (p_preset->get("application/modify_resources")) {
  150. _rcedit_add_data(p_preset, p_path, true);
  151. String wrapper_path = p_path.get_basename() + ".console.exe";
  152. if (FileAccess::exists(wrapper_path)) {
  153. _rcedit_add_data(p_preset, wrapper_path, false);
  154. }
  155. }
  156. return OK;
  157. }
  158. Error EditorExportPlatformWindows::export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags) {
  159. bool export_as_zip = p_path.ends_with("zip");
  160. bool embedded = p_preset->get("binary_format/embed_pck");
  161. String pkg_name;
  162. if (String(ProjectSettings::get_singleton()->get("application/config/name")) != "") {
  163. pkg_name = String(ProjectSettings::get_singleton()->get("application/config/name"));
  164. } else {
  165. pkg_name = "Unnamed";
  166. }
  167. pkg_name = OS::get_singleton()->get_safe_dir_name(pkg_name);
  168. // Setup temp folder.
  169. String path = p_path;
  170. String tmp_dir_path = EditorPaths::get_singleton()->get_cache_dir().path_join(pkg_name);
  171. Ref<DirAccess> tmp_app_dir = DirAccess::create_for_path(tmp_dir_path);
  172. if (export_as_zip) {
  173. if (tmp_app_dir.is_null()) {
  174. return ERR_CANT_CREATE;
  175. }
  176. if (DirAccess::exists(tmp_dir_path)) {
  177. if (tmp_app_dir->change_dir(tmp_dir_path) == OK) {
  178. tmp_app_dir->erase_contents_recursive();
  179. }
  180. }
  181. tmp_app_dir->make_dir_recursive(tmp_dir_path);
  182. path = tmp_dir_path.path_join(p_path.get_file().get_basename() + ".exe");
  183. }
  184. // Export project.
  185. String pck_path = path;
  186. if (embedded) {
  187. pck_path = pck_path.get_basename() + ".tmp";
  188. }
  189. Error err = EditorExportPlatformPC::export_project(p_preset, p_debug, pck_path, p_flags);
  190. if (p_preset->get("codesign/enable") && err == OK) {
  191. _code_sign(p_preset, pck_path);
  192. String wrapper_path = p_path.get_basename() + ".console.exe";
  193. if (FileAccess::exists(wrapper_path)) {
  194. _code_sign(p_preset, wrapper_path);
  195. }
  196. }
  197. if (embedded && err == OK) {
  198. Ref<DirAccess> tmp_dir = DirAccess::create_for_path(p_path.get_base_dir());
  199. err = tmp_dir->rename(pck_path, p_path);
  200. if (err != OK) {
  201. add_message(EXPORT_MESSAGE_ERROR, TTR("PCK Embedding"), vformat(TTR("Failed to rename temporary file \"%s\"."), pck_path));
  202. }
  203. }
  204. // ZIP project.
  205. if (export_as_zip) {
  206. if (FileAccess::exists(p_path)) {
  207. OS::get_singleton()->move_to_trash(p_path);
  208. }
  209. Ref<FileAccess> io_fa_dst;
  210. zlib_filefunc_def io_dst = zipio_create_io(&io_fa_dst);
  211. zipFile zip = zipOpen2(p_path.utf8().get_data(), APPEND_STATUS_CREATE, nullptr, &io_dst);
  212. zip_folder_recursive(zip, tmp_dir_path, "", pkg_name);
  213. zipClose(zip, nullptr);
  214. if (tmp_app_dir->change_dir(tmp_dir_path) == OK) {
  215. tmp_app_dir->erase_contents_recursive();
  216. tmp_app_dir->change_dir("..");
  217. tmp_app_dir->remove(pkg_name);
  218. }
  219. }
  220. return err;
  221. }
  222. String EditorExportPlatformWindows::get_template_file_name(const String &p_target, const String &p_arch) const {
  223. return "windows_" + p_target + "_" + p_arch + ".exe";
  224. }
  225. List<String> EditorExportPlatformWindows::get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const {
  226. List<String> list;
  227. list.push_back("exe");
  228. list.push_back("zip");
  229. return list;
  230. }
  231. String EditorExportPlatformWindows::get_export_option_warning(const EditorExportPreset *p_preset, const StringName &p_name) const {
  232. if (p_preset) {
  233. if (p_name == "application/icon") {
  234. String icon_path = ProjectSettings::get_singleton()->globalize_path(p_preset->get("application/icon"));
  235. if (!icon_path.is_empty() && !FileAccess::exists(icon_path)) {
  236. return TTR("Invalid icon path.");
  237. }
  238. } else if (p_name == "application/file_version") {
  239. String file_version = p_preset->get("application/file_version");
  240. if (!file_version.is_empty()) {
  241. PackedStringArray version_array = file_version.split(".", false);
  242. if (version_array.size() != 4 || !version_array[0].is_valid_int() ||
  243. !version_array[1].is_valid_int() || !version_array[2].is_valid_int() ||
  244. !version_array[3].is_valid_int() || file_version.find("-") > -1) {
  245. return TTR("Invalid file version.");
  246. }
  247. }
  248. } else if (p_name == "application/product_version") {
  249. String product_version = p_preset->get("application/product_version");
  250. if (!product_version.is_empty()) {
  251. PackedStringArray version_array = product_version.split(".", false);
  252. if (version_array.size() != 4 || !version_array[0].is_valid_int() ||
  253. !version_array[1].is_valid_int() || !version_array[2].is_valid_int() ||
  254. !version_array[3].is_valid_int() || product_version.find("-") > -1) {
  255. return TTR("Invalid product version.");
  256. }
  257. }
  258. }
  259. }
  260. return EditorExportPlatformPC::get_export_option_warning(p_preset, p_name);
  261. }
  262. bool EditorExportPlatformWindows::get_export_option_visibility(const EditorExportPreset *p_preset, const String &p_option) const {
  263. // This option is not supported by "osslsigncode", used on non-Windows host.
  264. if (!OS::get_singleton()->has_feature("windows") && p_option == "codesign/identity_type") {
  265. return false;
  266. }
  267. // Hide codesign.
  268. bool codesign = p_preset->get("codesign/enable");
  269. if (!codesign && p_option != "codesign/enable" && p_option.begins_with("codesign/")) {
  270. return false;
  271. }
  272. // Hide resources.
  273. bool mod_res = p_preset->get("application/modify_resources");
  274. if (!mod_res && p_option != "application/modify_resources" && p_option.begins_with("application/")) {
  275. return false;
  276. }
  277. // Hide SSH options.
  278. bool ssh = p_preset->get("ssh_remote_deploy/enabled");
  279. if (!ssh && p_option != "ssh_remote_deploy/enabled" && p_option.begins_with("ssh_remote_deploy/")) {
  280. return false;
  281. }
  282. return true;
  283. }
  284. void EditorExportPlatformWindows::get_export_options(List<ExportOption> *r_options) const {
  285. EditorExportPlatformPC::get_export_options(r_options);
  286. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "binary_format/architecture", PROPERTY_HINT_ENUM, "x86_64,x86_32,arm64"), "x86_64"));
  287. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/enable"), false, true));
  288. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/identity_type", PROPERTY_HINT_ENUM, "Select automatically,Use PKCS12 file (specify *.PFX/*.P12 file),Use certificate store (specify SHA-1 hash)"), 0));
  289. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/identity", PROPERTY_HINT_GLOBAL_FILE, "*.pfx,*.p12"), ""));
  290. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/password", PROPERTY_HINT_PASSWORD), ""));
  291. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/timestamp"), true));
  292. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/timestamp_server_url"), ""));
  293. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/digest_algorithm", PROPERTY_HINT_ENUM, "SHA1,SHA256"), 1));
  294. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/description"), ""));
  295. r_options->push_back(ExportOption(PropertyInfo(Variant::PACKED_STRING_ARRAY, "codesign/custom_options"), PackedStringArray()));
  296. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "application/modify_resources"), true, true));
  297. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/icon", PROPERTY_HINT_FILE, "*.ico,*.png,*.webp,*.svg"), "", false, true));
  298. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/console_wrapper_icon", PROPERTY_HINT_FILE, "*.ico,*.png,*.webp,*.svg"), ""));
  299. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "application/icon_interpolation", PROPERTY_HINT_ENUM, "Nearest neighbor,Bilinear,Cubic,Trilinear,Lanczos"), 4));
  300. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/file_version", PROPERTY_HINT_PLACEHOLDER_TEXT, "1.0.0.0"), "", false, true));
  301. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/product_version", PROPERTY_HINT_PLACEHOLDER_TEXT, "1.0.0.0"), "", false, true));
  302. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/company_name", PROPERTY_HINT_PLACEHOLDER_TEXT, "Company Name"), ""));
  303. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/product_name", PROPERTY_HINT_PLACEHOLDER_TEXT, "Game Name"), ""));
  304. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/file_description"), ""));
  305. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/copyright"), ""));
  306. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/trademarks"), ""));
  307. String run_script = "Expand-Archive -LiteralPath '{temp_dir}\\{archive_name}' -DestinationPath '{temp_dir}'\n"
  308. "$action = New-ScheduledTaskAction -Execute '{temp_dir}\\{exe_name}' -Argument '{cmd_args}'\n"
  309. "$trigger = New-ScheduledTaskTrigger -Once -At 00:00\n"
  310. "$settings = New-ScheduledTaskSettingsSet\n"
  311. "$task = New-ScheduledTask -Action $action -Trigger $trigger -Settings $settings\n"
  312. "Register-ScheduledTask godot_remote_debug -InputObject $task -Force:$true\n"
  313. "Start-ScheduledTask -TaskName godot_remote_debug\n"
  314. "while (Get-ScheduledTask -TaskName godot_remote_debug | ? State -eq running) { Start-Sleep -Milliseconds 100 }\n"
  315. "Unregister-ScheduledTask -TaskName godot_remote_debug -Confirm:$false -ErrorAction:SilentlyContinue";
  316. String cleanup_script = "Stop-ScheduledTask -TaskName godot_remote_debug -ErrorAction:SilentlyContinue\n"
  317. "Unregister-ScheduledTask -TaskName godot_remote_debug -Confirm:$false -ErrorAction:SilentlyContinue\n"
  318. "Remove-Item -Recurse -Force '{temp_dir}'";
  319. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "ssh_remote_deploy/enabled"), false, true));
  320. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "ssh_remote_deploy/host"), "user@host_ip"));
  321. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "ssh_remote_deploy/port"), "22"));
  322. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "ssh_remote_deploy/extra_args_ssh", PROPERTY_HINT_MULTILINE_TEXT), ""));
  323. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "ssh_remote_deploy/extra_args_scp", PROPERTY_HINT_MULTILINE_TEXT), ""));
  324. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "ssh_remote_deploy/run_script", PROPERTY_HINT_MULTILINE_TEXT), run_script));
  325. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "ssh_remote_deploy/cleanup_script", PROPERTY_HINT_MULTILINE_TEXT), cleanup_script));
  326. }
  327. Error EditorExportPlatformWindows::_rcedit_add_data(const Ref<EditorExportPreset> &p_preset, const String &p_path, bool p_console_icon) {
  328. String rcedit_path = EDITOR_GET("export/windows/rcedit");
  329. if (rcedit_path != String() && !FileAccess::exists(rcedit_path)) {
  330. add_message(EXPORT_MESSAGE_WARNING, TTR("Resources Modification"), vformat(TTR("Could not find rcedit executable at \"%s\"."), rcedit_path));
  331. return ERR_FILE_NOT_FOUND;
  332. }
  333. if (rcedit_path == String()) {
  334. rcedit_path = "rcedit"; // try to run rcedit from PATH
  335. }
  336. #ifndef WINDOWS_ENABLED
  337. // On non-Windows we need WINE to run rcedit
  338. String wine_path = EDITOR_GET("export/windows/wine");
  339. if (!wine_path.is_empty() && !FileAccess::exists(wine_path)) {
  340. add_message(EXPORT_MESSAGE_WARNING, TTR("Resources Modification"), vformat(TTR("Could not find wine executable at \"%s\"."), wine_path));
  341. return ERR_FILE_NOT_FOUND;
  342. }
  343. if (wine_path.is_empty()) {
  344. wine_path = "wine"; // try to run wine from PATH
  345. }
  346. #endif
  347. String icon_path = ProjectSettings::get_singleton()->globalize_path(p_preset->get("application/icon"));
  348. if (p_console_icon) {
  349. String console_icon_path = ProjectSettings::get_singleton()->globalize_path(p_preset->get("application/console_wrapper_icon"));
  350. if (!console_icon_path.is_empty() && FileAccess::exists(console_icon_path)) {
  351. icon_path = console_icon_path;
  352. }
  353. }
  354. String tmp_icon_path = EditorPaths::get_singleton()->get_cache_dir().path_join("_rcedit.ico");
  355. if (!icon_path.is_empty()) {
  356. if (_process_icon(p_preset, icon_path, tmp_icon_path) != OK) {
  357. add_message(EXPORT_MESSAGE_WARNING, TTR("Resources Modification"), vformat(TTR("Invalid icon file \"%s\"."), icon_path));
  358. icon_path = String();
  359. }
  360. }
  361. String file_verion = p_preset->get("application/file_version");
  362. String product_version = p_preset->get("application/product_version");
  363. String company_name = p_preset->get("application/company_name");
  364. String product_name = p_preset->get("application/product_name");
  365. String file_description = p_preset->get("application/file_description");
  366. String copyright = p_preset->get("application/copyright");
  367. String trademarks = p_preset->get("application/trademarks");
  368. String comments = p_preset->get("application/comments");
  369. List<String> args;
  370. args.push_back(p_path);
  371. if (!icon_path.is_empty()) {
  372. args.push_back("--set-icon");
  373. args.push_back(tmp_icon_path);
  374. }
  375. if (!file_verion.is_empty()) {
  376. args.push_back("--set-file-version");
  377. args.push_back(file_verion);
  378. }
  379. if (!product_version.is_empty()) {
  380. args.push_back("--set-product-version");
  381. args.push_back(product_version);
  382. }
  383. if (!company_name.is_empty()) {
  384. args.push_back("--set-version-string");
  385. args.push_back("CompanyName");
  386. args.push_back(company_name);
  387. }
  388. if (!product_name.is_empty()) {
  389. args.push_back("--set-version-string");
  390. args.push_back("ProductName");
  391. args.push_back(product_name);
  392. }
  393. if (!file_description.is_empty()) {
  394. args.push_back("--set-version-string");
  395. args.push_back("FileDescription");
  396. args.push_back(file_description);
  397. }
  398. if (!copyright.is_empty()) {
  399. args.push_back("--set-version-string");
  400. args.push_back("LegalCopyright");
  401. args.push_back(copyright);
  402. }
  403. if (!trademarks.is_empty()) {
  404. args.push_back("--set-version-string");
  405. args.push_back("LegalTrademarks");
  406. args.push_back(trademarks);
  407. }
  408. #ifndef WINDOWS_ENABLED
  409. // On non-Windows we need WINE to run rcedit
  410. args.push_front(rcedit_path);
  411. rcedit_path = wine_path;
  412. #endif
  413. String str;
  414. Error err = OS::get_singleton()->execute(rcedit_path, args, &str, nullptr, true);
  415. if (FileAccess::exists(tmp_icon_path)) {
  416. DirAccess::remove_file_or_error(tmp_icon_path);
  417. }
  418. if (err != OK || (str.find("not found") != -1) || (str.find("not recognized") != -1)) {
  419. add_message(EXPORT_MESSAGE_WARNING, TTR("Resources Modification"), TTR("Could not start rcedit executable. Configure rcedit path in the Editor Settings (Export > Windows > rcedit), or disable \"Application > Modify Resources\" in the export preset."));
  420. return err;
  421. }
  422. print_line("rcedit (" + p_path + "): " + str);
  423. if (str.find("Fatal error") != -1) {
  424. add_message(EXPORT_MESSAGE_WARNING, TTR("Resources Modification"), vformat(TTR("rcedit failed to modify executable: %s."), str));
  425. return FAILED;
  426. }
  427. return OK;
  428. }
  429. Error EditorExportPlatformWindows::_code_sign(const Ref<EditorExportPreset> &p_preset, const String &p_path) {
  430. List<String> args;
  431. #ifdef WINDOWS_ENABLED
  432. String signtool_path = EDITOR_GET("export/windows/signtool");
  433. if (!signtool_path.is_empty() && !FileAccess::exists(signtool_path)) {
  434. add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), vformat(TTR("Could not find signtool executable at \"%s\"."), signtool_path));
  435. return ERR_FILE_NOT_FOUND;
  436. }
  437. if (signtool_path.is_empty()) {
  438. signtool_path = "signtool"; // try to run signtool from PATH
  439. }
  440. #else
  441. String signtool_path = EDITOR_GET("export/windows/osslsigncode");
  442. if (!signtool_path.is_empty() && !FileAccess::exists(signtool_path)) {
  443. add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), vformat(TTR("Could not find osslsigncode executable at \"%s\"."), signtool_path));
  444. return ERR_FILE_NOT_FOUND;
  445. }
  446. if (signtool_path.is_empty()) {
  447. signtool_path = "osslsigncode"; // try to run signtool from PATH
  448. }
  449. #endif
  450. args.push_back("sign");
  451. //identity
  452. #ifdef WINDOWS_ENABLED
  453. int id_type = p_preset->get("codesign/identity_type");
  454. if (id_type == 0) { //auto select
  455. args.push_back("/a");
  456. } else if (id_type == 1) { //pkcs12
  457. if (p_preset->get("codesign/identity") != "") {
  458. args.push_back("/f");
  459. args.push_back(p_preset->get("codesign/identity"));
  460. } else {
  461. add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), TTR("No identity found."));
  462. return FAILED;
  463. }
  464. } else if (id_type == 2) { //Windows certificate store
  465. if (p_preset->get("codesign/identity") != "") {
  466. args.push_back("/sha1");
  467. args.push_back(p_preset->get("codesign/identity"));
  468. } else {
  469. add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), TTR("No identity found."));
  470. return FAILED;
  471. }
  472. } else {
  473. add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), TTR("Invalid identity type."));
  474. return FAILED;
  475. }
  476. #else
  477. int id_type = 1;
  478. if (p_preset->get("codesign/identity") != "") {
  479. args.push_back("-pkcs12");
  480. args.push_back(p_preset->get("codesign/identity"));
  481. } else {
  482. add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), TTR("No identity found."));
  483. return FAILED;
  484. }
  485. #endif
  486. //password
  487. if ((id_type == 1) && (p_preset->get("codesign/password") != "")) {
  488. #ifdef WINDOWS_ENABLED
  489. args.push_back("/p");
  490. #else
  491. args.push_back("-pass");
  492. #endif
  493. args.push_back(p_preset->get("codesign/password"));
  494. }
  495. //timestamp
  496. if (p_preset->get("codesign/timestamp")) {
  497. if (p_preset->get("codesign/timestamp_server") != "") {
  498. #ifdef WINDOWS_ENABLED
  499. args.push_back("/tr");
  500. args.push_back(p_preset->get("codesign/timestamp_server_url"));
  501. args.push_back("/td");
  502. if ((int)p_preset->get("codesign/digest_algorithm") == 0) {
  503. args.push_back("sha1");
  504. } else {
  505. args.push_back("sha256");
  506. }
  507. #else
  508. args.push_back("-ts");
  509. args.push_back(p_preset->get("codesign/timestamp_server_url"));
  510. #endif
  511. } else {
  512. add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), TTR("Invalid timestamp server."));
  513. return FAILED;
  514. }
  515. }
  516. //digest
  517. #ifdef WINDOWS_ENABLED
  518. args.push_back("/fd");
  519. #else
  520. args.push_back("-h");
  521. #endif
  522. if ((int)p_preset->get("codesign/digest_algorithm") == 0) {
  523. args.push_back("sha1");
  524. } else {
  525. args.push_back("sha256");
  526. }
  527. //description
  528. if (p_preset->get("codesign/description") != "") {
  529. #ifdef WINDOWS_ENABLED
  530. args.push_back("/d");
  531. #else
  532. args.push_back("-n");
  533. #endif
  534. args.push_back(p_preset->get("codesign/description"));
  535. }
  536. //user options
  537. PackedStringArray user_args = p_preset->get("codesign/custom_options");
  538. for (int i = 0; i < user_args.size(); i++) {
  539. String user_arg = user_args[i].strip_edges();
  540. if (!user_arg.is_empty()) {
  541. args.push_back(user_arg);
  542. }
  543. }
  544. #ifndef WINDOWS_ENABLED
  545. args.push_back("-in");
  546. #endif
  547. args.push_back(p_path);
  548. #ifndef WINDOWS_ENABLED
  549. args.push_back("-out");
  550. args.push_back(p_path + "_signed");
  551. #endif
  552. String str;
  553. Error err = OS::get_singleton()->execute(signtool_path, args, &str, nullptr, true);
  554. if (err != OK || (str.find("not found") != -1) || (str.find("not recognized") != -1)) {
  555. #ifdef WINDOWS_ENABLED
  556. add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), TTR("Could not start signtool executable. Configure signtool path in the Editor Settings (Export > Windows > signtool), or disable \"Codesign\" in the export preset."));
  557. #else
  558. add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), TTR("Could not start osslsigncode executable. Configure signtool path in the Editor Settings (Export > Windows > osslsigncode), or disable \"Codesign\" in the export preset."));
  559. #endif
  560. return err;
  561. }
  562. print_line("codesign (" + p_path + "): " + str);
  563. #ifndef WINDOWS_ENABLED
  564. if (str.find("SignTool Error") != -1) {
  565. #else
  566. if (str.find("Failed") != -1) {
  567. #endif
  568. add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), vformat(TTR("Signtool failed to sign executable: %s."), str));
  569. return FAILED;
  570. }
  571. #ifndef WINDOWS_ENABLED
  572. Ref<DirAccess> tmp_dir = DirAccess::create_for_path(p_path.get_base_dir());
  573. err = tmp_dir->remove(p_path);
  574. if (err != OK) {
  575. add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), vformat(TTR("Failed to remove temporary file \"%s\"."), p_path));
  576. return err;
  577. }
  578. err = tmp_dir->rename(p_path + "_signed", p_path);
  579. if (err != OK) {
  580. add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), vformat(TTR("Failed to rename temporary file \"%s\"."), p_path + "_signed"));
  581. return err;
  582. }
  583. #endif
  584. return OK;
  585. }
  586. bool EditorExportPlatformWindows::has_valid_export_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const {
  587. String err = "";
  588. bool valid = EditorExportPlatformPC::has_valid_export_configuration(p_preset, err, r_missing_templates);
  589. String rcedit_path = EDITOR_GET("export/windows/rcedit");
  590. if (p_preset->get("application/modify_resources") && rcedit_path.is_empty()) {
  591. err += TTR("The rcedit tool must be configured in the Editor Settings (Export > Windows > rcedit) to change the icon or app information data.") + "\n";
  592. }
  593. if (!err.is_empty()) {
  594. r_error = err;
  595. }
  596. return valid;
  597. }
  598. bool EditorExportPlatformWindows::has_valid_project_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error) const {
  599. String err = "";
  600. bool valid = true;
  601. List<ExportOption> options;
  602. get_export_options(&options);
  603. for (const EditorExportPlatform::ExportOption &E : options) {
  604. if (get_export_option_visibility(p_preset.ptr(), E.option.name)) {
  605. String warn = get_export_option_warning(p_preset.ptr(), E.option.name);
  606. if (!warn.is_empty()) {
  607. err += warn + "\n";
  608. if (E.required) {
  609. valid = false;
  610. }
  611. }
  612. }
  613. }
  614. if (!err.is_empty()) {
  615. r_error = err;
  616. }
  617. return valid;
  618. }
  619. Error EditorExportPlatformWindows::fixup_embedded_pck(const String &p_path, int64_t p_embedded_start, int64_t p_embedded_size) {
  620. // Patch the header of the "pck" section in the PE file so that it corresponds to the embedded data
  621. if (p_embedded_size + p_embedded_start >= 0x100000000) { // Check for total executable size
  622. add_message(EXPORT_MESSAGE_ERROR, TTR("PCK Embedding"), TTR("Windows executables cannot be >= 4 GiB."));
  623. return ERR_INVALID_DATA;
  624. }
  625. Ref<FileAccess> f = FileAccess::open(p_path, FileAccess::READ_WRITE);
  626. if (f.is_null()) {
  627. add_message(EXPORT_MESSAGE_ERROR, TTR("PCK Embedding"), vformat(TTR("Failed to open executable file \"%s\"."), p_path));
  628. return ERR_CANT_OPEN;
  629. }
  630. // Jump to the PE header and check the magic number
  631. {
  632. f->seek(0x3c);
  633. uint32_t pe_pos = f->get_32();
  634. f->seek(pe_pos);
  635. uint32_t magic = f->get_32();
  636. if (magic != 0x00004550) {
  637. add_message(EXPORT_MESSAGE_ERROR, TTR("PCK Embedding"), TTR("Executable file header corrupted."));
  638. return ERR_FILE_CORRUPT;
  639. }
  640. }
  641. // Process header
  642. int num_sections;
  643. {
  644. int64_t header_pos = f->get_position();
  645. f->seek(header_pos + 2);
  646. num_sections = f->get_16();
  647. f->seek(header_pos + 16);
  648. uint16_t opt_header_size = f->get_16();
  649. // Skip rest of header + optional header to go to the section headers
  650. f->seek(f->get_position() + 2 + opt_header_size);
  651. }
  652. // Search for the "pck" section
  653. int64_t section_table_pos = f->get_position();
  654. bool found = false;
  655. for (int i = 0; i < num_sections; ++i) {
  656. int64_t section_header_pos = section_table_pos + i * 40;
  657. f->seek(section_header_pos);
  658. uint8_t section_name[9];
  659. f->get_buffer(section_name, 8);
  660. section_name[8] = '\0';
  661. if (strcmp((char *)section_name, "pck") == 0) {
  662. // "pck" section found, let's patch!
  663. // Set virtual size to a little to avoid it taking memory (zero would give issues)
  664. f->seek(section_header_pos + 8);
  665. f->store_32(8);
  666. f->seek(section_header_pos + 16);
  667. f->store_32(p_embedded_size);
  668. f->seek(section_header_pos + 20);
  669. f->store_32(p_embedded_start);
  670. found = true;
  671. break;
  672. }
  673. }
  674. if (!found) {
  675. add_message(EXPORT_MESSAGE_ERROR, TTR("PCK Embedding"), TTR("Executable \"pck\" section not found."));
  676. return ERR_FILE_CORRUPT;
  677. }
  678. return OK;
  679. }
  680. Ref<Texture2D> EditorExportPlatformWindows::get_run_icon() const {
  681. return run_icon;
  682. }
  683. bool EditorExportPlatformWindows::poll_export() {
  684. Ref<EditorExportPreset> preset;
  685. for (int i = 0; i < EditorExport::get_singleton()->get_export_preset_count(); i++) {
  686. Ref<EditorExportPreset> ep = EditorExport::get_singleton()->get_export_preset(i);
  687. if (ep->is_runnable() && ep->get_platform() == this) {
  688. preset = ep;
  689. break;
  690. }
  691. }
  692. int prev = menu_options;
  693. menu_options = (preset.is_valid() && preset->get("ssh_remote_deploy/enabled").operator bool());
  694. if (ssh_pid != 0 || !cleanup_commands.is_empty()) {
  695. if (menu_options == 0) {
  696. cleanup();
  697. } else {
  698. menu_options += 1;
  699. }
  700. }
  701. return menu_options != prev;
  702. }
  703. Ref<ImageTexture> EditorExportPlatformWindows::get_option_icon(int p_index) const {
  704. return p_index == 1 ? stop_icon : EditorExportPlatform::get_option_icon(p_index);
  705. }
  706. int EditorExportPlatformWindows::get_options_count() const {
  707. return menu_options;
  708. }
  709. String EditorExportPlatformWindows::get_option_label(int p_index) const {
  710. return (p_index) ? TTR("Stop and uninstall") : TTR("Run on remote Windows system");
  711. }
  712. String EditorExportPlatformWindows::get_option_tooltip(int p_index) const {
  713. return (p_index) ? TTR("Stop and uninstall running project from the remote system") : TTR("Run exported project on remote Windows system");
  714. }
  715. void EditorExportPlatformWindows::cleanup() {
  716. if (ssh_pid != 0 && OS::get_singleton()->is_process_running(ssh_pid)) {
  717. print_line("Terminating connection...");
  718. OS::get_singleton()->kill(ssh_pid);
  719. OS::get_singleton()->delay_usec(1000);
  720. }
  721. if (!cleanup_commands.is_empty()) {
  722. print_line("Stopping and deleting previous version...");
  723. for (const SSHCleanupCommand &cmd : cleanup_commands) {
  724. if (cmd.wait) {
  725. ssh_run_on_remote(cmd.host, cmd.port, cmd.ssh_args, cmd.cmd_args);
  726. } else {
  727. ssh_run_on_remote_no_wait(cmd.host, cmd.port, cmd.ssh_args, cmd.cmd_args);
  728. }
  729. }
  730. }
  731. ssh_pid = 0;
  732. cleanup_commands.clear();
  733. }
  734. Error EditorExportPlatformWindows::run(const Ref<EditorExportPreset> &p_preset, int p_device, int p_debug_flags) {
  735. cleanup();
  736. if (p_device) { // Stop command, cleanup only.
  737. return OK;
  738. }
  739. EditorProgress ep("run", TTR("Running..."), 5);
  740. const String dest = EditorPaths::get_singleton()->get_cache_dir().path_join("windows");
  741. Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  742. if (!da->dir_exists(dest)) {
  743. Error err = da->make_dir_recursive(dest);
  744. if (err != OK) {
  745. EditorNode::get_singleton()->show_warning(TTR("Could not create temp directory:") + "\n" + dest);
  746. return err;
  747. }
  748. }
  749. String host = p_preset->get("ssh_remote_deploy/host").operator String();
  750. String port = p_preset->get("ssh_remote_deploy/port").operator String();
  751. if (port.is_empty()) {
  752. port = "22";
  753. }
  754. Vector<String> extra_args_ssh = p_preset->get("ssh_remote_deploy/extra_args_ssh").operator String().split(" ", false);
  755. Vector<String> extra_args_scp = p_preset->get("ssh_remote_deploy/extra_args_scp").operator String().split(" ", false);
  756. const String basepath = dest.path_join("tmp_windows_export");
  757. #define CLEANUP_AND_RETURN(m_err) \
  758. { \
  759. if (da->file_exists(basepath + ".zip")) { \
  760. da->remove(basepath + ".zip"); \
  761. } \
  762. if (da->file_exists(basepath + "_start.ps1")) { \
  763. da->remove(basepath + "_start.ps1"); \
  764. } \
  765. if (da->file_exists(basepath + "_clean.ps1")) { \
  766. da->remove(basepath + "_clean.ps1"); \
  767. } \
  768. return m_err; \
  769. } \
  770. ((void)0)
  771. if (ep.step(TTR("Exporting project..."), 1)) {
  772. return ERR_SKIP;
  773. }
  774. Error err = export_project(p_preset, true, basepath + ".zip", p_debug_flags);
  775. if (err != OK) {
  776. DirAccess::remove_file_or_error(basepath + ".zip");
  777. return err;
  778. }
  779. String cmd_args;
  780. {
  781. Vector<String> cmd_args_list;
  782. gen_debug_flags(cmd_args_list, p_debug_flags);
  783. for (int i = 0; i < cmd_args_list.size(); i++) {
  784. if (i != 0) {
  785. cmd_args += " ";
  786. }
  787. cmd_args += cmd_args_list[i];
  788. }
  789. }
  790. const bool use_remote = (p_debug_flags & DEBUG_FLAG_REMOTE_DEBUG) || (p_debug_flags & DEBUG_FLAG_DUMB_CLIENT);
  791. int dbg_port = EditorSettings::get_singleton()->get("network/debug/remote_port");
  792. print_line("Creating temporary directory...");
  793. ep.step(TTR("Creating temporary directory..."), 2);
  794. String temp_dir;
  795. #ifndef WINDOWS_ENABLED
  796. err = ssh_run_on_remote(host, port, extra_args_ssh, "powershell -command \\\"\\$tmp = Join-Path \\$Env:Temp \\$(New-Guid); New-Item -Type Directory -Path \\$tmp | Out-Null; Write-Output \\$tmp\\\"", &temp_dir);
  797. #else
  798. err = ssh_run_on_remote(host, port, extra_args_ssh, "powershell -command \"$tmp = Join-Path $Env:Temp $(New-Guid); New-Item -Type Directory -Path $tmp ^| Out-Null; Write-Output $tmp\"", &temp_dir);
  799. #endif
  800. if (err != OK || temp_dir.is_empty()) {
  801. CLEANUP_AND_RETURN(err);
  802. }
  803. print_line("Uploading archive...");
  804. ep.step(TTR("Uploading archive..."), 3);
  805. err = ssh_push_to_remote(host, port, extra_args_scp, basepath + ".zip", temp_dir);
  806. if (err != OK) {
  807. CLEANUP_AND_RETURN(err);
  808. }
  809. if (cmd_args.is_empty()) {
  810. cmd_args = " ";
  811. }
  812. {
  813. String run_script = p_preset->get("ssh_remote_deploy/run_script");
  814. run_script = run_script.replace("{temp_dir}", temp_dir);
  815. run_script = run_script.replace("{archive_name}", basepath.get_file() + ".zip");
  816. run_script = run_script.replace("{exe_name}", basepath.get_file() + ".exe");
  817. run_script = run_script.replace("{cmd_args}", cmd_args);
  818. Ref<FileAccess> f = FileAccess::open(basepath + "_start.ps1", FileAccess::WRITE);
  819. if (f.is_null()) {
  820. CLEANUP_AND_RETURN(err);
  821. }
  822. f->store_string(run_script);
  823. }
  824. {
  825. String clean_script = p_preset->get("ssh_remote_deploy/cleanup_script");
  826. clean_script = clean_script.replace("{temp_dir}", temp_dir);
  827. clean_script = clean_script.replace("{archive_name}", basepath.get_file() + ".zip");
  828. clean_script = clean_script.replace("{exe_name}", basepath.get_file() + ".exe");
  829. clean_script = clean_script.replace("{cmd_args}", cmd_args);
  830. Ref<FileAccess> f = FileAccess::open(basepath + "_clean.ps1", FileAccess::WRITE);
  831. if (f.is_null()) {
  832. CLEANUP_AND_RETURN(err);
  833. }
  834. f->store_string(clean_script);
  835. }
  836. print_line("Uploading scripts...");
  837. ep.step(TTR("Uploading scripts..."), 4);
  838. err = ssh_push_to_remote(host, port, extra_args_scp, basepath + "_start.ps1", temp_dir);
  839. if (err != OK) {
  840. CLEANUP_AND_RETURN(err);
  841. }
  842. err = ssh_push_to_remote(host, port, extra_args_scp, basepath + "_clean.ps1", temp_dir);
  843. if (err != OK) {
  844. CLEANUP_AND_RETURN(err);
  845. }
  846. print_line("Starting project...");
  847. ep.step(TTR("Starting project..."), 5);
  848. err = ssh_run_on_remote_no_wait(host, port, extra_args_ssh, vformat("powershell -file \"%s\\%s\"", temp_dir, basepath.get_file() + "_start.ps1"), &ssh_pid, (use_remote) ? dbg_port : -1);
  849. if (err != OK) {
  850. CLEANUP_AND_RETURN(err);
  851. }
  852. cleanup_commands.clear();
  853. cleanup_commands.push_back(SSHCleanupCommand(host, port, extra_args_ssh, vformat("powershell -file \"%s\\%s\"", temp_dir, basepath.get_file() + "_clean.ps1")));
  854. print_line("Project started.");
  855. CLEANUP_AND_RETURN(OK);
  856. #undef CLEANUP_AND_RETURN
  857. }
  858. EditorExportPlatformWindows::EditorExportPlatformWindows() {
  859. if (EditorNode::get_singleton()) {
  860. #ifdef MODULE_SVG_ENABLED
  861. Ref<Image> img = memnew(Image);
  862. const bool upsample = !Math::is_equal_approx(Math::round(EDSCALE), EDSCALE);
  863. ImageLoaderSVG img_loader;
  864. img_loader.create_image_from_string(img, _windows_logo_svg, EDSCALE, upsample, false);
  865. set_logo(ImageTexture::create_from_image(img));
  866. img_loader.create_image_from_string(img, _windows_run_icon_svg, EDSCALE, upsample, false);
  867. run_icon = ImageTexture::create_from_image(img);
  868. #endif
  869. Ref<Theme> theme = EditorNode::get_singleton()->get_editor_theme();
  870. if (theme.is_valid()) {
  871. stop_icon = theme->get_icon(SNAME("Stop"), SNAME("EditorIcons"));
  872. } else {
  873. stop_icon.instantiate();
  874. }
  875. }
  876. }