mirror of
https://github.com/openharmony/developtools_global_resource_tool.git
synced 2026-07-19 11:31:44 -04:00
@@ -19,6 +19,7 @@
|
||||
#include "resource_util.h"
|
||||
#include "restool_errors.h"
|
||||
#include "compression_parser.h"
|
||||
#include "thread_pool.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Global {
|
||||
@@ -32,6 +33,24 @@ GenericCompiler::~GenericCompiler()
|
||||
{
|
||||
}
|
||||
|
||||
uint32_t GenericCompiler::CompileFiles(const std::vector<FileInfo> &fileInfos)
|
||||
{
|
||||
cout << "Info: GenericCompiler::CompileFiles" << endl;
|
||||
ThreadPool pool(THREAD_POOL_SIZE);
|
||||
pool.Start();
|
||||
std::vector<std::future<uint32_t>> results;
|
||||
for (const auto &fileInfo : fileInfos) {
|
||||
auto taskFunc = [this](const FileInfo &fileInfo) { return this->CompileSingleFile(fileInfo); };
|
||||
results.push_back(pool.Enqueue(taskFunc, fileInfo));
|
||||
}
|
||||
for (auto &ret : results) {
|
||||
if (ret.get() != RESTOOL_SUCCESS) {
|
||||
return RESTOOL_ERROR;
|
||||
}
|
||||
}
|
||||
return RESTOOL_SUCCESS;
|
||||
}
|
||||
|
||||
uint32_t GenericCompiler::CompileSingleFile(const FileInfo &fileInfo)
|
||||
{
|
||||
if (IsIgnore(fileInfo)) {
|
||||
@@ -51,6 +70,7 @@ uint32_t GenericCompiler::CompileSingleFile(const FileInfo &fileInfo)
|
||||
|
||||
bool GenericCompiler::PostMediaFile(const FileInfo &fileInfo, const std::string &output)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
ResourceItem resourceItem(fileInfo.filename, fileInfo.keyParams, type_);
|
||||
resourceItem.SetFilePath(fileInfo.filePath);
|
||||
resourceItem.SetLimitKey(fileInfo.limitKey);
|
||||
@@ -79,6 +99,7 @@ string GenericCompiler::GetOutputFilePath(const FileInfo &fileInfo) const
|
||||
|
||||
bool GenericCompiler::IsIgnore(const FileInfo &fileInfo)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
string output = GetOutputFilePath(fileInfo);
|
||||
if (!g_resourceSet.emplace(output).second) {
|
||||
cerr << "Warning: '" << fileInfo.filePath << "' is defined repeatedly." << endl;
|
||||
@@ -91,6 +112,7 @@ bool GenericCompiler::CopyMediaFile(const FileInfo &fileInfo, std::string &outpu
|
||||
{
|
||||
string outputFolder = GetOutputFolder(fileInfo);
|
||||
if (!ResourceUtil::CreateDirs(outputFolder)) {
|
||||
cerr << "Error: CopyMediaFile create dirs failed." << NEW_LINE_PATH << outputFolder << endl;
|
||||
return false;
|
||||
}
|
||||
output = GetOutputFilePath(fileInfo);
|
||||
|
||||
Reference in New Issue
Block a user