made dependency check more lax

Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
Trial97 2023-11-02 23:52:12 +02:00
parent f8bb1a872a
commit 4081c51573
No known key found for this signature in database
GPG Key ID: 55EF5DA53DB36318
2 changed files with 68 additions and 3 deletions

View File

@ -57,9 +57,11 @@ GetModDependenciesTask::GetModDependenciesTask(QObject* parent,
, m_version(mcVersion(instance)) , m_version(mcVersion(instance))
, m_loaderType(mcLoaders(instance)) , m_loaderType(mcLoaders(instance))
{ {
for (auto mod : folder->allMods()) for (auto mod : folder->allMods()) {
m_mods_file_names << mod->fileinfo().fileName();
if (auto meta = mod->metadata(); meta) if (auto meta = mod->metadata(); meta)
m_mods.append(meta); m_mods.append(meta);
}
prepare(); prepare();
} }
@ -225,9 +227,14 @@ Task::Ptr GetModDependenciesTask::prepareDependencyTask(const ModPlatform::Depen
if (dep_.addonId != pDep->version.addonId) { if (dep_.addonId != pDep->version.addonId) {
removePack(pDep->version.addonId); removePack(pDep->version.addonId);
addTask(prepareDependencyTask(dep_, provider.name, level)); addTask(prepareDependencyTask(dep_, provider.name, level));
} else } else {
addTask(getProjectInfoTask(pDep)); addTask(getProjectInfoTask(pDep));
} }
}
if (isLocalyInstalled(pDep)) {
removePack(pDep->version.addonId);
return;
}
for (auto dep_ : getDependenciesForVersion(pDep->version, provider.name)) { for (auto dep_ : getDependenciesForVersion(pDep->version, provider.name)) {
addTask(prepareDependencyTask(dep_, provider.name, level - 1)); addTask(prepareDependencyTask(dep_, provider.name, level - 1));
} }
@ -280,3 +287,57 @@ QHash<QString, QStringList> GetModDependenciesTask::getRequiredBy()
} }
return rby; return rby;
} }
// super lax compare (but not fuzzy)
// convert to lowercase
// convert all speratores to whitespace
// simplify sequence of internal whitespace to a single space
// efectivly compare two strings ignoring all separators and case
auto laxCompare = [](QString fsfilename, QString metadataFilename, bool excludeDigits = false) {
// allowed character seperators
QList<QChar> allowedSeperators = { '-', '+', '.', '_' };
if (excludeDigits)
allowedSeperators.append({ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' });
// copy in lowercase
auto fsName = fsfilename.toLower();
auto metaName = metadataFilename.toLower();
// replace all potential allowed seperatores with whitespace
for (auto sep : allowedSeperators) {
fsName = fsName.replace(sep, ' ');
metaName = metaName.replace(sep, ' ');
}
// remove extraneous whitespace
fsName = fsName.simplified();
metaName = metaName.simplified();
return fsName.compare(metaName) == 0;
};
bool GetModDependenciesTask::isLocalyInstalled(std::shared_ptr<PackDependency> pDep)
{
return pDep->version.fileName.isEmpty() ||
std::find_if(m_selected.begin(), m_selected.end(),
[pDep](std::shared_ptr<PackDependency> i) {
return !i->version.fileName.isEmpty() && laxCompare(i->version.fileName, pDep->version.fileName);
}) != m_selected.end() || // check the selected versions
std::find_if(m_mods_file_names.begin(), m_mods_file_names.end(),
[pDep](QString i) { return !i.isEmpty() && laxCompare(i, pDep->version.fileName); }) !=
m_mods_file_names.end() || // check the existing mods
std::find_if(m_pack_dependencies.begin(), m_pack_dependencies.end(), [pDep](std::shared_ptr<PackDependency> i) {
return pDep->pack->addonId != i->pack->addonId && !i->version.fileName.isEmpty() &&
laxCompare(pDep->version.fileName, i->version.fileName);
}) != m_pack_dependencies.end(); // check loaded dependencies
}
bool GetModDependenciesTask::isLaxInstalled(std::shared_ptr<PackDependency> pDep)
{
return std::find_if(m_mods_file_names.begin(), m_mods_file_names.end(), [pDep](QString i) {
return !i.isEmpty() && laxCompare(i, pDep->version.fileName, true);
}) != m_mods_file_names.end(); // check the existing mods
}

View File

@ -73,10 +73,14 @@ class GetModDependenciesTask : public SequentialTask {
ModPlatform::Dependency getOverride(const ModPlatform::Dependency&, const ModPlatform::ResourceProvider providerName); ModPlatform::Dependency getOverride(const ModPlatform::Dependency&, const ModPlatform::ResourceProvider providerName);
void removePack(const QVariant addonId); void removePack(const QVariant addonId);
bool isLocalyInstalled(std::shared_ptr<PackDependency> pDep);
bool isLaxInstalled(std::shared_ptr<PackDependency> pDep);
private: private:
QList<std::shared_ptr<PackDependency>> m_pack_dependencies; QList<std::shared_ptr<PackDependency>> m_pack_dependencies;
QList<std::shared_ptr<Metadata::ModStruct>> m_mods; QList<std::shared_ptr<Metadata::ModStruct>> m_mods;
QList<std::shared_ptr<PackDependency>> m_selected; QList<std::shared_ptr<PackDependency>> m_selected;
QStringList m_mods_file_names;
Provider m_flame_provider; Provider m_flame_provider;
Provider m_modrinth_provider; Provider m_modrinth_provider;