Skip to content

Commit

Permalink
Allow project export to be canceled
Browse files Browse the repository at this point in the history
  • Loading branch information
vnen committed May 18, 2019
1 parent ac58abf commit c121d88
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 48 deletions.
30 changes: 22 additions & 8 deletions editor/editor_export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,9 @@ Error EditorExportPlatform::_save_pack_file(void *p_userdata, const String &p_pa

pd->file_ofs.push_back(sd);

pd->ep->step(TTR("Storing File:") + " " + p_path, 2 + p_file * 100 / p_total, false);
if (pd->ep->step(TTR("Storing File:") + " " + p_path, 2 + p_file * 100 / p_total, false)) {
return ERR_SKIP;
}

return OK;
}
Expand All @@ -362,7 +364,9 @@ Error EditorExportPlatform::_save_zip_file(void *p_userdata, const String &p_pat
zipWriteInFileInZip(zip, p_data.ptr(), p_data.size());
zipCloseFileInZip(zip);

zd->ep->step(TTR("Storing File:") + " " + p_path, 2 + p_file * 100 / p_total, false);
if (zd->ep->step(TTR("Storing File:") + " " + p_path, 2 + p_file * 100 / p_total, false)) {
return ERR_SKIP;
}

return OK;
}
Expand Down Expand Up @@ -749,27 +753,37 @@ Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> &
this->resolve_platform_feature_priorities(p_preset, remap_features);
}

err = OK;

for (List<String>::Element *F = remaps.front(); F; F = F->next()) {

String remap = F->get();
if (remap == "path") {
String remapped_path = config->get_value("remap", remap);
Vector<uint8_t> array = FileAccess::get_file_as_array(remapped_path);
p_func(p_udata, remapped_path, array, idx, total);
err = p_func(p_udata, remapped_path, array, idx, total);
} else if (remap.begins_with("path.")) {
String feature = remap.get_slice(".", 1);

if (remap_features.has(feature)) {
String remapped_path = config->get_value("remap", remap);
Vector<uint8_t> array = FileAccess::get_file_as_array(remapped_path);
p_func(p_udata, remapped_path, array, idx, total);
err = p_func(p_udata, remapped_path, array, idx, total);
}
}
}

if (err != OK) {
return err;
}

//also save the .import file
Vector<uint8_t> array = FileAccess::get_file_as_array(path + ".import");
p_func(p_udata, path + ".import", array, idx, total);
err = p_func(p_udata, path + ".import", array, idx, total);

