summaryrefslogtreecommitdiffstats
path: root/api/logic/minecraft/Library.cpp
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2016-05-28 19:54:17 +0200
committerPetr Mrázek <peterix@gmail.com>2016-06-05 23:55:39 +0200
commita1abbd9e05c80584d831b1d12c27c5f7d731cece (patch)
tree3324eaf37efa228e07a0e3136952673f0bc3405a /api/logic/minecraft/Library.cpp
parenta750f6e63c783730380c19788deff2acfb3f4836 (diff)
downloadMultiMC-a1abbd9e05c80584d831b1d12c27c5f7d731cece.tar
MultiMC-a1abbd9e05c80584d831b1d12c27c5f7d731cece.tar.gz
MultiMC-a1abbd9e05c80584d831b1d12c27c5f7d731cece.tar.lz
MultiMC-a1abbd9e05c80584d831b1d12c27c5f7d731cece.tar.xz
MultiMC-a1abbd9e05c80584d831b1d12c27c5f7d731cece.zip
NOISSUE refactor *Download into more, smaller pieces
* Download is now Download. * Download uses Sink subclasses to process various events. * Validators can be used to further customize the Sink behaviour.
Diffstat (limited to 'api/logic/minecraft/Library.cpp')
-rw-r--r--api/logic/minecraft/Library.cpp24
1 files changed, 17 insertions, 7 deletions
diff --git a/api/logic/minecraft/Library.cpp b/api/logic/minecraft/Library.cpp
index 922db84e..584c7ac5 100644
--- a/api/logic/minecraft/Library.cpp
+++ b/api/logic/minecraft/Library.cpp
@@ -1,5 +1,6 @@
#include "Library.h"
-#include <net/CacheDownload.h>
+#include <net/Download.h>
+#include <net/ChecksumValidator.h>
#include <minecraft/forge/ForgeXzDownload.h>
#include <Env.h>
#include <FileSystem.h>
@@ -74,7 +75,7 @@ QList<NetActionPtr> Library::getDownloads(OpSys system, HttpMetaCache * cache, Q
bool isLocal = (hint() == "local");
bool isForge = (hint() == "forge-pack-xz");
- auto add_download = [&](QString storage, QString dl)
+ auto add_download = [&](QString storage, QString url, QString sha1 = QString())
{
auto entry = cache->resolveEntry("libraries", storage);
if (!entry->isStale())
@@ -95,7 +96,16 @@ QList<NetActionPtr> Library::getDownloads(OpSys system, HttpMetaCache * cache, Q
}
else
{
- out.append(CacheDownload::make(dl, entry));
+ if(sha1.size())
+ {
+ auto rawSha1 = QByteArray::fromHex(sha1.toLatin1());
+ auto dl = Net::Download::makeCached(url, entry);
+ dl->addValidator(new Net::ChecksumValidator(QCryptographicHash::Sha1, rawSha1));
+ out.append(dl);
+ }
+
+ else
+ out.append(Net::Download::makeCached(url, entry));
}
return true;
};
@@ -105,7 +115,7 @@ QList<NetActionPtr> Library::getDownloads(OpSys system, HttpMetaCache * cache, Q
if(m_mojangDownloads->artifact)
{
auto artifact = m_mojangDownloads->artifact;
- add_download(artifact->path, artifact->url);
+ add_download(artifact->path, artifact->url, artifact->sha1);
}
if(m_nativeClassifiers.contains(system))
{
@@ -118,17 +128,17 @@ QList<NetActionPtr> Library::getDownloads(OpSys system, HttpMetaCache * cache, Q
nat64Classifier.replace("${arch}", "64");
auto nat32info = m_mojangDownloads->getDownloadInfo(nat32Classifier);
if(nat32info)
- add_download(nat32info->path, nat32info->url);
+ add_download(nat32info->path, nat32info->url, nat32info->sha1);
auto nat64info = m_mojangDownloads->getDownloadInfo(nat64Classifier);
if(nat64info)
- add_download(nat64info->path, nat64info->url);
+ add_download(nat64info->path, nat64info->url, nat64info->sha1);
}
else
{
auto info = m_mojangDownloads->getDownloadInfo(nativeClassifier);
if(info)
{
- add_download(info->path, info->url);
+ add_download(info->path, info->url, info->sha1);
}
}
}