!102 【master】统一处理输入目录

Merge pull request !102 from fyz1019/master
This commit is contained in:
openharmony_ci
2023-05-27 06:30:22 +00:00
committed by Gitee
9 changed files with 64 additions and 24 deletions
+1
View File
@@ -69,6 +69,7 @@ private:
uint32_t AddConfig(const std::string& argValue);
uint32_t AddStartId(const std::string& argValue);
uint32_t AddCachePath(const std::string& argValue);
void AdaptResourcesDirForInput();
uint32_t CheckParam() const;
uint32_t HandleProcess(int c, const std::string& argValue);
uint32_t ParseFileList(const std::string& fileListPath);
+1 -1
View File
@@ -57,7 +57,7 @@ public:
static bool CopyFileInner(const std::string &src, const std::string &dst);
static bool IsDirectory(const std::string &path);
static std::string RealPath(const std::string &path);
static std::string AdapateLongPath(const std::string &path);
static std::string AdaptLongPath(const std::string &path);
private:
bool IsIgnore(const std::string &filename) const;
+18 -2
View File
@@ -16,9 +16,10 @@
#ifndef OHOS_RESTOOL_RESOURCE_UTIL_H
#define OHOS_RESTOOL_RESOURCE_UTIL_H
#include<vector>
#include "resource_data.h"
#include <vector>
#include "file_entry.h"
#include "json/json.h"
#include "resource_data.h"
namespace OHOS {
namespace Global {
@@ -192,6 +193,21 @@ public:
* @return All restype string
*/
static std::string GetAllRestypeString();
/**
* @brief get \base\element dir
* @param string inputpath
* @return resource\base\element dir
*/
static FileEntry::FilePath GetBaseElementPath(const std::string input);
/**
* @brief get main dir
* @param string inputpath
* @return main dir
*/
static FileEntry::FilePath GetMainPath(const std::string input);
private:
enum class IgnoreType {
IGNORE_FILE,
+15 -1
View File
@@ -50,7 +50,11 @@ uint32_t PackageParser::Parse(int argc, char *argv[])
if (ParseCommand(argc, argv) != RESTOOL_SUCCESS) {
return RESTOOL_ERROR;
}
return CheckParam();
if (CheckParam() != RESTOOL_SUCCESS) {
return RESTOOL_ERROR;
}
AdaptResourcesDirForInput();
return RESTOOL_SUCCESS;
}
const vector<string> &PackageParser::GetInputs() const
@@ -220,6 +224,16 @@ uint32_t PackageParser::AddCachePath(const string& argValue)
return RESTOOL_SUCCESS;
}
// -i input directory, add the resource directory
void PackageParser::AdaptResourcesDirForInput()
{
if (!isFileList_ && !combine_) { // -l and increment compile -i, no need to add resource directory
for (auto &path : inputs_) {
path = FileEntry::FilePath(path).Append(RESOURCES_DIR).GetPath();
}
}
}
uint32_t PackageParser::CheckParam() const
{
if (inputs_.empty() && append_.empty()) {
+10 -10
View File
@@ -64,7 +64,7 @@ const vector<unique_ptr<FileEntry>> FileEntry::GetChilds() const
#ifdef _WIN32
WIN32_FIND_DATA findData;
string temp(filePath + "\\*.*");
HANDLE handle = FindFirstFile(AdapateLongPath(temp).c_str(), &findData);
HANDLE handle = FindFirstFile(AdaptLongPath(temp).c_str(), &findData);
if (handle == INVALID_HANDLE_VALUE) {
return children;
}
@@ -113,7 +113,7 @@ const FileEntry::FilePath &FileEntry::GetFilePath() const
bool FileEntry::Exist(const string &path)
{
#ifdef _WIN32
return PathFileExists(AdapateLongPath(path).c_str());
return PathFileExists(AdaptLongPath(path).c_str());
#else
struct stat s;
if (stat(path.c_str(), &s) != 0) {
@@ -145,7 +145,7 @@ bool FileEntry::CreateDirs(const string &path)
bool FileEntry::CopyFileInner(const string &src, const string &dst)
{
#ifdef _WIN32
if (!CopyFile(AdapateLongPath(src).c_str(), AdapateLongPath(dst).c_str(), false)) {
if (!CopyFile(AdaptLongPath(src).c_str(), AdaptLongPath(dst).c_str(), false)) {
cerr << "Error: copy file fail from '" << src << "' to '" << dst << "'. reason:" << strerror(errno) << endl;
return false;
}
@@ -164,7 +164,7 @@ bool FileEntry::CopyFileInner(const string &src, const string &dst)
bool FileEntry::IsDirectory(const string &path)
{
#ifdef _WIN32
if (!PathIsDirectory(AdapateLongPath(path).c_str())) {
if (!PathIsDirectory(AdaptLongPath(path).c_str())) {
return false;
}
return true;
@@ -179,7 +179,7 @@ string FileEntry::RealPath(const string &path)
{
#ifdef _WIN32
char buffer[MAX_PATH];
if (!PathCanonicalize(buffer, AdapateLongPath(path).c_str())) {
if (!PathCanonicalize(buffer, AdaptLongPath(path).c_str())) {
return "";
}
@@ -283,7 +283,7 @@ bool FileEntry::RemoveAllDirInner(const FileEntry &entry)
string path = entry.GetFilePath().GetPath();
if (entry.IsFile()) {
#ifdef _WIN32
bool result = remove(AdapateLongPath(path).c_str()) == 0;
bool result = remove(AdaptLongPath(path).c_str()) == 0;
#else
bool result = remove(path.c_str()) == 0;
#endif
@@ -300,7 +300,7 @@ bool FileEntry::RemoveAllDirInner(const FileEntry &entry)
}
}
#ifdef _WIN32
bool result = rmdir(AdapateLongPath(path).c_str()) == 0;
bool result = rmdir(AdaptLongPath(path).c_str()) == 0;
#else
bool result = rmdir(path.c_str()) == 0;
#endif
@@ -316,7 +316,7 @@ bool FileEntry::CreateDirsInner(const string &path, string::size_type offset)
string::size_type pos = path.find_first_of(SEPARATE.front(), offset);
if (pos == string::npos) {
#ifdef _WIN32
return CreateDirectory(AdapateLongPath(path).c_str(), nullptr) != 0;
return CreateDirectory(AdaptLongPath(path).c_str(), nullptr) != 0;
#else
return mkdir(path.c_str(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) == 0;
#endif
@@ -325,7 +325,7 @@ bool FileEntry::CreateDirsInner(const string &path, string::size_type offset)
string subPath = path.substr(0, pos + 1);
if (!Exist(subPath)) {
#ifdef _WIN32
if (!CreateDirectory(AdapateLongPath(subPath).c_str(), nullptr)) {
if (!CreateDirectory(AdaptLongPath(subPath).c_str(), nullptr)) {
#else
if (mkdir(subPath.c_str(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) != 0) {
#endif
@@ -360,7 +360,7 @@ void FileEntry::FilePath::Init()
}
}
string FileEntry::AdapateLongPath(const string &path)
string FileEntry::AdaptLongPath(const string &path)
{
#ifdef _WIN32
if (path.size() >= MAX_PATH -12) { //the max file path can not exceed 260 - 12
+1 -2
View File
@@ -206,8 +206,7 @@ uint32_t IdWorker::InitIdDefined()
if (combine) {
idDefinedPath = FileEntry::FilePath(inputPath).Append(ID_DEFINED_FILE).GetPath();
} else {
idDefinedPath = FileEntry::FilePath(inputPath).Append(RESOURCES_DIR)
.Append("base").Append("element").Append(ID_DEFINED_FILE).GetPath();
idDefinedPath = ResourceUtil::GetBaseElementPath(inputPath).Append(ID_DEFINED_FILE).GetPath();
}
if (ResourceUtil::FileExist(idDefinedPath) && startId > 0) {
cerr << "Error: the set start_id and id_defined.json cannot be used together." << endl;
+4 -4
View File
@@ -48,14 +48,14 @@ uint32_t ResourceMerge::Init()
map<ConfigParser::ModuleType, vector<string>> inputTypes;
for (auto it = inputs.crbegin(); it != inputs.crend(); it++) {
string filePath = FileEntry::FilePath(*it).Append(ConfigParser::GetConfigName()).GetPath();
string resourceDir = FileEntry::FilePath(*it).Append(RESOURCES_DIR).GetPath();
string configPath = ResourceUtil::GetMainPath(*it).Append(ConfigParser::GetConfigName()).GetPath();
string resourceDir = FileEntry::FilePath(*it).GetPath();
ConfigParser::ModuleType moduleType = ConfigParser::ModuleType::NONE;
if (!ResourceUtil::FileExist(filePath)) {
if (!ResourceUtil::FileExist(configPath)) {
inputTypes[moduleType].push_back(resourceDir);
continue;
}
ConfigParser configParser(filePath);
ConfigParser configParser(configPath);
if (configParser.Init() != RESTOOL_SUCCESS) {
return RESTOOL_ERROR;
}
+2 -2
View File
@@ -168,9 +168,9 @@ uint32_t ResourcePack::InitConfigJson()
cerr << "Error: more input path, -j config.json empty" << endl;
return RESTOOL_ERROR;
}
config = FileEntry::FilePath(packageParser_.GetInputs()[0]).Append(CONFIG_JSON).GetPath();
config = ResourceUtil::GetMainPath(packageParser_.GetInputs()[0]).Append(CONFIG_JSON).GetPath();
if (!ResourceUtil::FileExist(config)) {
config = FileEntry::FilePath(packageParser_.GetInputs()[0]).Append(MODULE_JSON).GetPath();
config = ResourceUtil::GetMainPath(packageParser_.GetInputs()[0]).Append(MODULE_JSON).GetPath();
}
}
+12 -2
View File
@@ -72,7 +72,7 @@ bool ResourceUtil::RmoveAllDir(const string &path)
bool ResourceUtil::OpenJsonFile(const string &path, Json::Value &root)
{
ifstream ifs(FileEntry::AdapateLongPath(path), ios::binary);
ifstream ifs(FileEntry::AdaptLongPath(path), ios::binary);
if (!ifs.is_open()) {
cerr << "Error: open json failed '" << path << "', reason: " << strerror(errno) << endl;
return false;
@@ -98,7 +98,7 @@ bool ResourceUtil::SaveToJsonFile(const string &path, const Json::Value &root)
writerBuilder["indentation"] = " ";
writerBuilder["emitUTF8"] = true;
unique_ptr<Json::StreamWriter> writer(writerBuilder.newStreamWriter());
ofstream out(FileEntry::AdapateLongPath(path), ofstream::out | ofstream::binary);
ofstream out(FileEntry::AdaptLongPath(path), ofstream::out | ofstream::binary);
if (!out.is_open()) {
cerr << "Error: open failed '" << path <<"', reason: " << strerror(errno) << endl;
return false;
@@ -392,6 +392,16 @@ string ResourceUtil::GetAllRestypeString()
return result;
}
FileEntry::FilePath ResourceUtil::GetBaseElementPath(const string input)
{
return FileEntry::FilePath(input).Append("base").Append("element");
}
FileEntry::FilePath ResourceUtil::GetMainPath(const string input)
{
return FileEntry::FilePath(input).GetParent();
}
}
}
}