Latest version fixes: correctly order preferences (fixes #198)

Both CurseForge and Modrinth preferences were not being done in a specific order - so
a file with a newer Minecraft version would not necessarily take priority over a file
with a more preferred loader (e.g. Quilt over Fabric) or a file with a newer release
date / CurseForge ID.
Also fixed a loop variable reference in the CurseForge loop, which caused eagerly resolved
(included in API response) file info to be inconsistent with the chosen version, and
added filtering for duplicate values in the acceptable-game-versions/primary version list
to ensure game versions are always compared properly (so the same index == same version).
This commit is contained in:
comp500
2023-03-10 16:35:34 +00:00
parent 00fcaaade3
commit 42d8370d0c
3 changed files with 53 additions and 14 deletions

View File

@@ -3,6 +3,7 @@ package core
import (
"errors"
"fmt"
"golang.org/x/exp/slices"
"io"
"os"
"path/filepath"
@@ -171,7 +172,16 @@ func (pack Pack) GetSupportedMCVersions() ([]string, error) {
return nil, errors.New("no minecraft version specified in modpack")
}
allVersions := append(append([]string(nil), viper.GetStringSlice("acceptable-game-versions")...), mcVersion)
return allVersions, nil
// Deduplicate values
allVersionsDeduped := []string(nil)
for i, v := range allVersions {
// If another copy of this value exists past this point in the array, don't insert
// (i.e. prefer a later copy over an earlier copy, so the main version is last)
if !slices.Contains(allVersions[i+1:], v) {
allVersionsDeduped = append(allVersionsDeduped, v)
}
}
return allVersionsDeduped, nil
}
func (pack Pack) GetPackName() string {