export.cpp 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /*************************************************************************/
  2. /* export.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #include "core/os/file_access.h"
  31. #include "core/os/os.h"
  32. #include "editor/editor_export.h"
  33. #include "editor/editor_settings.h"
  34. #include "platform/windows/logo.gen.h"
  35. class EditorExportPlatformWindows : public EditorExportPlatformPC {
  36. public:
  37. virtual Error export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags = 0);
  38. virtual void get_export_options(List<ExportOption> *r_options);
  39. };
  40. Error EditorExportPlatformWindows::export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags) {
  41. Error err = EditorExportPlatformPC::export_project(p_preset, p_debug, p_path, p_flags);
  42. if (err != OK) {
  43. return err;
  44. }
  45. String rcedit_path = EditorSettings::get_singleton()->get("export/windows/rcedit");
  46. if (rcedit_path == String()) {
  47. return OK;
  48. }
  49. if (!FileAccess::exists(rcedit_path)) {
  50. ERR_PRINTS("Could not find rcedit executable at " + rcedit_path + ", aborting.");
  51. return ERR_FILE_NOT_FOUND;
  52. }
  53. #ifndef WINDOWS_ENABLED
  54. // On non-Windows we need WINE to run rcedit
  55. String wine_path = EditorSettings::get_singleton()->get("export/windows/wine");
  56. if (wine_path != String() && !FileAccess::exists(wine_path)) {
  57. ERR_PRINTS("Could not find wine executable at " + wine_path + ", aborting.");
  58. return ERR_FILE_NOT_FOUND;
  59. }
  60. if (wine_path == String()) {
  61. wine_path = "wine"; // try to run wine from PATH
  62. }
  63. #endif
  64. String icon_path = p_preset->get("application/icon");
  65. String file_verion = p_preset->get("application/file_version");
  66. String product_version = p_preset->get("application/product_version");
  67. String company_name = p_preset->get("application/company_name");
  68. String product_name = p_preset->get("application/product_name");
  69. String file_description = p_preset->get("application/file_description");
  70. String copyright = p_preset->get("application/copyright");
  71. String trademarks = p_preset->get("application/trademarks");
  72. String comments = p_preset->get("application/comments");
  73. List<String> args;
  74. args.push_back(p_path);
  75. if (icon_path != String()) {
  76. args.push_back("--set-icon");
  77. args.push_back(icon_path);
  78. }
  79. if (file_verion != String()) {
  80. args.push_back("--set-file-version");
  81. args.push_back(file_verion);
  82. }
  83. if (product_version != String()) {
  84. args.push_back("--set-product-version");
  85. args.push_back(product_version);
  86. }
  87. if (company_name != String()) {
  88. args.push_back("--set-version-string");
  89. args.push_back("CompanyName");
  90. args.push_back(company_name);
  91. }
  92. if (product_name != String()) {
  93. args.push_back("--set-version-string");
  94. args.push_back("ProductName");
  95. args.push_back(product_name);
  96. }
  97. if (file_description != String()) {
  98. args.push_back("--set-version-string");
  99. args.push_back("FileDescription");
  100. args.push_back(file_description);
  101. }
  102. if (copyright != String()) {
  103. args.push_back("--set-version-string");
  104. args.push_back("LegalCopyright");
  105. args.push_back(copyright);
  106. }
  107. if (trademarks != String()) {
  108. args.push_back("--set-version-string");
  109. args.push_back("LegalTrademarks");
  110. args.push_back(trademarks);
  111. }
  112. #ifdef WINDOWS_ENABLED
  113. OS::get_singleton()->execute(rcedit_path, args, true);
  114. #else
  115. // On non-Windows we need WINE to run rcedit
  116. args.push_front(rcedit_path);
  117. OS::get_singleton()->execute(wine_path, args, true);
  118. #endif
  119. return OK;
  120. }
  121. void EditorExportPlatformWindows::get_export_options(List<ExportOption> *r_options) {
  122. EditorExportPlatformPC::get_export_options(r_options);
  123. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/icon", PROPERTY_HINT_GLOBAL_FILE, "*.ico"), ""));
  124. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/file_version"), ""));
  125. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/product_version"), ""));
  126. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/company_name", PROPERTY_HINT_PLACEHOLDER_TEXT, "Company Name"), ""));
  127. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/product_name", PROPERTY_HINT_PLACEHOLDER_TEXT, "Game Name"), ""));
  128. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/file_description"), ""));
  129. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/copyright"), ""));
  130. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/trademarks"), ""));
  131. }
  132. void register_windows_exporter() {
  133. EDITOR_DEF("export/windows/rcedit", "");
  134. EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::STRING, "export/windows/rcedit", PROPERTY_HINT_GLOBAL_FILE, "*.exe"));
  135. #ifndef WINDOWS_ENABLED
  136. // On non-Windows we need WINE to run rcedit
  137. EDITOR_DEF("export/windows/wine", "");
  138. EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::STRING, "export/windows/wine", PROPERTY_HINT_GLOBAL_FILE));
  139. #endif
  140. Ref<EditorExportPlatformWindows> platform;
  141. platform.instance();
  142. Ref<Image> img = memnew(Image(_windows_logo));
  143. Ref<ImageTexture> logo;
  144. logo.instance();
  145. logo->create_from_image(img);
  146. platform->set_logo(logo);
  147. platform->set_name("Windows Desktop");
  148. platform->set_extension("exe");
  149. platform->set_release_32("windows_32_release.exe");
  150. platform->set_debug_32("windows_32_debug.exe");
  151. platform->set_release_64("windows_64_release.exe");
  152. platform->set_debug_64("windows_64_debug.exe");
  153. platform->set_os_name("Windows");
  154. EditorExport::get_singleton()->add_export_platform(platform);
  155. }