patchinstaller.cpp 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585
  1. #include "patchinstaller.h"
  2. #include "legacyapplication.h"
  3. #include "models/patchdownloader.h"
  4. #include "models/filesystem.h"
  5. #include "models/settings.h"
  6. #include "models/datoriginalfilesdatabase.h"
  7. #include <QDebug>
  8. #include <QProcess>
  9. #include <QApplication>
  10. #include <QSqlQuery>
  11. QString getComponentNameFromId(int id) {
  12. switch (id) {
  13. case 100: return "texts_main";
  14. case 101: return "texts_items";
  15. case 102: return "texts_emotes";
  16. case 200: return "maps";
  17. case 201: return "loadscreens";
  18. case 202: return "textures";
  19. case 300: return "sounds";
  20. case 301: return "videos";
  21. }
  22. return "none";
  23. }
  24. PatchInstaller::PatchInstaller(QObject *parent) : QObject(parent) {
  25. client_local_file_ = new LOTRO_DAT::DatFile(100);
  26. client_general_file_ = new LOTRO_DAT::DatFile(101);
  27. connect(&PatchDownloader::instance(), &PatchDownloader::finished, this, [this](){startPatchInstallationChain();});
  28. }
  29. bool PatchInstaller::initialised() {
  30. return client_general_file_->Initialized() && client_local_file_->Initialized();
  31. }
  32. void PatchInstaller::checkIfUpdatedByGame()
  33. {
  34. const int client_local_maxiter = client_local_file_->GetDatFileMaxIteration();
  35. const int client_general_maxiter = client_general_file_->GetDatFileMaxIteration();
  36. const int client_local_saved_maxiter = _current_applied_patches_info.client_local_header_maxiter;
  37. const int client_general_saved_maxiter = _current_applied_patches_info.client_general_header_maxiter;
  38. emit updatedByGameStatusChanged(
  39. (client_local_saved_maxiter != -1 && client_local_maxiter != client_local_saved_maxiter) ||
  40. (client_general_saved_maxiter != -1 && client_general_maxiter != client_general_saved_maxiter)
  41. );
  42. }
  43. PatchInstaller::~PatchInstaller() {
  44. deinit();
  45. delete client_local_file_;
  46. delete client_general_file_;
  47. }
  48. // ############## PRIVATE ############## //
  49. bool PatchInstaller::datPathIsRelevant() {
  50. QString game_folder = Settings::getValue("Lotro/game_path").toString();
  51. QString locale_prefix = Settings::getValue("Lotro/original_locale").toString();
  52. QString client_local_filepath = game_folder + "/client_local_" + locale_prefix + ".dat";
  53. QString client_general_filepath = game_folder + "/client_general.dat";
  54. QString client_local_current_path = QString::fromStdString(client_local_file_->GetFilename());
  55. QString client_general_current_path = QString::fromStdString(client_general_file_->GetFilename());
  56. return QFileInfo(client_local_filepath) != QFileInfo(client_local_current_path)
  57. || QFileInfo(client_general_filepath) != QFileInfo(client_general_current_path);
  58. }
  59. void PatchInstaller::deinit() {
  60. client_local_file_->Deinit();
  61. client_general_file_->Deinit();
  62. emit deinitialized();
  63. }
  64. PatchInstaller::AppliedPatchesInfo PatchInstaller::getPatchesInfo() {
  65. return _current_applied_patches_info;
  66. }
  67. void PatchInstaller::installPatch(QString patch_name, LOTRO_DAT::Database* database) {
  68. DatOriginalFilesDatabase orig_files_db(QApplication::applicationDirPath() + "/data/" + patch_name + "_orig.db");
  69. LOTRO_DAT::SubfileData file;
  70. qDebug() << "Total files in database " << database->CountRows();
  71. qDebug() << "Patching all files from database..." << database;
  72. while (!(file = database->GetNextFile()).Empty()) {
  73. if (!file.options["fid"]) {
  74. continue;
  75. }
  76. current_status.finished_parts++;
  77. if (current_status.finished_parts * 100 / current_status.total_parts !=
  78. (current_status.finished_parts - 1) * 100 * 10 / current_status.total_parts) {
  79. // emitting if changed at least on 0.1%
  80. emit progressChanged(current_status);
  81. }
  82. const int dat_id = file.options["did"] ? file.options["did"].as<int>() : E_CLIENT_LOCAL;
  83. if (dat_id != E_CLIENT_LOCAL && dat_id != E_CLIENT_GENERAL) {
  84. qWarning() << "Unknown dat id parameter for file " << file.options["fid"].as<long long>() << " (dat id value = " << dat_id << "), SKIPPING!";
  85. continue;
  86. }
  87. const int file_id = file.options["fid"].as<int>();
  88. int file_version = -1;
  89. int file_iteration = -1; // TODO: FILE ITERATION
  90. if (dat_id == E_CLIENT_LOCAL) {
  91. file_version = client_local_file_->GetFileVersion(file_id);
  92. } else if (dat_id == E_CLIENT_GENERAL) {
  93. file_version = client_general_file_->GetFileVersion(file_id);
  94. }
  95. if (file_version != _patch_files_versions && file_version != 0) {
  96. LOTRO_DAT::SubfileData data;
  97. if (dat_id == E_CLIENT_LOCAL) {
  98. data = client_local_file_->GetFile(file_id);
  99. } else if (dat_id == E_CLIENT_GENERAL) {
  100. data = client_general_file_->GetFile(file_id);
  101. }
  102. orig_files_db.addFile(file_id, dat_id, file_version, file_iteration, data);
  103. }
  104. if (dat_id == E_CLIENT_LOCAL) {
  105. client_local_file_->PatchFile(file, _patch_files_versions);
  106. } else if (dat_id == E_CLIENT_GENERAL) {
  107. client_general_file_->PatchFile(file, _patch_files_versions);
  108. }
  109. }
  110. const QString hashsum = Settings::getValue("PatchDatabases/" + patch_name + "/hashsum").toString();
  111. if (patch_name == "text") {
  112. _current_applied_patches_info.has_no_patch_mark = false;
  113. _current_applied_patches_info.texts_patch_hashsum = hashsum;
  114. } else if (patch_name == "image") {
  115. _current_applied_patches_info.has_no_patch_mark = false;
  116. _current_applied_patches_info.images_patch_hashsum = hashsum;
  117. } else if (patch_name == "sound") {
  118. _current_applied_patches_info.has_no_patch_mark = false;
  119. _current_applied_patches_info.sounds_patch_hashsum = hashsum;
  120. } else if (patch_name == "font") {
  121. _current_applied_patches_info.has_no_patch_mark = false;
  122. _current_applied_patches_info.fonts_patch_hashsum = hashsum;
  123. } else if (patch_name == "texture") {
  124. _current_applied_patches_info.has_no_patch_mark = false;
  125. _current_applied_patches_info.textures_patch_hashsum = hashsum;
  126. }
  127. orig_files_db.closeDatabase();
  128. if (patch_name == "video") {
  129. installVideos(database);
  130. }
  131. if (patch_name == "loadscreen") {
  132. installLoadscreens(database);
  133. return;
  134. }
  135. insertPatchesInfoInDatFile(_current_applied_patches_info);
  136. return;
  137. }
  138. void PatchInstaller::installOriginalPatch(QString patch_name)
  139. {
  140. qDebug() << "Installing original version of patch " << patch_name;
  141. DatOriginalFilesDatabase orig_db(QApplication::applicationDirPath() + "/data/" + patch_name + "_orig.db");
  142. DatOriginalFilesDatabase::FileOperation operation = [this](int file_id, int dat_id, int version, int iteration, const LOTRO_DAT::SubfileData& data) {
  143. int original_file_version = 0;
  144. if (dat_id == E_CLIENT_LOCAL) {
  145. original_file_version = client_local_file_->GetFileVersion(file_id);
  146. } else if (dat_id == E_CLIENT_GENERAL) {
  147. original_file_version = client_general_file_->GetFileVersion(file_id);
  148. }
  149. if (original_file_version == _patch_files_versions && dat_id == E_CLIENT_LOCAL) {
  150. client_local_file_->PatchFile(data, version, iteration);
  151. } else if (original_file_version == _patch_files_versions && dat_id == E_CLIENT_GENERAL) {
  152. client_general_file_->PatchFile(data, version, iteration);
  153. }
  154. current_status.finished_parts++;
  155. if (current_status.finished_parts * 100 / current_status.total_parts !=
  156. (current_status.finished_parts - 1) * 100 * 10 / current_status.total_parts) {
  157. // emitting if changed at least on 0.1%
  158. emit progressChanged(current_status);
  159. }
  160. };
  161. orig_db.performOperationOnAllFiles(operation);
  162. if (patch_name == "text") {
  163. _current_applied_patches_info.texts_patch_hashsum = "";
  164. } else if (patch_name == "image") {
  165. _current_applied_patches_info.images_patch_hashsum = "";
  166. } else if (patch_name == "sound") {
  167. _current_applied_patches_info.sounds_patch_hashsum = "";
  168. } else if (patch_name == "texture") {
  169. _current_applied_patches_info.textures_patch_hashsum = "";
  170. } else if (patch_name == "font") {
  171. _current_applied_patches_info.fonts_patch_hashsum = "";
  172. } else if (patch_name == "video") {
  173. _current_applied_patches_info.videos_patch_hashsum = "";
  174. } else if (patch_name == "loadscreen") {
  175. _current_applied_patches_info.loadscreens_patch_hashsum = "";
  176. }
  177. insertPatchesInfoInDatFile(_current_applied_patches_info);
  178. }
  179. void PatchInstaller::installLoadscreens(LOTRO_DAT::Database* database) {
  180. QString locale_prefix = Settings::getValue("Lotro/original_locale").toString();
  181. const QStringList loadscreens_filenames = {
  182. locale_prefix == "English" ? "lotro_ad_pregame.jpg" : "lotro_ad_pregame_" + locale_prefix + ".jpg",
  183. "lotro_generic_teleport_screen_01.jpg",
  184. "lotro_generic_teleport_screen_02.jpg",
  185. "lotro_generic_teleport_screen_03.jpg",
  186. "lotro_generic_teleport_screen_04.jpg",
  187. "lotro_generic_teleport_screen_05.jpg",
  188. "lotro_generic_teleport_screen_06.jpg",
  189. "lotro_generic_teleport_screen_07.jpg",
  190. "lotro_generic_teleport_screen_08.jpg",
  191. "lotro_generic_teleport_screen_09.jpg",
  192. "lotro_generic_teleport_screen_10.jpg"
  193. };
  194. LOTRO_DAT::SubfileData data;
  195. QString logo_path = Settings::getValue("Lotro/game_path").toString() + "/raw/" + (locale_prefix == "English" ? "en" : locale_prefix) + "/logo/";
  196. for (size_t i = 0; i < qMin(size_t(loadscreens_filenames.size()), database->CountRows()); ++i) {
  197. data = database->GetNextFile();
  198. if (data.options["did"].as<int>() != -1) {
  199. continue;
  200. }
  201. QFile::remove(logo_path + loadscreens_filenames[i]);
  202. if (!data.binary_data.WriteToFile((logo_path + loadscreens_filenames[i]).toLocal8Bit())) {
  203. qWarning() << "InstallLoadscreens: Cannot write to file " << logo_path + loadscreens_filenames[i];
  204. }
  205. current_status.finished_parts++;
  206. if (current_status.finished_parts * 100 / current_status.total_parts !=
  207. (current_status.finished_parts - 1) * 100 * 10 / current_status.total_parts) {
  208. // emitting if changed at least on 0.1%
  209. emit progressChanged(current_status);
  210. }
  211. }
  212. _current_applied_patches_info.has_no_patch_mark = false;
  213. _current_applied_patches_info.loadscreens_patch_hashsum = Settings::getValue("PatchDatabases/loadscreen/hashsum").toString();
  214. insertPatchesInfoInDatFile(_current_applied_patches_info);
  215. }
  216. void PatchInstaller::installVideos(LOTRO_DAT::Database* database) {
  217. current_status.finished_parts += database->CountRows();
  218. emit progressChanged(current_status);
  219. download_video_total_videos = database->CountRows();
  220. download_video_finished_videos = 0;
  221. LOTRO_DAT::SubfileData file;
  222. while (!(file = database->GetNextFile()).Empty()) {
  223. if (!file.options["name"] || !file.options["url"] || !file.options["hash"] || !file.options["folder"]) {
  224. continue;
  225. }
  226. const QString filename = QString::fromStdString(file.options["name"].as<std::string>());
  227. const QString url = QString::fromStdString(file.options["url"].as<std::string>());
  228. const QString hash = QString::fromStdString(file.options["hash"].as<std::string>());
  229. const QString folder = QString::fromStdString(file.options["folder"].as<std::string>());
  230. const QString full_filename = Settings::getValue("Lotro/game_path").toString() + "/" + folder + "/" + filename;
  231. FileSystem::createFilePath(full_filename);
  232. if (FileSystem::fileExists(full_filename) && FileSystem::fileHash(full_filename) == hash) {
  233. download_video_finished_videos++;
  234. continue;
  235. }
  236. QFile* target_file = new QFile(full_filename);
  237. target_file->open(QIODevice::WriteOnly);
  238. Downloader* video_downloader = new Downloader(this);
  239. connect(video_downloader, &Downloader::progressChanged, this, &PatchInstaller::onDownloaderProgressChanged);
  240. video_downloader->setUrl(url);
  241. video_downloader->targetFile = target_file;
  242. video_downloader->start();
  243. video_downloader->waitForDownloaded();
  244. video_downloader->targetFile->close();
  245. video_downloader->targetFile->deleteLater();
  246. video_downloader->targetFile = nullptr;
  247. video_downloader->deleteLater();
  248. download_video_finished_videos++;
  249. }
  250. _current_applied_patches_info.has_no_patch_mark = false;
  251. _current_applied_patches_info.videos_patch_hashsum = Settings::getValue("PatchDatabases/video/hashsum").toString();
  252. insertPatchesInfoInDatFile(_current_applied_patches_info);
  253. }
  254. PatchInstaller::AppliedPatchesInfo PatchInstaller::getAppliedPatchesInfoFromDatFile() {
  255. PatchInstaller::AppliedPatchesInfo result;
  256. const LOTRO_DAT::SubfileData patch_versions_file = client_local_file_->GetFile(_applied_patches_file_id);
  257. if (patch_versions_file.Empty()) {
  258. result.has_no_patch_mark = true;
  259. } else {
  260. const QString text_data = QString::fromUtf8(reinterpret_cast<const char*>(patch_versions_file.binary_data.data() + 4), patch_versions_file.binary_data.size() - 4);
  261. const QStringList text_data_splitted = text_data.split("\n");
  262. if (text_data_splitted.length() < 0 || text_data_splitted[0] != _patch_mark_header) {
  263. return result;
  264. }
  265. for (const QString& str: text_data_splitted) {
  266. if (str.startsWith("TEXTS:")) {
  267. result.texts_patch_hashsum = QString(str).remove(0, 6);
  268. } else if (str.startsWith("IMAGES:")) {
  269. result.images_patch_hashsum = QString(str).remove(0, 7);
  270. } else if (str.startsWith("SOUNDS:")) {
  271. result.sounds_patch_hashsum = QString(str).remove(0, 7);
  272. } else if (str.startsWith("LOADSCREENS:")) {
  273. result.loadscreens_patch_hashsum = QString(str).remove(0, 12);
  274. } else if (str.startsWith("TEXTURES:")) {
  275. result.textures_patch_hashsum = QString(str).remove(0, 9);
  276. } else if (str.startsWith("FONTS:")) {
  277. result.fonts_patch_hashsum = QString(str).remove(0, 6);
  278. } else if (str.startsWith("VIDEOS:")) {
  279. result.videos_patch_hashsum = QString(str).remove(0, 7);
  280. } else if (str.startsWith("CLIENT_LOCAL_HEADER_MAXITER:")) {
  281. result.client_local_header_maxiter = QString(str).remove(0, 28).toInt();
  282. } else if (str.startsWith("CLIENT_GENERAL_HEADER_MAXITER:")) {
  283. result.client_general_header_maxiter = QString(str).remove(0, 30).toInt();
  284. }
  285. }
  286. if (result.texts_patch_hashsum != "" || result.images_patch_hashsum != "" || result.textures_patch_hashsum != "" ||
  287. result.sounds_patch_hashsum != "" || result.videos_patch_hashsum != "" || result.fonts_patch_hashsum != "" ||
  288. result.loadscreens_patch_hashsum != "")
  289. {
  290. result.has_no_patch_mark = false;
  291. }
  292. }
  293. return result;
  294. }
  295. void PatchInstaller::insertPatchesInfoInDatFile(const PatchInstaller::AppliedPatchesInfo& info) {
  296. LOTRO_DAT::SubfileData file_data;
  297. file_data.options["fid"] = _applied_patches_file_id;
  298. file_data.options["ext"] = LOTRO_DAT::StringFromFileType(LOTRO_DAT::TEXT);
  299. QString patches_info_data = _patch_mark_header + "\n";
  300. patches_info_data += "TEXTS:" + info.texts_patch_hashsum + "\n";
  301. patches_info_data += "IMAGES:" + info.images_patch_hashsum + "\n";
  302. patches_info_data += "SOUNDS:" + info.sounds_patch_hashsum + "\n";
  303. patches_info_data += "LOADSCREENS:" + info.loadscreens_patch_hashsum + "\n";
  304. patches_info_data += "TEXTURES:" + info.textures_patch_hashsum + "\n";
  305. patches_info_data += "FONTS:" + info.fonts_patch_hashsum + "\n";
  306. patches_info_data += "VIDEOS:" + info.videos_patch_hashsum + "\n";
  307. const int client_local_maxiter = client_local_file_->GetDatFileMaxIteration();
  308. const int client_general_maxiter = client_general_file_->GetDatFileMaxIteration();
  309. patches_info_data += "CLIENT_LOCAL_HEADER_MAXITER:" + QString::number(client_local_maxiter) + "\n";
  310. patches_info_data += "CLIENT_GENERAL_HEADER_MAXITER:" + QString::number(client_general_maxiter) + "\n";
  311. QByteArray data = QByteArray((char*)&_applied_patches_file_id, 4) + patches_info_data.toUtf8();
  312. file_data.binary_data = LOTRO_DAT::BinaryData(data.data(), data.size());
  313. client_local_file_->PatchFile(file_data, _patch_files_versions, 1, true);
  314. }
  315. // ############## PUBLIC SLOTS ############## //
  316. void PatchInstaller::init()
  317. {
  318. if (client_local_file_->Initialized() || client_general_file_->Initialized()) {
  319. // Firstly - deinitializing existing client_local files.
  320. deinit();
  321. }
  322. qDebug() << __FUNCTION__ << "Starting initialisation of LotroDatManager";
  323. qRegisterMetaType<PatchInstaller::Status>();
  324. QString game_folder = Settings::getValue("Lotro/game_path").toString();
  325. QString locale_prefix = Settings::getValue("Lotro/original_locale").toString();
  326. QString client_local_filepath = game_folder + "/client_local_" + locale_prefix + ".dat";
  327. QString client_general_filepath = game_folder + "/client_general.dat";
  328. // Initialising client_local_*.dat file and client_general.dat
  329. auto client_local_init_res = client_local_file_->Init(client_local_filepath.toStdString());
  330. auto client_general_init_res = client_general_file_->Init(client_general_filepath.toStdString());
  331. if (!client_local_init_res || !client_general_init_res) {
  332. client_local_file_->Deinit();
  333. client_general_file_->Deinit();
  334. qCritical() << __FUNCTION__ << "Finished LotroDatManager initialisation - error: DatFile initialisation error!";
  335. return;
  336. }
  337. // Initializing db for original files backup
  338. QString database_path = game_folder + "/LotroLegacy/orig_files.db";
  339. if (!FileSystem::fileExists(database_path)) {
  340. FileSystem::createFilePath(database_path);
  341. }
  342. qDebug() << "LotroDatManager initialisation successfull! Dat files: "
  343. << QString::fromStdString(client_general_file_->GetFilename())
  344. << QString::fromStdString(client_local_file_->GetFilename());
  345. _current_applied_patches_info = getAppliedPatchesInfoFromDatFile();
  346. checkIfUpdatedByGame();
  347. emit successfullyInitialized();
  348. }
  349. void PatchInstaller::startGame(bool remove_dat_files) {
  350. QString game_folder = Settings::getValue("Lotro/game_path").toString();
  351. if (game_folder == "none") {
  352. qCritical() << __FUNCTION__ << "Starting game FAILED - game folder wasnt set!";
  353. return;
  354. }
  355. QStringList args;
  356. args << "-nosplashscreen";
  357. if (_current_applied_patches_info.loadscreens_patch_hashsum != "") {
  358. args << "-skiprawdownload";
  359. }
  360. client_general_file_->Deinit();
  361. client_local_file_->Deinit();
  362. if (remove_dat_files) {
  363. QString game_folder = Settings::getValue("Lotro/game_path").toString();
  364. QString locale_prefix = Settings::getValue("Lotro/original_locale").toString();
  365. QString client_local_filepath = game_folder + "/client_local_" + locale_prefix + ".dat";
  366. QString client_general_filepath = game_folder + "/client_general.dat";
  367. QFile::remove(client_local_filepath);
  368. QFile::remove(client_general_filepath);
  369. }
  370. QString username = Settings::getValue("Account/username").toString();
  371. QString password = Settings::getValue("Account/password").toString();
  372. if (!username.isEmpty() && !password.isEmpty()) {
  373. args << "-username" << username << "-password" << password;
  374. }
  375. qDebug() << __FUNCTION__ << "Starting game with arguments: " << args;
  376. QFile f(Settings::getValue("Lotro/game_path").toString() + "/LotroLauncher.exe");
  377. QProcess process;
  378. if (FileSystem::fileExists(f.fileName())) {
  379. if (f.fileName().contains(" ")) {
  380. f.setFileName("\"" + f.fileName() + "\"");
  381. }
  382. deinit();
  383. process.startDetached(f.fileName(), args);
  384. process.waitForFinished(-1);
  385. QMetaObject::invokeMethod(&LegacyApplication::instance(), &LegacyApplication::close, Qt::QueuedConnection);
  386. }
  387. }
  388. void PatchInstaller::startPatchInstallationChain(bool force_reinstall_patches) {
  389. emit started();
  390. qInfo() << "PatchInstaller: Starting installation chain...";
  391. const QVector<QString> patches = {"text", "font", "image", "loadscreen", "texture", "sound", "video", "micro"};
  392. QMap<QString, LOTRO_DAT::Database*> patch_databases;
  393. current_status.total_parts = 0;
  394. current_status.finished_parts = 0;
  395. for (const QString& patch: patches) {
  396. if (!Settings::getValue("DatabaseDownload/" + patch).toBool()) {
  397. continue;
  398. }
  399. const QString patch_hashsum = Settings::getValue("PatchDatabases/" + patch + "/hashsum").toString();
  400. const QString patch_filename = Settings::getValue("PatchDatabases/" + patch + "/path").toString();
  401. QString hashsum_in_dat_file = "";
  402. if (patch == "text") {
  403. hashsum_in_dat_file = _current_applied_patches_info.texts_patch_hashsum;
  404. } else if (patch == "image") {
  405. hashsum_in_dat_file = _current_applied_patches_info.images_patch_hashsum;
  406. } else if (patch == "sound") {
  407. hashsum_in_dat_file = _current_applied_patches_info.sounds_patch_hashsum;
  408. } else if (patch == "texture") {
  409. hashsum_in_dat_file = _current_applied_patches_info.textures_patch_hashsum;
  410. } else if (patch == "font") {
  411. hashsum_in_dat_file = _current_applied_patches_info.fonts_patch_hashsum;
  412. } else if (patch == "video") {
  413. hashsum_in_dat_file = _current_applied_patches_info.videos_patch_hashsum;
  414. } else if (patch == "loadscreen") {
  415. hashsum_in_dat_file = _current_applied_patches_info.loadscreens_patch_hashsum;
  416. }
  417. if (!force_reinstall_patches && patch_hashsum == hashsum_in_dat_file) {
  418. qDebug() << "Skipping patch " << patch << " because its hashsum (" << patch_hashsum << ") is equal to hashsum in dat file (" << hashsum_in_dat_file << ")";
  419. continue;
  420. }
  421. if (force_reinstall_patches) {
  422. qDebug() << "Forcelly installing patch " << patch << ". Its hashsum (" << patch_hashsum << "). Hashsum in dat file (" << hashsum_in_dat_file << ")";
  423. }
  424. const QString real_file_hashsum = FileSystem::fileHash(patch_filename);
  425. if (!FileSystem::fileExists(patch_filename) || real_file_hashsum != patch_hashsum) {
  426. qCritical() << "PatchInstallation: Incorrect patch file: " << patch_filename << ", hashsum: " << real_file_hashsum << ", expected: " << patch_hashsum;
  427. continue;
  428. }
  429. LOTRO_DAT::Database* db = new LOTRO_DAT::Database();
  430. if (!db->InitDatabase(patch_filename.toStdString())) {
  431. qCritical() << "PatchInstallation: failed to initialize db " << patch_filename;
  432. continue;
  433. }
  434. patch_databases[patch] = db;
  435. current_status.total_parts += db->CountRows();
  436. }
  437. // Parsing info about patches which original versions should be installed
  438. QStringList patches_to_be_installed_orig_versions;
  439. for (const QString& patch: patches) {
  440. if (Settings::getValue("DatabaseDownload/" + patch).toBool()) {
  441. continue;
  442. }
  443. QString hashsum_in_dat_file = "";
  444. if (patch == "text") {
  445. hashsum_in_dat_file = _current_applied_patches_info.texts_patch_hashsum;
  446. } else if (patch == "image") {
  447. hashsum_in_dat_file = _current_applied_patches_info.images_patch_hashsum;
  448. } else if (patch == "sound") {
  449. hashsum_in_dat_file = _current_applied_patches_info.sounds_patch_hashsum;
  450. } else if (patch == "texture") {
  451. hashsum_in_dat_file = _current_applied_patches_info.textures_patch_hashsum;
  452. } else if (patch == "font") {
  453. hashsum_in_dat_file = _current_applied_patches_info.fonts_patch_hashsum;
  454. } else if (patch == "video") {
  455. hashsum_in_dat_file = _current_applied_patches_info.videos_patch_hashsum;
  456. } else if (patch == "loadscreen") {
  457. hashsum_in_dat_file = _current_applied_patches_info.loadscreens_patch_hashsum;
  458. }
  459. if (hashsum_in_dat_file == "") {
  460. qDebug() << "Skipping installing original version of patch " << patch << " because hashsum in dat file is already empty";
  461. continue;
  462. }
  463. patches_to_be_installed_orig_versions.append(patch);
  464. DatOriginalFilesDatabase db(QApplication::applicationDirPath() + "/data/" + patch + "_orig.db");
  465. current_status.total_parts += db.getRowsCount();
  466. }
  467. emit progressChanged(current_status);
  468. for (const QString& patch_name: patch_databases.keys()) {
  469. qInfo() << "PatchInstaller: Installing patch " << patch_name;
  470. installPatch(patch_name, patch_databases[patch_name]);
  471. patch_databases[patch_name]->CloseDatabase();
  472. delete patch_databases[patch_name];
  473. }
  474. for (const QString& patch_name : patches_to_be_installed_orig_versions) {
  475. installOriginalPatch(patch_name);
  476. }
  477. insertPatchesInfoInDatFile(_current_applied_patches_info);
  478. qInfo() << "PatchInstaller: Finished installation chain...";
  479. if (force_reinstall_patches) {
  480. emit updatedByGameStatusChanged(false);
  481. }
  482. emit finished();
  483. }
  484. // ############## PRIVATE SLOTS ############## //
  485. void PatchInstaller::onDownloaderProgressChanged(Downloader*, Downloader::Status progress) {
  486. emit videosDownloadProgressChanged(download_video_finished_videos, download_video_total_videos, progress);
  487. }