diff --git a/BUILD.gn b/BUILD.gn index 8d9bcd0..e868a4a 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -31,7 +31,7 @@ ohos_executable("restool") { "src/id_worker.cpp", "src/json_compiler.cpp", "src/key_parser.cpp", - "src/rawfile_resfile_packer.cpp", + "src/binary_file_packer.cpp", "src/reference_parser.cpp", "src/resconfig_parser.cpp", "src/resource_append.cpp", diff --git a/include/rawfile_resfile_packer.h b/include/binary_file_packer.h similarity index 63% rename from include/rawfile_resfile_packer.h rename to include/binary_file_packer.h index cc795da..bfc64c4 100644 --- a/include/rawfile_resfile_packer.h +++ b/include/binary_file_packer.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef OHOS_RESTOOL_RAWFILE_RESFILE_PACKER_H -#define OHOS_RESTOOL_RAWFILE_RESFILE_PACKER_H +#ifndef OHOS_RESTOOL_BINARY_FILE_PACKER_H +#define OHOS_RESTOOL_BINARY_FILE_PACKER_H #include "cmd_parser.h" #include "resource_util.h" @@ -23,16 +23,16 @@ namespace OHOS { namespace Global { namespace Restool { -class RawFileResFilePacker { +class BinaryFilePacker { public: - explicit RawFileResFilePacker(const PackageParser &packageParser, const std::string &moduleName); - ~RawFileResFilePacker(); - std::future CopyRawFileOrResFileAsync(const std::vector &inputs); + explicit BinaryFilePacker(const PackageParser &packageParser, const std::string &moduleName); + ~BinaryFilePacker(); + std::future CopyBinaryFileAsync(const std::vector &inputs); private: - uint32_t CopyRawFileOrResFile(const std::vector &inputs); - uint32_t CopyRawFileOrResFile(const std::string &filePath, const std::string &fileType); - uint32_t CopyRawFileOrResFileImpl(const std::string &src, const std::string &dst); + uint32_t CopyBinaryFile(const std::vector &inputs); + uint32_t CopyBinaryFile(const std::string &filePath, const std::string &fileType); + uint32_t CopyBinaryFileImpl(const std::string &src, const std::string &dst); uint32_t CopySingleFile(const std::string &path, std::string &subPath); PackageParser packageParser_; std::string moduleName_; diff --git a/src/rawfile_resfile_packer.cpp b/src/binary_file_packer.cpp similarity index 79% rename from src/rawfile_resfile_packer.cpp rename to src/binary_file_packer.cpp index e60e7e6..d25d76d 100644 --- a/src/rawfile_resfile_packer.cpp +++ b/src/binary_file_packer.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "rawfile_resfile_packer.h" +#include "binary_file_packer.h" #include "compression_parser.h" #include "restool_errors.h" @@ -23,34 +23,34 @@ namespace Global { namespace Restool { using namespace std; -RawFileResFilePacker::RawFileResFilePacker(const PackageParser &packageParser, const std::string &moduleName) +BinaryFilePacker::BinaryFilePacker(const PackageParser &packageParser, const std::string &moduleName) : packageParser_(packageParser), moduleName_(moduleName), threadPool_(ThreadPool(THREAD_POOL_SIZE)) { threadPool_.Start(); } -RawFileResFilePacker::~RawFileResFilePacker() +BinaryFilePacker::~BinaryFilePacker() { threadPool_.Stop(); } -std::future RawFileResFilePacker::CopyRawFileOrResFileAsync(const std::vector &inputs) +std::future BinaryFilePacker::CopyBinaryFileAsync(const std::vector &inputs) { - auto func = [this](const std::vector &inputs) { return this->CopyRawFileOrResFile(inputs); }; + auto func = [this](const std::vector &inputs) { return this->CopyBinaryFile(inputs); }; std::future res = threadPool_.Enqueue(func, inputs); return res; } -uint32_t RawFileResFilePacker::CopyRawFileOrResFile(const vector &inputs) +uint32_t BinaryFilePacker::CopyBinaryFile(const vector &inputs) { for (const auto &input : inputs) { string rawfilePath = FileEntry::FilePath(input).Append(RAW_FILE_DIR).GetPath(); - if (CopyRawFileOrResFile(rawfilePath, RAW_FILE_DIR) == RESTOOL_ERROR) { + if (CopyBinaryFile(rawfilePath, RAW_FILE_DIR) == RESTOOL_ERROR) { cerr << "Error: copy raw file failed." << NEW_LINE_PATH << rawfilePath << endl; return RESTOOL_ERROR; } string resfilePath = FileEntry::FilePath(input).Append(RES_FILE_DIR).GetPath(); - if (CopyRawFileOrResFile(resfilePath, RES_FILE_DIR) == RESTOOL_ERROR) { + if (CopyBinaryFile(resfilePath, RES_FILE_DIR) == RESTOOL_ERROR) { cerr << "Error: copy res file failed." << NEW_LINE_PATH << resfilePath << endl; return RESTOOL_ERROR; } @@ -64,7 +64,7 @@ uint32_t RawFileResFilePacker::CopyRawFileOrResFile(const vector &inputs return RESTOOL_SUCCESS; } -uint32_t RawFileResFilePacker::CopyRawFileOrResFile(const string &filePath, const string &fileType) +uint32_t BinaryFilePacker::CopyBinaryFile(const string &filePath, const string &fileType) { if (!ResourceUtil::FileExist(filePath)) { return RESTOOL_SUCCESS; @@ -76,13 +76,13 @@ uint32_t RawFileResFilePacker::CopyRawFileOrResFile(const string &filePath, cons } string dst = FileEntry::FilePath(packageParser_.GetOutput()).Append(RESOURCES_DIR).Append(fileType).GetPath(); - if (CopyRawFileOrResFileImpl(filePath, dst) != RESTOOL_SUCCESS) { + if (CopyBinaryFileImpl(filePath, dst) != RESTOOL_SUCCESS) { return RESTOOL_ERROR; } return RESTOOL_SUCCESS; } -uint32_t RawFileResFilePacker::CopyRawFileOrResFileImpl(const string &src, const string &dst) +uint32_t BinaryFilePacker::CopyBinaryFileImpl(const string &src, const string &dst) { if (!ResourceUtil::CreateDirs(dst)) { cerr << "Error: copy rawfile of resfile, create dirs failed." << NEW_LINE_PATH << dst << endl; @@ -101,7 +101,7 @@ uint32_t RawFileResFilePacker::CopyRawFileOrResFileImpl(const string &src, const string subPath = FileEntry::FilePath(dst).Append(filename).GetPath(); if (!entry->IsFile()) { - if (CopyRawFileOrResFileImpl(entry->GetFilePath().GetPath(), subPath) != RESTOOL_SUCCESS) { + if (CopyBinaryFileImpl(entry->GetFilePath().GetPath(), subPath) != RESTOOL_SUCCESS) { return RESTOOL_ERROR; } continue; @@ -119,7 +119,7 @@ uint32_t RawFileResFilePacker::CopyRawFileOrResFileImpl(const string &src, const return RESTOOL_SUCCESS; } -uint32_t RawFileResFilePacker::CopySingleFile(const std::string &path, std::string &subPath) +uint32_t BinaryFilePacker::CopySingleFile(const std::string &path, std::string &subPath) { if (moduleName_ == "har" || CompressionParser::GetCompressionParser()->GetDefaultCompress()) { if (!ResourceUtil::CopyFileInner(path, subPath)) { diff --git a/src/resource_pack.cpp b/src/resource_pack.cpp index b95ce67..1d76700 100644 --- a/src/resource_pack.cpp +++ b/src/resource_pack.cpp @@ -23,7 +23,7 @@ #include "resource_merge.h" #include "resource_table.h" #include "compression_parser.h" -#include "rawfile_resfile_packer.h" +#include "binary_file_packer.h" namespace OHOS { namespace Global { @@ -293,8 +293,8 @@ uint32_t ResourcePack::PackNormal() return RESTOOL_ERROR; } - RawFileResFilePacker rawFilePacker(packageParser_, moduleName_); - std::future copyFuture = rawFilePacker.CopyRawFileOrResFileAsync(resourceMerge.GetInputs()); + BinaryFilePacker rawFilePacker(packageParser_, moduleName_); + std::future copyFuture = rawFilePacker.CopyBinaryFileAsync(resourceMerge.GetInputs()); if (ScanResources(resourceMerge.GetInputs(), packageParser_.GetOutput()) != RESTOOL_SUCCESS) { return RESTOOL_ERROR;