Commit 94b03658 authored by Ingemar Ceicer's avatar Ingemar Ceicer

v2.5.0 Are there duplicates?

parent 028c3e79
......@@ -50,11 +50,8 @@ void Hash::findDuplicates()
dialog->setOption(QFileDialog::DontUseNativeDialog, false);
dialog->setFileMode(QFileDialog::DirectoryOnly);
// dialog->setOption(QFileDialog::ShowDirsOnly);
dialog->setOption(QFileDialog::DontResolveSymlinks);
// dialog->setOption(QFileDialog::DontUseNativeDialog, true);
dialog->setReadOnly(true);
// dialog->setViewMode(QFileDialog::Detail);
QString directoryName;
if(dialog->exec()) {
......@@ -231,7 +228,7 @@ void Hash::collectDuplicates(QVector<PathHash> &v_ph, const QString &directoryNa
ui2->textBrowser->append(tr("Created: ") + datumtid());
ui2->textBrowser->append(tr("Recursively from ") + directoryNamne + "\n");
/* */
QColor c(218, 255, 221);
QColor c(RED, GREEN, BLUE);
QPalette p = ui2->textBrowser->palette(); // define pallete for textEdit..
p.setColor(QPalette::Base, c); // set color "Red" for textedit base
ui2->textBrowser->setPalette(p); // change textedit palette
......
......@@ -42,6 +42,10 @@ Hash::Hash(QWidget *parent) :
connect(ui->actionFindIdenticalFiles, &QAction::triggered, [this]() {
findDuplicates();
});
/* IS THERE A DUOLICATE */
connect(ui->actionIsThereADuplicate, &QAction::triggered, [this]() {
isThereADuplicate();
});
// Save
connect(ui->actionSaveToFile, SIGNAL(triggered()), this, SLOT(saveOne()));
// Recent Files, undermeny
......@@ -148,7 +152,7 @@ void Hash::openFile()
ui2->setupUi(d);
ui2->textBrowser->setFixedWidth(800);
/* COLOR */
QColor c(218, 255, 221);
QColor c(RED, GREEN, BLUE);
QPalette p = ui2->textBrowser->palette(); // define pallete for textEdit..
p.setColor(QPalette::Base, c); // set color "Red" for textedit base
ui2->textBrowser->setPalette(p); // change textedit palette
......@@ -243,7 +247,7 @@ void Hash::openHashSumList()
ui2->textBrowser->setFont(default_font);
// End Font
/* COLOR */
QColor c(218, 255, 221);
QColor c(RED, GREEN, BLUE);
QPalette p = ui2->textBrowser->palette(); // define pallete for textEdit..
p.setColor(QPalette::Base, c); // set color "Red" for textedit base
ui2->textBrowser->setPalette(p); // change textedit palette
......@@ -279,7 +283,7 @@ void Hash::openHashSumList()
ui2->textBrowser->setFont(default_font);
// End Font
/* COLOR */
QColor c(218, 255, 221);
QColor c(RED, GREEN, BLUE);
QPalette p = ui2->textBrowser->palette(); // define pallete for textEdit..
p.setColor(QPalette::Base, c); // set color "Red" for textedit base
ui2->textBrowser->setPalette(p); // change textedit palette
......@@ -377,7 +381,7 @@ void Hash::openComparisonList()
ui2->textBrowser->setFont(default_font);
// End Font
/* COLOR */
QColor c(218, 255, 221);
QColor c(RED, GREEN, BLUE);
QPalette p = ui2->textBrowser->palette(); // define pallete for textEdit..
p.setColor(QPalette::Base, c); // set color "Red" for textedit base
ui2->textBrowser->setPalette(p); // change textedit palette
......@@ -416,7 +420,7 @@ void Hash::openComparisonList()
ui2->textBrowser->setFont(default_font);
// End Font
/* COLOR */
QColor c(218, 255, 221);
QColor c(RED, GREEN, BLUE);
QPalette p = ui2->textBrowser->palette(); // define pallete for textEdit..
p.setColor(QPalette::Base, c); // set color "Red" for textedit base
ui2->textBrowser->setPalette(p); // change textedit palette
......@@ -954,7 +958,7 @@ void Hash::license()
ui2->textBrowser->setPlainText(content);
d->setWindowFlags(Qt::WindowSystemMenuHint);
/* COLOR */
QColor c(218, 255, 221);
QColor c(RED, GREEN, BLUE);
QPalette p = ui2->textBrowser->palette(); // define pallete for textEdit..
p.setColor(QPalette::Base, c); // set color "Red" for textedit base
ui2->textBrowser->setPalette(p); // change textedit palette
......@@ -1001,7 +1005,7 @@ void Hash::versionhistory()
ui2->setupUi(d);
ui2->textBrowser->setPlainText(content);
/* COLOR */
QColor c(218, 255, 221);
QColor c(RED, GREEN, BLUE);
QPalette p = ui2->textBrowser->palette(); // define pallete for textEdit..
p.setColor(QPalette::Base, c); // set color "Red" for textedit base
ui2->textBrowser->setPalette(p); // change textedit palette
......@@ -1691,7 +1695,7 @@ void Hash::checksum()
ui2->textBrowser->setFont(default_font);
// End Font
/* COLOR */
QColor c(218, 255, 221);
QColor c(RED, GREEN, BLUE);
QPalette p = ui2->textBrowser->palette(); // define pallete for textEdit..
p.setColor(QPalette::Base, c); // set color "Red" for textedit base
ui2->textBrowser->setPalette(p); // change textedit palette
......@@ -3719,7 +3723,7 @@ void Hash::dropEvent(QDropEvent *ev)
ui2->textBrowser->setFont(default_font);
// End Font
/* COLOR */
QColor c(218, 255, 221);
QColor c(RED, GREEN, BLUE);
QPalette p = ui2->textBrowser->palette(); // define pallete for textEdit..
p.setColor(QPalette::Base, c); // set color "Red" for textedit base
ui2->textBrowser->setPalette(p); // change textedit palette
......@@ -3755,7 +3759,7 @@ void Hash::save()
std::string usenativedialogs = k->getConf("usenativedialogs");
QString textBrowserText = ui2->textBrowser->toPlainText();
/* COLOR */
QColor c(218, 255, 221);
QColor c(RED, GREEN, BLUE);
QPalette p = ui2->textBrowser->palette(); // define pallete for textEdit..
p.setColor(QPalette::Base, c); // set color "Red" for textedit base
ui2->textBrowser->setPalette(p); // change textedit palette
......
......@@ -38,7 +38,7 @@
#define VERSION_PATH "http://bin.ceicer.com/hash/version.txt"
#define APPLICATION_NAME "hashSum"
#define EXECUTABLE_NAME "hashsum"
#define VERSION "2.4.1"
#define VERSION "2.5.0"
#define BUILD_DATE_TIME __DATE__ " " __TIME__
#define CURRENT_YEAR "2020"
#define LICENCE_VERSION "3"
......@@ -52,6 +52,9 @@
#define QLINEEDIT_MAX 32767
#define SIZE_OF_RECENT_FILES 50
#define RED 218
#define GREEN 255
#define BLUE 221
......@@ -69,6 +72,7 @@ class Hash : public QMainWindow
{
Q_OBJECT
public:
explicit Hash(QWidget *parent = nullptr);
~Hash();
......@@ -86,6 +90,7 @@ private:
Config *k{};
QDialog *d{};
void setStartConfig();
void setEndConfig();
bool doChecksum(const QString &);
......@@ -126,7 +131,10 @@ private:
void collectDuplicates(QVector<PathHash> &v_ph, const QString &directoryNamne);
bool rekursivt2(const QDir &, QVector<PathHash> &v_ph, const QString &alg, const QString &qopen_path);
static bool compareAlphabet(const Hash::PathHash & a, const Hash::PathHash & b);
/* IS THERE A DUOLICATE */
void isThereADuplicate();
bool rekursivt3(const QDir &qsokvag, const QString &alg, const QString &qopen_path, const QString &hashsumma, const QString &jfrFile, QStringList &likadana);
bool printDuplicates(const QStringList &likadana, const QString &jfrFile, const QString &directoryName);
private slots:
void checkForUpdates();
......
......@@ -31,7 +31,7 @@ CONFIG += c++14
# GCC
TEMPLATE = app
TARGET = hashsum-2.4.1
TARGET = hashsum-2.5.0
#DEPENDPATH += .
#INCLUDEPATH += .
......@@ -62,7 +62,8 @@ TARGET = hashsum-2.4.1
HEADERS += checkforupdates.h config.h createuser.h hash.h extqlineedit.h
FORMS += hash.ui license.ui
SOURCES += checkforupdates.cpp config.cpp createuser.cpp hash.cpp main.cpp extqlineedit.cpp \
duplicates.cpp
duplicates.cpp \
isthereaduplicate.cpp
RC_FILE = myapp.rc
#CODECFORSRC = UTF-8
#TRANSLATIONS += hashSum_sv_SE.ts hashSum_el_GR.ts hashSum_de_DE.ts hashSum_xx_XX.ts
......
......@@ -85,6 +85,7 @@
<addaction name="actionCompare"/>
<addaction name="actionCompareGivenHashSum"/>
<addaction name="actionFindIdenticalFiles"/>
<addaction name="actionIsThereADuplicate"/>
<addaction name="actionCreateChecksumList"/>
<addaction name="actionOpenHashSumList"/>
<addaction name="actionOpenComparisonList"/>
......@@ -616,6 +617,11 @@
<string>Find identical files</string>
</property>
</action>
<action name="actionIsThereADuplicate">
<property name="text">
<string>Are there duplicates?</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/*
hashSum
Copyright (C) 2011-2020 Ingemar Ceicer
http://ceicer.org/
programmering1 (at) ceicer (dot) org
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
#include "hash.h"
#include "ui_hash.h"
#include "ui_license.h"
void Hash::isThereADuplicate()
{
QString conf_file_name = QDir::toNativeSeparators("/" APPLICATION_NAME ".conf");
k = new Config(conf_file_name);
QString sokvag;
std::string open_path = k->getConf("open_path");
std::string allwaysopenhomedirectory = k->getConf("allwaysopenhomedirectory");
std::string dialogruta = k->getConf("usenativedialogs");
std::string algorithm = k->getConf("algorithm");
QString qsalgorithm = QString::fromStdString(algorithm);
QString qs = QString::fromStdString(open_path);
QFileInfo info(qs);
if(info.isReadable() && allwaysopenhomedirectory == "0")
sokvag = qs;
else
sokvag = QDir::homePath();
QFileDialog *dialog = new QFileDialog(this, tr("Open the file you want to find duplicates for"),
sokvag,
tr("All Files (*)"));
if(dialogruta == "0")
dialog->setOption(QFileDialog::DontUseNativeDialog, true);
else if(dialogruta == "1")
dialog->setOption(QFileDialog::DontUseNativeDialog, false);
dialog->setAcceptMode(QFileDialog::AcceptOpen);
dialog->setFileMode(QFileDialog::ExistingFile);
QStringList fileNames;
QString fileName;
QString directoryName;
if(dialog->exec()) {
ui->actionCopyPath->setDisabled(true);
ui->actionSaveToFile->setDisabled(true);
ui->actionCopyHashSum->setDisabled(true);
ui->progressLabel->clear();
//ui->progressLabel->toolTip().clear();
ui->lineEdit->clear();
fileName = dialog->selectedFiles().at(0);
QDir dir;
dir = dialog->directory();
directoryName = dir.path();
k->setConf("open_path", directoryName.toStdString());
fileNames = dialog->selectedFiles();
} else {
delete k;
return;
}
delete k;
bool lyckades = doChecksum(fileName);
if(!lyckades) {
QMessageBox::critical(this, APPLICATION_NAME " " VERSION, tr("No hash sum could be calculated"));
return;
}
QString hashsumma = ui->lineEdit->text();
/* OPEN RECURSIVE */
hurmangaFoldrar = 0;
if(info.isReadable() && allwaysopenhomedirectory == "0")
sokvag = qs + QDir::toNativeSeparators("/");
else
sokvag = QDir::homePath();
QFileDialog *dialog2 = new QFileDialog(this, tr("Select a folder to Find identical files"),
sokvag,
tr("All Files (*.*)"));
if(dialogruta == "0")
dialog2->setOption(QFileDialog::DontUseNativeDialog, true);
else if(dialogruta == "1")
dialog2->setOption(QFileDialog::DontUseNativeDialog, false);
dialog2->setFileMode(QFileDialog::DirectoryOnly);
dialog2->setOption(QFileDialog::DontResolveSymlinks);
dialog2->setReadOnly(true);
QString qsokvag = "";
if(dialog2->exec()) {
ui->progressLabel->clear();
// ui->progressLabel->toolTip().clear();
ui->lineEdit->clear();
QDir dir = dialog2->directory();
qsokvag = dir.path();
} else {
return;
}
/* SLUT RECURSIVE */
// QString qopen_path = QString::fromStdString(open_path);
QStringList likadana;
bool lyckats = rekursivt3(qsokvag, qsalgorithm, qsokvag, hashsumma, fileNames.at(0), likadana);
if(!lyckats)
QMessageBox::critical(this, APPLICATION_NAME " " VERSION, tr("Could not check the hash sum. Check your file permissions."));
printDuplicates(likadana, fileNames.at(0), qsokvag);
}
bool Hash::rekursivt3(const QDir &qsokvag, const QString &alg, const QString &qopen_path, const QString &hashsumma, const QString &jfrFile, QStringList &likadana)
{
QString nyHashsumma;
QFileInfoList list = qsokvag.entryInfoList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot);
foreach(QFileInfo finfo, list) {
if(finfo.isDir()) {
rekursivt3(QDir(finfo.absoluteFilePath()), alg, qopen_path, hashsumma, jfrFile, likadana);
hurmangaFoldrar++;
} else {
nyHashsumma = checksum2(finfo.absoluteFilePath(), alg);
if((nyHashsumma == hashsumma) && (finfo.absoluteFilePath() != jfrFile)) {
likadana.append(finfo.absoluteFilePath());
}
hurmangaFiler++;
}
}
QString tmp = "";
QApplication::processEvents();
if(hurmangaFoldrar < 2)
ui->progressLabel->setText(tr("I have been looking into ") + tmp.setNum(hurmangaFoldrar + 1) + tr(" folder for files. I have managed to calculate the hash sum in all folders containing files.\n") + tr("(Algorithm: ") + alg + ") ...");
else
ui->progressLabel->setText(tr("I have been looking into ") + tmp.setNum(hurmangaFoldrar + 1) + tr(" folders for files. I have managed to calculate the hash sum in all folders containing files.\n") + tr("(Algorithm: ") + alg + ") ...");
ui->statusBar->showMessage(tr("Path: ") + QDir::toNativeSeparators(qsokvag.path()));
if(QDir::toNativeSeparators(qsokvag.path()) == QDir::toNativeSeparators(qopen_path)) {
if(hurmangaFoldrar < 2)
ui->progressLabel->setText(tr("I have been looking into ") + tmp.setNum(hurmangaFoldrar + 1) + tr(" folder for files. I have managed to calculate the hash sum in all folders containing files.\n") + tr("(Algorithm: ") + alg + ")");
else
ui->progressLabel->setText(tr("I have been looking into ") + tmp.setNum(hurmangaFoldrar + 1) + tr(" folders for files. I have managed to calculate the hash sum in all folders containing files.\n") + tr("(Algorithm: ") + alg + ")");
ui->statusBar->showMessage(tr("I have checked all folders and checked all hash sums! Mission accomplished."));
QString s;
s.setNum(hurmangaFiler);
ui->lineEdit->setText(tr("Mission accomplished! I have calculated the hash sum of ") + s + tr(" files."));
hurmangaFiler = 0;
}
return true;
}
bool Hash::printDuplicates(const QStringList &likadana, const QString &jfrFile, const QString &directoryName)
{
/**** ****/
d = new QDialog;
ui2 = new Ui::Lic;
ui2->setupUi(d);
// Font
QString fontPath = ":/fonts/fonts/UbuntuMono-R.ttf";
int id = QFontDatabase::addApplicationFont(fontPath);
QString family = QFontDatabase::applicationFontFamilies(id).at(0);
QFont default_font(family);
default_font.setPointSize(12);
ui2->textBrowser->setFont(default_font);
// End Font
ui2->pbOpenFile->setText(tr("Save"));
/* */
QColor c(RED, GREEN, BLUE);
QPalette p = ui2->textBrowser->palette(); // define pallete for textEdit..
p.setColor(QPalette::Base, c); // set color "Red" for textedit base
ui2->textBrowser->setPalette(p); // change textedit palette
/* */
/***** *******/
ui2->textBrowser->append(tr("Created: ") + datumtid());
ui2->textBrowser->append(tr("Identical files with ") + "\"" + jfrFile + "\"");
ui2->textBrowser->append(tr("Recursively searched from ") + "\"" + directoryName + "\"");
foreach(QString s, likadana) {
ui2->textBrowser->append(s);
}
ui2->textBrowser->append(tr("I found ") + QString::number(likadana.count()) + tr(" duplicates."));
/***** *****/
d->setWindowModality(Qt::ApplicationModal);
d->setWindowFlags(d->windowFlags() | Qt::WindowMinMaxButtonsHint);
d->setWindowTitle(APPLICATION_NAME " " VERSION " " + tr("Duplicate files"));
QIcon ikon("/images/hashsum.ico");
d->setWindowIcon(ikon);
connect(ui2->pbClose, SIGNAL(clicked()), this, SLOT(stang()));
connect(ui2->pbOpenFile, SIGNAL(pressed()), this, SLOT(save()));
QTextCursor cursor = ui2->textBrowser->textCursor();
cursor.setPosition(0);
ui2->textBrowser->setTextCursor(cursor);
d->show();
/***** *****/
return true;
}
......@@ -48,7 +48,6 @@ int main(int argc, char *argv[])
// QString sprak = QString::fromStdString(s);
QString sprak = QString::fromStdString(s);
const QString translationPath = ":/i18n/hashSum";
// qDebug() << translationPath + "_" + sprak;
if(s == "nothing") {
QString locale = QLocale::system().name();
......@@ -64,12 +63,9 @@ int main(int argc, char *argv[])
k->setConf("language", "en_US");
}
} else {
//qDebug() << translationPath + "_" + sprak + ".qm";
// if(translator.load(INSTALL_DIR + APPLICATION_NAME + "_" + sprak))
if(translator.load(translationPath + "_" + sprak + ".qm")) {
// if(translator.load(":/i18n/hashSum_sv_SE.qm")) {
// qDebug() << "Laddar";
a.installTranslator(&translator);
}
}
......
......@@ -81,6 +81,7 @@ public:
QAction *actionKeccak_384;
QAction *actionKeccak_512;
QAction *actionFindIdenticalFiles;
QAction *actionIsThereADuplicate;
QWidget *centralWidget;
QHBoxLayout *horizontalLayout;
QVBoxLayout *verticalLayout;
......@@ -285,6 +286,8 @@ public:
actionKeccak_512->setCheckable(true);
actionFindIdenticalFiles = new QAction(Hash);
actionFindIdenticalFiles->setObjectName(QString::fromUtf8("actionFindIdenticalFiles"));
actionIsThereADuplicate = new QAction(Hash);
actionIsThereADuplicate->setObjectName(QString::fromUtf8("actionIsThereADuplicate"));
centralWidget = new QWidget(Hash);
centralWidget->setObjectName(QString::fromUtf8("centralWidget"));
horizontalLayout = new QHBoxLayout(centralWidget);
......@@ -354,6 +357,7 @@ public:
menuFile->addAction(actionCompare);
menuFile->addAction(actionCompareGivenHashSum);
menuFile->addAction(actionFindIdenticalFiles);
menuFile->addAction(actionIsThereADuplicate);
menuFile->addAction(actionCreateChecksumList);
menuFile->addAction(actionOpenHashSumList);
menuFile->addAction(actionOpenComparisonList);
......@@ -487,6 +491,7 @@ public:
actionKeccak_384->setText(QCoreApplication::translate("Hash", "Keccak_384", nullptr));
actionKeccak_512->setText(QCoreApplication::translate("Hash", "Keccak_512", nullptr));
actionFindIdenticalFiles->setText(QCoreApplication::translate("Hash", "Find identical files", nullptr));
actionIsThereADuplicate->setText(QCoreApplication::translate("Hash", "Are there duplicates?", nullptr));
progressLabel->setText(QString());
menuFile->setTitle(QCoreApplication::translate("Hash", "&File", nullptr));
menuRecentFiles->setTitle(QCoreApplication::translate("Hash", "Recent Files", nullptr));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment