mirror of
https://github.com/openharmony/developtools_global_resource_tool.git
synced 2026-07-18 17:24:42 -04:00
@@ -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",
|
||||
|
||||
@@ -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<uint32_t> CopyRawFileOrResFileAsync(const std::vector<std::string> &inputs);
|
||||
explicit BinaryFilePacker(const PackageParser &packageParser, const std::string &moduleName);
|
||||
~BinaryFilePacker();
|
||||
std::future<uint32_t> CopyBinaryFileAsync(const std::vector<std::string> &inputs);
|
||||
|
||||
private:
|
||||
uint32_t CopyRawFileOrResFile(const std::vector<std::string> &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<std::string> &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_;
|
||||
@@ -16,8 +16,6 @@
|
||||
#ifndef OHOS_RESTOOL_THREAD_POOL_H
|
||||
#define OHOS_RESTOOL_THREAD_POOL_H
|
||||
|
||||
#include "no_copy_able.h"
|
||||
|
||||
#include <condition_variable>
|
||||
#include <functional>
|
||||
#include <future>
|
||||
@@ -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 <class F, class... Args>
|
||||
auto Enqueue(F &&f, Args &&...args) -> std::future<typename std::result_of<F(Args...)>::type>;
|
||||
std::future<typename std::result_of<F(Args...)>::type> Enqueue(F &&f, Args &&...args);
|
||||
|
||||
private:
|
||||
void WorkInThread();
|
||||
@@ -69,7 +67,7 @@ private:
|
||||
};
|
||||
|
||||
template <typename F, typename... Args>
|
||||
auto ThreadPool::Enqueue(F &&f, Args &&...args) -> std::future<typename std::result_of<F(Args...)>::type>
|
||||
std::future<typename std::result_of<F(Args...)>::type> ThreadPool::Enqueue(F &&f, Args &&...args)
|
||||
{
|
||||
using return_type = typename std::result_of<F(Args...)>::type;
|
||||
using p_task = std::packaged_task<return_type()>;
|
||||
|
||||
@@ -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<uint32_t> RawFileResFilePacker::CopyRawFileOrResFileAsync(const std::vector<std::string> &inputs)
|
||||
std::future<uint32_t> BinaryFilePacker::CopyBinaryFileAsync(const std::vector<std::string> &inputs)
|
||||
{
|
||||
auto func = [this](const std::vector<std::string> &inputs) { return this->CopyRawFileOrResFile(inputs); };
|
||||
auto func = [this](const std::vector<std::string> &inputs) { return this->CopyBinaryFile(inputs); };
|
||||
std::future<uint32_t> res = threadPool_.Enqueue(func, inputs);
|
||||
return res;
|
||||
}
|
||||
|
||||
uint32_t RawFileResFilePacker::CopyRawFileOrResFile(const vector<string> &inputs)
|
||||
uint32_t BinaryFilePacker::CopyBinaryFile(const vector<string> &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<string> &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)) {
|
||||
@@ -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<uint32_t> copyFuture = rawFilePacker.CopyRawFileOrResFileAsync(resourceMerge.GetInputs());
|
||||
BinaryFilePacker rawFilePacker(packageParser_, moduleName_);
|
||||
std::future<uint32_t> copyFuture = rawFilePacker.CopyBinaryFileAsync(resourceMerge.GetInputs());
|
||||
|
||||
if (ScanResources(resourceMerge.GetInputs(), packageParser_.GetOutput()) != RESTOOL_SUCCESS) {
|
||||
return RESTOOL_ERROR;
|
||||
|
||||
Reference in New Issue
Block a user