extract_test.cpp 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. //
  2. // Created by Иван_Архипов on 30.10.2017.
  3. //
  4. #define _CRT_SECURE_NO_WARNINGS
  5. #include <iostream>
  6. #include <ctime>
  7. #include <algorithm>
  8. #ifdef WIN32
  9. #include <direct.h>
  10. #define mkdir(dir, mode) _mkdir(dir)
  11. #endif
  12. #include "../LotroDatPatcher.h"
  13. using namespace LOTRO_DAT;
  14. // Change these 2 variables to your path and name of .dat file
  15. const std::string path = "";//"E:\\SteamLibrary\\steamapps\\common\\";//Lord Of The Rings Online\\";
  16. const std::string filename = "client_local_English.dat";
  17. // Change these variables to true if you want export catecory to files.
  18. const bool exportImagesToFiles = false;
  19. const bool exportFontsToFiles = false;
  20. const bool exportSoundsToFiles = false;
  21. const bool exportTexturesToFiles = false;
  22. const bool exportUnknownToFiles = false;
  23. // Change these variables to true if you want export catecory to databases.
  24. const bool exportTextsToDb = true;
  25. const bool exportImagesToDb = true;
  26. const bool exportFontsToDb = true;
  27. const bool exportSoundsToDb = true;
  28. const bool exportTexturesToDb = true;
  29. const bool exportUnknownToDb = false;
  30. // There is no need to change anything else
  31. int main() {
  32. const clock_t begin_time = clock();
  33. mkdir("Extracted data", 744);
  34. std::time_t result = std::time(nullptr);
  35. char *ttime = std::asctime(std::localtime(&result));
  36. auto *out_time = new char[25];
  37. memcpy(out_time, ttime, 24);
  38. out_time[24] = '\0';
  39. std::string output_dir = std::string("Extracted data\\") + filename + " " + std::string(out_time) + "\\";
  40. std::replace(output_dir.begin(), output_dir.end(), ':', '-');
  41. mkdir(output_dir.c_str(), 744);
  42. freopen((output_dir + std::string("errors.log")).c_str(), "w", stderr);
  43. setbuf(stdout, NULL);
  44. setbuf(stderr, NULL);
  45. setvbuf (stdout, NULL, _IONBF, BUFSIZ);
  46. setvbuf (stderr, NULL, _IONBF, BUFSIZ);
  47. try {
  48. std::cout << "Starting search...\n" << std::flush;
  49. DatFile a((path + filename).c_str(), 0);
  50. std::cout << "Total files found: " << a.files_number() << std::endl << std::flush;
  51. std::cout << "Beginning unpacking... Please, wait for some minutes."
  52. "\nMaybe it's a good idea to have a cup of tea, while unpacker is working...\n" << std::flush;
  53. Database *out = new Database("out.db");
  54. if (exportImagesToDb) {
  55. Database *images = out;//new Database(output_dir + std::string("Images.db"));
  56. std::cout << "Extracted " << a.ExtractAllFilesByType(JPG, images) << " .jpg files to Images.db" << std::endl << std::flush;
  57. // delete images;
  58. }
  59. if (exportSoundsToDb) {
  60. Database *sounds = out;//new Database(output_dir + std::string("Sounds.db"));
  61. std::cout << "Extracted " << a.ExtractAllFilesByType(WAV, sounds) << " .wav files to Sounds.db" << std::endl << std::flush;
  62. std::cout << "Extracted " << a.ExtractAllFilesByType(OGG, sounds) << " .ogg files to Sounds.db" << std::endl << std::flush;
  63. // delete sounds;
  64. }
  65. if (exportTextsToDb) {
  66. Database *texts = out;//new Database(output_dir + std::string("Texts.db"));
  67. std::cout << "Extracted " << a.ExtractAllFilesByType(TEXT, texts) << " text files to Texts.db" << std::endl << std::flush;
  68. // delete texts;
  69. }
  70. if (exportFontsToDb) {
  71. Database *fonts = out;//new Database(output_dir + std::string("Fonts.db"));
  72. std::cout << "Extracted " << a.ExtractAllFilesByType(FONT, fonts) << " font files to Fonts.db" << std::endl << std::flush;
  73. // delete fonts;
  74. }
  75. if (exportTexturesToDb) {
  76. Database *textures = out;//new Database(output_dir + std::string("Textures.db"));
  77. std::cout << "Extracted " << a.ExtractAllFilesByType(DDS, textures) << " .dds files to Textures.db" << std::endl << std::flush;
  78. // delete textures;
  79. }
  80. delete out;
  81. if (exportUnknownToDb) {
  82. Database *unknown = new Database(output_dir + std::string("Unknown.db"));
  83. std::cout << "Extracted " << a.ExtractAllFilesByType(UNKNOWN, unknown) << " unknown files to Unknown.db" << std::endl << std::flush;
  84. }
  85. if (exportImagesToFiles) {
  86. mkdir((output_dir + "jpg").c_str(), 744);
  87. std::cout << "Extracted " << a.ExtractAllFilesByType(JPG, output_dir + "jpg\\") << " .jpg files to directory" << std::endl << std::flush;
  88. }
  89. if (exportTexturesToFiles) {
  90. mkdir((output_dir + "dds").c_str(), 744);
  91. std::cout << "Extracted " << a.ExtractAllFilesByType(DDS, output_dir + "dds\\") << " .dds files to directory" << std::endl << std::flush;
  92. }
  93. if (exportSoundsToFiles) {
  94. mkdir((output_dir + "wav").c_str(), 744);
  95. std::cout << "Extracted " << a.ExtractAllFilesByType(WAV, output_dir + "wav\\") << " .wav files to directory" << std::endl << std::flush;
  96. mkdir((output_dir + "ogg").c_str(), 744);
  97. std::cout << "Extracted " << a.ExtractAllFilesByType(OGG, output_dir + "ogg\\") << " .ogg files to directory" << std::endl << std::flush;
  98. }
  99. if (exportFontsToFiles) {
  100. mkdir((output_dir + "fonts").c_str(), 744);
  101. std::cout << "Extracted " << a.ExtractAllFilesByType(FONT, output_dir + "fonts\\") << " font files to directory" << std::endl << std::flush;
  102. }
  103. if (exportUnknownToFiles) {
  104. mkdir((output_dir + "unknown").c_str(), 744);
  105. std::cout << "Extracted " << a.ExtractAllFilesByType(FONT, output_dir + "unknown\\") << " unknown files to directory" << std::endl << std::flush;
  106. }
  107. } catch (std::exception &e) {
  108. fprintf(stderr, "Caught %s exception.", e.what());
  109. printf("Some critical errors occured. Need to stop execution. See information in errors.log file\n");
  110. fprintf(stderr, "Some critical errors occured. Need to stop execution now...\n");
  111. }
  112. fprintf(stdout, "Spent %f seconds on running unpacker! Thank you for your patience!\n",
  113. float(clock() - begin_time) / CLOCKS_PER_SEC);
  114. system("pause");
  115. return 0;
  116. }