-
Notifications
You must be signed in to change notification settings - Fork 7
/
umanifest.cpp
132 lines (104 loc) · 3.2 KB
/
umanifest.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/**
* This work is distributed under the General Public License,
* see LICENSE for details
*
* @author Gwennaël ARBONA
**/
#include "umanifest.h"
#include "ui_umanifest.h"
#include <QDebug>
#include <QDirIterator>
/*----------------------------------------------
Constructor & destructor
----------------------------------------------*/
UManifest::UManifest(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::UManifest)
{
ui->setupUi(this);
ui->releaseNotes->append("Searching for files...");
QDomDocument* dom = new QDomDocument("files");
QDomElement root = dom->createElement("FolderProperties");
root.setAttribute("FolderName", ".");
dom->appendChild(root);
this->GenerateManifest(dom, root, QDir::currentPath());
ui->releaseNotes->append("Writing manifest to XML...");
QFile* file = new QFile(MANIFEST_NAME);
if (file->open(QIODevice::WriteOnly | QIODevice::Text ))
{
QTextStream stream(file);
stream << dom->toString();
file->close();
}
ui->releaseNotes->append("Done !");
delete dom;
delete file;
exit(0);
}
UManifest::~UManifest()
{
delete ui;
}
/*----------------------------------------------
Private methods
----------------------------------------------*/
void UManifest::GenerateManifest(QDomDocument* dom, QDomElement root, QString dir)
{
QDomElement folders = dom->createElement("Folders");
root.appendChild(folders);
QDomElement files = dom->createElement("Files");
root.appendChild(files);
QDirIterator it(dir);
while (it.hasNext())
{
QString filePath = it.next();
QFileInfo fi(filePath);
if (fi.fileName() == "UnrealManifest.exe"
|| fi.fileName() == "ReleaseNotes.xml"
|| fi.fileName() == "GameManifest.xml"
||(fi.fileName().startsWith("Qt5") && fi.fileName().endsWith(".dll")))
{
continue;
}
if (QDir(filePath).exists())
{
if (!filePath.endsWith("."))
{
QDomElement folder = dom->createElement("FolderProperties");
folder.setAttribute("FolderName", fi.fileName());
root.appendChild(folder);
GenerateManifest(dom, folder, filePath);
}
}
else
{
QDomElement e = dom->createElement("FileProperties");
QString fileHash = HashFile(filePath);
if (fileHash.length() > 0)
{
e.setAttribute("FileName", fi.fileName());
e.setAttribute("Size", fi.size());
e.setAttribute("md5", fileHash);
ui->releaseNotes->append(filePath + " : " + fileHash);
}
else
{
e.setTagName("EmptyFile");
}
files.appendChild(e);
}
}
}
QString UManifest::HashFile(QString filePath)
{
QFile* file = new QFile(filePath);
QByteArray hashed;
if (file->open(QIODevice::ReadOnly))
{
QByteArray content = file->readAll();
hashed = QCryptographicHash::hash(content, QCryptographicHash::Md5);
file->close();
}
delete file;
return hashed.toHex().data();
}