mirror of
https://github.com/openharmony/developtools_global_resource_tool.git
synced 2026-07-18 09:14:48 -04:00
@@ -45,7 +45,6 @@ ohos_executable("restool") {
|
||||
"src/resource_util.cpp",
|
||||
"src/restool.cpp",
|
||||
"src/select_compile_parse.cpp",
|
||||
"src/task_handle.cpp",
|
||||
"src/thread_pool.cpp",
|
||||
"src/translatable_parser.cpp",
|
||||
]
|
||||
|
||||
@@ -29,7 +29,7 @@ public:
|
||||
~BinaryFilePacker();
|
||||
std::future<uint32_t> CopyBinaryFileAsync(const std::vector<std::string> &inputs);
|
||||
void StopCopy();
|
||||
void SetCopyHapMode(bool state);
|
||||
void SetCopyHap(bool state);
|
||||
|
||||
private:
|
||||
uint32_t CopyBinaryFile(const std::vector<std::string> &inputs);
|
||||
@@ -37,12 +37,13 @@ private:
|
||||
uint32_t CopyBinaryFileImpl(const std::string &src, const std::string &dst);
|
||||
uint32_t CopySingleFile(const std::string &path, std::string &subPath);
|
||||
uint32_t CopyBinaryFileWithHap(const std::vector<std::string> &inputs);
|
||||
bool IsDefinedFile(const std::unique_ptr<FileEntry> &entry, std::string subPath);
|
||||
PackageParser packageParser_;
|
||||
std::string moduleName_;
|
||||
ThreadPool threadPool_;
|
||||
std::vector<std::future<uint32_t>> copyResults_;
|
||||
std::atomic<bool> stopCopy_{false};
|
||||
bool copyHapMode_{false};
|
||||
bool copyHap_{false};
|
||||
std::mutex mutex_;
|
||||
};
|
||||
} // namespace Restool
|
||||
|
||||
@@ -57,8 +57,7 @@ public:
|
||||
bool IsTargetConfig() const;
|
||||
const std::vector<std::string> &GetSysIdDefinedPaths() const;
|
||||
const std::string &GetCompressionPath() const;
|
||||
bool ExistIndex();
|
||||
bool GetOverlap();
|
||||
bool ExistHapInput();
|
||||
|
||||
private:
|
||||
void InitCommand();
|
||||
@@ -114,7 +113,6 @@ private:
|
||||
bool isTtargetConfig_;
|
||||
std::vector<std::string> sysIdDefinedPaths_;
|
||||
std::string compressionPath_;
|
||||
bool overlap_ = false;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
|
||||
@@ -35,10 +35,10 @@ public:
|
||||
{
|
||||
moduleName_ = moduleName;
|
||||
};
|
||||
void SetHapItems();
|
||||
void MarkItemsAsHap();
|
||||
uint32_t MergeResourceItem(const std::map<int64_t, std::vector<ResourceItem>> &resourceInfos);
|
||||
bool ScaleIcons(const std::string &output, const std::map<std::string, std::set<uint32_t>> &iconMap);
|
||||
void SetHapMode(bool state);
|
||||
void SetScanHap(bool state);
|
||||
|
||||
private:
|
||||
uint32_t ScanModule(const std::string &input, const std::string &output);
|
||||
@@ -49,7 +49,7 @@ private:
|
||||
// id, resource items
|
||||
std::map<int64_t, std::vector<ResourceItem>> items_;
|
||||
std::string moduleName_;
|
||||
bool hapMode_ = false;
|
||||
bool scanHap_ = false;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ public:
|
||||
void SetModuleName(const std::string &moduleName);
|
||||
uint32_t CompileForAppend(const FileInfo &fileInfo);
|
||||
const std::map<std::pair<ResType, std::string>, std::vector<ResourceItem>> &GetResourceItems() const;
|
||||
void SetHapRes();
|
||||
void SetHapRes(bool state);
|
||||
|
||||
protected:
|
||||
virtual uint32_t CompileSingleFile(const FileInfo &fileInfo);
|
||||
@@ -43,7 +43,7 @@ protected:
|
||||
ResType type_;
|
||||
std::string output_;
|
||||
std::string moduleName_;
|
||||
bool isHapRes_ = false;
|
||||
bool hapRes_ = false;
|
||||
|
||||
// id, resource items
|
||||
std::map<int64_t, std::vector<ResourceItem>> resourceInfos_;
|
||||
|
||||
@@ -34,7 +34,7 @@ public:
|
||||
void SetFilePath(const std::string &filePath);
|
||||
void SetLimitKey(const std::string &limitKey);
|
||||
void SetName(const std::string &name);
|
||||
void SetHapRes();
|
||||
void MarkHapRes();
|
||||
|
||||
const int8_t *GetData() const;
|
||||
uint32_t GetDataLength() const;
|
||||
@@ -43,7 +43,6 @@ public:
|
||||
const std::vector<KeyParam> &GetKeyParam() const;
|
||||
const std::string &GetFilePath() const;
|
||||
const std::string &GetLimitKey() const;
|
||||
|
||||
bool IsHapRes() const;
|
||||
|
||||
ResourceItem &operator=(const ResourceItem &other);
|
||||
@@ -57,7 +56,7 @@ private:
|
||||
ResType type_;
|
||||
std::string filePath_;
|
||||
std::string limitKey_;
|
||||
bool isHapRes_ = false;
|
||||
bool hapRes_ = false;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
+10
-5
@@ -27,6 +27,11 @@
|
||||
namespace OHOS {
|
||||
namespace Global {
|
||||
namespace Restool {
|
||||
enum class PackType {
|
||||
NORMAL = 1,
|
||||
OVERLAP
|
||||
};
|
||||
|
||||
class ResourcePack {
|
||||
public:
|
||||
explicit ResourcePack(const PackageParser &packageParser);
|
||||
@@ -34,7 +39,7 @@ public:
|
||||
uint32_t Package();
|
||||
|
||||
private:
|
||||
uint32_t Init();
|
||||
uint32_t InitResourcePack();
|
||||
uint32_t InitModule();
|
||||
void InitHeaderCreater();
|
||||
uint32_t InitOutput() const;
|
||||
@@ -46,12 +51,12 @@ private:
|
||||
uint32_t GenerateJsHeader(const std::string &headerPath) const;
|
||||
uint32_t GenerateConfigJson();
|
||||
uint32_t ScanResources(const std::vector<std::string> &inputs, const std::string &output);
|
||||
uint32_t PackNormal();
|
||||
uint32_t Pack();
|
||||
uint32_t PackResources(const ResourceMerge &resourceMerge);
|
||||
uint32_t LoadHapResources();
|
||||
uint32_t PackPreview();
|
||||
uint32_t PackAppend();
|
||||
uint32_t PackCombine();
|
||||
uint32_t PackOverlap();
|
||||
uint32_t PackQualifierResources(const ResourceMerge &resourceMerge);
|
||||
uint32_t HandleFeature();
|
||||
uint32_t FindResourceItems(const std::map<int64_t, std::vector<ResourceItem>> &resInfoLocal,
|
||||
std::vector<ResourceItem> &items, int64_t id) const;
|
||||
@@ -61,12 +66,12 @@ private:
|
||||
void CheckConfigJson();
|
||||
void CheckConfigJsonForCombine(ResourceAppend &resourceAppend);
|
||||
bool CopyIcon(std::string &dataPath, const std::string &idName, std::string &fileName) const;
|
||||
uint32_t LoadHapResources();
|
||||
PackageParser packageParser_;
|
||||
std::string moduleName_;
|
||||
using HeaderCreater = std::function<uint32_t(const std::string&)>;
|
||||
std::map<std::string, HeaderCreater> headerCreaters_;
|
||||
ConfigParser configJson_;
|
||||
PackType packType_ = PackType::NORMAL;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_RESTOOL_TASK_HANDLE_H
|
||||
#define OHOS_RESTOOL_TASK_HANDLE_H
|
||||
|
||||
#include "cmd_parser.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Global {
|
||||
namespace Restool {
|
||||
class TaskHandle {
|
||||
public:
|
||||
TaskHandle() {};
|
||||
~TaskHandle() {};
|
||||
uint32_t HandlePackage(const PackageParser &packageParser);
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
+27
-19
@@ -39,14 +39,14 @@ void BinaryFilePacker::StopCopy()
|
||||
stopCopy_.store(true);
|
||||
}
|
||||
|
||||
void BinaryFilePacker::SetCopyHapMode(bool state)
|
||||
void BinaryFilePacker::SetCopyHap(bool state)
|
||||
{
|
||||
copyHapMode_ = state;
|
||||
copyHap_ = state;
|
||||
}
|
||||
|
||||
std::future<uint32_t> BinaryFilePacker::CopyBinaryFileAsync(const std::vector<std::string> &inputs)
|
||||
{
|
||||
if (copyHapMode_) {
|
||||
if (copyHap_) {
|
||||
auto func = [this](const vector<string> &inputs) { return this->CopyBinaryFileWithHap(inputs); };
|
||||
future<uint32_t> res = threadPool_.Enqueue(func, inputs);
|
||||
return res;
|
||||
@@ -58,12 +58,13 @@ std::future<uint32_t> BinaryFilePacker::CopyBinaryFileAsync(const std::vector<st
|
||||
|
||||
uint32_t BinaryFilePacker::CopyBinaryFileWithHap(const vector<string> &inputs)
|
||||
{
|
||||
vector<string> hapResource(inputs.begin(), inputs.begin() + 1);
|
||||
vector<string> hapResource{inputs[0]};
|
||||
if (CopyBinaryFile(hapResource) != RESTOOL_SUCCESS) {
|
||||
return RESTOOL_ERROR;
|
||||
}
|
||||
copyResults_.clear();
|
||||
SetCopyHapMode(false);
|
||||
SetCopyHap(false);
|
||||
|
||||
vector<string> resource(inputs.begin() + 1, inputs.end());
|
||||
if (CopyBinaryFile(resource) != RESTOOL_SUCCESS) {
|
||||
return RESTOOL_ERROR;
|
||||
@@ -141,20 +142,7 @@ uint32_t BinaryFilePacker::CopyBinaryFileImpl(const string &src, const string &d
|
||||
continue;
|
||||
}
|
||||
|
||||
bool hapEmplaceSuccess = true;
|
||||
bool gResEmplaceSuccess = true;
|
||||
lock_guard<mutex> lock(mutex_);
|
||||
if (copyHapMode_) {
|
||||
hapEmplaceSuccess = g_hapResourceSet.emplace(subPath).second;
|
||||
gResEmplaceSuccess = g_resourceSet.emplace(subPath).second;
|
||||
} else if (g_hapResourceSet.count(subPath)) { // overlap the hap resource by new resource
|
||||
g_hapResourceSet.erase(subPath);
|
||||
} else {
|
||||
gResEmplaceSuccess = g_resourceSet.emplace(subPath).second;
|
||||
}
|
||||
|
||||
if (!hapEmplaceSuccess || !gResEmplaceSuccess) {
|
||||
cerr << "Warning: '" << entry->GetFilePath().GetPath() << "' is defined repeatedly." << endl;
|
||||
if (IsDefinedFile(entry, subPath)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -171,6 +159,26 @@ uint32_t BinaryFilePacker::CopyBinaryFileImpl(const string &src, const string &d
|
||||
return RESTOOL_SUCCESS;
|
||||
}
|
||||
|
||||
bool BinaryFilePacker::IsDefinedFile(const unique_ptr<FileEntry> &entry, string subPath)
|
||||
{
|
||||
lock_guard<mutex> lock(mutex_);
|
||||
bool resEmplaceSuccess = true;
|
||||
if (copyHap_) {
|
||||
g_hapResourceSet.emplace(subPath);
|
||||
g_resourceSet.emplace(subPath);
|
||||
} else if (g_hapResourceSet.count(subPath)) {
|
||||
g_hapResourceSet.erase(subPath);
|
||||
} else {
|
||||
resEmplaceSuccess = g_resourceSet.emplace(subPath).second;
|
||||
}
|
||||
|
||||
if (!resEmplaceSuccess) {
|
||||
cerr << "Warning: '" << entry->GetFilePath().GetPath() << "' is defined repeatedly." << endl;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32_t BinaryFilePacker::CopySingleFile(const std::string &path, std::string &subPath)
|
||||
{
|
||||
if (moduleName_ == "har" || CompressionParser::GetCompressionParser()->GetDefaultCompress()) {
|
||||
|
||||
+1
-7
@@ -444,25 +444,19 @@ const std::string &PackageParser::GetCompressionPath() const
|
||||
return compressionPath_;
|
||||
}
|
||||
|
||||
bool PackageParser::ExistIndex()
|
||||
bool PackageParser::ExistHapInput()
|
||||
{
|
||||
for (auto &input : inputs_) {
|
||||
string indexPath = ResourceUtil::GetMainPath(input).Append(RESOURCE_INDEX_FILE).GetPath();
|
||||
if (ResourceUtil::FileExist(indexPath)) {
|
||||
inputs_.erase(find(inputs_.begin(), inputs_.end(), input));
|
||||
inputs_.emplace(inputs_.begin(), input);
|
||||
overlap_ = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool PackageParser::GetOverlap()
|
||||
{
|
||||
return overlap_;
|
||||
}
|
||||
|
||||
void PackageParser::InitCommand()
|
||||
{
|
||||
using namespace placeholders;
|
||||
|
||||
@@ -42,17 +42,17 @@ uint32_t FileManager::ScanModules(const vector<string> &inputs, const string &ou
|
||||
if (!noBaseResource.empty()) {
|
||||
ResourceUtil::PrintWarningMsg(noBaseResource);
|
||||
}
|
||||
if (hapMode_) {
|
||||
SetHapItems();
|
||||
if (scanHap_) {
|
||||
MarkItemsAsHap();
|
||||
}
|
||||
return isHar || hapMode_ ? RESTOOL_SUCCESS : ParseReference(output);
|
||||
return isHar || scanHap_ ? RESTOOL_SUCCESS : ParseReference(output);
|
||||
}
|
||||
|
||||
void FileManager::SetHapItems()
|
||||
void FileManager::MarkItemsAsHap()
|
||||
{
|
||||
for (auto &item : items_) {
|
||||
for (auto &resourceItem : item.second) {
|
||||
resourceItem.SetHapRes();
|
||||
resourceItem.MarkHapRes();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -66,7 +66,7 @@ uint32_t FileManager::MergeResourceItem(const map<int64_t, vector<ResourceItem>>
|
||||
uint32_t FileManager::ScanModule(const string &input, const string &output)
|
||||
{
|
||||
ResourceModule resourceModule(input, output, moduleName_);
|
||||
if (resourceModule.ScanResource(hapMode_) != RESTOOL_SUCCESS) {
|
||||
if (resourceModule.ScanResource(scanHap_) != RESTOOL_SUCCESS) {
|
||||
return RESTOOL_ERROR;
|
||||
}
|
||||
MergeResourceItem(resourceModule.GetOwner());
|
||||
@@ -132,9 +132,9 @@ bool FileManager::ScaleIcons(const string &output, const std::map<std::string, s
|
||||
return true;
|
||||
}
|
||||
|
||||
void FileManager::SetHapMode(bool state)
|
||||
void FileManager::SetScanHap(bool state)
|
||||
{
|
||||
hapMode_ = state;
|
||||
scanHap_ = state;
|
||||
}
|
||||
|
||||
bool FileManager::ScaleIcon(const string &output, ResourceItem &item)
|
||||
|
||||
@@ -101,18 +101,17 @@ bool GenericCompiler::IsIgnore(const FileInfo &fileInfo)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
string output = GetOutputFilePath(fileInfo);
|
||||
bool hapEmplaceSuccess = true;
|
||||
bool gResEmplaceSuccess = true;
|
||||
if (isHapRes_) {
|
||||
hapEmplaceSuccess = g_hapResourceSet.emplace(output).second;
|
||||
gResEmplaceSuccess = g_resourceSet.emplace(output).second;
|
||||
} else if (g_hapResourceSet.count(output)) { // overlap the hap resource by new resource
|
||||
bool resEmplaceSuccess = true;
|
||||
if (hapRes_) {
|
||||
g_hapResourceSet.emplace(output);
|
||||
g_resourceSet.emplace(output);
|
||||
} else if (g_hapResourceSet.count(output)) {
|
||||
g_hapResourceSet.erase(output);
|
||||
} else {
|
||||
gResEmplaceSuccess = g_resourceSet.emplace(output).second;
|
||||
resEmplaceSuccess = g_resourceSet.emplace(output).second;
|
||||
}
|
||||
|
||||
if (!hapEmplaceSuccess || !gResEmplaceSuccess) {
|
||||
if (!resEmplaceSuccess) {
|
||||
cerr << "Warning: '" << fileInfo.filePath << "' is defined repeatedly." << endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -104,9 +104,9 @@ const map<pair<ResType, string>, vector<ResourceItem>> &IResourceCompiler::GetRe
|
||||
return nameInfos_;
|
||||
}
|
||||
|
||||
void IResourceCompiler::SetHapRes()
|
||||
void IResourceCompiler::SetHapRes(bool state)
|
||||
{
|
||||
isHapRes_ = true;
|
||||
hapRes_ = state;
|
||||
}
|
||||
|
||||
void IResourceCompiler::SetModuleName(const string &moduleName)
|
||||
|
||||
@@ -85,9 +85,9 @@ void ResourceItem::SetName(const string &name)
|
||||
name_ = name;
|
||||
}
|
||||
|
||||
void ResourceItem::SetHapRes()
|
||||
void ResourceItem::MarkHapRes()
|
||||
{
|
||||
isHapRes_ = true;
|
||||
hapRes_ = true;
|
||||
}
|
||||
|
||||
const int8_t *ResourceItem::GetData() const
|
||||
@@ -127,7 +127,7 @@ const string &ResourceItem::GetLimitKey() const
|
||||
|
||||
bool ResourceItem::IsHapRes() const
|
||||
{
|
||||
return isHapRes_;
|
||||
return hapRes_;
|
||||
}
|
||||
|
||||
ResourceItem &ResourceItem::operator=(const ResourceItem &other)
|
||||
@@ -157,7 +157,7 @@ void ResourceItem::CopyFrom(const ResourceItem &other)
|
||||
dataLen_ = other.dataLen_;
|
||||
filePath_ = other.filePath_;
|
||||
limitKey_ = other.limitKey_;
|
||||
isHapRes_ = other.isHapRes_;
|
||||
hapRes_ = other.hapRes_;
|
||||
if (!SetData(other.data_, other.dataLen_)) {
|
||||
ReleaseData();
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ uint32_t ResourceMerge::Init(const PackageParser &packageParser)
|
||||
continue;
|
||||
}
|
||||
ConfigParser::ModuleType moduleType = ConfigParser::ModuleType::NONE;
|
||||
if (!ResourceUtil::FileExist(configPath) || ResourceUtil::FileExist(indexPath)) {
|
||||
if (!ResourceUtil::FileExist(configPath)) {
|
||||
inputTypes[moduleType].push_back(resourceDir);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ uint32_t ResourceModule::ScanResource(bool isHap)
|
||||
FactoryResourceCompiler::CreateCompiler(type, moduleOutput_);
|
||||
resourceCompiler->SetModuleName(moduleName_);
|
||||
if (isHap) {
|
||||
resourceCompiler->SetHapRes();
|
||||
resourceCompiler->SetHapRes(true);
|
||||
}
|
||||
if (resourceCompiler->Compile(item->second) != RESTOOL_SUCCESS) {
|
||||
return RESTOOL_ERROR;
|
||||
|
||||
+63
-73
@@ -43,10 +43,10 @@ uint32_t ResourcePack::Package()
|
||||
return PackCombine();
|
||||
}
|
||||
|
||||
if (packageParser_.ExistIndex()) {
|
||||
return PackOverlap();
|
||||
if (packageParser_.ExistHapInput()) {
|
||||
packType_ = PackType::OVERLAP;
|
||||
}
|
||||
return PackNormal();
|
||||
return Pack();
|
||||
}
|
||||
|
||||
uint32_t ResourcePack::InitCompression()
|
||||
@@ -62,9 +62,13 @@ uint32_t ResourcePack::InitCompression()
|
||||
}
|
||||
|
||||
// below private founction
|
||||
uint32_t ResourcePack::Init()
|
||||
uint32_t ResourcePack::InitResourcePack()
|
||||
{
|
||||
InitHeaderCreater();
|
||||
if (InitCompression() != RESTOOL_SUCCESS) {
|
||||
return RESTOOL_ERROR;
|
||||
}
|
||||
|
||||
if (InitOutput() != RESTOOL_SUCCESS) {
|
||||
return RESTOOL_ERROR;
|
||||
}
|
||||
@@ -276,12 +280,13 @@ uint32_t ResourcePack::ScanResources(const vector<string> &inputs, const string
|
||||
{
|
||||
auto &fileManager = FileManager::GetInstance();
|
||||
fileManager.SetModuleName(moduleName_);
|
||||
if (packageParser_.GetOverlap()) {
|
||||
if (packType_ == PackType::OVERLAP) {
|
||||
vector<string> hapResInput{inputs[0]};
|
||||
if (fileManager.ScanModules(hapResInput, output, configJson_.IsHar()) != RESTOOL_SUCCESS) {
|
||||
return RESTOOL_ERROR;
|
||||
}
|
||||
fileManager.SetHapMode(false);
|
||||
fileManager.SetScanHap(false);
|
||||
|
||||
vector<string> resInputs(inputs.begin() + 1, inputs.end());
|
||||
if (fileManager.ScanModules(resInputs, output, configJson_.IsHar()) != RESTOOL_SUCCESS) {
|
||||
return RESTOOL_ERROR;
|
||||
@@ -294,33 +299,50 @@ uint32_t ResourcePack::ScanResources(const vector<string> &inputs, const string
|
||||
return RESTOOL_SUCCESS;
|
||||
}
|
||||
|
||||
uint32_t ResourcePack::PackNormal()
|
||||
uint32_t ResourcePack::Pack()
|
||||
{
|
||||
if (InitCompression() != RESTOOL_SUCCESS) {
|
||||
return RESTOOL_ERROR;
|
||||
if (packType_ == PackType::NORMAL) {
|
||||
cout << "Info: Pack: normal pack mode" << endl;
|
||||
} else if (packType_ == PackType::OVERLAP) {
|
||||
cout << "Info: Pack: overlap pack mode" << endl;
|
||||
}
|
||||
|
||||
if (Init() != RESTOOL_SUCCESS) {
|
||||
if (InitResourcePack() != RESTOOL_SUCCESS) {
|
||||
cerr << "Error: ResourcePack init failed." << endl;
|
||||
return RESTOOL_ERROR;
|
||||
}
|
||||
|
||||
ResourceMerge resourceMerge;
|
||||
if (resourceMerge.Init() != RESTOOL_SUCCESS) {
|
||||
if (resourceMerge.Init(packageParser_) != RESTOOL_SUCCESS) {
|
||||
cerr << "Error: resourceMerge init failed." << endl;
|
||||
return RESTOOL_ERROR;
|
||||
}
|
||||
|
||||
BinaryFilePacker rawFilePacker(packageParser_, moduleName_);
|
||||
std::future<uint32_t> copyFuture = rawFilePacker.CopyBinaryFileAsync(resourceMerge.GetInputs());
|
||||
uint32_t packQualifierRet = PackQualifierResources(resourceMerge);
|
||||
if (packQualifierRet != RESTOOL_SUCCESS) {
|
||||
rawFilePacker.StopCopy();
|
||||
if (packType_ == PackType::OVERLAP) {
|
||||
rawFilePacker.SetCopyHap(true);
|
||||
}
|
||||
uint32_t copyRet = copyFuture.get();
|
||||
return packQualifierRet == RESTOOL_SUCCESS && copyRet == RESTOOL_SUCCESS ? RESTOOL_SUCCESS : RESTOOL_ERROR;
|
||||
std::future<uint32_t> copyFuture = rawFilePacker.CopyBinaryFileAsync(resourceMerge.GetInputs());
|
||||
|
||||
if (PackResources(resourceMerge) != RESTOOL_SUCCESS) {
|
||||
rawFilePacker.StopCopy();
|
||||
cerr << "Error: pack resources failed." << endl;
|
||||
return RESTOOL_ERROR;
|
||||
}
|
||||
|
||||
if (copyFuture.get() != RESTOOL_SUCCESS) {
|
||||
cerr << "Error: copy binary file failed." << endl;
|
||||
return RESTOOL_ERROR;
|
||||
}
|
||||
return RESTOOL_SUCCESS;
|
||||
}
|
||||
|
||||
uint32_t ResourcePack::PackQualifierResources(const ResourceMerge &resourceMerge)
|
||||
uint32_t ResourcePack::PackResources(const ResourceMerge &resourceMerge)
|
||||
{
|
||||
if (packType_ == PackType::OVERLAP && LoadHapResources() != RESTOOL_SUCCESS) {
|
||||
return RESTOOL_ERROR;
|
||||
}
|
||||
|
||||
if (ScanResources(resourceMerge.GetInputs(), packageParser_.GetOutput()) != RESTOOL_SUCCESS) {
|
||||
return RESTOOL_ERROR;
|
||||
}
|
||||
@@ -357,6 +379,28 @@ uint32_t ResourcePack::PackQualifierResources(const ResourceMerge &resourceMerge
|
||||
return RESTOOL_SUCCESS;
|
||||
}
|
||||
|
||||
uint32_t ResourcePack::LoadHapResources()
|
||||
{
|
||||
ResourceTable resourceTabel;
|
||||
map<int64_t, vector<ResourceItem>> items;
|
||||
string resourceIndexPath =
|
||||
FileEntry::FilePath(packageParser_.GetInputs()[0]).GetParent().Append(RESOURCE_INDEX_FILE).GetPath();
|
||||
if (resourceTabel.LoadResTable(resourceIndexPath, items) != RESTOOL_SUCCESS) {
|
||||
return RESTOOL_ERROR;
|
||||
}
|
||||
|
||||
IdWorker::GetInstance().LoadIdFromHap(items);
|
||||
|
||||
FileManager &fileManager = FileManager::GetInstance();
|
||||
fileManager.SetModuleName(moduleName_);
|
||||
if (fileManager.MergeResourceItem(items) != RESTOOL_SUCCESS) {
|
||||
return RESTOOL_ERROR;
|
||||
}
|
||||
fileManager.MarkItemsAsHap();
|
||||
fileManager.SetScanHap(true);
|
||||
return RESTOOL_SUCCESS;
|
||||
}
|
||||
|
||||
uint32_t ResourcePack::HandleFeature()
|
||||
{
|
||||
string output = packageParser_.GetOutput();
|
||||
@@ -548,7 +592,7 @@ uint32_t ResourcePack::PackAppend()
|
||||
|
||||
uint32_t ResourcePack::PackCombine()
|
||||
{
|
||||
if (Init() != RESTOOL_SUCCESS) {
|
||||
if (InitResourcePack() != RESTOOL_SUCCESS) {
|
||||
return RESTOOL_ERROR;
|
||||
}
|
||||
|
||||
@@ -571,60 +615,6 @@ uint32_t ResourcePack::PackCombine()
|
||||
return RESTOOL_SUCCESS;
|
||||
}
|
||||
|
||||
uint32_t ResourcePack::PackOverlap()
|
||||
{
|
||||
if (InitCompression() != RESTOOL_SUCCESS) {
|
||||
return RESTOOL_ERROR;
|
||||
}
|
||||
|
||||
if (Init() != RESTOOL_SUCCESS) {
|
||||
return RESTOOL_ERROR;
|
||||
}
|
||||
|
||||
ResourceMerge resourceMerge;
|
||||
if (resourceMerge.Init(packageParser_) != RESTOOL_SUCCESS) {
|
||||
return RESTOOL_ERROR;
|
||||
}
|
||||
|
||||
BinaryFilePacker rawFilePacker(packageParser_, moduleName_);
|
||||
rawFilePacker.SetCopyHapMode(true);
|
||||
std::future<uint32_t> copyFuture = rawFilePacker.CopyBinaryFileAsync(resourceMerge.GetInputs());
|
||||
|
||||
if (LoadHapResources() != RESTOOL_SUCCESS) {
|
||||
rawFilePacker.StopCopy();
|
||||
return RESTOOL_ERROR;
|
||||
}
|
||||
|
||||
if (PackQualifierResources(resourceMerge) != RESTOOL_SUCCESS) {
|
||||
rawFilePacker.StopCopy();
|
||||
return RESTOOL_ERROR;
|
||||
}
|
||||
|
||||
uint32_t copyRet = copyFuture.get();
|
||||
return copyRet == RESTOOL_SUCCESS ? RESTOOL_SUCCESS : RESTOOL_ERROR;
|
||||
}
|
||||
|
||||
uint32_t ResourcePack::LoadHapResources()
|
||||
{
|
||||
ResourceTable resourceTabel;
|
||||
map<int64_t, vector<ResourceItem>> items;
|
||||
string resourceIndexPath =
|
||||
FileEntry::FilePath(packageParser_.GetInputs()[0]).GetParent().Append(RESOURCE_INDEX_FILE).GetPath();
|
||||
if (resourceTabel.LoadResTable(resourceIndexPath, items) != RESTOOL_SUCCESS) {
|
||||
return RESTOOL_ERROR;
|
||||
}
|
||||
IdWorker::GetInstance().LoadIdFromHap(items);
|
||||
|
||||
FileManager &fileManager = FileManager::GetInstance();
|
||||
fileManager.SetModuleName(moduleName_);
|
||||
if (fileManager.MergeResourceItem(items) != RESTOOL_SUCCESS) {
|
||||
return RESTOOL_ERROR;
|
||||
}
|
||||
fileManager.SetHapItems();
|
||||
fileManager.SetHapMode(true);
|
||||
return RESTOOL_SUCCESS;
|
||||
}
|
||||
|
||||
void ResourcePack::CheckConfigJsonForCombine(ResourceAppend &resourceAppend)
|
||||
{
|
||||
ResourceCheck resourceCheck(configJson_.GetCheckNode(), make_shared<ResourceAppend>(resourceAppend));
|
||||
|
||||
+3
-3
@@ -14,7 +14,7 @@
|
||||
*/
|
||||
|
||||
#include "cmd_parser.h"
|
||||
#include "task_handle.h"
|
||||
#include "resource_pack.h"
|
||||
#include "compression_parser.h"
|
||||
|
||||
using namespace std;
|
||||
@@ -22,8 +22,8 @@ using namespace OHOS::Global::Restool;
|
||||
namespace {
|
||||
uint32_t ProccssHap(PackageParser &packageParser)
|
||||
{
|
||||
TaskHandle taskHandle;
|
||||
return taskHandle.HandlePackage(packageParser);
|
||||
ResourcePack pack(packageParser);
|
||||
return pack.Package();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
/*
|
||||
* 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 "task_handle.h"
|
||||
#include "resource_pack.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Global {
|
||||
namespace Restool {
|
||||
uint32_t TaskHandle::HandlePackage(const PackageParser &packageParser)
|
||||
{
|
||||
ResourcePack pack(packageParser);
|
||||
return pack.Package();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user