123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788 |
- #include "export.h"
- #include "core/io/marshalls.h"
- #include "core/io/resource_saver.h"
- #include "core/io/zip_io.h"
- #include "core/os/file_access.h"
- #include "core/os/os.h"
- #include "core/project_settings.h"
- #include "core/version.h"
- #include "editor/editor_export.h"
- #include "editor/editor_node.h"
- #include "editor/editor_settings.h"
- #include "platform/osx/logo.gen.h"
- #include "string.h"
- #include <sys/stat.h>
- class EditorExportPlatformOSX : public EditorExportPlatform {
- GDCLASS(EditorExportPlatformOSX, EditorExportPlatform);
- int version_code;
- Ref<ImageTexture> logo;
- void _fix_plist(const Ref<EditorExportPreset> &p_preset, Vector<uint8_t> &plist, const String &p_binary);
- void _make_icon(const Ref<Image> &p_icon, Vector<uint8_t> &p_data);
- Error _code_sign(const Ref<EditorExportPreset> &p_preset, const String &p_path);
- Error _create_dmg(const String &p_dmg_path, const String &p_pkg_name, const String &p_app_path_name);
- #ifdef OSX_ENABLED
- bool use_codesign() const { return true; }
- bool use_dmg() const { return true; }
- #else
- bool use_codesign() const { return false; }
- bool use_dmg() const { return false; }
- #endif
- protected:
- virtual void get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features);
- virtual void get_export_options(List<ExportOption> *r_options);
- public:
- virtual String get_name() const { return "Mac OSX"; }
- virtual String get_os_name() const { return "OSX"; }
- virtual Ref<Texture> get_logo() const { return logo; }
- virtual List<String> get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const {
- List<String> list;
- if (use_dmg()) {
- list.push_back("dmg");
- }
- list.push_back("zip");
- return list;
- }
- virtual Error export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags = 0);
- virtual bool can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const;
- virtual void get_platform_features(List<String> *r_features) {
- r_features->push_back("pc");
- r_features->push_back("s3tc");
- r_features->push_back("OSX");
- }
- virtual void resolve_platform_feature_priorities(const Ref<EditorExportPreset> &p_preset, Set<String> &p_features) {
- }
- EditorExportPlatformOSX();
- ~EditorExportPlatformOSX();
- };
- void EditorExportPlatformOSX::get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features) {
- if (p_preset->get("texture_format/s3tc")) {
- r_features->push_back("s3tc");
- }
- if (p_preset->get("texture_format/etc")) {
- r_features->push_back("etc");
- }
- if (p_preset->get("texture_format/etc2")) {
- r_features->push_back("etc2");
- }
- r_features->push_back("64");
- }
- void EditorExportPlatformOSX::get_export_options(List<ExportOption> *r_options) {
- r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_package/debug", PROPERTY_HINT_GLOBAL_FILE, "*.zip"), ""));
- r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_package/release", PROPERTY_HINT_GLOBAL_FILE, "*.zip"), ""));
- r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/name", PROPERTY_HINT_PLACEHOLDER_TEXT, "Game Name"), ""));
- r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/info"), "Made with Godot Engine"));
- r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/icon", PROPERTY_HINT_FILE, "*.png"), ""));
- r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/identifier", PROPERTY_HINT_PLACEHOLDER_TEXT, "com.example.game"), ""));
- r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/signature"), ""));
- r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/short_version"), "1.0"));
- r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/version"), "1.0"));
- r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/copyright"), ""));
- r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "display/high_res"), false));
- #ifdef OSX_ENABLED
- r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/identity"), ""));
- r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/entitlements"), ""));
- #endif
- r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "texture_format/s3tc"), true));
- r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "texture_format/etc"), false));
- r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "texture_format/etc2"), false));
- }
- void _rgba8_to_packbits_encode(int p_ch, int p_size, PoolVector<uint8_t> &p_source, Vector<uint8_t> &p_dest) {
- int src_len = p_size * p_size;
- Vector<uint8_t> result;
- result.resize(src_len * 1.25);
- int res_size = 0;
- uint8_t buf[128];
- int buf_size = 0;
- int i = 0;
- while (i < src_len) {
- uint8_t cur = p_source.read()[i * 4 + p_ch];
- if (i < src_len - 2) {
- if ((p_source.read()[(i + 1) * 4 + p_ch] == cur) && (p_source.read()[(i + 2) * 4 + p_ch] == cur)) {
- if (buf_size > 0) {
- result.write[res_size++] = (uint8_t)(buf_size - 1);
- copymem(&result.write[res_size], &buf, buf_size);
- res_size += buf_size;
- buf_size = 0;
- }
- uint8_t lim = i + 130 >= src_len ? src_len - i - 1 : 130;
- bool hit_lim = true;
- for (int j = 3; j <= lim; j++) {
- if (p_source.read()[(i + j) * 4 + p_ch] != cur) {
- hit_lim = false;
- i = i + j - 1;
- result.write[res_size++] = (uint8_t)(j - 3 + 0x80);
- result.write[res_size++] = cur;
- break;
- }
- }
- if (hit_lim) {
- result.write[res_size++] = (uint8_t)(lim - 3 + 0x80);
- result.write[res_size++] = cur;
- i = i + lim;
- }
- } else {
- buf[buf_size++] = cur;
- if (buf_size == 128) {
- result.write[res_size++] = (uint8_t)(buf_size - 1);
- copymem(&result.write[res_size], &buf, buf_size);
- res_size += buf_size;
- buf_size = 0;
- }
- }
- } else {
- buf[buf_size++] = cur;
- result.write[res_size++] = (uint8_t)(buf_size - 1);
- copymem(&result.write[res_size], &buf, buf_size);
- res_size += buf_size;
- buf_size = 0;
- }
- i++;
- }
- int ofs = p_dest.size();
- p_dest.resize(p_dest.size() + res_size);
- copymem(&p_dest.write[ofs], result.ptr(), res_size);
- }
- void EditorExportPlatformOSX::_make_icon(const Ref<Image> &p_icon, Vector<uint8_t> &p_data) {
- Ref<ImageTexture> it = memnew(ImageTexture);
- Vector<uint8_t> data;
- data.resize(8);
- data.write[0] = 'i';
- data.write[1] = 'c';
- data.write[2] = 'n';
- data.write[3] = 's';
- struct MacOSIconInfo {
- const char *name;
- const char *mask_name;
- bool is_png;
- int size;
- };
- static const MacOSIconInfo icon_infos[] = {
- { "ic10", "", true, 1024 },
- { "ic09", "", true, 512 },
- { "ic14", "", true, 512 },
- { "ic08", "", true, 256 },
- { "ic13", "", true, 256 },
- { "ic07", "", true, 128 },
- { "ic12", "", true, 64 },
- { "ic11", "", true, 32 },
- { "il32", "l8mk", false, 32 },
- { "is32", "s8mk", false, 16 }
- };
- for (unsigned int i = 0; i < (sizeof(icon_infos) / sizeof(icon_infos[0])); ++i) {
- Ref<Image> copy = p_icon;
- copy->convert(Image::FORMAT_RGBA8);
- copy->resize(icon_infos[i].size, icon_infos[i].size);
- if (icon_infos[i].is_png) {
-
- it->create_from_image(copy);
- String path = EditorSettings::get_singleton()->get_cache_dir().plus_file("icon.png");
- ResourceSaver::save(path, it);
- FileAccess *f = FileAccess::open(path, FileAccess::READ);
- ERR_FAIL_COND(!f);
- int ofs = data.size();
- uint32_t len = f->get_len();
- data.resize(data.size() + len + 8);
- f->get_buffer(&data.write[ofs + 8], len);
- memdelete(f);
- len += 8;
- len = BSWAP32(len);
- copymem(&data.write[ofs], icon_infos[i].name, 4);
- encode_uint32(len, &data.write[ofs + 4]);
- } else {
- PoolVector<uint8_t> src_data = copy->get_data();
-
- {
- int ofs = data.size();
- data.resize(data.size() + 8);
- _rgba8_to_packbits_encode(0, icon_infos[i].size, src_data, data);
- _rgba8_to_packbits_encode(1, icon_infos[i].size, src_data, data);
- _rgba8_to_packbits_encode(2, icon_infos[i].size, src_data, data);
- int len = data.size() - ofs;
- len = BSWAP32(len);
- copymem(&data.write[ofs], icon_infos[i].name, 4);
- encode_uint32(len, &data.write[ofs + 4]);
- }
-
- {
- int ofs = data.size();
- int len = copy->get_width() * copy->get_height();
- data.resize(data.size() + len + 8);
- for (int j = 0; j < len; j++) {
- data.write[ofs + 8 + j] = src_data.read()[j * 4 + 3];
- }
- len += 8;
- len = BSWAP32(len);
- copymem(&data.write[ofs], icon_infos[i].mask_name, 4);
- encode_uint32(len, &data.write[ofs + 4]);
- }
- }
- }
- uint32_t total_len = data.size();
- total_len = BSWAP32(total_len);
- encode_uint32(total_len, &data.write[4]);
- p_data = data;
- }
- void EditorExportPlatformOSX::_fix_plist(const Ref<EditorExportPreset> &p_preset, Vector<uint8_t> &plist, const String &p_binary) {
- String str;
- String strnew;
- str.parse_utf8((const char *)plist.ptr(), plist.size());
- Vector<String> lines = str.split("\n");
- for (int i = 0; i < lines.size(); i++) {
- if (lines[i].find("$binary") != -1) {
- strnew += lines[i].replace("$binary", p_binary) + "\n";
- } else if (lines[i].find("$name") != -1) {
- strnew += lines[i].replace("$name", p_binary) + "\n";
- } else if (lines[i].find("$info") != -1) {
- strnew += lines[i].replace("$info", p_preset->get("application/info")) + "\n";
- } else if (lines[i].find("$identifier") != -1) {
- strnew += lines[i].replace("$identifier", p_preset->get("application/identifier")) + "\n";
- } else if (lines[i].find("$short_version") != -1) {
- strnew += lines[i].replace("$short_version", p_preset->get("application/short_version")) + "\n";
- } else if (lines[i].find("$version") != -1) {
- strnew += lines[i].replace("$version", p_preset->get("application/version")) + "\n";
- } else if (lines[i].find("$signature") != -1) {
- strnew += lines[i].replace("$signature", p_preset->get("application/signature")) + "\n";
- } else if (lines[i].find("$copyright") != -1) {
- strnew += lines[i].replace("$copyright", p_preset->get("application/copyright")) + "\n";
- } else if (lines[i].find("$highres") != -1) {
- strnew += lines[i].replace("$highres", p_preset->get("display/high_res") ? "<true/>" : "<false/>") + "\n";
- } else {
- strnew += lines[i] + "\n";
- }
- }
- CharString cs = strnew.utf8();
- plist.resize(cs.size() - 1);
- for (int i = 0; i < cs.size() - 1; i++) {
- plist.write[i] = cs[i];
- }
- }
- Error EditorExportPlatformOSX::_code_sign(const Ref<EditorExportPreset> &p_preset, const String &p_path) {
- List<String> args;
- if (p_preset->get("codesign/entitlements") != "") {
-
- args.push_back("-entitlements");
- args.push_back(p_preset->get("codesign/entitlements"));
- }
- args.push_back("-s");
- args.push_back(p_preset->get("codesign/identity"));
- args.push_back("-v");
- args.push_back(p_path);
- String str;
- Error err = OS::get_singleton()->execute("codesign", args, true, NULL, &str, NULL, true);
- ERR_FAIL_COND_V(err != OK, err);
- print_line("codesign: " + str);
- if (str.find("no identity found") != -1) {
- EditorNode::add_io_error("codesign: no identity found");
- return FAILED;
- }
- return OK;
- }
- Error EditorExportPlatformOSX::_create_dmg(const String &p_dmg_path, const String &p_pkg_name, const String &p_app_path_name) {
- List<String> args;
- OS::get_singleton()->move_to_trash(p_dmg_path);
- args.push_back("create");
- args.push_back(p_dmg_path);
- args.push_back("-volname");
- args.push_back(p_pkg_name);
- args.push_back("-fs");
- args.push_back("HFS+");
- args.push_back("-srcfolder");
- args.push_back(p_app_path_name);
- String str;
- Error err = OS::get_singleton()->execute("hdiutil", args, true, NULL, &str, NULL, true);
- ERR_FAIL_COND_V(err != OK, err);
- print_line("hdiutil returned: " + str);
- if (str.find("create failed") != -1) {
- if (str.find("File exists") != -1) {
- EditorNode::add_io_error("hdiutil: create failed - file exists");
- } else {
- EditorNode::add_io_error("hdiutil: create failed");
- }
- return FAILED;
- }
- return OK;
- }
- Error EditorExportPlatformOSX::export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags) {
- ExportNotifier notifier(*this, p_preset, p_debug, p_path, p_flags);
- String src_pkg_name;
- EditorProgress ep("export", "Exporting for OSX", 3);
- if (p_debug)
- src_pkg_name = p_preset->get("custom_package/debug");
- else
- src_pkg_name = p_preset->get("custom_package/release");
- if (src_pkg_name == "") {
- String err;
- src_pkg_name = find_export_template("osx.zip", &err);
- if (src_pkg_name == "") {
- EditorNode::add_io_error(err);
- return ERR_FILE_NOT_FOUND;
- }
- }
- FileAccess *src_f = NULL;
- zlib_filefunc_def io = zipio_create_io_from_file(&src_f);
- ep.step("Creating app", 0);
- unzFile src_pkg_zip = unzOpen2(src_pkg_name.utf8().get_data(), &io);
- if (!src_pkg_zip) {
- EditorNode::add_io_error("Could not find template app to export:\n" + src_pkg_name);
- return ERR_FILE_NOT_FOUND;
- }
- ERR_FAIL_COND_V(!src_pkg_zip, ERR_CANT_OPEN);
- int ret = unzGoToFirstFile(src_pkg_zip);
- String binary_to_use = "godot_osx_" + String(p_debug ? "debug" : "release") + ".64";
- String pkg_name;
- if (p_preset->get("application/name") != "")
- pkg_name = p_preset->get("application/name");
- else if (String(ProjectSettings::get_singleton()->get("application/config/name")) != "")
- pkg_name = String(ProjectSettings::get_singleton()->get("application/config/name"));
- else
- pkg_name = "Unnamed";
- Error err = OK;
- String tmp_app_path_name = "";
- zlib_filefunc_def io2 = io;
- FileAccess *dst_f = NULL;
- io2.opaque = &dst_f;
- zipFile dst_pkg_zip = NULL;
- String export_format = use_dmg() && p_path.ends_with("dmg") ? "dmg" : "zip";
- if (export_format == "dmg") {
-
- tmp_app_path_name = EditorSettings::get_singleton()->get_cache_dir().plus_file(pkg_name + ".app");
- print_line("Exporting to " + tmp_app_path_name);
- DirAccess *tmp_app_path = DirAccess::create_for_path(tmp_app_path_name);
- if (!tmp_app_path) {
- err = ERR_CANT_CREATE;
- }
-
- if (err == OK) {
- print_line("Creating " + tmp_app_path_name + "/Contents/MacOS");
- err = tmp_app_path->make_dir_recursive(tmp_app_path_name + "/Contents/MacOS");
- }
- if (err == OK) {
- print_line("Creating " + tmp_app_path_name + "/Contents/Frameworks");
- err = tmp_app_path->make_dir_recursive(tmp_app_path_name + "/Contents/Frameworks");
- }
- if (err == OK) {
- print_line("Creating " + tmp_app_path_name + "/Contents/Resources");
- err = tmp_app_path->make_dir_recursive(tmp_app_path_name + "/Contents/Resources");
- }
- } else {
-
- dst_pkg_zip = zipOpen2(p_path.utf8().get_data(), APPEND_STATUS_CREATE, NULL, &io2);
- if (!dst_pkg_zip) {
- err = ERR_CANT_CREATE;
- }
- }
-
- bool found_binary = false;
- int total_size = 0;
- while (ret == UNZ_OK && err == OK) {
- bool is_execute = false;
-
- unz_file_info info;
- char fname[16384];
- ret = unzGetCurrentFileInfo(src_pkg_zip, &info, fname, 16384, NULL, 0, NULL, 0);
- String file = fname;
- Vector<uint8_t> data;
- data.resize(info.uncompressed_size);
-
- unzOpenCurrentFile(src_pkg_zip);
- unzReadCurrentFile(src_pkg_zip, data.ptrw(), data.size());
- unzCloseCurrentFile(src_pkg_zip);
-
- file = file.replace_first("osx_template.app/", "");
- if (file == "Contents/Info.plist") {
- _fix_plist(p_preset, data, pkg_name);
- }
- if (file.begins_with("Contents/MacOS/godot_")) {
- if (file != "Contents/MacOS/" + binary_to_use) {
- ret = unzGoToNextFile(src_pkg_zip);
- continue;
- }
- found_binary = true;
- is_execute = true;
- file = "Contents/MacOS/" + pkg_name;
- }
- if (file == "Contents/Resources/icon.icns") {
-
- String iconpath;
- if (p_preset->get("application/icon") != "")
- iconpath = p_preset->get("application/icon");
- else
- iconpath = ProjectSettings::get_singleton()->get("application/config/icon");
- if (iconpath != "") {
- Ref<Image> icon;
- icon.instance();
- icon->load(iconpath);
- if (!icon->empty()) {
- _make_icon(icon, data);
- }
- }
-
- }
- if (data.size() > 0) {
- print_line("ADDING: " + file + " size: " + itos(data.size()));
- total_size += data.size();
- if (export_format == "dmg") {
-
- file = tmp_app_path_name + "/" + file;
-
- FileAccess *f = FileAccess::open(file, FileAccess::WRITE);
- if (f) {
- f->store_buffer(data.ptr(), data.size());
- f->close();
- if (is_execute) {
-
- f->_chmod(file, 0755);
- }
- memdelete(f);
- } else {
- err = ERR_CANT_CREATE;
- }
- } else {
-
- file = pkg_name + ".app/" + file;
- zip_fileinfo fi;
- fi.tmz_date.tm_hour = info.tmu_date.tm_hour;
- fi.tmz_date.tm_min = info.tmu_date.tm_min;
- fi.tmz_date.tm_sec = info.tmu_date.tm_sec;
- fi.tmz_date.tm_mon = info.tmu_date.tm_mon;
- fi.tmz_date.tm_mday = info.tmu_date.tm_mday;
- fi.tmz_date.tm_year = info.tmu_date.tm_year;
- fi.dosDate = info.dosDate;
- fi.internal_fa = info.internal_fa;
- fi.external_fa = info.external_fa;
- zipOpenNewFileInZip(dst_pkg_zip,
- file.utf8().get_data(),
- &fi,
- NULL,
- 0,
- NULL,
- 0,
- NULL,
- Z_DEFLATED,
- Z_DEFAULT_COMPRESSION);
- zipWriteInFileInZip(dst_pkg_zip, data.ptr(), data.size());
- zipCloseFileInZip(dst_pkg_zip);
- }
- }
- ret = unzGoToNextFile(src_pkg_zip);
- }
-
- unzClose(src_pkg_zip);
- if (!found_binary) {
- ERR_PRINTS("Requested template binary '" + binary_to_use + "' not found. It might be missing from your template archive.");
- err = ERR_FILE_NOT_FOUND;
- }
- if (err == OK) {
- ep.step("Making PKG", 1);
- if (export_format == "dmg") {
- String pack_path = tmp_app_path_name + "/Contents/Resources/" + pkg_name + ".pck";
- Vector<SharedObject> shared_objects;
- err = save_pack(p_preset, pack_path, &shared_objects);
-
- String identity = p_preset->get("codesign/identity");
- if (err == OK) {
- DirAccess *da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
- for (int i = 0; i < shared_objects.size(); i++) {
- err = da->copy(shared_objects[i].path, tmp_app_path_name + "/Contents/Frameworks/" + shared_objects[i].path.get_file());
- if (err == OK && identity != "") {
- err = _code_sign(p_preset, tmp_app_path_name + "/Contents/Frameworks/" + shared_objects[i].path.get_file());
- }
- }
- memdelete(da);
- }
- if (err == OK && identity != "") {
- ep.step("Code signing bundle", 2);
-
-
- err = _code_sign(p_preset, tmp_app_path_name + "/Contents/MacOS/" + pkg_name);
-
- }
- if (err == OK && identity != "") {
-
- err = _code_sign(p_preset, tmp_app_path_name + "/Contents/Resources/icon.icns");
- }
- if (err == OK && identity != "") {
- err = _code_sign(p_preset, pack_path);
- }
- if (err == OK && identity != "") {
- err = _code_sign(p_preset, tmp_app_path_name + "/Contents/Info.plist");
- }
-
- if (err == OK) {
- ep.step("Making DMG", 3);
- err = _create_dmg(p_path, pkg_name, tmp_app_path_name);
- }
-
- OS::get_singleton()->move_to_trash(tmp_app_path_name);
- } else {
- String pack_path = EditorSettings::get_singleton()->get_cache_dir().plus_file(pkg_name + ".pck");
- Vector<SharedObject> shared_objects;
- err = save_pack(p_preset, pack_path, &shared_objects);
- if (err == OK) {
- zipOpenNewFileInZip(dst_pkg_zip,
- (pkg_name + ".app/Contents/Resources/" + pkg_name + ".pck").utf8().get_data(),
- NULL,
- NULL,
- 0,
- NULL,
- 0,
- NULL,
- Z_DEFLATED,
- Z_DEFAULT_COMPRESSION);
- FileAccess *pf = FileAccess::open(pack_path, FileAccess::READ);
- if (pf) {
- const int BSIZE = 16384;
- uint8_t buf[BSIZE];
- while (true) {
- int r = pf->get_buffer(buf, BSIZE);
- if (r <= 0)
- break;
- zipWriteInFileInZip(dst_pkg_zip, buf, r);
- }
- zipCloseFileInZip(dst_pkg_zip);
- memdelete(pf);
- } else {
- err = ERR_CANT_OPEN;
- }
- }
- if (err == OK) {
-
- for (int i = 0; i < shared_objects.size(); i++) {
- Vector<uint8_t> file = FileAccess::get_file_as_array(shared_objects[i].path);
- ERR_CONTINUE(file.empty());
- zipOpenNewFileInZip(dst_pkg_zip,
- (pkg_name + ".app/Contents/Frameworks/").plus_file(shared_objects[i].path.get_file()).utf8().get_data(),
- NULL,
- NULL,
- 0,
- NULL,
- 0,
- NULL,
- Z_DEFLATED,
- Z_DEFAULT_COMPRESSION);
- zipWriteInFileInZip(dst_pkg_zip, file.ptr(), file.size());
- zipCloseFileInZip(dst_pkg_zip);
- }
- }
- }
- }
- if (dst_pkg_zip) {
- zipClose(dst_pkg_zip, NULL);
- }
- return err;
- }
- bool EditorExportPlatformOSX::can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const {
- bool valid = false;
- String err;
- if (exists_export_template("osx.zip", &err)) {
- valid = true;
- }
- if (p_preset->get("custom_package/debug") != "") {
- if (FileAccess::exists(p_preset->get("custom_package/debug"))) {
- valid = true;
- } else {
- err += "Custom debug package not found.\n";
- }
- }
- if (p_preset->get("custom_package/release") != "") {
- if (FileAccess::exists(p_preset->get("custom_package/release"))) {
- valid = true;
- } else {
- err += "Custom release package not found.\n";
- }
- }
- if (!err.empty())
- r_error = err;
- r_missing_templates = !valid;
- return valid;
- }
- EditorExportPlatformOSX::EditorExportPlatformOSX() {
- Ref<Image> img = memnew(Image(_osx_logo));
- logo.instance();
- logo->create_from_image(img);
- }
- EditorExportPlatformOSX::~EditorExportPlatformOSX() {
- }
- void register_osx_exporter() {
- Ref<EditorExportPlatformOSX> platform;
- platform.instance();
- EditorExport::get_singleton()->add_export_platform(platform);
- }
|