Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export: Modify template without rcedit #75950

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

pkowal1982
Copy link
Contributor

@pkowal1982 pkowal1982 commented Apr 11, 2023

Using rcedit is little problematic so I've created a POC which shows how it can be dropped.
PR contains only crucial code, if it's decided to go this way I'll fix loose ends.
For now code drops old resources section and replaces it with brand new created from scratch.
Questions which I can think of:

  1. How to test this solution properly?
  2. Do we need to copy anything from original resources?
  3. Is there a minimum set of information which user should provide?
  4. All the editor code regarding rcedit should be probably removed in another dedicated PR?

@Calinou
Copy link
Member

Calinou commented Apr 11, 2023

All the editor code regarding rcedit should be probably removed in another dedicated PR?

I think the rcedit code should be removed in the same PR, as we don't want to support both approaches at the same time. While we try to preserve compatibility across 4.x, this mainly applies to the API, not the export system.

(Also, it should be possible to create compatibility handlers to automatically update old entries' names in the Windows export presets to the new names.)

@akien-mga
Copy link
Member

All the editor code regarding rcedit should be probably removed in another dedicated PR?

I think the rcedit code should be removed in the same PR, as we don't want to support both approaches at the same time. While we try to preserve compatibility across 4.x, this mainly applies to the API, not the export system.

(Also, it should be possible to create compatibility handlers to automatically update old entries' names in the Windows export presets to the new names.)

I think it's fine to first assess whether this approach is good, before doing the extra work to remove the old. If it's not clear whether this PR wouldn't be merged (it hasn't been reviewed yet), there's no point doing removing the code it's meant to replace.

@sammypanda

This comment was marked as off-topic.

@fire
Copy link
Member

fire commented Jul 17, 2023

I am interested in getting this to work since I export from Linux for Windows.

@Maran23
Copy link
Contributor

Maran23 commented Dec 21, 2023

I also think this is a good idea since it has multiple advantages:

  • No rcedit needed on Windows
  • Project can be exported on Linux or MacOS without using Wine (for this particular feature)

Note: This PR needs a rebase. I would be happy to test this as I always used rcedit in the past.

@pkowal1982
Copy link
Contributor Author

Ok, rebased it so you can test it.

Also fixed a bug introduced here which prevented exporting console template.
Looks like it never worked, probably not too popular feature.

@YuriSizov
Copy link
Contributor

Also fixed a bug introduced here which prevented exporting console template.
Looks like it never worked, probably not too popular feature.

This is incorrect. The official export templates (and the editor executable) are named with the underscore:

image

The name with a period is what is produced by our buildsystem by default, but the actual distribution is renamed. So this code was correct and should not be modified.

@YuriSizov YuriSizov requested a review from a team December 22, 2023 13:38
@pkowal1982
Copy link
Contributor Author

Ok, the ones built on github contained in artifact windows-template.zip are named:
godot.windows.template_release.x86_64.console.exe

Would be nice to change the github workflow probably to be consistent.

@YuriSizov
Copy link
Contributor

@pkowal1982 That's not related to the CI. As I mentioned, that's how the name is generated by the buildsystem. It uses a number of suffixes to differentiate between build options, but those get removed for the official distribution. It may be worth discussing the naming scheme of the official distribution, but in the meantime we should not break the system in favor of CI artifacts which are not supposed to be used in development anyway.

@pkowal1982
Copy link
Contributor Author

Ok, reverted _console -> .console change. Though I think it would be nice
to change the CI workflow in another PR to produce _console named templates.
Now editor built from master does not work smoothly with templates built from the same branch.

Copy link
Contributor

@Maran23 Maran23 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now, I can not really test this as I always get Wrong number of icon images..
With the old implementation, I just got a bunch of warnings (that I do not provide icons for all formats) but the modify process worked (and the icon worked in the explorer, not when I opened the properties though).

@Maran23
Copy link
Contributor

Maran23 commented Jan 7, 2024

Tested now with an icon containing all 6 required image formats.
Looks good. I can confirm that the icon and all the metadata is set correctly. Nice!
Results below (Note: My Windows is set to German)

Godot 4.2.1 Godot 4.3.dev (this PR)
image image

I would still recommend that if the icon does not contain all 6 image formats, we just print a warning as before, and continue with the modification.

@AThousandShips AThousandShips changed the title Export: Modify template without rcedit, fix #73497 Export: Modify template without rcedit Jan 7, 2024
return;
}
if (p_icon_file->get_16() != IMAGE_COUNT) {
print_error("Wrong number of icon images.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible like with rcedit to also do that operation with just one icon image? Would be nice for backward compatibility.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have application/icon_interpolation option in export settings, which is going to be unused if icon resizing is not implemented. This needs to be resolved.

@fire
Copy link
Member

fire commented Sep 4, 2024

@KoBeWi What are you thoughts about modifying the template without rcedit?

@KoBeWi
Copy link
Member

KoBeWi commented Sep 4, 2024

This basically reimplements what rcedit does and makes it built-in, no? If it works the same as before then why not I guess.
Custom code also gives us more control.

@Maran23
Copy link
Contributor

Maran23 commented Sep 4, 2024

And it works on other platforms as well. Currently you need to use Wine on Linux to run rcedit to modify the .exe. Which is annoying for cross platform creation of the game binaries.

Copy link
Member

@fire fire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • design proposal review: I think it's a great idea
  • technical review: unreviewed
  • style review: @AThousandShips Can you take a look?
  • test plan: untested

String key;

Vector<uint8_t> save() const;
Vector<uint8_t> &add_length(Vector<uint8_t> &bytes) const;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Vector<uint8_t> &add_length(Vector<uint8_t> &bytes) const;
Vector<uint8_t> &add_length(Vector<uint8_t> &r_bytes) const;


Vector<uint8_t> save() const;
StringStructure();
StringStructure(String p_key, String p_value);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
StringStructure(String p_key, String p_value);
StringStructure(const String &p_key, const String &p_value);


uint32_t offset = sizeof(RESOURCE_DIRECTORY_TABLES) + data_entries.size() * ResourceDataEntry::SIZE;

for (Vector<uint8_t> data_entry : data_entries) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for (Vector<uint8_t> data_entry : data_entries) {
for (const Vector<uint8_t> &data_entry : data_entries) {

memcpy(resources.ptrw(), RESOURCE_DIRECTORY_TABLES, sizeof(RESOURCE_DIRECTORY_TABLES));

Vector<Vector<uint8_t>> data_entries;
for (Vector<uint8_t> image : p_group_icon.images) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for (Vector<uint8_t> image : p_group_icon.images) {
for (const Vector<uint8_t> &image : p_group_icon.images) {

}
}

for (Vector<uint8_t> data_entry : data_entries) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for (Vector<uint8_t> data_entry : data_entries) {
for (const Vector<uint8_t> &data_entry : data_entries) {

Comment on lines +242 to +243
print_error("Wrong icon file type.");
return;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
print_error("Wrong icon file type.");
return;
ERR_FAIL_MSG("Wrong icon file type.");

Comment on lines +246 to +247
print_error("Wrong number of icon images.");
return;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
print_error("Wrong number of icon images.");
return;
ERR_FAIL_MSG("Wrong number of icon images.");

Error error;

Ref<FileAccess> file = FileAccess::open(path, FileAccess::READ, &error);
ERR_FAIL_COND_V(error, ERR_CANT_OPEN);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ERR_FAIL_COND_V(error, ERR_CANT_OPEN);
ERR_FAIL_COND_V(error != OK, ERR_CANT_OPEN);

Be consistent about error check here (you use != OK below)


String truncated_path = path + ".truncated";
Ref<FileAccess> truncated = FileAccess::open(truncated_path, FileAccess::WRITE, &error);
ERR_FAIL_COND_V(error, ERR_CANT_CREATE);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ERR_FAIL_COND_V(error, ERR_CANT_CREATE);
ERR_FAIL_COND_V(error != OK, ERR_CANT_CREATE);


Vector<uint8_t> TemplateModifier::StringTable::save() const {
Vector<uint8_t> bytes = Structure::save();
for (StringStructure string : strings) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for (StringStructure string : strings) {
for (const StringStructure &string : strings) {

@KoBeWi
Copy link
Member

KoBeWi commented Sep 5, 2024

Tested on Windows. Using svg icon prints "Wrong icon file type.", using ico generated with GIMP iconify extension, which I'm always using, results in "Wrong number of icon images.". The executables end up without any icon. Both cases worked perfectly before the change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
9 participants