-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathmain.cpp
More file actions
175 lines (139 loc) · 4.72 KB
/
main.cpp
File metadata and controls
175 lines (139 loc) · 4.72 KB
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/**
*
* Creates null particle files for Path of Exile 2.0.
*
* HowTo:
*
* 1. Export particle files from Content.ggpk using VisualGGPK. Atm it's "Metadata\Particles" folder.
* 2. Put this app near "Metadata" folder.
* 3. Launch once, wait "End" message.
* 4. Import created "nullParticles\Metadata" folder into Content.ggpk using VisualGGPK.
*
* Dmitriy Kravtsov <ajaxvs@gmail.com>, 2015-10-11.
*
*/
//========================================
#include <iostream>
#include <Windows.h>
#include <direct.h>
#include <stdio.h>
#include <algorithm>
using namespace std;
//========================================
const char nullBytesFile[] = { 0xFF, 0xFE, 0x30, 0x00, 0x0D, 0x00, 0x0A, 0x00 };
const string particleFileExtension = "pet";
//========================================
int createdFiles = 0;
//========================================
void out(const char * s) {
cout << s << std::endl;
}
//==================================================
string getAppPath() {
string sBuf = "";
TCHAR szPath[MAX_PATH];
if (GetModuleFileName(NULL, szPath, MAX_PATH)) {
sBuf = szPath;
size_t iPos = sBuf.rfind("/");
if (iPos == string::npos) {
iPos = sBuf.rfind("\\");
if (iPos == string::npos) {
return "";
}
sBuf = sBuf.substr(0, iPos + 1);
}
}
return sBuf;
}
//==================================================
bool isDirExist(const string &filePath) {
DWORD fileAtt = GetFileAttributesA(filePath.c_str());
return (fileAtt != INVALID_FILE_ATTRIBUTES && fileAtt & FILE_ATTRIBUTE_DIRECTORY);
}
//==================================================
string cstr(const int i) {
static char * c = new char[16];
_itoa_s(i, c, 12, 10);
string s = c;
return s;
}
//========================================
string getFileExtension(const string fileName) {
string lowerCase = fileName;
std::transform(lowerCase.begin(), lowerCase.end(), lowerCase.begin(), ::tolower);
size_t i = lowerCase.rfind('.', lowerCase.length());
if (i != string::npos) {
return(lowerCase.substr(i + 1, lowerCase.length() - i));
} else {
return("");
}
}
//========================================
void createNullFile(const string &filePath) {
FILE * pf;
pf = fopen(filePath.c_str(), "wb");
fwrite(nullBytesFile, sizeof(char), sizeof(nullBytesFile), pf);
fclose(pf);
createdFiles++;
//out(filePath.c_str()); //debug
}
//========================================
void createFilesFromDir(const string src, const string dest) {
WIN32_FIND_DATA fd;
HANDLE h;
//out("==="); //debug
string folderFiles = src + "*.*";
h = FindFirstFile(folderFiles.c_str(), &fd);
if (h != INVALID_HANDLE_VALUE) {
do {
string fileName = fd.cFileName;
if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
string fileExtension = getFileExtension(fileName);
if (fileExtension == particleFileExtension) {
createNullFile(dest + fileName);
}
} else {
if (fileName != "." && fileName != "..") {
string newSrcDir = src + fileName + "\\";
string newDestDir = dest + fileName + "\\";
mkdir(newDestDir.c_str());
createFilesFromDir(newSrcDir, newDestDir);
}
}
} while (FindNextFile(h, &fd));
FindClose(h);
}
//out("==="); //debug
}
//========================================
void main() {
out("poeNullParticles. Start.");
const string metadataFolder = "Metadata\\";
const string nullParticlesFolder = "nullParticles\\";
string appPath = getAppPath();
string metadataPath = appPath + metadataFolder;
if (isDirExist(metadataPath)) {
string nullParticlesPath = appPath + nullParticlesFolder;
if (!isDirExist(nullParticlesPath)) {
try {
mkdir(nullParticlesPath.c_str());
nullParticlesPath += metadataFolder;
mkdir(nullParticlesPath.c_str());
out("Creating null files, please wait...");
createFilesFromDir(metadataPath, nullParticlesPath);
string sDone = "Done. Created: " + cstr(createdFiles) + " null files";
out(sDone.c_str());
} catch (char * err) {
out("Something gone wrong:");
out(err);
}
} else {
out("Stop. There's already nullParticles folder created.");
}
} else {
out("Can't find Metadata folder.");
}
out("End. Press Enter to exit.");
cin.ignore();
}
//========================================