代码拉取完成,页面将自动刷新
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "resource_module.h"
#include <algorithm>
#include <iostream>
#include "resource_compiler_factory.h"
#include "restool_errors.h"
namespace OHOS {
namespace Global {
namespace Restool {
using namespace std;
const vector<ResType> ResourceModule::SCAN_SEQ = {
ResType::ELEMENT,
ResType::MEDIA,
ResType::PROF,
};
ResourceModule::ResourceModule(const string &modulePath, const string &moduleOutput, const string &moduleName)
: modulePath_(modulePath), moduleOutput_(moduleOutput), moduleName_(moduleName)
{
}
uint32_t ResourceModule::ScanResource(bool isHap)
{
if (!ResourceUtil::FileExist(modulePath_)) {
return RESTOOL_SUCCESS;
}
ResourceDirectory directory;
if (!directory.ScanResources(modulePath_, [this](const DirectoryInfo &info) -> bool {
scanDirs_[info.dirType].push_back(info);
return true;
})) {
return RESTOOL_ERROR;
}
for (const auto &type : SCAN_SEQ) {
const auto &item = scanDirs_.find(type);
if (item == scanDirs_.end() || item->second.empty()) {
continue;
}
unique_ptr<IResourceCompiler> resourceCompiler =
ResourceCompilerFactory::CreateCompiler(type, moduleOutput_, isHap);
resourceCompiler->SetModuleName(moduleName_);
if (resourceCompiler->Compile(item->second) != RESTOOL_SUCCESS) {
return RESTOOL_ERROR;
}
Push(resourceCompiler->GetResult());
}
return RESTOOL_SUCCESS;
}
const map<int64_t, vector<ResourceItem>> &ResourceModule::GetOwner() const
{
return owner_;
}
const map<ResType, vector<DirectoryInfo>> &ResourceModule::GetScanDirectorys() const
{
return scanDirs_;
}
uint32_t ResourceModule::MergeResourceItem(map<int64_t, vector<ResourceItem>> &alls,
const map<int64_t, vector<ResourceItem>> &other, bool tipError)
{
for (const auto &iter : other) {
auto result = alls.emplace(iter.first, iter.second);
if (result.second) {
continue;
}
for (const auto &resourceItem : iter.second) {
auto ret = find_if(result.first->second.begin(), result.first->second.end(), [&resourceItem](auto &iter) {
return resourceItem.GetLimitKey() == iter.GetLimitKey();
});
if (ret == result.first->second.end()) {
result.first->second.push_back(resourceItem);
continue;
}
if (ret->IsCoverable()) { // overlap the hap resource by new resource
*ret = resourceItem;
continue;
}
if (tipError) {
PrintError(GetError(ERR_CODE_RESOURCE_DUPLICATE)
.FormatCause(resourceItem.GetName().c_str(), ret->GetFilePath().c_str(),
resourceItem.GetFilePath().c_str()));
return RESTOOL_ERROR;
}
cout << "Warning: '"<< resourceItem.GetName() <<"' conflict, first declared.";
cout << NEW_LINE_PATH << ret->GetFilePath() << endl;
cout << "but declared again." << NEW_LINE_PATH << resourceItem.GetFilePath() << endl;
}
}
return RESTOOL_SUCCESS;
}
// below private
void ResourceModule::Push(const map<int64_t, std::vector<ResourceItem>> &other)
{
for (const auto &iter : other) {
owner_.emplace(iter.first, iter.second);
}
}
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。