From f3a1f33bd7445d493d9901b987c4acbad683f0d6 Mon Sep 17 00:00:00 2001 From: HanSY Date: Mon, 20 Jan 2025 20:07:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B8=85=E7=90=86=E5=91=8A=E8=AD=A6=E4=BF=A1?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: HanSY --- include/id_worker.h | 2 +- src/id_worker.cpp | 9 +++++++-- src/resource_overlap.cpp | 4 +++- src/resource_pack.cpp | 6 +++++- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/include/id_worker.h b/include/id_worker.h index 3fe29e2..a22afa6 100644 --- a/include/id_worker.h +++ b/include/id_worker.h @@ -33,7 +33,7 @@ public: std::vector GetHeaderId() const; int64_t GetId(ResType resType, const std::string &name) const; int64_t GetSystemId(ResType resType, const std::string &name) const; - void LoadIdFromHap(const std::map> &items); + int64_t LoadIdFromHap(const std::map> &items); private: int64_t GenerateAppId(ResType resType, const std::string &name); diff --git a/src/id_worker.cpp b/src/id_worker.cpp index 406573a..15d8124 100644 --- a/src/id_worker.cpp +++ b/src/id_worker.cpp @@ -84,7 +84,7 @@ int64_t IdWorker::GetSystemId(ResType resType, const string &name) const return result->second.id; } -void IdWorker::LoadIdFromHap(const map> &items) +int64_t IdWorker::LoadIdFromHap(const map> &items) { int64_t minId = 0xffffffff; int64_t maxId = 0x01000000; @@ -96,7 +96,12 @@ void IdWorker::LoadIdFromHap(const map> &items) maxId = max(maxId, item.first); } maxId_ = GetMaxId(minId); - appId_ = maxId + 1; + if (static_cast(maxId) > maxId_) { + PrintError(GetError(ERR_CODE_RESOURCE_ID_EXCEED).FormatCause(static_cast(maxId), maxId_)); + return RESTOOL_ERROR; + } + appId_ = static_cast(maxId) + 1; + return RESTOOL_SUCCESS; } int64_t IdWorker::GenerateAppId(ResType resType, const string &name) diff --git a/src/resource_overlap.cpp b/src/resource_overlap.cpp index 9dc1e3a..8934794 100644 --- a/src/resource_overlap.cpp +++ b/src/resource_overlap.cpp @@ -88,7 +88,9 @@ uint32_t ResourceOverlap::LoadHapResources() return RESTOOL_ERROR; } - IdWorker::GetInstance().LoadIdFromHap(items); + if (IdWorker::GetInstance().LoadIdFromHap(items) != RESTOOL_SUCCESS) { + return RESTOOL_ERROR; + } FileManager &fileManager = FileManager::GetInstance(); fileManager.SetModuleName(moduleName_); diff --git a/src/resource_pack.cpp b/src/resource_pack.cpp index e835a2c..4fbbc9d 100644 --- a/src/resource_pack.cpp +++ b/src/resource_pack.cpp @@ -47,7 +47,11 @@ uint32_t ResourcePack::Package() } unique_ptr resourcePacker = ResourcePackerFactory::CreatePacker(packType_, packageParser_); - errorCode = resourcePacker->Pack(); + if (!resourcePacker) { + errorCode = RESTOOL_ERROR; + } else { + errorCode = resourcePacker->Pack(); + } } if (errorCode == RESTOOL_SUCCESS) { ShowPackSuccess();