diff --git a/BUILD.gn b/BUILD.gn index 8d9bcd0..532a37f 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -18,6 +18,7 @@ import("./restool.gni") ohos_executable("restool") { sources = [ "src/append_compiler.cpp", + "src/binary_file_packer.cpp", "src/cmd_parser.cpp", "src/compression_parser.cpp", "src/config_parser.cpp", @@ -31,7 +32,6 @@ ohos_executable("restool") { "src/id_worker.cpp", "src/json_compiler.cpp", "src/key_parser.cpp", - "src/rawfile_resfile_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/include/thread_pool.h b/include/thread_pool.h index 5139a91..3c5c7dc 100644 --- a/include/thread_pool.h +++ b/include/thread_pool.h @@ -16,8 +16,6 @@ #ifndef OHOS_RESTOOL_THREAD_POOL_H #define OHOS_RESTOOL_THREAD_POOL_H -#include "no_copy_able.h" - #include #include #include @@ -30,14 +28,14 @@ namespace OHOS { namespace Global { namespace Restool { -class ThreadPool : public NoCopyable { +class ThreadPool { public: /** * @brief Creates a thread pool with specify thread count * @param threadCount the count of threads to be created */ explicit ThreadPool(const size_t threadCount); - ~ThreadPool() override; + ~ThreadPool(); /** * @brief Start the thread pool @@ -55,7 +53,7 @@ public: * @param args the args of the function */ template - auto Enqueue(F &&f, Args &&...args) -> std::future::type>; + std::future::type> Enqueue(F &&f, Args &&...args); private: void WorkInThread(); @@ -69,7 +67,7 @@ private: }; template -auto ThreadPool::Enqueue(F &&f, Args &&...args) -> std::future::type> +std::future::type> ThreadPool::Enqueue(F &&f, Args &&...args) { using return_type = typename std::result_of::type; using p_task = std::packaged_task; 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;