mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-28 08:48:48 +02:00
Merge pull request #2880 from Nordsoft91/fix-1787
This commit is contained in:
commit
dc6144bffe
@ -131,7 +131,7 @@ void CDownloadManager::downloadProgressChanged(qint64 bytesReceived, qint64 byte
|
|||||||
|
|
||||||
entry.file->write(entry.reply->readAll());
|
entry.file->write(entry.reply->readAll());
|
||||||
entry.bytesReceived = bytesReceived;
|
entry.bytesReceived = bytesReceived;
|
||||||
if(bytesTotal)
|
if(bytesTotal > entry.totalSize)
|
||||||
entry.totalSize = bytesTotal;
|
entry.totalSize = bytesTotal;
|
||||||
|
|
||||||
quint64 total = 0;
|
quint64 total = 0;
|
||||||
|
@ -590,6 +590,8 @@ void CModListView::downloadFile(QString file, QString url, QString description,
|
|||||||
connect(dlManager, SIGNAL(finished(QStringList,QStringList,QStringList)),
|
connect(dlManager, SIGNAL(finished(QStringList,QStringList,QStringList)),
|
||||||
this, SLOT(downloadFinished(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);
|
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)
|
void CModListView::downloadProgress(qint64 current, qint64 max)
|
||||||
{
|
{
|
||||||
// display progress, in megabytes
|
// display progress, in megabytes
|
||||||
|
ui->progressBar->setVisible(true);
|
||||||
ui->progressBar->setMaximum(max / (1024 * 1024));
|
ui->progressBar->setMaximum(max / (1024 * 1024));
|
||||||
ui->progressBar->setValue(current / (1024 * 1024));
|
ui->progressBar->setValue(current / (1024 * 1024));
|
||||||
}
|
}
|
||||||
@ -640,15 +643,16 @@ void CModListView::downloadFinished(QStringList savedFiles, QStringList failedFi
|
|||||||
doInstallFiles = true;
|
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->deleteLater();
|
||||||
dlManager = nullptr;
|
dlManager = nullptr;
|
||||||
|
|
||||||
|
ui->progressBar->setMaximum(0);
|
||||||
|
ui->progressBar->setValue(0);
|
||||||
|
|
||||||
if(doInstallFiles)
|
if(doInstallFiles)
|
||||||
installFiles(savedFiles);
|
installFiles(savedFiles);
|
||||||
|
|
||||||
|
hideProgressBar();
|
||||||
emit modsChanged();
|
emit modsChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -751,7 +755,10 @@ void CModListView::installMods(QStringList archives)
|
|||||||
}
|
}
|
||||||
|
|
||||||
for(int i = 0; i < modNames.size(); i++)
|
for(int i = 0; i < modNames.size(); i++)
|
||||||
|
{
|
||||||
|
ui->progressBar->setFormat(tr("Installing mod %1").arg(modNames[i]));
|
||||||
manager->installMod(modNames[i], archives[i]);
|
manager->installMod(modNames[i], archives[i]);
|
||||||
|
}
|
||||||
|
|
||||||
std::function<void(QString)> enableMod;
|
std::function<void(QString)> enableMod;
|
||||||
|
|
||||||
|
@ -284,8 +284,19 @@ bool CModManager::doInstallMod(QString modname, QString archivePath)
|
|||||||
QString modDirName = ::detectModArchive(archivePath, modname, filesToExtract);
|
QString modDirName = ::detectModArchive(archivePath, modname, filesToExtract);
|
||||||
if(!modDirName.size())
|
if(!modDirName.size())
|
||||||
return addError(modname, "Mod archive is invalid or corrupted");
|
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);
|
removeModDir(destDir + modDirName);
|
||||||
return addError(modname, "Failed to extract mod data");
|
return addError(modname, "Failed to extract mod data");
|
||||||
|
@ -53,4 +53,7 @@ public:
|
|||||||
bool canUninstallMod(QString mod);
|
bool canUninstallMod(QString mod);
|
||||||
bool canEnableMod(QString mod);
|
bool canEnableMod(QString mod);
|
||||||
bool canDisableMod(QString mod);
|
bool canDisableMod(QString mod);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void extractionProgress(qint64 currentAmount, qint64 maxAmount);
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user