|
@@ -1,65 +1,26 @@
|
|
|
#include "patchinstaller.h"
|
|
|
#include "models/filesystem.h"
|
|
|
+#include "models/downloader.h"
|
|
|
#include "models/settings.h"
|
|
|
|
|
|
#include <QDebug>
|
|
|
#include <QProcess>
|
|
|
|
|
|
-
|
|
|
-PatchInstaller::PatchInstaller(QObject *parent) : QObject(parent) {
|
|
|
-}
|
|
|
-
|
|
|
-void PatchInstaller::init()
|
|
|
-{
|
|
|
- emit operationStarted("initializeManager");
|
|
|
- qDebug() << __FUNCTION__ << "Starting initialisation of LotroDatManager";
|
|
|
-
|
|
|
- QString game_folder = Settings::getValue("Lotro/game_path").toString();
|
|
|
- QString locale_prefix = Settings::getValue("Lotro/original_locale").toString();
|
|
|
-
|
|
|
- QString client_local_filepath = game_folder + "/client_local_" + locale_prefix + ".dat";
|
|
|
- QString client_general_filepath = game_folder + "/client_general.dat";
|
|
|
-
|
|
|
- if (!FileSystem::fileExists(client_local_filepath) || !FileSystem::fileExists(client_general_filepath)) {
|
|
|
- emit errorOccured("initializeManager", {}, "DatFilesNotFound");
|
|
|
- emit operationFinished("initializeManager", {}, false);
|
|
|
- return;
|
|
|
+QString getComponentNameFromId(int id) {
|
|
|
+ switch (id) {
|
|
|
+ case 100: return "texts_main";
|
|
|
+ case 101: return "texts_items";
|
|
|
+ case 102: return "texts_emotes";
|
|
|
+ case 200: return "maps";
|
|
|
+ case 201: return "loadscreens";
|
|
|
+ case 202: return "textures";
|
|
|
+ case 300: return "sounds";
|
|
|
+ case 301: return "videos";
|
|
|
}
|
|
|
+ return "none";
|
|
|
+}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
- if (!QFile::setPermissions(client_local_filepath, QFileDevice::Permission(0x6666))) {
|
|
|
- qDebug() << __FUNCTION__ << "Unable to update permissions on client_local_* file!";
|
|
|
- }
|
|
|
-
|
|
|
- if (!QFile::setPermissions(client_general_filepath, QFileDevice::Permission(0x6666))) {
|
|
|
- qDebug() << __FUNCTION__ << "Unable to update permissions on client_general* file!";
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- client_local_file_ = new LOTRO_DAT::DatFile(1);
|
|
|
- client_general_file_ = new LOTRO_DAT::DatFile(2);
|
|
|
-
|
|
|
- auto client_local_init_res = client_local_file_->Init(client_local_filepath.toStdString());
|
|
|
- auto client_general_init_res = client_general_file_->Init(client_general_filepath.toStdString());
|
|
|
-
|
|
|
- if (!client_local_init_res || !client_general_init_res) {
|
|
|
- client_local_file_->Deinit();
|
|
|
- client_general_file_->Deinit();
|
|
|
-
|
|
|
- qDebug() << __FUNCTION__ << "Finished LotroDatManager initialisation - error: DatFile initialisation error!";
|
|
|
-
|
|
|
- emit errorOccured("initializeManager", {}, "DatInitError");
|
|
|
- emit operationFinished("initializeManager", {}, false);
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- qDebug() << "LotroDatManager initialisation successfull! Dat files: "
|
|
|
- << QString::fromStdString(client_general_file_->GetFilename())
|
|
|
- << QString::fromStdString(client_local_file_->GetFilename());
|
|
|
-
|
|
|
- emit operationFinished("initializeManager", {}, true);
|
|
|
+PatchInstaller::PatchInstaller(QObject *parent) : QObject(parent) {
|
|
|
}
|
|
|
|
|
|
bool PatchInstaller::initialised() {
|
|
@@ -70,6 +31,7 @@ PatchInstaller::~PatchInstaller() {
|
|
|
deinit();
|
|
|
}
|
|
|
|
|
|
+
|
|
|
|
|
|
bool PatchInstaller::datPathIsRelevant() {
|
|
|
QString game_folder = Settings::getValue("Lotro/game_path").toString();
|
|
@@ -92,12 +54,19 @@ void PatchInstaller::deinit() {
|
|
|
emit operationFinished("deinitializeManager");
|
|
|
}
|
|
|
|
|
|
-void PatchInstaller::installPatch(QString patch_name, QString database_path, RESOURCE_FILE_TYPE dat_file) {
|
|
|
- emit operationStarted("installPatch", {patch_name, database_path});
|
|
|
- LOTRO_DAT::Database db;
|
|
|
+void PatchInstaller::installPatch(QString patch_name, LOTRO_DAT::Database& database) {
|
|
|
+ if (patch_name == "loadscreen") {
|
|
|
+ installLoadscreens(database);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (patch_name == "video") {
|
|
|
+ installVideos(database);
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- if (!db.InitDatabase(database_path.toStdString())) {
|
|
|
- qDebug() << __FUNCTION__ << "Error database " << database_path << ": failed to open!";
|
|
|
+ if (patch_name == "micro" && !Settings::getValue("Components/micropatch").toBool()) {
|
|
|
+ Settings::setValue("DatabaseNeedInstall/micropatch", false);
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -105,9 +74,9 @@ void PatchInstaller::installPatch(QString patch_name, QString database_path, RES
|
|
|
|
|
|
LOTRO_DAT::SubfileData file;
|
|
|
int i = 0;
|
|
|
- const int total_files = db.CountRows();
|
|
|
+ const int total_files = database.CountRows();
|
|
|
qDebug() << "Patching all files from database...";
|
|
|
- while (!(file = db.GetNextFile()).Empty()) {
|
|
|
+ while (!(file = database.GetNextFile()).Empty()) {
|
|
|
if (i * 100 / total_files != (i - 1) * 100 / total_files) {
|
|
|
qDebug() << "Completed " << i * 100 / total_files << "%";
|
|
|
}
|
|
@@ -117,18 +86,129 @@ void PatchInstaller::installPatch(QString patch_name, QString database_path, RES
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- if (dat_file == E_CLIENT_LOCAL) {
|
|
|
+ const int category = file.options["cat"] ? file.options["cat"].as<int>() : -1;
|
|
|
+ QString component_name = getComponentNameFromId(category);
|
|
|
+ if (!Settings::getValue("Components/" + component_name).toBool()) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ const int dat_id = file.options["fid"].as<int>();
|
|
|
+
|
|
|
+ if (dat_id == E_CLIENT_LOCAL) {
|
|
|
client_local_file_->PatchFile(file);
|
|
|
- } else if (dat_file == E_CLIENT_GENERAL) {
|
|
|
+ } else if (dat_id == E_CLIENT_GENERAL) {
|
|
|
client_general_file_->PatchFile(file);
|
|
|
+ } else {
|
|
|
+ qWarning() << "Unknown dat id parameter for file " << file.options["fid"].as<long long>() << " (dat id value = " << dat_id << "), SKIPPING!";
|
|
|
}
|
|
|
++patched_files_num;
|
|
|
}
|
|
|
+ Settings::setValue("DatabaseNeedInstall/" + patch_name, false);
|
|
|
+ return;
|
|
|
+}
|
|
|
|
|
|
- db.CloseDatabase();
|
|
|
- emit operationFinished("installPatch", {patch_name, database_path}, true);
|
|
|
+
|
|
|
+void PatchInstaller::installLoadscreens(LOTRO_DAT::Database& database) {
|
|
|
+ if (!Settings::getValue("DatabaseNeedInstall/loadscreen").toBool() ||
|
|
|
+ !Settings::getValue("Components/loadscreens").toBool())
|
|
|
+ {
|
|
|
+ Settings::setValue("DatabaseNeedInstall/loadscreen", false);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ QString locale_prefix = Settings::getValue("Lotro/original_locale").toString();
|
|
|
+
|
|
|
+ const QStringList loadscreens_filenames = {
|
|
|
+ locale_prefix == "English" ? "lotro_ad_pregame.jpg" : "lotro_ad_pregame_" + locale_prefix + ".jpg",
|
|
|
+ "lotro_generic_teleport_screen_01.jpg",
|
|
|
+ "lotro_generic_teleport_screen_02.jpg",
|
|
|
+ "lotro_generic_teleport_screen_03.jpg",
|
|
|
+ "lotro_generic_teleport_screen_04.jpg",
|
|
|
+ "lotro_generic_teleport_screen_05.jpg",
|
|
|
+ "lotro_generic_teleport_screen_06.jpg",
|
|
|
+ "lotro_generic_teleport_screen_07.jpg",
|
|
|
+ "lotro_generic_teleport_screen_08.jpg",
|
|
|
+ "lotro_generic_teleport_screen_09.jpg",
|
|
|
+ "lotro_generic_teleport_screen_10.jpg"
|
|
|
+ };
|
|
|
+
|
|
|
+ LOTRO_DAT::SubfileData data;
|
|
|
+
|
|
|
+ QString logo_path = Settings::getValue("Lotro/game_path").toString() + "/raw/" + (locale_prefix == "English" ? "en" : locale_prefix) + "/logo/";
|
|
|
+
|
|
|
+ for (size_t i = 0; i < qMin(size_t(loadscreens_filenames.size()), database.CountRows()); ++i) {
|
|
|
+ data = database.GetNextFile();
|
|
|
+ QFile::remove(logo_path + loadscreens_filenames[i]);
|
|
|
+
|
|
|
+ if (!data.binary_data.WriteToFile((logo_path + loadscreens_filenames[i]).toLocal8Bit())) {
|
|
|
+ qWarning() << "InstallLoadscreens: Cannot write to file " << logo_path + loadscreens_filenames[i];
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ Settings::setValue("DatabaseNeedInstall/loadscreen", false);
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+void PatchInstaller::installVideos(LOTRO_DAT::Database& database) {
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+void PatchInstaller::init()
|
|
|
+{
|
|
|
+ emit operationStarted("initializeManager");
|
|
|
+ qDebug() << __FUNCTION__ << "Starting initialisation of LotroDatManager";
|
|
|
+
|
|
|
+ QString game_folder = Settings::getValue("Lotro/game_path").toString();
|
|
|
+ QString locale_prefix = Settings::getValue("Lotro/original_locale").toString();
|
|
|
+
|
|
|
+ QString client_local_filepath = game_folder + "/client_local_" + locale_prefix + ".dat";
|
|
|
+ QString client_general_filepath = game_folder + "/client_general.dat";
|
|
|
+
|
|
|
+ if (!FileSystem::fileExists(client_local_filepath) || !FileSystem::fileExists(client_general_filepath)) {
|
|
|
+ emit errorOccured("initializeManager", {}, "DatFilesNotFound");
|
|
|
+ emit operationFinished("initializeManager", {}, false);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (!QFile::setPermissions(client_local_filepath, QFileDevice::Permission(0x6666))) {
|
|
|
+ qDebug() << __FUNCTION__ << "Unable to update permissions on client_local_* file!";
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!QFile::setPermissions(client_general_filepath, QFileDevice::Permission(0x6666))) {
|
|
|
+ qDebug() << __FUNCTION__ << "Unable to update permissions on client_general* file!";
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ client_local_file_ = new LOTRO_DAT::DatFile(1);
|
|
|
+ client_general_file_ = new LOTRO_DAT::DatFile(2);
|
|
|
+
|
|
|
+ auto client_local_init_res = client_local_file_->Init(client_local_filepath.toStdString());
|
|
|
+ auto client_general_init_res = client_general_file_->Init(client_general_filepath.toStdString());
|
|
|
+
|
|
|
+ if (!client_local_init_res || !client_general_init_res) {
|
|
|
+ client_local_file_->Deinit();
|
|
|
+ client_general_file_->Deinit();
|
|
|
+
|
|
|
+ qDebug() << __FUNCTION__ << "Finished LotroDatManager initialisation - error: DatFile initialisation error!";
|
|
|
+
|
|
|
+ emit errorOccured("initializeManager", {}, "DatInitError");
|
|
|
+ emit operationFinished("initializeManager", {}, false);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ qDebug() << "LotroDatManager initialisation successfull! Dat files: "
|
|
|
+ << QString::fromStdString(client_general_file_->GetFilename())
|
|
|
+ << QString::fromStdString(client_local_file_->GetFilename());
|
|
|
+
|
|
|
+ emit operationFinished("initializeManager", {}, true);
|
|
|
+}
|
|
|
|
|
|
void PatchInstaller::startGame(bool freeze_updates) {
|
|
|
|
|
@@ -223,3 +303,9 @@ void PatchInstaller::startGame(bool freeze_updates) {
|
|
|
|
|
|
emit operationFinished("startGame");
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+void PatchInstaller::startPatchInstallationChain() {
|
|
|
+
|
|
|
+}
|