Merge pull request #24483 from vnen/cancel-export

Allow project export to be canceled
This commit is contained in:
Max Hilbrunner 2019-05-18 23:19:14 +02:00 committed by GitHub
commit 6bfb9ed054
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 120 additions and 48 deletions

View File

@ -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;
}
@ -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;
}
@ -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 {
@ -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);
@ -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);
@ -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);

View File

@ -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.
@ -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);
@ -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 {

View File

@ -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;
}
@ -1255,7 +1257,9 @@ public:
}
//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;
@ -1278,7 +1282,9 @@ public:
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);
@ -1291,7 +1297,9 @@ public:
}
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");
@ -1357,7 +1365,9 @@ public:
}
}
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);
@ -1763,7 +1773,7 @@ public:
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
@ -1855,7 +1865,9 @@ public:
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) {
@ -1997,7 +2009,9 @@ public:
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++) {
@ -2135,14 +2149,18 @@ public:
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)) {
@ -2174,7 +2192,9 @@ public:
return ERR_CANT_CREATE;
}
ep.step("Verifying APK...", 104);
if (ep.step("Verifying APK...", 104)) {
return ERR_SKIP;
}
args.clear();
args.push_back("-verify");
@ -2194,7 +2214,9 @@ public:
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) {

View File

@ -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.");
@ -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";
@ -1053,7 +1057,9 @@ 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);
@ -1061,7 +1067,9 @@ Error EditorExportPlatformIOS::export_project(const Ref<EditorExportPreset> &p_p
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");
@ -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");

View File

@ -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");
@ -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) {
@ -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";
@ -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
@ -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);
}

View File

@ -187,7 +187,7 @@ class AppxPackager {
public:
void set_progress_task(String p_task) { progress_task = p_task; }
void init(FileAccess *p_fa);
void add_file(String p_file_name, const uint8_t *p_buffer, size_t p_len, int p_file_no, int p_total_files, bool p_compress = false);
Error add_file(String p_file_name, const uint8_t *p_buffer, size_t p_len, int p_file_no, int p_total_files, bool p_compress = false);
void finish();
AppxPackager();
@ -468,10 +468,12 @@ void AppxPackager::init(FileAccess *p_fa) {
tmp_content_types_file_path = EditorSettings::get_singleton()->get_cache_dir().plus_file("tmpcontenttypes.xml");
}
void AppxPackager::add_file(String p_file_name, const uint8_t *p_buffer, size_t p_len, int p_file_no, int p_total_files, bool p_compress) {
Error AppxPackager::add_file(String p_file_name, const uint8_t *p_buffer, size_t p_len, int p_file_no, int p_total_files, bool p_compress) {
if (p_file_no >= 1 && p_total_files >= 1) {
EditorNode::progress_task_step(progress_task, "File: " + p_file_name, (p_file_no * 100) / p_total_files);
if (EditorNode::progress_task_step(progress_task, "File: " + p_file_name, (p_file_no * 100) / p_total_files)) {
return ERR_SKIP;
}
}
FileMeta meta;
@ -584,6 +586,8 @@ void AppxPackager::add_file(String p_file_name, const uint8_t *p_buffer, size_t
package->store_buffer(file_buffer.ptr(), file_buffer.size());
file_metadata.push_back(meta);
return OK;
}
void AppxPackager::finish() {
@ -1008,9 +1012,7 @@ class EditorExportPlatformUWP : public EditorExportPlatform {
AppxPackager *packager = (AppxPackager *)p_userdata;
String dst_path = p_path.replace_first("res://", "game/");
packager->add_file(dst_path, p_data.ptr(), p_data.size(), p_file, p_total, _should_compress_asset(p_path, p_data));
return OK;
return packager->add_file(dst_path, p_data.ptr(), p_data.size(), p_file, p_total, _should_compress_asset(p_path, p_data));
}
public:
@ -1230,7 +1232,7 @@ public:
String src_appx;
EditorProgress ep("export", "Exporting for Windows Universal", 7);
EditorProgress ep("export", "Exporting for Windows Universal", 7, true);
if (p_debug)
src_appx = p_preset->get("custom_template/debug");
@ -1280,7 +1282,9 @@ public:
FileAccess *src_f = NULL;
zlib_filefunc_def io = zipio_create_io_from_file(&src_f);
ep.step("Creating package...", 0);
if (ep.step("Creating package...", 0)) {
return ERR_SKIP;
}
unzFile pkg = unzOpen2(src_appx.utf8().get_data(), &io);
@ -1292,7 +1296,9 @@ public:
int ret = unzGoToFirstFile(pkg);
ep.step("Copying template files...", 1);
if (ep.step("Copying template files...", 1)) {
return ERR_SKIP;
}
EditorNode::progress_add_task("template_files", "Template files", 100);
packager.set_progress_task("template_files");
@ -1341,14 +1347,19 @@ public:
print_line("ADDING: " + path);
packager.add_file(path, data.ptr(), data.size(), template_file_no++, template_files_amount, _should_compress_asset(path, data));
err = packager.add_file(path, data.ptr(), data.size(), template_file_no++, template_files_amount, _should_compress_asset(path, data));
if (err != OK) {
return err;
}
ret = unzGoToNextFile(pkg);
}
EditorNode::progress_end_task("template_files");
ep.step("Creating command line...", 2);
if (ep.step("Creating command line...", 2)) {
return ERR_SKIP;
}
Vector<String> cl = ((String)p_preset->get("command_line/extra_args")).strip_edges().split(" ");
for (int i = 0; i < cl.size(); i++) {
@ -1382,9 +1393,14 @@ public:
print_line(itos(i) + " param: " + cl[i]);
}
packager.add_file("__cl__.cl", clf.ptr(), clf.size(), -1, -1, false);
err = packager.add_file("__cl__.cl", clf.ptr(), clf.size(), -1, -1, false);
if (err != OK) {
return err;
}
ep.step("Adding project files...", 3);
if (ep.step("Adding project files...", 3)) {
return ERR_SKIP;
}
EditorNode::progress_add_task("project_files", "Project Files", 100);
packager.set_progress_task("project_files");
@ -1393,7 +1409,9 @@ public:
EditorNode::progress_end_task("project_files");
ep.step("Closing package...", 7);
if (ep.step("Closing package...", 7)) {
return ERR_SKIP;
}
unzClose(pkg);