Reimplement export module for OSX

This commit is contained in:
BastiaanOlij 2017-06-21 19:11:38 +10:00
parent 320c1af616
commit 5b44f092f9
2 changed files with 203 additions and 328 deletions

View file

@ -235,7 +235,7 @@ void ProjectExportDialog::_edit_preset(int p_index) {
export_button->set_disabled(true); export_button->set_disabled(true);
} else { } else {
export_error->show(); export_error->hide();
export_templates_error->hide(); export_templates_error->hide();
export_button->set_disabled(false); export_button->set_disabled(false);
} }

View file

@ -27,6 +27,7 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/ /*************************************************************************/
#include "export.h" #include "export.h"
#include "editor/editor_export.h" #include "editor/editor_export.h"
#include "editor/editor_node.h" #include "editor/editor_node.h"
@ -40,156 +41,58 @@
#include "platform/osx/logo.h" #include "platform/osx/logo.h"
#include "string.h" #include "string.h"
#include "version.h" #include "version.h"
#if 0
class EditorExportPlatformOSX : public EditorExportPlatform { class EditorExportPlatformOSX : public EditorExportPlatform {
GDCLASS(EditorExportPlatformOSX, EditorExportPlatform); GDCLASS(EditorExportPlatformOSX, EditorExportPlatform);
String custom_release_package;
String custom_debug_package;
enum BitsMode {
BITS_FAT,
BITS_64,
BITS_32
};
int version_code; int version_code;
String app_name;
String info;
String icon;
String identifier;
String short_version;
String version;
String signature;
String copyright;
BitsMode bits_mode;
bool high_resolution;
Ref<ImageTexture> logo; Ref<ImageTexture> logo;
void _fix_plist(Vector<uint8_t>& plist, const String &p_binary); void _fix_plist(const Ref<EditorExportPreset> &p_preset, Vector<uint8_t> &plist, const String &p_binary);
void _make_icon(const Image& p_icon,Vector<uint8_t>& data); void _make_icon(const Ref<Image> &p_icon, Vector<uint8_t> &p_data);
protected: protected:
virtual void get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features);
bool _set(const StringName& p_name, const Variant& p_value); virtual void get_export_options(List<ExportOption> *r_options);
bool _get(const StringName& p_name,Variant &r_ret) const;
void _get_property_list( List<PropertyInfo> *p_list) const;
public: public:
virtual String get_name() const { return "Mac OSX"; } virtual String get_name() const { return "Mac OSX"; }
virtual ImageCompression get_image_compression() const { return IMAGE_COMPRESSION_BC; }
virtual Ref<Texture> get_logo() const { return logo; } virtual Ref<Texture> get_logo() const { return logo; }
virtual bool poll_devices() { return false;}
virtual int get_device_count() const { return 0; }
virtual String get_device_name(int p_device) const { return String(); }
virtual String get_device_info(int p_device) const { return String(); }
virtual Error run(int p_device,int p_flags=0);
virtual bool requires_password(bool p_debug) const { return false; }
virtual String get_binary_extension() const { return "zip"; } virtual String get_binary_extension() const { return "zip"; }
virtual Error export_project(const String& p_path,bool p_debug,int p_flags=0); virtual Error export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags = 0);
virtual bool can_export(String *r_error=NULL) const; virtual bool can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const;
EditorExportPlatformOSX(); EditorExportPlatformOSX();
~EditorExportPlatformOSX(); ~EditorExportPlatformOSX();
}; };
bool EditorExportPlatformOSX::_set(const StringName& p_name, const Variant& p_value) { void EditorExportPlatformOSX::get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features) {
String n=p_name; // what does this need to do?
if (n=="custom_package/debug")
custom_debug_package=p_value;
else if (n=="custom_package/release")
custom_release_package=p_value;
else if (n=="application/name")
app_name=p_value;
else if (n=="application/info")
info=p_value;
else if (n=="application/icon")
icon=p_value;
else if (n=="application/identifier")
identifier=p_value;
else if (n=="application/signature")
signature=p_value;
else if (n=="application/short_version")
short_version=p_value;
else if (n=="application/version")
version=p_value;
else if (n=="application/copyright")
copyright=p_value;
else if (n=="application/bits_mode")
bits_mode=BitsMode(int(p_value));
else if (n=="display/high_res")
high_resolution=p_value;
else
return false;
return true;
} }
bool EditorExportPlatformOSX::_get(const StringName& p_name,Variant &r_ret) const{ void EditorExportPlatformOSX::get_export_options(List<ExportOption> *r_options) {
String n=p_name; 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"), ""));
if (n=="custom_package/debug")
r_ret=custom_debug_package;
else if (n=="custom_package/release")
r_ret=custom_release_package;
else if (n=="application/name")
r_ret=app_name;
else if (n=="application/info")
r_ret=info;
else if (n=="application/icon")
r_ret=icon;
else if (n=="application/identifier")
r_ret=identifier;
else if (n=="application/signature")
r_ret=signature;
else if (n=="application/short_version")
r_ret=short_version;
else if (n=="application/version")
r_ret=version;
else if (n=="application/copyright")
r_ret=copyright;
else if (n=="application/bits_mode")
r_ret=bits_mode;
else if (n=="display/high_res")
r_ret=high_resolution;
else
return false;
return true;
}
void EditorExportPlatformOSX::_get_property_list( List<PropertyInfo> *p_list) const{
p_list->push_back( PropertyInfo( Variant::STRING, "custom_package/debug", PROPERTY_HINT_GLOBAL_FILE,"zip"));
p_list->push_back( PropertyInfo( Variant::STRING, "custom_package/release", PROPERTY_HINT_GLOBAL_FILE,"zip"));
p_list->push_back( PropertyInfo( Variant::STRING, "application/name") );
p_list->push_back( PropertyInfo( Variant::STRING, "application/info") );
p_list->push_back( PropertyInfo( Variant::STRING, "application/icon",PROPERTY_HINT_FILE,"png") );
p_list->push_back( PropertyInfo( Variant::STRING, "application/identifier") );
p_list->push_back( PropertyInfo( Variant::STRING, "application/signature") );
p_list->push_back( PropertyInfo( Variant::STRING, "application/short_version") );
p_list->push_back( PropertyInfo( Variant::STRING, "application/version") );
p_list->push_back( PropertyInfo( Variant::STRING, "application/copyright") );
p_list->push_back( PropertyInfo( Variant::INT, "application/bits_mode", PROPERTY_HINT_ENUM, "Fat (32 & 64 bits),64 bits,32 bits") );
p_list->push_back( PropertyInfo( Variant::BOOL, "display/high_res") );
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/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"), "org.godotengine.macgame"));
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/signature"), "godotmacgame"));
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::INT, "application/bits_mode", PROPERTY_HINT_ENUM, "Fat (32 & 64 bits),64 bits,32 bits"), 0));
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "display/high_res"), false));
} }
void EditorExportPlatformOSX::_make_icon(const Image& p_icon,Vector<uint8_t>& icon) { void EditorExportPlatformOSX::_make_icon(const Ref<Image> &p_icon, Vector<uint8_t> &p_data) {
Ref<ImageTexture> it = memnew(ImageTexture); Ref<ImageTexture> it = memnew(ImageTexture);
int size = 512; int size = 512;
@ -207,9 +110,9 @@ void EditorExportPlatformOSX::_make_icon(const Image& p_icon,Vector<uint8_t>& ic
while (size >= 16) { while (size >= 16) {
Image copy = p_icon; 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?
copy.convert(Image::FORMAT_RGBA8); copy->convert(Image::FORMAT_RGBA8);
copy.resize(size,size); copy->resize(size, size);
it->create_from_image(copy); it->create_from_image(copy);
String path = EditorSettings::get_singleton()->get_settings_path() + "/tmp/icon.png"; String path = EditorSettings::get_singleton()->get_settings_path() + "/tmp/icon.png";
ResourceSaver::save(path, it); ResourceSaver::save(path, it);
@ -234,12 +137,10 @@ void EditorExportPlatformOSX::_make_icon(const Image& p_icon,Vector<uint8_t>& ic
total_len = BSWAP32(total_len); total_len = BSWAP32(total_len);
encode_uint32(total_len, &data[4]); encode_uint32(total_len, &data[4]);
icon=data; p_data = data;
} }
void EditorExportPlatformOSX::_fix_plist(const Ref<EditorExportPreset> &p_preset, Vector<uint8_t> &plist, const String &p_binary) {
void EditorExportPlatformOSX::_fix_plist(Vector<uint8_t>& plist,const String& p_binary) {
String str; String str;
String strnew; String strnew;
@ -251,19 +152,19 @@ void EditorExportPlatformOSX::_fix_plist(Vector<uint8_t>& plist,const String& p_
} else if (lines[i].find("$name") != -1) { } else if (lines[i].find("$name") != -1) {
strnew += lines[i].replace("$name", p_binary) + "\n"; strnew += lines[i].replace("$name", p_binary) + "\n";
} else if (lines[i].find("$info") != -1) { } else if (lines[i].find("$info") != -1) {
strnew+=lines[i].replace("$info",info)+"\n"; strnew += lines[i].replace("$info", p_preset->get("application/info")) + "\n";
} else if (lines[i].find("$identifier") != -1) { } else if (lines[i].find("$identifier") != -1) {
strnew+=lines[i].replace("$identifier",identifier)+"\n"; strnew += lines[i].replace("$identifier", p_preset->get("application/identifier")) + "\n";
} else if (lines[i].find("$short_version") != -1) { } else if (lines[i].find("$short_version") != -1) {
strnew+=lines[i].replace("$short_version",short_version)+"\n"; strnew += lines[i].replace("$short_version", p_preset->get("application/short_version")) + "\n";
} else if (lines[i].find("$version") != -1) { } else if (lines[i].find("$version") != -1) {
strnew+=lines[i].replace("$version",version)+"\n"; strnew += lines[i].replace("$version", p_preset->get("application/version")) + "\n";
} else if (lines[i].find("$signature") != -1) { } else if (lines[i].find("$signature") != -1) {
strnew+=lines[i].replace("$signature",signature)+"\n"; strnew += lines[i].replace("$signature", p_preset->get("application/signature")) + "\n";
} else if (lines[i].find("$copyright") != -1) { } else if (lines[i].find("$copyright") != -1) {
strnew+=lines[i].replace("$copyright",copyright)+"\n"; strnew += lines[i].replace("$copyright", p_preset->get("application/copyright")) + "\n";
} else if (lines[i].find("$highres") != -1) { } else if (lines[i].find("$highres") != -1) {
strnew+=lines[i].replace("$highres",high_resolution?"<true/>":"<false/>")+"\n"; strnew += lines[i].replace("$highres", p_preset->get("display/high_res") ? "<true/>" : "<false/>") + "\n";
} else { } else {
strnew += lines[i] + "\n"; strnew += lines[i] + "\n";
} }
@ -276,17 +177,16 @@ void EditorExportPlatformOSX::_fix_plist(Vector<uint8_t>& plist,const String& p_
} }
} }
Error EditorExportPlatformOSX::export_project(const String& p_path, bool p_debug, int p_flags) { Error EditorExportPlatformOSX::export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags) {
String src_pkg; String src_pkg;
EditorProgress ep("export", "Exporting for OSX", 104); EditorProgress ep("export", "Exporting for OSX", 104);
if (p_debug) if (p_debug)
src_pkg=custom_debug_package; src_pkg = p_preset->get("custom_package/debug");
else else
src_pkg=custom_release_package; src_pkg = p_preset->get("custom_package/release");
if (src_pkg == "") { if (src_pkg == "") {
String err; String err;
@ -297,7 +197,6 @@ Error EditorExportPlatformOSX::export_project(const String& p_path, bool p_debug
} }
} }
FileAccess *src_f = NULL; FileAccess *src_f = NULL;
zlib_filefunc_def io = zipio_create_io_from_file(&src_f); zlib_filefunc_def io = zipio_create_io_from_file(&src_f);
@ -319,18 +218,18 @@ Error EditorExportPlatformOSX::export_project(const String& p_path, bool p_debug
zipFile dpkg = zipOpen2(p_path.utf8().get_data(), APPEND_STATUS_CREATE, NULL, &io2); zipFile dpkg = zipOpen2(p_path.utf8().get_data(), APPEND_STATUS_CREATE, NULL, &io2);
String binary_to_use = "godot_osx_" + String(p_debug ? "debug" : "release") + "."; String binary_to_use = "godot_osx_" + String(p_debug ? "debug" : "release") + ".";
binary_to_use += String(bits_mode==BITS_FAT ? "fat" : bits_mode==BITS_64 ? "64" : "32"); int bits_mode = p_preset->get("application/bits_mode");
binary_to_use += String(bits_mode == 0 ? "fat" : bits_mode == 1 ? "64" : "32");
print_line("binary: " + binary_to_use); print_line("binary: " + binary_to_use);
String pkg_name; String pkg_name;
if (app_name!="") if (p_preset->get("application/name") != "")
pkg_name=app_name; pkg_name = p_preset->get("application/name"); // app_name
else if (String(GlobalConfig::get_singleton()->get("application/name")) != "") else if (String(GlobalConfig::get_singleton()->get("application/name")) != "")
pkg_name = String(GlobalConfig::get_singleton()->get("application/name")); pkg_name = String(GlobalConfig::get_singleton()->get("application/name"));
else else
pkg_name = "Unnamed"; pkg_name = "Unnamed";
bool found_binary = false; bool found_binary = false;
while (ret == UNZ_OK) { while (ret == UNZ_OK) {
@ -355,10 +254,9 @@ Error EditorExportPlatformOSX::export_project(const String& p_path, bool p_debug
file = file.replace_first("osx_template.app/", ""); file = file.replace_first("osx_template.app/", "");
if (file == "Contents/Info.plist") { if (file == "Contents/Info.plist") {
print_line("parse plist"); print_line("parse plist");
_fix_plist(data,pkg_name); _fix_plist(p_preset, data, pkg_name);
} }
if (file.begins_with("Contents/MacOS/godot_")) { if (file.begins_with("Contents/MacOS/godot_")) {
@ -372,12 +270,17 @@ Error EditorExportPlatformOSX::export_project(const String& p_path, bool p_debug
if (file == "Contents/Resources/icon.icns") { if (file == "Contents/Resources/icon.icns") {
//see if there is an icon //see if there is an icon
String iconpath = GlobalConfig::get_singleton()->get("application/icon"); String iconpath;
if (p_preset->get("application/icon") != "")
iconpath = p_preset->get("application/icon");
else
iconpath = GlobalConfig::get_singleton()->get("application/icon");
print_line("icon? " + iconpath); print_line("icon? " + iconpath);
if (iconpath != "") { if (iconpath != "") {
Image icon; Ref<Image> icon;
icon.load(iconpath); icon.instance();
if (!icon.empty()) { icon->load(iconpath);
if (!icon->empty()) {
print_line("loaded?"); print_line("loaded?");
_make_icon(icon, data); _make_icon(icon, data);
} }
@ -428,19 +331,15 @@ Error EditorExportPlatformOSX::export_project(const String& p_path, bool p_debug
return ERR_FILE_NOT_FOUND; return ERR_FILE_NOT_FOUND;
} }
ep.step("Making PKG", 1); ep.step("Making PKG", 1);
String pack_path = EditorSettings::get_singleton()->get_settings_path() + "/tmp/data.pck"; String pack_path = EditorSettings::get_singleton()->get_settings_path() + "/tmp/data.pck";
FileAccess *pfs = FileAccess::open(pack_path,FileAccess::WRITE); Error err = save_pack(p_preset, pack_path);
Error err = save_pack(pfs);
memdelete(pfs);
if (err) { if (err) {
zipClose(dpkg, NULL); zipClose(dpkg, NULL);
unzClose(pkg); unzClose(pkg);
return err; return err;
} }
{ {
@ -457,7 +356,6 @@ Error EditorExportPlatformOSX::export_project(const String& p_path, bool p_debug
Z_DEFLATED, Z_DEFLATED,
Z_DEFAULT_COMPRESSION); Z_DEFAULT_COMPRESSION);
FileAccess *pf = FileAccess::open(pack_path, FileAccess::READ); FileAccess *pf = FileAccess::open(pack_path, FileAccess::READ);
ERR_FAIL_COND_V(!pf, ERR_CANT_OPEN); ERR_FAIL_COND_V(!pf, ERR_CANT_OPEN);
const int BSIZE = 16384; const int BSIZE = 16384;
@ -469,11 +367,9 @@ Error EditorExportPlatformOSX::export_project(const String& p_path, bool p_debug
if (r <= 0) if (r <= 0)
break; break;
zipWriteInFileInZip(dpkg, buf, r); zipWriteInFileInZip(dpkg, buf, r);
} }
zipCloseFileInZip(dpkg); zipCloseFileInZip(dpkg);
memdelete(pf); memdelete(pf);
} }
zipClose(dpkg, NULL); zipClose(dpkg, NULL);
@ -482,66 +378,45 @@ Error EditorExportPlatformOSX::export_project(const String& p_path, bool p_debug
return OK; return OK;
} }
bool EditorExportPlatformOSX::can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const {
Error EditorExportPlatformOSX::run(int p_device, int p_flags) {
return OK;
}
EditorExportPlatformOSX::EditorExportPlatformOSX() {
Image img( _osx_logo );
logo = Ref<ImageTexture>( memnew( ImageTexture ));
logo->create_from_image(img);
info="Made with Godot Engine";
identifier="org.godotengine.macgame";
signature="godotmacgame";
short_version="1.0";
version="1.0";
bits_mode=BITS_FAT;
high_resolution=false;
}
bool EditorExportPlatformOSX::can_export(String *r_error) const {
bool valid = true; bool valid = true;
String err; String err;
if (!exists_export_template("osx.zip")) { if (!exists_export_template("osx.zip", &err)) {
valid = false; valid = false;
err+="No export templates found.\nDownload and install export templates.\n";
} }
if (custom_debug_package!="" && !FileAccess::exists(custom_debug_package)) { if (p_preset->get("custom_package/debug") != "" && !FileAccess::exists(p_preset->get("custom_package/debug"))) {
valid = false; valid = false;
err += "Custom debug package not found.\n"; err += "Custom debug package not found.\n";
} }
if (custom_release_package!="" && !FileAccess::exists(custom_release_package)) { if (p_preset->get("custom_package/release") != "" && !FileAccess::exists(p_preset->get("custom_package/release"))) {
valid = false; valid = false;
err += "Custom release package not found.\n"; err += "Custom release package not found.\n";
} }
if (r_error) if (!err.empty())
*r_error=err; r_error = err;
return valid; return valid;
} }
EditorExportPlatformOSX::EditorExportPlatformOSX() {
Ref<Image> img = memnew(Image(_osx_logo));
logo.instance();
logo->create_from_image(img);
}
EditorExportPlatformOSX::~EditorExportPlatformOSX() { EditorExportPlatformOSX::~EditorExportPlatformOSX() {
} }
#endif
void register_osx_exporter() { void register_osx_exporter() {
#if 0 Ref<EditorExportPlatformOSX> platform;
Ref<EditorExportPlatformOSX> exporter = Ref<EditorExportPlatformOSX>( memnew(EditorExportPlatformOSX) ); platform.instance();
EditorImportExport::get_singleton()->add_export_platform(exporter);
#endif EditorExport::get_singleton()->add_export_platform(platform);
} }