forked from dubreuia/abledecoder
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
54 lines (40 loc) · 1.19 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
#include <iostream>
#include <fstream>
#include "FileChunk.h"
#include "FormChunk.h"
int main(int argc, char *argv[]) {
if (argc != 3) {
std::cout << "usage: abledecoder <in> <out>" << std::endl;
return 0;
}
std::string inPath = argv[1];
std::string outPath = argv[2];
FormChunk formChunk;
std::ifstream input(inPath, std::ifstream::binary);
if (!input.good()) {
throw std::runtime_error("error opening input file: " + inPath);
}
try {
formChunk.read(input);
} catch (const std::exception &ex) {
std::cerr << ex.what() << std::endl;
std::cerr << "reading file " << inPath << " failed" << std::endl;
input.close();
return 0;
}
input.close();
std::ofstream output(outPath, std::ofstream::binary);
if (!output.good()) {
throw std::runtime_error("error opening output file: " + outPath);
}
try {
formChunk.write(output);
} catch (const std::exception &ex) {
std::cerr << ex.what() << std::endl;
std::cerr << "writing file " << outPath << " failed" << std::endl;
output.close();
return 0;
}
output.close();
return 0;
}