-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.cpp
75 lines (59 loc) · 2.34 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
#include <boost/filesystem.hpp>
#include <zipper/unzipper.h>
#include <headers/keynote.h>
#include "src/key_to_svg/svg_wrapper.h"
#define NANOSVG_IMPLEMENTATION // Expands implementation
using namespace boost::filesystem;
int generate_svg(std::string filePath);
inline bool file_exists (const std::string& name) {
ifstream f(name.c_str());
return f.good();
}
inline bool ends_with(const std::string &path, const std::string& ending) {
return path.size() >= ending.size() &&
path.compare(path.size() - ending.size(), ending.size(), ending) == 0;
}
int main(int argc,char* argv[]) {
if(argc == 2) {
path canonicalPath = canonical(argv[1]);
generate_svg(canonicalPath.generic_string());
} else {
std::cout << "Wrong formatting of command line arguments" << std::endl;
std::cout << "This tool expects the path of a keynote file as command line argument" << std::endl;
}
}
int generate_svg(std::string filePath) {
svg_wrapper svg;
zipper::Unzipper* currentZip;
// check if contains index.zip, otherwise extract the .key file as it will be newer format.
if (file_exists(filePath + "/Index.zip")) {
currentZip = new zipper::Unzipper(filePath + "/Index.zip");
} else {
currentZip = new zipper::Unzipper(filePath);
}
std::vector<zipper::ZipEntry> entries = currentZip->entries();
// erase all entries which are not ".iwa" files.
entries.erase(
std::remove_if(entries.begin(),
entries.end(),
[](const zipper::ZipEntry& entry){
return !ends_with(entry.name, ".iwa");
}),
entries.end());
std::vector<keynoteIWAFile> entriesInMemory(entries.size());
std::transform(entries.begin(), entries.end(), entriesInMemory.begin(), [&](auto const &x) {
keynoteIWAFile entry;
entry.name = x.name;
currentZip->extractEntryToMemory(x.name, entry.contents);
return entry;
}
);
currentZip->close();
delete currentZip;
auto output_file = "output.svg";
std::ofstream outFile;
outFile.open(output_file);
outFile << generateSVGFromKeynoteIWAFiles(entriesInMemory);
outFile.close();
return 0;
}