Browse Source

Added more informative logs

Ivan Arkhipov 4 years ago
parent
commit
4ec43b7d64

+ 6 - 6
src/Legacy/models/patchdownloader.cpp

@@ -60,7 +60,7 @@ void PatchDownloader::onDownloaderFinished(Downloader* context) {
 }
 
 void PatchDownloader::checkForUpdates() {
-    qDebug() << __FUNCTION__ << "Started check for updates!";
+    qInfo() << "PatchDownloader: Started check for updates!";
     QUrlQuery query; // query for building GET-request aka patch-version
 
     for (const QString& patch: patches_) {
@@ -113,9 +113,9 @@ void PatchDownloader::checkForUpdates() {
             const QString patch_hashsum = FileSystem::fileExists(patch_filename) ? FileSystem::fileHash(patch_filename) : "none";
             if (patch_hashsum != patch_data[1]) {
                 there_are_available_patch_updates = true;
-                qDebug() << "CheckForUpdates: Existing patch " << patch << " checksum (" << patch_hashsum << ") does not match actual (" << patch_data[1] << ")";
+                qInfo() << "CheckForUpdates: Existing patch " << patch << " checksum (" << patch_hashsum << ") does not match actual (" << patch_data[1] << ")";
             } else {
-                qDebug() << "CheckForUpdates: Existing patch " << patch << " checksum (" << patch_hashsum << ") matches actual (" << patch_data[1] << ")";
+                qInfo() << "CheckForUpdates: Existing patch " << patch << " checksum (" << patch_hashsum << ") matches actual (" << patch_data[1] << ")";
 
             }
         }
@@ -128,7 +128,7 @@ void PatchDownloader::downloadDatabases() {
     for (const QString& patch: patches_) {
         QString target_filename = Settings::getValue("PatchDatabases/" + patch + "/path").toString();
 
-        qDebug() << __FUNCTION__ << patch << ": Checking if there's need to download patch";
+        qInfo() << "PatchDownloader::downloadDatabases: " << patch << ": Checking if there's need to download patch";
         if (!needDownloadDatabase(patch)) {
             qInfo() << patch << ": file " << target_filename << " is up-to-date, no need to download";
             continue;
@@ -137,11 +137,11 @@ void PatchDownloader::downloadDatabases() {
         FileSystem::createFilePath(target_filename);
         QFile* target_file = new QFile(target_filename);
         if (!target_file->open(QIODevice::ReadWrite | QIODevice::Truncate)) {
-            qWarning() << __FUNCTION__ << patch << "Cannot open file " << target_filename;
+            qWarning() << "PatchDownloader::downloadDatabases: " << patch << "Cannot open file " << target_filename;
             continue;
         }
 
-        qInfo() << __FUNCTION__ << patch << ": beginning download of file " << target_filename;
+        qInfo() << "PatchDownloader::downloadDatabases: " << patch << ": beginning download of file " << target_filename;
 
         patch_downloaders_[patch]->setUrl(Settings::getValue("PatchDatabases/" + patch + "/url").toUrl());
         patch_downloaders_[patch]->targetFile = target_file;

+ 24 - 30
src/Legacy/models/patchinstaller.cpp

@@ -96,7 +96,7 @@ void PatchInstaller::installPatch(QString patch_name, LOTRO_DAT::Database* datab
     DatOriginalFilesDatabase orig_files_db(database_path);
     LOTRO_DAT::SubfileData file;
     qDebug() << "Total files in database " << database->CountRows();
-    qDebug() << "Patching all files from database..." << database;
+    qInfo() << "Patching all files from database..." << database_path;
     while (!(file = database->GetNextFile()).Empty()) {
         if (!file.options["fid"]) {
             continue;
@@ -166,22 +166,22 @@ void PatchInstaller::installPatch(QString patch_name, LOTRO_DAT::Database* datab
         _current_applied_patches_info.textures_patch_hashsum = hashsum;
     }
     orig_files_db.closeDatabase();
+    insertPatchesInfoInDatFile(_current_applied_patches_info);
+
     if (patch_name == "video") {
         installVideos(database);
     }
 
     if (patch_name == "loadscreen") {
         installLoadscreens(database);
-        return;
     }
 
-    insertPatchesInfoInDatFile(_current_applied_patches_info);
-    return;
+    qInfo() << "Successfully installed patch " << patch_name;
 }
 
 void PatchInstaller::installOriginalPatch(QString patch_name)
 {
-    qDebug() << "Installing original version of patch " << patch_name;
+    qInfo() << "PatchInstaller: Installing original version of patch " << patch_name;
     const QString locale_prefix = Settings::getValue("Lotro/original_locale").toString();
     const QString database_path = QApplication::applicationDirPath() + "/data/" + patch_name + "_" + locale_prefix + "_orig.db";
     const QString database_path_old = QApplication::applicationDirPath() + "/data/" + patch_name + "_orig.db";
@@ -235,6 +235,8 @@ void PatchInstaller::installOriginalPatch(QString patch_name)
         _current_applied_patches_info.loadscreens_patch_hashsum = "";
     }
     insertPatchesInfoInDatFile(_current_applied_patches_info);
+
+    qInfo() << "Successfully installed original version of patch" << patch_name;
 }
 
 void PatchInstaller::installLoadscreens(LOTRO_DAT::Database* database) {
@@ -284,6 +286,7 @@ void PatchInstaller::installLoadscreens(LOTRO_DAT::Database* database) {
 }
 
 void PatchInstaller::installVideos(LOTRO_DAT::Database* database) {
+    qInfo() << "PatchInstaller: Starting downloading videos";
     current_status.finished_parts += database->CountRows();
     emit progressChanged(current_status);
 
@@ -303,9 +306,11 @@ void PatchInstaller::installVideos(LOTRO_DAT::Database* database) {
 
         const QString full_filename = Settings::getValue("Lotro/game_path").toString() + "/" + folder + "/" + filename;
 
+        qInfo() << "PatchInstaller::installVideos: Processing file " << filename << " with patch hash " << hash;
         FileSystem::createFilePath(full_filename);
         if (FileSystem::fileExists(full_filename) && FileSystem::fileHash(full_filename) == hash) {
             download_video_finished_videos++;
+            qInfo() << "PatchInstaller::installVideos: File " << filename << " hash matches patch, skipping download";
             continue;
         }
 
@@ -316,19 +321,21 @@ void PatchInstaller::installVideos(LOTRO_DAT::Database* database) {
         connect(video_downloader, &Downloader::progressChanged, this, &PatchInstaller::onDownloaderProgressChanged);
         video_downloader->setUrl(url);
         video_downloader->targetFile = target_file;
+        qInfo() << "PatchInstaller::installVideos: Starting download of file " << filename;
         video_downloader->start();
         video_downloader->waitForDownloaded();
         video_downloader->targetFile->close();
         video_downloader->targetFile->deleteLater();
         video_downloader->targetFile = nullptr;
         video_downloader->deleteLater();
-
+        qInfo() << "PatchInstaller::installVideos: Finished download of file " << filename;
         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);
+    qInfo() << "PatchInstaller: finished downloading videos";
 }
 
 PatchInstaller::AppliedPatchesInfo PatchInstaller::getAppliedPatchesInfoFromDatFile() {
@@ -408,7 +415,7 @@ void PatchInstaller::init()
         // Firstly - deinitializing existing client_local files.
         deinit();
     }
-    qDebug() << __FUNCTION__ << "Starting initialisation of LotroDatManager";
+    qInfo() << "PatchInstaller: Starting initialisation of LotroDatManager";
     qRegisterMetaType<PatchInstaller::Status>();
 
     QString game_folder = Settings::getValue("Lotro/game_path").toString();
@@ -419,24 +426,10 @@ void PatchInstaller::init()
 
     // Initialising client_local_*.dat file and client_general.dat
 
-    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();
-
-        qCritical() << __FUNCTION__ << "Finished LotroDatManager initialisation - error: DatFile initialisation error!";
-        return;
-    }
-
-    // Initializing db for original files backup
-    QString database_path = game_folder + "/LotroLegacy/orig_files.db";
-    if (!FileSystem::fileExists(database_path)) {
-        FileSystem::createFilePath(database_path);
-    }
+    client_local_file_->Init(client_local_filepath.toStdString());
+    client_general_file_->Init(client_general_filepath.toStdString());
 
-    qDebug() << "LotroDatManager initialisation successfull! Dat files: "
+    qInfo() << "PatchInstaller: initialisation successfull! Dat files: "
              << QString::fromStdString(client_general_file_->GetFilename())
              << QString::fromStdString(client_local_file_->GetFilename());
 
@@ -484,7 +477,7 @@ void PatchInstaller::startGame(bool remove_dat_files) {
         args << "-username" << username << "-password" << password;
     }
 
-    qDebug() << __FUNCTION__ << "Starting game with arguments: " << args;
+    qInfo() << "Starting LOTRO. Path =" << game_folder;
 
     deinit();
 
@@ -529,22 +522,22 @@ void PatchInstaller::startPatchInstallationChain(bool force_reinstall_patches) {
         }
 
         if (!force_reinstall_patches && 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 << ")";
+            qInfo() << "PatchInstaller: Skipping patch " << patch << " because its hashsum (" << patch_hashsum << ") is equal to hashsum in dat file (" << hashsum_in_dat_file << ")";
             continue;
         }
         if (force_reinstall_patches) {
-            qDebug() << "Forcelly installing patch " << patch << ". Its hashsum (" << patch_hashsum << "). Hashsum in dat file (" << hashsum_in_dat_file << ")";
+            qInfo() << "PatchInstaller: Force installing patch " << patch << ". Its hashsum (" << patch_hashsum << "). Hashsum in dat file (" << hashsum_in_dat_file << ")";
         }
 
         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;
+            qCritical() << "PatchInstaller: Incorrect patch file: " << patch_filename << ", hashsum: " << real_file_hashsum << ", expected: " << patch_hashsum;
             continue;
         }
 
         LOTRO_DAT::Database* db = new LOTRO_DAT::Database();
         if (!db->InitDatabase(patch_filename.toStdString())) {
-            qCritical() << "PatchInstallation: failed to initialize db " << patch_filename;
+            qCritical() << "PatchInstaller: failed to initialize db " << patch_filename;
             continue;
         }
         patch_databases[patch] = db;
@@ -576,7 +569,7 @@ void PatchInstaller::startPatchInstallationChain(bool force_reinstall_patches) {
         }
 
         if (hashsum_in_dat_file == "") {
-            qDebug() << "Skipping installing original version of patch " << patch << " because hashsum in dat file is already empty";
+            qInfo() << "PatchInstaller: Skipping installing original version of patch " << patch << " because hashsum in dat file is already empty";
             continue;
         }
         patches_to_be_installed_orig_versions.append(patch);
@@ -593,6 +586,7 @@ void PatchInstaller::startPatchInstallationChain(bool force_reinstall_patches) {
     }
 
     for (const QString& patch_name : patches_to_be_installed_orig_versions) {
+        qInfo() << "PatchInstaller: Installing original version of patch " << patch_name;
         installOriginalPatch(patch_name);
     }
 

+ 5 - 0
src/Legacy/widgets/gamesettings.cpp

@@ -23,6 +23,11 @@ GameSettings::GameSettings(QWidget *parent) :
     connect(ui->lotro_base_language_combobox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &GameSettings::onLanguageChanged);
     connect(&PatchInstaller::instance(), &PatchInstaller::started, this, &GameSettings::onPatchTotalOperationsStarted);
     connect(&PatchInstaller::instance(), &PatchInstaller::finished, this, &GameSettings::onPatchTotalOperationsFinished);
+    connect(&PatchInstaller::instance(), &PatchInstaller::initializationStarted, this, &GameSettings::onPatchTotalOperationsStarted);
+    connect(&PatchInstaller::instance(), &PatchInstaller::successfullyInitialized, this, &GameSettings::onPatchTotalOperationsFinished);
+    connect(&LegacyApplication::instance(), &LegacyApplication::ModulesInitializationStarted, this, &GameSettings::onPatchTotalOperationsStarted);
+    connect(&LegacyApplication::instance(), &LegacyApplication::ErrorStatusChanged, this, &GameSettings::onPatchTotalOperationsFinished);
+
     connect(&PatchDownloader::instance(), &PatchDownloader::started, this, &GameSettings::onPatchTotalOperationsStarted);
     connect(&PatchDownloader::instance(), &PatchDownloader::finished, this, &GameSettings::onPatchTotalOperationsFinished);
 }

+ 5 - 0
src/Legacy/widgets/statuswidget.cpp

@@ -55,6 +55,11 @@ StatusWidget::StatusWidget(QWidget *parent)
     connect(&PatchInstaller::instance(), &PatchInstaller::updatedByGameStatusChanged, this, [this](bool updated){_need_to_forcely_patch = updated; updateButtonStatus();});
     connect(&PatchInstaller::instance(), &PatchInstaller::deinitialized, this, &StatusWidget::hideComponentsStatus);
 
+    connect(&PatchInstaller::instance(), &PatchInstaller::initializationStarted, this, [this](){ui->game_button->setDisabled(true);});
+    connect(&PatchInstaller::instance(), &PatchInstaller::successfullyInitialized, this, [this](){ui->game_button->setDisabled(false);});
+    connect(&LegacyApplication::instance(), &LegacyApplication::ModulesInitializationStarted, this, [this](){ui->game_button->setDisabled(true);});
+    connect(&LegacyApplication::instance(), &LegacyApplication::ErrorStatusChanged, this, [this](){ui->game_button->setDisabled(false);});
+
     connect(&LegacyApplication::instance(), &LegacyApplication::ErrorStatusChanged, this, &StatusWidget::onErrorStatusChanged);
 
     connect(ui->b_components_status, &TranslationComponents::needToPatch, this, &StatusWidget::onTranslationComponentsNeedToPatch);