diff --git a/launcher/modManager/cdownloadmanager_moc.cpp b/launcher/modManager/cdownloadmanager_moc.cpp index 3a9c86471..a0e3eddaa 100644 --- a/launcher/modManager/cdownloadmanager_moc.cpp +++ b/launcher/modManager/cdownloadmanager_moc.cpp @@ -131,7 +131,7 @@ void CDownloadManager::downloadProgressChanged(qint64 bytesReceived, qint64 byte entry.file->write(entry.reply->readAll()); entry.bytesReceived = bytesReceived; - if(bytesTotal) + if(bytesTotal > entry.totalSize) entry.totalSize = bytesTotal; quint64 total = 0; diff --git a/launcher/modManager/cmodlistview_moc.cpp b/launcher/modManager/cmodlistview_moc.cpp index 8adeb05e7..f4e8c7be5 100644 --- a/launcher/modManager/cmodlistview_moc.cpp +++ b/launcher/modManager/cmodlistview_moc.cpp @@ -590,6 +590,8 @@ void CModListView::downloadFile(QString file, QString url, QString description, connect(dlManager, SIGNAL(finished(QStringList,QStringList,QStringList)), this, SLOT(downloadFinished(QStringList,QStringList,QStringList))); + connect(manager.get(), SIGNAL(extractionProgress(qint64,qint64)), + this, SLOT(downloadProgress(qint64,qint64))); connect(modModel, &CModListModel::dataChanged, filterModel, &QAbstractItemModel::dataChanged); @@ -606,6 +608,7 @@ void CModListView::downloadFile(QString file, QString url, QString description, void CModListView::downloadProgress(qint64 current, qint64 max) { // display progress, in megabytes + ui->progressBar->setVisible(true); ui->progressBar->setMaximum(max / (1024 * 1024)); ui->progressBar->setValue(current / (1024 * 1024)); } @@ -640,15 +643,16 @@ void CModListView::downloadFinished(QStringList savedFiles, QStringList failedFi doInstallFiles = true; } - // remove progress bar after some delay so user can see that download was complete and not interrupted. - QTimer::singleShot(1000, this, SLOT(hideProgressBar())); - dlManager->deleteLater(); dlManager = nullptr; + + ui->progressBar->setMaximum(0); + ui->progressBar->setValue(0); if(doInstallFiles) installFiles(savedFiles); + hideProgressBar(); emit modsChanged(); } @@ -751,7 +755,10 @@ void CModListView::installMods(QStringList archives) } for(int i = 0; i < modNames.size(); i++) + { + ui->progressBar->setFormat(tr("Installing mod %1").arg(modNames[i])); manager->installMod(modNames[i], archives[i]); + } std::function enableMod; diff --git a/launcher/modManager/cmodmanager.cpp b/launcher/modManager/cmodmanager.cpp index 8c7ddcae4..4e0c37e59 100644 --- a/launcher/modManager/cmodmanager.cpp +++ b/launcher/modManager/cmodmanager.cpp @@ -284,8 +284,19 @@ bool CModManager::doInstallMod(QString modname, QString archivePath) QString modDirName = ::detectModArchive(archivePath, modname, filesToExtract); if(!modDirName.size()) return addError(modname, "Mod archive is invalid or corrupted"); - - if(!ZipArchive::extract(qstringToPath(archivePath), qstringToPath(destDir), filesToExtract)) + + auto futureExtract = std::async(std::launch::async, [&archivePath, &destDir, &filesToExtract]() + { + return ZipArchive::extract(qstringToPath(archivePath), qstringToPath(destDir), filesToExtract); + }); + + while(futureExtract.wait_for(std::chrono::milliseconds(50)) != std::future_status::ready) + { + emit extractionProgress(0, 0); + qApp->processEvents(); + } + + if(!futureExtract.get()) { removeModDir(destDir + modDirName); return addError(modname, "Failed to extract mod data"); diff --git a/launcher/modManager/cmodmanager.h b/launcher/modManager/cmodmanager.h index d2bc6271d..987d1a580 100644 --- a/launcher/modManager/cmodmanager.h +++ b/launcher/modManager/cmodmanager.h @@ -53,4 +53,7 @@ public: bool canUninstallMod(QString mod); bool canEnableMod(QString mod); bool canDisableMod(QString mod); + +signals: + void extractionProgress(qint64 currentAmount, qint64 maxAmount); };