Support for installing plugins from .zip urls
This adds support for installing plugins from .zip files hosted on the web.
This command would now work: plug("https://github.com/TokisanGames/Terrain3D/releases/download/v1.0.0-stable/terrain3D-1.0.0-stable-godot4.3.zip")
I noticed a lot of godot plugins are distributed as .zip files on github release pages, especially if they include compiled binaries. I figure it might be useful to let people install plugins that way.
I doubt this is of acceptable quality to merge, but I figured I would share my work in case it's interesting to you.
Other notes:
- The
download_zipfunction shells out tocurlto download the zip file. Then it uses godot's builtin ZipReader to decompress. -
download_zipwas added to the_GitExecutableclass. That's kind of weird, but_GitExecutablealready had all the methods needed to shell out to an external command, so I just piggybacked off of it. Could maybe rename_GitExecutableto_ExternalExecutableor something.
There's also an unrelated change in here. I added a new field to plugins called on_updated_callable which works exactly like on_updated, but takes a callable instead of a string. Happy to back that out if it's weird to have both changes in the same PR.
Cool! I always thought this feature should be implemented with Github API, now it just seem completely unnecessary.
I have only tested the example provided and godot-jolt, but they both works well without any problem.
Some suggestions:
- Regarding the
_ExternalExecutable, if you don't mind, can you help me to implement it and makes_GitExecutableinherits from it? The purpose of_GitExecutableis to provide convenient API to interact with git repo, likefetch,pull,clone, etc. - Rename
on_updated_callabletoupdated.
Other than that, I think this PR is quite stable and ready to merge after cleaning the code. Great job!
This needs a bit more work. The links in the assetlib generally contain an extra outer directory that needs to be trimmed off. And some of them need to have the addons directory name put back into them so they don't copy over to the top level of the project.
One such important core module is the WebRTC code:
plug("https://github.com/godotengine/webrtc-native/releases/download/1.0.6-stable/godot-extension-4.1-webrtc.zip", { "branch":"addons/webrtc"})
Not very happy with this hack to make it work, and I misused the branch value to set the extra directory levels of ldir, but I'm in a hurry.
var files = reader.get_files()
for file_path in files:
var zip_file_path = file_path
file_path = file_path.split("/", true, 1)[1]
if ldir:
file_path = ldir+"/"+file_path
if file_path.ends_with("/"):
root_dir.make_dir_recursive(file_path)
continue
root_dir.make_dir_recursive(root_dir.get_current_dir().path_join(file_path).get_base_dir())
var file = FileAccess.open(root_dir.get_current_dir().path_join(file_path), FileAccess.WRITE)
var buffer = reader.read_file(zip_file_path)
file.store_buffer(buffer)
Maybe this would better be done in the install phase rather than the unpack phase, and I don't know how we're going to handle new versions that are just different zip file urls without any context.