Browse Source

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.
Josh Kabo 3 years ago
parent
commit
0bff53135a
2 changed files with 3 additions and 9 deletions
  1. 2 6
      editor/export_template_manager.cpp
  2. 1 3
      editor/project_manager.cpp

+ 2 - 6
editor/export_template_manager.cpp

@@ -404,9 +404,7 @@ bool ExportTemplateManager::_install_file_selected(const String &p_file, bool p_
 			// Read.
 			// Read.
 			unzOpenCurrentFile(pkg);
 			unzOpenCurrentFile(pkg);
 			ret = unzReadCurrentFile(pkg, data.ptrw(), data.size());
 			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);
 			unzCloseCurrentFile(pkg);
 
 
 			String data_str;
 			String data_str;
@@ -478,9 +476,7 @@ bool ExportTemplateManager::_install_file_selected(const String &p_file, bool p_
 		// Read
 		// Read
 		unzOpenCurrentFile(pkg);
 		unzOpenCurrentFile(pkg);
 		ret = unzReadCurrentFile(pkg, data.ptrw(), data.size());
 		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);
 		unzCloseCurrentFile(pkg);
 
 
 		String base_dir = file_path.get_base_dir().trim_suffix("/");
 		String base_dir = file_path.get_base_dir().trim_suffix("/");

+ 1 - 3
editor/project_manager.cpp

@@ -557,9 +557,7 @@ private:
 							//read
 							//read
 							unzOpenCurrentFile(pkg);
 							unzOpenCurrentFile(pkg);
 							ret = unzReadCurrentFile(pkg, data.ptrw(), data.size());
 							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);
 							unzCloseCurrentFile(pkg);
 
 
 							Ref<FileAccess> f = FileAccess::open(dir.plus_file(rel_path), FileAccess::WRITE);
 							Ref<FileAccess> f = FileAccess::open(dir.plus_file(rel_path), FileAccess::WRITE);