hash.h 5.33 KB
Newer Older
Ingemar Ceicer's avatar
Ingemar Ceicer committed
1 2
/*
    hashSum
Ingemar Ceicer's avatar
Ingemar Ceicer committed
3
    Copyright (C) 2011-2020 Ingemar Ceicer
Ingemar Ceicer's avatar
Ingemar Ceicer committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
    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.
*/

#ifndef HASH_H
#define HASH_H

#include <string>
#include <sstream>
#include <fstream>
Ingemar Ceicer's avatar
Ingemar Ceicer committed
24
#include <algorithm>
Ingemar Ceicer's avatar
Ingemar Ceicer committed
25 26 27 28 29 30 31
#include "checkforupdates.h"
#include "config.h"
#include "extqlineedit.h"
#include <QSysInfo>
#include <QtWidgets>
#include <QTextCodec>

Ingemar Ceicer's avatar
Ingemar Ceicer committed
32 33 34 35 36
/* draganddrop */
#include <QDropEvent>
#include <QUrl>
#include <QDebug>

Ingemar Ceicer's avatar
Ingemar Ceicer committed
37 38


Ingemar Ceicer's avatar
Ingemar Ceicer committed
39
#define VERSION_PATH "http://bin.ceicer.com/hash/version2.txt"
Ingemar Ceicer's avatar
Ingemar Ceicer committed
40 41
#define APPLICATION_NAME "hashSum"
#define EXECUTABLE_NAME "hashsum"
Ingemar Ceicer's avatar
Ingemar Ceicer committed
42
#define VERSION "2.5.1"
Ingemar Ceicer's avatar
Ingemar Ceicer committed
43
#define BUILD_DATE_TIME __DATE__ " " __TIME__
Ingemar Ceicer's avatar
Ingemar Ceicer committed
44
#define CURRENT_YEAR "2020"
Ingemar Ceicer's avatar
Ingemar Ceicer committed
45 46 47 48 49 50
#define LICENCE_VERSION "3"
#define PROGRAMMER_EMAIL "[email protected]"
#define PROGRAMMER_NAME "Ingemar Ceicer"
#define PROGRAMMER_PHONE "+46706361747"
#define APPLICATION_HOMEPAGE "http://ceicer.org/hash/index.php"
#define APPLICATION_HOMEPAGE_ENG "http://ceicer.org/hash/index_eng.php"
Ingemar Ceicer's avatar
Ingemar Ceicer committed
51
#define DOWNLOAD_PATH "https://gitlab.com/posktomten/hashsum/-/wikis/DOWNLOADS"
Ingemar Ceicer's avatar
Ingemar Ceicer committed
52 53 54 55 56
#define elGR_TRANSLATOR "www.geogeo.gr"
#define deDE_TRANSLATOR "Benjamin Weis"

#define QLINEEDIT_MAX 32767
#define SIZE_OF_RECENT_FILES 50
Ingemar Ceicer's avatar
Ingemar Ceicer committed
57 58 59
#define RED 218
#define GREEN 255
#define BLUE 221
Ingemar Ceicer's avatar
Ingemar Ceicer committed
60

Ingemar Ceicer's avatar
BUGG  
Ingemar Ceicer committed
61 62
#define LINUX_FONT 13
#define WINDOWS_FONT 10
Ingemar Ceicer's avatar
Ingemar Ceicer committed
63 64 65



Ingemar Ceicer's avatar
Ingemar Ceicer committed
66 67
namespace Ui
{
68
class Hash;
Ingemar Ceicer's avatar
Ingemar Ceicer committed
69
}
Ingemar Ceicer's avatar
Ingemar Ceicer committed
70 71
namespace Ui
{
72
class Lic;
Ingemar Ceicer's avatar
Ingemar Ceicer committed
73 74
}

Ingemar Ceicer's avatar
Ingemar Ceicer committed
75 76
class Hash : public QMainWindow
{
Ingemar Ceicer's avatar
Ingemar Ceicer committed
77 78
    Q_OBJECT

Ingemar Ceicer's avatar
Ingemar Ceicer committed
79

Ingemar Ceicer's avatar
Ingemar Ceicer committed
80
public:
Ingemar Ceicer's avatar
Ingemar Ceicer committed
81
    explicit Hash(QWidget *parent = nullptr);
Ingemar Ceicer's avatar
Ingemar Ceicer committed
82 83 84 85
    ~Hash();


protected:
Ingemar Ceicer's avatar
Ingemar Ceicer committed
86 87 88
    /* draganddrop */
    void dropEvent(QDropEvent *ev);
    void dragEnterEvent(QDragEnterEvent *ev);
Ingemar Ceicer's avatar
Ingemar Ceicer committed
89 90 91


private:
Ingemar Ceicer's avatar
Ingemar Ceicer committed
92 93 94 95
    Ui::Hash *ui{};
    Ui::Lic *ui2{};
    Config  *k{};
    QDialog *d{};
Ingemar Ceicer's avatar
Ingemar Ceicer committed
96

Ingemar Ceicer's avatar
Ingemar Ceicer committed
97

Ingemar Ceicer's avatar
Ingemar Ceicer committed
98

Ingemar Ceicer's avatar
Ingemar Ceicer committed
99 100
    void setStartConfig();
    void setEndConfig();
Ingemar Ceicer's avatar
Ingemar Ceicer committed
101 102 103 104 105 106 107 108
    bool doChecksum(const QString &);
    bool doChecksum(const QString &, QStringList *lista);
    bool doChecksumText(const QString &);
    bool doChecksumList(const QString &, QString &, const string &);
    bool doCompare(const QString &, const QString &);
    bool askForFileName(const QString &, const string &, QStringList);
    bool askForFileNameCheck(const QString &, const string &, QStringList);
    bool dontAskForFileName(const string &, QStringList);
Ingemar Ceicer's avatar
Ingemar Ceicer committed
109
    QString datumtid();
Ingemar Ceicer's avatar
Ingemar Ceicer committed
110
    bool rekursivt(const QDir &, QString);
Ingemar Ceicer's avatar
Ingemar Ceicer committed
111

Ingemar Ceicer's avatar
Ingemar Ceicer committed
112
    bool rekursivtPrint(const QString &, const QString &, QDir, const string &);
Ingemar Ceicer's avatar
Ingemar Ceicer committed
113
    int hurmangaFoldrar{};
Ingemar Ceicer's avatar
Ingemar Ceicer committed
114
    void checkSumList(int);
Ingemar Ceicer's avatar
Ingemar Ceicer committed
115 116
    int hurmangaFiler{};
    bool createDeb(const QString &sokvag2, QStringList fileNames);
Ingemar Ceicer's avatar
Ingemar Ceicer committed
117
    QString getSystem();
Ingemar Ceicer's avatar
Ingemar Ceicer committed
118
    bool rekursivtDeb(const QDir &path, QString &indent, QStringList &allt);
Ingemar Ceicer's avatar
Ingemar Ceicer committed
119
    bool rekursivtPrintDeb(QDir path, QStringList &allt);
Ingemar Ceicer's avatar
Ingemar Ceicer committed
120 121 122

