Skip to content

Commit

Permalink
chore: 修改替换宏
Browse files Browse the repository at this point in the history
  • Loading branch information
MistEO committed Dec 13, 2024
1 parent c73fa6b commit 67cb6b5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
8 changes: 4 additions & 4 deletions docs/en_us/3.1-PipelineProtocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -566,10 +566,10 @@ This action attribute requires additional fields:
The arguments to be executed. Optional.
Some runtime parameters can be passed in:

- `{Entry}`: Task entry name
- `{Node}`: Current task name
- `{Image}`: Current screenshot file path
- `{Box}`: Identify the hit target
- `{ENTRY}`: Task entry name
- `{NODE}`: Current task name
- `{IMAGE}`: Current screenshot file path
- `{BOX}`: Identify the hit target

- `detach`: *bool*
Detach the child process, that is, do not wait for the child process to complete, and directly continue with the subsequent tasks. Optional, default false.
Expand Down
8 changes: 4 additions & 4 deletions docs/zh_cn/3.1-任务流水线协议.md
Original file line number Diff line number Diff line change
Expand Up @@ -576,10 +576,10 @@ Orange 的 next 中,
执行的参数。可选。
可传入部分运行期参数:
- `{Entry}`: 任务入口名
- `{Node}`: 当前任务名
- `{Image}`: 当前截图文件路径
- `{Box}`: 识别命中的目标
- `{ENTRY}`: 任务入口名
- `{NODE}`: 当前任务名
- `{IMAGE}`: 当前截图文件路径
- `{BOX}`: 识别命中的目标
- `detach`: *bool*
分离子进程,即不等待子进程执行完成,直接继续之后后面的任务。可选,默认 false。
Expand Down
21 changes: 14 additions & 7 deletions source/MaaFramework/Task/Component/CommandAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include "Utils/ImageIo.h"
#include "Utils/Logger.h"
#include "Utils/Platform.h"
#include "Utils/Runtime.h"
#include "Utils/StringMisc.hpp"

MAA_TASK_NS_BEGIN

Expand All @@ -27,19 +29,24 @@ bool CommandAction::run(const MAA_RES_NS::Action::CommandParam& command, const R
{
LogFunc << VAR(command.exec) << VAR(command.args) << VAR(command.detach);

static std::unordered_map<std::string, std::function<std::string(const Runtime&)>> kArgvReplacement = {
{ "{Entry}", std::bind(&CommandAction::gen_entry_name, this, std::placeholders::_1) },
{ "{Node}", std::bind(&CommandAction::gen_node_name, this, std::placeholders::_1) },
{ "{Image}", std::bind(&CommandAction::gen_image_path, this, std::placeholders::_1) },
{ "{Box}", std::bind(&CommandAction::gen_box, this, std::placeholders::_1) },
static std::unordered_map<std::string, std::string> kExecReplacement = {
{ "{LIBRARY_DIR}", path_to_utf8_string(library_dir()) },
};
std::string conv_exec = string_replace_all(command.exec, kExecReplacement);

std::filesystem::path exec = boost::process::search_path(path(command.exec));
std::filesystem::path exec = boost::process::search_path(path(conv_exec));
if (!std::filesystem::exists(exec)) {
LogError << "exec not exists" << VAR(command.exec) << VAR(exec);
LogError << "exec not exists" << VAR(command.exec) << VAR(conv_exec) << VAR(exec);
return false;
}

static std::unordered_map<std::string, std::function<std::string(const Runtime&)>> kArgvReplacement = {
{ "{ENTRY}", std::bind(&CommandAction::gen_entry_name, this, std::placeholders::_1) },
{ "{NODE}", std::bind(&CommandAction::gen_node_name, this, std::placeholders::_1) },
{ "{IMAGE}", std::bind(&CommandAction::gen_image_path, this, std::placeholders::_1) },
{ "{BOX}", std::bind(&CommandAction::gen_box, this, std::placeholders::_1) },
};

std::vector<os_string> args;
for (const std::string& arg : command.args) {
auto iter = kArgvReplacement.find(arg);
Expand Down

0 comments on commit 67cb6b5

Please sign in to comment.