Small fixes

Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
Trial97 2023-06-19 00:36:37 +03:00
parent 319ce8c19f
commit 1bdde1f947
No known key found for this signature in database
GPG Key ID: 55EF5DA53DB36318
7 changed files with 54 additions and 51 deletions

View File

@ -33,7 +33,7 @@
#include "ui/pages/modplatform/flame/FlameResourceModels.h"
#include "ui/pages/modplatform/modrinth/ModrinthResourceModels.h"
static Version mcVersions(BaseInstance* inst)
static Version mcVersion(BaseInstance* inst)
{
return static_cast<MinecraftInstance*>(inst)->getPackProfile()->getComponent("net.minecraft")->getVersion();
}
@ -53,7 +53,7 @@ GetModDependenciesTask::GetModDependenciesTask(QObject* parent,
std::make_shared<FlameAPI>() }
, m_modrinth_provider{ ModPlatform::ResourceProvider::MODRINTH, std::make_shared<ResourceDownload::ModrinthModModel>(*instance),
std::make_shared<ModrinthAPI>() }
, m_version(mcVersions(instance))
, m_version(mcVersion(instance))
, m_loaderType(mcLoaders(instance))
{
for (auto mod : folder->allMods())
@ -74,34 +74,39 @@ void GetModDependenciesTask::prepare()
QList<ModPlatform::Dependency> GetModDependenciesTask::getDependenciesForVersion(const ModPlatform::IndexedVersion& version,
const ModPlatform::ResourceProvider providerName)
{
auto c_dependencies = QList<ModPlatform::Dependency>();
QList<ModPlatform::Dependency> c_dependencies;
for (auto ver_dep : version.dependencies) {
if (ver_dep.type == ModPlatform::DependencyType::REQUIRED) {
if (ver_dep.type != ModPlatform::DependencyType::REQUIRED)
continue;
if (auto dep = std::find_if(c_dependencies.begin(), c_dependencies.end(),
[&ver_dep](const ModPlatform::Dependency& i) { return i.addonId == ver_dep.addonId; });
dep == c_dependencies.end()) { // check the current dependency list
dep != c_dependencies.end())
continue; // check the current dependency list
if (auto dep = std::find_if(m_selected.begin(), m_selected.end(),
[&ver_dep, providerName](std::shared_ptr<PackDependency> i) {
return i->pack->addonId == ver_dep.addonId && i->pack->provider == providerName;
});
dep == m_selected.end()) { // check the selected versions
dep != m_selected.end())
continue; // check the selected versions
if (auto dep = std::find_if(m_mods.begin(), m_mods.end(),
[&ver_dep, providerName](std::shared_ptr<Metadata::ModStruct> i) {
return i->project_id == ver_dep.addonId && i->provider == providerName;
});
dep == m_mods.end()) { // check the existing mods
dep != m_mods.end())
continue; // check the existing mods
if (auto dep = std::find_if(m_pack_dependencies.begin(), m_pack_dependencies.end(),
[&ver_dep, providerName](std::shared_ptr<PackDependency> i) {
return i->pack->addonId == ver_dep.addonId && i->pack->provider == providerName;
});
dep == m_pack_dependencies.end()) { // check loaded dependencies
dep != m_pack_dependencies.end()) // check loaded dependencies
continue;
c_dependencies.append(ver_dep);
}
}
}
}
}
}
return c_dependencies;
};

View File

