NOISSUE Check mod and config checksums for ATLauncher

This commit is contained in:
Jamie Mansfield 2021-06-23 18:19:48 +01:00
parent c77f5285e3
commit 7c0fdaa730
No known key found for this signature in database
GPG Key ID: 36F61598F39F67B0
3 changed files with 36 additions and 2 deletions

View File

@ -4,6 +4,7 @@
#include <MMCZip.h> #include <MMCZip.h>
#include <minecraft/OneSixVersionFormat.h> #include <minecraft/OneSixVersionFormat.h>
#include <Version.h> #include <Version.h>
#include <net/ChecksumValidator.h>
#include "ATLPackInstallTask.h" #include "ATLPackInstallTask.h"
#include "BuildConfig.h" #include "BuildConfig.h"
@ -407,7 +408,12 @@ void PackInstallTask::installConfigs()
auto entry = ENV.metacache()->resolveEntry("ATLauncherPacks", path); auto entry = ENV.metacache()->resolveEntry("ATLauncherPacks", path);
entry->setStale(true); entry->setStale(true);
jobPtr->addNetAction(Net::Download::makeCached(url, entry)); auto dl = Net::Download::makeCached(url, entry);
if (!m_version.configs.sha1.isEmpty()) {
auto rawSha1 = QByteArray::fromHex(m_version.configs.sha1.toLatin1());
dl->addValidator(new Net::ChecksumValidator(QCryptographicHash::Sha1, rawSha1));
}
jobPtr->addNetAction(dl);
archivePath = entry->getFullPath(); archivePath = entry->getFullPath();
connect(jobPtr.get(), &NetJob::succeeded, this, [&]() connect(jobPtr.get(), &NetJob::succeeded, this, [&]()
@ -508,6 +514,10 @@ void PackInstallTask::downloadMods()
modsToExtract.insert(entry->getFullPath(), mod); modsToExtract.insert(entry->getFullPath(), mod);
auto dl = Net::Download::makeCached(url, entry); auto dl = Net::Download::makeCached(url, entry);
if (!mod.md5.isEmpty()) {
auto rawMd5 = QByteArray::fromHex(mod.md5.toLatin1());
dl->addValidator(new Net::ChecksumValidator(QCryptographicHash::Md5, rawMd5));
}
jobPtr->addNetAction(dl); jobPtr->addNetAction(dl);
} }
else if(mod.type == ModType::Decomp) { else if(mod.type == ModType::Decomp) {
@ -516,6 +526,10 @@ void PackInstallTask::downloadMods()
modsToDecomp.insert(entry->getFullPath(), mod); modsToDecomp.insert(entry->getFullPath(), mod);
auto dl = Net::Download::makeCached(url, entry); auto dl = Net::Download::makeCached(url, entry);
if (!mod.md5.isEmpty()) {
auto rawMd5 = QByteArray::fromHex(mod.md5.toLatin1());
dl->addValidator(new Net::ChecksumValidator(QCryptographicHash::Md5, rawMd5));
}
jobPtr->addNetAction(dl); jobPtr->addNetAction(dl);
} }
else { else {
@ -526,6 +540,10 @@ void PackInstallTask::downloadMods()
entry->setStale(true); entry->setStale(true);
auto dl = Net::Download::makeCached(url, entry); auto dl = Net::Download::makeCached(url, entry);
if (!mod.md5.isEmpty()) {
auto rawMd5 = QByteArray::fromHex(mod.md5.toLatin1());
dl->addValidator(new Net::ChecksumValidator(QCryptographicHash::Md5, rawMd5));
}
jobPtr->addNetAction(dl); jobPtr->addNetAction(dl);
auto path = FS::PathCombine(m_stagingPath, "minecraft", relpath, mod.file); auto path = FS::PathCombine(m_stagingPath, "minecraft", relpath, mod.file);

View File

@ -109,6 +109,11 @@ static void loadVersionLibrary(ATLauncher::VersionLibrary & p, QJsonObject & obj
p.server = Json::ensureString(obj, "server", ""); p.server = Json::ensureString(obj, "server", "");
} }
static void loadVersionConfigs(ATLauncher::VersionConfigs & p, QJsonObject & obj) {
p.filesize = Json::requireInteger(obj, "filesize");
p.sha1 = Json::requireString(obj, "sha1");
}
static void loadVersionMod(ATLauncher::VersionMod & p, QJsonObject & obj) { static void loadVersionMod(ATLauncher::VersionMod & p, QJsonObject & obj) {
p.name = Json::requireString(obj, "name"); p.name = Json::requireString(obj, "name");
p.version = Json::requireString(obj, "version"); p.version = Json::requireString(obj, "version");
@ -195,7 +200,6 @@ void ATLauncher::loadVersion(PackVersion & v, QJsonObject & obj)
} }
} }
if(obj.contains("mods")) { if(obj.contains("mods")) {
auto mods = Json::requireArray(obj, "mods"); auto mods = Json::requireArray(obj, "mods");
for (const auto modRaw : mods) for (const auto modRaw : mods)
@ -206,4 +210,9 @@ void ATLauncher::loadVersion(PackVersion & v, QJsonObject & obj)
v.mods.append(mod); v.mods.append(mod);
} }
} }
if(obj.contains("configs")) {
auto configsObj = Json::requireObject(obj, "configs");
loadVersionConfigs(v.configs, configsObj);
}
} }

View File

@ -101,6 +101,12 @@ struct VersionMod
bool effectively_hidden; bool effectively_hidden;
}; };
struct VersionConfigs
{
int filesize;
QString sha1;
};
struct PackVersion struct PackVersion
{ {
QString version; QString version;
@ -112,6 +118,7 @@ struct PackVersion
VersionLoader loader; VersionLoader loader;
QVector<VersionLibrary> libraries; QVector<VersionLibrary> libraries;
QVector<VersionMod> mods; QVector<VersionMod> mods;
VersionConfigs configs;
}; };
MULTIMC_LOGIC_EXPORT void loadVersion(PackVersion & v, QJsonObject & obj); MULTIMC_LOGIC_EXPORT void loadVersion(PackVersion & v, QJsonObject & obj);