mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2025-06-13 05:37:42 +02:00
fix the flame loaders match
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
@ -270,21 +270,35 @@ std::optional<ModPlatform::IndexedVersion> FlameAPI::getLatestVersion(QList<ModP
|
||||
QList<ModPlatform::ModLoaderType> instanceLoaders,
|
||||
ModPlatform::ModLoaderTypes modLoaders)
|
||||
{
|
||||
// edge case: mod has installed for forge but the instance is fabric => fabric version will be prioritizated on update
|
||||
auto bestVersion = [&versions](ModPlatform::ModLoaderTypes loader) {
|
||||
std::optional<ModPlatform::IndexedVersion> ver;
|
||||
for (auto file_tmp : versions) {
|
||||
if (file_tmp.loaders & loader && (!ver.has_value() || file_tmp.date > ver->date)) {
|
||||
ver = file_tmp;
|
||||
QHash<ModPlatform::ModLoaderType, ModPlatform::IndexedVersion> bestMatch;
|
||||
auto checkVersion = [&bestMatch](const ModPlatform::IndexedVersion& version, const ModPlatform::ModLoaderType& loader) {
|
||||
if (bestMatch.contains(loader)) {
|
||||
auto best = bestMatch.value(loader);
|
||||
if (version.date > best.date) {
|
||||
bestMatch[loader] = version;
|
||||
}
|
||||
} else {
|
||||
bestMatch[loader] = version;
|
||||
}
|
||||
};
|
||||
for (auto file_tmp : versions) {
|
||||
auto loaders = ModPlatform::modLoaderTypesToList(file_tmp.loaders);
|
||||
if (loaders.isEmpty()) {
|
||||
checkVersion(file_tmp, ModPlatform::ModLoaderType(0));
|
||||
} else {
|
||||
for (auto loader : loaders) {
|
||||
checkVersion(file_tmp, loader);
|
||||
}
|
||||
}
|
||||
return ver;
|
||||
};
|
||||
for (auto l : instanceLoaders) {
|
||||
auto ver = bestVersion(l);
|
||||
if (ver.has_value()) {
|
||||
return ver;
|
||||
}
|
||||
// edge case: mod has installed for forge but the instance is fabric => fabric version will be prioritizated on update
|
||||
auto currentLoaders = instanceLoaders + ModPlatform::modLoaderTypesToList(modLoaders);
|
||||
currentLoaders.append(ModPlatform::ModLoaderType(0)); // add a fallback in case the versions do not define a loader
|
||||
|
||||
for (auto loader : currentLoaders) {
|
||||
if (bestMatch.contains(loader)) {
|
||||
return bestMatch.value(loader);
|
||||
}
|
||||
}
|
||||
return bestVersion(modLoaders);
|
||||
return {};
|
||||
}
|
||||
|
Reference in New Issue
Block a user