extractor_example.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. //
  2. // Created by Иван_Архипов on 30.10.2017.
  3. //
  4. #include <iostream>
  5. #include <ctime>
  6. #include <algorithm>
  7. #ifdef WIN32
  8. #include <direct.h>
  9. #define mkdir(dir, mode) _mkdir(dir)
  10. #endif
  11. #include "LotroDat.h"
  12. using namespace LOTRO_DAT;
  13. using namespace std;
  14. // Change these variables to true if you want export category to files.
  15. bool exportTextsToFiles = false;
  16. bool exportImagesToFiles = false;
  17. bool exportFontsToFiles = false;
  18. bool exportSoundsToFiles = false;
  19. bool exportTexturesToFiles = false;
  20. bool exportUnknownToFiles = false;
  21. // Change these variables to true if you want export category to databases.
  22. bool exportTextsToDb = false;
  23. bool exportImagesToDb = false;
  24. bool exportFontsToDb = false;
  25. bool exportSoundsToDb = false;
  26. bool exportTexturesToDb = false;
  27. bool exportUnknownToDb = false;
  28. // There is no need to change anything else
  29. int main() {
  30. std::cout << "Gi1dor's LotRO .dat extractor ver. " << LOTRO_DAT_VERSION << std::endl;
  31. std::cout << "Hello! I'm a basic shell version of .dat file extractor. I can open .dat file directly, "
  32. "if you write path to it (with name of file) in file \"dat_file_path.txt\"\n";
  33. DatFile file;
  34. ifstream in("dat_file_path.txt");
  35. if (!in.fail()) {
  36. std::string filename;
  37. getline(in, filename);
  38. std::cout << "Using .dat file from dat_file_path.txt...\n";
  39. std::cout << "Opening file " << filename << std::endl;
  40. auto operation = file.Initialise(filename, 0);
  41. if (operation.result == false)
  42. std::cout << "Dat initialisation failed. Error message: " << operation.msg << "\n";
  43. }
  44. while (!file.Initialized()) {
  45. std::cout << "Please, tell, where the .dat file is\n";
  46. std::cout << "Enter path to file (including filename): ";
  47. std::string filename;
  48. std::getline(std::cin, filename);
  49. std::cout << "Opening file " << filename << std::endl;
  50. auto operation = file.Initialise(filename, 0);
  51. if (operation.result == false)
  52. std::cout << "Dat initialisation failed. Error message: " << operation.msg << "\nTo try again enter path to .dat file\n";
  53. }
  54. std::cout << "Great! File initialised successfully!\n";
  55. std::cout << "Gathering file information...";
  56. file.GatherInformation("dat_info.log");
  57. int cmd = 0;
  58. while (true) {
  59. std::cout << "Please, choose, what should I do. I can extract .dat file to files (press 1), "
  60. "open another .dat file (press 2), or configure, what should I extract. Choose, what to do or exit (press -1)\n";
  61. if (cmd != 3) {
  62. std::cout << "Enter number of command (1-3): ";
  63. std::cin >> cmd;
  64. std::string tmp;
  65. std::getline(std::cin, tmp);
  66. }
  67. if (cmd == -1) {
  68. std::cout << "Exiting. Thanks for using me!\n";
  69. break;
  70. }
  71. if (cmd == 1) {
  72. const clock_t begin_time = clock();
  73. mkdir("Extracted data", 744);
  74. std::time_t result = std::time(nullptr);
  75. char *ttime = std::asctime(std::localtime(&result));
  76. auto *out_time = new char[25];
  77. memcpy(out_time, ttime, 24);
  78. out_time[24] = '\0';
  79. std::string filename = file.GetIO().GetFilename().value;
  80. std::cout << "FILENAME = " << filename << std::endl;
  81. std::string output_dir = std::string("Extracted data\\") + filename.substr(std::max(filename.length() - 16, 0u), 16) + " " + std::string(out_time) + "\\";
  82. std::replace(output_dir.begin(), output_dir.end(), ':', '-');
  83. mkdir(output_dir.c_str(), 744);
  84. std::cout << "Beginning unpacking... Please, wait for some minutes."
  85. "\nMaybe it's a good idea to have a cup of tea, while unpacker is working...\n" << std::flush;
  86. Database output_db;
  87. if (exportImagesToDb) {
  88. output_db.InitDatabase(output_dir + std::string("Images.db"));
  89. std::cout << "Extracted " << file.GetExporter().ExtractAllFilesByType(JPG, &output_db).value << " .jpg files to Images.db" << std::endl << std::flush;
  90. output_db.CloseDatabase();
  91. }
  92. if (exportSoundsToDb) {
  93. output_db.InitDatabase(output_dir + std::string("Sounds.db"));
  94. std::cout << "Extracted " << file.GetExporter().ExtractAllFilesByType(WAV, &output_db).value << " .wav files to Sounds.db" << std::endl << std::flush;
  95. std::cout << "Extracted " << file.GetExporter().ExtractAllFilesByType(OGG, &output_db).value << " .ogg files to Sounds.db" << std::endl << std::flush;
  96. output_db.CloseDatabase();
  97. }
  98. if (exportTextsToDb) {
  99. output_db.InitDatabase(output_dir + std::string("Texts.db"));
  100. std::cout << "Extracted " << file.GetExporter().ExtractAllFilesByType(TEXT, &output_db).value << " text files to Texts.db" << std::endl << std::flush;
  101. output_db.CloseDatabase();
  102. }
  103. if (exportFontsToDb) {
  104. output_db.InitDatabase(output_dir + std::string("Fonts.db"));
  105. std::cout << "Extracted " << file.GetExporter().ExtractAllFilesByType(FONT, &output_db).value << " font files to Fonts.db" << std::endl << std::flush;
  106. output_db.CloseDatabase();
  107. }
  108. if (exportTexturesToDb) {
  109. output_db.InitDatabase(output_dir + std::string("Textures.db"));
  110. std::cout << "Extracted " << file.GetExporter().ExtractAllFilesByType(DDS, &output_db).value << " .dds files to Textures.db" << std::endl << std::flush;
  111. output_db.CloseDatabase();
  112. }
  113. if (exportImagesToFiles) {
  114. mkdir((output_dir + "jpg").c_str(), 744);
  115. std::cout << "Extracted " << file.GetExporter().ExtractAllFilesByType(JPG, output_dir + "jpg\\").value << " .jpg files to directory" << std::endl << std::flush;
  116. }
  117. if (exportTexturesToFiles) {
  118. mkdir((output_dir + "dds").c_str(), 744);
  119. std::cout << "Extracted " << file.GetExporter().ExtractAllFilesByType(DDS, output_dir + "dds\\").value << " .dds files to directory" << std::endl << std::flush;
  120. }
  121. if (exportSoundsToFiles) {
  122. mkdir((output_dir + "wav").c_str(), 744);
  123. std::cout << "Extracted " << file.GetExporter().ExtractAllFilesByType(WAV, output_dir + "wav\\").value << " .wav files to directory" << std::endl << std::flush;
  124. mkdir((output_dir + "ogg").c_str(), 744);
  125. std::cout << "Extracted " << file.GetExporter().ExtractAllFilesByType(OGG, output_dir + "ogg\\").value << " .ogg files to directory" << std::endl << std::flush;
  126. }
  127. if (exportFontsToFiles) {
  128. mkdir((output_dir + "fonts").c_str(), 744);
  129. std::cout << "Extracted " << file.GetExporter().ExtractAllFilesByType(FONT, output_dir + "fonts\\").value << " font files to directory" << std::endl << std::flush;
  130. }
  131. if (exportUnknownToFiles) {
  132. mkdir((output_dir + "unknown").c_str(), 744);
  133. std::cout << "Extracted " << file.GetExporter().ExtractAllFilesByType(UNKNOWN, output_dir + "unknown\\").value << " unknown files to directory" << std::endl << std::flush;
  134. }
  135. if (exportTextsToFiles) {
  136. mkdir((output_dir + "texts").c_str(), 744);
  137. std::cout << "Extracted " << file.GetExporter().ExtractAllFilesByType(TEXT, output_dir + "texts\\").value << " text files to directory" << std::endl << std::flush;
  138. }
  139. fprintf(stdout, "Spent %f seconds on running unpacker! Thank you for your patience!\n",
  140. float(clock() - begin_time) / CLOCKS_PER_SEC);
  141. }
  142. if (cmd == 2) {
  143. std::cout << "Closing file...\n";
  144. file.Deinitialize();
  145. while (!file.Initialized()) {
  146. std::cout << "Please, tell, where the .dat file is\n";
  147. std::cout << "Enter path to file (including filename): ";
  148. std::string filename;
  149. std::getline(std::cin, filename);
  150. std::cout << "Opening file " << filename << std::endl;
  151. auto operation = file.Initialise(filename, 0);
  152. if (operation.result == false) {
  153. std::cout << "Some error caused while opening the file... "
  154. "Could you enter .dat filename once more?" << std::endl;
  155. std::cout << "Error message: " << operation.msg << std::endl;
  156. file.Deinitialize();
  157. }
  158. }
  159. }
  160. if (cmd == 3) {
  161. std::cout << "Current parameters:\n";
  162. std::cout << "(01) Export texts to files - " << (exportTextsToFiles ? "true\n" : "false\n");
  163. std::cout << "(02) Export texts to database - " << (exportTextsToDb ? "true\n" : "false\n");
  164. std::cout << "(11) Export images to files - " << (exportImagesToFiles ? "true\n" : "false\n");
  165. std::cout << "(12) Export images to database - " << (exportImagesToDb ? "true\n" : "false\n");
  166. std::cout << "(21) Export fonts to files - " << (exportFontsToFiles ? "true\n" : "false\n");
  167. std::cout << "(22) Export fonts to database - " << (exportFontsToDb ? "true\n" : "false\n");
  168. std::cout << "(31) Export sounds to files - " << (exportSoundsToFiles ? "true\n" : "false\n");
  169. std::cout << "(32) Export sounds to database - " << (exportSoundsToDb ? "true\n" : "false\n");
  170. std::cout << "(41) Export textures to files - " << (exportTexturesToFiles ? "true\n" : "false\n");
  171. std::cout << "(42) Export textures to database - " << (exportTexturesToDb ? "true\n" : "false\n");
  172. std::cout << "(51) Export unknown files to files - " << (exportUnknownToFiles ? "true\n" : "false\n");
  173. std::cout << "(52) Export unknown files to database - " << (exportUnknownToDb ? "true\n" : "false\n");
  174. std::cout << "Enter number of parameter to change (or -1 to exit this menu): ";
  175. int number = 0;
  176. std::cin >> number;
  177. std::string tmp;
  178. std::getline(std::cin, tmp);
  179. if (number == -1) {
  180. std::cout << "Returning to main menu..\n";
  181. cmd = 0;
  182. } else {
  183. switch (number) {
  184. case 01:
  185. exportTextsToFiles = !exportTextsToFiles;
  186. break;
  187. case 02:
  188. exportTextsToDb = !exportTextsToDb;
  189. break;
  190. case 11:
  191. exportImagesToFiles = !exportImagesToFiles;
  192. break;
  193. case 12:
  194. exportImagesToDb = !exportImagesToDb;
  195. break;
  196. case 21:
  197. exportFontsToFiles = !exportFontsToFiles;
  198. break;
  199. case 22:
  200. exportFontsToDb = !exportFontsToDb;
  201. break;
  202. case 31:
  203. exportSoundsToFiles = !exportSoundsToFiles;
  204. break;
  205. case 32:
  206. exportSoundsToDb = !exportSoundsToDb;
  207. break;
  208. case 41:
  209. exportTexturesToFiles = !exportTexturesToFiles;
  210. break;
  211. case 42:
  212. exportTexturesToDb = !exportTexturesToDb;
  213. break;
  214. case 51:
  215. exportUnknownToFiles = !exportTexturesToFiles;
  216. break;
  217. case 52:
  218. exportUnknownToDb = !exportTexturesToDb;
  219. break;
  220. default:
  221. std::cout << "Incorrect number. Returning to main menu..\n";
  222. }
  223. }
  224. }
  225. }
  226. file.Deinitialize();
  227. system("pause");
  228. return 0;
  229. }