| 387 | } |
| 388 | |
| 389 | Error gdre::unzip_file_to_dir(const String &zip_path, const String &output_dir) { |
| 390 | // check if the zip file is a tar archive |
| 391 | if (is_path_tar(zip_path)) { |
| 392 | ERR_FAIL_COND_V_MSG(ensure_dir(output_dir) != OK, ERR_FILE_CANT_OPEN, "Failed to create output directory: " + output_dir); |
| 393 | int exit_code = 0; |
| 394 | String pipe; |
| 395 | Error err = OS::get_singleton()->execute("tar", { "-xf", zip_path, "-C", output_dir }, &pipe, &exit_code, true); |
| 396 | ERR_FAIL_COND_V_MSG(err != OK || exit_code != 0, ERR_FILE_CANT_OPEN, vformat("Failed to extract tar archive: %s\n%s", zip_path, pipe)); |
| 397 | return OK; |
| 398 | } |
| 399 | Ref<ZIPReader> zip; |
| 400 | zip.instantiate(); |
| 401 | |
| 402 | Error err = zip->open(zip_path); |
| 403 | if (err != OK) { |
| 404 | return err; |
| 405 | } |
| 406 | auto files = zip->get_files(); |
| 407 | for (int i = 0; i < files.size(); i++) { |
| 408 | auto file = files[i]; |
| 409 | auto data = zip->read_file(file, true); |
| 410 | if (data.size() == 0) { |
| 411 | continue; |
| 412 | } |
| 413 | String out_path = output_dir.path_join(file); |
| 414 | ensure_dir(out_path.get_base_dir()); |
| 415 | Ref<FileAccess> fa = FileAccess::open(out_path, FileAccess::WRITE); |
| 416 | if (fa.is_null()) { |
| 417 | continue; |
| 418 | } |
| 419 | fa->store_buffer(data.ptr(), data.size()); |
| 420 | fa->close(); |
| 421 | } |
| 422 | return OK; |
| 423 | } |
| 424 | namespace { |
| 425 | String get_sha256_for_dir(const String &dir) { |
| 426 | auto p_file = Glob::rglob(dir.path_join("**/*"), true); |
nothing calls this directly
no test coverage detected