patchinstaller.cpp 28 KB

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