mirror of
https://github.com/openharmony/developtools_global_resource_tool.git
synced 2026-07-18 17:24:42 -04:00
@@ -45,7 +45,7 @@ public:
|
||||
const std::vector<std::string> &GetModuleNames() const;
|
||||
const std::string &GetConfig() const;
|
||||
const std::string &GetRestoolPath() const;
|
||||
int32_t GetStartId() const;
|
||||
uint32_t GetStartId() const;
|
||||
bool IsFileList() const;
|
||||
const std::vector<std::string> &GetAppend() const;
|
||||
bool GetCombine() const;
|
||||
@@ -60,6 +60,7 @@ public:
|
||||
private:
|
||||
void InitCommand();
|
||||
uint32_t ParseCommand(int argc, char *argv[]);
|
||||
uint32_t CheckError(int argc, char *argv[], int c, int optIndex);
|
||||
uint32_t AddInput(const std::string& argValue);
|
||||
uint32_t AddPackageName(const std::string& argValue);
|
||||
uint32_t AddOutput(const std::string& argValue);
|
||||
@@ -81,7 +82,7 @@ private:
|
||||
uint32_t SetIdDefinedInputPath(const std::string& argValue);
|
||||
uint32_t AddSysIdDefined(const std::string& argValue);
|
||||
bool IsAscii(const std::string& argValue) const;
|
||||
bool IsLongOpt(char *argv[]) const;
|
||||
bool IsLongOpt(int argc, char *argv[]) const;
|
||||
uint32_t IconCheck();
|
||||
uint32_t ParseTargetConfig(const std::string& argValue);
|
||||
|
||||
@@ -97,7 +98,7 @@ private:
|
||||
std::vector<std::string> moduleNames_;
|
||||
std::string configPath_;
|
||||
std::string restoolPath_;
|
||||
int32_t startId_ = 0;
|
||||
uint32_t startId_ = 0;
|
||||
bool isFileList_ = false;
|
||||
std::vector<std::string> append_;
|
||||
bool combine_ = false;
|
||||
|
||||
+1
-3
@@ -32,15 +32,13 @@ public:
|
||||
std::vector<ResourceId> GetHeaderId() const;
|
||||
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:
|
||||
int64_t GenerateAppId(ResType resType, const std::string &name);
|
||||
int64_t GenerateSysId(ResType resType, const std::string &name);
|
||||
uint64_t GetMaxId(uint64_t startId) const;
|
||||
int64_t GetCurId();
|
||||
int64_t appId_;
|
||||
uint64_t appId_;
|
||||
uint64_t maxId_;
|
||||
ResourceIdCluster type_;
|
||||
std::map<std::pair<ResType, std::string>, int64_t> ids_;
|
||||
|
||||
@@ -74,12 +74,12 @@ 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, uint64_t &pos, int64_t length) const;
|
||||
bool ReadFileHeader(std::ifstream &in, IndexHeader &indexHeader, uint64_t &pos, uint64_t length) const;
|
||||
bool ReadLimitKeys(std::ifstream &in, std::map<int64_t, std::vector<KeyParam>> &limitKeys,
|
||||
uint32_t count, uint64_t &pos, int64_t length) const;
|
||||
uint32_t count, uint64_t &pos, uint64_t length) const;
|
||||
bool ReadIdTables(std::ifstream &in, std::map<int64_t, std::pair<int64_t, int64_t>> &datas,
|
||||
uint32_t count, uint64_t &pos, int64_t length) const;
|
||||
bool ReadDataRecordPrepare(std::ifstream &in, RecordItem &record, uint64_t &pos, int64_t length) const;
|
||||
uint32_t count, uint64_t &pos, uint64_t length) const;
|
||||
bool ReadDataRecordPrepare(std::ifstream &in, RecordItem &record, uint64_t &pos, uint64_t length) const;
|
||||
bool ReadDataRecordStart(std::ifstream &in, RecordItem &record,
|
||||
const std::map<int64_t, std::vector<KeyParam>> &limitKeys,
|
||||
const std::map<int64_t, std::pair<int64_t, int64_t>> &datas,
|
||||
|
||||
+41
-27
@@ -101,7 +101,7 @@ const string &PackageParser::GetRestoolPath() const
|
||||
return restoolPath_;
|
||||
}
|
||||
|
||||
int32_t PackageParser::GetStartId() const
|
||||
uint32_t PackageParser::GetStartId() const
|
||||
{
|
||||
return startId_;
|
||||
}
|
||||
@@ -472,23 +472,49 @@ uint32_t PackageParser::ParseFileList(const string& fileListPath)
|
||||
return RESTOOL_SUCCESS;
|
||||
}
|
||||
|
||||
uint32_t PackageParser::CheckError(int argc, char *argv[], int c, int optIndex)
|
||||
{
|
||||
if (optIndex != -1) {
|
||||
if ((optarg == nullptr && (optind - 1 < 0 || optind - 1 >= argc)) ||
|
||||
(optarg != nullptr && (optind - 2 < 0 || optind - 2 >= argc))) { // 1 or 2 menas optind offset value
|
||||
return RESTOOL_ERROR;
|
||||
}
|
||||
string curOpt = (optarg == nullptr) ? argv[optind - 1] : argv[optind - 2];
|
||||
if (curOpt != ("--" + string(CMD_OPTS[optIndex].name))) {
|
||||
cerr << "Error: unknown option " << curOpt << endl;
|
||||
return RESTOOL_ERROR;
|
||||
}
|
||||
}
|
||||
if (c == Option::UNKNOWN) {
|
||||
if (optopt == 0 && (optind - 1 < 0 || optind - 1 >= argc)) {
|
||||
return RESTOOL_ERROR;
|
||||
}
|
||||
string optUnknown = (optopt == 0) ? argv[optind - 1] : ("-" + string(1, optopt));
|
||||
cerr << "Error: unknown option " << optUnknown << endl;
|
||||
return RESTOOL_ERROR;
|
||||
}
|
||||
if (c == Option::NO_ARGUMENT) {
|
||||
if (optind - 1 < 0 || optind - 1 >= argc) {
|
||||
return RESTOOL_ERROR;
|
||||
}
|
||||
if (IsLongOpt(argc, argv)) {
|
||||
cerr << "Error: option " << argv[optind - 1] << " must have argument" << endl;
|
||||
} else {
|
||||
cerr << "Error: unknown option " << argv[optind - 1] << endl;
|
||||
}
|
||||
return RESTOOL_ERROR;
|
||||
}
|
||||
return RESTOOL_SUCCESS;
|
||||
}
|
||||
|
||||
uint32_t PackageParser::ParseCommand(int argc, char *argv[])
|
||||
{
|
||||
restoolPath_ = string(argv[0]);
|
||||
while (true) {
|
||||
int optIndex = -1;
|
||||
opterr = 0;
|
||||
int c = getopt_long(argc, argv, CMD_PARAMS.c_str(), CMD_OPTS, &optIndex);
|
||||
if (optIndex != -1) {
|
||||
// 1 or 2 menas optind offset value
|
||||
if ((optarg == nullptr && optind - 1 < 0) || (optarg != nullptr && optind - 2 < 0)) {
|
||||
return RESTOOL_ERROR;
|
||||
}
|
||||
string curOpt = (optarg == nullptr) ? argv[optind - 1] : argv[optind - 2];
|
||||
if (curOpt != ("--" + string(CMD_OPTS[optIndex].name))) {
|
||||
cerr << "Error: unknown option " << curOpt << endl;
|
||||
return RESTOOL_ERROR;
|
||||
}
|
||||
if (CheckError(argc, argv, c, optIndex) != RESTOOL_SUCCESS) {
|
||||
return RESTOOL_ERROR;
|
||||
}
|
||||
if (c == Option::END) {
|
||||
if (argc == optind) {
|
||||
@@ -501,19 +527,7 @@ uint32_t PackageParser::ParseCommand(int argc, char *argv[])
|
||||
cerr << errmsg << endl;
|
||||
return RESTOOL_ERROR;
|
||||
}
|
||||
if (c == Option::UNKNOWN) {
|
||||
string optUnknown = (optopt == 0) ? argv[optind - 1] : ("-" + string(1, optopt));
|
||||
cerr << "Error: unknown option " << optUnknown << endl;
|
||||
return RESTOOL_ERROR;
|
||||
}
|
||||
if (c == Option::NO_ARGUMENT) {
|
||||
if (IsLongOpt(argv)) {
|
||||
cerr << "Error: option " << argv[optind - 1] << " must have argument" << endl;
|
||||
} else {
|
||||
cerr << "Error: unknown option " << argv[optind - 1] << endl;
|
||||
}
|
||||
return RESTOOL_ERROR;
|
||||
}
|
||||
|
||||
string argValue = (optarg != nullptr) ? optarg : "";
|
||||
if (c == Option::FILELIST) {
|
||||
return ParseFileList(argValue);
|
||||
@@ -525,9 +539,9 @@ uint32_t PackageParser::ParseCommand(int argc, char *argv[])
|
||||
return RESTOOL_SUCCESS;
|
||||
}
|
||||
|
||||
bool PackageParser::IsLongOpt(char *argv[]) const
|
||||
bool PackageParser::IsLongOpt(int argc, char *argv[]) const
|
||||
{
|
||||
if (optind - 1 < 0) {
|
||||
if (optind - 1 < 0 || optind - 1 >= argc) {
|
||||
return false;
|
||||
}
|
||||
for (auto iter : CMD_OPTS) {
|
||||
|
||||
@@ -38,7 +38,7 @@ uint32_t IdDefinedParser::Init()
|
||||
{
|
||||
InitParser();
|
||||
string idDefinedInput = packageParser_.GetIdDefinedInputPath();
|
||||
int64_t startId = packageParser_.GetStartId();
|
||||
int64_t startId = static_cast<int64_t>(packageParser_.GetStartId());
|
||||
bool combine = packageParser_.GetCombine();
|
||||
bool isSys = type_ == ResourceIdCluster::RES_ID_SYS;
|
||||
for (const auto &inputPath : packageParser_.GetInputs()) {
|
||||
|
||||
+5
-32
@@ -34,7 +34,7 @@ uint32_t IdWorker::Init(ResourceIdCluster &type, int64_t startId)
|
||||
sysDefinedIds_ = idDefinedParser.GetSysDefinedIds();
|
||||
appDefinedIds_ = idDefinedParser.GetAppDefinedIds();
|
||||
if (type == ResourceIdCluster::RES_ID_APP) {
|
||||
appId_ = startId;
|
||||
appId_ = static_cast<uint64_t>(startId);
|
||||
maxId_ = GetMaxId(startId);
|
||||
}
|
||||
return RESTOOL_SUCCESS;
|
||||
@@ -84,33 +84,6 @@ int64_t IdWorker::GetSystemId(ResType resType, const string &name) const
|
||||
return result->second.id;
|
||||
}
|
||||
|
||||
bool IdWorker::PushCache(ResType resType, const string &name, int64_t id)
|
||||
{
|
||||
auto result = cacheIds_.emplace(make_pair(resType, name), id);
|
||||
if (!result.second) {
|
||||
return false;
|
||||
}
|
||||
if (appId_ == id) {
|
||||
appId_ = id + 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (id < appId_) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int64_t i = appId_; i < id; i++) {
|
||||
delIds_.push_back(i);
|
||||
}
|
||||
appId_ = id + 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
void IdWorker::PushDelId(int64_t id)
|
||||
{
|
||||
delIds_.push_back(id);
|
||||
}
|
||||
|
||||
int64_t IdWorker::GenerateAppId(ResType resType, const string &name)
|
||||
{
|
||||
auto result = ids_.find(make_pair(resType, name));
|
||||
@@ -151,15 +124,15 @@ int64_t IdWorker::GenerateAppId(ResType resType, const string &name)
|
||||
int64_t IdWorker::GetCurId()
|
||||
{
|
||||
if (appDefinedIds_.size() == 0) {
|
||||
return appId_++;
|
||||
return static_cast<int64_t>(appId_++);
|
||||
}
|
||||
while (appId_ <= maxId_) {
|
||||
int64_t id = appId_;
|
||||
uint64_t id = appId_;
|
||||
auto ret = find_if(appDefinedIds_.begin(), appDefinedIds_.end(), [id](const auto &iter) {
|
||||
return id == iter.second.id;
|
||||
});
|
||||
if (ret == appDefinedIds_.end()) {
|
||||
return appId_++;
|
||||
return static_cast<int64_t>(appId_++);
|
||||
}
|
||||
appId_++;
|
||||
}
|
||||
@@ -188,7 +161,7 @@ uint64_t IdWorker::GetMaxId(uint64_t startId) const
|
||||
while ((flag & startId) == 0) {
|
||||
flag = flag << 1;
|
||||
}
|
||||
return (startId + flag - 1);
|
||||
return (startId + flag - 1) > 0 ? (startId + flag - 1) : 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ uint32_t ResourcePack::InitModule()
|
||||
moduleName_ = configJson_.GetModuleName();
|
||||
vector<string> moduleNames = packageParser_.GetModuleNames();
|
||||
IdWorker &idWorker = IdWorker::GetInstance();
|
||||
int64_t startId = packageParser_.GetStartId();
|
||||
int64_t startId = static_cast<int64_t>(packageParser_.GetStartId());
|
||||
if (startId > 0) {
|
||||
return idWorker.Init(hapType, startId);
|
||||
}
|
||||
@@ -474,8 +474,7 @@ uint32_t ResourcePack::HandleLabel(vector<ResourceItem> &items, ConfigParser &co
|
||||
if (it.GetDataLength() - 1 < 0) {
|
||||
return RESTOOL_ERROR;
|
||||
}
|
||||
if (!it.SetData(reinterpret_cast<const int8_t *>(data.c_str()),
|
||||
static_cast<uint32_t>(it.GetDataLength() - 1))) {
|
||||
if (!it.SetData(reinterpret_cast<const int8_t *>(data.c_str()), it.GetDataLength() - 1)) {
|
||||
return RESTOOL_ERROR;
|
||||
}
|
||||
if (nextId <= 0) {
|
||||
|
||||
@@ -117,26 +117,26 @@ uint32_t ResourceTable::LoadResTable(const string path, map<int64_t, vector<Reso
|
||||
|
||||
uint64_t pos = 0;
|
||||
IndexHeader indexHeader;
|
||||
if (!ReadFileHeader(in, indexHeader, pos, length)) {
|
||||
if (!ReadFileHeader(in, indexHeader, pos, static_cast<uint64_t>(length))) {
|
||||
in.close();
|
||||
return RESTOOL_ERROR;
|
||||
}
|
||||
|
||||
map<int64_t, vector<KeyParam>> limitKeys;
|
||||
if (!ReadLimitKeys(in, limitKeys, indexHeader.limitKeyConfigSize, pos, length)) {
|
||||
if (!ReadLimitKeys(in, limitKeys, indexHeader.limitKeyConfigSize, pos, static_cast<uint64_t>(length))) {
|
||||
in.close();
|
||||
return RESTOOL_ERROR;
|
||||
}
|
||||
|
||||
map<int64_t, pair<int64_t, int64_t>> datas;
|
||||
if (!ReadIdTables(in, datas, indexHeader.limitKeyConfigSize, pos, length)) {
|
||||
if (!ReadIdTables(in, datas, indexHeader.limitKeyConfigSize, pos, static_cast<uint64_t>(length))) {
|
||||
in.close();
|
||||
return RESTOOL_ERROR;
|
||||
}
|
||||
|
||||
while (in.tellg() < length) {
|
||||
RecordItem record;
|
||||
if (!ReadDataRecordPrepare(in, record, pos, length) ||
|
||||
if (!ReadDataRecordPrepare(in, record, pos, static_cast<uint64_t>(length)) ||
|
||||
!ReadDataRecordStart(in, record, limitKeys, datas, resInfos)) {
|
||||
in.close();
|
||||
return RESTOOL_ERROR;
|
||||
@@ -347,7 +347,7 @@ void ResourceTable::SaveIdSets(const map<string, IdSet> &idSets, ostringstream &
|
||||
}
|
||||
}
|
||||
|
||||
bool ResourceTable::ReadFileHeader(ifstream &in, IndexHeader &indexHeader, uint64_t &pos, int64_t length) const
|
||||
bool ResourceTable::ReadFileHeader(ifstream &in, IndexHeader &indexHeader, uint64_t &pos, uint64_t length) const
|
||||
{
|
||||
pos += sizeof(indexHeader);
|
||||
if (pos > length) {
|
||||
@@ -361,7 +361,7 @@ bool ResourceTable::ReadFileHeader(ifstream &in, IndexHeader &indexHeader, uint6
|
||||
}
|
||||
|
||||
bool ResourceTable::ReadLimitKeys(ifstream &in, map<int64_t, vector<KeyParam>> &limitKeys,
|
||||
uint32_t count, uint64_t &pos, int64_t length) const
|
||||
uint32_t count, uint64_t &pos, uint64_t length) const
|
||||
{
|
||||
for (uint32_t i = 0; i< count; i++) {
|
||||
pos = pos + TAG_LEN + INT_TO_BYTES + INT_TO_BYTES;
|
||||
@@ -397,7 +397,7 @@ bool ResourceTable::ReadLimitKeys(ifstream &in, map<int64_t, vector<KeyParam>> &
|
||||
}
|
||||
|
||||
bool ResourceTable::ReadIdTables(std::ifstream &in, std::map<int64_t, std::pair<int64_t, int64_t>> &datas,
|
||||
uint32_t count, uint64_t &pos, int64_t length) const
|
||||
uint32_t count, uint64_t &pos, uint64_t length) const
|
||||
{
|
||||
for (uint32_t i = 0; i< count; i++) {
|
||||
pos = pos + TAG_LEN + INT_TO_BYTES;
|
||||
@@ -430,7 +430,7 @@ bool ResourceTable::ReadIdTables(std::ifstream &in, std::map<int64_t, std::pair<
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ResourceTable::ReadDataRecordPrepare(ifstream &in, RecordItem &record, uint64_t &pos, int64_t length) const
|
||||
bool ResourceTable::ReadDataRecordPrepare(ifstream &in, RecordItem &record, uint64_t &pos, uint64_t length) const
|
||||
{
|
||||
pos = pos + INT_TO_BYTES;
|
||||
if (pos > length) {
|
||||
|
||||
Reference in New Issue
Block a user