Skip to content

Commit

Permalink
feat: CheckAdbAddress 解析实体设备 Serial
Browse files Browse the repository at this point in the history
  • Loading branch information
Dissectum committed Oct 10, 2023
1 parent 3cfe91a commit 67fb796
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions src/MBA.Cli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ static bool ProcArgs(string[] args)
if (string.IsNullOrWhiteSpace(arg)) continue;
var value = arg;

if (CheckAdbAddress(value, out var address))
if (Enum.TryParse(value, out TaskType task))
{
Config.Core.AdbAddress = address;
taskList.Add(task);
continue;
}

Expand All @@ -159,21 +159,18 @@ static bool ProcArgs(string[] args)
continue;
}

if (Enum.TryParse(value, out TaskType task))
{
taskList.Add(task);
}
else
if (CheckAdbAddress(value, out var address))
{
Log.Error("未知任务名/Id:{arg} (解析为:{value})", arg, value);
return false;
Config.Core.AdbAddress = address;
continue;
}

if (task == TaskType.Test)
Log.Warning("解析到测试用任务, 请确保测试任务存在!");

Log.Error("未知任务名/Id:{arg} (解析为:{value})", arg, value);
return false;
}

if (taskList.Contains(TaskType.Test))
Log.Warning("解析到测试用任务, 请确保测试任务存在!");
if (taskList.Any())
Config.Tasks = taskList;

Expand Down Expand Up @@ -306,7 +303,16 @@ static bool CheckAdbAddress(string value, out string result)
{
result = value.Replace(':', ':').Replace('。', '.');
var parts = result.Split(':');
if (parts.Length != 2) return false;
if (parts.Length != 2)
{
var count = MaaToolKit.Extensions.MaaTool.FindDevice(Config.Core.Adb);
for (ulong i = 0; i < count; i++)
{
if (MaaToolKit.Extensions.MaaTool.GetDeviceAdbSerial(i) == value)
return true;
}
return false;
}
if (!int.TryParse(parts[1], out int port)) return false;
if (port < 0 || port > 65535) return false;
try
Expand Down

0 comments on commit 67fb796

Please sign in to comment.