summaryrefslogtreecommitdiffstats
path: root/api/logic/minecraft
diff options
context:
space:
mode:
Diffstat (limited to 'api/logic/minecraft')
-rw-r--r--api/logic/minecraft/AssetsUtils.cpp11
-rw-r--r--api/logic/minecraft/Library.cpp24
-rw-r--r--api/logic/minecraft/MinecraftVersionList.cpp8
-rw-r--r--api/logic/minecraft/forge/ForgeInstaller.cpp2
-rw-r--r--api/logic/minecraft/forge/ForgeVersionList.cpp16
-rw-r--r--api/logic/minecraft/forge/ForgeVersionList.h4
-rw-r--r--api/logic/minecraft/legacy/LegacyUpdate.cpp4
-rw-r--r--api/logic/minecraft/liteloader/LiteLoaderVersionList.cpp8
-rw-r--r--api/logic/minecraft/liteloader/LiteLoaderVersionList.h2
-rw-r--r--api/logic/minecraft/onesix/OneSixUpdate.cpp13
10 files changed, 55 insertions, 37 deletions
diff --git a/api/logic/minecraft/AssetsUtils.cpp b/api/logic/minecraft/AssetsUtils.cpp
index 7a525abe..bb630528 100644
--- a/api/logic/minecraft/AssetsUtils.cpp
+++ b/api/logic/minecraft/AssetsUtils.cpp
@@ -25,7 +25,9 @@
#include "AssetsUtils.h"
#include "FileSystem.h"
-#include "net/MD5EtagDownload.h"
+#include "net/Download.h"
+#include "net/ChecksumValidator.h"
+
namespace AssetsUtils
{
@@ -191,7 +193,12 @@ NetActionPtr AssetObject::getDownloadAction()
QFileInfo objectFile(getLocalPath());
if ((!objectFile.isFile()) || (objectFile.size() != size))
{
- auto objectDL = MD5EtagDownload::make(getUrl(), objectFile.filePath());
+ auto objectDL = Net::Download::makeFile(getUrl(), objectFile.filePath());
+ if(hash.size())
+ {
+ auto rawHash = QByteArray::fromHex(hash.toLatin1());
+ objectDL->addValidator(new Net::ChecksumValidator(QCryptographicHash::Sha1, rawHash));
+ }
objectDL->m_total_progress = size;
return objectDL;
}
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);
}
}
}
diff --git a/api/logic/minecraft/MinecraftVersionList.cpp b/api/logic/minecraft/MinecraftVersionList.cpp
index a5cc3a39..4e4eafbc 100644
--- a/api/logic/minecraft/MinecraftVersionList.cpp
+++ b/api/logic/minecraft/MinecraftVersionList.cpp
@@ -68,6 +68,7 @@ slots:
protected:
NetJobPtr specificVersionDownloadJob;
+ QByteArray versionIndexData;
std::shared_ptr<MinecraftVersion> updatedVersion;
MinecraftVersionList *m_list;
};
@@ -410,7 +411,7 @@ MCVListVersionUpdateTask::MCVListVersionUpdateTask(MinecraftVersionList *vlist,
void MCVListVersionUpdateTask::executeTask()
{
auto job = new NetJob("Version index");
- job->addNetAction(ByteArrayDownload::make(QUrl(updatedVersion->getUrl())));
+ job->addNetAction(Net::Download::makeByteArray(QUrl(updatedVersion->getUrl()), &versionIndexData));
specificVersionDownloadJob.reset(job);
connect(specificVersionDownloadJob.get(), SIGNAL(succeeded()), SLOT(json_downloaded()));
connect(specificVersionDownloadJob.get(), SIGNAL(failed(QString)), SIGNAL(failed(QString)));
@@ -420,12 +421,11 @@ void MCVListVersionUpdateTask::executeTask()
void MCVListVersionUpdateTask::json_downloaded()
{
- NetActionPtr DlJob = specificVersionDownloadJob->first();
- auto data = std::dynamic_pointer_cast<ByteArrayDownload>(DlJob)->m_data;
specificVersionDownloadJob.reset();
QJsonParseError jsonError;
- QJsonDocument jsonDoc = QJsonDocument::fromJson(data, &jsonError);
+ QJsonDocument jsonDoc = QJsonDocument::fromJson(versionIndexData, &jsonError);
+ versionIndexData.clear();
if (jsonError.error != QJsonParseError::NoError)
{
diff --git a/api/logic/minecraft/forge/ForgeInstaller.cpp b/api/logic/minecraft/forge/ForgeInstaller.cpp
index 353328ab..4d004bf5 100644
--- a/api/logic/minecraft/forge/ForgeInstaller.cpp
+++ b/api/logic/minecraft/forge/ForgeInstaller.cpp
@@ -397,7 +397,7 @@ protected:
if (entry->isStale())
{
NetJob *fjob = new NetJob("Forge download");
- fjob->addNetAction(CacheDownload::make(forgeVersion->url(), entry));
+ fjob->addNetAction(Net::Download::makeCached(forgeVersion->url(), entry));
connect(fjob, &NetJob::progress, this, &Task::setProgress);
connect(fjob, &NetJob::status, this, &Task::setStatus);
connect(fjob, &NetJob::failed, [this](QString reason)
diff --git a/api/logic/minecraft/forge/ForgeVersionList.cpp b/api/logic/minecraft/forge/ForgeVersionList.cpp
index de185e5f..fe024780 100644
--- a/api/logic/minecraft/forge/ForgeVersionList.cpp
+++ b/api/logic/minecraft/forge/ForgeVersionList.cpp
@@ -131,10 +131,8 @@ void ForgeListLoadTask::executeTask()
forgeListEntry->setStale(true);
gradleForgeListEntry->setStale(true);
- job->addNetAction(listDownload = CacheDownload::make(QUrl(URLConstants::FORGE_LEGACY_URL),
- forgeListEntry));
- job->addNetAction(gradleListDownload = CacheDownload::make(
- QUrl(URLConstants::FORGE_GRADLE_URL), gradleForgeListEntry));
+ job->addNetAction(listDownload = Net::Download::makeCached(QUrl(URLConstants::FORGE_LEGACY_URL),forgeListEntry));
+ job->addNetAction(gradleListDownload = Net::Download::makeCached(QUrl(URLConstants::FORGE_GRADLE_URL), gradleForgeListEntry));
connect(listDownload.get(), SIGNAL(failed(int)), SLOT(listFailed()));
connect(gradleListDownload.get(), SIGNAL(failed(int)), SLOT(gradleListFailed()));
@@ -154,15 +152,14 @@ bool ForgeListLoadTask::parseForgeList(QList<BaseVersionPtr> &out)
{
QByteArray data;
{
- auto dlJob = listDownload;
- auto filename = std::dynamic_pointer_cast<CacheDownload>(dlJob)->getTargetFilepath();
+ auto filename = listDownload->getTargetFilepath();
QFile listFile(filename);
if (!listFile.open(QIODevice::ReadOnly))
{
return false;
}
data = listFile.readAll();
- dlJob.reset();
+ listDownload.reset();
}
QJsonParseError jsonError;
@@ -266,15 +263,14 @@ bool ForgeListLoadTask::parseForgeGradleList(QList<BaseVersionPtr> &out)
QMap<int, std::shared_ptr<ForgeVersion>> lookup;
QByteArray data;
{
- auto dlJob = gradleListDownload;
- auto filename = std::dynamic_pointer_cast<CacheDownload>(dlJob)->getTargetFilepath();
+ auto filename = gradleListDownload->getTargetFilepath();
QFile listFile(filename);
if (!listFile.open(QIODevice::ReadOnly))
{
return false;
}
data = listFile.readAll();
- dlJob.reset();
+ gradleListDownload.reset();
}
QJsonParseError jsonError;
diff --git a/api/logic/minecraft/forge/ForgeVersionList.h b/api/logic/minecraft/forge/ForgeVersionList.h
index 62c08b2a..7b30bbb4 100644
--- a/api/logic/minecraft/forge/ForgeVersionList.h
+++ b/api/logic/minecraft/forge/ForgeVersionList.h
@@ -81,8 +81,8 @@ protected:
NetJobPtr listJob;
ForgeVersionList *m_list;
- CacheDownloadPtr listDownload;
- CacheDownloadPtr gradleListDownload;
+ Net::Download::Ptr listDownload;
+ Net::Download::Ptr gradleListDownload;
private:
bool parseForgeList(QList<BaseVersionPtr> &out);
diff --git a/api/logic/minecraft/legacy/LegacyUpdate.cpp b/api/logic/minecraft/legacy/LegacyUpdate.cpp
index 6539b2d3..a0d1933f 100644
--- a/api/logic/minecraft/legacy/LegacyUpdate.cpp
+++ b/api/logic/minecraft/legacy/LegacyUpdate.cpp
@@ -114,7 +114,7 @@ void LegacyUpdate::fmllibsStart()
auto entry = metacache->resolveEntry("fmllibs", lib.filename);
QString urlString = lib.ours ? URLConstants::FMLLIBS_OUR_BASE_URL + lib.filename
: URLConstants::FMLLIBS_FORGE_BASE_URL + lib.filename;
- dljob->addNetAction(CacheDownload::make(QUrl(urlString), entry));
+ dljob->addNetAction(Net::Download::makeCached(QUrl(urlString), entry));
}
connect(dljob, &NetJob::succeeded, this, &LegacyUpdate::fmllibsFinished);
@@ -372,7 +372,7 @@ void LegacyUpdate::jarStart()
auto metacache = ENV.metacache();
auto entry = metacache->resolveEntry("versions", URLConstants::getJarPath(version_id));
- dljob->addNetAction(CacheDownload::make(QUrl(URLConstants::getLegacyJarUrl(version_id)), entry));
+ dljob->addNetAction(Net::Download::makeCached(QUrl(URLConstants::getLegacyJarUrl(version_id)), entry));
connect(dljob, SIGNAL(succeeded()), SLOT(jarFinished()));
connect(dljob, SIGNAL(failed(QString)), SLOT(jarFailed(QString)));
connect(dljob, SIGNAL(progress(qint64, qint64)), SIGNAL(progress(qint64, qint64)));
diff --git a/api/logic/minecraft/liteloader/LiteLoaderVersionList.cpp b/api/logic/minecraft/liteloader/LiteLoaderVersionList.cpp
index b0c9736a..f8bf095f 100644
--- a/api/logic/minecraft/liteloader/LiteLoaderVersionList.cpp
+++ b/api/logic/minecraft/liteloader/LiteLoaderVersionList.cpp
@@ -146,8 +146,7 @@ void LLListLoadTask::executeTask()
// verify by poking the server.
liteloaderEntry->setStale(true);
- job->addNetAction(listDownload = CacheDownload::make(QUrl(URLConstants::LITELOADER_URL),
- liteloaderEntry));
+ job->addNetAction(listDownload = Net::Download::makeCached(QUrl(URLConstants::LITELOADER_URL), liteloaderEntry));
connect(listDownload.get(), SIGNAL(failed(int)), SLOT(listFailed()));
@@ -167,8 +166,7 @@ void LLListLoadTask::listDownloaded()
{
QByteArray data;
{
- auto dlJob = listDownload;
- auto filename = std::dynamic_pointer_cast<CacheDownload>(dlJob)->getTargetFilepath();
+ auto filename = listDownload->getTargetFilepath();
QFile listFile(filename);
if (!listFile.open(QIODevice::ReadOnly))
{
@@ -177,7 +175,7 @@ void LLListLoadTask::listDownloaded()
}
data = listFile.readAll();
listFile.close();
- dlJob.reset();
+ listDownload.reset();
}
QJsonParseError jsonError;
diff --git a/api/logic/minecraft/liteloader/LiteLoaderVersionList.h b/api/logic/minecraft/liteloader/LiteLoaderVersionList.h
index 1dba4b6a..ae8bee92 100644
--- a/api/logic/minecraft/liteloader/LiteLoaderVersionList.h
+++ b/api/logic/minecraft/liteloader/LiteLoaderVersionList.h
@@ -112,7 +112,7 @@ slots:
protected:
NetJobPtr listJob;
- CacheDownloadPtr listDownload;
+ Net::Download::Ptr listDownload;
LiteLoaderVersionList *m_list;
};
diff --git a/api/logic/minecraft/onesix/OneSixUpdate.cpp b/api/logic/minecraft/onesix/OneSixUpdate.cpp
index 1c2cd196..d3cd197d 100644
--- a/api/logic/minecraft/onesix/OneSixUpdate.cpp
+++ b/api/logic/minecraft/onesix/OneSixUpdate.cpp
@@ -31,6 +31,7 @@
#include "minecraft/MinecraftProfile.h"
#include "minecraft/Library.h"
#include "net/URLConstants.h"
+#include "net/ChecksumValidator.h"
#include "minecraft/AssetsUtils.h"
#include "Exception.h"
#include "MMCZip.h"
@@ -96,7 +97,13 @@ void OneSixUpdate::assetIndexStart()
auto metacache = ENV.metacache();
auto entry = metacache->resolveEntry("asset_indexes", localPath);
entry->setStale(true);
- job->addNetAction(CacheDownload::make(indexUrl, entry));
+ auto hexSha1 = assets->sha1.toLatin1();
+ qDebug() << "Asset index SHA1:" << hexSha1;
+ auto dl = Net::Download::makeCached(indexUrl, entry);
+ auto rawSha1 = QByteArray::fromHex(assets->sha1.toLatin1());
+ dl->addValidator(new Net::ChecksumValidator(QCryptographicHash::Sha1, rawSha1));
+ job->addNetAction(dl);
+
jarlibDownloadJob.reset(job);
connect(jarlibDownloadJob.get(), SIGNAL(succeeded()), SLOT(assetIndexFinished()));
@@ -180,7 +187,7 @@ void OneSixUpdate::jarlibStart()
auto metacache = ENV.metacache();
auto entry = metacache->resolveEntry("versions", localPath);
- job->addNetAction(CacheDownload::make(QUrl(urlstr), entry));
+ job->addNetAction(Net::Download::makeCached(QUrl(urlstr), entry));
jarlibDownloadJob.reset(job);
}
@@ -293,7 +300,7 @@ void OneSixUpdate::fmllibsStart()
auto entry = metacache->resolveEntry("fmllibs", lib.filename);
QString urlString = lib.ours ? URLConstants::FMLLIBS_OUR_BASE_URL + lib.filename
: URLConstants::FMLLIBS_FORGE_BASE_URL + lib.filename;
- dljob->addNetAction(CacheDownload::make(QUrl(urlString), entry));
+ dljob->addNetAction(Net::Download::makeCached(QUrl(urlString), entry));
}
connect(dljob, SIGNAL(succeeded()), SLOT(fmllibsFinished()));