mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2025-08-03 11:27:33 -04:00
rework parse dependency function
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
parent
1346783c5e
commit
0f5a890051
@ -83,11 +83,11 @@ ModDetails ReadMCModInfo(QByteArray contents)
|
||||
};
|
||||
|
||||
if (firstObj.contains("requiredMods")) {
|
||||
for (auto dep : firstObj.value("dependencies").toArray().toVariantList()) {
|
||||
for (auto dep : firstObj.value("requiredMods").toArray()) {
|
||||
addDep(dep.toString());
|
||||
}
|
||||
} else if (firstObj.contains("dependencies")) {
|
||||
for (auto dep : firstObj.value("dependencies").toArray().toVariantList()) {
|
||||
for (auto dep : firstObj.value("dependencies").toArray()) {
|
||||
addDep(dep.toString());
|
||||
}
|
||||
}
|
||||
@ -230,19 +230,29 @@ ModDetails ReadMCModTOML(QByteArray contents)
|
||||
details.icon_file = logoFile;
|
||||
|
||||
auto parseDep = [&details](toml::array* dependencies) {
|
||||
if (dependencies) {
|
||||
for (auto& dep : *dependencies) {
|
||||
auto dep_table = dep.as_table();
|
||||
if (dep_table) {
|
||||
auto modId = dep_table->get("modId")->value_or<std::string>("");
|
||||
if (modId != "forge" && modId != "neoforge" && modId != "minecraft") {
|
||||
if (dep_table->contains("type") && (dep_table->get("type"))->value_or<std::string>("") == "required") {
|
||||
details.dependencies.append(QString::fromStdString(modId));
|
||||
} else if (dep_table->contains("mandatory") && (dep_table->get("mandatory"))->value_or(false)) {
|
||||
details.dependencies.append(QString::fromStdString(modId));
|
||||
}
|
||||
}
|
||||
}
|
||||
static const QStringList ignoreModIds = { "", "forge", "neoforge", "minecraft" };
|
||||
if (!dependencies) {
|
||||
return;
|
||||
}
|
||||
auto isNeoForgeDep = [](toml::table* t) {
|
||||
auto type = (*t)["type"].as_string();
|
||||
return type && type->get() == "required";
|
||||
};
|
||||
auto isForgeDep = [](toml::table* t) {
|
||||
auto mandatory = (*t)["mandatory"].as_boolean();
|
||||
return mandatory && mandatory->get();
|
||||
};
|
||||
for (auto& dep : *dependencies) {
|
||||
auto dep_table = dep.as_table();
|
||||
if (!dep_table) {
|
||||
continue;
|
||||
}
|
||||
auto modId = (*dep_table)["modId"].as_string();
|
||||
if (!modId || ignoreModIds.contains(modId->get())) {
|
||||
continue;
|
||||
}
|
||||
if (isNeoForgeDep(dep_table) || isForgeDep(dep_table)) {
|
||||
details.dependencies.append(QString::fromStdString(modId->get()));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user