Skip to content

Commit

Permalink
feat: manually enter device info
Browse files Browse the repository at this point in the history
  • Loading branch information
dongwlin committed Nov 21, 2023
1 parent 494c7da commit 27ca03b
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 13 deletions.
79 changes: 67 additions & 12 deletions source/cli/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,14 +212,23 @@ bool default_device_init(DeviceConfig& device)
bool select_device(std::string& name, std::string& SN, std::string& adb)
{
auto device_size = scanning_devices();
if (device_size == 0) {
mpause();
return false;
if (!device_size) {
if (!manually_enter_device_info(name, SN, adb)) {
return false;
}
return true;
}
MaaSize device_index;
if (!select_device_index(device_size, device_index)) {
int number = 0;
if (!select_device_number(device_size, number)) {
return false;
}
if (!number) {
if (!manually_enter_device_info(name, SN, adb)) {
return false;
}
return true;
}
MaaSize device_index = number - 1;
name = MaaToolKitGetDeviceName(device_index);
SN = MaaToolKitGetDeviceAdbSerial(device_index);
adb = MaaToolKitGetDeviceAdbPath(device_index);
Expand All @@ -230,16 +239,18 @@ bool select_device(std::string& name, std::string& SN, std::string& adb)
return true;
}

bool select_device_index(const MaaSize& device_size, MaaSize& index)
bool select_device_number(const MaaSize& device_size, int& number)
{
std::cout << std::endl << "Please select a device to connect:" << std::endl << std::endl;
std::cout << std::endl << "Please select a device:" << std::endl << std::endl;
std::cout << " 0. Manual" << std::endl;
print_device_list(device_size);
std::cout << std::endl << "Please enter the device number:" << std::endl;
std::cout << std::endl << "Please enter option number:" << std::endl;

std::cin >> index;
std::cin >> number;
std::cin.ignore();

if (index > device_size) {
std::cout << std::endl << "Unknown Device Number: " << index << std::endl;
if (number > device_size) {
std::cout << std::endl << "Unknown option number: " << number << std::endl;
return false;
}

Expand All @@ -249,11 +260,55 @@ bool select_device_index(const MaaSize& device_size, MaaSize& index)
void print_device_list(const MaaSize& device_size)
{
for (MaaSize i = 0; i < device_size; i++) {
std::cout << " " << i << ". " << MaaToolKitGetDeviceName(i) << " (" << MaaToolKitGetDeviceAdbSerial(i)
std::cout << " " << i + 1 << ". " << MaaToolKitGetDeviceName(i) << " (" << MaaToolKitGetDeviceAdbSerial(i)
<< ")\n";
}
}

bool manually_enter_device_info(std::string& name, std::string& SN, std::string& adb)
{
if (!manually_enter_device_name(name)) {
return false;
}
if (!manually_enter_device_SN(SN)) {
return false;
}
if (!manually_enter_device_adb(adb)) {
return false;
}
return true;
}

bool manually_enter_device_name(std::string& name)
{
std::cout << std::endl << "Please enter device name: " << std::endl;
std::getline(std::cin, name);
if (name.empty()) {
return false;
}
return true;
}

bool manually_enter_device_SN(std::string& SN)
{
std::cout << std::endl << "Please enter device serial number: " << std::endl;
std::getline(std::cin, SN);
if (SN.empty()) {
return false;
}
return true;
}

bool manually_enter_device_adb(std::string& adb)
{
std::cout << std::endl << "Please enter adb path: " << std::endl;
std::getline(std::cin, adb);
if (adb.empty()) {
return false;
}
return true;
}

bool default_tasks_init(TasksConfig& tasks)
{
std::vector<Task> tasklist;
Expand Down
10 changes: 9 additions & 1 deletion source/cli/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,18 @@ bool default_device_init(DeviceConfig& device);

bool select_device(std::string& name, std::string& SN, std::string& adb);

bool select_device_index(const MaaSize& device_size, MaaSize& index);
bool select_device_number(const MaaSize& device_size, int& number);

void print_device_list(const MaaSize& device_size);

bool manually_enter_device_info(std::string& name, std::string& SN, std::string& adb);

bool manually_enter_device_name(std::string& name);

bool manually_enter_device_SN(std::string& SN);

bool manually_enter_device_adb(std::string& adb);

bool default_tasks_init(TasksConfig& tasks);

bool select_tasks(std::vector<Task>& tasklist);
Expand Down

0 comments on commit 27ca03b

Please sign in to comment.