From c500dca41d3663e0c070b940d9f212bb33fcf552 Mon Sep 17 00:00:00 2001 From: DeeJayLSP Date: Fri, 9 Jan 2026 01:54:24 -0300 Subject: [PATCH] zip.unzip: use built-in `ZipReader` instead of `unzip` command --- src/extensions/zip.gd | 56 ++++++++++++++----------------------------- 1 file changed, 18 insertions(+), 38 deletions(-) diff --git a/src/extensions/zip.gd b/src/extensions/zip.gd index d351356a..75be8b35 100644 --- a/src/extensions/zip.gd +++ b/src/extensions/zip.gd @@ -2,45 +2,25 @@ class_name zip static func unzip(zip_path: String, target_dir: String) -> void: DirAccess.make_dir_absolute(target_dir) + var reader := ZIPReader.new() + if reader.open(zip_path) == OK: + var destination := DirAccess.open(target_dir) + for zip_file_name in reader.get_files(): + if zip_file_name.ends_with("/"): + destination.make_dir_recursive(zip_file_name) + continue - var output := [] - var exit_code: int - if OS.has_feature("windows"): - exit_code = OS.execute( - "powershell.exe", - [ - "-command", - "\"Expand-Archive '%s' '%s'\" -Force" % [ - ProjectSettings.globalize_path(zip_path), - ProjectSettings.globalize_path(target_dir) - ] - ], output, true - ) - Output.push(output.pop_front()) - Output.push("unzip executed with exit code: %s" % exit_code) - elif OS.has_feature("macos"): - exit_code = OS.execute( - "unzip", - [ - "%s" % ProjectSettings.globalize_path(zip_path), - "-d", - "%s" % ProjectSettings.globalize_path(target_dir) - ], output, true - ) - Output.push(output.pop_front()) - Output.push("unzip executed with exit code: %s" % exit_code) - elif OS.has_feature("linux"): - exit_code = OS.execute( - "unzip", - [ - "-o", - "%s" % ProjectSettings.globalize_path(zip_path), - "-d", - "%s" % ProjectSettings.globalize_path(target_dir) - ], output, true - ) - Output.push(output.pop_front()) - Output.push("unzip executed with exit code: %s" % exit_code) + var file_contents := reader.read_file(zip_file_name) + var file_path := destination.get_current_dir().path_join(zip_file_name) + destination.make_dir_recursive(file_path.get_base_dir()) + var file := FileAccess.open(file_path, FileAccess.WRITE) + if not file: + reader.close() + return + file.store_buffer(file_contents) + file.close() + + reader.close() ## A procedure that unzips a zip file to a target directory, keeping the