@@ -217,6 +217,11 @@ TemplateModifier::VersionInfo::VersionInfo() {
217217 value_length = 52 ;
218218}
219219
220+ Vector<uint8_t > TemplateModifier::ManifestInfo::save () const {
221+ Vector<uint8_t > bytes = manifest.to_utf8_buffer ();
222+ return bytes;
223+ }
224+
220225Vector<uint8_t > TemplateModifier::IconEntry::save () const {
221226 Vector<uint8_t > bytes;
222227 ByteStream::save (width, bytes);
@@ -347,10 +352,10 @@ uint32_t TemplateModifier::_snap(uint32_t p_value, uint32_t p_size) const {
347352 return p_value + (p_value % p_size ? p_size - (p_value % p_size) : 0 );
348353}
349354
350- Vector<uint8_t > TemplateModifier::_create_resources (uint32_t p_virtual_address, const GroupIcon &p_group_icon, const VersionInfo &p_version_info) const {
355+ Vector<uint8_t > TemplateModifier::_create_resources (uint32_t p_virtual_address, const GroupIcon &p_group_icon, const VersionInfo &p_version_info, const ManifestInfo &p_manifest_info ) const {
351356 // 0x04, 0x00 as string length ICON in UTF16 and padding to 32 bits
352357 const uint8_t ICON_DIRECTORY_STRING[] = { 0x04 , 0x00 , 0x49 , 0x00 , 0x43 , 0x00 , 0x4f , 0x00 , 0x4e , 0x00 , 0x00 , 0x00 };
353- const uint16_t RT_ENTRY_COUNT = 3 ;
358+ const uint16_t RT_ENTRY_COUNT = 4 ;
354359 const uint32_t icon_count = p_group_icon.images .size ();
355360
356361 ResourceDirectoryTable root_directory_table;
@@ -376,6 +381,12 @@ Vector<uint8_t> TemplateModifier::_create_resources(uint32_t p_virtual_address,
376381 rt_version_entry.subdirectory = true ;
377382 resources.append_array (rt_version_entry.save ());
378383
384+ ResourceDirectoryEntry rt_manifest_entry;
385+ rt_manifest_entry.id = ResourceDirectoryEntry::MANIFEST;
386+ rt_manifest_entry.data_offset = (6 + icon_count) * ResourceDirectoryTable::SIZE + (RT_ENTRY_COUNT + 2 * icon_count + 4 ) * ResourceDirectoryEntry::SIZE;
387+ rt_manifest_entry.subdirectory = true ;
388+ resources.append_array (rt_manifest_entry.save ());
389+
379390 ResourceDirectoryTable icon_table;
380391 icon_table.id_entry_count = icon_count;
381392 resources.append_array (icon_table.save ());
@@ -395,7 +406,7 @@ Vector<uint8_t> TemplateModifier::_create_resources(uint32_t p_virtual_address,
395406
396407 ResourceDirectoryEntry language_icon_entry;
397408 language_icon_entry.id = ResourceDirectoryEntry::ENGLISH;
398- language_icon_entry.data_offset = (6 + icon_count) * ResourceDirectoryTable::SIZE + (RT_ENTRY_COUNT + icon_count * 2 + 4 ) * ResourceDirectoryEntry::SIZE + sizeof (ICON_DIRECTORY_STRING) + i * ResourceDataEntry::SIZE;
409+ language_icon_entry.data_offset = (8 + icon_count) * ResourceDirectoryTable::SIZE + (RT_ENTRY_COUNT + icon_count * 2 + 6 ) * ResourceDirectoryEntry::SIZE + sizeof (ICON_DIRECTORY_STRING) + i * ResourceDataEntry::SIZE;
399410 resources.append_array (language_icon_entry.save ());
400411 }
401412
@@ -416,7 +427,7 @@ Vector<uint8_t> TemplateModifier::_create_resources(uint32_t p_virtual_address,
416427
417428 ResourceDirectoryEntry group_icon_language_entry;
418429 group_icon_language_entry.id = ResourceDirectoryEntry::ENGLISH;
419- group_icon_language_entry.data_offset = (6 + icon_count) * ResourceDirectoryTable::SIZE + (RT_ENTRY_COUNT + 2 * icon_count + 4 ) * ResourceDirectoryEntry::SIZE + sizeof (ICON_DIRECTORY_STRING) + icon_count * ResourceDataEntry::SIZE;
430+ group_icon_language_entry.data_offset = (8 + icon_count) * ResourceDirectoryTable::SIZE + (RT_ENTRY_COUNT + 2 * icon_count + 6 ) * ResourceDirectoryEntry::SIZE + sizeof (ICON_DIRECTORY_STRING) + icon_count * ResourceDataEntry::SIZE;
420431 resources.append_array (group_icon_language_entry.save ());
421432
422433 ResourceDirectoryTable version_table;
@@ -435,9 +446,28 @@ Vector<uint8_t> TemplateModifier::_create_resources(uint32_t p_virtual_address,
435446
436447 ResourceDirectoryEntry version_language_entry;
437448 version_language_entry.id = ResourceDirectoryEntry::ENGLISH;
438- version_language_entry.data_offset = (6 + icon_count) * ResourceDirectoryTable::SIZE + (RT_ENTRY_COUNT + 2 * icon_count + 4 ) * ResourceDirectoryEntry::SIZE + sizeof (ICON_DIRECTORY_STRING) + (icon_count + 1 ) * ResourceDataEntry::SIZE;
449+ version_language_entry.data_offset = (8 + icon_count) * ResourceDirectoryTable::SIZE + (RT_ENTRY_COUNT + 2 * icon_count + 6 ) * ResourceDirectoryEntry::SIZE + sizeof (ICON_DIRECTORY_STRING) + (icon_count + 1 ) * ResourceDataEntry::SIZE;
439450 resources.append_array (version_language_entry.save ());
440451
452+ ResourceDirectoryTable manifest_table;
453+ manifest_table.id_entry_count = 1 ;
454+ resources.append_array (manifest_table.save ());
455+
456+ ResourceDirectoryEntry manifest_entry;
457+ manifest_entry.id = 1 ;
458+ manifest_entry.data_offset = (7 + icon_count) * ResourceDirectoryTable::SIZE + (RT_ENTRY_COUNT + 2 * icon_count + 5 ) * ResourceDirectoryEntry::SIZE;
459+ manifest_entry.subdirectory = true ;
460+ resources.append_array (manifest_entry.save ());
461+
462+ ResourceDirectoryTable manifest_language_table;
463+ manifest_language_table.id_entry_count = 1 ;
464+ resources.append_array (manifest_language_table.save ());
465+
466+ ResourceDirectoryEntry manifest_language_entry;
467+ manifest_language_entry.id = ResourceDirectoryEntry::ENGLISH;
468+ manifest_language_entry.data_offset = (8 + icon_count) * ResourceDirectoryTable::SIZE + (RT_ENTRY_COUNT + 2 * icon_count + 6 ) * ResourceDirectoryEntry::SIZE + sizeof (ICON_DIRECTORY_STRING) + (icon_count + 2 ) * ResourceDataEntry::SIZE;
469+ resources.append_array (manifest_language_entry.save ());
470+
441471 Vector<uint8_t > icon_directory_string;
442472 icon_directory_string.resize (sizeof (ICON_DIRECTORY_STRING));
443473 memcpy (icon_directory_string.ptrw (), ICON_DIRECTORY_STRING, sizeof (ICON_DIRECTORY_STRING));
@@ -449,6 +479,7 @@ Vector<uint8_t> TemplateModifier::_create_resources(uint32_t p_virtual_address,
449479 }
450480 data_entries.append (p_group_icon.save ());
451481 data_entries.append (p_version_info.save ());
482+ data_entries.append (p_manifest_info.save ());
452483
453484 uint32_t offset = resources.size () + data_entries.size () * ResourceDataEntry::SIZE;
454485
@@ -497,6 +528,24 @@ TemplateModifier::VersionInfo TemplateModifier::_create_version_info(const HashM
497528 return version_info;
498529}
499530
531+ TemplateModifier::ManifestInfo TemplateModifier::_create_manifest_info () const {
532+ ManifestInfo manifest_info;
533+ manifest_info.manifest = R"MANIFEST( <?xml version="1.0" encoding="utf-8"?>
534+ <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
535+ <application xmlns="urn:schemas-microsoft-com:asm.v3">
536+ <windowsSettings xmlns:ws2="http://schemas.microsoft.com/SMI/2016/WindowsSettings">
537+ <ws2:longPathAware>true</ws2:longPathAware>
538+ </windowsSettings>
539+ </application>
540+ <dependency>
541+ <dependentAssembly>
542+ <assemblyIdentity type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'/>
543+ </dependentAssembly>
544+ </dependency>
545+ </assembly>)MANIFEST" ;
546+ return manifest_info;
547+ }
548+
500549TemplateModifier::GroupIcon TemplateModifier::_create_group_icon (const String &p_icon_path) const {
501550 GroupIcon group_icon;
502551
@@ -594,10 +643,11 @@ Error TemplateModifier::_modify_template(const Ref<EditorExportPreset> &p_preset
594643 GroupIcon group_icon = _create_group_icon (p_icon_path);
595644
596645 VersionInfo version_info = _create_version_info (_get_strings (p_preset));
646+ ManifestInfo manifest_info = _create_manifest_info ();
597647
598648 SectionEntry &resources_section_entry = section_entries.write [resource_index];
599649 uint32_t old_resources_size_of_raw_data = resources_section_entry.size_of_raw_data ;
600- Vector<uint8_t > resources = _create_resources (resources_section_entry.virtual_address , group_icon, version_info);
650+ Vector<uint8_t > resources = _create_resources (resources_section_entry.virtual_address , group_icon, version_info, manifest_info );
601651 resources_section_entry.virtual_size = resources.size ();
602652 resources.resize_initialized (_snap (resources.size (), BLOCK_SIZE));
603653 resources_section_entry.size_of_raw_data = resources.size ();
0 commit comments