Skip to content

Commit

Permalink
refactor: remove adb config cache
Browse files Browse the repository at this point in the history
  • Loading branch information
dongwlin committed Dec 11, 2024
1 parent 33adc7d commit 35e704d
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 152 deletions.
1 change: 0 additions & 1 deletion source/cli/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ add_executable(MAABH3_CLI
Config/DeviceConfig.cpp
Config/TasksConfig.cpp
Config/ConfigMgr.cpp
Cache/AdbConfigCache.cpp
)
target_link_libraries(MAABH3_CLI PRIVATE MaaFramework MaaToolkit)

Expand Down
96 changes: 0 additions & 96 deletions source/cli/Cache/AdbConfigCache.cpp

This file was deleted.

34 changes: 0 additions & 34 deletions source/cli/Cache/AdbConfigCache.h

This file was deleted.

14 changes: 0 additions & 14 deletions source/cli/Cache/Cache.h

This file was deleted.

2 changes: 0 additions & 2 deletions source/cli/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ bool select_device(std::string& name, std::string& SN, std::string& adb)
name = MaaToolkitGetDeviceName(device_index);
SN = MaaToolkitGetDeviceAdbSerial(device_index);
adb = MaaToolkitGetDeviceAdbPath(device_index);
AdbConfigCache adb_config_cache;
adb_config_cache.set_adb_config(name, SN, MaaToolkitGetDeviceAdbConfig(device_index));
return true;
}

Expand Down
1 change: 0 additions & 1 deletion source/cli/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <MaaFramework/MaaDef.h>

#include "Config/DeviceConfig.h"
#include "Cache/AdbConfigCache.h"

bool default_device_init(DeviceConfig& device);

Expand Down
22 changes: 19 additions & 3 deletions source/cli/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ int main(int argc, char** argv)

config.init();

AdbConfigCache adb_config_cache;
adb_config = adb_config_cache.get_adb_config(device.get_config_device_name(), device.get_config_device_SN());
adb_config = get_default_adb_config();

bool identified = app_package_and_activity(control.get_config_server(), package, activity);
if (!identified) {
Expand Down Expand Up @@ -247,7 +246,24 @@ void print_version()
<< std::endl;
}

std::string get_default_adb_config()
{
const std::filesystem::path local_dir = ".";
std::filesystem::path file_path = local_dir / "resource" / "adb_config.json";
std::ifstream ifs(file_path, std::ios::in);
if (!ifs.is_open()) {
std::cerr << "Failed to open default adb config file: " << file_path << std::endl;
return std::string();
}

std::stringstream buffer;
buffer << ifs.rdbuf();
ifs.close();

return buffer.str();
}

void mpause()
{
std::ignore = getchar();
}
}
3 changes: 2 additions & 1 deletion source/cli/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include <MaaFramework/MaaAPI.h>
#include <MaaToolkit/MaaToolkitAPI.h>

#include "Cache/AdbConfigCache.h"
#include "Config/ConfigMgr.h"

#include "CustomAction/CustomActionRegistry.h"
Expand All @@ -26,4 +25,6 @@ void print_help();

void print_version();

std::string get_default_adb_config();

void mpause();

0 comments on commit 35e704d

Please sign in to comment.