mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-21 17:17:06 +02:00
Support local and download mod size
This commit is contained in:
parent
c45ab07d0b
commit
3ee91ca9dc
@ -18,13 +18,13 @@ CDownloadManager::CDownloadManager()
|
||||
SLOT(downloadFinished(QNetworkReply *)));
|
||||
}
|
||||
|
||||
void CDownloadManager::downloadFile(const QUrl & url, const QString & file)
|
||||
void CDownloadManager::downloadFile(const QUrl & url, const QString & file, qint64 bytesTotal)
|
||||
{
|
||||
QNetworkRequest request(url);
|
||||
FileEntry entry;
|
||||
entry.file.reset(new QFile(CLauncherDirs::get().downloadsPath() + '/' + file));
|
||||
entry.bytesReceived = 0;
|
||||
entry.totalSize = 0;
|
||||
entry.totalSize = bytesTotal;
|
||||
entry.filename = file;
|
||||
|
||||
if(entry.file->open(QIODevice::WriteOnly | QIODevice::Truncate))
|
||||
@ -79,7 +79,7 @@ void CDownloadManager::downloadFinished(QNetworkReply * reply)
|
||||
break;
|
||||
}
|
||||
}
|
||||
downloadFile(qurl, filename);
|
||||
downloadFile(qurl, filename, file.totalSize);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -131,7 +131,8 @@ void CDownloadManager::downloadProgressChanged(qint64 bytesReceived, qint64 byte
|
||||
|
||||
entry.file->write(entry.reply->readAll());
|
||||
entry.bytesReceived = bytesReceived;
|
||||
entry.totalSize = bytesTotal;
|
||||
if(bytesTotal)
|
||||
entry.totalSize = bytesTotal;
|
||||
|
||||
quint64 total = 0;
|
||||
for(auto & entry : currentDownloads)
|
||||
@ -144,7 +145,7 @@ void CDownloadManager::downloadProgressChanged(qint64 bytesReceived, qint64 byte
|
||||
emit downloadProgress(received, total);
|
||||
}
|
||||
|
||||
bool CDownloadManager::downloadInProgress(const QUrl & url)
|
||||
bool CDownloadManager::downloadInProgress(const QUrl & url) const
|
||||
{
|
||||
for(auto & entry : currentDownloads)
|
||||
{
|
||||
|
@ -48,10 +48,10 @@ public:
|
||||
|
||||
// returns true if download with such URL is in progress/queued
|
||||
// FIXME: not sure what's right place for "mod download in progress" check
|
||||
bool downloadInProgress(const QUrl & url);
|
||||
bool downloadInProgress(const QUrl & url) const;
|
||||
|
||||
// returns network reply so caller can connect to required signals
|
||||
void downloadFile(const QUrl & url, const QString & file);
|
||||
void downloadFile(const QUrl & url, const QString & file, qint64 bytesTotal = 0);
|
||||
|
||||
public slots:
|
||||
void downloadFinished(QNetworkReply * reply);
|
||||
|
@ -243,8 +243,11 @@ QString CModListView::genModInfoText(CModEntry & mod)
|
||||
result += replaceIfNotEmpty(mod.getValue("installedVersion"), lineTemplate.arg(tr("Installed version")));
|
||||
result += replaceIfNotEmpty(mod.getValue("latestVersion"), lineTemplate.arg(tr("Latest version")));
|
||||
|
||||
if(mod.getValue("size").isValid())
|
||||
result += replaceIfNotEmpty(CModEntry::sizeToString(mod.getValue("size").toDouble()), lineTemplate.arg(tr("Download size")));
|
||||
if(mod.getValue("localSize").isValid())
|
||||
result += replaceIfNotEmpty(CModEntry::sizeToString(mod.getValue("localSize").toDouble()), lineTemplate.arg(tr("Size")));
|
||||
if((mod.isAvailable() || mod.isUpdateable()) && mod.getValue("size").isValid())
|
||||
result += replaceIfNotEmpty(CModEntry::sizeToString(mod.getValue("size").toDouble() * 1024.0), lineTemplate.arg(tr("Download size")));
|
||||
|
||||
result += replaceIfNotEmpty(mod.getValue("author"), lineTemplate.arg(tr("Authors")));
|
||||
|
||||
if(mod.getValue("licenseURL").isValid())
|
||||
@ -535,7 +538,7 @@ void CModListView::on_updateButton_clicked()
|
||||
auto mod = modModel->getMod(name);
|
||||
// update required mod, install missing (can be new dependency)
|
||||
if(mod.isUpdateable() || !mod.isInstalled())
|
||||
downloadFile(name + ".zip", mod.getValue("download").toString(), "mods");
|
||||
downloadFile(name + ".zip", mod.getValue("download").toString(), "mods", mod.getValue("size").toDouble() * 1024 * 1024);
|
||||
}
|
||||
}
|
||||
|
||||
@ -565,11 +568,11 @@ void CModListView::on_installButton_clicked()
|
||||
{
|
||||
auto mod = modModel->getMod(name);
|
||||
if(!mod.isInstalled())
|
||||
downloadFile(name + ".zip", mod.getValue("download").toString(), "mods");
|
||||
downloadFile(name + ".zip", mod.getValue("download").toString(), "mods", mod.getValue("size").toDouble() * 1024 * 1024);
|
||||
}
|
||||
}
|
||||
|
||||
void CModListView::downloadFile(QString file, QString url, QString description)
|
||||
void CModListView::downloadFile(QString file, QString url, QString description, qint64 size)
|
||||
{
|
||||
if(!dlManager)
|
||||
{
|
||||
@ -591,7 +594,7 @@ void CModListView::downloadFile(QString file, QString url, QString description)
|
||||
ui->progressBar->setFormat(progressBarFormat);
|
||||
}
|
||||
|
||||
dlManager->downloadFile(QUrl(url), file);
|
||||
dlManager->downloadFile(QUrl(url), file, size);
|
||||
}
|
||||
|
||||
void CModListView::downloadProgress(qint64 current, qint64 max)
|
||||
@ -855,7 +858,7 @@ void CModListView::doInstallMod(const QString & modName)
|
||||
{
|
||||
auto mod = modModel->getMod(name);
|
||||
if(!mod.isInstalled())
|
||||
downloadFile(name + ".zip", mod.getValue("download").toString(), "mods");
|
||||
downloadFile(name + ".zip", mod.getValue("download").toString(), "mods", mod.getValue("size").toDouble() * 1024 * 1024);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -51,7 +51,7 @@ class CModListView : public QWidget
|
||||
// find mods that depend on this one
|
||||
QStringList findDependentMods(QString mod, bool excludeDisabled);
|
||||
|
||||
void downloadFile(QString file, QString url, QString description);
|
||||
void downloadFile(QString file, QString url, QString description, qint64 size = 0);
|
||||
|
||||
void installMods(QStringList archives);
|
||||
void installFiles(QStringList mods);
|
||||
|
@ -87,15 +87,24 @@ void CModManager::loadMods()
|
||||
ResourceID resID(CModInfo::getModFile(modname));
|
||||
if(CResourceHandler::get()->existsResource(resID))
|
||||
{
|
||||
boost::filesystem::path name = *CResourceHandler::get()->getResourceName(resID);
|
||||
auto mod = JsonUtils::JsonFromFile(pathToQString(name));
|
||||
if(!name.is_absolute())
|
||||
//calculate mod size
|
||||
qint64 total = 0;
|
||||
ResourceID resDir(CModInfo::getModDir(modname), EResType::DIRECTORY);
|
||||
if(CResourceHandler::get()->existsResource(resDir))
|
||||
{
|
||||
auto json = JsonUtils::toJson(mod);
|
||||
json["storedLocaly"].Bool() = true;
|
||||
mod = JsonUtils::toVariant(json);
|
||||
for(QDirIterator iter(QString::fromStdString(CResourceHandler::get()->getResourceName(resDir)->string()), QDirIterator::Subdirectories); iter.hasNext(); iter.next())
|
||||
total += iter.fileInfo().size();
|
||||
total /= 1024; //to Kb
|
||||
}
|
||||
|
||||
boost::filesystem::path name = *CResourceHandler::get()->getResourceName(resID);
|
||||
auto mod = JsonUtils::JsonFromFile(pathToQString(name));
|
||||
auto json = JsonUtils::toJson(mod);
|
||||
json["localSize"].Integer() = total;
|
||||
if(!name.is_absolute())
|
||||
json["storedLocaly"].Bool() = true;
|
||||
|
||||
mod = JsonUtils::toVariant(json);
|
||||
localMods.insert(QString::fromUtf8(modname.c_str()).toLower(), mod);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user