From 0bff53135a7388d5604983e96610cbd47996d66c Mon Sep 17 00:00:00 2001 From: Josh Kabo Date: Sat, 16 Apr 2022 14:50:48 -0700 Subject: [PATCH] Unzip read success no longer breaks read loop unzReadCurrentFile(3) returns number of bytes read, so the current code only processes the file if no bytes were read (UNZ_OK is a #define equal to 0). I've altered the break to occur only on unsuccessful read, (when unzReadCurrentFile(3) returns less than zero), and added an error message for when an unsuccessful read occurs. --- editor/export_template_manager.cpp | 8 ++------ editor/project_manager.cpp | 4 +--- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/editor/export_template_manager.cpp b/editor/export_template_manager.cpp index 06c179e77c0..b34b08b5dea 100644 --- a/editor/export_template_manager.cpp +++ b/editor/export_template_manager.cpp @@ -404,9 +404,7 @@ bool ExportTemplateManager::_install_file_selected(const String &p_file, bool p_ // Read. unzOpenCurrentFile(pkg); ret = unzReadCurrentFile(pkg, data.ptrw(), data.size()); - if (ret != UNZ_OK) { - break; - } + ERR_BREAK_MSG(ret < 0, vformat("An error occurred while attempting to read from file: %s. This file will not be used.", file)); unzCloseCurrentFile(pkg); String data_str; @@ -478,9 +476,7 @@ bool ExportTemplateManager::_install_file_selected(const String &p_file, bool p_ // Read unzOpenCurrentFile(pkg); ret = unzReadCurrentFile(pkg, data.ptrw(), data.size()); - if (ret != UNZ_OK) { - break; - } + ERR_BREAK_MSG(ret < 0, vformat("An error occurred while attempting to read from file: %s. This file will not be used.", file)); unzCloseCurrentFile(pkg); String base_dir = file_path.get_base_dir().trim_suffix("/"); diff --git a/editor/project_manager.cpp b/editor/project_manager.cpp index 08b968edb6f..4ca0f18f0e6 100644 --- a/editor/project_manager.cpp +++ b/editor/project_manager.cpp @@ -557,9 +557,7 @@ private: //read unzOpenCurrentFile(pkg); ret = unzReadCurrentFile(pkg, data.ptrw(), data.size()); - if (ret != UNZ_OK) { - break; - } + ERR_BREAK_MSG(ret < 0, vformat("An error occurred while attempting to read from file: %s. This file will not be used.", rel_path)); unzCloseCurrentFile(pkg); Ref f = FileAccess::open(dir.plus_file(rel_path), FileAccess::WRITE);