-
Notifications
You must be signed in to change notification settings - Fork 9
/
utilities.cpp
35 lines (29 loc) · 857 Bytes
/
utilities.cpp
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
#include "utilities.h"
#include<QString>
#include<QFile>
#include<QCryptographicHash>
#include<QDebug>
QByteArray getHash(QString fileName)
{
QString hashString;
QFile file(fileName);
QByteArray hashArray;
QCryptographicHash *sha1Hash;
//Attempt to open the file
if(!file.open(QFile::ReadOnly))
{
qDebug() << "Unable to read file:" << fileName << ". Error:" << file.errorString() << "\n";
}
else
{
//Load the file's data to process
QByteArray fileContents = file.readAll();
hashArray = sha1Hash->hash(fileContents, QCryptographicHash::Sha1);
}
//clean up the file since we are done with it
file.flush();
file.close();
file.deleteLater();
//return the checksum in hexidecimal format since that is what the manifest requires
return hashArray.toHex();
}