-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: CustomExecAgent & 子进程 IO 的重构 (#110)
- Loading branch information
Showing
79 changed files
with
1,608 additions
and
992 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#pragma once | ||
|
||
#include "../MaaToolKitDef.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" | ||
{ | ||
#endif | ||
|
||
MaaBool MAA_TOOLKIT_API MaaToolKitRegisterCustomRecognizerExecutor( // | ||
MaaInstanceHandle handle, MaaStringView recognizer_name, MaaStringView recognizer_exec_path, | ||
MaaStringView recognizer_exec_param_json, MaaToolKitExecAgentArgvTransferMode argv_mode); | ||
MaaBool MAA_TOOLKIT_API MaaToolKitUnregisterCustomRecognizerExecutor( // | ||
MaaInstanceHandle handle, MaaStringView recognizer_name); | ||
|
||
MaaBool MAA_TOOLKIT_API MaaToolKitRegisterCustomActionExecutor( // | ||
MaaInstanceHandle handle, MaaStringView action_name, MaaStringView action_exec_path, | ||
MaaStringView action_exec_param_json, MaaToolKitExecAgentArgvTransferMode argv_mode); | ||
MaaBool MAA_TOOLKIT_API MaaToolKitUnregisterCustomActionExecutor( // | ||
MaaInstanceHandle handle, MaaStringView action_name); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#include "ProcessArgvGenerator.h" | ||
|
||
#include "Utils/IOStream/BoostIO.hpp" | ||
#include "Utils/Logger.h" | ||
#include "Utils/Platform.h" | ||
|
||
MAA_CTRL_UNIT_NS_BEGIN | ||
|
||
std::optional<ProcessArgvGenerator> ProcessArgvGenerator::create(const json::array& arr) | ||
{ | ||
if (!arr.all<std::string>()) { | ||
LogError << "array not all string" << VAR(arr); | ||
return std::nullopt; | ||
} | ||
|
||
auto raw = arr.to_vector<std::string>(); | ||
if (raw.empty()) { | ||
LogError << "array is empty"; | ||
return std::nullopt; | ||
} | ||
|
||
return ProcessArgvGenerator(std::move(raw)); | ||
} | ||
std::optional<ProcessArgvGenerator::ProcessArgv> ProcessArgvGenerator::gen(const Replacement& replacement) const | ||
{ | ||
if (raw_.empty()) { | ||
LogError << "raw is empty"; | ||
return std::nullopt; | ||
} | ||
|
||
auto res = raw_; | ||
for (auto& s : res) { | ||
string_replace_all_(s, replacement); | ||
} | ||
|
||
auto stdpath = MAA_NS::path(res.front()); | ||
auto searched_path = boost::process::search_path(stdpath); | ||
|
||
if (!std::filesystem::exists(searched_path)) { | ||
LogError << "exec path not exits" << VAR(searched_path); | ||
return std::nullopt; | ||
} | ||
|
||
auto args = std::vector(std::make_move_iterator(res.begin() + 1), std::make_move_iterator(res.end())); | ||
|
||
return ProcessArgv { .exec = std::move(searched_path), .args = std::move(args) }; | ||
} | ||
|
||
MAA_CTRL_UNIT_NS_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#pragma once | ||
|
||
#include <filesystem> | ||
#include <optional> | ||
#include <unordered_map> | ||
|
||
#include <meojson/json.hpp> | ||
|
||
#include "Utils/StringMisc.hpp" | ||
|
||
MAA_CTRL_UNIT_NS_BEGIN | ||
|
||
class ProcessArgvGenerator | ||
{ | ||
public: | ||
using Replacement = std::unordered_map<std::string, std::string>; | ||
|
||
struct ProcessArgv | ||
{ | ||
std::filesystem::path exec; | ||
std::vector<std::string> args; | ||
}; | ||
|
||
public: | ||
static std::optional<ProcessArgvGenerator> create(const json::array& arr); | ||
|
||
ProcessArgvGenerator() = default; | ||
ProcessArgvGenerator(std::vector<std::string> raw) : raw_(std::move(raw)) {} | ||
|
||
std::optional<ProcessArgv> gen(const Replacement& replacement) const; | ||
|
||
private: | ||
std::vector<std::string> raw_; | ||
}; | ||
|
||
MAA_CTRL_UNIT_NS_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.