From 9fe8eeb8fae144d942a299a816f022826665dab0 Mon Sep 17 00:00:00 2001 From: sunjie Date: Wed, 12 Mar 2025 15:01:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20dump?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: sunjie Change-Id: Id9b8bf46a543639c32dbcd0468ba3a18708d5248 --- src/resource_dumper.cpp | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/src/resource_dumper.cpp b/src/resource_dumper.cpp index ec106f3..7cb3b0a 100644 --- a/src/resource_dumper.cpp +++ b/src/resource_dumper.cpp @@ -69,6 +69,8 @@ uint32_t ResourceDumper::LoadHap() } if (ReadFileFromZip(zipFile, "resources.index", buffer, len) != RESTOOL_SUCCESS) { unzClose(zipFile); + PrintError(GetError(ERR_CODE_PARSE_HAP_ERROR) + .FormatCause("read resources.index failed").SetPosition(inputPath_)); return RESTOOL_ERROR; } unzClose(zipFile); @@ -108,40 +110,26 @@ uint32_t ResourceDumper::ReadFileFromZip( { unz_file_info fileInfo; if (unzLocateFile2(zipFile, fileName, 1) != UNZ_OK) { - std::string msg; - msg.append("file not found: ").append(fileName); - PrintError(GetError(ERR_CODE_PARSE_HAP_ERROR).FormatCause(msg.c_str()).SetPosition(inputPath_)); return RESTOOL_ERROR; } char filenameInZip[256]; int err = unzGetCurrentFileInfo(zipFile, &fileInfo, filenameInZip, sizeof(filenameInZip), nullptr, 0, nullptr, 0); if (err != UNZ_OK) { - std::string msg; - msg.append("get file info error: ").append(std::to_string(err)); - msg.append(", filename: ").append(fileName); - PrintError(GetError(ERR_CODE_PARSE_HAP_ERROR).FormatCause(msg.c_str()).SetPosition(inputPath_)); return RESTOOL_ERROR; } - len = fileInfo.compressed_size; + len = fileInfo.uncompressed_size; buffer = std::make_unique(len); if (!buffer) { - PrintError(GetError(ERR_CODE_PARSE_HAP_ERROR).FormatCause("allocating memory failed")); return RESTOOL_ERROR; } err = unzOpenCurrentFilePassword(zipFile, nullptr); if (err != UNZ_OK) { - std::string msg; - msg.append("unzOpenCurrentFilePassword error: ").append(std::to_string(err)); - PrintError(GetError(ERR_CODE_PARSE_HAP_ERROR).FormatCause(msg.c_str())); return RESTOOL_ERROR; } err = unzReadCurrentFile(zipFile, buffer.get(), len); if (err < 0) { - std::string msg; - msg.append("unzReadCurrentFile error: ").append(std::to_string(err)); - PrintError(GetError(ERR_CODE_PARSE_HAP_ERROR).FormatCause(msg.c_str())); return RESTOOL_ERROR; } return RESTOOL_SUCCESS;