add:update功能添加支持变量(未完全测试)。
This commit is contained in:
parent
e775175c14
commit
df17c7906f
@ -363,9 +363,10 @@ bool CClient::request_update_list(const std::string& param)
|
||||
}
|
||||
|
||||
// 读取list文件
|
||||
std::ifstream in(COfPath::to_full(list_file));
|
||||
std::string list_file_full = COfPath::to_full(list_file);
|
||||
std::ifstream in(list_file_full);
|
||||
if (!in.is_open()) {
|
||||
mperror("Can't Open File:{}", COfPath::to_full(list_file));
|
||||
mperror("Can't Open File:{}", list_file_full);
|
||||
return false;
|
||||
}
|
||||
std::istreambuf_iterator<char> iterf(in);
|
||||
@ -389,12 +390,14 @@ bool CClient::request_update_list(const std::string& param)
|
||||
mpinfo("---> check {}", hitem);
|
||||
auto v = COfStr::split(hitem, "|");
|
||||
if (v.size() >= 2) {
|
||||
if (!fs::exists(v[0])) {
|
||||
mperror("file {} not exist.", v[0]);
|
||||
auto pr = variable_handle(list_file_full, v[0], true);
|
||||
if (!fs::exists(pr)) {
|
||||
mperror("file {} not exist.", pr);
|
||||
valid = false;
|
||||
break;
|
||||
}
|
||||
handled_content.append(hitem + "\n");
|
||||
mpinfo("---> check pass {}", pr);
|
||||
handled_content.append(pr + "|" + v[1] + "\n");
|
||||
continue;
|
||||
}
|
||||
valid = false;
|
||||
@ -402,7 +405,7 @@ bool CClient::request_update_list(const std::string& param)
|
||||
}
|
||||
|
||||
if (!valid) {
|
||||
mperror("Judge List File {} Format Not Passed.", list_file);
|
||||
mperror("Judge List File {} Format Not Passed.", list_file_full);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -410,7 +413,7 @@ bool CClient::request_update_list(const std::string& param)
|
||||
handled_content = CCodec::ansi_to_u8(handled_content);
|
||||
#endif
|
||||
|
||||
list_file_ = list_file;
|
||||
list_file_ = list_file_full;
|
||||
std::shared_ptr<CFrameBuffer> buf = std::make_shared<CFrameBuffer>();
|
||||
buf->type_ = TYPE_REQUEST_UPDATE_LIST;
|
||||
buf->data_ = new char[handled_content.size() + 1]();
|
||||
@ -442,15 +445,17 @@ bool CClient::check_update_list(const std::string& content, std::map<std::string
|
||||
valid = false;
|
||||
break;
|
||||
}
|
||||
if (!fs::exists(vi[1])) {
|
||||
auto pr = variable_handle("", vi[1], false);
|
||||
if (!fs::exists(pr)) {
|
||||
valid = false;
|
||||
mperror("Not exist {}", vi[1]);
|
||||
mperror("Not exist {}", pr);
|
||||
break;
|
||||
}
|
||||
mpinfo("---> check pass {}", pr);
|
||||
#ifdef _WIN32
|
||||
files[CCodec::ansi_to_u8(vi[0])] = CCodec::ansi_to_u8(vi[1]);
|
||||
files[CCodec::ansi_to_u8(vi[0])] = CCodec::ansi_to_u8(pr);
|
||||
#else
|
||||
files[vi[0]] = vi[1];
|
||||
files[vi[0]] = pr;
|
||||
#endif
|
||||
}
|
||||
return valid;
|
||||
@ -766,6 +771,24 @@ void CClient::judget_down_active()
|
||||
}
|
||||
}
|
||||
|
||||
std::string CClient::variable_handle(const std::string& task_list_path, const std::string& source,
|
||||
bool is_send)
|
||||
{
|
||||
std::string result(source);
|
||||
// 支持的变量如下:
|
||||
// ${HOME} 用户目录(发送端接收端均支持)
|
||||
// ${CURRENT} 任务文件所在目录(该变量仅支持发送端,因为接收端没有任务文件所在路径)
|
||||
if (source.find("${HOME}") != std::string::npos) {
|
||||
result = COfStr::replace(result, "${HOME}", COfPath::get_home());
|
||||
}
|
||||
if (is_send && source.find("${CURRENT}") != std::string::npos) {
|
||||
fs::path p(task_list_path);
|
||||
std::string list_dir = p.parent_path().string();
|
||||
result = COfStr::replace(result, "${CURRENT}", list_dir);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
CFileOpr::CFileOpr() = default;
|
||||
|
||||
CFileOpr::~CFileOpr() = default;
|
||||
|
@ -50,7 +50,7 @@ public:
|
||||
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& param);
|
||||
static bool check_update_list(const std::string& content, std::map<std::string, std::string>& files);
|
||||
bool check_update_list(const std::string& content, std::map<std::string, std::string>& files);
|
||||
bool down_update_file(const std::map<std::string, std::string>& files);
|
||||
|
||||
private:
|
||||
@ -61,6 +61,7 @@ private:
|
||||
void send_file_data_th(const char* keys);
|
||||
void hearts();
|
||||
void judget_down_active();
|
||||
std::string variable_handle(const std::string& task_list_path, const std::string& source, bool is_send);
|
||||
|
||||
private:
|
||||
std::mutex mutex_;
|
||||
|
Loading…
x
Reference in New Issue
Block a user