!159 har包不支持转码和默认media转码修改

Merge pull request !159 from fyz1019/master
This commit is contained in:
openharmony_ci
2024-06-24 08:41:26 +00:00
committed by Gitee
7 changed files with 85 additions and 25 deletions
+3
View File
@@ -66,6 +66,7 @@ public:
bool CopyAndTranscode(const std::string &src, std::string &dst);
bool GetMediaSwitch();
std::string PrintTransMessage();
bool GetDefaultCompress();
private:
bool ParseContext(const cJSON *contextNode);
bool ParseCompression(const cJSON *compressionNode);
@@ -86,11 +87,13 @@ private:
std::string GetOptionsString(const std::shared_ptr<CompressFilter> &compressFilter, int type);
bool CheckAndTranscode(const std::string &src, std::string &dst, std::string &output,
const std::shared_ptr<CompressFilter> &compressFilter);
bool IsDefaultCompress();
std::string filePath_;
std::string extensionPath_;
std::vector<std::shared_ptr<CompressFilter>> compressFilters_;
bool mediaSwitch_;
cJSON *root_;
bool defaultCompress_;
unsigned long long totalTime_ = 0;
uint32_t totalCounts_ = 0;
unsigned long long compressTime_ = 0;
+1 -1
View File
@@ -30,7 +30,7 @@ protected:
bool PostMediaFile(const FileInfo &fileInfo, const std::string &output);
private:
std::string GetOutputFilePath(const FileInfo &fileInfo) const;
bool IsIgnore(const FileInfo &fileInfo) const;
bool IsIgnore(const FileInfo &fileInfo);
bool CopyMediaFile(const FileInfo &fileInfo, std::string &output);
};
}
+2
View File
@@ -17,6 +17,7 @@
#define OHOS_RESTOOL_RESOURCE_DATA_H
#include <map>
#include <set>
#include <stdint.h>
#include <string>
#include <vector>
@@ -48,6 +49,7 @@ const static int32_t VERSION_MAX_LEN = 128;
const static int32_t INT_TO_BYTES = sizeof(uint32_t);
static const int8_t RESTOOL_VERSION[VERSION_MAX_LEN] = { "Restool 5.009" };
const static int32_t TAG_LEN = 4;
static std::set<std::string> g_resourceSet;
enum class KeyType {
LANGUAGE = 0,
+4 -3
View File
@@ -37,14 +37,15 @@ private:
uint32_t InitModule();
void InitHeaderCreater();
uint32_t InitOutput() const;
uint32_t InitCompression();
uint32_t GenerateHeader() const;
uint32_t InitConfigJson();
uint32_t GenerateTextHeader(const std::string &headerPath) const;
uint32_t GenerateCplusHeader(const std::string &headerPath) const;
uint32_t GenerateJsHeader(const std::string &headerPath) const;
uint32_t CopyRawFileOrResFile(const std::string &filePath, const std::string &fileType) const;
uint32_t CopyRawFileOrResFile(const std::vector<std::string> &inputs) const;
uint32_t CopyRawFileOrResFileImpl(const std::string &src, const std::string &dst) const;
uint32_t CopyRawFileOrResFile(const std::string &filePath, const std::string &fileType);
uint32_t CopyRawFileOrResFile(const std::vector<std::string> &inputs);
uint32_t CopyRawFileOrResFileImpl(const std::string &src, const std::string &dst);
uint32_t GenerateConfigJson();
uint32_t ScanResources(const std::vector<std::string> &inputs, const std::string &output);
uint32_t PackNormal();
+32 -4
View File
@@ -46,12 +46,12 @@ const map<TranscodeError, string> ERRORCODEMAP = {
};
CompressionParser::CompressionParser()
: filePath_(""), extensionPath_(""), mediaSwitch_(false), root_(nullptr)
: filePath_(""), extensionPath_(""), mediaSwitch_(false), root_(nullptr), defaultCompress_(false)
{
}
CompressionParser::CompressionParser(const string &filePath)
: filePath_(filePath), extensionPath_(""), mediaSwitch_(false), root_(nullptr)
: filePath_(filePath), extensionPath_(""), mediaSwitch_(false), root_(nullptr), defaultCompress_(false)
{
}
@@ -219,14 +219,25 @@ bool CompressionParser::ParseFilters(const cJSON *filtersNode)
compressFilter->expandRules = ParseRules(expandRulesNode);
compressFilters_.emplace_back(compressFilter);
}
defaultCompress_ = IsDefaultCompress();
return true;
}
bool CompressionParser::IsDefaultCompress()
{
if (compressFilters_.size() != 1) {
return false;
}
auto compressFilter = compressFilters_[0];
return (compressFilter->path.size() == 0) && (compressFilter->excludePath.size() == 0) &&
(compressFilter->rules.size() == 0) && (compressFilter->expandRules.size() == 0);
}
vector<string> CompressionParser::ParseRules(const cJSON *rulesNode)
{
vector<string> res;
if (!rulesNode || !cJSON_IsObject(rulesNode)) {
cerr << "Error: ParseRules fail." << endl;
cerr << "Warning: rules is not exist." << endl;
return res;
}
for (cJSON *item = rulesNode->child; item; item = item->next) {
@@ -243,7 +254,7 @@ vector<string> CompressionParser::ParsePath(const cJSON *pathNode)
{
vector<string> res;
if (!pathNode || !cJSON_IsArray(pathNode)) {
cerr << "Error: ParsePath fail." << endl;
cerr << "Warning: path is not exist." << endl;
return res;
}
for (cJSON *item = pathNode->child; item; item = item->next) {
@@ -440,11 +451,28 @@ bool CompressionParser::GetMediaSwitch()
return mediaSwitch_;
}
bool CompressionParser::GetDefaultCompress()
{
return defaultCompress_;
}
bool CompressionParser::CheckAndTranscode(const string &src, string &dst, string &output,
const shared_ptr<CompressFilter> &compressFilter)
{
auto t1 = std::chrono::steady_clock::now();
TranscodeResult result = {0, 0, 0, 0};
if (defaultCompress_) {
if (!SetTranscodeOptions(GetOptionsString(compressFilter, OPT_TYPE_ONE))) {
return false;
}
auto res = TranscodeImages(src, output, result);
CollectTimeAndSize(res, t1, result);
if (res != TranscodeError::SUCCESS) {
return false;
}
dst = output;
return true;
}
if (!IsInPath(src, compressFilter)) {
return false;
}
+12 -3
View File
@@ -77,9 +77,14 @@ string GenericCompiler::GetOutputFilePath(const FileInfo &fileInfo) const
return outputFilePath;
}
bool GenericCompiler::IsIgnore(const FileInfo &fileInfo) const
bool GenericCompiler::IsIgnore(const FileInfo &fileInfo)
{
return ResourceUtil::FileExist(GetOutputFilePath(fileInfo));
string output = GetOutputFilePath(fileInfo);
if (!g_resourceSet.emplace(output).second) {
cerr << "Warning: '" << fileInfo.filePath << "' is defined repeatedly." << endl;
return true;
}
return false;
}
bool GenericCompiler::CopyMediaFile(const FileInfo &fileInfo, std::string &output)
@@ -89,7 +94,11 @@ bool GenericCompiler::CopyMediaFile(const FileInfo &fileInfo, std::string &outpu
return false;
}
output = GetOutputFilePath(fileInfo);
return CompressionParser::GetCompressionParser()->CopyAndTranscode(fileInfo.filePath, output);
if (moduleName_ == "har" || type_ != ResType::MEDIA) {
return ResourceUtil::CopyFileInner(fileInfo.filePath, output);
} else {
return CompressionParser::GetCompressionParser()->CopyAndTranscode(fileInfo.filePath, output);
}
}
}
}
+31 -14
View File
@@ -37,16 +37,22 @@ uint32_t ResourcePack::Package()
if (!packageParser_.GetAppend().empty()) {
return PackAppend();
}
if (packageParser_.GetCombine()) {
return PackCombine();
}
return PackNormal();
}
uint32_t ResourcePack::InitCompression()
{
if (!packageParser_.GetCompressionPath().empty()) {
auto compressionMgr = CompressionParser::GetCompressionParser(packageParser_.GetCompressionPath());
if (compressionMgr->Init() != RESTOOL_SUCCESS) {
return RESTOOL_ERROR;
}
}
if (packageParser_.GetCombine()) {
return PackCombine();
}
return PackNormal();
return RESTOOL_SUCCESS;
}
// below private founction
@@ -244,7 +250,7 @@ uint32_t ResourcePack::GenerateJsHeader(const std::string &headerPath) const
return result;
}
uint32_t ResourcePack::CopyRawFileOrResFile(const string &filePath, const string &fileType) const
uint32_t ResourcePack::CopyRawFileOrResFile(const string &filePath, const string &fileType)
{
if (!ResourceUtil::FileExist(filePath)) {
return RESTOOL_SUCCESS;
@@ -263,7 +269,7 @@ uint32_t ResourcePack::CopyRawFileOrResFile(const string &filePath, const string
return RESTOOL_SUCCESS;
}
uint32_t ResourcePack::CopyRawFileOrResFile(const vector<string> &inputs) const
uint32_t ResourcePack::CopyRawFileOrResFile(const vector<string> &inputs)
{
for (const auto &input : inputs) {
string rawfilePath = FileEntry::FilePath(input).Append(RAW_FILE_DIR).GetPath();
@@ -278,7 +284,7 @@ uint32_t ResourcePack::CopyRawFileOrResFile(const vector<string> &inputs) const
return RESTOOL_SUCCESS;
}
uint32_t ResourcePack::CopyRawFileOrResFileImpl(const string &src, const string &dst) const
uint32_t ResourcePack::CopyRawFileOrResFileImpl(const string &src, const string &dst)
{
if (!ResourceUtil::CreateDirs(dst)) {
return RESTOOL_ERROR;
@@ -299,15 +305,22 @@ uint32_t ResourcePack::CopyRawFileOrResFileImpl(const string &src, const string
if (CopyRawFileOrResFileImpl(entry->GetFilePath().GetPath(), subPath) != RESTOOL_SUCCESS) {
return RESTOOL_ERROR;
}
} else {
if (ResourceUtil::FileExist(subPath)) {
cerr << "Warning: '" << entry->GetFilePath().GetPath() << "' is defined repeatedly." << endl;
continue;
}
string path = entry->GetFilePath().GetPath();
if (!CompressionParser::GetCompressionParser()->CopyAndTranscode(path, subPath)) {
continue;
}
if (!g_resourceSet.emplace(subPath).second) {
cerr << "Warning: '" << entry->GetFilePath().GetPath() << "' is defined repeatedly." << endl;
continue;
}
string path = entry->GetFilePath().GetPath();
if (moduleName_ == "har" || CompressionParser::GetCompressionParser()->GetDefaultCompress()) {
if (!ResourceUtil::CopyFileInner(path, subPath)) {
return RESTOOL_ERROR;
}
continue;
}
if (!CompressionParser::GetCompressionParser()->CopyAndTranscode(path, subPath)) {
return RESTOOL_ERROR;
}
}
return RESTOOL_SUCCESS;
@@ -341,6 +354,10 @@ uint32_t ResourcePack::ScanResources(const vector<string> &inputs, const string
uint32_t ResourcePack::PackNormal()
{
if (InitCompression() != RESTOOL_SUCCESS) {
return RESTOOL_ERROR;
}
if (Init() != RESTOOL_SUCCESS) {
return RESTOOL_ERROR;
}