git-svn-id: svn://db.shs.com.ru/pip@236 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5

This commit is contained in:
2016-08-23 13:24:12 +00:00
parent 7b227f15ac
commit fb25f8dbfe
16 changed files with 136 additions and 57 deletions

View File

@@ -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;
}