-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwzextractor.cpp
More file actions
73 lines (56 loc) · 2.1 KB
/
wzextractor.cpp
File metadata and controls
73 lines (56 loc) · 2.1 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
#include <iostream>
#include <fstream>
#include <map>
#include <memory>
#include <unistd.h>
#include <boost/filesystem.hpp>
#include "wzfile.hpp"
#include "constants.hpp"
int main(int argc, char* argv[]) {
// exit if incorrect num of parameters
if (argc != 2) {
std::cout << "Usage: ./WZExtractor <MaplestoryFolderPath>\n";
std::cout << "Example: ./WZExtractor maplestory\n";
return EXIT_FAILURE_PARAM;
}
const char* wzFolder = argv[1];
std::map<std::string, std::unique_ptr<BasicWZFile>> files;
// exit if nonexistent folder
if (!boost::filesystem::is_directory(wzFolder)) {
std::cout << "Usage: ./WZExtractor <MaplestoryFolderPath>\n";
std::cout << "Error: Folder '" << wzFolder << "' does not exist\n";
return EXIT_FAILURE_NONEXISTENT_FOLDER;
}
// store cwd and traverse to wz directory
auto curPath = boost::filesystem::current_path();
chdir(wzFolder);
// populate map with wz files from folder
boost::filesystem::directory_iterator wzIt(".");
boost::filesystem::directory_iterator endIt;
for (; wzIt != endIt; ++wzIt) {
const boost::filesystem::path filePath(wzIt->path().filename());
// skip non wz files
if (filePath.extension() != maplereverence::wzExtension) {
continue;
}
// skip List.wz
if (filePath.string() == maplereverence::listWZName) {
continue;
}
files.emplace(filePath.string(), std::unique_ptr<BasicWZFile>(
new BasicWZFile(filePath.string())));
}
// restore back to original path
chdir(curPath.c_str());
// create directory, traverse and extract
boost::filesystem::create_directory(maplereverence::wzExtractPath);
chdir(maplereverence::wzExtractPath.c_str());
for (const auto& file : files) {
std::cout << "===== " << file.second->getName() << " =====\n";
file.second->print();
std::cout << "\nExtracting: " << file.second->getName();
std::cout << std::endl;;
file.second->extract();
}
return EXIT_SUCCESS;
}