Browse Source

Finished with basic patch installation functionality

Ivan Arkhipov 3 years ago
parent
commit
7401e6e3a5

+ 1 - 1
import/LotroDat/SubfileData.h

@@ -25,7 +25,7 @@ namespace LOTRO_DAT {
         }
 
         bool Empty() const {
-            return binary_data.size() == 0 && text_data.length() == 0;
+            return binary_data.size() == 0 && text_data.length() == 0 && options.IsNull();
         }
 
         bool operator == (const SubfileData &other) {

+ 20 - 23
src/Legacy/models/patchinstaller.cpp

@@ -91,7 +91,7 @@ void PatchInstaller::installPatch(QString patch_name, LOTRO_DAT::Database* datab
 
         const int category = file.options["cat"] ? file.options["cat"].as<int>() : -1;
         QString component_name = getComponentNameFromId(category);
-        if (!Settings::getValue("Components/" + component_name).toBool()) {
+        if (category != -1 && !Settings::getValue("Components/" + component_name).toBool()) {
             continue;
         }
         const int dat_id = file.options["did"] ? file.options["did"].as<int>() : 0;
@@ -156,19 +156,22 @@ void PatchInstaller::installLoadscreens(LOTRO_DAT::Database* database) {
 }
 
 void PatchInstaller::installVideos(LOTRO_DAT::Database* database) {
+
     current_status.finished_parts += database->CountRows();
     emit progressChanged(current_status);
 
+    download_video_total_videos = database->CountRows();
+    download_video_finished_videos = 0;
+
     if (!Settings::getValue("Components/videos").toBool()) {
         Settings::setValue("DatabaseNeedInstall/video", false);
         return;
     }
-    video_downloaders_status.clear();
-    QVector<Downloader*> video_downloaders;
 
     LOTRO_DAT::SubfileData file;
     while (!(file = database->GetNextFile()).Empty()) {
         if (!file.options["name"] || !file.options["url"] || !file.options["hash"] || !file.options["folder"]) {
+            download_video_finished_videos++;
             continue;
         }
 
@@ -178,27 +181,28 @@ void PatchInstaller::installVideos(LOTRO_DAT::Database* database) {
         const QString folder = QString::fromStdString(file.options["folder"].as<std::string>());
 
         const QString full_filename = Settings::getValue("Lotro/game_path").toString() + "/" + folder + "/" + filename;
+
         FileSystem::createFilePath(full_filename);
         if (FileSystem::fileExists(full_filename) && FileSystem::fileHash(full_filename) == hash) {
+            download_video_finished_videos++;
             continue;
         }
 
-        QFile target_file(full_filename);
-        target_file.open(QIODevice::WriteOnly);
+        QFile* target_file = new QFile(full_filename);
+        target_file->open(QIODevice::WriteOnly);
 
         Downloader* video_downloader = new Downloader(this);
-        video_downloaders_status[video_downloader] = Downloader::Status();
+        connect(video_downloader, &Downloader::progressChanged, this, &PatchInstaller::onDownloaderProgressChanged);
         video_downloader->setUrl(url);
-        video_downloader->targetFile = &target_file;
+        video_downloader->targetFile = target_file;
         video_downloader->start();
-        video_downloaders.push_back(video_downloader);
-    }
+        video_downloader->waitForDownloaded();
+        video_downloader->targetFile->close();
+        video_downloader->targetFile->deleteLater();
+        video_downloader->targetFile = nullptr;
+        video_downloader->deleteLater();
 
-    for (Downloader* downloader: video_downloaders) {
-        downloader->waitForDownloaded();
-        downloader->targetFile->close();
-        downloader->targetFile = nullptr;
-        downloader->deleteLater();
+        download_video_finished_videos++;
     }
 
     Settings::setValue("DatabaseNeedInstall/video", false);
@@ -375,7 +379,6 @@ void PatchInstaller::startPatchInstallationChain() {
             qCritical() << "PatchInstallation: failed to initialize db " << patch_filename;
             continue;
         }
-        LOTRO_DAT::SubfileData data = db->GetNextFile();
         patch_databases[patch] = db;
         current_status.total_parts += db->CountRows();
     }
@@ -394,12 +397,6 @@ void PatchInstaller::startPatchInstallationChain() {
 
 
 // ############## PRIVATE SLOTS ############## //
-void PatchInstaller::onDownloaderProgressChanged(Downloader* context, Downloader::Status progress) {
-    video_downloaders_status[context] = progress;
-
-    Downloader::Status cumulative_status;
-    for (const Downloader::Status& status: video_downloaders_status.values()) {
-        cumulative_status = cumulative_status + status;
-    }
-    emit videosDownloadProgressChanged(cumulative_status);
+void PatchInstaller::onDownloaderProgressChanged(Downloader*, Downloader::Status progress) {
+    emit videosDownloadProgressChanged(download_video_finished_videos, download_video_total_videos, progress);
 }

+ 3 - 2
src/Legacy/models/patchinstaller.h

@@ -63,7 +63,7 @@ private slots:
 signals:
     void started();
     void progressChanged(PatchInstaller::Status status);
-    void videosDownloadProgressChanged(Downloader::Status status);
+    void videosDownloadProgressChanged(int finished_videos, int total_videos, Downloader::Status status);
     void finished();
 
 private:
@@ -71,7 +71,8 @@ private:
     LOTRO_DAT::DatFile* client_general_file_;
 
     Status current_status;
-    QMap<Downloader*, Downloader::Status> video_downloaders_status;
+    int download_video_finished_videos = 0;
+    int download_video_total_videos = 0;
 };
 
 Q_DECLARE_METATYPE(PatchInstaller::Status)

+ 11 - 8
src/Legacy/widgets/statuswidget.cpp

@@ -38,6 +38,7 @@ StatusWidget::StatusWidget(QWidget *parent)
     connect(&PatchInstaller::instance(), &PatchInstaller::started, this, &StatusWidget::onPatchInstallerStarted);
     connect(&PatchInstaller::instance(), &PatchInstaller::progressChanged, this, &StatusWidget::onPatchInstallerProgressChanged);
     connect(&PatchInstaller::instance(), &PatchInstaller::finished, this, &StatusWidget::onPatchInstallerFinished);
+    connect(&PatchInstaller::instance(), &PatchInstaller::videosDownloadProgressChanged, this, &StatusWidget::onPatchInstallerVideoProgressChanged);
 
     generateRandomTooltipMessage();
     random_tooltip_generator_timer_.setInterval(5 * 1000);
@@ -252,7 +253,7 @@ void StatusWidget::onPatchDownloaderFinished() {
 }
 
 void StatusWidget::onPatchDownloaderProgressChanged(Downloader::Status status) {
-    if (last_statusbar_update_time_.elapsed() > 650) {
+    if (last_statusbar_update_time_.elapsed() > 450) {
         double download_percent = double(status.downloaded_bytes) * 100.0 / double(status.total_bytes);
         QString text = "Загрузка данных: " + QString::number(download_percent, 'f', 1) + "% ("
                      + Downloader::getSizeFormatted(status.downloaded_bytes) + "/"
@@ -280,23 +281,25 @@ void StatusWidget::onPatchInstallerFinished() {
 }
 
 void StatusWidget::onPatchInstallerProgressChanged(PatchInstaller::Status status) {
-    if (last_statusbar_update_time_.elapsed() > 650 || status.finished_parts == 0) {
+    if (last_statusbar_update_time_.elapsed() > 450 || status.finished_parts == 0) {
         QString text = "Установка русификации: "
                      + QString::number(double(status.finished_parts) * 100.0 / double(status.total_parts), 'f', 1)
-                     + "% (" + QString::number(status.finished_parts)
+                     + "%\n(" + QString::number(status.finished_parts)
                      + " фрагментов из " + QString::number(status.total_parts) + ")";
         setToolTipMessage(text, E_PROCESS);
         last_statusbar_update_time_.restart();
     }
 }
 
-void StatusWidget::onPatchInstallerVideoProgressChanged(Downloader::Status status) {
-    if (last_statusbar_update_time_.elapsed() > 650) {
+void StatusWidget::onPatchInstallerVideoProgressChanged(int finished_videos, int total_videos, Downloader::Status status) {
+    if (last_statusbar_update_time_.elapsed() > 450) {
         double download_percent = double(status.downloaded_bytes) * 100.0 / double(status.total_bytes);
-        QString text = "Загрузка видеороликов: " + QString::number(download_percent, 'f', 1) + "% ("
+        QString text = "Загрузка и установка видеороликов ("
+                     + QString::number(finished_videos + 1) + " из " + QString::number(total_videos)
+                     + ")\n"
+                     + "Загружено: " + QString::number(download_percent, 'f', 1) + "% ("
                      + Downloader::getSizeFormatted(status.downloaded_bytes) + "/"
-                     + Downloader::getSizeFormatted(status.total_bytes) + ")\n"
-                     + "До конца загрузки: " + Downloader::getElapsedTimeFormatted(status.elapsed_time);
+                     + Downloader::getSizeFormatted(status.total_bytes) + ")";
         setToolTipMessage(text, E_PROCESS);
         last_statusbar_update_time_.restart();
     }

+ 1 - 1
src/Legacy/widgets/statuswidget.h

@@ -65,7 +65,7 @@ private slots:
 
     void onPatchInstallerProgressChanged(PatchInstaller::Status status);
 
-    void onPatchInstallerVideoProgressChanged(Downloader::Status status);
+    void onPatchInstallerVideoProgressChanged(int finished_videos, int total_videos, Downloader::Status status);
 
     void on_game_button_clicked();