From b575a1b2a9a90596d6c8ae08d9c2cdeeb393caab Mon Sep 17 00:00:00 2001 From: fangyunzhong Date: Fri, 15 Mar 2024 18:53:29 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B5=84=E6=BA=90=E7=BC=96=E8=AF=91=E6=97=B6id?= =?UTF-8?q?=E5=9B=BA=E5=AE=9A=E5=BC=82=E5=B8=B8bug=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: fangyunzhong --- include/cmd_parser.h | 2 +- include/file_manager.h | 6 +++--- include/i_resource_compiler.h | 4 ++-- include/id_defined_parser.h | 8 +++---- include/id_worker.h | 30 +++++++++++++------------- include/reference_parser.h | 2 +- include/resource_append.h | 8 +++---- include/resource_data.h | 6 +++--- include/resource_module.h | 10 ++++----- include/resource_pack.h | 6 +++--- include/resource_table.h | 24 ++++++++++----------- src/cmd_parser.cpp | 4 ++-- src/config_parser.cpp | 6 ++++-- src/file_manager.cpp | 2 +- src/i_resource_compiler.cpp | 4 ++-- src/id_defined_parser.cpp | 25 +++++++++++----------- src/id_worker.cpp | 28 ++++++++++++------------ src/reference_parser.cpp | 2 +- src/resource_append.cpp | 4 ++-- src/resource_item.cpp | 2 +- src/resource_module.cpp | 8 +++---- src/resource_pack.cpp | 20 +++++++++--------- src/resource_table.cpp | 40 +++++++++++++++++------------------ src/resource_util.cpp | 3 +-- 24 files changed, 128 insertions(+), 126 deletions(-) diff --git a/include/cmd_parser.h b/include/cmd_parser.h index 9dafad5..3c45bfe 100644 --- a/include/cmd_parser.h +++ b/include/cmd_parser.h @@ -134,7 +134,7 @@ void CmdParser::ShowUseage() std::cout << " -m/--modules module name, can add more, split by ','(like entry1,entry2,...).\n"; std::cout << " -j/--json config.json path.\n"; std::cout << " -e/--startId start id mask, e.g 0x01000000,"; - std::cout << " in [0x01000000, 0x06FFFFFF),[0x08000000, 0x41FFFFFF)\n"; + std::cout << " in [0x01000000, 0x06FFFFFF),[0x08000000, 0xFFFFFFFF)\n"; std::cout << " -x/--append resources folder path\n"; std::cout << " -z/--combine flag for incremental compilation\n"; std::cout << " -h/--help Displays this help menu\n"; diff --git a/include/file_manager.h b/include/file_manager.h index 1d39e62..ceb7eeb 100644 --- a/include/file_manager.h +++ b/include/file_manager.h @@ -27,7 +27,7 @@ namespace Restool { class FileManager : public Singleton { public: uint32_t ScanModules(const std::vector &inputs, const std::string &output); - const std::map> &GetResources() const + const std::map> &GetResources() const { return items_; }; @@ -35,7 +35,7 @@ public: { moduleName_ = moduleName; }; - uint32_t MergeResourceItem(const std::map> &resourceInfos); + uint32_t MergeResourceItem(const std::map> &resourceInfos); private: uint32_t ScanModule(const std::string &input, const std::string &output); @@ -43,7 +43,7 @@ private: void CheckAllItems(std::vector> &noBaseResource); // id, resource items - std::map> items_; + std::map> items_; std::string moduleName_; }; } diff --git a/include/i_resource_compiler.h b/include/i_resource_compiler.h index 4735820..06d3041 100644 --- a/include/i_resource_compiler.h +++ b/include/i_resource_compiler.h @@ -28,7 +28,7 @@ public: IResourceCompiler(ResType type, const std::string &output); virtual ~IResourceCompiler(); uint32_t Compile(const std::vector &directoryInfos); - const std::map> &GetResult() const; + const std::map> &GetResult() const; uint32_t Compile(const FileInfo &fileInfo); void SetModuleName(const std::string &moduleName); uint32_t CompileForAppend(const FileInfo &fileInfo); @@ -43,7 +43,7 @@ protected: std::string moduleName_; // id, resource items - std::map> resourceInfos_; + std::map> resourceInfos_; // ResType, name, resourceItems std::map, std::vector> nameInfos_; diff --git a/include/id_defined_parser.h b/include/id_defined_parser.h index 504886b..6c407f7 100755 --- a/include/id_defined_parser.h +++ b/include/id_defined_parser.h @@ -40,19 +40,19 @@ private: uint32_t Init(const std::string &filePath, bool isSystem); using ParseFunction = std::function; void InitParser(); - uint32_t IdDefinedToResourceIds(const cJSON *record, bool isSystem, const int32_t strtSysId = 0); + uint32_t IdDefinedToResourceIds(const cJSON *record, bool isSystem, const int64_t strtSysId = 0); bool ParseType(const cJSON *type, ResourceId &resourceId); bool ParseName(const cJSON *name, ResourceId &resourceId); bool ParseOrder(const cJSON *order, ResourceId &resourceId); bool ParseId(const cJSON *id, ResourceId &resourceId); bool PushResourceId(const ResourceId &resourceId, bool isSystem); - int32_t GetStartId() const; + int64_t GetStartId() const; std::map, ResourceId> sysDefinedIds_; std::map, ResourceId> appDefinedIds_; - std::map idDefineds_; + std::map idDefineds_; std::map handles_; const PackageParser packageParser_; - static const int32_t START_SYS_ID; + static const int64_t START_SYS_ID; ResourceIdCluster type_; cJSON *root_; }; diff --git a/include/id_worker.h b/include/id_worker.h index fcaac91..f2c0cba 100644 --- a/include/id_worker.h +++ b/include/id_worker.h @@ -27,27 +27,27 @@ namespace Global { namespace Restool { class IdWorker : public Singleton { public: - uint32_t Init(ResourceIdCluster &type, int32_t start = 0x01000000); - int32_t GenerateId(ResType resType, const std::string &name); + uint32_t Init(ResourceIdCluster &type, int64_t start = 0x01000000); + int64_t GenerateId(ResType resType, const std::string &name); std::vector GetHeaderId() const; - int32_t GetId(ResType resType, const std::string &name) const; - int32_t GetSystemId(ResType resType, const std::string &name) const; - bool PushCache(ResType resType, const std::string &name, int32_t id); - void PushDelId(int32_t id); + int64_t GetId(ResType resType, const std::string &name) const; + int64_t GetSystemId(ResType resType, const std::string &name) const; + bool PushCache(ResType resType, const std::string &name, int64_t id); + void PushDelId(int64_t id); private: - int32_t GenerateAppId(ResType resType, const std::string &name); - int32_t GenerateSysId(ResType resType, const std::string &name); - int32_t GetMaxId(int32_t startId) const; - int32_t GetCurId(); - int32_t appId_; - int32_t maxId_; + int64_t GenerateAppId(ResType resType, const std::string &name); + int64_t GenerateSysId(ResType resType, const std::string &name); + int64_t GetMaxId(int64_t startId) const; + int64_t GetCurId(); + int64_t appId_; + int64_t maxId_; ResourceIdCluster type_; - std::map, int32_t> ids_; + std::map, int64_t> ids_; std::map, ResourceId> sysDefinedIds_; std::map, ResourceId> appDefinedIds_; - std::vector delIds_; - std::map, int32_t> cacheIds_; + std::vector delIds_; + std::map, int64_t> cacheIds_; }; } } diff --git a/include/reference_parser.h b/include/reference_parser.h index e90552f..322a03e 100644 --- a/include/reference_parser.h +++ b/include/reference_parser.h @@ -27,7 +27,7 @@ class ReferenceParser { public: ReferenceParser(); virtual ~ReferenceParser(); - uint32_t ParseRefInResources(std::map> &items, const std::string &output); + uint32_t ParseRefInResources(std::map> &items, const std::string &output); uint32_t ParseRefInResourceItem(ResourceItem &resourceItem) const; uint32_t ParseRefInJsonFile(ResourceItem &resourceItem, const std::string &output, const bool isIncrement = false); uint32_t ParseRefInString(std::string &value, bool &update) const; diff --git a/include/resource_append.h b/include/resource_append.h index 5feeaba..662c44d 100644 --- a/include/resource_append.h +++ b/include/resource_append.h @@ -30,7 +30,7 @@ public: virtual ~ResourceAppend() {}; uint32_t Append(); uint32_t Combine(); - const std::map>> GetItems() const + const std::map>> GetItems() const { return items_; } @@ -60,15 +60,15 @@ private: std::string ParseString(const char buffer[], int32_t length, int32_t &offset) const; int32_t ParseInt32(const char buffer[], int32_t length, int32_t &offset) const; bool ParseRef(); - bool CheckModuleResourceItem(const std::shared_ptr &resourceItem, int32_t id); + bool CheckModuleResourceItem(const std::shared_ptr &resourceItem, int64_t id); bool IsBaseIdDefined(const FileInfo &fileInfo); #ifdef __WIN32 bool LoadResourceItemWin(const std::string &filePath); #endif void CheckAllItems(std::vector> &noBaseResource); const PackageParser &packageParser_; - std::map>> items_; - std::map>> itemsForModule_; + std::map>> items_; + std::map>> itemsForModule_; std::vector> refs_; }; } diff --git a/include/resource_data.h b/include/resource_data.h index 12f9884..368bfaa 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.003" }; +static const int8_t RESTOOL_VERSION[VERSION_MAX_LEN] = { "Restool 5.004" }; const static int32_t TAG_LEN = 4; enum class KeyType { @@ -190,8 +190,8 @@ struct IdData { }; struct ResourceId { - int32_t id; - int32_t seq; + int64_t id; + int64_t seq; std::string type; std::string name; }; diff --git a/include/resource_module.h b/include/resource_module.h index fcd0997..3e13805 100644 --- a/include/resource_module.h +++ b/include/resource_module.h @@ -28,19 +28,19 @@ public: ResourceModule(const std::string &modulePath, const std::string &moduleOutput, const std::string &moduleName); virtual ~ResourceModule() {}; uint32_t ScanResource(); - const std::map> &GetOwner() const; + const std::map> &GetOwner() const; const std::map> &GetScanDirectorys() const; - static uint32_t MergeResourceItem(std::map> &alls, - const std::map> &other, bool tipError = false); + static uint32_t MergeResourceItem(std::map> &alls, + const std::map> &other, bool tipError = false); protected: const std::string &modulePath_; const std::string &moduleOutput_; const std::string &moduleName_; - std::map> owner_; + std::map> owner_; std::map> scanDirs_; private: - void Push(const std::map> &other); + void Push(const std::map> &other); static const std::vector SCAN_SEQ; }; } diff --git a/include/resource_pack.h b/include/resource_pack.h index a291dbe..7a9b8bb 100644 --- a/include/resource_pack.h +++ b/include/resource_pack.h @@ -52,11 +52,11 @@ private: uint32_t PackAppend(); uint32_t PackCombine(); uint32_t HandleFeature(); - uint32_t FindResourceItems(const std::map> &resInfoLocal, - std::vector &items, int32_t id) const; + uint32_t FindResourceItems(const std::map> &resInfoLocal, + std::vector &items, int64_t id) const; uint32_t HandleLabel(std::vector &items, ConfigParser &config) const; uint32_t HandleIcon(std::vector &items, ConfigParser &config) const; - void SaveResourceItem(const ResourceItem &resourceItem, int32_t nextId) const; + void SaveResourceItem(const ResourceItem &resourceItem, int64_t nextId) const; void CheckConfigJson(); void CheckConfigJsonForCombine(ResourceAppend &resourceAppend); bool CopyIcon(std::string &dataPath, const std::string &idName, std::string &fileName) const; diff --git a/include/resource_table.h b/include/resource_table.h index ebf2fd3..587c971 100644 --- a/include/resource_table.h +++ b/include/resource_table.h @@ -30,8 +30,8 @@ public: ResourceTable(); virtual ~ResourceTable(); uint32_t CreateResourceTable(); - uint32_t CreateResourceTable(const std::map>> &items); - uint32_t LoadResTable(const std::string path, std::map> &resInfos); + uint32_t CreateResourceTable(const std::map>> &items); + uint32_t LoadResTable(const std::string path, std::map> &resInfos); private: struct TableData { int32_t id; @@ -63,7 +63,7 @@ private: int32_t id; }; uint32_t SaveToResouorceIndex(const std::map> &configs) const; - uint32_t CreateIdDefined(const std::map> &allResource) const; + uint32_t CreateIdDefined(const std::map> &allResource) const; bool InitIndexHeader(IndexHeader &indexHeader, uint32_t count) const; bool Prepare(const std::map> &configs, std::map &limitKeyConfigs, @@ -74,16 +74,16 @@ private: void SaveLimitKeyConfigs(const std::map &limitKeyConfigs, std::ostringstream &out) const; void SaveIdSets(const std::map &idSets, std::ostringstream &out) const; - bool ReadFileHeader(std::ifstream &in, IndexHeader &indexHeader, int32_t &pos, int32_t length) const; - bool ReadLimitKeys(std::ifstream &in, std::map> &limitKeys, - uint32_t count, int32_t &pos, int32_t length) const; - bool ReadIdTables(std::ifstream &in, std::map> &datas, - uint32_t count, int32_t &pos, int32_t length) const; - bool ReadDataRecordPrepare(std::ifstream &in, RecordItem &record, int32_t &pos, int32_t length) const; + bool ReadFileHeader(std::ifstream &in, IndexHeader &indexHeader, int64_t &pos, int64_t length) const; + bool ReadLimitKeys(std::ifstream &in, std::map> &limitKeys, + uint32_t count, int64_t &pos, int64_t length) const; + bool ReadIdTables(std::ifstream &in, std::map> &datas, + uint32_t count, int64_t &pos, int64_t length) const; + bool ReadDataRecordPrepare(std::ifstream &in, RecordItem &record, int64_t &pos, int64_t length) const; bool ReadDataRecordStart(std::ifstream &in, RecordItem &record, - const std::map> &limitKeys, - const std::map> &datas, - std::map> &resInfos) const; + const std::map> &limitKeys, + const std::map> &datas, + std::map> &resInfos) const; std::string indexFilePath_; std::string idDefinedPath_; }; diff --git a/src/cmd_parser.cpp b/src/cmd_parser.cpp index 2548b6c..60297e2 100644 --- a/src/cmd_parser.cpp +++ b/src/cmd_parser.cpp @@ -214,8 +214,8 @@ uint32_t PackageParser::AddConfig(const string& argValue) uint32_t PackageParser::AddStartId(const string& argValue) { - startId_ = strtol(argValue.c_str(), nullptr, 16); // 16 is hexadecimal number - if ((startId_ >= 0x01000000 && startId_ < 0x06ffffff) || (startId_ >= 0x08000000 && startId_ < 0x41ffffff)) { + startId_ = strtoll(argValue.c_str(), nullptr, 16); // 16 is hexadecimal number + if ((startId_ >= 0x01000000 && startId_ < 0x06ffffff) || (startId_ >= 0x08000000 && startId_ < 0xffffffff)) { return RESTOOL_SUCCESS; } cerr << "Error: invalid start id " << argValue << endl; diff --git a/src/config_parser.cpp b/src/config_parser.cpp index 3d3993e..b0bfc24 100644 --- a/src/config_parser.cpp +++ b/src/config_parser.cpp @@ -51,12 +51,14 @@ const map ConfigParser::JSON_ARRAY_IDS = { bool ConfigParser::useModule_ = false; ConfigParser::ConfigParser() - : filePath_(""), packageName_(""), moduleName_(""), moduleType_(ModuleType::NONE), root_(nullptr) + : filePath_(""), packageName_(""), moduleName_(""), moduleType_(ModuleType::NONE), + abilityIconId_(0), abilityLabelId_(0), root_(nullptr) { } ConfigParser::ConfigParser(const string &filePath) - : filePath_(filePath), packageName_(""), moduleName_(""), moduleType_(ModuleType::NONE), root_(nullptr) + : filePath_(filePath), packageName_(""), moduleName_(""), moduleType_(ModuleType::NONE), + abilityIconId_(0), abilityLabelId_(0), root_(nullptr) { } diff --git a/src/file_manager.cpp b/src/file_manager.cpp index c1faae5..b861955 100644 --- a/src/file_manager.cpp +++ b/src/file_manager.cpp @@ -44,7 +44,7 @@ uint32_t FileManager::ScanModules(const vector &inputs, const string &ou return ParseReference(output); } -uint32_t FileManager::MergeResourceItem(const map> &resourceInfos) +uint32_t FileManager::MergeResourceItem(const map> &resourceInfos) { return ResourceModule::MergeResourceItem(items_, resourceInfos); } diff --git a/src/i_resource_compiler.cpp b/src/i_resource_compiler.cpp index ad89d9e..1e43666 100644 --- a/src/i_resource_compiler.cpp +++ b/src/i_resource_compiler.cpp @@ -73,7 +73,7 @@ uint32_t IResourceCompiler::Compile(const vector &directoryInfos) return PostCommit(); } -const map> &IResourceCompiler::GetResult() const +const map> &IResourceCompiler::GetResult() const { return resourceInfos_; } @@ -110,7 +110,7 @@ uint32_t IResourceCompiler::PostCommit() { IdWorker &idWorker = IdWorker::GetInstance(); for (const auto &nameInfo : nameInfos_) { - int32_t id = idWorker.GenerateId(nameInfo.first.first, nameInfo.first.second); + int64_t id = idWorker.GenerateId(nameInfo.first.first, nameInfo.first.second); if (id < 0) { cerr << "Error: restype='" << ResourceUtil::ResTypeToString(nameInfo.first.first) << "' name='"; cerr << nameInfo.first.second << "' id not be defined." << endl; diff --git a/src/id_defined_parser.cpp b/src/id_defined_parser.cpp index a6b765b..8e67955 100755 --- a/src/id_defined_parser.cpp +++ b/src/id_defined_parser.cpp @@ -21,7 +21,7 @@ namespace OHOS { namespace Global { namespace Restool { using namespace std; -const int32_t IdDefinedParser::START_SYS_ID = 0x07800000; +const int64_t IdDefinedParser::START_SYS_ID = 0x07800000; IdDefinedParser::IdDefinedParser(const PackageParser &packageParser, const ResourceIdCluster &type) : packageParser_(packageParser), type_(type), root_(nullptr) { @@ -38,7 +38,7 @@ uint32_t IdDefinedParser::Init() { InitParser(); string idDefinedInput = packageParser_.GetIdDefinedInputPath(); - int32_t startId = packageParser_.GetStartId(); + int64_t startId = packageParser_.GetStartId(); bool combine = packageParser_.GetCombine(); bool isSys = type_ == ResourceIdCluster::RES_ID_SYS; for (const auto &inputPath : packageParser_.GetInputs()) { @@ -101,7 +101,7 @@ uint32_t IdDefinedParser::Init(const string &filePath, bool isSystem) cerr << NEW_LINE_PATH << filePath << endl; return RESTOOL_ERROR; } - int32_t startSysId = 0; + int64_t startSysId = 0; if (isSystem) { startSysId = GetStartId(); if (startSysId < 0) { @@ -124,9 +124,9 @@ void IdDefinedParser::InitParser() handles_.emplace("order", bind(&IdDefinedParser::ParseOrder, this, _1, _2)); } -uint32_t IdDefinedParser::IdDefinedToResourceIds(const cJSON *record, bool isSystem, const int32_t startSysId) +uint32_t IdDefinedParser::IdDefinedToResourceIds(const cJSON *record, bool isSystem, const int64_t startSysId) { - int32_t index = -1; + int64_t index = -1; for (cJSON *item = record->child; item; item = item->next) { index++; if (!cJSON_IsObject(item)) { @@ -190,10 +190,11 @@ bool IdDefinedParser::ParseId(const cJSON *origId, ResourceId &resourceId) cerr << " id must be a hex string, eg:^0[xX][0-9a-fA-F]{8}" << endl; return false; } - int32_t id = strtol(idStr.c_str(), nullptr, 16); - if (id < 0x01000000 || (id >= 0x06FFFFFF && id < 0x08000000) || id >= 0x41FFFFFF) { - cerr << "Warning: id_defined.json seq = "<< resourceId.seq; - cerr << " id must in [0x01000000,0x06FFFFFF),[0x08000000,0x41FFFFFF)." << endl; + int64_t id = strtoll(idStr.c_str(), nullptr, 16); + if (id < 0x01000000 || (id > 0x06FFFFFF && id < 0x08000000) || id > 0xFFFFFFFF) { + cerr << "Error: id_defined.json seq = "<< resourceId.seq; + cerr << " id must in [0x01000000,0x06FFFFFF],[0x08000000,0xFFFFFFFF]." << endl; + return false; } resourceId.id = id; return true; @@ -247,7 +248,7 @@ bool IdDefinedParser::ParseOrder(const cJSON *order, ResourceId &resourceId) cerr << "Error: id_defined.json seq =" << resourceId.seq << " order not int." << endl; return false; } - int32_t orderId = order->valueint; + int64_t orderId = order->valueint; if (orderId != resourceId.seq) { cerr << "Error: id_defined.json seq =" << resourceId.seq << " order value "; cerr << orderId << " vs expect " << resourceId.seq << endl; @@ -257,7 +258,7 @@ bool IdDefinedParser::ParseOrder(const cJSON *order, ResourceId &resourceId) return true; } -int32_t IdDefinedParser::GetStartId() const +int64_t IdDefinedParser::GetStartId() const { cJSON *startIdNode = cJSON_GetObjectItem(root_, "startId"); if (!startIdNode) { @@ -270,7 +271,7 @@ int32_t IdDefinedParser::GetStartId() const return -1; } - int32_t id = strtol(startIdNode->valuestring, nullptr, 16); + int64_t id = strtoll(startIdNode->valuestring, nullptr, 16); return id; } diff --git a/src/id_worker.cpp b/src/id_worker.cpp index fe49190..f665c4d 100644 --- a/src/id_worker.cpp +++ b/src/id_worker.cpp @@ -22,7 +22,7 @@ namespace OHOS { namespace Global { namespace Restool { using namespace std; -uint32_t IdWorker::Init(ResourceIdCluster &type, int32_t startId) +uint32_t IdWorker::Init(ResourceIdCluster &type, int64_t startId) { type_ = type; CmdParser &parser = CmdParser::GetInstance(); @@ -40,7 +40,7 @@ uint32_t IdWorker::Init(ResourceIdCluster &type, int32_t startId) return RESTOOL_SUCCESS; } -int32_t IdWorker::GenerateId(ResType resType, const string &name) +int64_t IdWorker::GenerateId(ResType resType, const string &name) { if (type_ == ResourceIdCluster::RES_ID_APP) { return GenerateAppId(resType, name); @@ -48,7 +48,7 @@ int32_t IdWorker::GenerateId(ResType resType, const string &name) return GenerateSysId(resType, name); } -int32_t IdWorker::GetId(ResType resType, const string &name) const +int64_t IdWorker::GetId(ResType resType, const string &name) const { auto result = ids_.find(make_pair(resType, name)); if (result == ids_.end()) { @@ -75,7 +75,7 @@ vector IdWorker::GetHeaderId() const return ids; } -int32_t IdWorker::GetSystemId(ResType resType, const string &name) const +int64_t IdWorker::GetSystemId(ResType resType, const string &name) const { auto result = sysDefinedIds_.find(make_pair(resType, name)); if (result == sysDefinedIds_.end()) { @@ -84,7 +84,7 @@ int32_t IdWorker::GetSystemId(ResType resType, const string &name) const return result->second.id; } -bool IdWorker::PushCache(ResType resType, const string &name, int32_t id) +bool IdWorker::PushCache(ResType resType, const string &name, int64_t id) { auto result = cacheIds_.emplace(make_pair(resType, name), id); if (!result.second) { @@ -99,19 +99,19 @@ bool IdWorker::PushCache(ResType resType, const string &name, int32_t id) return false; } - for (int32_t i = appId_; i < id; i++) { + for (int64_t i = appId_; i < id; i++) { delIds_.push_back(i); } appId_ = id + 1; return true; } -void IdWorker::PushDelId(int32_t id) +void IdWorker::PushDelId(int64_t id) { delIds_.push_back(id); } -int32_t IdWorker::GenerateAppId(ResType resType, const string &name) +int64_t IdWorker::GenerateAppId(ResType resType, const string &name) { auto result = ids_.find(make_pair(resType, name)); if (result != ids_.end()) { @@ -134,7 +134,7 @@ int32_t IdWorker::GenerateAppId(ResType resType, const string &name) cerr << "Error: id count exceed " << appId_ << ">" << maxId_ << endl; return -1; } - int32_t id = -1; + int64_t id = -1; if (!delIds_.empty()) { id = delIds_.front(); delIds_.erase(delIds_.begin()); @@ -148,13 +148,13 @@ int32_t IdWorker::GenerateAppId(ResType resType, const string &name) return id; } -int32_t IdWorker::GetCurId() +int64_t IdWorker::GetCurId() { if (appDefinedIds_.size() == 0) { return appId_++; } while (appId_ <= maxId_) { - int32_t id = appId_; + int64_t id = appId_; auto ret = find_if(appDefinedIds_.begin(), appDefinedIds_.end(), [id](const auto &iter) { return id == iter.second.id; }); @@ -167,7 +167,7 @@ int32_t IdWorker::GetCurId() return -1; } -int32_t IdWorker::GenerateSysId(ResType resType, const string &name) +int64_t IdWorker::GenerateSysId(ResType resType, const string &name) { auto result = ids_.find(make_pair(resType, name)); if (result != ids_.end()) { @@ -182,9 +182,9 @@ int32_t IdWorker::GenerateSysId(ResType resType, const string &name) return -1; } -int32_t IdWorker::GetMaxId(int32_t startId) const +int64_t IdWorker::GetMaxId(int64_t startId) const { - int32_t flag = 1; + int64_t flag = 1; while ((flag & startId) == 0) { flag = flag << 1; } diff --git a/src/reference_parser.cpp b/src/reference_parser.cpp index 5e01d6c..77f5d8c 100644 --- a/src/reference_parser.cpp +++ b/src/reference_parser.cpp @@ -64,7 +64,7 @@ ReferenceParser::~ReferenceParser() } } -uint32_t ReferenceParser::ParseRefInResources(map> &items, const string &output) +uint32_t ReferenceParser::ParseRefInResources(map> &items, const string &output) { for (auto &iter : items) { for (auto &resourceItem : iter.second) { diff --git a/src/resource_append.cpp b/src/resource_append.cpp index 8c39226..f56bb0c 100644 --- a/src/resource_append.cpp +++ b/src/resource_append.cpp @@ -469,7 +469,7 @@ bool ResourceAppend::WriteRawFilesOrResFiles(const string &filePath, const strin bool ResourceAppend::Push(const shared_ptr &resourceItem) { string idName = ResourceUtil::GetIdName(resourceItem->GetName(), resourceItem->GetResType()); - int32_t id = IdWorker::GetInstance().GenerateId(resourceItem->GetResType(), idName); + int64_t id = IdWorker::GetInstance().GenerateId(resourceItem->GetResType(), idName); if (id < 0) { return false; } @@ -611,7 +611,7 @@ int32_t ResourceAppend::ParseInt32(const char buffer[], int32_t length, int32_t return size; } -bool ResourceAppend::CheckModuleResourceItem(const shared_ptr &resourceItem, int32_t id) +bool ResourceAppend::CheckModuleResourceItem(const shared_ptr &resourceItem, int64_t id) { const auto &result = itemsForModule_.find(id); if (result == itemsForModule_.end()) { diff --git a/src/resource_item.cpp b/src/resource_item.cpp index 25ecc1c..35b6391 100644 --- a/src/resource_item.cpp +++ b/src/resource_item.cpp @@ -21,7 +21,7 @@ namespace OHOS { namespace Global { namespace Restool { using namespace std; -ResourceItem::ResourceItem() +ResourceItem::ResourceItem() : type_(ResType::INVALID_RES_TYPE) { } diff --git a/src/resource_module.cpp b/src/resource_module.cpp index b808f30..726c5d9 100644 --- a/src/resource_module.cpp +++ b/src/resource_module.cpp @@ -64,7 +64,7 @@ uint32_t ResourceModule::ScanResource() return RESTOOL_SUCCESS; } -const map> &ResourceModule::GetOwner() const +const map> &ResourceModule::GetOwner() const { return owner_; } @@ -74,8 +74,8 @@ const map> &ResourceModule::GetScanDirectorys() c return scanDirs_; } -uint32_t ResourceModule::MergeResourceItem(map> &alls, - const map> &other, bool tipError) +uint32_t ResourceModule::MergeResourceItem(map> &alls, + const map> &other, bool tipError) { for (const auto &iter : other) { auto result = alls.emplace(iter.first, iter.second); @@ -105,7 +105,7 @@ uint32_t ResourceModule::MergeResourceItem(map> &a return RESTOOL_SUCCESS; } // below private -void ResourceModule::Push(const map> &other) +void ResourceModule::Push(const map> &other) { for (const auto &iter : other) { owner_.emplace(iter.first, iter.second); diff --git a/src/resource_pack.cpp b/src/resource_pack.cpp index 02581d5..31fb068 100644 --- a/src/resource_pack.cpp +++ b/src/resource_pack.cpp @@ -72,7 +72,7 @@ uint32_t ResourcePack::InitModule() moduleName_ = configJson_.GetModuleName(); vector moduleNames = packageParser_.GetModuleNames(); IdWorker &idWorker = IdWorker::GetInstance(); - int32_t startId = packageParser_.GetStartId(); + int64_t startId = packageParser_.GetStartId(); if (startId > 0) { return idWorker.Init(hapType, startId); } @@ -393,14 +393,14 @@ uint32_t ResourcePack::HandleFeature() return RESTOOL_ERROR; } - int32_t labelId = entryJson.GetAbilityLabelId(); - int32_t iconId = entryJson.GetAbilityIconId(); + int64_t labelId = entryJson.GetAbilityLabelId(); + int64_t iconId = entryJson.GetAbilityIconId(); if (labelId <= 0 || iconId <= 0) { cerr << "Error: Entry MainAbility must have 'icon' and 'label'." << endl; return RESTOOL_ERROR; } string path = FileEntry::FilePath(featureDependEntry).Append(RESOURCE_INDEX_FILE).GetPath(); - map> resInfoLocal; + map> resInfoLocal; ResourceTable resourceTable; if (resourceTable.LoadResTable(path, resInfoLocal) != RESTOOL_SUCCESS) { cerr << "Error: LoadResTable fail." << endl; @@ -430,8 +430,8 @@ uint32_t ResourcePack::HandleFeature() return RESTOOL_SUCCESS; } -uint32_t ResourcePack::FindResourceItems(const map> &resInfoLocal, - vector &items, int32_t id) const +uint32_t ResourcePack::FindResourceItems(const map> &resInfoLocal, + vector &items, int64_t id) const { auto ret = resInfoLocal.find(id); if (ret == resInfoLocal.end()) { @@ -459,7 +459,7 @@ uint32_t ResourcePack::FindResourceItems(const map uint32_t ResourcePack::HandleLabel(vector &items, ConfigParser &config) const { - int32_t nextId = 0; + int64_t nextId = 0; string idName; for (auto it : items) { if (it.GetResType() != ResType::STRING) { @@ -508,7 +508,7 @@ bool ResourcePack::CopyIcon(string &dataPath, const string &idName, string &file uint32_t ResourcePack::HandleIcon(vector &items, ConfigParser &config) const { - int32_t nextId = 0; + int64_t nextId = 0; string idName; for (auto it : items) { if (it.GetResType() != ResType::MEDIA) { @@ -545,9 +545,9 @@ uint32_t ResourcePack::HandleIcon(vector &items, ConfigParser &con return RESTOOL_SUCCESS; } -void ResourcePack::SaveResourceItem(const ResourceItem &resourceItem, int32_t nextId) const +void ResourcePack::SaveResourceItem(const ResourceItem &resourceItem, int64_t nextId) const { - map> resInfo; + map> resInfo; vector vet; vet.push_back(resourceItem); resInfo.insert(make_pair(nextId, vet)); diff --git a/src/resource_table.cpp b/src/resource_table.cpp index dffa35c..d10b8e7 100644 --- a/src/resource_table.cpp +++ b/src/resource_table.cpp @@ -68,10 +68,10 @@ uint32_t ResourceTable::CreateResourceTable() return RESTOOL_SUCCESS; } -uint32_t ResourceTable::CreateResourceTable(const map>> &items) +uint32_t ResourceTable::CreateResourceTable(const map>> &items) { map> configs; - map> allResource; + map> allResource; for (const auto &item : items) { vector resourceItems; for (const auto &resourceItemPtr : item.second) { @@ -99,7 +99,7 @@ uint32_t ResourceTable::CreateResourceTable(const map> &resInfos) +uint32_t ResourceTable::LoadResTable(const string path, map> &resInfos) { ifstream in(path, ios::binary); if (!in.is_open()) { @@ -108,27 +108,27 @@ uint32_t ResourceTable::LoadResTable(const string path, map> limitKeys; + map> limitKeys; if (!ReadLimitKeys(in, limitKeys, indexHeader.limitKeyConfigSize, pos, length)) { in.close(); return RESTOOL_ERROR; } - map> datas; + map> datas; if (!ReadIdTables(in, datas, indexHeader.limitKeyConfigSize, pos, length)) { in.close(); return RESTOOL_ERROR; @@ -146,7 +146,7 @@ uint32_t ResourceTable::LoadResTable(const string path, map> &allResource) const +uint32_t ResourceTable::CreateIdDefined(const map> &allResource) const { cJSON *root = cJSON_CreateObject(); cJSON *recordArray = cJSON_CreateArray(); @@ -157,7 +157,7 @@ uint32_t ResourceTable::CreateIdDefined(const map> ResType resType = item.GetResType(); string type = ResourceUtil::ResTypeToString(resType); string name = item.GetName(); - int32_t id = pairPtr.first; + int64_t id = pairPtr.first; if (type.empty()) { cerr << "Error : name = " << name << " ,ResType must is"; cerr << ResourceUtil::GetAllRestypeString() << endl; @@ -328,7 +328,7 @@ void ResourceTable::SaveIdSets(const map &idSets, ostringstream & } } -bool ResourceTable::ReadFileHeader(ifstream &in, IndexHeader &indexHeader, int32_t &pos, int32_t length) const +bool ResourceTable::ReadFileHeader(ifstream &in, IndexHeader &indexHeader, int64_t &pos, int64_t length) const { pos += sizeof(indexHeader); if (pos > length) { @@ -341,8 +341,8 @@ bool ResourceTable::ReadFileHeader(ifstream &in, IndexHeader &indexHeader, int32 return true; } -bool ResourceTable::ReadLimitKeys(ifstream &in, map> &limitKeys, - uint32_t count, int32_t &pos, int32_t length) const +bool ResourceTable::ReadLimitKeys(ifstream &in, map> &limitKeys, + uint32_t count, int64_t &pos, int64_t length) const { for (uint32_t i = 0; i< count; i++) { pos = pos + TAG_LEN + INT_TO_BYTES + INT_TO_BYTES; @@ -377,8 +377,8 @@ bool ResourceTable::ReadLimitKeys(ifstream &in, map> & return true; } -bool ResourceTable::ReadIdTables(std::ifstream &in, std::map> &datas, - uint32_t count, int32_t &pos, int32_t length) const +bool ResourceTable::ReadIdTables(std::ifstream &in, std::map> &datas, + uint32_t count, int64_t &pos, int64_t length) const { for (uint32_t i = 0; i< count; i++) { pos = pos + TAG_LEN + INT_TO_BYTES; @@ -387,7 +387,7 @@ bool ResourceTable::ReadIdTables(std::ifstream &in, std::map(idss.idTag), TAG_LEN); string idTag(reinterpret_cast(idss.idTag), TAG_LEN); if (idTag != "IDSS") { @@ -411,7 +411,7 @@ bool ResourceTable::ReadIdTables(std::ifstream &in, std::map length) { @@ -430,11 +430,11 @@ bool ResourceTable::ReadDataRecordPrepare(ifstream &in, RecordItem &record, int3 } bool ResourceTable::ReadDataRecordStart(std::ifstream &in, RecordItem &record, - const std::map> &limitKeys, - const std::map> &datas, - std::map> &resInfos) const + const std::map> &limitKeys, + const std::map> &datas, + std::map> &resInfos) const { - int32_t offset = in.tellg(); + int64_t offset = in.tellg(); offset = offset - INT_TO_BYTES - INT_TO_BYTES - INT_TO_BYTES; uint16_t value_size = 0; in.read(reinterpret_cast(&value_size), sizeof(uint16_t)); diff --git a/src/resource_util.cpp b/src/resource_util.cpp index 223e102..2ede156 100644 --- a/src/resource_util.cpp +++ b/src/resource_util.cpp @@ -81,8 +81,7 @@ bool ResourceUtil::OpenJsonFile(const string &path, cJSON **root) string jsonString((istreambuf_iterator(ifs)), istreambuf_iterator()); *root = cJSON_Parse(jsonString.c_str()); if (!*root) { - cerr << "Error: cJSON_Parse failed, please check the JSON file." << NEW_LINE_PATH << path; - cerr << "\n" << cJSON_GetErrorPtr() << endl; + cerr << "Error: cJSON_Parse failed, please check the JSON file." << NEW_LINE_PATH << path << endl; ifs.close(); return false; }