if (err != OK) {
return err;
}

} else {

Expand Down Expand Up @@ -884,7 +898,7 @@ Error EditorExportPlatform::_add_shared_object(void *p_userdata, const SharedObj

Error EditorExportPlatform::save_pack(const Ref<EditorExportPreset> &p_preset, const String &p_path, Vector<SharedObject> *p_so_files) {

EditorProgress ep("savepack", TTR("Packing"), 102);
EditorProgress ep("savepack", TTR("Packing"), 102, true);

String tmppath = EditorSettings::get_singleton()->get_cache_dir().plus_file("packtmp");
FileAccess *ftmp = FileAccess::open(tmppath, FileAccess::WRITE);
Expand Down Expand Up @@ -982,7 +996,7 @@ Error EditorExportPlatform::save_pack(const Ref<EditorExportPreset> &p_preset, c

Error EditorExportPlatform::save_zip(const Ref<EditorExportPreset> &p_preset, const String &p_path) {

EditorProgress ep("savezip", TTR("Packing"), 102);
EditorProgress ep("savezip", TTR("Packing"), 102, true);

//FileAccess *tmp = FileAccess::open(tmppath,FileAccess::WRITE);

Expand All @@ -995,7 +1009,7 @@ Error EditorExportPlatform::save_zip(const Ref<EditorExportPreset> &p_preset, co
zd.zip = zip;

Error err = export_project_files(p_preset, _save_zip_file, &zd);
if (err != OK)
if (err != OK && err != ERR_SKIP)
ERR_PRINT("Failed to export project files");

zipClose(zip, NULL);
Expand Down
6 changes: 3 additions & 3 deletions editor/project_export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -972,7 +972,7 @@ void ProjectExportDialog::_export_project_to_path(const String &p_path) {
current->set_export_path(p_path);

Error err = platform->export_project(current, export_debug->is_pressed(), p_path, 0);
if (err != OK) {
if (err != OK && err != ERR_SKIP) {
if (err == ERR_FILE_NOT_FOUND) {
error_dialog->set_text(vformat(TTR("Failed to export the project for platform '%s'.\nExport templates seem to be missing or invalid."), platform->get_name()));
} else { // Assume misconfiguration. FIXME: Improve error handling and preset config validation.
Expand Down Expand Up @@ -1001,7 +1001,7 @@ void ProjectExportDialog::_export_all_dialog_action(const String &p_str) {
void ProjectExportDialog::_export_all(bool p_debug) {

String mode = p_debug ? TTR("Debug") : TTR("Release");
EditorProgress ep("exportall", TTR("Exporting All") + " " + mode, EditorExport::get_singleton()->get_export_preset_count());
EditorProgress ep("exportall", TTR("Exporting All") + " " + mode, EditorExport::get_singleton()->get_export_preset_count(), true);

for (int i = 0; i < EditorExport::get_singleton()->get_export_preset_count(); i++) {
Ref<EditorExportPreset> preset = EditorExport::get_singleton()->get_export_preset(i);
Expand All @@ -1012,7 +1012,7 @@ void ProjectExportDialog::_export_all(bool p_debug) {
ep.step(preset->get_name(), i);

Error err = platform->export_project(preset, p_debug, preset->get_export_path(), 0);
if (err != OK) {
if (err != OK && err != ERR_SKIP) {
if (err == ERR_FILE_BAD_PATH) {
error_dialog->set_text(TTR("The given export path doesn't exist:") + "\n" + preset->get_export_path().get_base_dir());
} else {
Expand Down
46 changes: 34 additions & 12 deletions platform/android/export/export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,9 @@ class EditorExportPlatformAndroid : public EditorExportPlatform {
String dst_path = p_path.replace_first("res://", "assets/");

store_in_apk(ed, dst_path, p_data, _should_compress_asset(p_path, p_data) ? Z_DEFLATED : 0);
ed->ep->step("File: " + p_path, 3 + p_file * 100 / p_total);
if (ed->ep->step("File: " + p_path, 3 + p_file * 100 / p_total)) {
return ERR_SKIP;
}
return OK;
}

Expand Down Expand Up @@ -1255,7 +1257,9 @@ class EditorExportPlatformAndroid : public EditorExportPlatform {
}

//export_temp
ep.step("Exporting APK", 0);
if (ep.step("Exporting APK", 0)) {
return ERR_SKIP;
}

const bool use_remote = (p_debug_flags & DEBUG_FLAG_REMOTE_DEBUG) || (p_debug_flags & DEBUG_FLAG_DUMB_CLIENT);
const bool use_reverse = devices[p_device].api_level >= 21;
Expand All @@ -1278,7 +1282,9 @@ class EditorExportPlatformAndroid : public EditorExportPlatform {
String package_name = p_preset->get("package/unique_name");

if (remove_prev) {
ep.step("Uninstalling...", 1);
if (ep.step("Uninstalling...", 1)) {
return ERR_SKIP;
}

print_line("Uninstalling previous version: " + devices[p_device].name);

Expand All @@ -1291,7 +1297,9 @@ class EditorExportPlatformAndroid : public EditorExportPlatform {
}

print_line("Installing to device (please wait...): " + devices[p_device].name);
ep.step("Installing to device (please wait...)", 2);
if (ep.step("Installing to device (please wait...)", 2)) {
return ERR_SKIP;
}

args.clear();
args.push_back("-s");
Expand Down Expand Up @@ -1357,7 +1365,9 @@ class EditorExportPlatformAndroid : public EditorExportPlatform {
}
}

ep.step("Running on Device...", 3);
if (ep.step("Running on Device...", 3)) {
return ERR_SKIP;
}
args.clear();
args.push_back("-s");
args.push_back(devices[p_device].id);
Expand Down Expand Up @@ -1763,7 +1773,7 @@ class EditorExportPlatformAndroid : public EditorExportPlatform {

String src_apk;

EditorProgress ep("export", "Exporting for Android", 105);
EditorProgress ep("export", "Exporting for Android", 105, true);

if (bool(p_preset->get("custom_package/use_custom_build"))) { //custom build
//re-generate build.gradle and AndroidManifest.xml
Expand Down Expand Up @@ -1855,7 +1865,9 @@ class EditorExportPlatformAndroid : public EditorExportPlatform {
FileAccess *src_f = NULL;
zlib_filefunc_def io = zipio_create_io_from_file(&src_f);

ep.step("Creating APK", 0);
if (ep.step("Creating APK", 0)) {
return ERR_SKIP;
}

unzFile pkg = unzOpen2(src_apk.utf8().get_data(), &io);
if (!pkg) {
Expand Down Expand Up @@ -1997,7 +2009,9 @@ class EditorExportPlatformAndroid : public EditorExportPlatform {
ret = unzGoToNextFile(pkg);
}

ep.step("Adding Files...", 1);
if (ep.step("Adding Files...", 1)) {
return ERR_SKIP;
}
Error err = OK;
Vector<String> cl = cmdline.strip_edges().split(" ");
for (int i = 0; i < cl.size(); i++) {
Expand Down Expand Up @@ -2135,14 +2149,18 @@ class EditorExportPlatformAndroid : public EditorExportPlatform {
user = EditorSettings::get_singleton()->get("export/android/debug_keystore_user");
}

ep.step("Signing debug APK...", 103);
if (ep.step("Signing debug APK...", 103)) {
return ERR_SKIP;
}

} else {
keystore = release_keystore;
password = release_password;
user = release_username;

ep.step("Signing release APK...", 103);
if (ep.step("Signing release APK...", 103)) {
return ERR_SKIP;
}
}

if (!FileAccess::exists(keystore)) {
Expand Down Expand Up @@ -2174,7 +2192,9 @@ class EditorExportPlatformAndroid : public EditorExportPlatform {
return ERR_CANT_CREATE;
}

ep.step("Verifying APK...", 104);
if (ep.step("Verifying APK...", 104)) {
return ERR_SKIP;
}

args.clear();
args.push_back("-verify");
Expand All @@ -2194,7 +2214,9 @@ class EditorExportPlatformAndroid : public EditorExportPlatform {

static const int ZIP_ALIGNMENT = 4;

ep.step("Aligning APK...", 105);
if (ep.step("Aligning APK...", 105)) {
return ERR_SKIP;
}

unzFile tmp_unaligned = unzOpen2(unaligned_path.utf8().get_data(), &io);
if (!tmp_unaligned) {
Expand Down
22 changes: 16 additions & 6 deletions platform/iphone/export/export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ Error EditorExportPlatformIOS::export_project(const Ref<EditorExportPreset> &p_p
String dest_dir = p_path.get_base_dir() + "/";
String binary_name = p_path.get_file().get_basename();

EditorProgress ep("export", "Exporting for iOS", 5);
EditorProgress ep("export", "Exporting for iOS", 5, true);

String team_id = p_preset->get("application/app_store_team_id");
ERR_EXPLAIN("App Store Team ID not specified - cannot configure the project.");
Expand Down Expand Up @@ -868,14 +868,18 @@ Error EditorExportPlatformIOS::export_project(const Ref<EditorExportPreset> &p_p
memdelete(da);
}

ep.step("Making .pck", 0);
if (ep.step("Making .pck", 0)) {
return ERR_SKIP;
}
String pack_path = dest_dir + binary_name + ".pck";
Vector<SharedObject> libraries;
Error err = save_pack(p_preset, pack_path, &libraries);
if (err)
return err;

ep.step("Extracting and configuring Xcode project", 1);
if (ep.step("Extracting and configuring Xcode project", 1)) {
return ERR_SKIP;
}

String library_to_use = "libgodot.iphone." + String(p_debug ? "debug" : "release") + ".fat.a";

Expand Down Expand Up @@ -1053,15 +1057,19 @@ Error EditorExportPlatformIOS::export_project(const Ref<EditorExportPreset> &p_p
memdelete(f);

#ifdef OSX_ENABLED
ep.step("Code-signing dylibs", 2);
if (ep.step("Code-signing dylibs", 2)) {
return ERR_SKIP;
}
DirAccess *dylibs_dir = DirAccess::open(dest_dir + binary_name + "/dylibs");
ERR_FAIL_COND_V(!dylibs_dir, ERR_CANT_OPEN);
CodesignData codesign_data(p_preset, p_debug);
err = _walk_dir_recursive(dylibs_dir, _codesign, &codesign_data);
memdelete(dylibs_dir);
ERR_FAIL_COND_V(err, err);

ep.step("Making .xcarchive", 3);
if (ep.step("Making .xcarchive", 3)) {
return ERR_SKIP;
}
String archive_path = p_path.get_basename() + ".xcarchive";
List<String> archive_args;
archive_args.push_back("-project");
Expand All @@ -1080,7 +1088,9 @@ Error EditorExportPlatformIOS::export_project(const Ref<EditorExportPreset> &p_p
err = OS::get_singleton()->execute("xcodebuild", archive_args, true);
ERR_FAIL_COND_V(err, err);

ep.step("Making .ipa", 4);
if (ep.step("Making .ipa", 4)) {
return ERR_SKIP;
}
List<String> export_args;
export_args.push_back("-exportArchive");
export_args.push_back("-archivePath");
Expand Down
18 changes: 13 additions & 5 deletions platform/osx/export/export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ Error EditorExportPlatformOSX::export_project(const Ref<EditorExportPreset> &p_p

String src_pkg_name;

EditorProgress ep("export", "Exporting for OSX", 3);
EditorProgress ep("export", "Exporting for OSX", 3, true);

if (p_debug)
src_pkg_name = p_preset->get("custom_package/debug");
Expand All @@ -432,7 +432,9 @@ Error EditorExportPlatformOSX::export_project(const Ref<EditorExportPreset> &p_p
FileAccess *src_f = NULL;
zlib_filefunc_def io = zipio_create_io_from_file(&src_f);

ep.step("Creating app", 0);
if (ep.step("Creating app", 0)) {
return ERR_SKIP;
}

unzFile src_pkg_zip = unzOpen2(src_pkg_name.utf8().get_data(), &io);
if (!src_pkg_zip) {
Expand Down Expand Up @@ -626,7 +628,9 @@ Error EditorExportPlatformOSX::export_project(const Ref<EditorExportPreset> &p_p
}

if (err == OK) {
ep.step("Making PKG", 1);
if (ep.step("Making PKG", 1)) {
return ERR_SKIP;
}

if (export_format == "dmg") {
String pack_path = tmp_app_path_name + "/Contents/Resources/" + pkg_name + ".pck";
Expand All @@ -648,7 +652,9 @@ Error EditorExportPlatformOSX::export_project(const Ref<EditorExportPreset> &p_p
}

if (err == OK && identity != "") {
ep.step("Code signing bundle", 2);
if (ep.step("Code signing bundle", 2)) {
return ERR_SKIP;
}

// 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

Expand All @@ -673,7 +679,9 @@ Error EditorExportPlatformOSX::export_project(const Ref<EditorExportPreset> &p_p

// and finally create a DMG
if (err == OK) {
ep.step("Making DMG", 3);
if (ep.step("Making DMG", 3)) {
return ERR_SKIP;
}
err = _create_dmg(p_path, pkg_name, tmp_app_path_name);
}

Expand Down
Loading

0 comments on commit c121d88

Please sign in to comment.