int main(int argc, char *argv[]) { if (argc!=2 && argc!=3) { std::cerr<<"To extract a file: "<<std::endl; std::cerr<<argv[0]<<" <img> <file>"<<std::endl; std::cerr<<"To extract all files: "<<std::endl; std::cerr<<argv[0]<<" <img>"<<std::endl; return EXIT_FAILURE; } bool all_files = argc==2; std::string extract; if (!all_files) extract = argv[2]; try { std::ifstream in; in.open(argv[1], std::ios::binary); APP_ASSERT_IO_SUCCESSFUL(in,"opening IMG"); Img img; img.init(in, argv[1]); if (!all_files) { unsigned long off = img.fileOffset(extract); unsigned long sz = img.fileSize(extract); extract_file(in, extract, off, sz); return EXIT_SUCCESS; } for (size_t i=0 ; i<img.size() ; i++) { unsigned long off = img.fileOffset(i); unsigned long sz = img.fileSize(i); extract_file(in, img.fileName(i), off, sz); } return EXIT_SUCCESS; } catch (const Exception &e) { CERR << e << std::endl; return EXIT_FAILURE; } }