| 7 | #include "MaaUtils/Logger.h" |
| 8 | |
| 9 | MAA_PROJECT_INTERFACE_NS_BEGIN |
| 10 | |
| 11 | std::optional<InterfaceData> Parser::parse_interface(const std::filesystem::path& path) |
| 12 | { |
| 13 | LogFunc << VAR(path); |
| 14 | |
| 15 | auto json_opt = json::open(path, true, true); |
| 16 | if (!json_opt) { |
| 17 | LogError << "failed to parse" << path; |
| 18 | return std::nullopt; |
| 19 | } |
| 20 | |
| 21 | const json::value& json = *json_opt; |
| 22 | auto data_opt = parse_interface(json); |
| 23 | if (!data_opt) { |
| 24 | return std::nullopt; |
| 25 | } |
| 26 | |
| 27 | InterfaceData& data = *data_opt; |
| 28 | |
| 29 | auto base_dir = path.parent_path(); |
| 30 | for (const std::string& import_path : data_opt->import_) { |
| 31 | auto import_full_path = base_dir / MaaNS::path(import_path); |
| 32 | auto import_data = parse_import_data(import_full_path); |
| 33 | if (!import_data) { |
| 34 | LogError << "failed to parse import interface data" << VAR(import_full_path) << VAR(import_path); |
| 35 | return std::nullopt; |
| 36 | } |
| 37 | data.task.insert( |
| 38 | data.task.end(), |
| 39 | std::make_move_iterator(import_data->task.begin()), |
| 40 | std::make_move_iterator(import_data->task.end())); |
| 41 | |
| 42 | data.option.insert(std::make_move_iterator(import_data->option.begin()), std::make_move_iterator(import_data->option.end())); |
| 43 | |
| 44 | data.preset.insert( |
| 45 | data.preset.end(), |
| 46 | std::make_move_iterator(import_data->preset.begin()), |
| 47 | std::make_move_iterator(import_data->preset.end())); |
| 48 | } |
| 49 | |
| 50 | return data; |
| 51 | } |
| 52 | |
| 53 | std::optional<InterfaceData> Parser::parse_interface(const json::value& json) |
| 54 | { |
nothing calls this directly
no outgoing calls
no test coverage detected