|
@@ -1,4 +1,5 @@
|
|
|
#include "patchinstaller.h"
|
|
|
+#include "models/patchdownloader.h"
|
|
|
#include "models/filesystem.h"
|
|
|
#include "models/settings.h"
|
|
|
|
|
@@ -27,6 +28,7 @@ PatchInstaller::PatchInstaller(QObject *parent)
|
|
|
, orig_files_db(QSqlDatabase::addDatabase("QSQLITE")) {
|
|
|
client_local_file_ = new LOTRO_DAT::DatFile(100);
|
|
|
client_general_file_ = new LOTRO_DAT::DatFile(101);
|
|
|
+ connect(&PatchDownloader::instance(), &PatchDownloader::finished, this, &PatchInstaller::startPatchInstallationChain);
|
|
|
}
|
|
|
|
|
|
bool PatchInstaller::initialised() {
|
|
@@ -63,14 +65,10 @@ void PatchInstaller::deinit() {
|
|
|
}
|
|
|
|
|
|
PatchInstaller::AppliedPatchesInfo PatchInstaller::getPatchesInfo() {
|
|
|
- return { false, false, 0, 100, 100, 100, 100 };
|
|
|
+ return _current_applied_patches_info;
|
|
|
}
|
|
|
|
|
|
void PatchInstaller::installPatch(QString patch_name, LOTRO_DAT::Database* database) {
|
|
|
- if (!Settings::getValue("DatabaseNeedInstall/" + patch_name).toBool()) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
if (patch_name == "loadscreen") {
|
|
|
installLoadscreens(database);
|
|
|
return;
|
|
@@ -128,6 +126,20 @@ void PatchInstaller::installPatch(QString patch_name, LOTRO_DAT::Database* datab
|
|
|
orig_files_db.exec(query);
|
|
|
}
|
|
|
}
|
|
|
+ _current_applied_patches_info.has_no_patch_mark = false;
|
|
|
+ const QString hashsum = Settings::getValue("PatchDatabases/" + patch_name + "/hashsum").toString();
|
|
|
+ if (patch_name == "text") {
|
|
|
+ _current_applied_patches_info.texts_patch_hashsum = hashsum;
|
|
|
+ } else if (patch_name == "image") {
|
|
|
+ _current_applied_patches_info.images_patch_hashsum = hashsum;
|
|
|
+ } else if (patch_name == "sound") {
|
|
|
+ _current_applied_patches_info.sounds_patch_hashsum = hashsum;
|
|
|
+ } else if (patch_name == "texture") {
|
|
|
+ _current_applied_patches_info.textures_patch_hashsum = hashsum;
|
|
|
+ } else if (patch_name == "font") {
|
|
|
+ _current_applied_patches_info.fonts_patch_hashsum = hashsum;
|
|
|
+ }
|
|
|
+ insertPatchesInfoInDatFile(_current_applied_patches_info);
|
|
|
Settings::setValue("DatabaseNeedInstall/" + patch_name, false);
|
|
|
return;
|
|
|
}
|
|
@@ -177,6 +189,9 @@ void PatchInstaller::installLoadscreens(LOTRO_DAT::Database* database) {
|
|
|
}
|
|
|
|
|
|
Settings::setValue("DatabaseNeedInstall/loadscreen", false);
|
|
|
+ _current_applied_patches_info.has_no_patch_mark = false;
|
|
|
+ _current_applied_patches_info.loadscreens_patch_hashsum = Settings::getValue("PatchDatabases/loadscreen/hashsum").toString();
|
|
|
+ insertPatchesInfoInDatFile(_current_applied_patches_info);
|
|
|
}
|
|
|
|
|
|
void PatchInstaller::installVideos(LOTRO_DAT::Database* database) {
|
|
@@ -229,9 +244,46 @@ void PatchInstaller::installVideos(LOTRO_DAT::Database* database) {
|
|
|
download_video_finished_videos++;
|
|
|
}
|
|
|
|
|
|
+ _current_applied_patches_info.has_no_patch_mark = false;
|
|
|
+ _current_applied_patches_info.videos_patch_hashsum = Settings::getValue("PatchDatabases/video/hashsum").toString();
|
|
|
+ insertPatchesInfoInDatFile(_current_applied_patches_info);
|
|
|
Settings::setValue("DatabaseNeedInstall/video", false);
|
|
|
}
|
|
|
|
|
|
+PatchInstaller::AppliedPatchesInfo PatchInstaller::getAppliedPatchesInfoFromDatFile() {
|
|
|
+ PatchInstaller::AppliedPatchesInfo result;
|
|
|
+ const LOTRO_DAT::SubfileData patch_versions_file = client_local_file_->GetFile(_applied_patches_file_id);
|
|
|
+ if (patch_versions_file.Empty()) {
|
|
|
+ result.has_no_patch_mark = true;
|
|
|
+ } else {
|
|
|
+ result.has_no_patch_mark = false;
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+}
|
|
|
+
|
|
|
+void PatchInstaller::insertPatchesInfoInDatFile(const PatchInstaller::AppliedPatchesInfo& info) {
|
|
|
+ LOTRO_DAT::SubfileData file_data;
|
|
|
+ file_data.options["fid"] = _applied_patches_file_id;
|
|
|
+ file_data.options["ext"] = LOTRO_DAT::StringFromFileType(LOTRO_DAT::TEXT);
|
|
|
+
|
|
|
+ QString patches_info_data = "1::::::[HI_FROM_ENDEVIR_V2.0\n";
|
|
|
+ patches_info_data += "TEXTS:" + info.texts_patch_hashsum + "\n";
|
|
|
+ patches_info_data += "IMAGES:" + info.images_patch_hashsum + "\n";
|
|
|
+ patches_info_data += "SOUNDS:" + info.sounds_patch_hashsum + "\n";
|
|
|
+ patches_info_data += "LOADSCREENS:" + info.loadscreens_patch_hashsum + "\n";
|
|
|
+ patches_info_data += "TEXTURES:" + info.textures_patch_hashsum + "\n";
|
|
|
+ patches_info_data += "FONTS:" + info.fonts_patch_hashsum + "\n";
|
|
|
+ patches_info_data += "VIDEOS:" + info.videos_patch_hashsum + "\n";
|
|
|
+ patches_info_data += "]";
|
|
|
+
|
|
|
+ file_data.text_data = patches_info_data.toStdU16String();
|
|
|
+ client_local_file_->PatchFile(file_data);
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
void PatchInstaller::init()
|
|
@@ -249,21 +301,6 @@ void PatchInstaller::init()
|
|
|
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)) {
|
|
|
- qCritical() << __FUNCTION__ << "DatFiles do not exist!" << client_local_filepath << " " << client_general_filepath;
|
|
|
- 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!";
|
|
|
- }
|
|
|
-
|
|
|
|
|
|
|
|
|
auto client_local_init_res = client_local_file_->Init(client_local_filepath.toStdString());
|
|
@@ -297,6 +334,7 @@ void PatchInstaller::init()
|
|
|
<< QString::fromStdString(client_general_file_->GetFilename())
|
|
|
<< QString::fromStdString(client_local_file_->GetFilename());
|
|
|
|
|
|
+ _current_applied_patches_info = getAppliedPatchesInfoFromDatFile();
|
|
|
emit successfullyInitialized();
|
|
|
}
|
|
|
|
|
@@ -390,13 +428,32 @@ void PatchInstaller::startPatchInstallationChain() {
|
|
|
current_status.finished_parts = 0;
|
|
|
|
|
|
for (const QString& patch: patches) {
|
|
|
- if (!Settings::getValue("DatabaseNeedInstall/" + patch).toBool()) {
|
|
|
+ if (!Settings::getValue("DatabaseDownload/" + patch).toBool()) {
|
|
|
+ qDebug() << "Skipping patch " << patch << " because its disabled";
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
const QString patch_hashsum = Settings::getValue("PatchDatabases/" + patch + "/hashsum").toString();
|
|
|
const QString patch_filename = Settings::getValue("PatchDatabases/" + patch + "/path").toString();
|
|
|
|
|
|
+ QString hashsum_in_dat_file = "";
|
|
|
+ if (patch == "text") {
|
|
|
+ hashsum_in_dat_file = _current_applied_patches_info.texts_patch_hashsum;
|
|
|
+ } else if (patch == "image") {
|
|
|
+ hashsum_in_dat_file = _current_applied_patches_info.images_patch_hashsum;
|
|
|
+ } else if (patch == "sound") {
|
|
|
+ hashsum_in_dat_file = _current_applied_patches_info.sounds_patch_hashsum;
|
|
|
+ } else if (patch == "texture") {
|
|
|
+ hashsum_in_dat_file = _current_applied_patches_info.textures_patch_hashsum;
|
|
|
+ } else if (patch == "font") {
|
|
|
+ hashsum_in_dat_file = _current_applied_patches_info.fonts_patch_hashsum;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (patch_hashsum == hashsum_in_dat_file) {
|
|
|
+ qDebug() << "Skipping patch " << patch << " because its hashsum (" << patch_hashsum << ") is equal to hashsum in dat file (" << hashsum_in_dat_file << ")";
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
const QString real_file_hashsum = FileSystem::fileHash(patch_filename);
|
|
|
if (!FileSystem::fileExists(patch_filename) || real_file_hashsum != patch_hashsum) {
|
|
|
qCritical() << "PatchInstallation: Incorrect patch file: " << patch_filename << ", hashsum: " << real_file_hashsum << ", expected: " << patch_hashsum;
|