git-svn-id: svn://db.shs.com.ru/pip@236 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include "daemon.h"
|
||||
#include "shared.h"
|
||||
#include "pisysteminfo.h"
|
||||
#include "picrypt.h"
|
||||
|
||||
const char self_name[] = "__self__";
|
||||
extern PIScreen screen;
|
||||
@@ -43,7 +44,7 @@ void Daemon::Remote::run() {
|
||||
case RemoveFiles:
|
||||
::removeFiles(d, _fl);
|
||||
updateDirEntries();
|
||||
removeFinished(name(), d.absolutePath());
|
||||
changeDirFinished(name(), d.absolutePath());
|
||||
break;
|
||||
case RequestChangeDir:
|
||||
updateDirEntries();
|
||||
@@ -54,6 +55,15 @@ void Daemon::Remote::run() {
|
||||
updateDirEntries();
|
||||
changeDirFinished(name(), d.absolutePath());
|
||||
break;
|
||||
case CryptFiles:
|
||||
piCoutObj << "CryptFiles";
|
||||
if (!_fl.isEmpty()) {
|
||||
PIString p = askUserInput("Password:");
|
||||
::cryptFiles(d, _fl, PICrypt::hash(p));
|
||||
}
|
||||
updateDirEntries();
|
||||
changeDirFinished(name(), d.absolutePath());
|
||||
break;
|
||||
default: break;
|
||||
};
|
||||
}
|
||||
@@ -208,6 +218,7 @@ Daemon::Daemon(): inited__(false), PIPeer(pisd_prefix + PISystemInfo::instance()
|
||||
CONNECTU(_self, sendRequest, this, localSend)
|
||||
CONNECTU(_self, receiveFinished, this, closeFileDialog)
|
||||
CONNECTU(_self, sendFinished, this, closeFileDialog)
|
||||
CONNECTU(_self, changeDirFinished, this, dirChanged)
|
||||
localft.setName(self_name);
|
||||
CONNECTU(&localft, sendRequest, _self, received)
|
||||
dtimer.addDelimiter(5);
|
||||
@@ -393,7 +404,7 @@ void Daemon::fmKeyEvent(PIKbdListener::KeyEvent key) {
|
||||
void Daemon::fmActionRequest(bool remote_tile, FileManager::Action type, PIVariant data) {
|
||||
Remote * r = 0;
|
||||
r = remotes.value(conn_name, 0);
|
||||
if (!r && type != FileManager::LocalCopy) return;
|
||||
if (!r && type != FileManager::LocalCopy && type != FileManager::LocalCrypt) return;
|
||||
switch (type) {
|
||||
case FileManager::Copy:
|
||||
if (remote_tile) {
|
||||
@@ -435,6 +446,25 @@ void Daemon::fmActionRequest(bool remote_tile, FileManager::Action type, PIVaria
|
||||
}
|
||||
tile_file_progress->rec = false;
|
||||
tile_file_progress->show(&(_self->ft));
|
||||
case FileManager::Crypt:
|
||||
if (remote_tile) {
|
||||
PIByteArray ba;
|
||||
ba << int(CryptFiles) << fm.selectedRemote();
|
||||
send(conn_name, ba);
|
||||
} else {
|
||||
_self->dir_my.setDir(fm.localDir());
|
||||
_self->cryptFiles(data.toStringList());
|
||||
}
|
||||
break;
|
||||
case FileManager::LocalCrypt:
|
||||
piCoutObj << "LocalCrypt";
|
||||
if (remote_tile) {
|
||||
_self->dir_my.setDir(fm.remoteDir());
|
||||
} else {
|
||||
_self->dir_my.setDir(fm.localDir());
|
||||
}
|
||||
_self->cryptFiles(data.toStringList());
|
||||
break;
|
||||
default: break;
|
||||
};
|
||||
//piCout << remote_tile << type << data;
|
||||
@@ -502,7 +532,6 @@ void Daemon::peerConnected(const PIString & p_name) {
|
||||
CONNECTU(r, receiveFinished, this, filesReceived)
|
||||
CONNECTU(r, receiveFinished, this, closeFileDialog)
|
||||
CONNECTU(r, sendFinished, this, closeFileDialog)
|
||||
CONNECTU(r, removeFinished, this, filesRemoved)
|
||||
CONNECTU(r, changeDirFinished, this, dirChanged)
|
||||
PIMutexLocker ml2(remote_mutex);
|
||||
remotes.insert(p_name, r);
|
||||
@@ -535,15 +564,13 @@ void Daemon::filesReceived(const PIString & p_name, bool ok) {
|
||||
|
||||
|
||||
void Daemon::dirChanged(const PIString & p_name, const PIString & dir) {
|
||||
PIMutexLocker ml(remote_mutex);
|
||||
Remote * r = remotes.value(p_name, 0);
|
||||
if (!r) return;
|
||||
if (r->dir_my.absolutePath() != dir) return;
|
||||
sendDirToRemote(r);
|
||||
}
|
||||
|
||||
|
||||
void Daemon::filesRemoved(const PIString & p_name, const PIString & dir) {
|
||||
if (p_name == self_name) {
|
||||
fm.clearSelectionLocal();
|
||||
fm.clearSelectionRemote();
|
||||
fm.updateLocalDir();
|
||||
fm.updateRemoteDir();
|
||||
return;
|
||||
}
|
||||
PIMutexLocker ml(remote_mutex);
|
||||
Remote * r = remotes.value(p_name, 0);
|
||||
if (!r) return;
|
||||
@@ -652,6 +679,15 @@ void Daemon::dataReceived(const PIString & from, const PIByteArray & data) {
|
||||
case FileTransfer:
|
||||
if (r) r->received(ba);
|
||||
break;
|
||||
case CryptFiles:
|
||||
if (!r) return;
|
||||
if (r->isRunning()) return;
|
||||
{
|
||||
PIStringList files;
|
||||
ba >> files;
|
||||
r->cryptFiles(files);
|
||||
}
|
||||
break;
|
||||
};
|
||||
if (!rba.isEmpty()) send(from, rba);
|
||||
}
|
||||
|
||||
@@ -71,6 +71,7 @@ private:
|
||||
CopyFiles,
|
||||
RemoveFiles,
|
||||
MkDir,
|
||||
CryptFiles,
|
||||
|
||||
FileTransfer = 30
|
||||
|
||||
@@ -85,6 +86,7 @@ private:
|
||||
void removeFiles(const PIStringList & fl) {startAction(Daemon::RemoveFiles, PIString(), fl);}
|
||||
void updateDir() {startAction(Daemon::RequestChangeDir, PIString(), PIStringList());}
|
||||
void makeDir(const PIString & dir) {startAction(Daemon::MkDir, dir, PIStringList() << "");}
|
||||
void cryptFiles(const PIStringList & fl) {startAction(Daemon::CryptFiles, PIString(), fl);}
|
||||
EVENT_HANDLER1(void, ftSendRequest, PIByteArray &, data) {PIByteArray h; h << int(FileTransfer); data.insert(0, h); sendRequest(name(), data);}
|
||||
EVENT_HANDLER1(void, ftReceived, bool, ok) {receiveFinished(name(), ok);}
|
||||
EVENT_HANDLER1(void, ftSended, bool, ok) {sendFinished(name(), ok);}
|
||||
@@ -92,7 +94,6 @@ private:
|
||||
EVENT2(sendRequest, const PIString &, p_name, const PIByteArray &, data)
|
||||
EVENT2(receiveFinished, const PIString & , p_name, bool, ok)
|
||||
EVENT2(sendFinished, const PIString & , p_name, bool, ok)
|
||||
EVENT2(removeFinished, const PIString & , p_name, const PIString & , dir)
|
||||
EVENT2(changeDirFinished, const PIString & , p_name, const PIString & , dir)
|
||||
EVENT_HANDLER1(void, received, PIByteArray & , data) {ft.received(data);}
|
||||
|
||||
@@ -135,7 +136,6 @@ private:
|
||||
EVENT_HANDLER3(void, fmActionRequest, bool, remote_tile, FileManager::Action, type, PIVariant, data);
|
||||
EVENT_HANDLER2(void, timerEvent, void * , _d, int, delim);
|
||||
EVENT_HANDLER2(void, filesReceived, const PIString & , p_name, bool, ok);
|
||||
EVENT_HANDLER2(void, filesRemoved, const PIString & , p_name, const PIString & , dir);
|
||||
EVENT_HANDLER2(void, dirChanged, const PIString & , p_name, const PIString & , dir);
|
||||
EVENT_HANDLER2(void, closeFileDialog, const PIString & , p_name, bool, ok);
|
||||
EVENT_HANDLER2(void, localSend, const PIString & , p_name, const PIByteArray &, data);
|
||||
|
||||
@@ -40,7 +40,12 @@ bool FileManager::TileDir::keyEvent(PIKbdListener::KeyEvent key) {
|
||||
break;
|
||||
case PIKbdListener::F6:
|
||||
if (key.modifiers[PIKbdListener::Shift]) {
|
||||
askQuestion("Crypt selected files?");
|
||||
if (selected.isEmpty())
|
||||
selected << cur;
|
||||
if (!askQuestion("Crypt selected files?")) return true;
|
||||
setFocus();
|
||||
if (remote_mode) actionRequest(is_right, Crypt, selectedNames());
|
||||
else actionRequest(is_right, LocalCrypt, selectedNames());
|
||||
}
|
||||
break;
|
||||
case PIKbdListener::F7:
|
||||
|
||||
@@ -15,7 +15,7 @@ public:
|
||||
PIScreenTile * localTile() const {return panels[0];}
|
||||
PIScreenTile * remoteTile() const {return panels[1];}
|
||||
|
||||
enum Action {MkDir, Remove, Copy, Move, LocalCopy};
|
||||
enum Action {MkDir, Remove, Copy, Move, LocalCopy, Crypt, LocalCrypt};
|
||||
|
||||
void setLocal();
|
||||
void setRemote();
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "shared.h"
|
||||
#include "picrypt.h"
|
||||
|
||||
extern PIScreen screen;
|
||||
|
||||
@@ -118,7 +119,7 @@ void showInfo(const PIString & t) {
|
||||
|
||||
|
||||
void removeFiles(const PIDir & dir, PIStringList l) {
|
||||
l.removeOne("..");
|
||||
l.removeAll("..");
|
||||
PIString ap = dir.absolutePath();
|
||||
//piCout << "remove from" << ap;
|
||||
piForeachC (PIString & s, l) {
|
||||
@@ -134,3 +135,42 @@ void removeFiles(const PIDir & dir, PIStringList l) {
|
||||
PIFile::remove(fi.path);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool cryptFiles(const PIDir & dir, PIStringList l, const PIByteArray & secret) {
|
||||
if (secret.size() != PICrypt::sizeKey() || secret.isEmpty()) return false;
|
||||
l.removeAll("..");
|
||||
PIString ap = dir.absolutePath();
|
||||
piForeachC (PIString & s, l) {
|
||||
PIFile::FileInfo fi = PIFile::fileInfo(ap + PIDir::separator + s);
|
||||
if (fi.isDir()) {
|
||||
PIVector<PIFile::FileInfo> el = PIDir::allEntries(fi.path);
|
||||
piForeachCR (PIFile::FileInfo & e, el) {
|
||||
if (e.size != 0)
|
||||
cryptFile(e.path, secret);
|
||||
}
|
||||
}
|
||||
if (fi.size != 0)
|
||||
cryptFile(fi.path, secret);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool cryptFile(const PIString & path, const PIByteArray & secret){
|
||||
PIFile inf;
|
||||
PIByteArray ba;
|
||||
PICrypt crypt;
|
||||
if (!crypt.setKey(secret)) return false;
|
||||
if (!inf.open(path, PIIODevice::ReadOnly)) return false;
|
||||
ba = inf.readAll();
|
||||
ba = crypt.crypt(ba);
|
||||
if (ba.isEmpty()) return false;
|
||||
PIFile outf;
|
||||
if (!outf.open(path + ".crypt", PIIODevice::ReadWrite)) return false;
|
||||
outf.resize(0);
|
||||
outf.write(ba);
|
||||
outf.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,5 +15,7 @@ PIString askUserInput(const PIString &desc);
|
||||
bool askQuestion(const PIString & t);
|
||||
void showInfo(const PIString & t);
|
||||
void removeFiles(const PIDir & dir, PIStringList l);
|
||||
bool cryptFiles(const PIDir & dir, PIStringList l, const PIByteArray & secret);
|
||||
bool cryptFile(const PIString & path, const PIByteArray & secret);
|
||||
|
||||
#endif // SHARED_H
|
||||
|
||||
Reference in New Issue
Block a user