mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2025-09-23 03:07:09 -04:00
feat: store provider dependencies
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
parent
1a6693e57a
commit
c12f3c4038
@ -152,9 +152,6 @@ class Resource : public QObject {
|
||||
|
||||
bool isMoreThanOneHardLink() const;
|
||||
|
||||
auto mod_id() const -> QString { return m_mod_id; }
|
||||
void setModId(const QString& modId) { m_mod_id = modId; }
|
||||
|
||||
protected:
|
||||
/* The file corresponding to this resource. */
|
||||
QFileInfo m_file_info;
|
||||
@ -165,7 +162,6 @@ class Resource : public QObject {
|
||||
QString m_internal_id;
|
||||
/* Name as reported via the file name. In the absence of a better name, this is shown to the user. */
|
||||
QString m_name;
|
||||
QString m_mod_id;
|
||||
|
||||
/* The type of file we're dealing with. */
|
||||
ResourceType m_type = ResourceType::UNKNOWN;
|
||||
|
@ -197,4 +197,40 @@ Side SideUtils::fromString(QString side)
|
||||
return Side::UniversalSide;
|
||||
return Side::UniversalSide;
|
||||
}
|
||||
|
||||
QString DependencyTypeUtils::toString(DependencyType type)
|
||||
{
|
||||
switch (type) {
|
||||
case DependencyType::REQUIRED:
|
||||
return "REQUIRED";
|
||||
case DependencyType::OPTIONAL:
|
||||
return "OPTIONAL";
|
||||
case DependencyType::INCOMPATIBLE:
|
||||
return "INCOMPATIBLE";
|
||||
case DependencyType::EMBEDDED:
|
||||
return "EMBEDDED";
|
||||
case DependencyType::TOOL:
|
||||
return "TOOL";
|
||||
case DependencyType::INCLUDE:
|
||||
return "INCLUDE";
|
||||
case DependencyType::UNKNOWN:
|
||||
return "UNKNOWN";
|
||||
}
|
||||
return "UNKNOWN";
|
||||
}
|
||||
|
||||
DependencyType DependencyTypeUtils::fromString(const QString& str)
|
||||
{
|
||||
static const QHash<QString, DependencyType> map = {
|
||||
{ "REQUIRED", DependencyType::REQUIRED },
|
||||
{ "OPTIONAL", DependencyType::OPTIONAL },
|
||||
{ "INCOMPATIBLE", DependencyType::INCOMPATIBLE },
|
||||
{ "EMBEDDED", DependencyType::EMBEDDED },
|
||||
{ "TOOL", DependencyType::TOOL },
|
||||
{ "INCLUDE", DependencyType::INCLUDE },
|
||||
{ "UNKNOWN", DependencyType::UNKNOWN },
|
||||
};
|
||||
|
||||
return map.value(str.toUpper(), DependencyType::UNKNOWN);
|
||||
}
|
||||
} // namespace ModPlatform
|
||||
|
@ -57,6 +57,11 @@ QString toString(Side side);
|
||||
Side fromString(QString side);
|
||||
} // namespace SideUtils
|
||||
|
||||
namespace DependencyTypeUtils {
|
||||
QString toString(DependencyType type);
|
||||
DependencyType fromString(const QString& str);
|
||||
} // namespace DependencyTypeUtils
|
||||
|
||||
namespace ProviderCapabilities {
|
||||
const char* name(ResourceProvider);
|
||||
QString readableName(ResourceProvider);
|
||||
|
@ -122,6 +122,7 @@ auto V1::createModFormat([[maybe_unused]] const QDir& index_dir,
|
||||
if (mod.version_number.isNull()) // on CurseForge, there is only a version name - not a version number
|
||||
mod.version_number = mod_version.version;
|
||||
|
||||
mod.dependencies = mod_version.dependencies;
|
||||
return mod;
|
||||
}
|
||||
|
||||
@ -190,6 +191,16 @@ void V1::updateModIndex(const QDir& index_dir, Mod& mod)
|
||||
return;
|
||||
}
|
||||
|
||||
toml::array deps;
|
||||
for (auto dep : mod.dependencies) {
|
||||
auto tbl = toml::table{ { "addonId", dep.addonId.toString().toStdString() },
|
||||
{ "type", ModPlatform::DependencyTypeUtils::toString(dep.type).toStdString() } };
|
||||
if (!dep.version.isEmpty()) {
|
||||
tbl.emplace("version", dep.version.toStdString());
|
||||
}
|
||||
deps.push_back(tbl);
|
||||
}
|
||||
|
||||
// Put TOML data into the file
|
||||
QTextStream in_stream(&index_file);
|
||||
{
|
||||
@ -200,6 +211,7 @@ void V1::updateModIndex(const QDir& index_dir, Mod& mod)
|
||||
{ "x-prismlauncher-mc-versions", mcVersions },
|
||||
{ "x-prismlauncher-release-type", mod.releaseType.toString().toStdString() },
|
||||
{ "x-prismlauncher-version-number", mod.version_number.toStdString() },
|
||||
{ "x-prismlauncher-dependencies", deps },
|
||||
{ "download",
|
||||
toml::table{
|
||||
{ "mode", mod.mode.toStdString() },
|
||||
@ -330,6 +342,21 @@ auto V1::getIndexForMod(const QDir& index_dir, QString slug) -> Mod
|
||||
return {};
|
||||
}
|
||||
}
|
||||
{ // dependencies
|
||||
auto deps = table["x-prismlauncher-dependencies"].as_array();
|
||||
if (deps) {
|
||||
for (auto&& depNode : *deps) {
|
||||
auto dep = depNode.as_table();
|
||||
if (dep) {
|
||||
ModPlatform::Dependency d;
|
||||
d.addonId = stringEntry(*dep, "addonId");
|
||||
d.version = stringEntry(*dep, "version");
|
||||
d.type = ModPlatform::DependencyTypeUtils::fromString(stringEntry(*dep, "type"));
|
||||
mod.dependencies << d;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return mod;
|
||||
}
|
||||
|
@ -55,6 +55,8 @@ class V1 {
|
||||
QVariant project_id{};
|
||||
QString version_number{};
|
||||
|
||||
QList<ModPlatform::Dependency> dependencies;
|
||||
|
||||
public:
|
||||
// This is a totally heuristic, but should work for now.
|
||||
auto isValid() const -> bool { return !slug.isEmpty() && !project_id.isNull(); }
|
||||
|
Loading…
x
Reference in New Issue
Block a user