-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtextureunpacker.cpp
60 lines (49 loc) · 1.88 KB
/
textureunpacker.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
#include "textureunpacker.h"
#include <QFileInfo>
namespace ProjectZomboidPackManager
{
TextureUnpacker::TextureUnpacker(QObject *parent)
: ThreadableTask(parent)
{
}
TextureUnpacker::~TextureUnpacker()
{
}
void TextureUnpacker::DoTask()
{
QFileInfo dirInfo(_folder.absolutePath());
QDir currentDir = _folder;
currentDir.cdUp();
emit SendMessage("Unpacking " + dirInfo.baseName() + ".pack");
if (currentDir.exists(dirInfo.baseName() + ".pack"))
{
QFile file(currentDir.absoluteFilePath(dirInfo.baseName() + ".pack"));
if (file.open(QIODevice::ReadOnly))
{
currentDir.cd(dirInfo.baseName());
for (quint32 i = 0; i < _fileData->Pages().size(); ++i)
{
PackFilePageMetaData nextPage = _fileData->Pages().at(i);
QString fileExtension = "";
if (nextPage.ImageType() == "PNG")
{
fileExtension = ".png";
}
else if (nextPage.ImageType() == "DDS")
{
fileExtension = ".dds";
}
QString imageName = nextPage.Name();
emit SendMessage("Unpacking " + imageName + "...");
QFile imageFile(currentDir.absolutePath() + "/" + imageName + fileExtension);
imageFile.open(QIODevice::WriteOnly);
file.seek(nextPage.ImageOffset());
imageFile.write(file.read(nextPage.ImageLength()));
imageFile.close();
}
file.close();
}
}
emit SendMessage("Finished Unpacking " + dirInfo.baseName() + ".pack");
}
}