Skip to content

Commit

Permalink
Add warning for Windows export when rcedit is not configured
Browse files Browse the repository at this point in the history
  • Loading branch information
NeilKleistGao authored and akien-mga committed Feb 11, 2022
1 parent 49059e3 commit ef0ec3f
Showing 1 changed file with 48 additions and 3 deletions.
51 changes: 48 additions & 3 deletions platform/windows/export/export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class EditorExportPlatformWindows : public EditorExportPlatformPC {
virtual Error sign_shared_object(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path);
virtual void get_export_options(List<ExportOption> *r_options);
virtual bool get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const;
virtual bool can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const;
};

Error EditorExportPlatformWindows::sign_shared_object(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path) {
Expand Down Expand Up @@ -96,8 +97,8 @@ void EditorExportPlatformWindows::get_export_options(List<ExportOption> *r_optio
r_options->push_back(ExportOption(PropertyInfo(Variant::POOL_STRING_ARRAY, "codesign/custom_options"), PoolStringArray()));

r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/icon", PROPERTY_HINT_FILE, "*.ico"), ""));
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/file_version", PROPERTY_HINT_PLACEHOLDER_TEXT, "1.0.0"), ""));
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/product_version", PROPERTY_HINT_PLACEHOLDER_TEXT, "1.0.0"), ""));
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/file_version", PROPERTY_HINT_PLACEHOLDER_TEXT, "1.0.0.0"), ""));
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/product_version", PROPERTY_HINT_PLACEHOLDER_TEXT, "1.0.0.0"), ""));
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/company_name", PROPERTY_HINT_PLACEHOLDER_TEXT, "Company Name"), ""));
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/product_name", PROPERTY_HINT_PLACEHOLDER_TEXT, "Game Name"), ""));
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/file_description"), ""));
Expand All @@ -108,7 +109,8 @@ void EditorExportPlatformWindows::get_export_options(List<ExportOption> *r_optio
void EditorExportPlatformWindows::_rcedit_add_data(const Ref<EditorExportPreset> &p_preset, const String &p_path) {
String rcedit_path = EditorSettings::get_singleton()->get("export/windows/rcedit");

if (rcedit_path == String()) {
if (rcedit_path.empty()) {
WARN_PRINT("The rcedit tool is not configured in the Editor Settings (Export > Windows > Rcedit). No custom icon or app information data will be embedded in the exported executable.");
return;
}

Expand Down Expand Up @@ -348,6 +350,49 @@ Error EditorExportPlatformWindows::_code_sign(const Ref<EditorExportPreset> &p_p
return OK;
}

bool EditorExportPlatformWindows::can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const {
String err = "";
bool valid = EditorExportPlatformPC::can_export(p_preset, err, r_missing_templates);

String rcedit_path = EditorSettings::get_singleton()->get("export/windows/rcedit");
if (rcedit_path.empty()) {
err += TTR("The rcedit tool must be configured in the Editor Settings (Export > Windows > Rcedit) to change the icon or app information data.") + "\n";
}

String icon_path = ProjectSettings::get_singleton()->globalize_path(p_preset->get("application/icon"));
if (!icon_path.empty() && !FileAccess::exists(icon_path)) {
err += TTR("Invalid icon path:") + " " + icon_path + "\n";
}

// Only non-negative integers can exist in the version string.

String file_version = p_preset->get("application/file_version");
if (!file_version.empty()) {
Vector<String> version_array = file_version.split(".", false);
if (version_array.size() != 4 || !version_array[0].is_valid_integer() ||
!version_array[1].is_valid_integer() || !version_array[2].is_valid_integer() ||
!version_array[3].is_valid_integer() || file_version.find("-") > -1) {
err += TTR("Invalid file version:") + " " + file_version + "\n";
}
}

String product_version = p_preset->get("application/product_version");
if (!product_version.empty()) {
Vector<String> version_array = product_version.split(".", false);
if (version_array.size() != 4 || !version_array[0].is_valid_integer() ||
!version_array[1].is_valid_integer() || !version_array[2].is_valid_integer() ||
!version_array[3].is_valid_integer() || product_version.find("-") > -1) {
err += TTR("Invalid product version:") + " " + product_version + "\n";
}
}

if (!err.empty()) {
r_error = err;
}

return valid;
}

void register_windows_exporter() {
EDITOR_DEF("export/windows/rcedit", "");
EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::STRING, "export/windows/rcedit", PROPERTY_HINT_GLOBAL_FILE, "*.exe"));
Expand Down

0 comments on commit ef0ec3f

Please sign in to comment.