|
|
|
|
@@ -23,17 +23,29 @@ Daemon::Remote::~Remote() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Daemon::Remote::sendFiles(const PIString & dir, const PIStringList & fl) {
|
|
|
|
|
void Daemon::Remote::startAction(Daemon::PacketType a, const PIString & dir, const PIStringList & fl) {
|
|
|
|
|
_fl = fl;
|
|
|
|
|
piForeach (PIString & s, _fl)
|
|
|
|
|
s.prepend(dir);
|
|
|
|
|
piCout << "send" << _fl;
|
|
|
|
|
if (!dir.isEmpty())
|
|
|
|
|
piForeach (PIString & s, _fl)
|
|
|
|
|
s.prepend(dir);
|
|
|
|
|
//piCout << "send" << _fl;
|
|
|
|
|
action = a;
|
|
|
|
|
startOnce();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Daemon::Remote::run() {
|
|
|
|
|
ft.send(_fl);
|
|
|
|
|
switch (action) {
|
|
|
|
|
case CopyFiles: ft.send(_fl); break;
|
|
|
|
|
case RemoveFiles:
|
|
|
|
|
{
|
|
|
|
|
PIDir d(dir_my);
|
|
|
|
|
::removeFiles(d, _fl);
|
|
|
|
|
removeFinished(name(), d.absolutePath());
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default: break;
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -45,20 +57,23 @@ Daemon::TileFileProgress::TileFileProgress(): PIScreenTile() {
|
|
|
|
|
setMargins(1, 1, 1, 1);
|
|
|
|
|
spacing = 1;
|
|
|
|
|
back_format.color_back = Yellow;
|
|
|
|
|
label_file = new TileSimple("");
|
|
|
|
|
label_speed = new TileSimple("");
|
|
|
|
|
label_file = new TileSimple();
|
|
|
|
|
label_speed = new TileSimple();
|
|
|
|
|
label_cnt = new TileSimple();
|
|
|
|
|
prog_file = new TileProgress();
|
|
|
|
|
prog_all = new TileProgress();
|
|
|
|
|
buttons = new TileButtons("fd_buttons");
|
|
|
|
|
buttons->content << TileButtons::Button("Pause", CellFormat());
|
|
|
|
|
buttons->content << TileButtons::Button("Cancel", CellFormat());
|
|
|
|
|
buttons->back_format.color_back = label_file->back_format.color_back = label_speed->back_format.color_back = Yellow;
|
|
|
|
|
label_file->back_format.color_char = label_speed->back_format.color_char = Black;
|
|
|
|
|
label_file->content.resize(1);
|
|
|
|
|
label_speed->content.resize(1);
|
|
|
|
|
label_file->content[0].second = label_speed->content[0].second = CellFormat(Black, Transparent);
|
|
|
|
|
label_cnt->content.resize(1);
|
|
|
|
|
buttons->back_format.color_back = Yellow;
|
|
|
|
|
label_file->back_format.color_back = label_speed->back_format.color_back = label_cnt->back_format.color_back = Yellow;
|
|
|
|
|
label_file->content[0].second = label_speed->content[0].second = label_cnt->content[0].second = CellFormat(Black, Transparent);
|
|
|
|
|
addTile(label_file);
|
|
|
|
|
addTile(label_speed);
|
|
|
|
|
addTile(label_cnt);
|
|
|
|
|
addTile(prog_file);
|
|
|
|
|
addTile(prog_all);
|
|
|
|
|
addTile(buttons);
|
|
|
|
|
@@ -84,10 +99,29 @@ void Daemon::TileFileProgress::drawEvent(PIScreenDrawer * d) {
|
|
|
|
|
label_file->content[0].first = ft->stateString() + " " + ft->curFile();
|
|
|
|
|
if (!label_file->content[0].first.isEmpty())
|
|
|
|
|
label_file->content[0].first[0] = label_file->content[0].first[0].toUpper();
|
|
|
|
|
PIString spd;
|
|
|
|
|
PIString spd("Speed: "), cnt;
|
|
|
|
|
if (ft->isReceiving()) spd = ft->diagnostic().receiveSpeed();
|
|
|
|
|
else spd = ft->diagnostic().sendSpeed();
|
|
|
|
|
else spd = ft->diagnostic().sendSpeed().expandRightTo(10, ' ');
|
|
|
|
|
spd += " ETA: ";
|
|
|
|
|
if (!ft->isReceiving() && !ft->isSending()) {
|
|
|
|
|
tm.reset();
|
|
|
|
|
spd += "-";
|
|
|
|
|
} else {
|
|
|
|
|
double el = tm.elapsed_s();
|
|
|
|
|
int cb = ft->bytesCur();
|
|
|
|
|
if ((el <= 0.) || (cb <= 0)) spd += "-";
|
|
|
|
|
else {
|
|
|
|
|
double s = (el / cb) * (ft->bytesAll() - cb);
|
|
|
|
|
spd += readableTime(PITime::fromSystemTime(PISystemTime::fromSeconds(s)));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
spd += " Elapsed: " + readableTime(PITime::fromSystemTime(PISystemTime::fromSeconds(tme.elapsed_s())));
|
|
|
|
|
label_speed->content[0].first = spd;
|
|
|
|
|
cnt = "File: " + PIString::readableSize(ft->bytesFileCur()).expandLeftTo(8, ' ');
|
|
|
|
|
cnt += " / " + PIString::readableSize(ft->bytesFileAll()).expandLeftTo(8, ' ');
|
|
|
|
|
cnt += " All: " + PIString::readableSize(ft->bytesCur()).expandLeftTo(8, ' ');
|
|
|
|
|
cnt += " / " + PIString::readableSize(ft->bytesAll()).expandLeftTo(8, ' ');
|
|
|
|
|
label_cnt->content[0].first = cnt;
|
|
|
|
|
if (ft->bytesFileAll() > 0)
|
|
|
|
|
prog_file->value = piRoundd(ft->bytesFileCur() / double(ft->bytesFileAll()) * 100.);
|
|
|
|
|
if (ft->bytesAll() > 0)
|
|
|
|
|
@@ -104,6 +138,8 @@ void Daemon::TileFileProgress::show(PIFileTransfer * f) {
|
|
|
|
|
::screen.setDialogTile(this);
|
|
|
|
|
buttons->cur = 0;
|
|
|
|
|
buttons->setFocus();
|
|
|
|
|
tm.reset();
|
|
|
|
|
tme.reset();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -410,6 +446,7 @@ void Daemon::peerConnected(const PIString & name) {
|
|
|
|
|
CONNECTU(r, receiveFinished, this, filesReceived)
|
|
|
|
|
CONNECTU(r, receiveFinished, this, closeFileDialog)
|
|
|
|
|
CONNECTU(r, sendFinished, this, closeFileDialog)
|
|
|
|
|
CONNECTU(r, removeFinished, this, filesRemoved)
|
|
|
|
|
remotes.insert(name, r);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -433,6 +470,14 @@ void Daemon::filesReceived(const PIString & name, bool ok) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Daemon::filesRemoved(const PIString & name, const PIString & dir) {
|
|
|
|
|
Remote * r = remotes.value(name, 0);
|
|
|
|
|
if (!r) return;
|
|
|
|
|
if (r->dir_my.absolutePath() != dir) return;
|
|
|
|
|
sendDirToRemote(r);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Daemon::closeFileDialog(const PIString & name, bool ok) {
|
|
|
|
|
//piCout << "CLOSE" << tile_file_progress->conn_name << name << ok;
|
|
|
|
|
if (tile_file_progress->conn_name != name) return;
|
|
|
|
|
@@ -458,7 +503,6 @@ void Daemon::dataReceived(const PIString & from, const PIByteArray & data) {
|
|
|
|
|
Remote * r(0);
|
|
|
|
|
PIString dir;
|
|
|
|
|
int type; ba >> type;
|
|
|
|
|
bool answer_dirs = false;
|
|
|
|
|
//piCout << "rec from " << from << type;
|
|
|
|
|
switch (type) {
|
|
|
|
|
case RequestHostInfo:
|
|
|
|
|
@@ -472,8 +516,8 @@ void Daemon::dataReceived(const PIString & from, const PIByteArray & data) {
|
|
|
|
|
r->dir_my.cd(dir);
|
|
|
|
|
r->ft.setDirectory(r->dir_my);
|
|
|
|
|
piCout << "store to" << r->dir_my.absolutePath();
|
|
|
|
|
answer_dirs = true;
|
|
|
|
|
piCout << "cd to" << dir << ", abs =" << r->dir_my.absolutePath();
|
|
|
|
|
sendDirToRemote(r);
|
|
|
|
|
break;
|
|
|
|
|
case ReplyHostInfo:
|
|
|
|
|
ba >> info_other;
|
|
|
|
|
@@ -495,6 +539,7 @@ void Daemon::dataReceived(const PIString & from, const PIByteArray & data) {
|
|
|
|
|
case CopyFiles:
|
|
|
|
|
r = remotes.value(from);
|
|
|
|
|
if (!r) return;
|
|
|
|
|
if (r->isRunning()) return;
|
|
|
|
|
{
|
|
|
|
|
PIStringList files;
|
|
|
|
|
ba >> files;
|
|
|
|
|
@@ -505,12 +550,13 @@ void Daemon::dataReceived(const PIString & from, const PIByteArray & data) {
|
|
|
|
|
case RemoveFiles:
|
|
|
|
|
r = remotes.value(from);
|
|
|
|
|
if (!r) return;
|
|
|
|
|
if (r->isRunning()) return;
|
|
|
|
|
{
|
|
|
|
|
PIStringList files;
|
|
|
|
|
ba >> files;
|
|
|
|
|
//piCout << "send" << files << "from" << r->dir_my.absolutePath();
|
|
|
|
|
removeFiles(r->dir_my, files);
|
|
|
|
|
answer_dirs = true;
|
|
|
|
|
r->removeFiles(files);
|
|
|
|
|
//answer_dirs = true;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case MkDir:
|
|
|
|
|
@@ -521,7 +567,7 @@ void Daemon::dataReceived(const PIString & from, const PIByteArray & data) {
|
|
|
|
|
ba >> dn;
|
|
|
|
|
//piCout << "send" << files << "from" << r->dir_my.absolutePath();
|
|
|
|
|
PIDir::make(r->dir_my.absolutePath() + PIDir::separator + dn);
|
|
|
|
|
answer_dirs = true;
|
|
|
|
|
sendDirToRemote(r);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case FileTransfer:
|
|
|
|
|
@@ -529,16 +575,21 @@ void Daemon::dataReceived(const PIString & from, const PIByteArray & data) {
|
|
|
|
|
if (r) r->received(ba);
|
|
|
|
|
break;
|
|
|
|
|
};
|
|
|
|
|
if (answer_dirs) {
|
|
|
|
|
PIVector<PIFile::FileInfo> fil = r->dir_my.entries();
|
|
|
|
|
piForeach (PIFile::FileInfo & f, fil)
|
|
|
|
|
f.path = f.name();
|
|
|
|
|
rba << int(ReplyChangeDir) << r->dir_my.absolutePath() << fil;
|
|
|
|
|
}
|
|
|
|
|
if (!rba.isEmpty()) send(from, rba);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Daemon::sendDirToRemote(Remote * r) {
|
|
|
|
|
if (!r) return;
|
|
|
|
|
PIVector<PIFile::FileInfo> fil = r->dir_my.entries();
|
|
|
|
|
piForeach (PIFile::FileInfo & f, fil)
|
|
|
|
|
f.path = f.name();
|
|
|
|
|
PIByteArray ba;
|
|
|
|
|
ba << int(ReplyChangeDir) << r->dir_my.absolutePath() << fil;
|
|
|
|
|
send(r->name(), ba);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Daemon::makeMyHostInfo() {
|
|
|
|
|
info_my.execCommand = PISystemInfo::instance()->execCommand;
|
|
|
|
|
info_my.hostname = PISystemInfo::instance()->hostname;
|
|
|
|
|
|