1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-24 08:32:34 +02:00

Merge pull request #2880 from Nordsoft91/fix-1787

This commit is contained in:
Nordsoft91 2023-09-20 22:19:20 +02:00 committed by GitHub
commit dc6144bffe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 6 deletions

View File

@ -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;

View File

@ -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<void(QString)> enableMod;

View File

@ -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");

View File

@ -53,4 +53,7 @@ public:
bool canUninstallMod(QString mod);
bool canEnableMod(QString mod);
bool canDisableMod(QString mod);
signals:
void extractionProgress(qint64 currentAmount, qint64 maxAmount);
};