Merge pull request #3897 from jamierocks/atl-opt-mod-install-btn

NOISSUE Close optional mod dialog with Install button
This commit is contained in:
Petr Mrázek 2021-06-25 12:20:27 +02:00 committed by GitHub
commit d92733feae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 104 additions and 2 deletions

View File

@ -246,6 +246,8 @@ set(MINECRAFT_SOURCES
minecraft/launch/ReconstructAssets.h
minecraft/launch/ScanModFolders.cpp
minecraft/launch/ScanModFolders.h
minecraft/launch/VerifyJavaInstall.cpp
minecraft/launch/VerifyJavaInstall.h
minecraft/legacy/LegacyModList.h
minecraft/legacy/LegacyModList.cpp

View File

@ -23,6 +23,7 @@
#include "minecraft/launch/ClaimAccount.h"
#include "minecraft/launch/ReconstructAssets.h"
#include "minecraft/launch/ScanModFolders.h"
#include "minecraft/launch/VerifyJavaInstall.h"
#include "java/launch/CheckJava.h"
#include "java/JavaUtils.h"
#include "meta/Index.h"
@ -915,6 +916,11 @@ shared_qobject_ptr<LaunchTask> MinecraftInstance::createLaunchTask(AuthSessionPt
process->appendStep(new ReconstructAssets(pptr));
}
// verify that minimum Java requirements are met
{
process->appendStep(new VerifyJavaInstall(pptr));
}
{
// actually launch the game
auto method = launchMethod();

View File

@ -65,4 +65,7 @@ VersionFilterData::VersionFilterData()
QSet<QString>{"net.java.jinput:jinput", "net.java.jinput:jinput-platform",
"net.java.jutils:jutils", "org.lwjgl.lwjgl:lwjgl",
"org.lwjgl.lwjgl:lwjgl_util", "org.lwjgl.lwjgl:lwjgl-platform"};
java8BeginsDate = timeFromS3Time("2017-03-30T09:32:19+00:00");
java16BeginsDate = timeFromS3Time("2021-05-12T11:19:15+00:00");
}

View File

@ -23,5 +23,9 @@ struct VersionFilterData
QDateTime legacyCutoffDate;
// Libraries that belong to LWJGL
QSet<QString> lwjglWhitelist;
// release date of first version to require Java 8 (17w13a)
QDateTime java8BeginsDate;
// release data of first version to require Java 16 (21w19a)
QDateTime java16BeginsDate;
};
extern VersionFilterData MULTIMC_LOGIC_EXPORT g_VersionFilterData;

View File

@ -0,0 +1,34 @@
#include "VerifyJavaInstall.h"
#include <launch/LaunchTask.h>
#include <minecraft/MinecraftInstance.h>
#include <minecraft/PackProfile.h>
#include <minecraft/VersionFilterData.h>
void VerifyJavaInstall::executeTask() {
auto m_inst = std::dynamic_pointer_cast<MinecraftInstance>(m_parent->instance());
auto javaVersion = m_inst->getJavaVersion();
auto minecraftComponent = m_inst->getPackProfile()->getComponent("net.minecraft");
// Java 16 requirement
if (minecraftComponent->getReleaseDateTime() >= g_VersionFilterData.java16BeginsDate) {
if (javaVersion.major() < 16) {
emit logLine("Minecraft 21w19a and above require the use of Java 16",
MessageLevel::Fatal);
emitFailed(tr("Minecraft 21w19a and above require the use of Java 16"));
return;
}
}
// Java 8 requirement
else if (minecraftComponent->getReleaseDateTime() >= g_VersionFilterData.java8BeginsDate) {
if (javaVersion.major() < 8) {
emit logLine("Minecraft 17w13a and above require the use of Java 8",
MessageLevel::Fatal);
emitFailed(tr("Minecraft 17w13a and above require the use of Java 8"));
return;
}
}
emitSucceeded();
}

View File

@ -0,0 +1,17 @@
#pragma once
#include <launch/LaunchStep.h>
class VerifyJavaInstall : public LaunchStep {
Q_OBJECT
public:
explicit VerifyJavaInstall(LaunchTask *parent) : LaunchStep(parent) {
};
~VerifyJavaInstall() override = default;
void executeTask() override;
bool canAbort() const override {
return false;
}
};

View File

@ -4,6 +4,7 @@
#include <MMCZip.h>
#include <minecraft/OneSixVersionFormat.h>
#include <Version.h>
#include <net/ChecksumValidator.h>
#include "ATLPackInstallTask.h"
#include "BuildConfig.h"
@ -407,7 +408,12 @@ void PackInstallTask::installConfigs()
auto entry = ENV.metacache()->resolveEntry("ATLauncherPacks", path);
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();
connect(jobPtr.get(), &NetJob::succeeded, this, [&]()
@ -508,6 +514,10 @@ void PackInstallTask::downloadMods()
modsToExtract.insert(entry->getFullPath(), mod);
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);
}
else if(mod.type == ModType::Decomp) {
@ -516,6 +526,10 @@ void PackInstallTask::downloadMods()
modsToDecomp.insert(entry->getFullPath(), mod);
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);
}
else {
@ -526,6 +540,10 @@ void PackInstallTask::downloadMods()
entry->setStale(true);
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);
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", "");
}
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) {
p.name = Json::requireString(obj, "name");
p.version = Json::requireString(obj, "version");
@ -195,7 +200,6 @@ void ATLauncher::loadVersion(PackVersion & v, QJsonObject & obj)
}
}
if(obj.contains("mods")) {
auto mods = Json::requireArray(obj, "mods");
for (const auto modRaw : mods)
@ -206,4 +210,9 @@ void ATLauncher::loadVersion(PackVersion & v, QJsonObject & obj)
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;
};
struct VersionConfigs
{
int filesize;
QString sha1;
};
struct PackVersion
{
QString version;
@ -112,6 +118,7 @@ struct PackVersion
VersionLoader loader;
QVector<VersionLibrary> libraries;
QVector<VersionMod> mods;
VersionConfigs configs;
};
MULTIMC_LOGIC_EXPORT void loadVersion(PackVersion & v, QJsonObject & obj);

View File

@ -200,6 +200,8 @@ AtlOptionalModDialog::AtlOptionalModDialog(QWidget *parent, QVector<ATLauncher::
listModel, &AtlOptionalModListModel::selectRecommended);
connect(ui->clearAllButton, &QPushButton::pressed,
listModel, &AtlOptionalModListModel::clearAll);
connect(ui->installButton, &QPushButton::pressed,
this, &QDialog::close);
}
AtlOptionalModDialog::~AtlOptionalModDialog() {