-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomparator.cpp
More file actions
31 lines (28 loc) · 850 Bytes
/
comparator.cpp
File metadata and controls
31 lines (28 loc) · 850 Bytes
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
#include "comparator.h"
#include <QtAlgorithms>
bool Comparator::isFilesEquals(const FileHash & file1, const FileHash & file2)
{
bool isPath = file1.path == file2.path;
bool isHash = file1.hash == file2.hash;
bool isEquals = false;
if(isPath == false && isHash == true)
{
isEquals = binCompare(file1, file2);
}
return isEquals;
}
bool Comparator::binCompare(const FileHash & first, const FileHash & second)
{
QFile f1(first.path);
QFile f2(second.path);
bool isOpen1 = f1.open(QIODevice::ReadOnly);
bool isOpen2 = f2.open(QIODevice::ReadOnly);
bool result = false;
if(isOpen1 == true && isOpen2 == true)
{
QByteArray data1 = f1.readAll();
QByteArray data2 = f2.readAll();
result = qEqual(data1.begin(), data1.end(), data2.begin());
}
return result;
}