File tree 4 files changed +46
-7
lines changed
4 files changed +46
-7
lines changed Original file line number Diff line number Diff line change 1
1
<?xml version =" 1.0" encoding =" UTF-8" ?>
2
2
<!DOCTYPE QtCreatorProject >
3
- <!-- Written by QtCreator 4.2.1, 2017-02-19T03:10:13 . -->
3
+ <!-- Written by QtCreator 4.2.1, 2017-02-19T16:19:10 . -->
4
4
<qtcreator >
5
5
<data >
6
6
<variable >EnvironmentId</variable >
Original file line number Diff line number Diff line change 1
1
#include " license.h"
2
2
3
+ #include < string>
4
+ #include < iostream>
5
+
6
+ #include < QFile>
7
+ #include < QDebug>
8
+ #include < QTextStream>
3
9
#include < QCryptographicHash>
4
10
11
+ void License::printLicenseHash () const
12
+ {
13
+ std::string str = _licenseHash.toStdString ();
14
+ std::cout << " [ " << str << " ]" ;
15
+
16
+ qDebug () << QString::fromStdString (str);
17
+ }
18
+
5
19
QByteArray License::generateLicenseHash (QByteArray addr)
6
20
{
7
21
return QCryptographicHash::hash (addr, QCryptographicHash::Md4);
8
22
}
9
23
24
+ void License::saveToFile (QString fileName, QString path)
25
+ {
26
+ QFile file (fileName);
27
+ QDir::setCurrent (path);
28
+
29
+ if ( !file.open (QIODevice::WriteOnly | QIODevice::Text) ) {
30
+ qDebug () << " Failed to open file." ;
31
+ return ;
32
+ }
33
+
34
+ QTextStream stream (&file);
35
+ foreach (char c, _licenseHash) {
36
+ stream << c;
37
+ }
38
+ }
39
+
10
40
QDate License::getExpiryDate () const
11
41
{
12
42
return _expiryDate;
Original file line number Diff line number Diff line change 1
1
#ifndef LICENSE_H
2
2
#define LICENSE_H
3
3
4
- #include < QHash >
4
+ #include < QDir >
5
5
#include < QDate>
6
- // #include <QFile >
6
+ #include < QString >
7
7
#include < QByteArray>
8
8
9
9
class License
10
10
{
11
11
public:
12
12
// Constructors
13
13
License () :
14
- _macAddress (" " ), _expiryDate(QDate::currentDate()), _licenseHash(" " ) {}
14
+ _macAddress (" " ), _expiryDate(QDate::currentDate()), _licenseHash(" " )
15
+ {
16
+ saveToFile (QString (" test.txt" ));
17
+ }
15
18
16
19
License (QString mac):
17
20
_macAddress (mac), _expiryDate(QDate::currentDate())
18
21
{
19
- _licenseHash = generateLicenseHash (_macAddress.toLatin1 ());
22
+ _licenseHash = generateLicenseHash (_macAddress.toUtf8 ());
23
+ saveToFile (QString (" test.txt" ));
20
24
}
21
25
22
26
License (QString mac, QDate expiry) :
23
27
_macAddress (mac),
24
28
_expiryDate (expiry)
25
29
{
26
- _licenseHash = generateLicenseHash (_macAddress.toLatin1 ());
30
+ _licenseHash = generateLicenseHash (_macAddress.toUtf8 ());
31
+ saveToFile (QString (" test.txt" ));
27
32
}
28
33
34
+ // Print the generated license hash
35
+ void printLicenseHash () const ;
36
+
29
37
// Generate the Hash from a MAC addr
30
38
QByteArray generateLicenseHash (QByteArray addr);
31
39
32
40
// Write the generated license hash and expiry date to a file
33
- // void saveToFile();
41
+ void saveToFile (QString fileName, QString path=QDir::homePath() );
34
42
35
43
// Getter methods
36
44
QDate getExpiryDate () const ;
Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ int main(int argc, char *argv[])
22
22
Validate v (l);
23
23
24
24
v.isValidLicense () ? qDebug () << " Valid License" : qDebug () << " Invalid License" ;
25
+ l->printLicenseHash ();
25
26
26
27
return a.exec ();
27
28
}
You can’t perform that action at this time.
0 commit comments