mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2025-08-03 19:37:45 -04:00
feat: decode dependencies from mod jar
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
parent
9565affa64
commit
d2da8b5c37
@ -284,3 +284,8 @@ bool Mod::valid() const
|
|||||||
{
|
{
|
||||||
return !m_local_details.mod_id.isEmpty();
|
return !m_local_details.mod_id.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QStringList Mod::dependencies() const
|
||||||
|
{
|
||||||
|
return details().dependencies;
|
||||||
|
}
|
||||||
|
@ -72,6 +72,7 @@ class Mod : public Resource {
|
|||||||
auto loaders() const -> QString;
|
auto loaders() const -> QString;
|
||||||
auto mcVersions() const -> QString;
|
auto mcVersions() const -> QString;
|
||||||
auto releaseType() const -> QString;
|
auto releaseType() const -> QString;
|
||||||
|
QStringList dependencies() const;
|
||||||
|
|
||||||
/** Get the intneral path to the mod's icon file*/
|
/** Get the intneral path to the mod's icon file*/
|
||||||
QString iconPath() const { return m_local_details.icon_file; }
|
QString iconPath() const { return m_local_details.icon_file; }
|
||||||
|
@ -142,6 +142,8 @@ struct ModDetails {
|
|||||||
/* Path of mod logo */
|
/* Path of mod logo */
|
||||||
QString icon_file = {};
|
QString icon_file = {};
|
||||||
|
|
||||||
|
QStringList dependencies = {};
|
||||||
|
|
||||||
ModDetails() = default;
|
ModDetails() = default;
|
||||||
|
|
||||||
/** Metadata should be handled manually to properly set the mod status. */
|
/** Metadata should be handled manually to properly set the mod status. */
|
||||||
@ -156,6 +158,7 @@ struct ModDetails {
|
|||||||
, issue_tracker(other.issue_tracker)
|
, issue_tracker(other.issue_tracker)
|
||||||
, licenses(other.licenses)
|
, licenses(other.licenses)
|
||||||
, icon_file(other.icon_file)
|
, icon_file(other.icon_file)
|
||||||
|
, dependencies(other.dependencies)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
ModDetails& operator=(const ModDetails& other) = default;
|
ModDetails& operator=(const ModDetails& other) = default;
|
||||||
|
@ -62,6 +62,36 @@ ModDetails ReadMCModInfo(QByteArray contents)
|
|||||||
for (auto author : authors) {
|
for (auto author : authors) {
|
||||||
details.authors.append(author.toString());
|
details.authors.append(author.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (details.mod_id.startsWith("mod_")) {
|
||||||
|
details.mod_id = details.mod_id.mid(4);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto addDep = [&details](QString dep) {
|
||||||
|
if (dep == "mod_MinecraftForge" || dep == "Forge")
|
||||||
|
return;
|
||||||
|
if (dep.contains(":")) {
|
||||||
|
dep = dep.section(":", 1);
|
||||||
|
}
|
||||||
|
if (dep.contains("@")) {
|
||||||
|
dep = dep.section("@", 0, 0);
|
||||||
|
}
|
||||||
|
if (dep.startsWith("mod_")) {
|
||||||
|
dep = dep.mid(4);
|
||||||
|
}
|
||||||
|
details.dependencies.append(dep);
|
||||||
|
};
|
||||||
|
|
||||||
|
if (firstObj.contains("requiredMods")) {
|
||||||
|
for (auto dep : firstObj.value("dependencies").toArray().toVariantList()) {
|
||||||
|
addDep(dep.toString());
|
||||||
|
}
|
||||||
|
} else if (firstObj.contains("dependencies")) {
|
||||||
|
for (auto dep : firstObj.value("dependencies").toArray().toVariantList()) {
|
||||||
|
addDep(dep.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return details;
|
return details;
|
||||||
};
|
};
|
||||||
QJsonParseError jsonError;
|
QJsonParseError jsonError;
|
||||||
@ -199,6 +229,42 @@ ModDetails ReadMCModTOML(QByteArray contents)
|
|||||||
}
|
}
|
||||||
details.icon_file = logoFile;
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (tomlData.contains("dependencies")) {
|
||||||
|
auto depValue = tomlData["dependencies"];
|
||||||
|
if (auto array = depValue.as_array()) {
|
||||||
|
parseDep(array);
|
||||||
|
} else if (auto depTable = depValue.as_table()) {
|
||||||
|
auto expectedKey = details.mod_id.toStdString();
|
||||||
|
if (!depTable->contains(expectedKey)) {
|
||||||
|
for (auto [k, v] : *depTable) {
|
||||||
|
expectedKey = k;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (auto array = (*depTable)[expectedKey].as_array()) {
|
||||||
|
parseDep(array);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return details;
|
return details;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -286,6 +352,18 @@ ModDetails ReadFabricModInfo(QByteArray contents)
|
|||||||
details.icon_file = icon.toString();
|
details.icon_file = icon.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (object.contains("depends")) {
|
||||||
|
auto depends = object.value("depends");
|
||||||
|
if (depends.isObject()) {
|
||||||
|
auto obj = depends.toObject();
|
||||||
|
for (auto key : obj.keys()) {
|
||||||
|
if (key != "fabricloader" && key != "minecraft" && !key.startsWith("fabric-")) {
|
||||||
|
details.dependencies.append(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return details;
|
return details;
|
||||||
}
|
}
|
||||||
@ -373,6 +451,29 @@ ModDetails ReadQuiltModInfo(QByteArray contents)
|
|||||||
details.icon_file = icon.toString();
|
details.icon_file = icon.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (object.contains("depends")) {
|
||||||
|
auto depends = object.value("depends");
|
||||||
|
if (depends.isArray()) {
|
||||||
|
auto array = depends.toArray();
|
||||||
|
for (auto obj : array) {
|
||||||
|
QString modId;
|
||||||
|
if (obj.isString()) {
|
||||||
|
modId = obj.toString();
|
||||||
|
} else if (obj.isObject()) {
|
||||||
|
auto objValue = obj.toObject();
|
||||||
|
modId = objValue.value("id").toString();
|
||||||
|
if (objValue.contains("optional") && objValue.value("optional").toBool()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (modId != "minecraft" && !modId.startsWith("quilt_")) {
|
||||||
|
details.dependencies.append(modId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (const Exception& e) {
|
} catch (const Exception& e) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user