mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-16 09:50:40 +08:00
fix.修复displayId不存在时的报错
This commit is contained in:
@@ -42,7 +42,6 @@
|
||||
"swipe": "[Adb] -s [Address] shell input swipe [x1] [y1] [x2] [y2] [duration]",
|
||||
"display": "[Adb] -s [Address] shell dumpsys window displays | grep init= | awk ' { print $3 } '",
|
||||
"displayFormat": "cur=%dx%d",
|
||||
"displayId": "",
|
||||
"screencapRawWithGzip": "[Adb] -s [Address] exec-out \"screencap | gzip -1\"",
|
||||
"screencapEncode": "[Adb] -s [Address] exec-out screencap -p",
|
||||
"release": "[Adb] kill-server"
|
||||
@@ -72,7 +71,7 @@
|
||||
"release": "[Adb] kill-server"
|
||||
}
|
||||
},
|
||||
"BlueStacksInternationalNewVersion": {
|
||||
"BlueStacksInternationalNewVersion": {
|
||||
"handle": {
|
||||
"class": "",
|
||||
"window": "BlueStacks App Player"
|
||||
@@ -91,7 +90,6 @@
|
||||
"swipe": "[Adb] -s [Address] shell input swipe [x1] [y1] [x2] [y2] [duration]",
|
||||
"display": "[Adb] -s [Address] shell dumpsys window displays | grep init= | awk ' { print $3 } '",
|
||||
"displayFormat": "cur=%dx%d",
|
||||
"displayId": "",
|
||||
"screencapRawWithGzip": "[Adb] -s [Address] exec-out \"screencap | gzip -1\"",
|
||||
"screencapEncode": "[Adb] -s [Address] exec-out screencap -p",
|
||||
"release": "[Adb] kill-server"
|
||||
@@ -114,7 +112,6 @@
|
||||
"swipe": "[Adb] -s [Address] shell input swipe [x1] [y1] [x2] [y2] [duration]",
|
||||
"display": "[Adb] -s [Address] shell dumpsys window displays | grep init= | awk ' { print $3 } '",
|
||||
"displayFormat": "cur=%dx%d",
|
||||
"displayId": "",
|
||||
"screencapRawWithGzip": "[Adb] -s [Address] exec-out \"screencap | gzip -1\"",
|
||||
"screencapEncode": "[Adb] -s [Address] exec-out screencap -p",
|
||||
"release": "[Adb] kill-server"
|
||||
@@ -138,7 +135,6 @@
|
||||
"swipe": "[Adb] -s [Address] shell input swipe [x1] [y1] [x2] [y2] [duration]",
|
||||
"display": "[Adb] -s [Address] shell dumpsys window displays | grep init= | awk ' { print $3 } '",
|
||||
"displayFormat": "cur=%dx%d",
|
||||
"displayId": "",
|
||||
"screencapRawWithGzip": "[Adb] -s [Address] shell \"screencap | gzip -1\"",
|
||||
"screencapEncode": "[Adb] -s [Address] shell screencap -p",
|
||||
"release": "[Adb] kill-server"
|
||||
@@ -162,7 +158,6 @@
|
||||
"swipe": "[Adb] -s [Address] shell input swipe [x1] [y1] [x2] [y2] [duration]",
|
||||
"display": "[Adb] -s [Address] shell dumpsys window displays | grep init= | awk ' { print $3 } '",
|
||||
"displayFormat": "cur=%dx%d",
|
||||
"displayId": "",
|
||||
"screencapRawWithGzip": "[Adb] -s [Address] exec-out \"screencap | gzip -1\"",
|
||||
"screencapEncode": "[Adb] -s [Address] exec-out screencap -p",
|
||||
"release": "[Adb] kill-server"
|
||||
@@ -186,7 +181,6 @@
|
||||
"swipe": "[Adb] -s [Address] shell input swipe [x1] [y1] [x2] [y2] [duration]",
|
||||
"display": "[Adb] -s [Address] shell dumpsys window displays | grep init= | awk ' { print $3 } '",
|
||||
"displayFormat": "cur=%dx%d",
|
||||
"displayId": "",
|
||||
"screencapRawWithGzip": "[Adb] -s [Address] exec-out \"screencap | gzip -1\"",
|
||||
"screencapEncode": "[Adb] -s [Address] exec-out screencap -p",
|
||||
"release": "[Adb] kill-server"
|
||||
@@ -209,7 +203,6 @@
|
||||
"swipe": "[Adb] -s [Address] shell input swipe [x1] [y1] [x2] [y2] [duration]",
|
||||
"display": "[Adb] -s [Address] shell dumpsys window displays | grep init=",
|
||||
"displayFormat": " init=%dx%d",
|
||||
"displayId": "",
|
||||
"screencapRawWithGzip": "[Adb] -s [Address] shell \"screencap | gzip -1\"",
|
||||
"screencapEncode": "[Adb] -s [Address] shell screencap -p",
|
||||
"release": "[Adb] kill-server"
|
||||
@@ -254,7 +247,6 @@
|
||||
"click": "[Adb] -s [Address] shell input tap [x] [y]",
|
||||
"swipe": "[Adb] -s [Address] shell input swipe [x1] [y1] [x2] [y2] [duration]",
|
||||
"display": "[Adb] -s [Address] shell dumpsys window displays | grep init=",
|
||||
"displayId": "",
|
||||
"displayFormat": " init=%dx%d",
|
||||
"screencapRawWithGzip": "[Adb] -s [Address] exec-out \"screencap | gzip -1\"",
|
||||
"screencapEncode": "[Adb] -s [Address] exec-out screencap -p",
|
||||
|
||||
@@ -107,11 +107,14 @@ bool asst::Controller::connect_adb(const std::string & address)
|
||||
{
|
||||
LogTraceScope("connect_adb " + address);
|
||||
|
||||
std::string connect_cmd = utils::string_replace_all(
|
||||
utils::string_replace_all(m_emulator_info.adb.connect, "[Adb]", m_emulator_info.adb.path),
|
||||
"[Address]", address);
|
||||
std::vector<std::pair<std::string, std::string>> replaces = {
|
||||
{"[Adb]", m_emulator_info.adb.path},
|
||||
{"[Address]", address}
|
||||
};
|
||||
|
||||
std::string connect_cmd = utils::string_replace_all_batch(
|
||||
m_emulator_info.adb.connect, replaces);
|
||||
|
||||
std::string display_id;
|
||||
auto connect_ret = call_command(connect_cmd, 600 * 1000);
|
||||
// 端口即使错误,命令仍然会返回0,TODO 对connect_result进行判断
|
||||
if (!connect_ret) {
|
||||
@@ -120,9 +123,8 @@ bool asst::Controller::connect_adb(const std::string & address)
|
||||
|
||||
// 按需获取display ID 信息
|
||||
if (!m_emulator_info.adb.display_id.empty()) {
|
||||
std::string display_id_cmd = utils::string_replace_all(
|
||||
utils::string_replace_all(m_emulator_info.adb.display_id, "[Adb]", m_emulator_info.adb.path),
|
||||
"[Address]", address);
|
||||
std::string display_id_cmd = utils::string_replace_all_batch(
|
||||
m_emulator_info.adb.display_id, replaces);
|
||||
auto display_id_ret = call_command(display_id_cmd);
|
||||
if (!display_id_ret) {
|
||||
return false;
|
||||
@@ -138,15 +140,12 @@ bool asst::Controller::connect_adb(const std::string & address)
|
||||
return false;
|
||||
}
|
||||
|
||||
display_id = display_id_pipe_str.substr(last + 1);
|
||||
std::string display_id = display_id_pipe_str.substr(last + 1);
|
||||
// 去掉换行
|
||||
display_id.pop_back();
|
||||
|
||||
replaces.emplace_back("[DisplayId]", std::move(display_id));
|
||||
}
|
||||
std::vector<std::pair<std::string, std::string>> replaces = {
|
||||
{"[Adb]", m_emulator_info.adb.path},
|
||||
{"[Address]", address},
|
||||
{"[DisplayId]", display_id}
|
||||
};
|
||||
|
||||
std::string display_cmd = utils::string_replace_all_batch(
|
||||
m_emulator_info.adb.display, replaces);
|
||||
@@ -178,29 +177,33 @@ bool asst::Controller::connect_adb(const std::string & address)
|
||||
|
||||
constexpr double DefaultRatio =
|
||||
static_cast<double>(WindowWidthDefault) / static_cast<double>(WindowHeightDefault);
|
||||
double cur_ratio = static_cast<double>(m_emulator_info.adb.display_width) / static_cast<double>(m_emulator_info.adb.display_height);
|
||||
double cur_ratio = static_cast<double>(m_emulator_info.adb.display_width) /
|
||||
static_cast<double>(m_emulator_info.adb.display_height);
|
||||
|
||||
if (cur_ratio >= DefaultRatio // 说明是宽屏或默认16:9,按照高度计算缩放
|
||||
|| std::fabs(cur_ratio - DefaultRatio) < DoubleDiff) {
|
||||
int scale_width = static_cast<int>(cur_ratio * WindowHeightDefault);
|
||||
m_scale_size = std::make_pair(scale_width, WindowHeightDefault);
|
||||
m_control_scale = static_cast<double>(m_emulator_info.adb.display_height) / static_cast<double>(WindowHeightDefault);
|
||||
m_control_scale = static_cast<double>(m_emulator_info.adb.display_height) /
|
||||
static_cast<double>(WindowHeightDefault);
|
||||
}
|
||||
else { // 否则可能是偏正方形的屏幕,按宽度计算
|
||||
int scale_height = static_cast<int>(WindowWidthDefault / cur_ratio);
|
||||
m_scale_size = std::make_pair(WindowWidthDefault, scale_height);
|
||||
m_control_scale = static_cast<double>(m_emulator_info.adb.display_width) / static_cast<double>(WindowWidthDefault);
|
||||
m_control_scale = static_cast<double>(m_emulator_info.adb.display_width) /
|
||||
static_cast<double>(WindowWidthDefault);
|
||||
}
|
||||
|
||||
|
||||
m_emulator_info.adb.click = utils::string_replace_all_batch(
|
||||
m_emulator_info.adb.click, replaces);
|
||||
m_emulator_info.adb.swipe = utils::string_replace_all_batch(
|
||||
m_emulator_info.adb.swipe, replaces);
|
||||
m_emulator_info.adb.screencap_raw_with_gzip =
|
||||
utils::string_replace_all_batch(
|
||||
m_emulator_info.adb.screencap_raw_with_gzip = utils::string_replace_all_batch(
|
||||
m_emulator_info.adb.screencap_raw_with_gzip, replaces);
|
||||
m_emulator_info.adb.screencap_encode = utils::string_replace_all_batch(m_emulator_info.adb.screencap_encode, replaces);
|
||||
m_emulator_info.adb.release = utils::string_replace_all(m_emulator_info.adb.release, "[Adb]", m_emulator_info.adb.path);
|
||||
m_emulator_info.adb.screencap_encode = utils::string_replace_all_batch(
|
||||
m_emulator_info.adb.screencap_encode, replaces);
|
||||
m_emulator_info.adb.release = utils::string_replace_all_batch(
|
||||
m_emulator_info.adb.release, replaces);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ bool asst::GeneralConfiger::parse(const json::value& json)
|
||||
emulator_info.adb.click = adb_json.at("click").as_string();
|
||||
emulator_info.adb.swipe = adb_json.at("swipe").as_string();
|
||||
emulator_info.adb.display = adb_json.at("display").as_string();
|
||||
emulator_info.adb.display_id = adb_json.at("displayId").as_string();
|
||||
emulator_info.adb.display_id = adb_json.get("displayId", std::string());
|
||||
emulator_info.adb.display_format = adb_json.at("displayFormat").as_string();
|
||||
emulator_info.adb.screencap_raw_with_gzip = adb_json.at("screencapRawWithGzip").as_string();
|
||||
emulator_info.adb.screencap_encode = adb_json.at("screencapEncode").as_string();
|
||||
|
||||
Reference in New Issue
Block a user