void ExtractKyra::execute() { Common::Filename inputpath(_inputPaths[0].path); Extractor *extract = 0; if (isHoFInstaller) { extract = new HoFInstaller(inputpath.getFullPath().c_str()); } else { PAKFile *myfile = new PAKFile; if (!myfile->loadFile(inputpath.getFullPath().c_str(), isAmiga)) { delete myfile; error("Couldn't load file '%s'", inputpath.getFullPath().c_str()); } extract = myfile; } // Everything has been decided, do the actual extraction if (extractAll) { extract->outputAllFiles(&_outputPath); } else if (extractOne) { inputpath.setFullName(singleFilename); extract->outputFileAs(singleFilename.c_str(), inputpath.getFullPath().c_str()); } else { extract->drawFileList(); } delete extract; }
int main(int argc, char *argv[]) { if (argc < 3) { printHelp(argv[0]); return -1; } // Special case for developer mode of this tool: // With "--create filename offset size" the tool will output // a search entry for the specifed data in the specified file. if (!strcmp(argv[1], "--create")) { if (argc < 5) { printf("Developer usage: %s --create input_file hex_offset hex_size\n", argv[0]); return -1; } uint32 offset, size; sscanf(argv[3], "%x", &offset); sscanf(argv[4], "%x", &size); FILE *input = fopen(argv[2], "rb"); if (!input) error("Couldn't open file '%s'", argv[2]); byte *buffer = new byte[size]; fseek(input, offset, SEEK_SET); if (fread(buffer, 1, size, input) != size) { delete[] buffer; error("Couldn't read from file '%s'", argv[2]); } fclose(input); SearchData d = SearchCreator::create(buffer, size); delete[] buffer; printf("{ 0x%.08X, 0x%.08X, { {", d.size, d.byteSum); for (int j = 0; j < 16; ++j) { printf(" 0x%.2X", d.hash.digest[j]); if (j != 15) printf(","); else printf(" } } }\n"); } return 0; } PAKFile out; out.loadFile(argv[1], false); // When the output file is no valid kyra.dat file, we will delete // all the output. if (!checkIndex(out)) out.clearFile(); MD5Map inputFiles = createMD5Sums(argc - 2, &argv[2]); GameMap games = createGameMap(inputFiles); // Check for unused input files MD5Map unusedFiles = inputFiles; for (GameMap::const_iterator i = games.begin(); i != games.end(); ++i) { unusedFiles.erase(i->first->md5[0]); if (i->first->md5[1]) unusedFiles.erase(i->first->md5[1]); } for (MD5Map::const_iterator i = unusedFiles.begin(); i != unusedFiles.end(); ++i) printf("Input file '%s' with md5 sum '%s' is not known.\n", i->second.c_str(), i->first.c_str()); unusedFiles.clear(); // Short circuit, in case no games are found. if (games.empty()) { printf("No games found. Exiting prematurely\n"); return -1; } // Process all games found for (GameMap::const_iterator i = games.begin(); i != games.end(); ++i) { MD5Map::const_iterator f1 = inputFiles.find(i->first->md5[0]); MD5Map::const_iterator f2 = inputFiles.end(); if (i->first->md5[1]) f2 = inputFiles.find(i->first->md5[1]); if (f2 != inputFiles.end()) printf("Processing files '%s' and '%s'...\n", f1->second.c_str(), f2->second.c_str()); else printf("Processing file '%s'...\n", f1->second.c_str()); if (!process(out, i->first, i->second.data, i->second.size)) printf("FAILED\n"); else printf("OK\n"); } // Free up memory for (GameMap::iterator i = games.begin(); i != games.end(); ++i) delete[] i->second.data; games.clear(); inputFiles.clear(); if (!out.saveFile(argv[1])) error("couldn't save changes to '%s'", argv[1]); uint8 digest[16]; if (!md5_file(argv[1], digest, 0)) error("couldn't calc. md5 for file '%s'", argv[1]); FILE *f = fopen(argv[1], "ab"); if (!f) error("couldn't open file '%s'", argv[1]); if (fwrite(digest, 1, 16, f) != 16) error("couldn't write md5sum to file '%s'", argv[1]); fclose(f); return 0; }