diff --git a/.vscode/settings.json b/.vscode/settings.json index 1af970f..60a10c2 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -21,7 +21,7 @@ ], "visualizerFile": "${workspaceRoot}/.vscode/qt5.natvis", "args": [ - "-n", "1" + "-n", "0" ] }, "cmake.environment": { diff --git a/client/client.cpp b/client/client.cpp index 704722c..a3ccfa6 100644 --- a/client/client.cpp +++ b/client/client.cpp @@ -272,6 +272,7 @@ bool CClient::down_one_file(const std::string& id, const std::string& file, cons down_->trans_state_ = TRANS_REDAY; cur_down_size_ = 0; float percent = 0.0; + disable_cur(); while (down_->trans_state_ != TRANS_DONE && down_->trans_state_ != TRANS_FAILED) { std::this_thread::sleep_for(std::chrono::milliseconds(down_check_wait)); if (cur_file_size_ > 0) { @@ -288,6 +289,7 @@ bool CClient::down_one_file(const std::string& id, const std::string& file, cons percent = (float)cur_down_size_ / cur_file_size_; CTransProtocal::display_progress(percent); } + enable_cur(); if (cur_down_size_ > 0 && cur_file_size_ == cur_down_size_) { mpwarn("down one file success, total:[{}/{}]", cur_down_size_, cur_file_size_); return true; @@ -600,11 +602,14 @@ void CClient::handle_frame(CFrameBuffer* buf) } case TYPE_TRANS_DONE: { report_trans_ret(TRANS_DONE); - if (down_) { +#ifdef _WIN32 +#else + if (down_ && down_->remote_plat == 1) { mpinfo("recovery permissions {}.", down_->permissions); fs::perms perms = static_cast(down_->permissions); fs::permissions(down_->cur_file_, perms); } +#endif break; } case TYPE_OPEN_FAILED: { @@ -683,15 +688,16 @@ void CClient::handle_frame(CFrameBuffer* buf) case TYPE_FILE_INFO: { std::string str_size(buf->data_, buf->len_); auto vec = COfStr::split(str_size, ","); - if (vec.size() < 2) { + if (vec.size() < 3) { mperror("invalid file information:{}", str_size); break; } - long long size = std::stoll(vec[0]); + long long size = std::stoll(vec[1]); std::string show_str = OfUtil::get_file_size(size); mpinfo("Ready Down Size: {}, permissions:{}", show_str, vec[1]); if (down_) { - down_->permissions = static_cast(std::stoul(vec[1])); + down_->permissions = static_cast(std::stoul(vec[2])); + down_->remote_plat = static_cast(std::stoul(vec[0])); } cur_file_size_ = size; } @@ -720,7 +726,7 @@ void CClient::send_file_data_th(const char* keys) buf->tid_ = str_key; // ******************************************************** - // TYPE_FILE_INFO格式:大小,权限 + // TYPE_FILE_INFO格式:平台([0,win], [1,unix]),大小,权限 // ******************************************************** // seekg 用于读,seekp 用于写。 @@ -733,8 +739,14 @@ void CClient::send_file_data_th(const char* keys) // 文件权限 auto perms = fs::status(t->cur_file_).permissions(); std::string str_perm = std::to_string(static_cast(perms)); - std::string info_result = str_size + "," + str_perm; +#if defined(_WIN32) + std::string plat("0"); +#else + std::string plat("1"); +#endif + + std::string info_result = plat + "," + str_size + "," + str_perm; mpinfo("To {} File Size: {} [{}], permissions:{}", str_key, ofen::OfUtil::get_file_size(size), size, str_perm); buf->len_ = std::snprintf(buf->data_, g_BuffSize, "%s", info_result.c_str()); diff --git a/client/client.h b/client/client.h index ea2a6fc..9ef7662 100644 --- a/client/client.h +++ b/client/client.h @@ -31,6 +31,7 @@ struct TransInfomation { std::string cur_file_; std::fstream file_{}; uint16_t permissions{}; + uint16_t remote_plat{}; TransState trans_state_{TRANS_FAILED}; }; diff --git a/filecomplete b/filecomplete index 58fa3db..a00a498 160000 --- a/filecomplete +++ b/filecomplete @@ -1 +1 @@ -Subproject commit 58fa3dbb09b41538192ae0c8ecf73dc8245a225a +Subproject commit a00a49809ed1d4b0a0c922ef6c5fc99216e04418 diff --git a/util/CMakeLists.txt b/util/CMakeLists.txt index 7585f0c..4213118 100644 --- a/util/CMakeLists.txt +++ b/util/CMakeLists.txt @@ -9,5 +9,5 @@ endif() set(SOURCES util.h util.cpp) add_library(trans_util STATIC ${SOURCES}) -target_link_libraries(trans_util PUBLIC ofen) +target_link_libraries(trans_util PUBLIC ofen filecomplete) target_include_directories(trans_util PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) \ No newline at end of file diff --git a/util/util.h b/util/util.h index 6a527db..a3bdbbc 100644 --- a/util/util.h +++ b/util/util.h @@ -2,6 +2,7 @@ #include "of_util.h" #include #include +#include #include #include #include @@ -93,17 +94,25 @@ inline std::string now_str() template void mpdebug(const std::string& format, Args&&... args) { + lock_print(); fmt::print(fg(fmt::color::steel_blue), now_str() + format + "\n", std::forward(args)...); + unlock_print(); } template void mpinfo(const std::string& format, Args&&... args) { + lock_print(); fmt::print(fg(static_cast(0x0EA113)), now_str() + format + "\n", std::forward(args)...); + unlock_print(); } template void mpwarn(const std::string& format, Args&&... args) { + lock_print(); fmt::print(fg(fmt::color::yellow_green), now_str() + format + "\n", std::forward(args)...); + unlock_print(); } template void mperror(const std::string& format, Args&&... args) { + lock_print(); fmt::print(fg(fmt::color::orange_red), now_str() + format + "\n", std::forward(args)...); + unlock_print(); } \ No newline at end of file