Compare commits
2 Commits
4c4eaf8734
...
12323d5148
Author | SHA1 | Date | |
---|---|---|---|
12323d5148 | |||
6559569f38 |
@ -1,6 +1,6 @@
|
|||||||
cmake_minimum_required(VERSION 3.16)
|
cmake_minimum_required(VERSION 3.16)
|
||||||
|
|
||||||
project(transm VERSION 1.3.0 LANGUAGES CXX)
|
project(transm VERSION 1.3.1 LANGUAGES CXX)
|
||||||
set(CMAKE_CXX_STANDARD 17)
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
|
@ -126,6 +126,10 @@ void CClient::run(const std::string& ip, const std::string& port, const std::str
|
|||||||
request_update_list(param);
|
request_update_list(param);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (scmd == "Send" || scmd == "send") {
|
||||||
|
send_files(param);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (scmd == "Down" || scmd == "down") {
|
if (scmd == "Down" || scmd == "down") {
|
||||||
down_task(param);
|
down_task(param);
|
||||||
continue;
|
continue;
|
||||||
@ -195,7 +199,6 @@ bool CClient::down_task(const std::string& param)
|
|||||||
|
|
||||||
bool CClient::up_task(const std::string& param)
|
bool CClient::up_task(const std::string& param)
|
||||||
{
|
{
|
||||||
|
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(mutex_);
|
std::lock_guard<std::mutex> lock(mutex_);
|
||||||
for (const auto& item : up_) {
|
for (const auto& item : up_) {
|
||||||
@ -263,6 +266,82 @@ bool CClient::cancel_task()
|
|||||||
return send_frame(buf.get());
|
return send_frame(buf.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CClient::send_files(const std::string& param)
|
||||||
|
{
|
||||||
|
auto tvec = COfStr::split(param, " ");
|
||||||
|
if (tvec.size() < 3) {
|
||||||
|
TLOGE("{} invalid param format [{}]", __FUNCTION__, param);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
int index = std::stoi(tvec[0]);
|
||||||
|
std::string list_file = tvec[1];
|
||||||
|
std::string pur = tvec[2];
|
||||||
|
|
||||||
|
if (downloading_) {
|
||||||
|
TLOGW("Have Task Downloading, Please wait.....");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!task_list_.count(index)) {
|
||||||
|
TLOGE("No Index Found {}.", index);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto& sr = task_list_[index];
|
||||||
|
if (sr->id == own_id_) {
|
||||||
|
TLOGW("You can't send file to yourself!!!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 校验格式是否正确
|
||||||
|
auto vec = COfStr::split(list_file, "|");
|
||||||
|
bool valid = true;
|
||||||
|
int line = 1;
|
||||||
|
std::unordered_map<int, std::string> mre{};
|
||||||
|
std::string handled_content;
|
||||||
|
for (const auto& item : vec) {
|
||||||
|
std::string hitem = COfStr::trim(item);
|
||||||
|
if (hitem.empty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
auto real_path = COfPath::to_full(hitem);
|
||||||
|
if (!fs::exists(real_path)) {
|
||||||
|
TLOGE("file {} not exist.", real_path);
|
||||||
|
valid = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
TLOGI("--->check pass {}:{}", line, real_path);
|
||||||
|
mre[line++] = real_path + "|" + pur;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!valid) {
|
||||||
|
TLOGE("Judge File Not Passed.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto handel_ret = handle_user_select(mre);
|
||||||
|
if (handel_ret.empty()) {
|
||||||
|
TLOGE("handle_user_select not pass, abort action!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined(_WIN32)
|
||||||
|
handel_ret = CCodec::ansi_to_u8(handel_ret);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
list_file_ = "auto_list";
|
||||||
|
std::shared_ptr<CFrameBuffer> buf = std::make_shared<CFrameBuffer>();
|
||||||
|
buf->type_ = TYPE_REQUEST_UPDATE_LIST;
|
||||||
|
buf->data_ = new char[handel_ret.size() + 1]();
|
||||||
|
buf->len_ = std::snprintf(buf->data_, handel_ret.size() + 1, "%s", handel_ret.c_str());
|
||||||
|
buf->tid_ = task_list_[index]->id;
|
||||||
|
|
||||||
|
if (!send_frame(buf.get())) {
|
||||||
|
TLOGE("Send Failed {}", __LINE__);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool CClient::down_one_file(const std::string& id, const std::string& file, const std::string& local_dir)
|
bool CClient::down_one_file(const std::string& id, const std::string& file, const std::string& local_dir)
|
||||||
{
|
{
|
||||||
std::string back_file(file);
|
std::string back_file(file);
|
||||||
|
@ -51,6 +51,7 @@ public:
|
|||||||
bool down_task(const std::string& param);
|
bool down_task(const std::string& param);
|
||||||
bool up_task(const std::string& param);
|
bool up_task(const std::string& param);
|
||||||
bool cancel_task();
|
bool cancel_task();
|
||||||
|
bool send_files(const std::string& param);
|
||||||
bool down_one_file(const std::string& id, const std::string& file, const std::string& local_dir = "");
|
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 = "");
|
void report_trans_ret(TransState state, const std::string& key = "");
|
||||||
bool request_update_list(const std::string& param);
|
bool request_update_list(const std::string& param);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user