1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
|
#include "ObjectConsole.h"
#include "ThreadCalcHash.h"
#include <QCoreApplication>
#include <QDebug>
#include <iostream>
ObjectConsole::ObjectConsole(QObject *parent, int gostSupport) : QObject(parent),_gostSupport(gostSupport){
current_progress=0;
}
void ObjectConsole::calcHash(QStringList listPositionalArguments,bool showProgress,bool showlistOption,QString compareHash){
if (showlistOption){
std::cout << "CRC-8, CRC-32, MD4, MD5, SHA-1, SHA-224, SHA-256, SHA-384, SHA-512";
if (_gostSupport){
std::cout << ", md_gost94, md_gost12_256, md_gost12_512";
}
std::cout << std::endl;
exit(0);
}
if (listPositionalArguments.size()!=2){
qCritical("%s",qUtf8Printable(tr("Invalid positional arguments")));
exit(0);
}
QString filename = listPositionalArguments.at(0);
QString hashAlgorithm = listPositionalArguments.at(1);
HASH_ALGORITHM hash = HASH_ALGORITHM::Crc8;
_showProgress=showProgress;
_compareHash=compareHash;
if (hashAlgorithm=="CRC-8"){
hash=HASH_ALGORITHM::Crc8;
}else if (hashAlgorithm=="CRC-32"){
hash=HASH_ALGORITHM::Crc32;
}else if (hashAlgorithm=="MD4"){
hash=HASH_ALGORITHM::Md4;
}else if (hashAlgorithm=="MD5"){
hash=HASH_ALGORITHM::Md5;
}else if (hashAlgorithm=="SHA-1"){
hash=HASH_ALGORITHM::Sha1;
}else if (hashAlgorithm=="SHA-224"){
hash=HASH_ALGORITHM::Sha224;
}else if (hashAlgorithm=="SHA-256"){
hash=HASH_ALGORITHM::Sha256;
}else if (hashAlgorithm=="SHA-384"){
hash=HASH_ALGORITHM::Sha384;
}else if (hashAlgorithm=="SHA-512"){
hash=HASH_ALGORITHM::Sha512;
}else if (_gostSupport && hashAlgorithm=="md_gost94"){
hash=HASH_ALGORITHM::md_gost94;
}else if (_gostSupport && hashAlgorithm=="md_gost12_256"){
hash=HASH_ALGORITHM::md_gost12_256;
}else if (_gostSupport && hashAlgorithm=="md_gost12_512"){
hash=HASH_ALGORITHM::md_gost12_512;
}else{
qCritical("%s",qUtf8Printable(tr("Invalid hash argument")));
exit(0);
}
qInfo(qUtf8Printable(tr("Filename: %s")),qUtf8Printable(filename));
ThreadCalcHash *thCaclHash = new ThreadCalcHash();
thCaclHash->setFilename(filename);
thCaclHash->setHashAlgorithm(hash);
if (showProgress){
connect(thCaclHash,SIGNAL(changeValue(int)),this,SLOT(calcHashChangeValue(int)));
}
connect(thCaclHash,SIGNAL(result(QString)),this,SLOT(calcHashResult(QString)));
thCaclHash->start();
}
void ObjectConsole::calcHashChangeValue(int value){
int proc = value/10;
std::cout << "\033[0G";
std::cout << "Calc: [";
for (int i=0;i<proc;i++) std::cout << "#" ;
for (int i=0;i<10-proc;i++) std::cout << " " ;
std::cout << "] " << value << "% " << std::flush;
}
void ObjectConsole::calcHashResult(QString hash){
if (_showProgress) std::cout << std::endl;
qInfo(qUtf8Printable(tr("Result: %s")),qUtf8Printable(hash));
if (_compareHash!=""){
if (hash.toUpper()==_compareHash){
qInfo(qUtf8Printable(tr("Check: %s")),qUtf8Printable(tr("equally")));
}else{
qInfo(qUtf8Printable(tr("Check: %s")),qUtf8Printable(tr("different")));
}
}
exit(0);
}
|