From 22ba6516b5872e84913a7bd86b7337597d521841 Mon Sep 17 00:00:00 2001 From: "ZUNMX\\36083" Date: Wed, 10 Apr 2024 15:55:11 +0800 Subject: [PATCH] first version --- Hasher.pro | 29 ++++ Hasher.pro.user | 267 ++++++++++++++++++++++++++++++ calculator.cpp | 172 ++++++++++++++++++++ calculator.h | 22 +++ comp_window.cpp | 140 ++++++++++++++++ comp_window.h | 31 ++++ comp_window.ui | 178 ++++++++++++++++++++ main.cpp | 13 ++ mainwindow.cpp | 420 ++++++++++++++++++++++++++++++++++++++++++++++++ mainwindow.h | 50 ++++++ mainwindow.ui | 246 ++++++++++++++++++++++++++++ readme.md | 21 +++ 12 files changed, 1589 insertions(+) create mode 100644 Hasher.pro create mode 100644 Hasher.pro.user create mode 100644 calculator.cpp create mode 100644 calculator.h create mode 100644 comp_window.cpp create mode 100644 comp_window.h create mode 100644 comp_window.ui create mode 100644 main.cpp create mode 100644 mainwindow.cpp create mode 100644 mainwindow.h create mode 100644 mainwindow.ui create mode 100644 readme.md diff --git a/Hasher.pro b/Hasher.pro new file mode 100644 index 0000000..18cdc3d --- /dev/null +++ b/Hasher.pro @@ -0,0 +1,29 @@ +QT += core gui concurrent + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +CONFIG += c++17 + +# You can make your code fail to compile if it uses deprecated APIs. +# In order to do so, uncomment the following line. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + +SOURCES += \ + calculator.cpp \ + comp_window.cpp \ + main.cpp \ + mainwindow.cpp + +HEADERS += \ + calculator.h \ + comp_window.h \ + mainwindow.h + +FORMS += \ + comp_window.ui \ + mainwindow.ui + +# Default rules for deployment. +qnx: target.path = /tmp/$${TARGET}/bin +else: unix:!android: target.path = /opt/$${TARGET}/bin +!isEmpty(target.path): INSTALLS += target diff --git a/Hasher.pro.user b/Hasher.pro.user new file mode 100644 index 0000000..982acf1 --- /dev/null +++ b/Hasher.pro.user @@ -0,0 +1,267 @@ + + + + + + EnvironmentId + {ee5feb50-f37c-4025-be75-74dc258ebaed} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + 0 + false + true + false + 0 + true + true + 0 + 8 + true + false + 1 + true + true + true + *.md, *.MD, Makefile + false + true + true + + + + ProjectExplorer.Project.PluginSettings + + + true + false + true + true + true + true + + + 0 + true + + true + true + Builtin.DefaultTidyAndClazy + 8 + true + + + + true + + + + + ProjectExplorer.Project.Target.0 + + Desktop + Desktop Qt 6.6.1 MinGW 64-bit + Desktop Qt 6.6.1 MinGW 64-bit + qt.qt6.661.win64_mingw_kit + 0 + 0 + 0 + + 0 + F:\StudyCode\qt\build-Hasher-Desktop_Qt_6_6_1_MinGW_64_bit-Debug + F:/StudyCode/qt/build-Hasher-Desktop_Qt_6_6_1_MinGW_64_bit-Debug + + + true + QtProjectManager.QMakeBuildStep + false + + + + true + Qt4ProjectManager.MakeStep + + 2 + 构建 + 构建 + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + clean + + 1 + 清除 + 清除 + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Debug + Qt4ProjectManager.Qt4BuildConfiguration + 2 + + + F:\StudyCode\qt\build-Hasher-Desktop_Qt_6_6_1_MinGW_64_bit-Release + F:/StudyCode/qt/build-Hasher-Desktop_Qt_6_6_1_MinGW_64_bit-Release + + + true + QtProjectManager.QMakeBuildStep + false + + + + true + Qt4ProjectManager.MakeStep + + 2 + 构建 + 构建 + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + clean + + 1 + 清除 + 清除 + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Release + Qt4ProjectManager.Qt4BuildConfiguration + 0 + 0 + + + 0 + F:\StudyCode\qt\build-Hasher-Desktop_Qt_6_6_1_MinGW_64_bit-Profile + F:/StudyCode/qt/build-Hasher-Desktop_Qt_6_6_1_MinGW_64_bit-Profile + + + true + QtProjectManager.QMakeBuildStep + false + + + + true + Qt4ProjectManager.MakeStep + + 2 + 构建 + 构建 + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + clean + + 1 + 清除 + 清除 + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Profile + Qt4ProjectManager.Qt4BuildConfiguration + 0 + 0 + 0 + + 3 + + + 0 + 部署 + 部署 + ProjectExplorer.BuildSteps.Deploy + + 1 + + false + ProjectExplorer.DefaultDeployConfiguration + + 1 + + true + true + 0 + true + + 2 + + false + + Qt4ProjectManager.Qt4RunConfiguration:F:/StudyCode/qt/Hasher/Hasher.pro + F:/StudyCode/qt/Hasher/Hasher.pro + false + true + true + true + F:/StudyCode/qt/build-Hasher-Desktop_Qt_6_6_1_MinGW_64_bit-Debug + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 22 + + + Version + 22 + + diff --git a/calculator.cpp b/calculator.cpp new file mode 100644 index 0000000..ee0992a --- /dev/null +++ b/calculator.cpp @@ -0,0 +1,172 @@ +#include "calculator.h" +int calc_number = 7; +std::map> process; + + +QString GetCRC32(QString fileName,int col) +{//多项式公式:x32 + x26 + x23 + x22 + x16 + x12 + x11 + x10 + x8 + x7 + x5 + x4 + x2 + x + 1 宽度:32 多项式:04C11DB7 初始值:FFFFFFFF 结果异或值:FFFFFFFF 输入反转:true 输出反转:true + static const quint32 crc32Table[] = + { + 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, + 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, + 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2, + 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, + 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, + 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, + 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c, + 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, + 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, + 0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, + 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106, + 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, + 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, + 0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, + 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, + 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, + 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, + 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, + 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, + 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, + 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, + 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, + 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84, + 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, + 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, + 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, + 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e, + 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, + 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, + 0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, + 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28, + 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, + 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, + 0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, + 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, + 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, + 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, + 0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, + 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, + 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, + 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, + 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, + 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d + }; + QFile file(fileName); + QByteArray array; + if(file.open(QFile::ReadOnly)){ + array = file.readAll(); + } + quint32 crc32 = 0xFFFFFFFF; + for ( auto i = 0; i < array.size(); ++i ) + { + process[QString("%1%2").arg(fileName).arg(col)]["crc32"] = 1.0 * i / array.size(); + crc32 = crc32Table[ ( crc32 ^ array.constData()[ i ]) & 0xff ] ^ ( crc32 >> 8 ); + } + process[QString("%1%2").arg(fileName).arg(col)]["crc32"] = 1; + crc32 ^=0xFFFFFFFF; + file.close(); + return QString::number(crc32,16); +} +QString GetMD4(QString fileName,int col){ + QFile file(fileName); + if (!file.open(QIODevice::ReadOnly)) { + qWarning("Cannot open file for reading"); + return QByteArray(); + } + + QCryptographicHash hash(QCryptographicHash::Md4); + int i = 0; + while (!file.atEnd()) { + process[QString("%1%2").arg(fileName).arg(col)]["md4"] = (1.0 * i++ * pre_size) / file.size(); + hash.addData(file.read(pre_size)); // 每次读取1MB + } + process[QString("%1%2").arg(fileName).arg(col)]["md4"]=1; + file.close(); + return hash.result().toHex(); +} +QString GetMD5(QString fileName,int col){ + QFile file(fileName); + if (!file.open(QIODevice::ReadOnly)) { + qWarning("Cannot open file for reading"); + return QByteArray(); + } + + QCryptographicHash hash(QCryptographicHash::Md5); + int i = 0; + while (!file.atEnd()) { + process[QString("%1%2").arg(fileName).arg(col)]["md5"] = (1.0 * i++ * pre_size) / file.size(); + hash.addData(file.read(pre_size)); // 每次读取1MB + } + process[QString("%1%2").arg(fileName).arg(col)]["md5"]=1; + file.close(); + return hash.result().toHex(); +} +QString GetSHA1(QString fileName,int col){ + QFile file(fileName); + if (!file.open(QIODevice::ReadOnly)) { + qWarning("Cannot open file for reading"); + return QByteArray(); + } + + QCryptographicHash hash(QCryptographicHash::Sha1); + int i = 0; + while (!file.atEnd()) { + process[QString("%1%2").arg(fileName).arg(col)]["sha1"] = (1.0 * i++ * pre_size) / file.size(); + hash.addData(file.read(pre_size)); // 每次读取1MB + } + process[QString("%1%2").arg(fileName).arg(col)]["sha1"]=1; + file.close(); + return hash.result().toHex(); +} +QString GetSHA256(QString fileName,int col){ + QFile file(fileName); + if (!file.open(QIODevice::ReadOnly)) { + qWarning("Cannot open file for reading"); + return QByteArray(); + } + + QCryptographicHash hash(QCryptographicHash::Sha256); + int i = 0; + while (!file.atEnd()) { + process[QString("%1%2").arg(fileName).arg(col)]["sha256"] = (1.0 * i++ * pre_size) / file.size(); + hash.addData(file.read(pre_size)); // 每次读取1MB + } + process[QString("%1%2").arg(fileName).arg(col)]["sha256"]=1; + file.close(); + return hash.result().toHex(); +} +QString GetSHA384(QString fileName,int col){ + QFile file(fileName); + if (!file.open(QIODevice::ReadOnly)) { + qWarning("Cannot open file for reading"); + return QByteArray(); + } + + QCryptographicHash hash(QCryptographicHash::Sha384); + int i = 0; + while (!file.atEnd()) { + process[QString("%1%2").arg(fileName).arg(col)]["sha384"] = (1.0 * i++ * pre_size) / file.size(); + hash.addData(file.read(pre_size)); // 每次读取1MB + } + process[QString("%1%2").arg(fileName).arg(col)]["sha384"]=1; + file.close(); + return hash.result().toHex(); +} +QString GetSHA512(QString fileName,int col){ + + QFile file(fileName); + if (!file.open(QIODevice::ReadOnly)) { + qWarning("Cannot open file for reading"); + return QByteArray(); + } + + QCryptographicHash hash(QCryptographicHash::Sha512); + int i = 0; + while (!file.atEnd()) { + process[QString("%1%2").arg(fileName).arg(col)]["sha512"] = (1.0 * i++ * pre_size) / file.size(); + hash.addData(file.read(pre_size)); // 每次读取1MB + } + process[QString("%1%2").arg(fileName).arg(col)]["sha512"]=1; + file.close(); + return hash.result().toHex(); +} diff --git a/calculator.h b/calculator.h new file mode 100644 index 0000000..19de1cb --- /dev/null +++ b/calculator.h @@ -0,0 +1,22 @@ +#include +#include +#include +#include + +#ifndef CALCULATOR_H +#define CALCULATOR_H + +extern int calc_number; +extern std::map> process; + +const unsigned int pre_size = 1024*1024; +QString GetCRC32(QString fileName,int col); +QString GetMD4(QString fileName,int col); +QString GetMD5 ( QString fileName ,int col); +QString GetSHA1(QString fileName,int col); +QString GetSHA256(QString fileName,int col); +QString GetSHA384(QString fileName,int col); +QString GetSHA512(QString fileName,int col); + +#endif // CALCULATOR_H + diff --git a/comp_window.cpp b/comp_window.cpp new file mode 100644 index 0000000..21a4b88 --- /dev/null +++ b/comp_window.cpp @@ -0,0 +1,140 @@ +#include "comp_window.h" +#include "ui_comp_window.h" +#include "QClipboard" + +int comp_style = false; + +comp_window::comp_window(QWidget *parent) + : QDialog(parent) + , ui(new Ui::comp_window) +{ + ui->setupUi(this); + QClipboard *clipboard = QGuiApplication::clipboard(); + QString originalText = clipboard->text().trimmed(); + ui->lineEdit_need_comp->setText(originalText); + ui->lineEdit_need_comp->setFocus(); +} + +comp_window::~comp_window() +{ + comp_style = false; + delete ui; +} +void comp_window::draw_comp_result(){ + QString need = ui->lineEdit_need_comp->text(); + QString CRC32 = ui->lineEdit_CRC32->text(); + QString MD4 = ui->lineEdit_MD4->text(); + QString MD5 = ui->lineEdit_MD5->text(); + QString SHA1 = ui->lineEdit_SHA1->text(); + QString SHA256 = ui->lineEdit_SHA256->text(); + QString SHA384 = ui->lineEdit_SHA384->text(); + QString SHA512 = ui->lineEdit_SHA512->text(); + if(need == CRC32){ + ui->lineEdit_CRC32->setGraphicsEffect(gen_style(1)); + }else{ + ui->lineEdit_CRC32->setGraphicsEffect(gen_style(2)); + } + + if(need == MD4){ + ui->lineEdit_MD4->setGraphicsEffect(gen_style(1)); + }else{ + ui->lineEdit_MD4->setGraphicsEffect(gen_style(2)); + } + + if(need == MD5){ + ui->lineEdit_MD5->setGraphicsEffect(gen_style(1)); + }else{ + ui->lineEdit_MD5->setGraphicsEffect(gen_style(2)); + } + + if(need == SHA1){ + ui->lineEdit_SHA1->setGraphicsEffect(gen_style(1)); + }else{ + ui->lineEdit_SHA1->setGraphicsEffect(gen_style(2)); + } + + if(need == SHA256){ + ui->lineEdit_SHA256->setGraphicsEffect(gen_style(1)); + }else{ + ui->lineEdit_SHA256->setGraphicsEffect(gen_style(2)); + } + + if(need == SHA384){ + ui->lineEdit_SHA384->setGraphicsEffect(gen_style(1)); + }else{ + + ui->lineEdit_SHA384->setGraphicsEffect(gen_style(2)); + } + + if(need == SHA512){ + ui->lineEdit_SHA512->setGraphicsEffect(gen_style(1)); + }else{ + + ui->lineEdit_SHA512->setGraphicsEffect(gen_style(2)); + } +} + + +QGraphicsDropShadowEffect * comp_window::gen_style(int style){ + QGraphicsDropShadowEffect * effect = new QGraphicsDropShadowEffect(this); + + effect->setOffset(0, 0); + effect->setBlurRadius(10); + if(style==1){ + effect->setColor(Qt::green); + } + if(style==2){ + effect->setColor(Qt::red); + } + return effect; +} +void comp_window::set_hash_info(const QString &str, const QString &type) +{ + + this->setWindowTitle(str); + if(type=="type" && str == "查看"){ + ui->label->hide(); + ui->lineEdit_need_comp->hide(); + ui->lineEdit_CRC32->setGraphicsEffect(gen_style(0)); + ui->lineEdit_MD5->setGraphicsEffect(gen_style(0)); + ui->lineEdit_MD4->setGraphicsEffect(gen_style(0)); + ui->lineEdit_SHA1->setGraphicsEffect(gen_style(0)); + ui->lineEdit_SHA256->setGraphicsEffect(gen_style(0)); + ui->lineEdit_SHA384->setGraphicsEffect(gen_style(0)); + ui->lineEdit_SHA512->setGraphicsEffect(gen_style(0)); + } + if(type=="file_name") + ui->lineEdit_file_name->setText(str); + if(type=="file_size") + ui->lineEdit_file_size->setText(str); + if(type=="file_path") + ui->lineEdit_file_path->setText(str); + if(type=="CRC32") + ui->lineEdit_CRC32->setText(str); + if(type=="MD4") + ui->lineEdit_MD4->setText(str); + if(type=="MD5") + ui->lineEdit_MD5->setText(str); + if(type=="SHA1") + ui->lineEdit_SHA1->setText(str); + if(type=="SHA256") + ui->lineEdit_SHA256->setText(str); + if(type=="SHA384") + ui->lineEdit_SHA384->setText(str); + if(type=="SHA512") + ui->lineEdit_SHA512->setText(str); + + if(type=="type" && str=="对比"){ + comp_style = true; + draw_comp_result(); + } + +} + +void comp_window::on_lineEdit_need_comp_textChanged(const QString &arg1) +{ + if(comp_style) + draw_comp_result(); + +} + diff --git a/comp_window.h b/comp_window.h new file mode 100644 index 0000000..07b0a47 --- /dev/null +++ b/comp_window.h @@ -0,0 +1,31 @@ +#ifndef COMP_WINDOW_H +#define COMP_WINDOW_H + +#include "QGraphicsDropShadowEffect" +#include + +namespace Ui { +class comp_window; +} + +class comp_window : public QDialog +{ + Q_OBJECT + +public: + explicit comp_window(QWidget *parent = nullptr); + void draw_comp_result(); + ~comp_window(); +public slots: + + void set_hash_info(const QString &str, const QString &type); +private slots: + void on_lineEdit_need_comp_textChanged(const QString &arg1); + + +private: + Ui::comp_window *ui; + QGraphicsDropShadowEffect * gen_style(int style); +}; + +#endif // COMP_WINDOW_H diff --git a/comp_window.ui b/comp_window.ui new file mode 100644 index 0000000..9d08dc9 --- /dev/null +++ b/comp_window.ui @@ -0,0 +1,178 @@ + + + comp_window + + + + 0 + 0 + 561 + 333 + + + + Dialog + + + true + + + + + + + + true + + + + + + + 文件名称 + + + + + + + true + + + + + + + true + + + + + + + SHA1 + + + + + + + SHA512 + + + + + + + SHA384 + + + + + + + true + + + + + + + + + + true + + + + + + + MD5 + + + + + + + SHA256 + + + + + + + 文件大小 + + + + + + + true + + + + + + + true + + + + + + + MD4 + + + + + + + true + + + + + + + CRC32 + + + + + + + 哈希对比: + + + + + + + 文件路径 + + + + + + + true + + + + + + + true + + + + + + + + + + diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..58d6de8 --- /dev/null +++ b/main.cpp @@ -0,0 +1,13 @@ +#include "mainwindow.h" + +#include +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + a.setStyle(QStyleFactory::create("fusion")); + MainWindow w; + w.show(); + return a.exec(); +} diff --git a/mainwindow.cpp b/mainwindow.cpp new file mode 100644 index 0000000..0683fa3 --- /dev/null +++ b/mainwindow.cpp @@ -0,0 +1,420 @@ +#include "mainwindow.h" +#include "ui_mainwindow.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +QString global_status = "空闲"; + +QString get_file_size_string(double file_size) { + const char* units[] = {"B", "KB", "MB", "GB", "TB", "PB"}; + double size = static_cast(file_size); + long long unsigned int i = 0; + while (size >= 1024 && i < (sizeof(units) / sizeof(units[0]) - 1)) { + size /= 1024; + ++i; + } + return QString("%1 %2").arg(size).arg(units[i]); +} + + + +void MainWindow::resizeEvent(QResizeEvent *event) +{ + adjustColumnSize(); +} + +double getProcess(){ + auto cursor = process.begin(); + int total = 0; + double process_percent = 0; + while(cursor!=process.end()){ + total++; + double single = (cursor->second["crc32"]+ + cursor->second["md4"]+ + cursor->second["md5"]+ + cursor->second["sha1"]+ + cursor->second["sha256"]+ + cursor->second["sha384"]+ + cursor->second["sha512"])*1.0 / (calc_number) * 100; + process_percent += single; + cursor ++; + } + return process_percent / total; +} +MainWindow::MainWindow(QWidget *parent) : + QMainWindow(parent), + ui(new Ui::MainWindow) +{ + ui->setupUi(this); + this->setAcceptDrops(true); + QLabel * status = new QLabel(); + ui->statusbar->insertWidget(0,status); + QLabel * calc_process = new QLabel(); + ui->statusbar->insertWidget(1,calc_process); + QTimer * kernel = new QTimer(); + kernel->start(500); + connect(kernel,&QTimer::timeout,[=](){ + double p = getProcess(); + if(int(p)==100){ + global_status = "已完成"; + process.clear(); + } + status->setText("状态: " + global_status); + + if(global_status == "已完成" || global_status == "空闲" ){ + + calc_process->setText("队列进度: 100%" ); + }else{ + + calc_process->setText("队列进度: " + QString("%1%").arg(p)); + } + }); +} + + +MainWindow::~MainWindow() +{ + delete ui; +} + +void MainWindow::dragEnterEvent(QDragEnterEvent *e) +{ + e->acceptProposedAction(); +} + + +auto MainWindow::gen_obj(QString text){ + auto obj = new QLineEdit(); + obj->setText(text); + obj->setReadOnly(true); + obj->setStyleSheet("QLineEdit{border:0px solid gray;}QLineEdit:focus {border-width:2px;border-color:rgb(170, 170, 255);background:rgba(69, 63, 45, 255);}"); + + + // QGraphicsDropShadowEffect *shadow_effect = new QGraphicsDropShadowEffect(this); + // shadow_effect->setOffset(0, 0); + // shadow_effect->setColor(Qt::red); + // shadow_effect->setBlurRadius(20); + // obj->setGraphicsEffect(shadow_effect); + + return obj; +} +void MainWindow::open_comp_window(int type, int curr_row){ + auto cursor = process.begin(); + while(cursor!=process.end()){ + if(cursor->first == QString("%1%2").arg(ui->tableWidget->item(curr_row,4)->text()).arg(curr_row)){ + double single = (cursor->second["crc32"]+ + cursor->second["md4"]+ + cursor->second["md5"]+ + cursor->second["sha1"]+ + cursor->second["sha256"]+ + cursor->second["sha384"]+ + cursor->second["sha512"])* 1.0 / (calc_number) * 100; + if(single != 100){ + QMessageBox::warning(this,"稍等片刻","数据尚未计算完毕,请稍后再试"); + return; + } + } + cursor++; + } + + comp_window *comp_win = new comp_window(); + connect(this, &MainWindow::send_hash_info,comp_win, &comp_window::set_hash_info); + emit send_hash_info(ui->tableWidget->item(curr_row,2)->text(), "file_name"); + emit send_hash_info(ui->tableWidget->item(curr_row,3)->text(), "file_size"); + emit send_hash_info(ui->tableWidget->item(curr_row,4)->text(), "file_path"); + emit send_hash_info(ui->tableWidget->item(curr_row,5)->text(), "CRC32"); + emit send_hash_info(ui->tableWidget->item(curr_row,6)->text(), "MD4"); + emit send_hash_info(ui->tableWidget->item(curr_row,7)->text(), "MD5"); + emit send_hash_info(ui->tableWidget->item(curr_row,8)->text(), "SHA1"); + emit send_hash_info(ui->tableWidget->item(curr_row,9)->text(), "SHA256"); + emit send_hash_info(ui->tableWidget->item(curr_row,10)->text(), "SHA384"); + emit send_hash_info(ui->tableWidget->item(curr_row,11)->text(), "SHA512"); + if(type==1){ + emit send_hash_info("对比", "type"); + } + else if (type == 2){ + emit send_hash_info("查看", "type"); + } + comp_win->show(); + +} +void MainWindow::Calculate(QString path){ + global_status = "正在计算"; + QFileInfo fileInfo(path); + int rowCount = ui->tableWidget->rowCount(); + ui->tableWidget->insertRow(rowCount); + QHBoxLayout *layout = new QHBoxLayout(); + auto * show_btn = new QPushButton(); + show_btn->setText("查看" ); + auto * comp_btn = new QPushButton(); + comp_btn->setText("比较"); + layout->insertWidget(0, comp_btn); + layout->insertWidget(0, show_btn); + + connect(comp_btn, &QPushButton::clicked,this, [&]() { + QObject * obj = sender()->parent(); + QTableWidgetItem * item = (QTableWidgetItem *)obj; + QWidget * widget = (QWidget *)item; + int x = widget->frameGeometry().x(); + int y = widget->frameGeometry().y(); + QModelIndex modelIndex = ui->tableWidget->indexAt(QPoint(x, y)); + int curr_row = modelIndex.row(); + int column = modelIndex.column(); + open_comp_window(1,curr_row); + + }); + + connect(show_btn, &QPushButton::clicked,this, [&]() { + QObject * obj = sender()->parent(); + QTableWidgetItem * item = (QTableWidgetItem *)obj; + QWidget * widget = (QWidget *)item; + int x = widget->frameGeometry().x(); + int y = widget->frameGeometry().y(); + QModelIndex modelIndex = ui->tableWidget->indexAt(QPoint(x, y)); + int curr_row = modelIndex.row(); + int column = modelIndex.column(); + open_comp_window(2,curr_row); + }); + + + layout->setContentsMargins(0,0,0,0); + QWidget *widget = new QWidget(); + widget->setLayout(layout); + ui->tableWidget->setItem(rowCount, 0, new QTableWidgetItem("")); + ui->tableWidget->setCellWidget(rowCount, 0,widget ); + + + ui->tableWidget->setItem(rowCount, 1, new QTableWidgetItem(QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss"))); + ui->tableWidget->setCellWidget(rowCount, 1, gen_obj(QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss"))); + ui->tableWidget->setItem(rowCount, 2, new QTableWidgetItem(fileInfo.fileName())); + ui->tableWidget->setCellWidget(rowCount, 2, gen_obj(fileInfo.fileName())); + ui->tableWidget->setItem(rowCount, 3, new QTableWidgetItem(get_file_size_string(fileInfo.size()))); + ui->tableWidget->setCellWidget(rowCount, 3, gen_obj(get_file_size_string(fileInfo.size()))); + ui->tableWidget->setItem(rowCount, 4, new QTableWidgetItem(fileInfo.filePath())); + ui->tableWidget->setCellWidget(rowCount, 4, gen_obj(fileInfo.filePath())); + adjustColumnSize(); + if(ui->checkBox_CRC32->isChecked()){ + + QFuture future = QtConcurrent::run(GetCRC32, path,rowCount); + QFutureWatcher *m_watcher = new QFutureWatcher(this); + m_watcher = new QFutureWatcher(this); + m_watcher->setFuture(future); + connect(m_watcher, &QFutureWatcher::finished, this, [=](){ + auto item = new QTableWidgetItem(future.result()); + this->ui->tableWidget->setItem(rowCount, 5, item); + ui->tableWidget->setCellWidget(rowCount, 5, gen_obj(future.result())); + adjustColumnSize(); + }); + }else{ + + process[QString("%1%2").arg(path).arg(rowCount)]["crc32"] = 1; + this->ui->tableWidget->setItem(rowCount, 5, new QTableWidgetItem("---")); + ui->tableWidget->setCellWidget(rowCount, 5, gen_obj("---")); + } + if(ui->checkBox_MD4->isChecked()){ + QFuture future = QtConcurrent::run(GetMD4, path,rowCount); + QFutureWatcher *m_watcher = new QFutureWatcher(this); + m_watcher = new QFutureWatcher(this); + m_watcher->setFuture(future); + connect(m_watcher, &QFutureWatcher::finished, this, [=](){ + this->ui->tableWidget->setItem(rowCount, 6, new QTableWidgetItem(future.result())); + ui->tableWidget->setCellWidget(rowCount, 6, gen_obj(future.result())); + adjustColumnSize(); + }); + }else{ + process[QString("%1%2").arg(path).arg(rowCount)]["md4"] = 1; + this->ui->tableWidget->setItem(rowCount, 6, new QTableWidgetItem("---")); + ui->tableWidget->setCellWidget(rowCount, 6, gen_obj("---")); + } + if(ui->checkBox_MD5->isChecked()){ + QFuture future = QtConcurrent::run(GetMD5, path,rowCount); + QFutureWatcher *m_watcher = new QFutureWatcher(this); + m_watcher = new QFutureWatcher(this); + m_watcher->setFuture(future); + connect(m_watcher, &QFutureWatcher::finished, this, [=](){ + this->ui->tableWidget->setItem(rowCount, 7, new QTableWidgetItem(future.result())); + ui->tableWidget->setCellWidget(rowCount, 7, gen_obj(future.result())); + adjustColumnSize(); + }); + }else{ + + process[QString("%1%2").arg(path).arg(rowCount)]["md5"] = 1; + this->ui->tableWidget->setItem(rowCount, 7, new QTableWidgetItem("---")); + ui->tableWidget->setCellWidget(rowCount, 7, gen_obj("---")); + } + if(ui->checkBox_SHA1->isChecked()){ + QFuture future = QtConcurrent::run(GetSHA1, path,rowCount); + QFutureWatcher *m_watcher = new QFutureWatcher(this); + m_watcher = new QFutureWatcher(this); + m_watcher->setFuture(future); + connect(m_watcher, &QFutureWatcher::finished, this, [=](){ + this->ui->tableWidget->setItem(rowCount, 8, new QTableWidgetItem(future.result())); + ui->tableWidget->setCellWidget(rowCount, 8, gen_obj(future.result())); + adjustColumnSize(); + }); + }else{ + process[QString("%1%2").arg(path).arg(rowCount)]["sha1"] = 1; + this->ui->tableWidget->setItem(rowCount, 8, new QTableWidgetItem("---")); + ui->tableWidget->setCellWidget(rowCount, 8, gen_obj("---")); + } + if(ui->checkBox_SHA256->isChecked()){ + QFuture future = QtConcurrent::run(GetSHA256, path,rowCount); + QFutureWatcher *m_watcher = new QFutureWatcher(this); + m_watcher = new QFutureWatcher(this); + m_watcher->setFuture(future); + connect(m_watcher, &QFutureWatcher::finished, this, [=](){ + this->ui->tableWidget->setItem(rowCount, 9, new QTableWidgetItem(future.result())); + ui->tableWidget->setCellWidget(rowCount, 9, gen_obj(future.result())); + adjustColumnSize(); + }); + }else{ + process[QString("%1%2").arg(path).arg(rowCount)]["sha256"] = 1; + this->ui->tableWidget->setItem(rowCount, 9, new QTableWidgetItem("---")); + ui->tableWidget->setCellWidget(rowCount, 9, gen_obj("---")); + } + if(ui->checkBox_SHA384->isChecked()){ + QFuture future = QtConcurrent::run(GetSHA384, path,rowCount); + QFutureWatcher *m_watcher = new QFutureWatcher(this); + m_watcher = new QFutureWatcher(this); + m_watcher->setFuture(future); + connect(m_watcher, &QFutureWatcher::finished, this, [=](){ + this->ui->tableWidget->setItem(rowCount, 10, new QTableWidgetItem(future.result())); + ui->tableWidget->setCellWidget(rowCount, 10, gen_obj(future.result())); + adjustColumnSize(); + }); + }else{ + process[QString("%1%2").arg(path).arg(rowCount)]["sha384"] = 1; + this->ui->tableWidget->setItem(rowCount, 10, new QTableWidgetItem("---")); + ui->tableWidget->setCellWidget(rowCount, 10, gen_obj("---")); + } + + + if(ui->checkBox_SHA512->isChecked()){ + QFuture future = QtConcurrent::run(GetSHA512, path, rowCount); + QFutureWatcher *m_watcher = new QFutureWatcher(this); + m_watcher = new QFutureWatcher(this); + m_watcher->setFuture(future); + connect(m_watcher, &QFutureWatcher::finished, this, [=](){ + this->ui->tableWidget->setItem(rowCount, 11, new QTableWidgetItem(future.result())); + ui->tableWidget->setCellWidget(rowCount, 11, gen_obj(future.result())); + adjustColumnSize(); + }); + }else{ + process[QString("%1%2").arg(path).arg(rowCount)]["sha512"] = 1; + this->ui->tableWidget->setItem(rowCount, 11, new QTableWidgetItem("---")); + ui->tableWidget->setCellWidget(rowCount, 11, gen_obj("---")); + } + + + +} +void MainWindow::dropEvent(QDropEvent *e) +{ + QList urls = e->mimeData()->urls(); + if(urls.isEmpty()) + return ; + foreach (QUrl u, urls) + { + QString filepath = u.toLocalFile(); + pathlist.append(filepath); + } + for(int i=0;itableWidget->setSelectionMode(QAbstractItemView::SingleSelection); + ui->tableWidget->horizontalHeader()->setStretchLastSection(true); +} +void MainWindow::columnSwitcher(int id, int flag){ + if(flag==2) ui->tableWidget->showColumn(id+4); + else ui->tableWidget->hideColumn(id+4); +} + +void MainWindow::on_checkBox_SHA512_stateChanged(int arg1) +{ + columnSwitcher(7,arg1); +} + + +void MainWindow::on_checkBox_SHA384_stateChanged(int arg1) +{ + columnSwitcher(6,arg1); +} + + +void MainWindow::on_checkBox_SHA256_stateChanged(int arg1) +{ + columnSwitcher(5,arg1); +} + + +void MainWindow::on_checkBox_SHA1_stateChanged(int arg1) +{ + columnSwitcher(4,arg1); +} + + +void MainWindow::on_checkBox_MD5_stateChanged(int arg1) +{ + columnSwitcher(3,arg1); +} + + +void MainWindow::on_checkBox_MD4_stateChanged(int arg1) +{ + columnSwitcher(2,arg1); +} + + +void MainWindow::on_checkBox_CRC32_stateChanged(int arg1) +{ + columnSwitcher(1,arg1); +} + + +void MainWindow::on_checkBox_calc_time_stateChanged(int arg1) +{ + columnSwitcher(-3,arg1); +} + + +void MainWindow::on_checkBox_file_name_stateChanged(int arg1) +{ + columnSwitcher(-2,arg1); +} + + +void MainWindow::on_checkBox_file_size_stateChanged(int arg1) +{ + columnSwitcher(-1,arg1); +} + + +void MainWindow::on_checkBox_file_path_stateChanged(int arg1) +{ + columnSwitcher(0,arg1); +} + + diff --git a/mainwindow.h b/mainwindow.h new file mode 100644 index 0000000..4ae76eb --- /dev/null +++ b/mainwindow.h @@ -0,0 +1,50 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include +#include + +namespace Ui { +class MainWindow; +} + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + explicit MainWindow(QWidget *parent = 0); + void Calculate(QString path); + auto gen_obj(QString text); + ~MainWindow(); + +protected: + void dragEnterEvent(QDragEnterEvent *e); + void dropEvent(QDropEvent *e); + void columnSwitcher(int id, int flag); + +private slots: + + void on_checkBox_SHA384_stateChanged(int arg1); + void on_checkBox_SHA512_stateChanged(int arg1); + void on_checkBox_SHA256_stateChanged(int arg1); + void on_checkBox_SHA1_stateChanged(int arg1); + void on_checkBox_MD5_stateChanged(int arg1); + void on_checkBox_MD4_stateChanged(int arg1); + void on_checkBox_CRC32_stateChanged(int arg1); + void on_checkBox_calc_time_stateChanged(int arg1); + void on_checkBox_file_name_stateChanged(int arg1); + void on_checkBox_file_size_stateChanged(int arg1); + void on_checkBox_file_path_stateChanged(int arg1); +signals: + void send_hash_info(const QString &str, const QString &type); + +private: + Ui::MainWindow *ui; + QList pathlist; + void adjustColumnSize(); + virtual void resizeEvent(QResizeEvent* event) override; + void open_comp_window(int type,int curr_row); +}; + +#endif // MAINWINDOW_H diff --git a/mainwindow.ui b/mainwindow.ui new file mode 100644 index 0000000..a41a18e --- /dev/null +++ b/mainwindow.ui @@ -0,0 +1,246 @@ + + + MainWindow + + + + 0 + 0 + 1120 + 523 + + + + Hasher + + + + + + + + 操作 + + + + + 计算时间 + + + + + 文件名 + + + + + 文件大小 + + + + + 文件路径 + + + + + CRC32 + + + + + MD4 + + + + + MD5 + + + + + SHA1 + + + + + SHA256 + + + + + SHA384 + + + + + SHA512 + + + + + + + + 0 + + + + + 表头显示: + + + + + + + 计算时间 + + + true + + + + + + + 文件名 + + + true + + + + + + + 文件大小 + + + true + + + + + + + 文件路径 + + + true + + + + + + + Qt::Vertical + + + + + + + 计算: + + + + + + + CRC32 + + + true + + + + + + + MD4 + + + true + + + + + + + MD5 + + + true + + + + + + + SHA1 + + + true + + + + + + + SHA256 + + + true + + + + + + + SHA384 + + + true + + + + + + + SHA512 + + + true + + + + + + + + + 移动文件至窗口内,进行哈希计算 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..af4615b --- /dev/null +++ b/readme.md @@ -0,0 +1,21 @@ +# + +QTĹϣ + +# 㷨 + +- CRC32 + +- MD4 + +- MD5 + +- SHA1 + +- SHA256 + +- SHA384 + +- SHA512 + +[![pFOqrqA.png](https://s21.ax1x.com/2024/04/10/pFOqrqA.png)](https://imgse.com/i/pFOqrqA) \ No newline at end of file