Add readable export errors.
This commit is contained in:
@@ -43,7 +43,10 @@ Error EditorExportPlatformWindows::sign_shared_object(const Ref<EditorExportPres
|
||||
|
||||
Error EditorExportPlatformWindows::_export_debug_script(const Ref<EditorExportPreset> &p_preset, const String &p_app_name, const String &p_pkg_name, const String &p_path) {
|
||||
Ref<FileAccess> f = FileAccess::open(p_path, FileAccess::WRITE);
|
||||
ERR_FAIL_COND_V(f.is_null(), ERR_CANT_CREATE);
|
||||
if (f.is_null()) {
|
||||
add_message(EXPORT_MESSAGE_ERROR, TTR("Debug Script Export"), vformat(TTR("Could not open file \"%s\"."), p_path));
|
||||
return ERR_CANT_CREATE;
|
||||
}
|
||||
|
||||
f->store_line("@echo off");
|
||||
f->store_line("title \"" + p_app_name + "\"");
|
||||
@@ -55,10 +58,9 @@ Error EditorExportPlatformWindows::_export_debug_script(const Ref<EditorExportPr
|
||||
|
||||
Error EditorExportPlatformWindows::modify_template(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags) {
|
||||
if (p_preset->get("application/modify_resources")) {
|
||||
return _rcedit_add_data(p_preset, p_path);
|
||||
} else {
|
||||
return OK;
|
||||
_rcedit_add_data(p_preset, p_path);
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
Error EditorExportPlatformWindows::export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags) {
|
||||
@@ -68,12 +70,15 @@ Error EditorExportPlatformWindows::export_project(const Ref<EditorExportPreset>
|
||||
}
|
||||
Error err = EditorExportPlatformPC::export_project(p_preset, p_debug, pck_path, p_flags);
|
||||
if (p_preset->get("codesign/enable") && err == OK) {
|
||||
err = _code_sign(p_preset, pck_path);
|
||||
_code_sign(p_preset, pck_path);
|
||||
}
|
||||
|
||||
if (p_preset->get("binary_format/embed_pck") && err == OK) {
|
||||
Ref<DirAccess> tmp_dir = DirAccess::create_for_path(p_path.get_base_dir());
|
||||
err = tmp_dir->rename(pck_path, p_path);
|
||||
if (err != OK) {
|
||||
add_message(EXPORT_MESSAGE_ERROR, TTR("PCK Embedding"), vformat(TTR("Failed to rename temporary file \"%s\"."), pck_path));
|
||||
}
|
||||
}
|
||||
|
||||
String app_name;
|
||||
@@ -89,7 +94,9 @@ Error EditorExportPlatformWindows::export_project(const Ref<EditorExportPreset>
|
||||
int con_scr = p_preset->get("debug/export_console_script");
|
||||
if ((con_scr == 1 && p_debug) || (con_scr == 2)) {
|
||||
String scr_path = p_path.get_basename() + ".cmd";
|
||||
err = _export_debug_script(p_preset, app_name, p_path.get_file(), scr_path);
|
||||
if (_export_debug_script(p_preset, app_name, p_path.get_file(), scr_path) != OK) {
|
||||
add_message(EXPORT_MESSAGE_ERROR, TTR("Debug Script Export"), TTR("Could not create console script."));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,7 +149,7 @@ Error EditorExportPlatformWindows::_rcedit_add_data(const Ref<EditorExportPreset
|
||||
String rcedit_path = EditorSettings::get_singleton()->get("export/windows/rcedit");
|
||||
|
||||
if (rcedit_path != String() && !FileAccess::exists(rcedit_path)) {
|
||||
ERR_PRINT("Could not find rcedit executable at " + rcedit_path + ", aborting.");
|
||||
add_message(EXPORT_MESSAGE_WARNING, TTR("Resources Modification"), vformat(TTR("Could not find rcedit executable at \"%s\"."), rcedit_path));
|
||||
return ERR_FILE_NOT_FOUND;
|
||||
}
|
||||
|
||||
@@ -155,7 +162,7 @@ Error EditorExportPlatformWindows::_rcedit_add_data(const Ref<EditorExportPreset
|
||||
String wine_path = EditorSettings::get_singleton()->get("export/windows/wine");
|
||||
|
||||
if (!wine_path.is_empty() && !FileAccess::exists(wine_path)) {
|
||||
ERR_PRINT("Could not find wine executable at " + wine_path + ", aborting.");
|
||||
add_message(EXPORT_MESSAGE_WARNING, TTR("Resources Modification"), vformat(TTR("Could not find wine executable at \"%s\"."), wine_path));
|
||||
return ERR_FILE_NOT_FOUND;
|
||||
}
|
||||
|
||||
@@ -222,10 +229,14 @@ Error EditorExportPlatformWindows::_rcedit_add_data(const Ref<EditorExportPreset
|
||||
|
||||
String str;
|
||||
Error err = OS::get_singleton()->execute(rcedit_path, args, &str, nullptr, true);
|
||||
ERR_FAIL_COND_V_MSG(err != OK, err, "Could not start rcedit executable, configure rcedit path in the Editor Settings (Export > Windows > Rcedit).");
|
||||
if (err != OK || (str.find("not found") != -1) || (str.find("not recognized") != -1)) {
|
||||
add_message(EXPORT_MESSAGE_WARNING, TTR("Resources Modification"), TTR("Could not start rcedit executable, configure rcedit path in the Editor Settings (Export > Windows > Rcedit)."));
|
||||
return err;
|
||||
}
|
||||
print_line("rcedit (" + p_path + "): " + str);
|
||||
|
||||
if (str.find("Fatal error") != -1) {
|
||||
add_message(EXPORT_MESSAGE_WARNING, TTR("Resources Modification"), vformat(TTR("rcedit failed to modify executable:\n%s"), str));
|
||||
return FAILED;
|
||||
}
|
||||
|
||||
@@ -238,7 +249,7 @@ Error EditorExportPlatformWindows::_code_sign(const Ref<EditorExportPreset> &p_p
|
||||
#ifdef WINDOWS_ENABLED
|
||||
String signtool_path = EditorSettings::get_singleton()->get("export/windows/signtool");
|
||||
if (!signtool_path.is_empty() && !FileAccess::exists(signtool_path)) {
|
||||
ERR_PRINT("Could not find signtool executable at " + signtool_path + ", aborting.");
|
||||
add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), vformat(TTR("Could not find signtool executable at \"%s\"."), signtool_path));
|
||||
return ERR_FILE_NOT_FOUND;
|
||||
}
|
||||
if (signtool_path.is_empty()) {
|
||||
@@ -247,7 +258,7 @@ Error EditorExportPlatformWindows::_code_sign(const Ref<EditorExportPreset> &p_p
|
||||
#else
|
||||
String signtool_path = EditorSettings::get_singleton()->get("export/windows/osslsigncode");
|
||||
if (!signtool_path.is_empty() && !FileAccess::exists(signtool_path)) {
|
||||
ERR_PRINT("Could not find osslsigncode executable at " + signtool_path + ", aborting.");
|
||||
add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), vformat(TTR("Could not find osslsigncode executable at \"%s\"."), signtool_path));
|
||||
return ERR_FILE_NOT_FOUND;
|
||||
}
|
||||
if (signtool_path.is_empty()) {
|
||||
@@ -267,7 +278,7 @@ Error EditorExportPlatformWindows::_code_sign(const Ref<EditorExportPreset> &p_p
|
||||
args.push_back("/f");
|
||||
args.push_back(p_preset->get("codesign/identity"));
|
||||
} else {
|
||||
EditorNode::add_io_error("codesign: no identity found");
|
||||
add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), TTR("No identity found."));
|
||||
return FAILED;
|
||||
}
|
||||
} else if (id_type == 2) { //Windows certificate store
|
||||
@@ -275,11 +286,11 @@ Error EditorExportPlatformWindows::_code_sign(const Ref<EditorExportPreset> &p_p
|
||||
args.push_back("/sha1");
|
||||
args.push_back(p_preset->get("codesign/identity"));
|
||||
} else {
|
||||
EditorNode::add_io_error("codesign: no identity found");
|
||||
add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), TTR("No identity found."));
|
||||
return FAILED;
|
||||
}
|
||||
} else {
|
||||
EditorNode::add_io_error("codesign: invalid identity type");
|
||||
add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), TTR("Invalid identity type."));
|
||||
return FAILED;
|
||||
}
|
||||
#else
|
||||
@@ -287,7 +298,7 @@ Error EditorExportPlatformWindows::_code_sign(const Ref<EditorExportPreset> &p_p
|
||||
args.push_back("-pkcs12");
|
||||
args.push_back(p_preset->get("codesign/identity"));
|
||||
} else {
|
||||
EditorNode::add_io_error("codesign: no identity found");
|
||||
add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), TTR("No identity found."));
|
||||
return FAILED;
|
||||
}
|
||||
#endif
|
||||
@@ -319,7 +330,7 @@ Error EditorExportPlatformWindows::_code_sign(const Ref<EditorExportPreset> &p_p
|
||||
args.push_back(p_preset->get("codesign/timestamp_server_url"));
|
||||
#endif
|
||||
} else {
|
||||
EditorNode::add_io_error("codesign: invalid timestamp server");
|
||||
add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), TTR("Invalid timestamp server."));
|
||||
return FAILED;
|
||||
}
|
||||
}
|
||||
@@ -366,7 +377,10 @@ Error EditorExportPlatformWindows::_code_sign(const Ref<EditorExportPreset> &p_p
|
||||
|
||||
String str;
|
||||
Error err = OS::get_singleton()->execute(signtool_path, args, &str, nullptr, true);
|
||||
ERR_FAIL_COND_V_MSG(err != OK, err, "Could not start signtool executable, configure signtool path in the Editor Settings (Export > Windows > Signtool).");
|
||||
if (err != OK || (str.find("not found") != -1) || (str.find("not recognized") != -1)) {
|
||||
add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), TTR("Could not start signtool executable, configure signtool path in the Editor Settings (Export > Windows > Signtool)."));
|
||||
return err;
|
||||
}
|
||||
|
||||
print_line("codesign (" + p_path + "): " + str);
|
||||
#ifndef WINDOWS_ENABLED
|
||||
@@ -374,6 +388,7 @@ Error EditorExportPlatformWindows::_code_sign(const Ref<EditorExportPreset> &p_p
|
||||
#else
|
||||
if (str.find("Failed") != -1) {
|
||||
#endif
|
||||
add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), vformat(TTR("Signtool failed to sign executable:\n%s"), str));
|
||||
return FAILED;
|
||||
}
|
||||
|
||||
@@ -381,10 +396,16 @@ Error EditorExportPlatformWindows::_code_sign(const Ref<EditorExportPreset> &p_p
|
||||
Ref<DirAccess> tmp_dir = DirAccess::create_for_path(p_path.get_base_dir());
|
||||
|
||||
err = tmp_dir->remove(p_path);
|
||||
ERR_FAIL_COND_V(err != OK, err);
|
||||
if (err != OK) {
|
||||
add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), vformat(TTR("Failed to remove temporary file \"%s\"."), p_path));
|
||||
return err;
|
||||
}
|
||||
|
||||
err = tmp_dir->rename(p_path + "_signed", p_path);
|
||||
ERR_FAIL_COND_V(err != OK, err);
|
||||
if (err != OK) {
|
||||
add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), vformat(TTR("Failed to rename temporary file \"%s\"."), p_path + "_signed"));
|
||||
return err;
|
||||
}
|
||||
#endif
|
||||
|
||||
return OK;
|
||||
@@ -433,15 +454,17 @@ bool EditorExportPlatformWindows::can_export(const Ref<EditorExportPreset> &p_pr
|
||||
return valid;
|
||||
}
|
||||
|
||||
Error EditorExportPlatformWindows::fixup_embedded_pck(const String &p_path, int64_t p_embedded_start, int64_t p_embedded_size) const {
|
||||
Error EditorExportPlatformWindows::fixup_embedded_pck(const String &p_path, int64_t p_embedded_start, int64_t p_embedded_size) {
|
||||
// Patch the header of the "pck" section in the PE file so that it corresponds to the embedded data
|
||||
|
||||
if (p_embedded_size + p_embedded_start >= 0x100000000) { // Check for total executable size
|
||||
ERR_FAIL_V_MSG(ERR_INVALID_DATA, "Windows executables cannot be >= 4 GiB.");
|
||||
add_message(EXPORT_MESSAGE_ERROR, TTR("PCK Embedding"), TTR("Windows executables cannot be >= 4 GiB."));
|
||||
return ERR_INVALID_DATA;
|
||||
}
|
||||
|
||||
Ref<FileAccess> f = FileAccess::open(p_path, FileAccess::READ_WRITE);
|
||||
if (f.is_null()) {
|
||||
add_message(EXPORT_MESSAGE_ERROR, TTR("PCK Embedding"), vformat(TTR("Failed to open executable file \"%s\"."), p_path));
|
||||
return ERR_CANT_OPEN;
|
||||
}
|
||||
|
||||
@@ -453,6 +476,7 @@ Error EditorExportPlatformWindows::fixup_embedded_pck(const String &p_path, int6
|
||||
f->seek(pe_pos);
|
||||
uint32_t magic = f->get_32();
|
||||
if (magic != 0x00004550) {
|
||||
add_message(EXPORT_MESSAGE_ERROR, TTR("PCK Embedding"), TTR("Executable file header corrupted."));
|
||||
return ERR_FILE_CORRUPT;
|
||||
}
|
||||
}
|
||||
@@ -502,5 +526,9 @@ Error EditorExportPlatformWindows::fixup_embedded_pck(const String &p_path, int6
|
||||
}
|
||||
}
|
||||
|
||||
return found ? OK : ERR_FILE_CORRUPT;
|
||||
if (!found) {
|
||||
add_message(EXPORT_MESSAGE_ERROR, TTR("PCK Embedding"), TTR("Executable \"pck\" section not found."));
|
||||
return ERR_FILE_CORRUPT;
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user