-
Notifications
You must be signed in to change notification settings - Fork 0
/
audiofile.cpp
74 lines (66 loc) · 1.9 KB
/
audiofile.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include "audiofile.h"
#include<QFile>
#include<QFileInfo>
#include<QCryptographicHash>
#include<QMessageBox>
#include<QDebug>
#include<QThread>
#include<QByteArray>
#include<QSettings>
AudioFile::AudioFile(const QString& file)
{
CompareResult.clear();
TreeAdded=false;
QFile tmpfile(file);
QFileInfo tmp(tmpfile);
if(!tmpfile.open(QFile::ReadOnly|QFile::Unbuffered))
QMessageBox::information(0,"Error","Can`t open a file");
AudioName=tmp.fileName();
AudioSize=QString::number(tmp.size()/1024./1024.);
QByteArray tmpdata=tmpfile.readAll();
int sz=0;
while(sz!=tmpdata.size())
AudioData+=tmpdata[sz++];
AudioData.chop(1024);
AudioData.remove(0,1024);
tmpdata.chop(1024);
tmpdata.remove(0,1024);
AudioPath=tmp.absoluteFilePath();
AudioHash=QString(QCryptographicHash::hash((tmpdata),QCryptographicHash::Md5).toHex());
tmpfile.flush();
tmpfile.close();
}
bool AudioFile::operator==(const AudioFile& other) const
{
return ((*this).AudioName==other.AudioName&&(*this).AudioHash==other.AudioHash&&(*this).AudioSize==other.AudioSize&&(*this).AudioPath==other.AudioPath&&(*this).AudioData==other.AudioData);
}
AudioFile::AudioFile()
{
AudioHash="";
AudioName="";
AudioPath="";
AudioSize="";
AudioData="";
TreeAdded=false;
CompareResult.clear();
}
bool AudioFile::DataEqual(AudioFile*other) const
{
return(this->AudioData==other->AudioData);
}
bool AudioFile::PathEqual(AudioFile*other) const
{
return(this->AudioPath==other->AudioPath);
}
bool AudioFile::HashEqual(AudioFile*other) const
{
return(this->AudioHash==other->AudioHash);
}
bool AudioFile::SizeEqual(AudioFile*other) const
{
return(this->AudioSize==other->AudioSize);
}
bool AudioFile::NameEqual(AudioFile*other) const
{
return(this->AudioName==other->AudioName);
}