@ -42,7 +42,7 @@ class GetModDependenciesTask : public SequentialTask {
ModPlatform::Dependency dependency;
ModPlatform::IndexedPack::Ptr pack;
ModPlatform::IndexedVersion version;
PackDependency(){};
PackDependency() = default;
PackDependency(const ModPlatform::IndexedPack::Ptr p, const ModPlatform::IndexedVersion& v)
{
pack = p;

View File

@ -34,7 +34,7 @@ enum class ResourceProvider { MODRINTH, FLAME };
enum class ResourceType { MOD, RESOURCE_PACK, SHADER_PACK };
enum class DependencyType { REQUIRED, OPTIONAL, INCOMPATIBLE, EMBEDDED, TOOL, INCLUDE };
enum class DependencyType { REQUIRED, OPTIONAL, INCOMPATIBLE, EMBEDDED, TOOL, INCLUDE, UNKNOWN };
class ProviderCapabilities {
public:

View File

@ -115,14 +115,6 @@ class ResourceAPI {
ModPlatform::Dependency dependency;
Version mcVersion;
ModLoaderTypes loader;
DependencySearchArgs(DependencySearchArgs const&) = default;
void operator=(DependencySearchArgs other)
{
dependency = other.dependency;
mcVersion = other.mcVersion;
loader = other.loader;
}
};
struct DependencySearchCallbacks {

View File

@ -160,6 +160,10 @@ auto FlameMod::loadIndexedPackVersion(QJsonObject& obj, bool load_changelog) ->
case 6: // Include
dependency.type = ModPlatform::DependencyType::INCLUDE;
break;
default:
dependency.type = ModPlatform::DependencyType::UNKNOWN;
break;
}
file.dependencies.append(dependency);
}
@ -172,7 +176,7 @@ auto FlameMod::loadIndexedPackVersion(QJsonObject& obj, bool load_changelog) ->
ModPlatform::IndexedVersion FlameMod::loadDependencyVersions(const ModPlatform::Dependency& m, QJsonArray& arr)
{
QVector<ModPlatform::IndexedVersion> unsortedVersions;
QVector<ModPlatform::IndexedVersion> versions;
for (auto versionIter : arr) {
auto obj = versionIter.toObject();
@ -181,13 +185,13 @@ ModPlatform::IndexedVersion FlameMod::loadDependencyVersions(const ModPlatform::
file.addonId = m.addonId;
if (file.fileId.isValid()) // Heuristic to check if the returned value is valid
unsortedVersions.append(file);
versions.append(file);
}
auto orderSortPredicate = [](const ModPlatform::IndexedVersion& a, const ModPlatform::IndexedVersion& b) -> bool {
// dates are in RFC 3339 format
return a.date > b.date;
};
std::sort(unsortedVersions.begin(), unsortedVersions.end(), orderSortPredicate);
return unsortedVersions.front();
std::sort(versions.begin(), versions.end(), orderSortPredicate);
return versions.front();
};

View File

@ -156,6 +156,8 @@ auto Modrinth::loadIndexedPackVersion(QJsonObject& obj, QString preferred_hash_t
dependency.type = ModPlatform::DependencyType::INCOMPATIBLE;
else if (depType == "embedded")
dependency.type = ModPlatform::DependencyType::EMBEDDED;
else
dependency.type = ModPlatform::DependencyType::UNKNOWN;
file.dependencies.append(dependency);
}
@ -218,19 +220,19 @@ auto Modrinth::loadIndexedPackVersion(QJsonObject& obj, QString preferred_hash_t
auto Modrinth::loadDependencyVersions(const ModPlatform::Dependency& m, QJsonArray& arr) -> ModPlatform::IndexedVersion
{
QVector<ModPlatform::IndexedVersion> unsortedVersions;
QVector<ModPlatform::IndexedVersion> versions;
for (auto versionIter : arr) {
auto obj = versionIter.toObject();
auto file = loadIndexedPackVersion(obj);
if (file.fileId.isValid()) // Heuristic to check if the returned value is valid
unsortedVersions.append(file);
versions.append(file);
}
auto orderSortPredicate = [](const ModPlatform::IndexedVersion& a, const ModPlatform::IndexedVersion& b) -> bool {
// dates are in RFC 3339 format
return a.date > b.date;
};
std::sort(unsortedVersions.begin(), unsortedVersions.end(), orderSortPredicate);
return unsortedVersions.length() != 0 ? unsortedVersions.front() : ModPlatform::IndexedVersion();
std::sort(versions.begin(), versions.end(), orderSortPredicate);
return versions.length() != 0 ? versions.front() : ModPlatform::IndexedVersion();
}

View File

@ -125,7 +125,7 @@ void ResourceDownloadDialog::connectButtons()
static ModPlatform::ProviderCapabilities ProviderCaps;
QStringList getReqiredBy(QList<ResourceDownloadDialog::DownloadTaskPtr> tasks, QVariant addonId)
QStringList getRequiredBy(QList<ResourceDownloadDialog::DownloadTaskPtr> tasks, QVariant addonId)
{
auto req = QStringList();
for (auto& task : tasks) {
@ -167,8 +167,8 @@ void ResourceDownloadDialog::confirm()
if (ret == QDialog::DialogCode::Rejected) {
QMetaObject::invokeMethod(this, "reject", Qt::QueuedConnection);
return;
} else
for (auto dep : task->getDependecies()) {
} else {
for (auto dep : task->getDependecies())
addResource(dep->pack, dep->version);
}
}
@ -179,7 +179,7 @@ void ResourceDownloadDialog::confirm()
});
for (auto& task : selected) {
confirm_dialog->appendResource({ task->getName(), task->getFilename(), task->getCustomPath(),
ProviderCaps.name(task->getProvider()), getReqiredBy(selected, task->getPack()->addonId) });
ProviderCaps.name(task->getProvider()), getRequiredBy(selected, task->getPack()->addonId) });
}
if (confirm_dialog->exec()) {