MCPcopy Create free account
hub / github.com/OpenApoc/OpenApoc / main

Function main

tools/imagedump/imagedump.cpp:8–51  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6using namespace OpenApoc;
7
8int main(int argc, char *argv[])
9{
10 config().addPositionalArgument("image_string", "Image string to read");
11 config().addPositionalArgument("output_file", "Output .png file");
12
13 if (config().parseOptions(argc, argv))
14 {
15 return EXIT_FAILURE;
16 }
17
18 auto outputFile = config().getString("output_file");
19 auto inputString = config().getString("image_string");
20
21 if (inputString.empty())
22 {
23 std::cerr << "Must provide image_string\n";
24 config().showHelp();
25 return EXIT_FAILURE;
26 }
27
28 if (outputFile.empty())
29 {
30 std::cerr << "Must provide output_file\n";
31 config().showHelp();
32 return EXIT_FAILURE;
33 }
34
35 Framework f(UString(argv[0]), false);
36
37 auto img = f.data->loadImage(inputString);
38 if (!img)
39 {
40 std::cerr << "Failed to load image \"" << inputString << "\"\n";
41 return EXIT_FAILURE;
42 }
43
44 if (!f.data->writeImage(outputFile, img))
45 {
46 std::cerr << "Failed to write output file \"" << outputFile << "\"\n";
47 return EXIT_FAILURE;
48 }
49
50 return EXIT_SUCCESS;
51}

Callers

nothing calls this directly

Calls 7

emptyMethod · 0.80
addPositionalArgumentMethod · 0.45
parseOptionsMethod · 0.45
getStringMethod · 0.45
showHelpMethod · 0.45
loadImageMethod · 0.45
writeImageMethod · 0.45

Tested by

no test coverage detected