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

Add "Pack Project as ZIP..." to Project menu #99781

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Meorge
Copy link
Contributor

@Meorge Meorge commented Nov 28, 2024

Closes godotengine/godot-proposals#227.

This PR adds a menu item, "Pack Project as ZIP...", to the Project menu in the menu bar. Clicking it opens a file save location dialog, which defaults to the same directory as the project's folder. Clicking "Save" packs the contents of the project, except for the .godot folder, into a ZIP file at that location.

Godot – Pack Project as ZIP Menu Item
Godot – Pack Project as ZIP Save Popup
Godot – Pack Project as ZIP File in Finder
Godot – Pack Project as ZIP Comparison of Folders

Most of the code for this is from the WebToolsEditorPlugin class, since it was already implementing most of this functionality. The relevant code has been pulled out of that class and into a new class with static methods, ProjectZIPPacker. Both WebToolsEditorPlugin and this new menu item simply use ProjectZIPPacker to accomplish their task.

Notes

  • I specifically used the term "Pack" here instead of "Export". I feel like "Export" implies that the output will be in a different, runnable format, whereas this is simply creating a copy of the project itself.
  • While the .godot folder is not present, other hidden files/directories like .git, .gitignore, etc are included.
    • We could potentially add checkboxes to the save dialog to decide whether to include certain types of hidden files like Git configuration/data.
  • "Date Modified" metadata is not preserved (you can see in the fourth screenshot that the "Date Modified" on all of the files is November 30, 1979 at 12:00 AM).
  • The behavior of "Download Project Source" for the web editor should be unchanged, although I haven't yet been able to test it. Assuming it works correctly, this will still mean that the web editor will have two menu items with different names that perform very similar tasks. If possible, "Pack Project as ZIP" should probably be modified so that when run in the web editor, it simply downloads to the user's device (replicating the behavior of the existing "Download Project Source"), and then we can remove the menu item for "Download Project Source".

To Do

  • Confirm that web export functionality ("Download Project Source") still works
  • Attempt to merge "Pack Project as ZIP" with web export functionality (look into using #defines for this perhaps?)

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.

This improves usability and export by exposing something hidden in the export system.

Did not do a thorough review and did not do testing.

@akien-mga akien-mga requested review from akien-mga and a team November 28, 2024 15:13
@adamscott
Copy link
Member

Interesting. Especially when asking for MRPs.

@Meorge
Copy link
Contributor Author

Meorge commented Nov 28, 2024

I was hoping to test the web editor today, but unfortunately ran into some strange issues with running it. I've asked for assistance with it in some other places, and will give a shot at building from master just in case my PR introduced bugs, but otherwise I won't be able to test the web editor for now 😅

@badsectoracula
Copy link
Contributor

I tried it here and from what i can see in the code it looks fine to me, with three notes:

  1. It seems to just be copying everything, but perhaps the exp directory (or at least the generated files from configured exports) could be ignored. The project i tried to "pack" had a previously (and outdated) build i made a few days ago i had forgotten and yet it took 99% of the ZIP file's space. Perhaps there should be some files it should ignore (maybe also parsing .gitignore for globs to ignore?)
  2. I'm not very familiar with that part of the code but isn't ERR_FAIL_COND_MSG(f.is_null(), "Unable to create ZIP file.") a bit too "raw" for error reporting? I see other surrounding code use show_accept for that.
  3. PR is made up of multiple commits, before it can be merged it should be squashed with a rebase and force pushed to be a single commit, check https://docs.godotengine.org/en/latest/contributing/workflow/pr_workflow.html#the-interactive-rebase

Aside from the above, i think it'd be useful functionality to have. I also tried to build the web-based editor but for some reason it wouldn't run (both Firefox Developer Edition and Falkon wouldn't work, stopping at godot's logo with an error about trying to call send_message from an undefined object, so something failed to load or initialize), so i couldn't test this for now.

@Meorge
Copy link
Contributor Author

Meorge commented Nov 29, 2024

Thanks for testing it!

To address your notes:

perhaps the exp directory (or at least the generated files from configured exports) could be ignored

If these are pre-defined/hard-coded directories that would exist in any project that's been exported, then I definitely agree they should be excluded by default. I was thinking of having it ignore Git-related files as an option as well. Parsing .gitignore itself to determine files to exclude would be clever too. I feel like that might be a bit out of scope for this PR - given that one of the big uses of it will be easily creating MRPs, I think it might be better to aim for the fine-grained exclusion options in a later PR.

I'm not very familiar with that part of the code but isn't ERR_FAIL_COND_MSG(f.is_null(), "Unable to create ZIP file.") a bit too "raw" for error reporting? I see other surrounding code use show_accept for that.

This was copied from the "Download Project Source" code, and I think I've also seen some other functions in Godot that just output their error messages to the console window. That being said, a show_accept (or similar nice GUI response) does sound better, and like it wouldn't increase the scope of the PR much, so I could look into adding that.

PR is made up of multiple commits, before it can be merged it should be squashed with a rebase and force pushed to be a single commit

Yep, I'm aware. I'm happy with the current overall state of the PR (that is, I don't foresee myself needing to check intermediate commits), so I'll probably squash what I have so far. I often prefer to keep the commits separate so I can check intermediate versions, then squash them once the PR is closer to being merged.

I also tried to build the web-based editor but for some reason it wouldn't run (both Firefox Developer Edition and Falkon wouldn't work, stopping at godot's logo with an error about trying to call send_message from an undefined object, so something failed to load or initialize), so i couldn't test this for now.

That may have been the same error message I was getting, that prevented me from testing the web editor! If I don't see an issue open for it, I'll open one.

Thanks again!

editor/export/project_zip_packer.h Outdated Show resolved Hide resolved
editor/export/project_zip_packer.h Outdated Show resolved Hide resolved
Co-authored-by: A Thousand Ships <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Expose "Download Project Source" option on platforms other than HTML5
6 participants