Worldstone
 All Classes Files Functions Variables Enumerations Enumerator Macros Pages
MPQextract.cpp
1 //
2 // Created by Lectem on 12/11/2016.
3 //
4 
5 #include <FileStream.h>
6 #include <MpqArchive.h>
7 #include <fmt/format.h>
8 #include <fstream>
9 
10 using namespace WorldStone;
11 int main(int argc, char* argv[])
12 {
13  if (argc >= 4) {
14  const char* mpqFilename = argv[1];
15  const char* fileToExtract = argv[2];
16  MpqArchive mpqArchive(mpqFilename);
17  if (!mpqArchive.good()) fmt::print("Could not open {}\n", mpqFilename);
18  if (!mpqArchive.exists(fileToExtract))
19  fmt::print("The file {} was not found in {}\n", fileToExtract, mpqFilename);
20  else
21  {
22  fmt::print("The file is in the MPQ !\n");
23  StreamPtr file = mpqArchive.open(fileToExtract);
24  std::ofstream outFile(argv[3], std::ofstream::binary);
25  if (!outFile) fmt::print("Couldn't create output file\n");
26  while (file && file->good() && outFile)
27  {
28  char buffer[1024];
29  size_t readFromMpq = file->read(buffer, sizeof(buffer));
30  outFile.write(buffer, static_cast<std::streamsize>(readFromMpq));
31  }
32  }
33  }
34  else
35  fmt::print("MPQextract usage : MPQextract archive.mpq filetoextract outputfile\n");
36 
37  return 0;
38 }
A wrapper to manage MPQ archives.
Definition: MpqArchive.h:17