Browse Source

Partially implemented text file patch mark

Ivan Arkhipov 3 years ago
parent
commit
0ecc3bbf1c

+ 0 - 1
src/Legacy/legacyapplication.cpp

@@ -77,7 +77,6 @@ bool LegacyApplication::init() {
     return true;
 }
 
-
 void LegacyApplication::InitModules() {
     modules_init_timer_.stop();
     AppErrorStatus status = CheckAppPrerequesities();

+ 78 - 21
src/Legacy/models/patchinstaller.cpp

@@ -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;
+//        const QString text_data = QString::fromUtf16(reinterpret_cast<const ushort*>(patch_versions_file.binary_data.data()), patch_versions_file.binary_data.size() / sizeof(ushort));
+//        qDebug() << "AAAAAAAAA PATCH INFO TEXT DATA " << text_data;
+    }
+    // TODO: PATCHED BY OLD LEGACY CHECK
+    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);
+}
+
+
 // ############## PUBLIC SLOTS ############## //
 
 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;
-    }
-
-    // Updating file permissions to be sure, that they're not in read-only mode
-
-    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!";
-    }
-
     // Initialising client_local_*.dat file and client_general.dat
 
     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;

+ 15 - 13
src/Legacy/models/patchinstaller.h

@@ -19,18 +19,17 @@ public:
     };
 
     struct AppliedPatchesInfo {
-        bool patched_by_old_legacy;
-        bool has_no_patch_mark;
-        unsigned long long texts_version;
-        unsigned long long images_version;
-        unsigned long long sounds_version;
-        unsigned long long loadscreens_version;
-        unsigned long long textures_version;
-        unsigned long long fonts_version;
-        unsigned long long videos_version;
+        bool patched_by_old_legacy = false;
+        bool has_no_patch_mark = false;
+        QString texts_patch_hashsum = "";
+        QString images_patch_hashsum = "";
+        QString sounds_patch_hashsum = "";
+        QString loadscreens_patch_hashsum = "";
+        QString textures_patch_hashsum = "";
+        QString fonts_patch_hashsum = "";
+        QString videos_patch_hashsum = "";
     };
 
-
 public:
     static PatchInstaller& instance() {
         static PatchInstaller instance_;
@@ -41,9 +40,6 @@ public:
 
     AppliedPatchesInfo getPatchesInfo(); // TODO: Implement
 
-//    TODO: bool NotPatched();
-
-
 private:
     Q_DISABLE_COPY(PatchInstaller)
 
@@ -62,6 +58,10 @@ private:
 
     void installVideos(LOTRO_DAT::Database* database);
 
+    AppliedPatchesInfo getAppliedPatchesInfoFromDatFile();
+
+    void insertPatchesInfoInDatFile(const AppliedPatchesInfo& info);
+
 public slots:
     void deinit();
     void init();
@@ -91,7 +91,9 @@ private:
                                        "`options` TEXT NOT NULL)";
 
 //    const QString upset_table_value_query = "INSERT INTO `patch_data` (`file_id`, ``) VALUES (?);";
+    AppliedPatchesInfo _current_applied_patches_info;
     Status current_status;
+    const int _applied_patches_file_id = 0x2500F0F0;
     int download_video_finished_videos = 0;
     int download_video_total_videos = 0;
 };

+ 20 - 20
src/Legacy/widgets/translationcomponents.cpp

@@ -53,19 +53,19 @@ TranslationComponents::~TranslationComponents()
 void TranslationComponents::resetSwitchesToDefault() {
     PatchInstaller::AppliedPatchesInfo info = PatchInstaller::instance().getPatchesInfo();
 
-    Settings::setValue("DatabaseDownload/text", info.texts_version != 0);
-    Settings::setValue("DatabaseDownload/font", info.texts_version != 0);
-    Settings::setValue("DatabaseDownload/image", info.images_version != 0);
-    Settings::setValue("DatabaseDownload/loadscreen", info.loadscreens_version != 0);
-    Settings::setValue("DatabaseDownload/texture", info.texts_version != 0);
-    Settings::setValue("DatabaseDownload/sound", info.sounds_version != 0);
-    Settings::setValue("DatabaseDownload/video", info.texts_version != 0);
-
-    ui->texts_block_switch->setValue(info.texts_version != 0 && info.fonts_version != 0);
-    ui->graphics_block_switch->setValue(info.images_version != 0 && info.textures_version != 0);
-    ui->video_block_switch->setValue(info.videos_version != 0);
-    ui->audio_block_switch->setValue(info.sounds_version != 0);
-    ui->loadscreens_block_switch->setValue(info.loadscreens_version != 0);
+    Settings::setValue("DatabaseDownload/text", info.texts_patch_hashsum != "");
+    Settings::setValue("DatabaseDownload/font", info.texts_patch_hashsum != "");
+    Settings::setValue("DatabaseDownload/image", info.images_patch_hashsum != "");
+    Settings::setValue("DatabaseDownload/loadscreen", info.loadscreens_patch_hashsum != "");
+    Settings::setValue("DatabaseDownload/texture", info.textures_patch_hashsum != "");
+    Settings::setValue("DatabaseDownload/sound", info.sounds_patch_hashsum != "");
+    Settings::setValue("DatabaseDownload/video", info.videos_patch_hashsum != "");
+
+    ui->texts_block_switch->setValue(info.texts_patch_hashsum != 0 && info.fonts_patch_hashsum != 0);
+    ui->graphics_block_switch->setValue(info.images_patch_hashsum != 0 && info.textures_patch_hashsum != 0);
+    ui->video_block_switch->setValue(info.videos_patch_hashsum != 0);
+    ui->audio_block_switch->setValue(info.sounds_patch_hashsum != 0);
+    ui->loadscreens_block_switch->setValue(info.loadscreens_patch_hashsum != 0);
 }
 
 void TranslationComponents::disableControls() {
@@ -118,13 +118,13 @@ void TranslationComponents::onLoadscreensChange(bool new_value) {
 
 void TranslationComponents::checkIfSettingsDoNotMatchCurrentDatState() {
     PatchInstaller::AppliedPatchesInfo info = PatchInstaller::instance().getPatchesInfo();
-    bool texts_enabled = info.texts_version != 0;
-    bool images_enabled = info.images_version != 0;
-    bool sounds_enabled = info.sounds_version != 0;
-    bool loadscreens_enabled = info.loadscreens_version != 0;
-    bool textures_enabled = info.textures_version != 0;
-    bool fonts_enabled = info.fonts_version != 0;
-    bool videos_enabled = info.videos_version != 0;
+    bool texts_enabled = info.texts_patch_hashsum != "";
+    bool images_enabled = info.images_patch_hashsum != "";
+    bool sounds_enabled = info.sounds_patch_hashsum != "";
+    bool loadscreens_enabled = info.loadscreens_patch_hashsum != "";
+    bool textures_enabled = info.textures_patch_hashsum != "";
+    bool fonts_enabled = info.fonts_patch_hashsum != "";
+    bool videos_enabled = info.videos_patch_hashsum != "";
 
     bool match = Settings::getValue("DatabaseDownload/text").toBool() == texts_enabled &&
                  Settings::getValue("DatabaseDownload/font").toBool() == fonts_enabled &&