diff --git a/client/client.cpp b/client/client.cpp index e32e1b7..021ce31 100644 --- a/client/client.cpp +++ b/client/client.cpp @@ -91,25 +91,27 @@ void CClient::run(const std::string& ip, const std::string& port) continue; } auto vec = COfStr::split(cmd_input, " "); - if (vec.size() == 3) { - if (vec[0] == "Update") { - request_update_list(vec[2], std::stoi(vec[1])); - continue; - } - logger_->error("No matched cmd, May be param size incorrect."); - } else if (vec.size() == 2) { - if (vec[0] == "Down") { - down_task(vec[1]); - continue; - } - if (vec[0] == "Up") { - up_task(cmd_input); - continue; - } - logger_->error("No matched cmd, May be param size incorrect."); - } else { + if (vec.size() < 2) { logger_->error("No matched cmd, May be param size incorrect."); + continue; } + std::string param(cmd_input); + std::string scmd = param.substr(0, param.find_first_of(" ")); + param.erase(0, param.find_first_of(" ") + 1); + + if (scmd == "Update") { + request_update_list(param); + continue; + } + if (scmd == "Down") { + down_task(param); + continue; + } + if (scmd == "Up") { + up_task(param); + continue; + } + logger_->error("No matched cmd, May be param size incorrect."); } client_->disconnect(); thread.join(); @@ -152,7 +154,7 @@ bool CClient::down_task(const std::string& param) return true; } -bool CClient::up_task(const std::string& cmd) +bool CClient::up_task(const std::string& param) { { @@ -165,7 +167,7 @@ bool CClient::up_task(const std::string& cmd) } } - auto list = CFileOpr::get_file_list(cmd); + auto list = CFileOpr::get_file_list(param); std::string msg; for (const auto& item : list) { @@ -316,8 +318,16 @@ void CClient::report_trans_ret(TransState state, const std::string& key) 功能为,请求某个客户端,更新我所列出的文件,右侧是远端需要存储的目录(必须存在,不存在则不理会) */ -bool CClient::request_update_list(const std::string& list_file, int index) +bool CClient::request_update_list(const std::string& param) { + auto tvec = COfStr::split(param, " "); + if (tvec.size() < 2) { + logger_->error("{} invalid param format [{}]", __FUNCTION__, param); + return false; + } + int index = std::stoi(tvec[0]); + std::string list_file = tvec[1]; + if (downloading_) { logger_->warn("Have Task Downloading, Please wait....."); return false; @@ -694,9 +704,7 @@ CFileOpr::~CFileOpr() std::vector CFileOpr::get_file_list(const std::string& input) { std::vector result; - std::string backup = input; - backup.erase(0, backup.find_first_of(" ")); - backup = COfStr::trim(backup); + auto backup = COfStr::trim(input); if (backup.empty()) { return result; } diff --git a/client/client.h b/client/client.h index 1af5697..0984921 100644 --- a/client/client.h +++ b/client/client.h @@ -43,11 +43,11 @@ public: public: bool get_task_list(); bool down_task(const std::string& param); - bool up_task(const std::string& cmd); + bool up_task(const std::string& param); bool cancel_task(); bool down_one_file(const std::string& id, const std::string& file, const std::string& local_dir = ""); void report_trans_ret(TransState state, const std::string& key = ""); - bool request_update_list(const std::string& list_file, int index); + bool request_update_list(const std::string& param); bool check_update_list(const std::string& content, std::map& files); bool down_update_file(std::map files);