-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsinglemod.cpp
104 lines (79 loc) · 3.02 KB
/
singlemod.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
#include "singlemod.h"
#include <QDataStream>
Mod::Mod(QString path, QObject* parent) : QObject(parent), folderPath(path)
{
using namespace Constants;
folderPathNative = QDir::toNativeSeparators(folderPath);
contentPath = folderPath + CONTENT_PFIX;
scriptsPath = contentPath + SCRIPTS_PFIX;
cachePath = contentPath + CACHE_PFIX;
modName = folderPath.mid( folderPath.lastIndexOf(SLASH) + 1 );
metadata.setFile(contentPath + METADATA_PFIX);
metadata.parse();
checker = new QFileInfo;
checker->setFile(scriptsPath);
hasScripts = checker->exists() && checker->isDir();
checker->setFile(cachePath);
hasCache = checker->exists() && checker->isFile() && checker->size() > 0;
hasMetadata = metadata.isValid();
if ( hasMetadata ) {
for (QString bundleName : metadata.bundlesList) {
bundles.append( new BundleFile( contentPath + SLASH + bundleName, this ) );
}
}
hasBundles = bundles.size() > 0;
QDir folder(contentPath);
folder.setNameFilters(QStringList("*" + RENAME_PFIX));
folder.setFilter(QDir::Files);
mergedResources = folder.entryInfoList();
modState = ( mergedResources.size() > 0 ) ? MERGED : NOT_MERGED;
isMergeable = (hasMetadata && hasBundles) || modState == MERGED;
folder.setNameFilters(QStringList({"*.bundle", "*.store", "*.cache"}));
folder.setFilter(QDir::Files);
QFileInfoList detectedResources = folder.entryInfoList();
/* Some checks for notes */
if ( mergedResources.size() > 0 && detectedResources.size() > 0) {
notes.append( tr("Mod contains both merged and unmerged bundles, please delete unnecessary files. ", "Incorrect mod structure warning.") );
modState = CORRUPTED;
}
if (isMergeable) {
for (QString line : metadata.filesList) {
if (line.indexOf(ICON_CHECK) != -1) {
isMergeable = false;
break;
}
if (line.indexOf(XML_CHECK) != -1) {
notes.append( tr("XML files detected, merging is NOT recommended. ", "Warns about detected xmls.") );
break;
}
if (line.indexOf(SWF_CHECK) != -1) {
notes.append( tr("SWF files detected, merging is NOT recommended. ", "Warns about detected swfs.") );
break;
}
}
}
}
void Mod::renameMerge()
{
using namespace Constants;
checker->setFile(cachePath);
if ( checker->exists() ) {
QFile::rename(cachePath, cachePath + RENAME_PFIX);
}
if (hasMetadata) {
QFile::rename(contentPath + METADATA_PFIX, contentPath + METADATA_PFIX + RENAME_PFIX);
}
if (hasBundles) {
for (auto file : bundles) {
QFile::rename(file->fullPath, file->fullPath + RENAME_PFIX);
}
}
}
void Mod::renameUnmerge()
{
for (QFileInfo mr : mergedResources) {
QString newName = mr.absoluteFilePath();
newName.chop(Constants::RENAME_PFIX.size());
QFile::rename( mr.absoluteFilePath(), newName );
}
}