export.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. /*************************************************************************/
  2. /* export.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2018 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 "export.h"
  31. #include "editor/editor_export.h"
  32. #include "editor/editor_node.h"
  33. #include "editor/editor_settings.h"
  34. #include "io/marshalls.h"
  35. #include "io/resource_saver.h"
  36. #include "io/zip_io.h"
  37. #include "os/file_access.h"
  38. #include "os/os.h"
  39. #include "platform/osx/logo.gen.h"
  40. #include "project_settings.h"
  41. #include "string.h"
  42. #include "version.h"
  43. #include <sys/stat.h>
  44. class EditorExportPlatformOSX : public EditorExportPlatform {
  45. GDCLASS(EditorExportPlatformOSX, EditorExportPlatform);
  46. int version_code;
  47. Ref<ImageTexture> logo;
  48. void _fix_plist(const Ref<EditorExportPreset> &p_preset, Vector<uint8_t> &plist, const String &p_binary);
  49. void _make_icon(const Ref<Image> &p_icon, Vector<uint8_t> &p_data);
  50. Error _code_sign(const Ref<EditorExportPreset> &p_preset, const String &p_path);
  51. Error _create_dmg(const String &p_dmg_path, const String &p_pkg_name, const String &p_app_path_name);
  52. #ifdef OSX_ENABLED
  53. bool use_codesign() const { return true; }
  54. bool use_dmg() const { return true; }
  55. #else
  56. bool use_codesign() const { return false; }
  57. bool use_dmg() const { return false; }
  58. #endif
  59. protected:
  60. virtual void get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features);
  61. virtual void get_export_options(List<ExportOption> *r_options);
  62. public:
  63. virtual String get_name() const { return "Mac OSX"; }
  64. virtual String get_os_name() const { return "OSX"; }
  65. virtual Ref<Texture> get_logo() const { return logo; }
  66. virtual String get_binary_extension(const Ref<EditorExportPreset> &p_preset) const { return use_dmg() ? "dmg" : "zip"; }
  67. virtual Error export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags = 0);
  68. virtual bool can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const;
  69. virtual void get_platform_features(List<String> *r_features) {
  70. r_features->push_back("pc");
  71. r_features->push_back("s3tc");
  72. r_features->push_back("OSX");
  73. }
  74. EditorExportPlatformOSX();
  75. ~EditorExportPlatformOSX();
  76. };
  77. void EditorExportPlatformOSX::get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features) {
  78. if (p_preset->get("texture_format/s3tc")) {
  79. r_features->push_back("s3tc");
  80. }
  81. if (p_preset->get("texture_format/etc")) {
  82. r_features->push_back("etc");
  83. }
  84. if (p_preset->get("texture_format/etc2")) {
  85. r_features->push_back("etc2");
  86. }
  87. int bits = p_preset->get("application/bits_mode");
  88. if (bits == 0 || bits == 1) {
  89. r_features->push_back("64");
  90. }
  91. if (bits == 0 || bits == 2) {
  92. r_features->push_back("32");
  93. }
  94. }
  95. void EditorExportPlatformOSX::get_export_options(List<ExportOption> *r_options) {
  96. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_package/debug", PROPERTY_HINT_GLOBAL_FILE, "zip"), ""));
  97. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_package/release", PROPERTY_HINT_GLOBAL_FILE, "zip"), ""));
  98. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/name"), ""));
  99. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/info"), "Made with Godot Engine"));
  100. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/icon", PROPERTY_HINT_FILE, "png"), ""));
  101. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/identifier"), "org.godotengine.macgame"));
  102. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/signature"), "godotmacgame"));
  103. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/short_version"), "1.0"));
  104. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/version"), "1.0"));
  105. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/copyright"), ""));
  106. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "application/bits_mode", PROPERTY_HINT_ENUM, "Fat (32 & 64 bits),64 bits,32 bits"), 0));
  107. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "display/high_res"), false));
  108. #ifdef OSX_ENABLED
  109. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/identity"), ""));
  110. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/entitlements"), ""));
  111. #endif
  112. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "texture_format/s3tc"), true));
  113. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "texture_format/etc"), false));
  114. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "texture_format/etc2"), false));
  115. }
  116. void EditorExportPlatformOSX::_make_icon(const Ref<Image> &p_icon, Vector<uint8_t> &p_data) {
  117. Ref<ImageTexture> it = memnew(ImageTexture);
  118. int size = 512;
  119. Vector<uint8_t> data;
  120. data.resize(8);
  121. data[0] = 'i';
  122. data[1] = 'c';
  123. data[2] = 'n';
  124. data[3] = 's';
  125. const char *name[] = { "ic09", "ic08", "ic07", "icp6", "icp5", "icp4" };
  126. int index = 0;
  127. while (size >= 16) {
  128. Ref<Image> copy = p_icon; // does this make sense? doesn't this just increase the reference count instead of making a copy? Do we even need a copy?
  129. copy->convert(Image::FORMAT_RGBA8);
  130. copy->resize(size, size);
  131. it->create_from_image(copy);
  132. String path = EditorSettings::get_singleton()->get_cache_dir().plus_file("icon.png");
  133. ResourceSaver::save(path, it);
  134. FileAccess *f = FileAccess::open(path, FileAccess::READ);
  135. ERR_FAIL_COND(!f);
  136. int ofs = data.size();
  137. uint32_t len = f->get_len();
  138. data.resize(data.size() + len + 8);
  139. f->get_buffer(&data[ofs + 8], len);
  140. memdelete(f);
  141. len += 8;
  142. len = BSWAP32(len);
  143. copymem(&data[ofs], name[index], 4);
  144. encode_uint32(len, &data[ofs + 4]);
  145. index++;
  146. size /= 2;
  147. }
  148. uint32_t total_len = data.size();
  149. total_len = BSWAP32(total_len);
  150. encode_uint32(total_len, &data[4]);
  151. p_data = data;
  152. }
  153. void EditorExportPlatformOSX::_fix_plist(const Ref<EditorExportPreset> &p_preset, Vector<uint8_t> &plist, const String &p_binary) {
  154. String str;
  155. String strnew;
  156. str.parse_utf8((const char *)plist.ptr(), plist.size());
  157. Vector<String> lines = str.split("\n");
  158. for (int i = 0; i < lines.size(); i++) {
  159. if (lines[i].find("$binary") != -1) {
  160. strnew += lines[i].replace("$binary", p_binary) + "\n";
  161. } else if (lines[i].find("$name") != -1) {
  162. strnew += lines[i].replace("$name", p_binary) + "\n";
  163. } else if (lines[i].find("$info") != -1) {
  164. strnew += lines[i].replace("$info", p_preset->get("application/info")) + "\n";
  165. } else if (lines[i].find("$identifier") != -1) {
  166. strnew += lines[i].replace("$identifier", p_preset->get("application/identifier")) + "\n";
  167. } else if (lines[i].find("$short_version") != -1) {
  168. strnew += lines[i].replace("$short_version", p_preset->get("application/short_version")) + "\n";
  169. } else if (lines[i].find("$version") != -1) {
  170. strnew += lines[i].replace("$version", p_preset->get("application/version")) + "\n";
  171. } else if (lines[i].find("$signature") != -1) {
  172. strnew += lines[i].replace("$signature", p_preset->get("application/signature")) + "\n";
  173. } else if (lines[i].find("$copyright") != -1) {
  174. strnew += lines[i].replace("$copyright", p_preset->get("application/copyright")) + "\n";
  175. } else if (lines[i].find("$highres") != -1) {
  176. strnew += lines[i].replace("$highres", p_preset->get("display/high_res") ? "<true/>" : "<false/>") + "\n";
  177. } else {
  178. strnew += lines[i] + "\n";
  179. }
  180. }
  181. CharString cs = strnew.utf8();
  182. plist.resize(cs.size() - 1);
  183. for (int i = 0; i < cs.size() - 1; i++) {
  184. plist[i] = cs[i];
  185. }
  186. }
  187. /**
  188. If we're running the OSX version of the Godot editor we'll:
  189. - export our application bundle to a temporary folder
  190. - attempt to code sign it
  191. - and then wrap it up in a DMG
  192. **/
  193. Error EditorExportPlatformOSX::_code_sign(const Ref<EditorExportPreset> &p_preset, const String &p_path) {
  194. List<String> args;
  195. if (p_preset->get("codesign/entitlements") != "") {
  196. /* this should point to our entitlements.plist file that sandboxes our application, I don't know if this should also be placed in our app bundle */
  197. args.push_back("-entitlements");
  198. args.push_back(p_preset->get("codesign/entitlements"));
  199. }
  200. args.push_back("-s");
  201. args.push_back(p_preset->get("codesign/identity"));
  202. args.push_back("-v"); /* provide some more feedback */
  203. args.push_back(p_path);
  204. String str;
  205. Error err = OS::get_singleton()->execute("codesign", args, true, NULL, &str, NULL, true);
  206. ERR_FAIL_COND_V(err != OK, err);
  207. print_line("codesign: " + str);
  208. if (str.find("no identity found") != -1) {
  209. EditorNode::add_io_error("codesign: no identity found");
  210. return FAILED;
  211. }
  212. return OK;
  213. }
  214. Error EditorExportPlatformOSX::_create_dmg(const String &p_dmg_path, const String &p_pkg_name, const String &p_app_path_name) {
  215. List<String> args;
  216. OS::get_singleton()->move_to_trash(p_dmg_path);
  217. args.push_back("create");
  218. args.push_back(p_dmg_path);
  219. args.push_back("-volname");
  220. args.push_back(p_pkg_name);
  221. args.push_back("-fs");
  222. args.push_back("HFS+");
  223. args.push_back("-srcfolder");
  224. args.push_back(p_app_path_name);
  225. String str;
  226. Error err = OS::get_singleton()->execute("hdiutil", args, true, NULL, &str, NULL, true);
  227. ERR_FAIL_COND_V(err != OK, err);
  228. print_line("hdiutil returned: " + str);
  229. if (str.find("create failed") != -1) {
  230. if (str.find("File exists") != -1) {
  231. EditorNode::add_io_error("hdiutil: create failed - file exists");
  232. } else {
  233. EditorNode::add_io_error("hdiutil: create failed");
  234. }
  235. return FAILED;
  236. }
  237. return OK;
  238. }
  239. Error EditorExportPlatformOSX::export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags) {
  240. ExportNotifier notifier(*this, p_preset, p_debug, p_path, p_flags);
  241. String src_pkg_name;
  242. EditorProgress ep("export", "Exporting for OSX", 3);
  243. if (p_debug)
  244. src_pkg_name = p_preset->get("custom_package/debug");
  245. else
  246. src_pkg_name = p_preset->get("custom_package/release");
  247. if (src_pkg_name == "") {
  248. String err;
  249. src_pkg_name = find_export_template("osx.zip", &err);
  250. if (src_pkg_name == "") {
  251. EditorNode::add_io_error(err);
  252. return ERR_FILE_NOT_FOUND;
  253. }
  254. }
  255. FileAccess *src_f = NULL;
  256. zlib_filefunc_def io = zipio_create_io_from_file(&src_f);
  257. ep.step("Creating app", 0);
  258. unzFile src_pkg_zip = unzOpen2(src_pkg_name.utf8().get_data(), &io);
  259. if (!src_pkg_zip) {
  260. EditorNode::add_io_error("Could not find template app to export:\n" + src_pkg_name);
  261. return ERR_FILE_NOT_FOUND;
  262. }
  263. ERR_FAIL_COND_V(!src_pkg_zip, ERR_CANT_OPEN);
  264. int ret = unzGoToFirstFile(src_pkg_zip);
  265. String binary_to_use = "godot_osx_" + String(p_debug ? "debug" : "release") + ".";
  266. int bits_mode = p_preset->get("application/bits_mode");
  267. binary_to_use += String(bits_mode == 0 ? "fat" : bits_mode == 1 ? "64" : "32");
  268. print_line("binary: " + binary_to_use);
  269. String pkg_name;
  270. if (p_preset->get("application/name") != "")
  271. pkg_name = p_preset->get("application/name"); // app_name
  272. else if (String(ProjectSettings::get_singleton()->get("application/config/name")) != "")
  273. pkg_name = String(ProjectSettings::get_singleton()->get("application/config/name"));
  274. else
  275. pkg_name = "Unnamed";
  276. Error err = OK;
  277. String tmp_app_path_name = "";
  278. zlib_filefunc_def io2 = io;
  279. FileAccess *dst_f = NULL;
  280. io2.opaque = &dst_f;
  281. zipFile dst_pkg_zip = NULL;
  282. if (use_dmg()) {
  283. // We're on OSX so we can export to DMG, but first we create our application bundle
  284. tmp_app_path_name = EditorSettings::get_singleton()->get_cache_dir().plus_file(pkg_name + ".app");
  285. print_line("Exporting to " + tmp_app_path_name);
  286. DirAccess *tmp_app_path = DirAccess::create_for_path(tmp_app_path_name);
  287. if (!tmp_app_path) {
  288. err = ERR_CANT_CREATE;
  289. }
  290. // Create our folder structure or rely on unzip?
  291. if (err == OK) {
  292. print_line("Creating " + tmp_app_path_name + "/Contents/MacOS");
  293. err = tmp_app_path->make_dir_recursive(tmp_app_path_name + "/Contents/MacOS");
  294. }
  295. if (err == OK) {
  296. print_line("Creating " + tmp_app_path_name + "/Contents/Frameworks");
  297. err = tmp_app_path->make_dir_recursive(tmp_app_path_name + "/Contents/Frameworks");
  298. }
  299. if (err == OK) {
  300. print_line("Creating " + tmp_app_path_name + "/Contents/Resources");
  301. err = tmp_app_path->make_dir_recursive(tmp_app_path_name + "/Contents/Resources");
  302. }
  303. } else {
  304. // Open our destination zip file
  305. dst_pkg_zip = zipOpen2(p_path.utf8().get_data(), APPEND_STATUS_CREATE, NULL, &io2);
  306. if (!dst_pkg_zip) {
  307. err = ERR_CANT_CREATE;
  308. }
  309. }
  310. // Now process our template
  311. bool found_binary = false;
  312. int total_size = 0;
  313. while (ret == UNZ_OK && err == OK) {
  314. bool is_execute = false;
  315. //get filename
  316. unz_file_info info;
  317. char fname[16384];
  318. ret = unzGetCurrentFileInfo(src_pkg_zip, &info, fname, 16384, NULL, 0, NULL, 0);
  319. String file = fname;
  320. print_line("READ: " + file);
  321. Vector<uint8_t> data;
  322. data.resize(info.uncompressed_size);
  323. //read
  324. unzOpenCurrentFile(src_pkg_zip);
  325. unzReadCurrentFile(src_pkg_zip, data.ptrw(), data.size());
  326. unzCloseCurrentFile(src_pkg_zip);
  327. //write
  328. file = file.replace_first("osx_template.app/", "");
  329. if (file == "Contents/Info.plist") {
  330. print_line("parse plist");
  331. _fix_plist(p_preset, data, pkg_name);
  332. }
  333. if (file.begins_with("Contents/MacOS/godot_")) {
  334. if (file != "Contents/MacOS/" + binary_to_use) {
  335. ret = unzGoToNextFile(src_pkg_zip);
  336. continue; //ignore!
  337. }
  338. found_binary = true;
  339. is_execute = true;
  340. file = "Contents/MacOS/" + pkg_name;
  341. }
  342. if (file == "Contents/Resources/icon.icns") {
  343. //see if there is an icon
  344. String iconpath;
  345. if (p_preset->get("application/icon") != "")
  346. iconpath = p_preset->get("application/icon");
  347. else
  348. iconpath = ProjectSettings::get_singleton()->get("application/config/icon");
  349. print_line("icon? " + iconpath);
  350. if (iconpath != "") {
  351. Ref<Image> icon;
  352. icon.instance();
  353. icon->load(iconpath);
  354. if (!icon->empty()) {
  355. print_line("loaded?");
  356. _make_icon(icon, data);
  357. }
  358. }
  359. //bleh?
  360. }
  361. if (data.size() > 0) {
  362. print_line("ADDING: " + file + " size: " + itos(data.size()));
  363. total_size += data.size();
  364. if (use_dmg()) {
  365. // write it into our application bundle
  366. file = tmp_app_path_name + "/" + file;
  367. // write the file, need to add chmod
  368. FileAccess *f = FileAccess::open(file, FileAccess::WRITE);
  369. if (f) {
  370. f->store_buffer(data.ptr(), data.size());
  371. f->close();
  372. if (is_execute) {
  373. // Chmod with 0755 if the file is executable
  374. f->_chmod(file, 0755);
  375. }
  376. memdelete(f);
  377. } else {
  378. err = ERR_CANT_CREATE;
  379. }
  380. } else {
  381. // add it to our zip file
  382. file = pkg_name + ".app/" + file;
  383. zip_fileinfo fi;
  384. fi.tmz_date.tm_hour = info.tmu_date.tm_hour;
  385. fi.tmz_date.tm_min = info.tmu_date.tm_min;
  386. fi.tmz_date.tm_sec = info.tmu_date.tm_sec;
  387. fi.tmz_date.tm_mon = info.tmu_date.tm_mon;
  388. fi.tmz_date.tm_mday = info.tmu_date.tm_mday;
  389. fi.tmz_date.tm_year = info.tmu_date.tm_year;
  390. fi.dosDate = info.dosDate;
  391. fi.internal_fa = info.internal_fa;
  392. fi.external_fa = info.external_fa;
  393. int zerr = zipOpenNewFileInZip(dst_pkg_zip,
  394. file.utf8().get_data(),
  395. &fi,
  396. NULL,
  397. 0,
  398. NULL,
  399. 0,
  400. NULL,
  401. Z_DEFLATED,
  402. Z_DEFAULT_COMPRESSION);
  403. print_line("OPEN ERR: " + itos(zerr));
  404. zerr = zipWriteInFileInZip(dst_pkg_zip, data.ptr(), data.size());
  405. print_line("WRITE ERR: " + itos(zerr));
  406. zipCloseFileInZip(dst_pkg_zip);
  407. }
  408. }
  409. ret = unzGoToNextFile(src_pkg_zip);
  410. }
  411. // we're done with our source zip
  412. unzClose(src_pkg_zip);
  413. if (!found_binary) {
  414. ERR_PRINTS("Requested template binary '" + binary_to_use + "' not found. It might be missing from your template archive.");
  415. err = ERR_FILE_NOT_FOUND;
  416. }
  417. if (err == OK) {
  418. ep.step("Making PKG", 1);
  419. if (use_dmg()) {
  420. String pack_path = tmp_app_path_name + "/Contents/Resources/" + pkg_name + ".pck";
  421. Vector<SharedObject> shared_objects;
  422. err = save_pack(p_preset, pack_path, &shared_objects);
  423. // see if we can code sign our new package
  424. String identity = p_preset->get("codesign/identity");
  425. if (err == OK) {
  426. DirAccess *da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  427. for (int i = 0; i < shared_objects.size(); i++) {
  428. err = da->copy(shared_objects[i].path, tmp_app_path_name + "/Contents/Frameworks/" + shared_objects[i].path.get_file());
  429. if (err == OK && identity != "") {
  430. err = _code_sign(p_preset, tmp_app_path_name + "/Contents/Frameworks/" + shared_objects[i].path.get_file());
  431. }
  432. }
  433. memdelete(da);
  434. }
  435. if (err == OK && identity != "") {
  436. ep.step("Code signing bundle", 2);
  437. // the order in which we code sign is important, this is a bit of a shame or we could do this in our loop that extracts the files from our ZIP
  438. // start with our application
  439. err = _code_sign(p_preset, tmp_app_path_name + "/Contents/MacOS/" + pkg_name);
  440. ///@TODO we should check the contents of /Contents/Frameworks for frameworks to sign
  441. }
  442. if (err == OK && identity != "") {
  443. // we should probably loop through all resources and sign them?
  444. err = _code_sign(p_preset, tmp_app_path_name + "/Contents/Resources/icon.icns");
  445. }
  446. if (err == OK && identity != "") {
  447. err = _code_sign(p_preset, pack_path);
  448. }
  449. if (err == OK && identity != "") {
  450. err = _code_sign(p_preset, tmp_app_path_name + "/Contents/Info.plist");
  451. }
  452. // and finally create a DMG
  453. if (err == OK) {
  454. ep.step("Making DMG", 3);
  455. err = _create_dmg(p_path, pkg_name, tmp_app_path_name);
  456. }
  457. // Clean up temporary .app dir
  458. OS::get_singleton()->move_to_trash(tmp_app_path_name);
  459. } else {
  460. String pack_path = EditorSettings::get_singleton()->get_cache_dir().plus_file(pkg_name + ".pck");
  461. Vector<SharedObject> shared_objects;
  462. err = save_pack(p_preset, pack_path, &shared_objects);
  463. if (err == OK) {
  464. zipOpenNewFileInZip(dst_pkg_zip,
  465. (pkg_name + ".app/Contents/Resources/" + pkg_name + ".pck").utf8().get_data(),
  466. NULL,
  467. NULL,
  468. 0,
  469. NULL,
  470. 0,
  471. NULL,
  472. Z_DEFLATED,
  473. Z_DEFAULT_COMPRESSION);
  474. FileAccess *pf = FileAccess::open(pack_path, FileAccess::READ);
  475. if (pf) {
  476. const int BSIZE = 16384;
  477. uint8_t buf[BSIZE];
  478. while (true) {
  479. int r = pf->get_buffer(buf, BSIZE);
  480. if (r <= 0)
  481. break;
  482. zipWriteInFileInZip(dst_pkg_zip, buf, r);
  483. }
  484. zipCloseFileInZip(dst_pkg_zip);
  485. memdelete(pf);
  486. } else {
  487. err = ERR_CANT_OPEN;
  488. }
  489. }
  490. if (err == OK) {
  491. //add shared objects
  492. for (int i = 0; i < shared_objects.size(); i++) {
  493. Vector<uint8_t> file = FileAccess::get_file_as_array(shared_objects[i].path);
  494. ERR_CONTINUE(file.empty());
  495. zipOpenNewFileInZip(dst_pkg_zip,
  496. (pkg_name + ".app/Contents/Frameworks/").plus_file(shared_objects[i].path.get_file()).utf8().get_data(),
  497. NULL,
  498. NULL,
  499. 0,
  500. NULL,
  501. 0,
  502. NULL,
  503. Z_DEFLATED,
  504. Z_DEFAULT_COMPRESSION);
  505. zipWriteInFileInZip(dst_pkg_zip, file.ptr(), file.size());
  506. zipCloseFileInZip(dst_pkg_zip);
  507. }
  508. }
  509. }
  510. }
  511. if (dst_pkg_zip) {
  512. zipClose(dst_pkg_zip, NULL);
  513. }
  514. return err;
  515. }
  516. bool EditorExportPlatformOSX::can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const {
  517. bool valid = false;
  518. String err;
  519. if (exists_export_template("osx.zip", &err)) {
  520. valid = true;
  521. }
  522. if (p_preset->get("custom_package/debug") != "") {
  523. if (FileAccess::exists(p_preset->get("custom_package/debug"))) {
  524. valid = true;
  525. } else {
  526. err += "Custom debug package not found.\n";
  527. }
  528. }
  529. if (p_preset->get("custom_package/release") != "") {
  530. if (FileAccess::exists(p_preset->get("custom_package/release"))) {
  531. valid = true;
  532. } else {
  533. err += "Custom release package not found.\n";
  534. }
  535. }
  536. if (!err.empty())
  537. r_error = err;
  538. r_missing_templates = !valid;
  539. return valid;
  540. }
  541. EditorExportPlatformOSX::EditorExportPlatformOSX() {
  542. Ref<Image> img = memnew(Image(_osx_logo));
  543. logo.instance();
  544. logo->create_from_image(img);
  545. }
  546. EditorExportPlatformOSX::~EditorExportPlatformOSX() {
  547. }
  548. void register_osx_exporter() {
  549. Ref<EditorExportPlatformOSX> platform;
  550. platform.instance();
  551. EditorExport::get_singleton()->add_export_platform(platform);
  552. }