Merge pull request #630 from jamierocks/h-atl-depends

This commit is contained in:
Sefa Eyeoglu 2022-05-25 14:52:34 +02:00 committed by GitHub
commit 7f73e57c67
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 67 additions and 8 deletions

View File

@ -414,7 +414,31 @@ bool PackInstallTask::createLibrariesComponent(QString instanceRoot, std::shared
bool PackInstallTask::createPackComponent(QString instanceRoot, std::shared_ptr<PackProfile> profile)
{
if(m_version.mainClass == QString() && m_version.extraArguments == QString()) {
if (m_version.mainClass.mainClass.isEmpty() && m_version.extraArguments.arguments.isEmpty()) {
return true;
}
auto mainClass = m_version.mainClass.mainClass;
auto extraArguments = m_version.extraArguments.arguments;
auto hasMainClassDepends = !m_version.mainClass.depends.isEmpty();
auto hasExtraArgumentsDepends = !m_version.extraArguments.depends.isEmpty();
if (hasMainClassDepends || hasExtraArgumentsDepends) {
QSet<QString> mods;
for (const auto& item : m_version.mods) {
mods.insert(item.name);
}
if (hasMainClassDepends && !mods.contains(m_version.mainClass.depends)) {
mainClass = "";
}
if (hasExtraArgumentsDepends && !mods.contains(m_version.extraArguments.depends)) {
extraArguments = "";
}
}
if (mainClass.isEmpty() && extraArguments.isEmpty()) {
return true;
}
@ -442,12 +466,12 @@ bool PackInstallTask::createPackComponent(QString instanceRoot, std::shared_ptr<
auto f = std::make_shared<VersionFile>();
f->name = m_pack + " " + m_version_name;
if(m_version.mainClass != QString() && !mainClasses.contains(m_version.mainClass)) {
f->mainClass = m_version.mainClass;
if (!mainClass.isEmpty() && !mainClasses.contains(mainClass)) {
f->mainClass = mainClass;
}
// Parse out tweakers
auto args = m_version.extraArguments.split(" ");
auto args = extraArguments.split(" ");
QString previous;
for(auto arg : args) {
if(arg.startsWith("--tweakClass=") || previous == "--tweakClass") {
@ -757,6 +781,17 @@ bool PackInstallTask::extractMods(
for (auto iter = toCopy.begin(); iter != toCopy.end(); iter++) {
auto &from = iter.key();
auto &to = iter.value();
// If the file already exists, assume the mod is the correct copy - and remove
// the copy from the Configs.zip
QFileInfo fileInfo(to);
if (fileInfo.exists()) {
if (!QFile::remove(to)) {
qWarning() << "Failed to delete" << to;
return false;
}
}
FS::copy fileCopyOperation(from, to);
if(!fileCopyOperation()) {
qWarning() << "Failed to copy" << from << "to" << to;

View File

@ -212,6 +212,18 @@ static void loadVersionMessages(ATLauncher::VersionMessages& m, QJsonObject& obj
m.update = Json::ensureString(obj, "update", "");
}
static void loadVersionMainClass(ATLauncher::PackVersionMainClass& m, QJsonObject& obj)
{
m.mainClass = Json::ensureString(obj, "mainClass", "");
m.depends = Json::ensureString(obj, "depends", "");
}
static void loadVersionExtraArguments(ATLauncher::PackVersionExtraArguments& a, QJsonObject& obj)
{
a.arguments = Json::ensureString(obj, "arguments", "");
a.depends = Json::ensureString(obj, "depends", "");
}
void ATLauncher::loadVersion(PackVersion & v, QJsonObject & obj)
{
v.version = Json::requireString(obj, "version");
@ -220,12 +232,12 @@ void ATLauncher::loadVersion(PackVersion & v, QJsonObject & obj)
if(obj.contains("mainClass")) {
auto main = Json::requireObject(obj, "mainClass");
v.mainClass = Json::ensureString(main, "mainClass", "");
loadVersionMainClass(v.mainClass, main);
}
if(obj.contains("extraArguments")) {
auto arguments = Json::requireObject(obj, "extraArguments");
v.extraArguments = Json::ensureString(arguments, "arguments", "");
loadVersionExtraArguments(v.extraArguments, arguments);
}
if(obj.contains("loader")) {

View File

@ -150,13 +150,25 @@ struct VersionMessages
QString update;
};
struct PackVersionMainClass
{
QString mainClass;
QString depends;
};
struct PackVersionExtraArguments
{
QString arguments;
QString depends;
};
struct PackVersion
{
QString version;
QString minecraft;
bool noConfigs;
QString mainClass;
QString extraArguments;
PackVersionMainClass mainClass;
PackVersionExtraArguments extraArguments;
VersionLoader loader;
QVector<VersionLibrary> libraries;