lotro.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. #include "lotro.h"
  2. #include "filesystem.h"
  3. #include <QtConcurrent/QtConcurrent>
  4. #include <QFontDatabase>
  5. #include <QMessageBox>
  6. Lotro::Lotro(QSettings& app_settings_, QObject *parent) : app_settings(app_settings_),
  7. QObject(parent) {
  8. }
  9. void Lotro::initialiseDatFile(QString file_name) {
  10. if (!tryToBlockFile())
  11. return;
  12. qDebug() << "Initialising file " << file_name;
  13. emit processStarted("initialiseDatFile", {file_name});
  14. if (!FileSystem::fileExists(file_path)) {
  15. emit caughtError("initialiseDatFile", {QString("Ошибка инициализации"), QString("Файл " + file_path + " несуществует! Невозможно инициализировать файл ресурсов.")});
  16. return;
  17. }
  18. file.Initialise((file_path).toStdString(), 0);
  19. busy = false;
  20. emit processFinished("initialiseDatFile", {QString("Success")});
  21. }
  22. void Lotro::changeLocale() {
  23. if (!tryToBlockFile())
  24. return;
  25. qDebug() << "Changing locale of dat file...";
  26. // Setting locale, opposite to current
  27. auto current_locale = file.GetLocaleManager().GetCurrentLocale();
  28. auto new_locale = current_locale == LOTRO_DAT::DatLocaleManager::PATCHED ?
  29. LOTRO_DAT::DatLocaleManager::ORIGINAL :
  30. LOTRO_DAT::DatLocaleManager::PATCHED;
  31. QString old_locale_name = (current_locale == LOTRO_DAT::DatLocaleManager::PATCHED ? "Русифицированная" : "Оригинальная");
  32. QString new_locale_name = (new_locale == LOTRO_DAT::DatLocaleManager::PATCHED ? "Русифицированная" : "Оригинальная");
  33. emit processStarted("changeLocale", {current_locale, new_locale});
  34. auto operation = file.GetLocaleManager().SetLocale(new_locale);
  35. auto new_current_locale = file.GetLocaleManager().GetCurrentLocale();
  36. QString new_current_locale_name = (new_current_locale == LOTRO_DAT::DatLocaleManager::PATCHED ? "Русифицированная" : "Оригинальная");
  37. if (operation.result == LOTRO_DAT::SUCCESS) {
  38. emit processFinished("changeLocale", {"Success", new_current_locale_name});
  39. } else {
  40. emit caughtError("changeLocale", {"Ошибка смены локали!", QString("Не удалось сменить локаль игры! Текущая локаль: ") + new_current_locale_name});
  41. emit processFinished("changeLocale", {"Error", new_current_locale_name});
  42. }
  43. busy = false;
  44. }
  45. void Lotro::getLocaleFileContents(long long file_id, int locale) {
  46. if (!tryToBlockFile())
  47. return;
  48. emit processStarted("getFileContents", {file_id, locale});
  49. auto getfile_op = file.GetLocaleManager().GetLocaleFile(file_id, locale);
  50. if (!getfile_op.result) {
  51. emit caughtError("getOriginalFileContents", {"Файл не найден!", QString("Не удаётся найти файл с id ") + QString::number(file_id)});
  52. emit processFinished("getOriginalFileContents", {"Error"});
  53. return false;
  54. }
  55. LOTRO_DAT::SubFile subfile = getfile_op.value;
  56. auto getfiledata_op = file.GetFileSystem().GetFileData(subfile, 8);
  57. if (!getfile_op.result) {
  58. emit caughtError("getOriginalFileContents", {"Ошибка извлечения!", QString("Обнаружены некорректные данные файла в словаре! Файл ресурсов мог быть повреждён!\nid = ") + QString::number(file_id) + ", locale_id = " + QString::number(locale)});
  59. emit processFinished("getOriginalFileContents", {"Error"});
  60. return false;
  61. }
  62. LOTRO_DAT::SubfileData result = subfile.PrepareForExport(getfiledata_op.value);
  63. emit LocaleFileContentsReceived(locale, result);
  64. emit processFinished("getFileContents", {"Success", file_id, locale});
  65. busy = false;
  66. }
  67. void Lotro::importFilesFromDatabase(QString database_path) {
  68. if (!tryToBlockFile())
  69. return;
  70. if (!FileSystem::fileExists(database_path)) {
  71. emit caughtError("importFilesFromDatabase", {QString("Ошибка импорта!"), QString("Файл " + file_path + " несуществует! Невозможно инициализировать базу данных!")});
  72. return;
  73. }
  74. emit processStarted("importFilesFromDatabase", {database_path});
  75. LOTRO_DAT::Database db;
  76. if (!db.InitDatabase(database_path.toStdString())) {
  77. emit caughtError("importFilesFromDatabase", {QString("Ошибка импорта!"), QString("Внутренняя ошибка инициализации базы данных!")});
  78. emit processFinished("importFilesFromDatabase", {QString("Error")});
  79. return;
  80. }
  81. auto patch_operation = file.GetPatcher().PatchAllDatabase(&db);
  82. if (patch_operation.result) {
  83. emit processFinished("importFilesFromDatabase", {QString("Success"), patch_operation.value});
  84. } else {
  85. emit processFinished("importFilesFromDatabase", {QString("Error"), 0});
  86. }
  87. busy = false;
  88. }
  89. void Lotro::importFile(long long file_id, QString file_path) {
  90. }
  91. void Lotro::importTextFragment(long long file_id, long long fragment_id,
  92. QString fragment_contents, QString arguments) {
  93. }
  94. void Lotro::getTextFragment(long long file_id, long long fragment_id) {
  95. }
  96. void Lotro::createCoreStatusFile(QString output_filename) {
  97. }
  98. void Lotro::extractSingleFile(QString output_filename, long long file_id) {
  99. }
  100. void Lotro::extractSingleFileToDatabase(QString database_path, long long file_id) {
  101. }
  102. void Lotro::extractGrouppedFiles(QString output_foldername, LOTRO_DAT::FILE_TYPE type) {
  103. }
  104. void Lotro::extractGrouppedFilesToDatabase(QString database_path, LOTRO_DAT::FILE_TYPE type) {
  105. }
  106. void Lotro::getUnactiveCategories() {
  107. }
  108. void Lotro::startGame() {
  109. }
  110. bool Lotro::initialised() {
  111. }
  112. int Lotro::currentLocale() {
  113. }
  114. bool Lotro::patched() {
  115. }
  116. bool Lotro::tryToBlockFile()
  117. {
  118. if (busy) {
  119. emit caughtError("common", {QString("Ошибка инициализации!"), QString("Уже выполняется другой процесс с ресурсами игры! Невозможно инициализировать во время выполнения другого процесса!")});
  120. return false;
  121. }
  122. busy = true;
  123. }
  124. void LegacyApp::ExtractFiles(QString folder_name, bool to_database, bool is_single_file, int file_id, LOTRO_DAT::FILE_TYPE type)
  125. {
  126. qDebug() << "Extracting files with parameters " << folder_name << to_database << is_single_file << file_id << type;
  127. QtConcurrent::run([this, folder_name, to_database, is_single_file, file_id, type](){
  128. if (client_local_dat_busy == false) {
  129. client_local_dat_busy = true;
  130. if (is_single_file) {
  131. auto operation = client_local_dat.GetExporter().ExtractFileById(file_id, std::string((folder_name + "/output").toLocal8Bit().constData()));
  132. if (operation.result == LOTRO_DAT::SUCCESS)
  133. QMessageBox::information(nullptr, "Извлечение успешно!", "Файл " + QString::number(file_id) + " был успешно извлечён!\nПуть к файлу: " + folder_name + "/output.{расширение файла}");
  134. else
  135. QMessageBox::critical(nullptr, "Ошибка извлечения!", "Файл " + QString::number(file_id) + " не был извлечён ввиду внутренней ошибки\nТекст ошибки: " + QString::fromStdString(operation.msg));
  136. }
  137. if (!is_single_file) {
  138. if (to_database) {
  139. LOTRO_DAT::Database db;
  140. qint64 msecs = QDateTime::currentDateTime().toMSecsSinceEpoch();
  141. QString output_database_filename = folder_name + "/database_" + QString::number(msecs) + ".db";
  142. db.InitDatabase(std::string(output_database_filename.toStdString()));
  143. auto operation = client_local_dat.GetExporter().ExtractAllFilesByType(type, &db);
  144. db.CloseDatabase();
  145. if (operation.result == LOTRO_DAT::SUCCESS)
  146. QMessageBox::information(nullptr, "Извлечение успешно!", "Выбранные типы файлов были успешно извлечены в базу данных\nКол-во извлечённых файлов: " + QString::number(operation.value) + "\nПуть к извлечённой базе данных: " + output_database_filename);
  147. else
  148. QMessageBox::critical(nullptr, "Ошибка извлечения!", "Файлы не были извлечены ввиду внутренней ошибки\nТекст ошибки: " + QString::fromStdString(operation.msg));
  149. } else {
  150. QString output_directory_path = folder_name + "/";
  151. auto operation = client_local_dat.GetExporter().ExtractAllFilesByType(type, std::string(output_directory_path.toLocal8Bit().constData()));
  152. if (operation.result == LOTRO_DAT::SUCCESS)
  153. QMessageBox::information(nullptr, "Извлечение успешно!", "Выбранные типы файлов были успешно извлечены в папку\nКол-во извлечённых файлов: " + QString::number(operation.value) + "\nПуть к папке: " + output_directory_path);
  154. else
  155. QMessageBox::critical(nullptr, "Ошибка извлечения!", "Файлы не были извлечены ввиду внутренней ошибки\nТекст ошибки: " + QString::fromStdString(operation.msg));
  156. }
  157. }
  158. client_local_dat_busy = false;
  159. }
  160. });
  161. }
  162. void LegacyApp::ChangeLocale()
  163. {
  164. }
  165. void LegacyApp::CreateCoreStatusFile(QString output_folder)
  166. {
  167. qDebug() << "Creating core status file to output folder " << output_folder;
  168. QtConcurrent::run([this, output_folder](){
  169. if (client_local_dat_busy == false) {
  170. client_local_dat_busy = true;
  171. qint64 msecs = QDateTime::currentDateTime().toMSecsSinceEpoch();
  172. QString output_filename = output_folder + "/core_" + QString::number(msecs) + ".txt";
  173. auto operation = client_local_dat.GatherInformation(std::string(output_filename.toLocal8Bit().constData()));
  174. client_local_dat_busy = false;
  175. if (operation.result == LOTRO_DAT::SUCCESS)
  176. QMessageBox::information(nullptr, "Успех!", "Файл ядра успешно создан!\nПуть к файлу: " + output_filename);
  177. else
  178. QMessageBox::critical(nullptr, "Неудача!", "Ошибка создания файла ядра!\nТекст ошибки: " + QString::fromStdString(operation.msg));
  179. }
  180. });
  181. }