From ab8b9be688db9a306b4bb62fe3d886a4ff6fe3e9 Mon Sep 17 00:00:00 2001 From: fangyunzhong Date: Thu, 29 Feb 2024 10:08:19 +0800 Subject: [PATCH] =?UTF-8?q?=E9=92=88=E5=AF=B9=E6=B2=A1=E6=9C=89base?= =?UTF-8?q?=E8=B5=84=E6=BA=90=EF=BC=8C=E7=BB=99=E5=87=BAwarning=E6=8F=90?= =?UTF-8?q?=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: fangyunzhong --- include/file_manager.h | 4 ++-- include/resource_append.h | 1 + include/resource_data.h | 2 +- include/resource_util.h | 6 ++++++ src/file_manager.cpp | 35 ++++++++++++++++++++++++++++++----- src/resource_append.cpp | 28 ++++++++++++++++++++++++++++ src/resource_util.cpp | 7 +++++++ 7 files changed, 75 insertions(+), 8 deletions(-) diff --git a/include/file_manager.h b/include/file_manager.h index 1857581..1d39e62 100644 --- a/include/file_manager.h +++ b/include/file_manager.h @@ -38,9 +38,9 @@ public: uint32_t MergeResourceItem(const std::map> &resourceInfos); private: - uint32_t ScanModule(const std::string &input, const std::string &output, - std::map> &resTypeOfDirs); + uint32_t ScanModule(const std::string &input, const std::string &output); uint32_t ParseReference(const std::string &output); + void CheckAllItems(std::vector> &noBaseResource); // id, resource items std::map> items_; diff --git a/include/resource_append.h b/include/resource_append.h index 840f4e2..5feeaba 100644 --- a/include/resource_append.h +++ b/include/resource_append.h @@ -65,6 +65,7 @@ private: #ifdef __WIN32 bool LoadResourceItemWin(const std::string &filePath); #endif + void CheckAllItems(std::vector> &noBaseResource); const PackageParser &packageParser_; std::map>> items_; std::map>> itemsForModule_; diff --git a/include/resource_data.h b/include/resource_data.h index b595bc4..12f9884 100644 --- a/include/resource_data.h +++ b/include/resource_data.h @@ -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 { diff --git a/include/resource_util.h b/include/resource_util.h index 59497a4..0577a6c 100644 --- a/include/resource_util.h +++ b/include/resource_util.h @@ -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> &noBaseResource); + private: enum class IgnoreType { IGNORE_FILE, diff --git a/src/file_manager.cpp b/src/file_manager.cpp index dde0d14..d85b83a 100644 --- a/src/file_manager.cpp +++ b/src/file_manager.cpp @@ -31,11 +31,15 @@ namespace Restool { using namespace std; uint32_t FileManager::ScanModules(const vector &inputs, const string &output) { + vector> noBaseResource; for (auto input : inputs) { - map> 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> } // below private founction -uint32_t FileManager::ScanModule(const string &input, const string &output, - map> &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> &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())); + } + } + } +} } } } diff --git a/src/resource_append.cpp b/src/resource_append.cpp index d18297f..25fd829 100644 --- a/src/resource_append.cpp +++ b/src/resource_append.cpp @@ -53,10 +53,15 @@ uint32_t ResourceAppend::Append() uint32_t ResourceAppend::Combine() { + vector> 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> &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())); + } + } + } +} } } } \ No newline at end of file diff --git a/src/resource_util.cpp b/src/resource_util.cpp index d6a9fab..bb88d23 100644 --- a/src/resource_util.cpp +++ b/src/resource_util.cpp @@ -453,6 +453,13 @@ bool ResourceUtil::IsValidName(const string &name) return true; } +void ResourceUtil::PrintWarningMsg(vector> &noBaseResource) +{ + for (const auto &item : noBaseResource) { + cerr << "Warning: the " << ResourceUtil::ResTypeToString(item.first); + cerr << " of '" << item.second << "' does not have a base resource." << endl; + } +} } } }