mirror of
https://github.com/openharmony/developtools_global_resource_tool.git
synced 2026-07-18 17:24:42 -04:00
@@ -52,8 +52,8 @@ private:
|
||||
bool WriteFileInner(std::ostringstream &outStream, const std::string &outputPath) const;
|
||||
bool WriteResourceItem(const ResourceItem &resourceItem, std::ostringstream &out);
|
||||
bool LoadResourceItem(const std::string &filePath);
|
||||
bool ScanRawFiles(const std::string &path, const std::string &outputPath);
|
||||
bool WriteRawFile(const std::string &filePath, const std::string &outputPath);
|
||||
bool ScanRawFilesOrResFiles(const std::string &path, const std::string &outputPath, const std::string &limit);
|
||||
bool WriteRawFilesOrResFiles(const std::string &filePath, const std::string &outputPath, const std::string &limit);
|
||||
bool Push(const std::shared_ptr<ResourceItem> &resourceItem);
|
||||
void AddRef(const std::shared_ptr<ResourceItem> &resourceItem);
|
||||
bool LoadResourceItemFromMem(const char buffer[], int32_t length);
|
||||
|
||||
@@ -29,6 +29,7 @@ const static std::string RESOURCES_DIR = "resources";
|
||||
const static std::string CONFIG_JSON = "config.json";
|
||||
const static std::string MODULE_JSON = "module.json";
|
||||
const static std::string RAW_FILE_DIR = "rawfile";
|
||||
const static std::string RES_FILE_DIR = "resfile";
|
||||
const static std::string ID_DEFINED_FILE = "id_defined.json";
|
||||
const static std::string RESOURCE_INDEX_FILE = "resources.index";
|
||||
const static std::string JSON_EXTENSION = ".json";
|
||||
@@ -75,6 +76,7 @@ enum class ResType {
|
||||
PROF = 20,
|
||||
PATTERN = 22,
|
||||
SYMBOL = 23,
|
||||
RES = 24,
|
||||
INVALID_RES_TYPE = -1,
|
||||
};
|
||||
|
||||
@@ -182,6 +184,11 @@ struct IdData {
|
||||
uint32_t dataOffset;
|
||||
};
|
||||
|
||||
const std::map<std::string, ResType> g_copyFileMap = {
|
||||
{ RAW_FILE_DIR, ResType::RAW },
|
||||
{ RES_FILE_DIR, ResType::RES },
|
||||
};
|
||||
|
||||
const std::map<std::string, ResType> g_fileClusterMap = {
|
||||
{ "element", ResType::ELEMENT },
|
||||
{ "media", ResType::MEDIA },
|
||||
@@ -220,6 +227,7 @@ const std::map<int32_t, ResType> g_resTypeMap = {
|
||||
{ static_cast<int32_t>(ResType::PROF), ResType::PROF},
|
||||
{ static_cast<int32_t>(ResType::PATTERN), ResType::PATTERN},
|
||||
{ static_cast<int32_t>(ResType::SYMBOL), ResType::SYMBOL},
|
||||
{ static_cast<int32_t>(ResType::RES), ResType::RES},
|
||||
{ static_cast<int32_t>(ResType::INVALID_RES_TYPE), ResType::INVALID_RES_TYPE},
|
||||
};
|
||||
|
||||
|
||||
@@ -42,8 +42,9 @@ private:
|
||||
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 CopyRawFile(const std::vector<std::string> &inputs) const;
|
||||
uint32_t CopyRawFileImpl(const std::string &src, const std::string &dst) 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 GenerateConfigJson();
|
||||
uint32_t ScanResources(const std::vector<std::string> &inputs, const std::string &output);
|
||||
uint32_t PackNormal();
|
||||
|
||||
+1
-1
@@ -280,7 +280,7 @@ uint32_t PackageParser::AddAppend(const string& argValue)
|
||||
{
|
||||
string appendPath = ResourceUtil::RealPath(argValue);
|
||||
if (appendPath.empty()) {
|
||||
cout << "Warning: invaild compress '" << argValue << "'" << endl;
|
||||
cout << "Warning: invalid compress '" << argValue << "'" << endl;
|
||||
appendPath = argValue;
|
||||
}
|
||||
auto ret = find_if(append_.begin(), append_.end(), [appendPath](auto iter) {return appendPath == iter;});
|
||||
|
||||
@@ -311,7 +311,7 @@ bool JsonCompiler::CheckJsonStringValue(const Json::Value &valueNode, const Reso
|
||||
string value = valueNode.asString();
|
||||
ResType type = resourceItem.GetResType();
|
||||
if (type == ResType::COLOR && !CheckColorValue(value.c_str())) {
|
||||
string error = "invaild color value '" + value + \
|
||||
string error = "invalid color value '" + value + \
|
||||
"', only support refer '$color:xxx' or '#rgb','#argb','#rrggbb','#aarrggbb'.";
|
||||
cerr << "Error: " << error << NEW_LINE_PATH << resourceItem.GetFilePath() << endl;
|
||||
return false;
|
||||
|
||||
+16
-11
@@ -163,8 +163,8 @@ bool ResourceAppend::ScanSubLimitkeyResources(const FileEntry entry, const strin
|
||||
continue;
|
||||
}
|
||||
|
||||
if (limitKey == RAW_FILE_DIR) {
|
||||
if (!ScanRawFiles(child->GetFilePath().GetPath(), outputPath)) {
|
||||
if (limitKey == RAW_FILE_DIR || limitKey == RES_FILE_DIR) {
|
||||
if (!ScanRawFilesOrResFiles(child->GetFilePath().GetPath(), outputPath, limitKey)) {
|
||||
return false;
|
||||
}
|
||||
continue;
|
||||
@@ -292,7 +292,11 @@ bool ResourceAppend::ScanFile(const FileInfo &fileInfo, const string &outputPath
|
||||
bool ResourceAppend::ScanSingleFile(const string &filePath, const string &outputPath)
|
||||
{
|
||||
if (filePath.find(RAW_FILE_DIR) != string::npos) {
|
||||
return WriteRawFile(filePath, outputPath);
|
||||
return WriteRawFilesOrResFiles(filePath, outputPath, RAW_FILE_DIR);
|
||||
}
|
||||
|
||||
if (filePath.find(RES_FILE_DIR) != string::npos) {
|
||||
return WriteRawFilesOrResFiles(filePath, outputPath, RES_FILE_DIR);
|
||||
}
|
||||
|
||||
FileEntry::FilePath path(filePath);
|
||||
@@ -400,7 +404,7 @@ bool ResourceAppend::LoadResourceItem(const string &filePath)
|
||||
#endif
|
||||
}
|
||||
|
||||
bool ResourceAppend::ScanRawFiles(const string &path, const string &outputPath)
|
||||
bool ResourceAppend::ScanRawFilesOrResFiles(const string &path, const string &outputPath, const string &limit)
|
||||
{
|
||||
FileEntry entry(path);
|
||||
if (!entry.Init()) {
|
||||
@@ -415,9 +419,9 @@ bool ResourceAppend::ScanRawFiles(const string &path, const string &outputPath)
|
||||
|
||||
bool ret = false;
|
||||
if (child->IsFile()) {
|
||||
ret = WriteRawFile(child->GetFilePath().GetPath(), outputPath);
|
||||
ret = WriteRawFilesOrResFiles(child->GetFilePath().GetPath(), outputPath, limit);
|
||||
} else {
|
||||
ret = ScanRawFiles(child->GetFilePath().GetPath(), outputPath);
|
||||
ret = ScanRawFilesOrResFiles(child->GetFilePath().GetPath(), outputPath, limit);
|
||||
}
|
||||
|
||||
if (!ret) {
|
||||
@@ -427,18 +431,19 @@ bool ResourceAppend::ScanRawFiles(const string &path, const string &outputPath)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ResourceAppend::WriteRawFile(const string &filePath, const string &outputPath)
|
||||
bool ResourceAppend::WriteRawFilesOrResFiles(const string &filePath, const string &outputPath, const string &limit)
|
||||
{
|
||||
string::size_type pos = filePath.find(RAW_FILE_DIR);
|
||||
string::size_type pos = filePath.find(limit);
|
||||
if (pos == string::npos) {
|
||||
cerr << "Error: invaild raw file." << NEW_LINE_PATH << filePath << endl;
|
||||
cerr << "Error: invalid file path." << NEW_LINE_PATH << filePath << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
string sub = filePath.substr(pos);
|
||||
sub = FileEntry::FilePath(RESOURCES_DIR).Append(sub).GetPath();
|
||||
vector<KeyParam> keyParams;
|
||||
ResourceItem resourceItem("", keyParams, ResType::RAW);
|
||||
auto iter = g_copyFileMap.find(limit);
|
||||
ResourceItem resourceItem("", keyParams, iter->second);
|
||||
resourceItem.SetData(sub);
|
||||
resourceItem.SetFilePath(filePath);
|
||||
resourceItem.SetLimitKey("");
|
||||
@@ -538,7 +543,7 @@ bool ResourceAppend::LoadResourceItemFromMem(const char buffer[], int32_t length
|
||||
}
|
||||
// data
|
||||
string data = ParseString(buffer, length, offset);
|
||||
if (resType == ResType::RAW) {
|
||||
if (resType == ResType::RAW || resType == ResType::RES) {
|
||||
FileEntry::FilePath outPath(packageParser_.GetOutput());
|
||||
if (ResourceUtil::FileExist(outPath.Append(data).GetPath())) {
|
||||
continue;
|
||||
|
||||
@@ -41,7 +41,7 @@ bool ResourceDirectory::ScanResources(const string &resourcesDir, function<bool(
|
||||
return false;
|
||||
}
|
||||
|
||||
if (limitKey == RAW_FILE_DIR) {
|
||||
if (limitKey == RAW_FILE_DIR || limitKey == RES_FILE_DIR) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
+26
-14
@@ -238,29 +238,41 @@ uint32_t ResourcePack::GenerateJsHeader(const std::string &headerPath) const
|
||||
return result;
|
||||
}
|
||||
|
||||
uint32_t ResourcePack::CopyRawFile(const vector<string> &inputs) const
|
||||
uint32_t ResourcePack::CopyRawFileOrResFile(const string &filePath, const string &fileType) const
|
||||
{
|
||||
if (!ResourceUtil::FileExist(filePath)) {
|
||||
return RESTOOL_SUCCESS;
|
||||
}
|
||||
|
||||
if (!FileEntry::IsDirectory(filePath)) {
|
||||
cerr << "Error: '" << filePath << "' not directory." << endl;
|
||||
return RESTOOL_ERROR;
|
||||
}
|
||||
|
||||
string dst = FileEntry::FilePath(packageParser_.GetOutput())
|
||||
.Append(RESOURCES_DIR).Append(fileType).GetPath();
|
||||
if (CopyRawFileOrResFileImpl(filePath, dst) != RESTOOL_SUCCESS) {
|
||||
return RESTOOL_ERROR;
|
||||
}
|
||||
return RESTOOL_SUCCESS;
|
||||
}
|
||||
|
||||
uint32_t ResourcePack::CopyRawFileOrResFile(const vector<string> &inputs) const
|
||||
{
|
||||
for (const auto &input : inputs) {
|
||||
string rawfilePath = FileEntry::FilePath(input).Append(RAW_FILE_DIR).GetPath();
|
||||
if (!ResourceUtil::FileExist(rawfilePath)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!FileEntry::IsDirectory(rawfilePath)) {
|
||||
cerr << "Error: '" << rawfilePath << "' not directory." << endl;
|
||||
if (CopyRawFileOrResFile(rawfilePath, RAW_FILE_DIR) == RESTOOL_ERROR) {
|
||||
return RESTOOL_ERROR;
|
||||
}
|
||||
|
||||
string dst = FileEntry::FilePath(packageParser_.GetOutput())
|
||||
.Append(RESOURCES_DIR).Append(RAW_FILE_DIR).GetPath();
|
||||
if (CopyRawFileImpl(rawfilePath, dst) != RESTOOL_SUCCESS) {
|
||||
string resfilePath = FileEntry::FilePath(input).Append(RES_FILE_DIR).GetPath();
|
||||
if (CopyRawFileOrResFile(resfilePath, RES_FILE_DIR) == RESTOOL_ERROR) {
|
||||
return RESTOOL_ERROR;
|
||||
}
|
||||
}
|
||||
return RESTOOL_SUCCESS;
|
||||
}
|
||||
|
||||
uint32_t ResourcePack::CopyRawFileImpl(const string &src, const string &dst) const
|
||||
uint32_t ResourcePack::CopyRawFileOrResFileImpl(const string &src, const string &dst) const
|
||||
{
|
||||
if (!ResourceUtil::CreateDirs(dst)) {
|
||||
return RESTOOL_ERROR;
|
||||
@@ -278,7 +290,7 @@ uint32_t ResourcePack::CopyRawFileImpl(const string &src, const string &dst) con
|
||||
|
||||
string subPath = FileEntry::FilePath(dst).Append(filename).GetPath();
|
||||
if (!entry->IsFile()) {
|
||||
if (CopyRawFileImpl(entry->GetFilePath().GetPath(), subPath) != RESTOOL_SUCCESS) {
|
||||
if (CopyRawFileOrResFileImpl(entry->GetFilePath().GetPath(), subPath) != RESTOOL_SUCCESS) {
|
||||
return RESTOOL_ERROR;
|
||||
}
|
||||
} else {
|
||||
@@ -338,7 +350,7 @@ uint32_t ResourcePack::PackNormal()
|
||||
return RESTOOL_ERROR;
|
||||
}
|
||||
|
||||
if (CopyRawFile(resourceMerge.GetInputs()) != RESTOOL_SUCCESS) {
|
||||
if (CopyRawFileOrResFile(resourceMerge.GetInputs()) != RESTOOL_SUCCESS) {
|
||||
return RESTOOL_ERROR;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user