From d2213f76a92e2c1af80f6e2846f08f1346da244a Mon Sep 17 00:00:00 2001 From: Fredia Huya-Kouadio Date: Sun, 17 Jul 2022 10:22:54 -0400 Subject: [PATCH] Refactor the export checking logic to improve separation of concerns --- editor/editor_export.cpp | 24 ++++++++++++++++++++++- editor/editor_export.h | 7 +++++-- platform/android/export/export_plugin.cpp | 24 ++++++++++++++++++----- platform/android/export/export_plugin.h | 3 ++- platform/iphone/export/export.cpp | 18 ++++++++++++++--- platform/javascript/export/export.cpp | 18 ++++++++++++++--- platform/osx/export/export.cpp | 16 +++++++++++++-- platform/uwp/export/export.cpp | 13 +++++++++++- platform/windows/export/export.cpp | 18 ++++++++++++++--- 9 files changed, 120 insertions(+), 21 deletions(-) diff --git a/editor/editor_export.cpp b/editor/editor_export.cpp index 19d44c2e81b..8c7f30e78ef 100644 --- a/editor/editor_export.cpp +++ b/editor/editor_export.cpp @@ -1656,7 +1656,7 @@ Ref EditorExportPlatformPC::get_logo() const { return logo; } -bool EditorExportPlatformPC::can_export(const Ref &p_preset, String &r_error, bool &r_missing_templates) const { +bool EditorExportPlatformPC::has_valid_export_configuration(const Ref &p_preset, String &r_error, bool &r_missing_templates) const { String err; bool valid = false; @@ -1688,6 +1688,28 @@ bool EditorExportPlatformPC::can_export(const Ref &p_preset, return valid; } +bool EditorExportPlatformPC::has_valid_project_configuration(const Ref &p_preset, String &r_error) const { + return true; +} + +bool EditorExportPlatform::can_export(const Ref &p_preset, String &r_error, bool &r_missing_templates) const { + String templates_error; + bool valid_export_configuration = has_valid_export_configuration(p_preset, templates_error, r_missing_templates); + + String project_configuration_error; + bool valid_project_configuration = has_valid_project_configuration(p_preset, project_configuration_error); + + if (!templates_error.empty()) { + r_error += templates_error; + } + + if (!project_configuration_error.empty()) { + r_error += project_configuration_error; + } + + return valid_export_configuration && valid_project_configuration; +} + List EditorExportPlatformPC::get_binary_extensions(const Ref &p_preset) const { List list; for (Map::Element *E = extensions.front(); E; E = E->next()) { diff --git a/editor/editor_export.h b/editor/editor_export.h index e4b9f3c919d..a418fa8a6bd 100644 --- a/editor/editor_export.h +++ b/editor/editor_export.h @@ -311,7 +311,9 @@ public: String test_etc2() const; //generic test for etc2 since most platforms use it String test_etc2_or_pvrtc() const; // test for etc2 or pvrtc support for iOS - virtual bool can_export(const Ref &p_preset, String &r_error, bool &r_missing_templates) const = 0; + bool can_export(const Ref &p_preset, String &r_error, bool &r_missing_templates) const; + virtual bool has_valid_export_configuration(const Ref &p_preset, String &r_error, bool &r_missing_templates) const = 0; + virtual bool has_valid_project_configuration(const Ref &p_preset, String &r_error) const = 0; virtual List get_binary_extensions(const Ref &p_preset) const = 0; virtual Error export_project(const Ref &p_preset, bool p_debug, const String &p_path, int p_flags = 0) = 0; @@ -481,7 +483,8 @@ public: virtual String get_os_name() const; virtual Ref get_logo() const; - virtual bool can_export(const Ref &p_preset, String &r_error, bool &r_missing_templates) const; + virtual bool has_valid_export_configuration(const Ref &p_preset, String &r_error, bool &r_missing_templates) const; + virtual bool has_valid_project_configuration(const Ref &p_preset, String &r_error) const; virtual List get_binary_extensions(const Ref &p_preset) const; virtual Error export_project(const Ref &p_preset, bool p_debug, const String &p_path, int p_flags = 0); virtual Error sign_shared_object(const Ref &p_preset, bool p_debug, const String &p_path); diff --git a/platform/android/export/export_plugin.cpp b/platform/android/export/export_plugin.cpp index 9eaad034f8e..acf0b05548b 100644 --- a/platform/android/export/export_plugin.cpp +++ b/platform/android/export/export_plugin.cpp @@ -2059,7 +2059,7 @@ String EditorExportPlatformAndroid::get_apksigner_path() { return apksigner_path; } -bool EditorExportPlatformAndroid::can_export(const Ref &p_preset, String &r_error, bool &r_missing_templates) const { +bool EditorExportPlatformAndroid::has_valid_export_configuration(const Ref &p_preset, String &r_error, bool &r_missing_templates) const { String err; bool valid = false; const bool custom_build_enabled = p_preset->get("custom_build/use_custom_build"); @@ -2107,7 +2107,7 @@ bool EditorExportPlatformAndroid::can_export(const Ref &p_pr valid = installed_android_build_template && !r_missing_templates; } - // Validate the rest of the configuration. + // Validate the rest of the export configuration. String dk = p_preset->get("keystore/debug"); String dk_user = p_preset->get("keystore/debug_user"); @@ -2183,6 +2183,19 @@ bool EditorExportPlatformAndroid::can_export(const Ref &p_pr } } + if (!err.empty()) { + r_error = err; + } + + return valid; +} + +bool EditorExportPlatformAndroid::has_valid_project_configuration(const Ref &p_preset, String &r_error) const { + String err; + bool valid = true; + const bool custom_build_enabled = p_preset->get("custom_build/use_custom_build"); + + // Validate the project configuration. bool apk_expansion = p_preset->get("apk_expansion/enable"); if (apk_expansion) { @@ -2249,8 +2262,7 @@ bool EditorExportPlatformAndroid::can_export(const Ref &p_pr } } - if (int(p_preset->get("custom_build/export_format")) == EXPORT_FORMAT_AAB && - !custom_build_enabled) { + if (int(p_preset->get("custom_build/export_format")) == EXPORT_FORMAT_AAB && !custom_build_enabled) { valid = false; err += TTR("\"Export AAB\" is only valid when \"Use Custom Build\" is enabled."); err += "\n"; @@ -2308,7 +2320,9 @@ bool EditorExportPlatformAndroid::can_export(const Ref &p_pr err += "\n"; } - r_error = err; + if (!err.empty()) { + r_error = err; + } return valid; } diff --git a/platform/android/export/export_plugin.h b/platform/android/export/export_plugin.h index 8898cf69552..0b4624081f8 100644 --- a/platform/android/export/export_plugin.h +++ b/platform/android/export/export_plugin.h @@ -204,7 +204,8 @@ public: static String get_apksigner_path(); - virtual bool can_export(const Ref &p_preset, String &r_error, bool &r_missing_templates) const; + virtual bool has_valid_export_configuration(const Ref &p_preset, String &r_error, bool &r_missing_templates) const; + virtual bool has_valid_project_configuration(const Ref &p_preset, String &r_error) const; virtual List get_binary_extensions(const Ref &p_preset) const; diff --git a/platform/iphone/export/export.cpp b/platform/iphone/export/export.cpp index 4a12233709a..b2a848d355c 100644 --- a/platform/iphone/export/export.cpp +++ b/platform/iphone/export/export.cpp @@ -204,7 +204,8 @@ public: virtual Error export_project(const Ref &p_preset, bool p_debug, const String &p_path, int p_flags = 0); - virtual bool can_export(const Ref &p_preset, String &r_error, bool &r_missing_templates) const; + virtual bool has_valid_export_configuration(const Ref &p_preset, String &r_error, bool &r_missing_templates) const; + virtual bool has_valid_project_configuration(const Ref &p_preset, String &r_error) const; virtual void get_platform_features(List *r_features) { r_features->push_back("mobile"); @@ -2099,7 +2100,7 @@ Error EditorExportPlatformIOS::export_project(const Ref &p_p return OK; } -bool EditorExportPlatformIOS::can_export(const Ref &p_preset, String &r_error, bool &r_missing_templates) const { +bool EditorExportPlatformIOS::has_valid_export_configuration(const Ref &p_preset, String &r_error, bool &r_missing_templates) const { String err; bool valid = false; @@ -2124,7 +2125,18 @@ bool EditorExportPlatformIOS::can_export(const Ref &p_preset valid = dvalid || rvalid; r_missing_templates = !valid; - // Validate the rest of the configuration. + if (!err.empty()) { + r_error = err; + } + + return valid; +} + +bool EditorExportPlatformIOS::has_valid_project_configuration(const Ref &p_preset, String &r_error) const { + String err; + bool valid = true; + + // Validate the project configuration. String team_id = p_preset->get("application/app_store_team_id"); if (team_id.length() == 0) { diff --git a/platform/javascript/export/export.cpp b/platform/javascript/export/export.cpp index 17e2fc21f02..8c2aae3a827 100644 --- a/platform/javascript/export/export.cpp +++ b/platform/javascript/export/export.cpp @@ -328,7 +328,8 @@ public: virtual String get_os_name() const; virtual Ref get_logo() const; - virtual bool can_export(const Ref &p_preset, String &r_error, bool &r_missing_templates) const; + virtual bool has_valid_export_configuration(const Ref &p_preset, String &r_error, bool &r_missing_templates) const; + virtual bool has_valid_project_configuration(const Ref &p_preset, String &r_error) const; virtual List get_binary_extensions(const Ref &p_preset) const; virtual Error export_project(const Ref &p_preset, bool p_debug, const String &p_path, int p_flags = 0); @@ -687,7 +688,7 @@ Ref EditorExportPlatformJavaScript::get_logo() const { return logo; } -bool EditorExportPlatformJavaScript::can_export(const Ref &p_preset, String &r_error, bool &r_missing_templates) const { +bool EditorExportPlatformJavaScript::has_valid_export_configuration(const Ref &p_preset, String &r_error, bool &r_missing_templates) const { String err; bool valid = false; ExportMode mode = (ExportMode)(int)p_preset->get("variant/export_type"); @@ -712,7 +713,18 @@ bool EditorExportPlatformJavaScript::can_export(const Ref &p valid = dvalid || rvalid; r_missing_templates = !valid; - // Validate the rest of the configuration. + if (!err.empty()) { + r_error = err; + } + + return valid; +} + +bool EditorExportPlatformJavaScript::has_valid_project_configuration(const Ref &p_preset, String &r_error) const { + String err; + bool valid = true; + + // Validate the project configuration. if (p_preset->get("vram_texture_compression/for_mobile")) { String etc_error = test_etc2(); diff --git a/platform/osx/export/export.cpp b/platform/osx/export/export.cpp index 9dd28d3125a..736c6ab01de 100644 --- a/platform/osx/export/export.cpp +++ b/platform/osx/export/export.cpp @@ -120,7 +120,8 @@ public: } virtual Error export_project(const Ref &p_preset, bool p_debug, const String &p_path, int p_flags = 0); - virtual bool can_export(const Ref &p_preset, String &r_error, bool &r_missing_templates) const; + virtual bool has_valid_export_configuration(const Ref &p_preset, String &r_error, bool &r_missing_templates) const; + virtual bool has_valid_project_configuration(const Ref &p_preset, String &r_error) const; virtual void get_platform_features(List *r_features) { r_features->push_back("pc"); @@ -1428,7 +1429,7 @@ void EditorExportPlatformOSX::_zip_folder_recursive(zipFile &p_zip, const String memdelete(da); } -bool EditorExportPlatformOSX::can_export(const Ref &p_preset, String &r_error, bool &r_missing_templates) const { +bool EditorExportPlatformOSX::has_valid_export_configuration(const Ref &p_preset, String &r_error, bool &r_missing_templates) const { String err; bool valid = false; @@ -1458,6 +1459,17 @@ bool EditorExportPlatformOSX::can_export(const Ref &p_preset valid = dvalid || rvalid; r_missing_templates = !valid; + if (!err.empty()) { + r_error = err; + } + + return valid; +} + +bool EditorExportPlatformOSX::has_valid_project_configuration(const Ref &p_preset, String &r_error) const { + String err; + bool valid = true; + String identifier = p_preset->get("application/identifier"); String pn_err; if (!is_package_name_valid(identifier, &pn_err)) { diff --git a/platform/uwp/export/export.cpp b/platform/uwp/export/export.cpp index 8864fa0d5af..1cdd816de59 100644 --- a/platform/uwp/export/export.cpp +++ b/platform/uwp/export/export.cpp @@ -1073,7 +1073,7 @@ public: } } - virtual bool can_export(const Ref &p_preset, String &r_error, bool &r_missing_templates) const { + virtual bool has_valid_export_configuration(const Ref &p_preset, String &r_error, bool &r_missing_templates) const { String err; bool valid = false; @@ -1112,6 +1112,17 @@ public: valid = dvalid || rvalid; r_missing_templates = !valid; + if (!err.empty()) { + r_error = err; + } + + return valid; + } + + virtual bool has_valid_project_configuration(const Ref &p_preset, String &r_error) const { + String err; + bool valid = true; + // Validate the rest of the configuration. if (!_valid_resource_name(p_preset->get("package/short_name"))) { diff --git a/platform/windows/export/export.cpp b/platform/windows/export/export.cpp index 0df4af3dc25..e68423a0390 100644 --- a/platform/windows/export/export.cpp +++ b/platform/windows/export/export.cpp @@ -48,7 +48,8 @@ public: virtual Error fixup_embedded_pck(const String &p_path, int64_t p_embedded_start, int64_t p_embedded_size); virtual void get_export_options(List *r_options); virtual bool get_option_visibility(const String &p_option, const Map &p_options) const; - virtual bool can_export(const Ref &p_preset, String &r_error, bool &r_missing_templates) const; + virtual bool has_valid_export_configuration(const Ref &p_preset, String &r_error, bool &r_missing_templates) const; + virtual bool has_valid_project_configuration(const Ref &p_preset, String &r_error) const; }; Error EditorExportPlatformWindows::sign_shared_object(const Ref &p_preset, bool p_debug, const String &p_path) { @@ -386,15 +387,26 @@ Error EditorExportPlatformWindows::_code_sign(const Ref &p_p return OK; } -bool EditorExportPlatformWindows::can_export(const Ref &p_preset, String &r_error, bool &r_missing_templates) const { +bool EditorExportPlatformWindows::has_valid_export_configuration(const Ref &p_preset, String &r_error, bool &r_missing_templates) const { String err = ""; - bool valid = EditorExportPlatformPC::can_export(p_preset, err, r_missing_templates); + bool valid = EditorExportPlatformPC::has_valid_export_configuration(p_preset, err, r_missing_templates); String rcedit_path = EditorSettings::get_singleton()->get("export/windows/rcedit"); if (p_preset->get("application/modify_resources") && 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"; } + if (!err.empty()) { + r_error = err; + } + + return valid; +} + +bool EditorExportPlatformWindows::has_valid_project_configuration(const Ref &p_preset, String &r_error) const { + String err = ""; + bool valid = true; + 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";