diff --git a/README_zh.md b/README_zh.md
index 9e921cf..500f031 100644
--- a/README_zh.md
+++ b/README_zh.md
@@ -48,7 +48,10 @@ restool(资源编译工具)是一种资源构建工具。通过编译资源
| --icon-check | 可缺省 | 不带参数 | 开启icon和startWindowIcon的PNG图片校验功能。 |
| --target-config | 可缺省 | 带参数 | 与“-i”命令同时使用,支持选择编译。
具体可参考如下**target-config参数说明**。|
| --thread | 可缺省 | 带参数 | 指定资源编译时开启的子线程数量。|
-| --ignored-file | 可缺省 | 带参数 | 指定资源编译时文件和文件夹的忽略规则,格式为正则表达式,多个规则之间以“:”分隔。例如:“\\.git:\\.svn”表示忽略名称为“.git”、“.svn”的文件和文件夹。|
+| --ignored-file | 可缺省 | 带参数 | 指定资源文件和文件夹的忽略规则,格式为正则表达式,匹配文件名称,多个规则之间以“:”分隔。例如:“\\.git:\\.svn”表示忽略名称为“.git”、“.svn”的文件和文件夹。|
+| --ignored-path | 可缺省 | 带参数 | 指定资源文件和文件夹的忽略规则,格式为正则表达式,匹配文件名称和文件路径,多个规则之间以“:”分隔。例如:“.+/rawfile/\\.git:.+/rawfile/\\.svn”表示忽略rawfile目录下的“.git”、“.svn”的文件和文件夹。|
+
+
**target-config参数说明**
diff --git a/include/cmd/package_parser.h b/include/cmd/package_parser.h
index 510b78e..4c77afe 100644
--- a/include/cmd/package_parser.h
+++ b/include/cmd/package_parser.h
@@ -86,7 +86,7 @@ private:
uint32_t ParseTargetConfig(const std::string &argValue);
uint32_t AddCompressionPath(const std::string &argValue);
uint32_t ParseThread(const std::string &argValue);
- uint32_t ParseIgnoreFileRegex(const std::string &argValue);
+ uint32_t ParseIgnoreFileRegex(const std::string &argValue, const bool &isIgnorePath = false);
static const struct option CMD_OPTS[];
static const std::string CMD_PARAMS;
diff --git a/include/resconfig_parser.h b/include/resconfig_parser.h
index 1230734..1fc410d 100644
--- a/include/resconfig_parser.h
+++ b/include/resconfig_parser.h
@@ -39,7 +39,7 @@ private:
uint32_t GetModuleNames(const cJSON *node, int c, HandleBack callback);
uint32_t GetBool(const std::string &nodeName, const cJSON *node, int c, HandleBack callback);
uint32_t GetNumber(const std::string &nodeName, const cJSON *node, int c, HandleBack callback);
- uint32_t GetIgnorePatterns(const std::string &nodeName, const cJSON *node, int c);
+ uint32_t GetIgnorePatterns(const std::string &nodeName, const cJSON *node, int c, const bool &isPath);
cJSON *root_;
std::string filePath_;
};
diff --git a/include/resource_data.h b/include/resource_data.h
index 8706b63..85633df 100644
--- a/include/resource_data.h
+++ b/include/resource_data.h
@@ -50,7 +50,7 @@ const static std::string LONG_PATH_HEAD = "\\\\?\\";
const static int32_t VERSION_MAX_LEN = 128;
static const std::string RESTOOL_NAME = "Restool";
static const std::string RESTOOLV2_NAME = "RestoolV2";
-static const std::string RESTOOL_VERSION = { " 6.0.0.002" };
+static const std::string RESTOOL_VERSION = { " 6.0.0.003" };
const static int32_t TAG_LEN = 4;
constexpr static int DEFAULT_POOL_SIZE = 8;
static std::set g_resourceSet;
@@ -157,6 +157,7 @@ enum Option {
COMPRESSED_CONFIG = 7,
THREAD = 8,
IGNORED_FILE = 9,
+ IGNORED_PATH = 10,
STARTID = 'e',
FORCEWRITE = 'f',
HELP = 'h',
diff --git a/include/resource_util.h b/include/resource_util.h
index c04ae2b..7959262 100644
--- a/include/resource_util.h
+++ b/include/resource_util.h
@@ -147,11 +147,10 @@ public:
/**
* @brief ignore file or directory
- * @param filename: file or directory name
- * @param isFile: ture if is file, other false
+ * @param fileEntry: file or directory
* @return true if ignore, other false
*/
- static bool IsIgnoreFile(const std::string &filename, bool isFile);
+ static bool IsIgnoreFile(const FileEntry &fileEntry);
/**
* @brief generate hash string
@@ -282,6 +281,17 @@ public:
*/
static void SetUseCustomIgnoreRegex(const bool &isUseCustomRegex);
+ /**
+ * @brief get whether use custom ignore regex pattern
+ */
+ static bool IsUseCustomIgnoreRegex();
+
+ /**
+ * @brief set whether to use ignore regex pattern matching for file paths
+ * @param isUseCustomRegex: true is use custom ignore file regex
+ */
+ static void SetIgnorePath(const bool &isIgnorePath);
+
private:
static const std::map DEFAULT_IGNORE_FILE_REGEX;
static std::string GetLocaleLimitkey(const KeyParam &KeyParam);
diff --git a/src/binary_file_packer.cpp b/src/binary_file_packer.cpp
index 120b921..4ae8247 100644
--- a/src/binary_file_packer.cpp
+++ b/src/binary_file_packer.cpp
@@ -86,8 +86,7 @@ uint32_t BinaryFilePacker::CopyBinaryFile(const string &filePath, const string &
PrintError(GetError(ERR_CODE_INVALID_RESOURCE_PATH).FormatCause(filePath.c_str(), "not a directory"));
return RESTOOL_ERROR;
}
-
- if (ResourceUtil::IsIgnoreFile(fileType, false)) {
+ if (ResourceUtil::IsIgnoreFile(FileEntry(filePath))) {
return RESTOOL_SUCCESS;
}
@@ -110,7 +109,7 @@ uint32_t BinaryFilePacker::CopyBinaryFileImpl(const string &src, const string &d
}
for (const auto &entry : f.GetChilds()) {
string filename = entry->GetFilePath().GetFilename();
- if (ResourceUtil::IsIgnoreFile(filename, entry->IsFile())) {
+ if (ResourceUtil::IsIgnoreFile(*entry)) {
continue;
}
diff --git a/src/cmd/cmd_parser.cpp b/src/cmd/cmd_parser.cpp
index 6ae4ab5..ce3f794 100644
--- a/src/cmd/cmd_parser.cpp
+++ b/src/cmd/cmd_parser.cpp
@@ -114,6 +114,8 @@ void CmdParser::ShowUseage()
std::cout << " --compressed-config Path of opt-compression.json.\n";
std::cout << " --thread Subthreads count.\n";
std::cout << " --ignored-file Regular patterns of ignored files, split by ':'(like \\.git:\\.svn).\n";
+ std::cout << " --ignored-path Regular patterns of ignored file paths, split by ':'";
+ std::cout << "(like .+/rawfile/\\.git:.+/resfile/\\.svn).\n";
}
}
}
diff --git a/src/cmd/package_parser.cpp b/src/cmd/package_parser.cpp
index f1092b3..f7825bd 100644
--- a/src/cmd/package_parser.cpp
+++ b/src/cmd/package_parser.cpp
@@ -53,6 +53,7 @@ const struct option PackageParser::CMD_OPTS[] = {
{ "compressed-config", required_argument, nullptr, Option::COMPRESSED_CONFIG},
{ "thread", required_argument, nullptr, Option::THREAD},
{ "ignored-file", required_argument, nullptr, Option::IGNORED_FILE},
+ { "ignored-path", required_argument, nullptr, Option::IGNORED_PATH},
{ 0, 0, 0, 0},
};
@@ -478,11 +479,16 @@ uint32_t PackageParser::ParseThread(const std::string &argValue)
return RESTOOL_SUCCESS;
}
-uint32_t PackageParser::ParseIgnoreFileRegex(const std::string &argValue)
+uint32_t PackageParser::ParseIgnoreFileRegex(const std::string &argValue, const bool &isIgnorePath)
{
+ if (ResourceUtil::IsUseCustomIgnoreRegex()) {
+ PrintError(GetError(ERR_CODE_EXCLUSIVE_OPTION).FormatCause("--ignored-file", "--ignored-path"));
+ return RESTOOL_ERROR;
+ }
std::stringstream in(argValue);
std::string regex;
ResourceUtil::SetUseCustomIgnoreRegex(true);
+ ResourceUtil::SetIgnorePath(isIgnorePath);
while (getline(in, regex, ':')) {
bool isSucceed = ResourceUtil::AddIgnoreFileRegex(regex, IgnoreType::IGNORE_ALL);
if (!isSucceed) {
@@ -567,7 +573,8 @@ void PackageParser::InitCommand()
handles_.emplace(Option::DEFINED_SYSIDS, bind(&PackageParser::AddSysIdDefined, this, _1));
handles_.emplace(Option::COMPRESSED_CONFIG, bind(&PackageParser::AddCompressionPath, this, _1));
handles_.emplace(Option::THREAD, bind(&PackageParser::ParseThread, this, _1));
- handles_.emplace(Option::IGNORED_FILE, bind(&PackageParser::ParseIgnoreFileRegex, this, _1));
+ handles_.emplace(Option::IGNORED_FILE, bind(&PackageParser::ParseIgnoreFileRegex, this, _1, false));
+ handles_.emplace(Option::IGNORED_PATH, bind(&PackageParser::ParseIgnoreFileRegex, this, _1, true));
}
uint32_t PackageParser::HandleProcess(int c, const string &argValue)
diff --git a/src/i_resource_compiler.cpp b/src/i_resource_compiler.cpp
index 43705e6..08b937e 100644
--- a/src/i_resource_compiler.cpp
+++ b/src/i_resource_compiler.cpp
@@ -47,7 +47,7 @@ uint32_t IResourceCompiler::Compile(const vector &directoryInfos)
return RESTOOL_ERROR;
}
for (const auto &it : f.GetChilds()) {
- if (ResourceUtil::IsIgnoreFile(it->GetFilePath().GetFilename(), it->IsFile())) {
+ if (ResourceUtil::IsIgnoreFile(*it)) {
continue;
}
diff --git a/src/resconfig_parser.cpp b/src/resconfig_parser.cpp
index e72fa1e..6ab7726 100644
--- a/src/resconfig_parser.cpp
+++ b/src/resconfig_parser.cpp
@@ -95,7 +95,9 @@ void ResConfigParser::InitFileListCommand(HandleBack callback)
fileListHandles_.emplace("thread", bind(&ResConfigParser::GetNumber, this, "thread", _1,
Option::THREAD, callback));
fileListHandles_.emplace("ignoreResourcePattern", bind(&ResConfigParser::GetIgnorePatterns, this,
- "ignoreResourcePattern", _1, Option::IGNORED_FILE));
+ "ignoreResourcePattern", _1, Option::IGNORED_FILE, false));
+ fileListHandles_.emplace("ignoreResourcePathPattern", bind(&ResConfigParser::GetIgnorePatterns, this,
+ "ignoreResourcePathPattern", _1, Option::IGNORED_PATH, true));
}
uint32_t ResConfigParser::GetString(const std::string &nodeName, const cJSON *node, int c, HandleBack callback)
@@ -199,13 +201,18 @@ uint32_t ResConfigParser::GetNumber(const std::string &nodeName, const cJSON *no
return RESTOOL_SUCCESS;
}
-uint32_t ResConfigParser::GetIgnorePatterns(const std::string &nodeName, const cJSON *node, int c)
+uint32_t ResConfigParser::GetIgnorePatterns(const std::string &nodeName, const cJSON *node, int c, const bool &isPath)
{
if (!node) {
PrintError(GetError(ERR_CODE_JSON_NODE_MISSING).FormatCause(nodeName.c_str()).SetPosition(filePath_));
return RESTOOL_ERROR;
}
+ if (ResourceUtil::IsUseCustomIgnoreRegex()) {
+ PrintError(GetError(ERR_CODE_EXCLUSIVE_OPTION).FormatCause("--ignored-file", "--ignored-path"));
+ return RESTOOL_ERROR;
+ }
ResourceUtil::SetUseCustomIgnoreRegex(true);
+ ResourceUtil::SetIgnorePath(isPath);
HandleBack callback = [](int c, const string &argValue) {
bool isSucceed = ResourceUtil::AddIgnoreFileRegex(argValue, IgnoreType::IGNORE_ALL);
if (!isSucceed) {
diff --git a/src/resource_append.cpp b/src/resource_append.cpp
index 1696def..a1d5fdf 100644
--- a/src/resource_append.cpp
+++ b/src/resource_append.cpp
@@ -170,7 +170,7 @@ bool ResourceAppend::ScanSubLimitkeyResources(const FileEntry entry, const strin
{
for (const auto &child : entry.GetChilds()) {
string limitKey = child->GetFilePath().GetFilename();
- if (ResourceUtil::IsIgnoreFile(limitKey, child->IsFile())) {
+ if (ResourceUtil::IsIgnoreFile(*child)) {
continue;
}
@@ -219,7 +219,7 @@ bool ResourceAppend::ScanLimitKey(const unique_ptr &entry,
for (const auto &child : entry->GetChilds()) {
string fileCuster = child->GetFilePath().GetFilename();
- if (ResourceUtil::IsIgnoreFile(fileCuster, child->IsFile())) {
+ if (ResourceUtil::IsIgnoreFile(*child)) {
continue;
}
@@ -251,7 +251,7 @@ bool ResourceAppend::ScanFiles(const unique_ptr &entry,
{
for (const auto &child : entry->GetChilds()) {
string filename = child->GetFilePath().GetFilename();
- if (ResourceUtil::IsIgnoreFile(filename, child->IsFile())) {
+ if (ResourceUtil::IsIgnoreFile(*child)) {
continue;
}
@@ -433,7 +433,7 @@ bool ResourceAppend::ScanRawFilesOrResFiles(const string &path, const string &ou
for (const auto &child : entry.GetChilds()) {
string filename = child->GetFilePath().GetFilename();
- if (ResourceUtil::IsIgnoreFile(filename, child->IsFile())) {
+ if (ResourceUtil::IsIgnoreFile(*child)) {
continue;
}
diff --git a/src/resource_directory.cpp b/src/resource_directory.cpp
index 08ed89d..8130353 100644
--- a/src/resource_directory.cpp
+++ b/src/resource_directory.cpp
@@ -35,7 +35,7 @@ bool ResourceDirectory::ScanResources(const string &resourcesDir, functionGetFilePath().GetFilename();
- if (ResourceUtil::IsIgnoreFile(limitKey, it->IsFile())) {
+ if (ResourceUtil::IsIgnoreFile(*it)) {
continue;
}
@@ -75,7 +75,7 @@ bool ResourceDirectory::ScanResourceLimitKeyDir(const string &resourceTypeDir, c
for (const auto &it : f.GetChilds()) {
string dirPath = it->GetFilePath().GetPath();
string fileCluster = it->GetFilePath().GetFilename();
- if (ResourceUtil::IsIgnoreFile(fileCluster, it->IsFile())) {
+ if (ResourceUtil::IsIgnoreFile(*it)) {
continue;
}
diff --git a/src/resource_util.cpp b/src/resource_util.cpp
index 9922459..9355ead 100644
--- a/src/resource_util.cpp
+++ b/src/resource_util.cpp
@@ -43,6 +43,7 @@ const map ResourceUtil::DEFAULT_IGNORE_FILE_REGEX = {
};
static std::map g_userIgnoreFileRegex;
static bool g_isUseCustomRegex = false;
+static bool g_isIgnorePath = false;
static std::mutex fileMutex_;
@@ -251,29 +252,39 @@ bool ResourceUtil::CreateDirs(const string &filePath)
return true;
}
-bool ResourceUtil::IsIgnoreFile(const string &filename, bool isFile)
+bool ResourceUtil::IsIgnoreFile(const FileEntry &fileEntry)
{
map regexs;
std::string regexSources;
- string key = filename;
+ string fileName = fileEntry.GetFilePath().GetFilename();
+ string filePath = fileEntry.GetFilePath().GetPath();
+ filePath = regex_replace(filePath, regex("\\\\+"), "/");
if (g_isUseCustomRegex) {
regexs = g_userIgnoreFileRegex;
regexSources = "user";
} else {
regexs = DEFAULT_IGNORE_FILE_REGEX;
regexSources = "default";
- transform(key.begin(), key.end(), key.begin(), ::tolower);
+ transform(fileName.begin(), fileName.end(), fileName.begin(), ::tolower);
}
+ bool isFile = fileEntry.IsFile();
for (const auto &iter : regexs) {
- if ((iter.second == IgnoreType::IGNORE_FILE && !isFile) ||
- (iter.second == IgnoreType::IGNORE_DIR && isFile)) {
+ if ((iter.second == IgnoreType::IGNORE_FILE && !isFile) || (iter.second == IgnoreType::IGNORE_DIR && isFile)) {
continue;
}
- if (regex_match(key, regex(iter.first))) {
- cout << "Info: file '" << filename << "' is ignored by " << regexSources << " regular pattern '"
+ if (regex_match(fileName, regex(iter.first))) {
+ cout << "Info: file '" << fileName << "' is ignored by " << regexSources << " filename pattern '"
<< iter.first << "'." << endl;
return true;
}
+
+ if (g_isUseCustomRegex && g_isIgnorePath) {
+ if (regex_match(filePath, regex(iter.first))) {
+ cout << "Info: file '" << filePath << "' is ignored by " << regexSources << " filepath pattern '"
+ << iter.first << "'." << endl;
+ return true;
+ }
+ }
}
return false;
}
@@ -540,6 +551,16 @@ void ResourceUtil::SetUseCustomIgnoreRegex(const bool &isUseCustomRegex)
{
g_isUseCustomRegex = isUseCustomRegex;
}
+
+void ResourceUtil::SetIgnorePath(const bool &isIgnorePath)
+{
+ g_isIgnorePath = isIgnorePath;
+}
+
+bool ResourceUtil::IsUseCustomIgnoreRegex()
+{
+ return g_isUseCustomRegex;
+}
}
}
}