针对没有base资源,给出warning提示

Signed-off-by: fangyunzhong <fangyunzhong2@huawei.com>
This commit is contained in:
fangyunzhong
2024-02-29 10:08:19 +08:00
parent 672c65eef5
commit ab8b9be688
7 changed files with 75 additions and 8 deletions
+2 -2
View File
@@ -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_;
+1
View File
@@ -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_;
+1 -1
View File
@@ -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 {
+6
View File
@@ -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
View File
@@ -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()));
}
}
}
}
}
}
}
+28
View File
@@ -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()));
}
}
}
}
}
}
}
+7
View File
@@ -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;
}
}
}
}
}