patchinstaller.cpp 23 KB

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