mirror of
https://github.com/openharmony/developtools_global_resource_tool.git
synced 2026-07-18 17:24:42 -04:00
针对没有base资源,给出warning提示
Signed-off-by: fangyunzhong <fangyunzhong2@huawei.com>
This commit is contained in:
@@ -38,9 +38,9 @@ public:
|
||||
uint32_t MergeResourceItem(const std::map<int32_t, std::vector<ResourceItem>> &resourceInfos);
|
||||
|
||||
private:
|
||||
uint32_t ScanModule(const std::string &input, const std::string &output,
|
||||
std::map<ResType, std::vector<DirectoryInfo>> &resTypeOfDirs);
|
||||
uint32_t ScanModule(const std::string &input, const std::string &output);
|
||||
uint32_t ParseReference(const std::string &output);
|
||||
void CheckAllItems(std::vector<std::pair<ResType, std::string>> &noBaseResource);
|
||||
|
||||
// id, resource items
|
||||
std::map<int32_t, std::vector<ResourceItem>> items_;
|
||||
|
||||
@@ -65,6 +65,7 @@ private:
|
||||
#ifdef __WIN32
|
||||
bool LoadResourceItemWin(const std::string &filePath);
|
||||
#endif
|
||||
void CheckAllItems(std::vector<std::pair<ResType, std::string>> &noBaseResource);
|
||||
const PackageParser &packageParser_;
|
||||
std::map<int32_t, std::vector<std::shared_ptr<ResourceItem>>> items_;
|
||||
std::map<int32_t, std::vector<std::shared_ptr<ResourceItem>>> itemsForModule_;
|
||||
|
||||
@@ -39,7 +39,7 @@ const static std::string NEW_LINE_PATH = "\nat ";
|
||||
const static std::string LONG_PATH_HEAD = "\\\\?\\";
|
||||
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.002" };
|
||||
static const int8_t RESTOOL_VERSION[VERSION_MAX_LEN] = { "Restool 5.003" };
|
||||
const static int32_t TAG_LEN = 4;
|
||||
|
||||
enum class KeyType {
|
||||
|
||||
@@ -234,6 +234,12 @@ public:
|
||||
*/
|
||||
static bool IsValidName(const std::string &name);
|
||||
|
||||
/**
|
||||
* @brief print warning msg
|
||||
* @param noBaseResource set of no base resources
|
||||
*/
|
||||
static void PrintWarningMsg(std::vector<std::pair<ResType, std::string>> &noBaseResource);
|
||||
|
||||
private:
|
||||
enum class IgnoreType {
|
||||
IGNORE_FILE,
|
||||
|
||||
+30
-5
@@ -31,11 +31,15 @@ namespace Restool {
|
||||
using namespace std;
|
||||
uint32_t FileManager::ScanModules(const vector<string> &inputs, const string &output)
|
||||
{
|
||||
vector<pair<ResType, string>> noBaseResource;
|
||||
for (auto input : inputs) {
|
||||
map<ResType, vector<DirectoryInfo>> resTypeOfDirs;
|
||||
if (ScanModule(input, output, resTypeOfDirs) != RESTOOL_SUCCESS) {
|
||||
if (ScanModule(input, output) != RESTOOL_SUCCESS) {
|
||||
return RESTOOL_ERROR;
|
||||
}
|
||||
CheckAllItems(noBaseResource);
|
||||
}
|
||||
if (!noBaseResource.empty()) {
|
||||
ResourceUtil::PrintWarningMsg(noBaseResource);
|
||||
}
|
||||
return ParseReference(output);
|
||||
}
|
||||
@@ -46,14 +50,12 @@ uint32_t FileManager::MergeResourceItem(const map<int32_t, vector<ResourceItem>>
|
||||
}
|
||||
|
||||
// below private founction
|
||||
uint32_t FileManager::ScanModule(const string &input, const string &output,
|
||||
map<ResType, vector<DirectoryInfo>> &resTypeOfDirs)
|
||||
uint32_t FileManager::ScanModule(const string &input, const string &output)
|
||||
{
|
||||
ResourceModule resourceModule(input, output, moduleName_);
|
||||
if (resourceModule.ScanResource() != RESTOOL_SUCCESS) {
|
||||
return RESTOOL_ERROR;
|
||||
}
|
||||
resTypeOfDirs = resourceModule.GetScanDirectorys();
|
||||
MergeResourceItem(resourceModule.GetOwner());
|
||||
return RESTOOL_SUCCESS;
|
||||
}
|
||||
@@ -66,6 +68,29 @@ uint32_t FileManager::ParseReference(const string &output)
|
||||
}
|
||||
return RESTOOL_SUCCESS;
|
||||
}
|
||||
|
||||
void FileManager::CheckAllItems(vector<pair<ResType, string>> &noBaseResource)
|
||||
{
|
||||
for (const auto &item : items_) {
|
||||
bool flag = false;
|
||||
for (const auto &iter : item.second) {
|
||||
if (iter.GetLimitKey() == "base") {
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!flag) {
|
||||
auto firstItem = item.second.front();
|
||||
auto ret = find_if(noBaseResource.begin(), noBaseResource.end(), [firstItem](auto &iterItem) {
|
||||
return (firstItem.GetResType() == iterItem.first) &&
|
||||
(firstItem.GetName() == iterItem.second);
|
||||
});
|
||||
if (ret == noBaseResource.end()) {
|
||||
noBaseResource.push_back(make_pair(firstItem.GetResType(), firstItem.GetName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,10 +53,15 @@ uint32_t ResourceAppend::Append()
|
||||
|
||||
uint32_t ResourceAppend::Combine()
|
||||
{
|
||||
vector<pair<ResType, string>> noBaseResource;
|
||||
for (const auto &iter : packageParser_.GetInputs()) {
|
||||
if (!Combine(iter)) {
|
||||
return RESTOOL_ERROR;
|
||||
}
|
||||
CheckAllItems(noBaseResource);
|
||||
}
|
||||
if (!noBaseResource.empty()) {
|
||||
ResourceUtil::PrintWarningMsg(noBaseResource);
|
||||
}
|
||||
|
||||
if (!ParseRef()) {
|
||||
@@ -670,6 +675,29 @@ bool ResourceAppend::IsBaseIdDefined(const FileInfo &fileInfo)
|
||||
filePath.GetParent().GetFilename() == "element" &&
|
||||
fileInfo.filename == ID_DEFINED_FILE;
|
||||
}
|
||||
|
||||
void ResourceAppend::CheckAllItems(vector<pair<ResType, string>> &noBaseResource)
|
||||
{
|
||||
for (const auto &item : items_) {
|
||||
bool flag = false;
|
||||
for (const auto &iter : item.second) {
|
||||
if (iter->GetLimitKey() == "base") {
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!flag) {
|
||||
auto firstItem = item.second.front();
|
||||
auto ret = find_if(noBaseResource.begin(), noBaseResource.end(), [firstItem](auto &iterItem) {
|
||||
return (firstItem->GetResType() == iterItem.first) &&
|
||||
(firstItem->GetName() == iterItem.second);
|
||||
});
|
||||
if (ret == noBaseResource.end()) {
|
||||
noBaseResource.push_back(make_pair(firstItem->GetResType(), firstItem->GetName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -453,6 +453,13 @@ bool ResourceUtil::IsValidName(const string &name)
|
||||
return true;
|
||||
}
|
||||
|
||||
void ResourceUtil::PrintWarningMsg(vector<pair<ResType, string>> &noBaseResource)
|
||||
{
|
||||
for (const auto &item : noBaseResource) {
|
||||
cerr << "Warning: the " << ResourceUtil::ResTypeToString(item.first);
|
||||
cerr << " of '" << item.second << "' does not have a base resource." << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user