fix:1.尝试处理Linux下光标错位问题,2.优化文件权限仅unix之间。 3.优化打印下载进度时暂时不显示光标。
This commit is contained in:
parent
fdd18882d8
commit
7767afee84
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
@ -21,7 +21,7 @@
|
||||
],
|
||||
"visualizerFile": "${workspaceRoot}/.vscode/qt5.natvis",
|
||||
"args": [
|
||||
"-n", "1"
|
||||
"-n", "0"
|
||||
]
|
||||
},
|
||||
"cmake.environment": {
|
||||
|
@ -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<fs::perms>(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<uint16_t>(std::stoul(vec[1]));
|
||||
down_->permissions = static_cast<uint16_t>(std::stoul(vec[2]));
|
||||
down_->remote_plat = static_cast<uint16_t>(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<uint16_t>(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());
|
||||
|
@ -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};
|
||||
};
|
||||
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 58fa3dbb09b41538192ae0c8ecf73dc8245a225a
|
||||
Subproject commit a00a49809ed1d4b0a0c922ef6c5fc99216e04418
|
@ -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})
|
@ -2,6 +2,7 @@
|
||||
#include "of_util.h"
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
#include <filecomplete.h>
|
||||
#include <fmt/color.h>
|
||||
#include <fmt/printf.h>
|
||||
#include <functional>
|
||||
@ -93,17 +94,25 @@ inline std::string now_str()
|
||||
|
||||
template <typename... Args> void mpdebug(const std::string& format, Args&&... args)
|
||||
{
|
||||
lock_print();
|
||||
fmt::print(fg(fmt::color::steel_blue), now_str() + format + "\n", std::forward<Args>(args)...);
|
||||
unlock_print();
|
||||
}
|
||||
template <typename... Args> void mpinfo(const std::string& format, Args&&... args)
|
||||
{
|
||||
lock_print();
|
||||
fmt::print(fg(static_cast<fmt::color>(0x0EA113)), now_str() + format + "\n", std::forward<Args>(args)...);
|
||||
unlock_print();
|
||||
}
|
||||
template <typename... Args> void mpwarn(const std::string& format, Args&&... args)
|
||||
{
|
||||
lock_print();
|
||||
fmt::print(fg(fmt::color::yellow_green), now_str() + format + "\n", std::forward<Args>(args)...);
|
||||
unlock_print();
|
||||
}
|
||||
template <typename... Args> void mperror(const std::string& format, Args&&... args)
|
||||
{
|
||||
lock_print();
|
||||
fmt::print(fg(fmt::color::orange_red), now_str() + format + "\n", std::forward<Args>(args)...);
|
||||
unlock_print();
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user