Commit 854cc8cc authored by Ingemar Ceicer's avatar Ingemar Ceicer

Remove duplicates

parent f9e70770
/*
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"
#include "extqlineedit.h"
void Hash::findDuplicates()
{
ui->actionCopyPath->setDisabled(true);
ui->actionSaveToFile->setDisabled(true);
ui->actionCopyHashSum->setDisabled(true);
hurmangaFoldrar = 0;
QString conf_file_name = QDir::toNativeSeparators("/" APPLICATION_NAME ".conf");
k = new Config(conf_file_name);
QString sokvag;
std::string s = k->getConf("open_path");
std::string allwaysopenhomedirectory = k->getConf("allwaysopenhomedirectory");
std::string dialogruta = k->getConf("usenativedialogs");
QString qs = QString::fromStdString(s);
QFileInfo info(qs);
if(info.isReadable() && allwaysopenhomedirectory == "0")
sokvag = qs + QDir::toNativeSeparators("/*");
else
sokvag = QDir::homePath();
QFileDialog *dialog = new QFileDialog(this, tr("Select a folder to Find identical files"),
sokvag,
tr("All Files (*)"));
if(dialogruta == "0")
dialog->setOption(QFileDialog::DontUseNativeDialog, true);
else if(dialogruta == "1")
dialog->setOption(QFileDialog::DontUseNativeDialog, false);
dialog->setFileMode(QFileDialog::Directory);
dialog->setOption(QFileDialog::ShowDirsOnly);
dialog->setReadOnly(true);
QString directoryName;
if(dialog->exec()) {
ui->progressLabel->clear();
ui->progressLabel->toolTip().clear();
ui->lineEdit->clear();
QDir dir = dialog->directory();
directoryName = dir.path();
k->setConf("open_path", directoryName.toStdString());
delete k;
} else {
delete k;
return;
}
QString tmp = "";
bool lyckats = rekursivt2(directoryName, tmp);
if(lyckats == false)
QMessageBox::critical(this, APPLICATION_NAME " " VERSION, tr("Could not check the hash sum. Check your file permissions."));
}
bool Hash::rekursivt2(QDir path, QString indent)
{
QString conf_file_name = QDir::toNativeSeparators("/" APPLICATION_NAME ".conf");
k = new Config(conf_file_name);
std::string fil = k->getConf("defaultfilename");
QString defaultfn = QString::fromStdString(fil);
std::string algoritm = k->getConf("algorithm");
QString alg = QString::fromStdString(algoritm);
std::string writedatetime = k->getConf("writeDateTimeHashSumFile");
std::string open_path = k->getConf("open_path");
QString qopen_path = QString::fromStdString(open_path);
delete k;
indent += "\t";
bool lyckades;
QFileInfoList list = path.entryInfoList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot);
foreach(QFileInfo finfo, list) {
if(finfo.isDir()) {
rekursivt2(QDir(finfo.absoluteFilePath()), indent);
hurmangaFoldrar++;
} else {
// ipac remove rekursivtPrint
lyckades = rekursivtPrint(defaultfn, alg, path, writedatetime);
if(lyckades == false)
return false;
}
}
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(path.path()));
if(QDir::toNativeSeparators(path.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 created all the files! 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;
}
......@@ -38,6 +38,10 @@ Hash::Hash(QWidget *parent) :
connect(ui->actionOpenHashSumList, SIGNAL(triggered()), this, SLOT(openHashSumList()));
connect(ui->actionOpenComparisonList, SIGNAL(triggered()), this, SLOT(openComparisonList()));
connect(ui->actionCreateChecksumLists, SIGNAL(triggered()), this, SLOT(checkSumLists())); //Rekursivt
/* DUPLICATES */
connect(ui->actionFindIdenticalFiles, &QAction::triggered, [this]() {
findDuplicates();
});
// Save
connect(ui->actionSaveToFile, SIGNAL(triggered()), this, SLOT(saveOne()));
// Recent Files, undermeny
......
......@@ -98,6 +98,7 @@ private:
bool dontAskForFileName(std::string, QStringList);
QString datumtid();
bool rekursivt(QDir, QString);
bool rekursivt2(QDir, QString);
bool rekursivtPrint(QString, QString, QDir, std::string);
int hurmangaFoldrar;
void checkSumList(int);
......@@ -114,6 +115,9 @@ private:
QStringList algoritmer;
QStringList *lista;
/* DUPLICATES */
void findDuplicates();
private slots:
void checkForUpdates();
......@@ -179,6 +183,8 @@ private slots:
void saveOne();
public slots:
......
......@@ -61,7 +61,8 @@ TARGET = hashsum-2.3.3
# Input
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
SOURCES += checkforupdates.cpp config.cpp createuser.cpp hash.cpp main.cpp extqlineedit.cpp \
duplicates.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
......
......@@ -69,7 +69,7 @@
<x>0</x>
<y>0</y>
<width>913</width>
<height>21</height>
<height>28</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
......@@ -84,6 +84,7 @@
<addaction name="actionChecksum"/>
<addaction name="actionCompare"/>
<addaction name="actionCompareGivenHashSum"/>
<addaction name="actionFindIdenticalFiles"/>
<addaction name="actionCreateChecksumList"/>
<addaction name="actionOpenHashSumList"/>
<addaction name="actionOpenComparisonList"/>
......@@ -610,6 +611,11 @@
<string>Keccak_512</string>
</property>
</action>
<action name="actionFindIdenticalFiles">
<property name="text">
<string>Find identical files</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
......
......@@ -80,6 +80,7 @@ public:
QAction *actionKeccak_256;
QAction *actionKeccak_384;
QAction *actionKeccak_512;
QAction *actionFindIdenticalFiles;
QWidget *centralWidget;
QHBoxLayout *horizontalLayout;
QVBoxLayout *verticalLayout;
......@@ -282,6 +283,8 @@ public:
actionKeccak_512 = new QAction(Hash);
actionKeccak_512->setObjectName(QString::fromUtf8("actionKeccak_512"));
actionKeccak_512->setCheckable(true);
actionFindIdenticalFiles = new QAction(Hash);
actionFindIdenticalFiles->setObjectName(QString::fromUtf8("actionFindIdenticalFiles"));
centralWidget = new QWidget(Hash);
centralWidget->setObjectName(QString::fromUtf8("centralWidget"));
horizontalLayout = new QHBoxLayout(centralWidget);
......@@ -317,7 +320,7 @@ public:
Hash->setCentralWidget(centralWidget);
menuBar = new QMenuBar(Hash);
menuBar->setObjectName(QString::fromUtf8("menuBar"));
menuBar->setGeometry(QRect(0, 0, 913, 21));
menuBar->setGeometry(QRect(0, 0, 913, 28));
menuFile = new QMenu(menuBar);
menuFile->setObjectName(QString::fromUtf8("menuFile"));
menuRecentFiles = new QMenu(menuFile);
......@@ -350,6 +353,7 @@ public:
menuFile->addAction(actionChecksum);
menuFile->addAction(actionCompare);
menuFile->addAction(actionCompareGivenHashSum);
menuFile->addAction(actionFindIdenticalFiles);
menuFile->addAction(actionCreateChecksumList);
menuFile->addAction(actionOpenHashSumList);
menuFile->addAction(actionOpenComparisonList);
......@@ -482,6 +486,7 @@ public:
actionKeccak_256->setText(QCoreApplication::translate("Hash", "Keccak_256", nullptr));
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));
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