3232
3333#include " logo_svg.gen.h"
3434#include " run_icon_svg.gen.h"
35+ #include " template_modifier.h"
3536
3637#include " core/config/project_settings.h"
3738#include " core/io/image_loader.h"
@@ -188,10 +189,10 @@ Error EditorExportPlatformWindows::sign_shared_object(const Ref<EditorExportPres
188189
189190Error EditorExportPlatformWindows::modify_template (const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, BitField<EditorExportPlatform::DebugFlags> p_flags) {
190191 if (p_preset->get (" application/modify_resources" )) {
191- _rcedit_add_data (p_preset, p_path, false );
192+ _add_data (p_preset, p_path, false );
192193 String wrapper_path = p_path.get_basename () + " .console.exe" ;
193194 if (FileAccess::exists (wrapper_path)) {
194- _rcedit_add_data (p_preset, wrapper_path, true );
195+ _add_data (p_preset, wrapper_path, true );
195196 }
196197 }
197198 return OK;
@@ -502,32 +503,7 @@ void EditorExportPlatformWindows::get_export_options(List<ExportOption> *r_optio
502503 r_options->push_back (ExportOption (PropertyInfo (Variant::STRING, " ssh_remote_deploy/cleanup_script" , PROPERTY_HINT_MULTILINE_TEXT), cleanup_script));
503504}
504505
505- Error EditorExportPlatformWindows::_rcedit_add_data (const Ref<EditorExportPreset> &p_preset, const String &p_path, bool p_console_icon) {
506- String rcedit_path = EDITOR_GET (" export/windows/rcedit" );
507-
508- if (rcedit_path != String () && !FileAccess::exists (rcedit_path)) {
509- add_message (EXPORT_MESSAGE_WARNING, TTR (" Resources Modification" ), vformat (TTR (" Could not find rcedit executable at \" %s\" ." ), rcedit_path));
510- return ERR_FILE_NOT_FOUND;
511- }
512-
513- if (rcedit_path == String ()) {
514- rcedit_path = " rcedit" ; // try to run rcedit from PATH
515- }
516-
517- #ifndef WINDOWS_ENABLED
518- // On non-Windows we need WINE to run rcedit
519- String wine_path = EDITOR_GET (" export/windows/wine" );
520-
521- if (!wine_path.is_empty () && !FileAccess::exists (wine_path)) {
522- add_message (EXPORT_MESSAGE_WARNING, TTR (" Resources Modification" ), vformat (TTR (" Could not find wine executable at \" %s\" ." ), wine_path));
523- return ERR_FILE_NOT_FOUND;
524- }
525-
526- if (wine_path.is_empty ()) {
527- wine_path = " wine" ; // try to run wine from PATH
528- }
529- #endif
530-
506+ Error EditorExportPlatformWindows::_add_data (const Ref<EditorExportPreset> &p_preset, const String &p_path, bool p_console_icon) {
531507 String icon_path;
532508 if (p_preset->get (" application/icon" ) != " " ) {
533509 icon_path = p_preset->get (" application/icon" );
@@ -545,87 +521,20 @@ Error EditorExportPlatformWindows::_rcedit_add_data(const Ref<EditorExportPreset
545521 }
546522 }
547523
548- String tmp_icon_path = EditorPaths::get_singleton ()->get_temp_dir ().path_join (" _rcedit .ico" );
524+ String tmp_icon_path = EditorPaths::get_singleton ()->get_temp_dir ().path_join (" _tmp .ico" );
549525 if (!icon_path.is_empty ()) {
550526 if (_process_icon (p_preset, icon_path, tmp_icon_path) != OK) {
551527 add_message (EXPORT_MESSAGE_WARNING, TTR (" Resources Modification" ), vformat (TTR (" Invalid icon file \" %s\" ." ), icon_path));
552528 icon_path = String ();
553529 }
554530 }
555531
556- String file_version = p_preset->get_version (" application/file_version" , true );
557- String product_version = p_preset->get_version (" application/product_version" , true );
558- String company_name = p_preset->get (" application/company_name" );
559- String product_name = p_preset->get (" application/product_name" );
560- String file_description = p_preset->get (" application/file_description" );
561- String copyright = p_preset->get (" application/copyright" );
562- String trademarks = p_preset->get (" application/trademarks" );
563- String comments = p_preset->get (" application/comments" );
564-
565- List<String> args;
566- args.push_back (p_path);
567- if (!icon_path.is_empty ()) {
568- args.push_back (" --set-icon" );
569- args.push_back (tmp_icon_path);
570- }
571- if (!file_version.is_empty ()) {
572- args.push_back (" --set-file-version" );
573- args.push_back (file_version);
574- }
575- if (!product_version.is_empty ()) {
576- args.push_back (" --set-product-version" );
577- args.push_back (product_version);
578- }
579- if (!company_name.is_empty ()) {
580- args.push_back (" --set-version-string" );
581- args.push_back (" CompanyName" );
582- args.push_back (company_name);
583- }
584- if (!product_name.is_empty ()) {
585- args.push_back (" --set-version-string" );
586- args.push_back (" ProductName" );
587- args.push_back (product_name);
588- }
589- if (!file_description.is_empty ()) {
590- args.push_back (" --set-version-string" );
591- args.push_back (" FileDescription" );
592- args.push_back (file_description);
593- }
594- if (!copyright.is_empty ()) {
595- args.push_back (" --set-version-string" );
596- args.push_back (" LegalCopyright" );
597- args.push_back (copyright);
598- }
599- if (!trademarks.is_empty ()) {
600- args.push_back (" --set-version-string" );
601- args.push_back (" LegalTrademarks" );
602- args.push_back (trademarks);
603- }
604-
605- #ifndef WINDOWS_ENABLED
606- // On non-Windows we need WINE to run rcedit
607- args.push_front (rcedit_path);
608- rcedit_path = wine_path;
609- #endif
610-
611- String str;
612- Error err = OS::get_singleton ()->execute (rcedit_path, args, &str, nullptr , true );
532+ TemplateModifier::modify (p_preset, p_path, tmp_icon_path);
613533
614534 if (FileAccess::exists (tmp_icon_path)) {
615535 DirAccess::remove_file_or_error (tmp_icon_path);
616536 }
617537
618- if (err != OK || str.contains (" not found" ) || str.contains (" not recognized" )) {
619- add_message (EXPORT_MESSAGE_WARNING, TTR (" Resources Modification" ), TTR (" Could not start rcedit executable. Configure rcedit path in the Editor Settings (Export > Windows > rcedit), or disable \" Application > Modify Resources\" in the export preset." ));
620- return err;
621- }
622- print_line (" rcedit (" + p_path + " ): " + str);
623-
624- if (str.contains (" Fatal error" )) {
625- add_message (EXPORT_MESSAGE_WARNING, TTR (" Resources Modification" ), vformat (TTR (" rcedit failed to modify executable: %s." ), str));
626- return FAILED;
627- }
628-
629538 return OK;
630539}
631540
@@ -823,11 +732,6 @@ bool EditorExportPlatformWindows::has_valid_export_configuration(const Ref<Edito
823732 }
824733 }
825734
826- String rcedit_path = EDITOR_GET (" export/windows/rcedit" );
827- if (p_preset->get (" application/modify_resources" ) && rcedit_path.is_empty ()) {
828- err += TTR (" The rcedit tool must be configured in the Editor Settings (Export > Windows > rcedit) to change the icon or app information data." ) + " \n " ;
829- }
830-
831735 if (!err.is_empty ()) {
832736 r_error = err;
833737 }
0 commit comments