资源编译时id固定异常bug处理

Signed-off-by: fangyunzhong <fangyunzhong2@huawei.com>
This commit is contained in:
fangyunzhong
2024-03-15 18:53:29 +08:00
parent ff3933d307
commit b575a1b2a9
24 changed files with 128 additions and 126 deletions
+1 -1
View File
@@ -134,7 +134,7 @@ void CmdParser<T>::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";
+3 -3
View File
@@ -27,7 +27,7 @@ namespace Restool {
class FileManager : public Singleton<FileManager> {
public:
uint32_t ScanModules(const std::vector<std::string> &inputs, const std::string &output);
const std::map<int32_t, std::vector<ResourceItem>> &GetResources() const
const std::map<int64_t, std::vector<ResourceItem>> &GetResources() const
{
return items_;
};
@@ -35,7 +35,7 @@ public:
{
moduleName_ = moduleName;
};
uint32_t MergeResourceItem(const std::map<int32_t, std::vector<ResourceItem>> &resourceInfos);
uint32_t MergeResourceItem(const std::map<int64_t, std::vector<ResourceItem>> &resourceInfos);
private:
uint32_t ScanModule(const std::string &input, const std::string &output);
@@ -43,7 +43,7 @@ private:
void CheckAllItems(std::vector<std::pair<ResType, std::string>> &noBaseResource);
// id, resource items
std::map<int32_t, std::vector<ResourceItem>> items_;
std::map<int64_t, std::vector<ResourceItem>> items_;
std::string moduleName_;
};
}
+2 -2
View File
@@ -28,7 +28,7 @@ public:
IResourceCompiler(ResType type, const std::string &output);
virtual ~IResourceCompiler();
uint32_t Compile(const std::vector<DirectoryInfo> &directoryInfos);
const std::map<int32_t, std::vector<ResourceItem>> &GetResult() const;
const std::map<int64_t, std::vector<ResourceItem>> &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<int32_t, std::vector<ResourceItem>> resourceInfos_;
std::map<int64_t, std::vector<ResourceItem>> resourceInfos_;
// ResType, name, resourceItems
std::map<std::pair<ResType, std::string>, std::vector<ResourceItem>> nameInfos_;
+4 -4
View File
@@ -40,19 +40,19 @@ private:
uint32_t Init(const std::string &filePath, bool isSystem);
using ParseFunction = std::function<bool(const cJSON *, ResourceId&)>;
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<std::pair<ResType, std::string>, ResourceId> sysDefinedIds_;
std::map<std::pair<ResType, std::string>, ResourceId> appDefinedIds_;
std::map<int32_t, ResourceId> idDefineds_;
std::map<int64_t, ResourceId> idDefineds_;
std::map<std::string, ParseFunction> handles_;
const PackageParser packageParser_;
static const int32_t START_SYS_ID;
static const int64_t START_SYS_ID;
ResourceIdCluster type_;
cJSON *root_;
};
+15 -15
View File
@@ -27,27 +27,27 @@ namespace Global {
namespace Restool {
class IdWorker : public Singleton<IdWorker> {
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<ResourceId> 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<std::pair<ResType, std::string>, int32_t> ids_;
std::map<std::pair<ResType, std::string>, int64_t> ids_;
std::map<std::pair<ResType, std::string>, ResourceId> sysDefinedIds_;
std::map<std::pair<ResType, std::string>, ResourceId> appDefinedIds_;
std::vector<int32_t> delIds_;
std::map<std::pair<ResType, std::string>, int32_t> cacheIds_;
std::vector<int64_t> delIds_;
std::map<std::pair<ResType, std::string>, int64_t> cacheIds_;
};
}
}
+1 -1
View File
@@ -27,7 +27,7 @@ class ReferenceParser {
public:
ReferenceParser();
virtual ~ReferenceParser();
uint32_t ParseRefInResources(std::map<int32_t, std::vector<ResourceItem>> &items, const std::string &output);
uint32_t ParseRefInResources(std::map<int64_t, std::vector<ResourceItem>> &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;
+4 -4
View File
@@ -30,7 +30,7 @@ public:
virtual ~ResourceAppend() {};
uint32_t Append();
uint32_t Combine();
const std::map<int32_t, std::vector<std::shared_ptr<ResourceItem>>> GetItems() const
const std::map<int64_t, std::vector<std::shared_ptr<ResourceItem>>> 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> &resourceItem, int32_t id);
bool CheckModuleResourceItem(const std::shared_ptr<ResourceItem> &resourceItem, int64_t id);
bool IsBaseIdDefined(const FileInfo &fileInfo);
#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_;
std::map<int64_t, std::vector<std::shared_ptr<ResourceItem>>> items_;
std::map<int64_t, std::vector<std::shared_ptr<ResourceItem>>> itemsForModule_;
std::vector<std::shared_ptr<ResourceItem>> refs_;
};
}
+3 -3
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.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;
};
+5 -5
View File
@@ -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<int32_t, std::vector<ResourceItem>> &GetOwner() const;
const std::map<int64_t, std::vector<ResourceItem>> &GetOwner() const;
const std::map<ResType, std::vector<DirectoryInfo>> &GetScanDirectorys() const;
static uint32_t MergeResourceItem(std::map<int32_t, std::vector<ResourceItem>> &alls,
const std::map<int32_t, std::vector<ResourceItem>> &other, bool tipError = false);
static uint32_t MergeResourceItem(std::map<int64_t, std::vector<ResourceItem>> &alls,
const std::map<int64_t, std::vector<ResourceItem>> &other, bool tipError = false);
protected:
const std::string &modulePath_;
const std::string &moduleOutput_;
const std::string &moduleName_;
std::map<int32_t, std::vector<ResourceItem>> owner_;
std::map<int64_t, std::vector<ResourceItem>> owner_;
std::map<ResType, std::vector<DirectoryInfo>> scanDirs_;
private:
void Push(const std::map<int32_t, std::vector<ResourceItem>> &other);
void Push(const std::map<int64_t, std::vector<ResourceItem>> &other);
static const std::vector<ResType> SCAN_SEQ;
};
}
+3 -3
View File
@@ -52,11 +52,11 @@ private:
uint32_t PackAppend();
uint32_t PackCombine();
uint32_t HandleFeature();
uint32_t FindResourceItems(const std::map<int32_t, std::vector<ResourceItem>> &resInfoLocal,
std::vector<ResourceItem> &items, int32_t id) const;
uint32_t FindResourceItems(const std::map<int64_t, std::vector<ResourceItem>> &resInfoLocal,
std::vector<ResourceItem> &items, int64_t id) const;
uint32_t HandleLabel(std::vector<ResourceItem> &items, ConfigParser &config) const;
uint32_t HandleIcon(std::vector<ResourceItem> &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;
+12 -12
View File
@@ -30,8 +30,8 @@ public:
ResourceTable();
virtual ~ResourceTable();
uint32_t CreateResourceTable();
uint32_t CreateResourceTable(const std::map<int32_t, std::vector<std::shared_ptr<ResourceItem>>> &items);
uint32_t LoadResTable(const std::string path, std::map<int32_t, std::vector<ResourceItem>> &resInfos);
uint32_t CreateResourceTable(const std::map<int64_t, std::vector<std::shared_ptr<ResourceItem>>> &items);
uint32_t LoadResTable(const std::string path, std::map<int64_t, std::vector<ResourceItem>> &resInfos);
private:
struct TableData {
int32_t id;
@@ -63,7 +63,7 @@ private:
int32_t id;
};
uint32_t SaveToResouorceIndex(const std::map<std::string, std::vector<TableData>> &configs) const;
uint32_t CreateIdDefined(const std::map<int32_t, std::vector<ResourceItem>> &allResource) const;
uint32_t CreateIdDefined(const std::map<int64_t, std::vector<ResourceItem>> &allResource) const;
bool InitIndexHeader(IndexHeader &indexHeader, uint32_t count) const;
bool Prepare(const std::map<std::string, std::vector<TableData>> &configs,
std::map<std::string, LimitKeyConfig> &limitKeyConfigs,
@@ -74,16 +74,16 @@ private:
void SaveLimitKeyConfigs(const std::map<std::string, LimitKeyConfig> &limitKeyConfigs,
std::ostringstream &out) const;
void SaveIdSets(const std::map<std::string, IdSet> &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<int32_t, std::vector<KeyParam>> &limitKeys,
uint32_t count, int32_t &pos, int32_t length) const;
bool ReadIdTables(std::ifstream &in, std::map<int32_t, std::pair<int32_t, int32_t>> &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<int64_t, std::vector<KeyParam>> &limitKeys,
uint32_t count, int64_t &pos, int64_t length) const;
bool ReadIdTables(std::ifstream &in, std::map<int64_t, std::pair<int64_t, int64_t>> &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<int32_t, std::vector<KeyParam>> &limitKeys,
const std::map<int32_t, std::pair<int32_t, int32_t>> &datas,
std::map<int32_t, std::vector<ResourceItem>> &resInfos) const;
const std::map<int64_t, std::vector<KeyParam>> &limitKeys,
const std::map<int64_t, std::pair<int64_t, int64_t>> &datas,
std::map<int64_t, std::vector<ResourceItem>> &resInfos) const;
std::string indexFilePath_;
std::string idDefinedPath_;
};
+2 -2
View File
@@ -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;
+4 -2
View File
@@ -51,12 +51,14 @@ const map<string, string> 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)
{
}
+1 -1
View File
@@ -44,7 +44,7 @@ uint32_t FileManager::ScanModules(const vector<string> &inputs, const string &ou
return ParseReference(output);
}
uint32_t FileManager::MergeResourceItem(const map<int32_t, vector<ResourceItem>> &resourceInfos)
uint32_t FileManager::MergeResourceItem(const map<int64_t, vector<ResourceItem>> &resourceInfos)
{
return ResourceModule::MergeResourceItem(items_, resourceInfos);
}
+2 -2
View File
@@ -73,7 +73,7 @@ uint32_t IResourceCompiler::Compile(const vector<DirectoryInfo> &directoryInfos)
return PostCommit();
}
const map<int32_t, vector<ResourceItem>> &IResourceCompiler::GetResult() const
const map<int64_t, vector<ResourceItem>> &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;
+13 -12
View File
@@ -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;
}
+14 -14
View File
@@ -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<PackageParser> &parser = CmdParser<PackageParser>::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<ResourceId> 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;
}
+1 -1
View File
@@ -64,7 +64,7 @@ ReferenceParser::~ReferenceParser()
}
}
uint32_t ReferenceParser::ParseRefInResources(map<int32_t, vector<ResourceItem>> &items, const string &output)
uint32_t ReferenceParser::ParseRefInResources(map<int64_t, vector<ResourceItem>> &items, const string &output)
{
for (auto &iter : items) {
for (auto &resourceItem : iter.second) {
+2 -2
View File
@@ -469,7 +469,7 @@ bool ResourceAppend::WriteRawFilesOrResFiles(const string &filePath, const strin
bool ResourceAppend::Push(const shared_ptr<ResourceItem> &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> &resourceItem, int32_t id)
bool ResourceAppend::CheckModuleResourceItem(const shared_ptr<ResourceItem> &resourceItem, int64_t id)
{
const auto &result = itemsForModule_.find(id);
if (result == itemsForModule_.end()) {
+1 -1
View File
@@ -21,7 +21,7 @@ namespace OHOS {
namespace Global {
namespace Restool {
using namespace std;
ResourceItem::ResourceItem()
ResourceItem::ResourceItem() : type_(ResType::INVALID_RES_TYPE)
{
}
+4 -4
View File
@@ -64,7 +64,7 @@ uint32_t ResourceModule::ScanResource()
return RESTOOL_SUCCESS;
}
const map<int32_t, vector<ResourceItem>> &ResourceModule::GetOwner() const
const map<int64_t, vector<ResourceItem>> &ResourceModule::GetOwner() const
{
return owner_;
}
@@ -74,8 +74,8 @@ const map<ResType, vector<DirectoryInfo>> &ResourceModule::GetScanDirectorys() c
return scanDirs_;
}
uint32_t ResourceModule::MergeResourceItem(map<int32_t, vector<ResourceItem>> &alls,
const map<int32_t, vector<ResourceItem>> &other, bool tipError)
uint32_t ResourceModule::MergeResourceItem(map<int64_t, vector<ResourceItem>> &alls,
const map<int64_t, vector<ResourceItem>> &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<int32_t, vector<ResourceItem>> &a
return RESTOOL_SUCCESS;
}
// below private
void ResourceModule::Push(const map<int32_t, std::vector<ResourceItem>> &other)
void ResourceModule::Push(const map<int64_t, std::vector<ResourceItem>> &other)
{
for (const auto &iter : other) {
owner_.emplace(iter.first, iter.second);
+10 -10
View File
@@ -72,7 +72,7 @@ uint32_t ResourcePack::InitModule()
moduleName_ = configJson_.GetModuleName();
vector<string> 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<int32_t, vector<ResourceItem>> resInfoLocal;
map<int64_t, vector<ResourceItem>> 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<int32_t, vector<ResourceItem>> &resInfoLocal,
vector<ResourceItem> &items, int32_t id) const
uint32_t ResourcePack::FindResourceItems(const map<int64_t, vector<ResourceItem>> &resInfoLocal,
vector<ResourceItem> &items, int64_t id) const
{
auto ret = resInfoLocal.find(id);
if (ret == resInfoLocal.end()) {
@@ -459,7 +459,7 @@ uint32_t ResourcePack::FindResourceItems(const map<int32_t, vector<ResourceItem>
uint32_t ResourcePack::HandleLabel(vector<ResourceItem> &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<ResourceItem> &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<ResourceItem> &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<int32_t, vector<ResourceItem>> resInfo;
map<int64_t, vector<ResourceItem>> resInfo;
vector<ResourceItem> vet;
vet.push_back(resourceItem);
resInfo.insert(make_pair(nextId, vet));
+20 -20
View File
@@ -68,10 +68,10 @@ uint32_t ResourceTable::CreateResourceTable()
return RESTOOL_SUCCESS;
}
uint32_t ResourceTable::CreateResourceTable(const map<int32_t, vector<shared_ptr<ResourceItem>>> &items)
uint32_t ResourceTable::CreateResourceTable(const map<int64_t, vector<shared_ptr<ResourceItem>>> &items)
{
map<string, vector<TableData>> configs;
map<int32_t, vector<ResourceItem>> allResource;
map<int64_t, vector<ResourceItem>> allResource;
for (const auto &item : items) {
vector<ResourceItem> resourceItems;
for (const auto &resourceItemPtr : item.second) {
@@ -99,7 +99,7 @@ uint32_t ResourceTable::CreateResourceTable(const map<int32_t, vector<shared_ptr
return RESTOOL_SUCCESS;
}
uint32_t ResourceTable::LoadResTable(const string path, map<int32_t, vector<ResourceItem>> &resInfos)
uint32_t ResourceTable::LoadResTable(const string path, map<int64_t, vector<ResourceItem>> &resInfos)
{
ifstream in(path, ios::binary);
if (!in.is_open()) {
@@ -108,27 +108,27 @@ uint32_t ResourceTable::LoadResTable(const string path, map<int32_t, vector<Reso
}
in.seekg(0, ios::end);
int32_t length = in.tellg();
int64_t length = in.tellg();
if (length <= 0) {
in.close();
return RESTOOL_ERROR;
}
in.seekg(0, ios::beg);
int32_t pos = 0;
int64_t pos = 0;
IndexHeader indexHeader;
if (!ReadFileHeader(in, indexHeader, pos, length)) {
in.close();
return RESTOOL_ERROR;
}
map<int32_t, vector<KeyParam>> limitKeys;
map<int64_t, vector<KeyParam>> limitKeys;
if (!ReadLimitKeys(in, limitKeys, indexHeader.limitKeyConfigSize, pos, length)) {
in.close();
return RESTOOL_ERROR;
}
map<int32_t, pair<int32_t, int32_t>> datas;
map<int64_t, pair<int64_t, int64_t>> 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<int32_t, vector<Reso
return RESTOOL_SUCCESS;
}
uint32_t ResourceTable::CreateIdDefined(const map<int32_t, vector<ResourceItem>> &allResource) const
uint32_t ResourceTable::CreateIdDefined(const map<int64_t, vector<ResourceItem>> &allResource) const
{
cJSON *root = cJSON_CreateObject();
cJSON *recordArray = cJSON_CreateArray();
@@ -157,7 +157,7 @@ uint32_t ResourceTable::CreateIdDefined(const map<int32_t, vector<ResourceItem>>
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<string, IdSet> &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<int32_t, vector<KeyParam>> &limitKeys,
uint32_t count, int32_t &pos, int32_t length) const
bool ResourceTable::ReadLimitKeys(ifstream &in, map<int64_t, vector<KeyParam>> &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<int32_t, vector<KeyParam>> &
return true;
}
bool ResourceTable::ReadIdTables(std::ifstream &in, std::map<int32_t, std::pair<int32_t, int32_t>> &datas,
uint32_t count, int32_t &pos, int32_t length) const
bool ResourceTable::ReadIdTables(std::ifstream &in, std::map<int64_t, std::pair<int64_t, int64_t>> &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<int32_t, std::pair<
return false;
}
IdSet idss;
int32_t offset = in.tellg();
int64_t offset = in.tellg();
in.read(reinterpret_cast<char *>(idss.idTag), TAG_LEN);
string idTag(reinterpret_cast<const char *>(idss.idTag), TAG_LEN);
if (idTag != "IDSS") {
@@ -411,7 +411,7 @@ bool ResourceTable::ReadIdTables(std::ifstream &in, std::map<int32_t, std::pair<
return true;
}
bool ResourceTable::ReadDataRecordPrepare(ifstream &in, RecordItem &record, int32_t &pos, int32_t length) const
bool ResourceTable::ReadDataRecordPrepare(ifstream &in, RecordItem &record, int64_t &pos, int64_t length) const
{
pos = pos + INT_TO_BYTES;
if (pos > length) {
@@ -430,11 +430,11 @@ bool ResourceTable::ReadDataRecordPrepare(ifstream &in, RecordItem &record, int3
}
bool ResourceTable::ReadDataRecordStart(std::ifstream &in, RecordItem &record,
const std::map<int32_t, std::vector<KeyParam>> &limitKeys,
const std::map<int32_t, std::pair<int32_t, int32_t>> &datas,
std::map<int32_t, std::vector<ResourceItem>> &resInfos) const
const std::map<int64_t, std::vector<KeyParam>> &limitKeys,
const std::map<int64_t, std::pair<int64_t, int64_t>> &datas,
std::map<int64_t, std::vector<ResourceItem>> &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<char *>(&value_size), sizeof(uint16_t));
+1 -2
View File
@@ -81,8 +81,7 @@ bool ResourceUtil::OpenJsonFile(const string &path, cJSON **root)
string jsonString((istreambuf_iterator<char>(ifs)), istreambuf_iterator<char>());
*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;
}