-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.cpp
107 lines (96 loc) · 2.44 KB
/
main.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
#include "pakfile.h"
#include "pack.h"
#include "unpack.h"
#include "native.h"
#include <iostream>
#include <sstream>
#include <fstream>
using namespace std;
using namespace scpak;
void printUsage(int argc, char *argv[])
{
string programPath = argv[0];
size_t i = programPath.rfind(pathsep);
string programName = programPath.substr(i+1);
cout << "Usage: " << programName << " <directory> | <pakfile>" << endl;
cout << "NOTE: You can just drag&drop directory or pakfile on scpak executable";
}
void printVersion()
{
cout << "scpak version " << scpak::Version << endl;
cout << "scpak is a tool for pack/unpack Survivalcraft pak format" << endl;
cout << "visit https://github.com/qnnnnez/scpak for more information" << endl;
}
void printLicense()
{
cout << "The MIT License (MIT) \nCopyright (c) 2017 qnnnnez" << endl;
}
int main(int argc, char *argv[])
{
string path;
bool interactive = false;
if (argc == 1)
{
printUsage(argc, argv);
cout << endl;
cout << "Enter a directory to pack or a .pak file to unpack: ";
cin >> path;
interactive = true;
}
else if (argc == 2)
{
std::string cmdarg = argv[1];
if (cmdarg == "--help" || cmdarg == "-h")
{
printUsage(argc, argv);
return 0;
}
else if (cmdarg == "--version" || cmdarg == "-v")
{
printVersion();
return 0;
}
else if (cmdarg == "--licence" || cmdarg == "--license")
{
printLicense();
return 0;
}
else
{
path = argv[1];
}
}
else
{
cerr << "error: unrecognized command line option" <<endl;
return 1;
}
if (!pathExists(path.c_str()))
{
cerr << "error: file/directory " << path << " does not exists" << endl;
return 1;
}
if (isDirectory(path.c_str()))
{
ofstream fout(path + ".pak", ios::binary);
PakFile pak = packAll(path);
pak.save(fout);
fout.close();
}
else if (isNormalFile(path.c_str()))
{
size_t i = path.rfind(".pak");
string directoryName;
if (i == string::npos)
directoryName = path + "_unpack";
else
directoryName = path.substr(0, i);
ifstream fin(path, ios::binary);
PakFile pak;
pak.load(fin);
unpackAll(pak, directoryName);
}
if (interactive)
cout << "Done." << endl;
return 0;
}