    bool recentFileList(QString);
    QStringList recentFiles;
Ingemar Ceicer's avatar
Ingemar Ceicer committed
123
    int MAX_RECENT_FILES{};
124

Ingemar Ceicer's avatar
Ingemar Ceicer committed
125
    QStringList algoritmer;
Ingemar Ceicer's avatar
Ingemar Ceicer committed
126
    QStringList *lista{};
Ingemar Ceicer's avatar
Ingemar Ceicer committed
127

Ingemar Ceicer's avatar
Ingemar Ceicer committed
128 129
    /* DUPLICATES */
    void findDuplicates();
Ingemar Ceicer's avatar
Ingemar Ceicer committed
130
    QString checksum2(const QString &in, const QString &s);
Ingemar Ceicer's avatar
Ingemar Ceicer committed
131 132 133
    struct PathHash {
        QString path;
        QString hash;
Ingemar Ceicer's avatar
Ingemar Ceicer committed
134

Ingemar Ceicer's avatar
Ingemar Ceicer committed
135
    };
Ingemar Ceicer's avatar
Ingemar Ceicer committed
136 137
    void collectDuplicates(QVector<PathHash> &v_ph, const QString &directoryNamne);
    bool rekursivt2(const QDir &, QVector<PathHash> &v_ph, const QString &alg, const QString &qopen_path);
Ingemar Ceicer's avatar
Ingemar Ceicer committed
138
    static bool compareAlphabet(const Hash::PathHash & a, const Hash::PathHash & b);
Ingemar Ceicer's avatar
Ingemar Ceicer committed
139 140 141 142
    /* 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);
Ingemar Ceicer's avatar
Ingemar Ceicer committed
143 144 145 146 147 148 149 150 151

private slots:
    void about();
    void checkOnStart();
    void saveChecksumListWhereFilesAre();
    void md4();
    void md5();
    void sha1();

152 153 154 155 156 157 158 159
    void sha224();
    void sha256();
    void sha384();
    void sha512();
    void sha3_224();
    void sha3_256();
    void sha3_384();
    void sha3_512();
Ingemar Ceicer's avatar
Ingemar Ceicer committed
160

161 162 163 164 165
    void keccak_224();
    void keccak_256();
    void keccak_384();
    void keccak_512();

Ingemar Ceicer's avatar
Ingemar Ceicer committed
166 167 168

    void compare();
    void checksum();
169

Ingemar Ceicer's avatar
Ingemar Ceicer committed
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
    void swedish();
    void english();
    void german();
    void greek();
    void checkSumListInit();
    void checkSumLists();
    void compareGivenHashSum();
    void defaultFileName();
    void writeTimeDateInHashSumFile();
    void findChangedFiles();
    void useNativeDialogs();
    void allwaysOpenHomeDirectory();
    void copyPath();
    void copyHashSum();
    void hashSumText();
    void compareHashSumText();
    void help();
    void license();
    void versionhistory();
    void createDebianMd5sums();
    void createDebianMd5sumsAuto();
    void showFullPathInHashSumFile();

    void slotRecentFiles();
Ingemar Ceicer's avatar
Ingemar Ceicer committed
194
    void recentFileRequested(const QString &path);
Ingemar Ceicer's avatar
Ingemar Ceicer committed
195 196 197 198 199 200 201 202
    void setRecentFiles();
    void clearRecentFiles();
    void stang();

    void openHashSumList();
    void openComparisonList();
    void openFile();

Ingemar Ceicer's avatar
Ingemar Ceicer committed
203
    void save();
204
    void saveOne();
Ingemar Ceicer's avatar
Ingemar Ceicer committed
205

Ingemar Ceicer's avatar
Ingemar Ceicer committed
206

Ingemar Ceicer's avatar
Ingemar Ceicer committed
207 208


Ingemar Ceicer's avatar
Ingemar Ceicer committed
209 210 211 212 213 214
public slots:


};

#endif // HASH_H