add PICli to pift
fix relative path in PIFileTransfer git-svn-id: svn://db.shs.com.ru/pip@67 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
const uint PIBaseTransfer::signature = 0x54444950;
|
||||
|
||||
PIBaseTransfer::PIBaseTransfer(): crc(standardCRC_16()) {
|
||||
PIBaseTransfer::PIBaseTransfer(): crc(standardCRC_16()), diag(false) {
|
||||
header.sig = signature;
|
||||
header.session_id = 0;
|
||||
packet_header_size = sizeof(PacketHeader) + customHeader().size();
|
||||
@@ -12,10 +12,11 @@ PIBaseTransfer::PIBaseTransfer(): crc(standardCRC_16()) {
|
||||
bytes_all = bytes_cur = 0;
|
||||
replies_cnt = send_queue = 0;
|
||||
timeout_ = 10.;
|
||||
diag.setDisconnectTimeout(10.);
|
||||
diag.setDisconnectTimeout(timeout_);
|
||||
CONNECTU(&diag, qualityChanged, this, diagChanged);
|
||||
packets_count = 32;
|
||||
setPacketSize(4096);
|
||||
srand(PISystemTime::current().toMilliseconds());
|
||||
randomize();
|
||||
}
|
||||
|
||||
|
||||
@@ -103,8 +104,9 @@ void PIBaseTransfer::received(PIByteArray data) {
|
||||
return;
|
||||
}
|
||||
if (header.session_id != h.session_id && is_receiving) {
|
||||
sendBreak(h.session_id);
|
||||
return;
|
||||
// sendBreak(h.session_id);
|
||||
// return;
|
||||
finish_receive(false, true);
|
||||
}
|
||||
if (data.size() == sizeof(StartRequest)) {
|
||||
StartRequest sr;
|
||||
@@ -391,14 +393,21 @@ bool PIBaseTransfer::finish_send(bool ok) {
|
||||
}
|
||||
|
||||
|
||||
void PIBaseTransfer::finish_receive(bool ok) {
|
||||
void PIBaseTransfer::finish_receive(bool ok, bool quet) {
|
||||
if (ok) state_string = "receive done";
|
||||
else state_string = "receive failed";
|
||||
// piCoutObj << state_string << PIString::readableSize(bytes_all);
|
||||
is_receiving = false;
|
||||
if (!ok) sendBreak(header.session_id);
|
||||
if (!ok && !quet) sendBreak(header.session_id);
|
||||
diag.stop();
|
||||
receiveFinished(ok);
|
||||
bytes_all = bytes_cur = 0;
|
||||
}
|
||||
|
||||
|
||||
void PIBaseTransfer::diagChanged(PIDiagnostics::Quality new_quality, PIDiagnostics::Quality old_quality) {
|
||||
if (is_receiving) {
|
||||
if (new_quality == PIDiagnostics::Failure) stopReceive();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -101,7 +101,8 @@ private:
|
||||
void sendReply(PacketType reply);
|
||||
bool getStartRequest();
|
||||
bool finish_send(bool ok);
|
||||
void finish_receive(bool ok);
|
||||
void finish_receive(bool ok, bool quet = false);
|
||||
EVENT_HANDLER2(void, diagChanged, PIDiagnostics::Quality, new_quality, PIDiagnostics::Quality, old_quality);
|
||||
};
|
||||
|
||||
inline PIByteArray & operator <<(PIByteArray & s, const PIBaseTransfer::PacketHeader & v) {s << v.sig << v.type << v.session_id << v.id << v.crc; return s;}
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
#include "pitimer.h"
|
||||
|
||||
|
||||
class PIP_EXPORT PIDiagnostics: private PITimer
|
||||
class PIP_EXPORT PIDiagnostics: public PITimer
|
||||
{
|
||||
PIOBJECT_SUBCLASS(PIDiagnostics, PITimer)
|
||||
friend class PIConnection;
|
||||
|
||||
@@ -316,4 +316,10 @@ inline PICout operator <<(PICout s, const PIFile::FileInfo & v) {
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
inline PIByteArray & operator <<(PIByteArray & s, const PIFile::FileInfo & v) {s << v.path << v.size << v.time_access << v.time_modification <<
|
||||
(int)v.flags << v.id_user << v.id_group << v.perm_user.raw << v.perm_group.raw << v.perm_other.raw; return s;}
|
||||
inline PIByteArray & operator >>(PIByteArray & s, PIFile::FileInfo & v) {s >> v.path >> v.size >> v.time_access >> v.time_modification >>
|
||||
*(int*)(&(v.flags)) >> v.id_user >> v.id_group >> v.perm_user.raw >> v.perm_group.raw >> v.perm_other.raw; return s;}
|
||||
|
||||
#endif // PIFILE_H
|
||||
|
||||
@@ -43,22 +43,30 @@ bool PIFileTransfer::send(const PIStringList& files) {
|
||||
|
||||
|
||||
bool PIFileTransfer::send(PIVector<PIFile::FileInfo> entries) {
|
||||
PIVector<PIFile::FileInfo> allEntries;
|
||||
PIVector<PFTFileInfo> allEntries;
|
||||
for (int i = 0; i < entries.size_s(); i++) {
|
||||
allEntries << entries[i];
|
||||
if (entries[i].isDir())
|
||||
allEntries << PIDir::allEntries(entries[i].path);
|
||||
allEntries << PFTFileInfo(entries[i]);
|
||||
allEntries.back().dest_path = entries[i].name();
|
||||
if (entries[i].isDir()) {
|
||||
PIDir d(entries[i].path);
|
||||
d.up();
|
||||
PIVector<PIFile::FileInfo> fls = d.allEntries();
|
||||
for (int j=0; j<fls.size(); j++) {
|
||||
allEntries << PFTFileInfo(fls[j]);
|
||||
allEntries.back().dest_path = d.relative(fls[j].path);
|
||||
}
|
||||
}
|
||||
}
|
||||
return sendFiles(allEntries);
|
||||
}
|
||||
|
||||
|
||||
bool PIFileTransfer::sendFiles(const PIVector<PIFile::FileInfo> &files) {
|
||||
bool PIFileTransfer::sendFiles(const PIVector<PFTFileInfo> &files) {
|
||||
files_ = files;
|
||||
PIStringList names;
|
||||
// piCoutObj << "prepare to send" << files_.size() << "files";
|
||||
for(int i=0; i<files_.size_s(); i++) {
|
||||
files_[i].path = dir.relative(files_[i].path);
|
||||
// files_[i].path = dir.relative(files_[i].path);
|
||||
if (names.contains(files_[i].path)) {files_.remove(i); i--;}
|
||||
else names << files_[i].path;
|
||||
if (files_[i].isDir()) files_[i].size = 0;
|
||||
@@ -159,7 +167,7 @@ PIByteArray PIFileTransfer::buildPacket(Part p) {
|
||||
PIFile::FileInfo fi = files_[p.id-1];
|
||||
if (fi.isFile()) {
|
||||
// piCout << "send file" << fi.name() << fi.size;
|
||||
PIString path = dir.absolutePath() + dir.separator + fi.path;
|
||||
PIString path = fi.path;
|
||||
if (work_file.path() != path || !work_file.isOpened()) {
|
||||
if (!work_file.open(path, PIIODevice::ReadOnly)) {
|
||||
break_ = true;
|
||||
|
||||
@@ -14,6 +14,10 @@ public:
|
||||
~PIFileTransfer();
|
||||
|
||||
enum StepType {pft_None, pft_Description, pft_Data};
|
||||
struct PFTFileInfo : public PIFile::FileInfo {
|
||||
PFTFileInfo(const PIFile::FileInfo &fi = PIFile::FileInfo()) : PIFile::FileInfo(fi) {}
|
||||
PIString dest_path;
|
||||
};
|
||||
|
||||
#pragma pack(push,1)
|
||||
struct PFTHeader {
|
||||
@@ -58,7 +62,7 @@ public:
|
||||
|
||||
private:
|
||||
static const char sign[];
|
||||
PIVector<PIFile::FileInfo> files_;
|
||||
PIVector<PFTFileInfo> files_;
|
||||
PIString cur_file_string;
|
||||
llong bytes_file_all, bytes_file_cur;
|
||||
PFTHeader pftheader;
|
||||
@@ -66,7 +70,7 @@ private:
|
||||
PIFile work_file;
|
||||
PIByteArray desc;
|
||||
|
||||
bool sendFiles(const PIVector<PIFile::FileInfo> &files);
|
||||
bool sendFiles(const PIVector<PFTFileInfo> &files);
|
||||
void processFile(int id, ullong start, PIByteArray &data);
|
||||
virtual void receivePart(Part fi, PIByteArray ba, PIByteArray pheader);
|
||||
virtual PIByteArray buildPacket(Part fi);
|
||||
@@ -80,9 +84,9 @@ private:
|
||||
inline PIByteArray & operator <<(PIByteArray & s, const PIFileTransfer::PFTHeader & v) {s << v.raw_sig << v.step << v.session_id; return s;}
|
||||
inline PIByteArray & operator >>(PIByteArray & s, PIFileTransfer::PFTHeader & v) {s >> v.raw_sig >> v.step >> v.session_id; return s;}
|
||||
|
||||
inline PIByteArray & operator <<(PIByteArray & s, const PIFile::FileInfo & v) {s << v.path << v.size << v.time_access << v.time_modification <<
|
||||
inline PIByteArray & operator <<(PIByteArray & s, const PIFileTransfer::PFTFileInfo & v) {s << v.dest_path << v.size << v.time_access << v.time_modification <<
|
||||
(int)v.flags << v.id_user << v.id_group << v.perm_user.raw << v.perm_group.raw << v.perm_other.raw; return s;}
|
||||
inline PIByteArray & operator >>(PIByteArray & s, PIFile::FileInfo & v) {s >> v.path >> v.size >> v.time_access >> v.time_modification >>
|
||||
inline PIByteArray & operator >>(PIByteArray & s, PIFileTransfer::PFTFileInfo & v) {s >> v.dest_path >> v.size >> v.time_access >> v.time_modification >>
|
||||
*(int*)(&(v.flags)) >> v.id_user >> v.id_group >> v.perm_user.raw >> v.perm_group.raw >> v.perm_other.raw; return s;}
|
||||
|
||||
#endif // PIFILETRANSFER_H
|
||||
|
||||
Reference in New Issue
Block a user