diff --git a/source/cli/CMakeLists.txt b/source/cli/CMakeLists.txt index b4c96c6..74f98a4 100644 --- a/source/cli/CMakeLists.txt +++ b/source/cli/CMakeLists.txt @@ -35,6 +35,8 @@ add_executable(MAABH3_CLI Config/DeviceConfig.cpp Config/TasksConfig.h Config/TasksConfig.cpp + Config/ConfigMgr.h + Config/ConfigMgr.cpp ) target_link_libraries(MAABH3_CLI PRIVATE MaaFramework MaaToolKit) diff --git a/source/cli/Config/ConfigMgr.cpp b/source/cli/Config/ConfigMgr.cpp new file mode 100644 index 0000000..ccdd58e --- /dev/null +++ b/source/cli/Config/ConfigMgr.cpp @@ -0,0 +1,57 @@ +#include "ConfigMgr.h" + +ConfigMgr& ConfigMgr::get_instance() +{ + static ConfigMgr instance; + return instance; +} + +bool ConfigMgr::init() +{ + if (!_control.load()) { + std::cerr << "Failed to load control config" << std::endl; + return false; + } + if (!_device.load()) { + std::cerr << "Failed to load device config" << std::endl; + return false; + } + if (!_tasks.load()) { + std::cerr << "Failed to load tasks config" << std::endl; + return false; + } + return true; +} + +bool ConfigMgr::set_config_target(ConfigOption option, std::string target) +{ + switch (option) { + case ConfigOption_Control: + _control.set_target(target); + break; + case ConfigOption_Device: + _device.set_target(target); + break; + case ConfigOption_Tasks: + _tasks.set_target(target); + break; + default: + return false; + } + return true; +} + +ControlConfig& ConfigMgr::get_control_config() +{ + return _control; +} + +DeviceConfig& ConfigMgr::get_device_config() +{ + return _device; +} + +TasksConfig& ConfigMgr::get_tasks_config() +{ + return _tasks; +} diff --git a/source/cli/Config/ConfigMgr.h b/source/cli/Config/ConfigMgr.h new file mode 100644 index 0000000..9d2d409 --- /dev/null +++ b/source/cli/Config/ConfigMgr.h @@ -0,0 +1,38 @@ +#pragma once + +#include + +#include "ControlConfig.h" +#include "DeviceConfig.h" +#include "TasksConfig.h" + +enum ConfigOption +{ + ConfigOption_Control = 0, + ConfigOption_Device = 1, + ConfigOption_Tasks = 2 +}; + +class ConfigMgr +{ +public: + static ConfigMgr& get_instance(); + +public: + bool init(); + bool set_config_target(ConfigOption option, std::string target); + +public: + ControlConfig& get_control_config(); + DeviceConfig& get_device_config(); + TasksConfig& get_tasks_config(); + +private: + ConfigMgr() = default; + ~ConfigMgr() = default; + +private: + ControlConfig _control; + DeviceConfig _device; + TasksConfig _tasks; +}; \ No newline at end of file