Hopefully handle snapshots (or at least 20w12a) correctly

This commit is contained in:
comp500 2020-03-25 20:42:01 +00:00
parent 1b21b91ac2
commit 6b04aaf74d
2 changed files with 35 additions and 3 deletions

View File

@ -28,6 +28,14 @@ var fileIDRegexes = [...]*regexp.Regexp{
regexp.MustCompile("^https?://(?:www\\.)?curseforge\\.com/minecraft/mc-mods/(.+)/download/(\\d+)"), regexp.MustCompile("^https?://(?:www\\.)?curseforge\\.com/minecraft/mc-mods/(.+)/download/(\\d+)"),
} }
// TODO: fix this later
func fixThisLater(mcVersion string) string {
if mcVersion == "20w12a" {
return "1.16-Snapshot"
}
return mcVersion
}
func getFileIDsFromString(mod string) (bool, int, int, error) { func getFileIDsFromString(mod string) (bool, int, int, error) {
for _, v := range fileIDRegexes { for _, v := range fileIDRegexes {
matches := v.FindStringSubmatch(mod) matches := v.FindStringSubmatch(mod)
@ -196,7 +204,7 @@ func (u cfUpdater) CheckUpdate(mods []core.Mod, mcVersion string) ([]core.Update
// TODO: change to timestamp-based comparison?? // TODO: change to timestamp-based comparison??
// TODO: manage alpha/beta/release correctly, check update channel? // TODO: manage alpha/beta/release correctly, check update channel?
// Choose "newest" version by largest ID // Choose "newest" version by largest ID
if file.GameVersion == mcVersion && file.ID > fileID { if file.GameVersion == fixThisLater(mcVersion) && file.ID > fileID {
updateAvailable = true updateAvailable = true
fileID = file.ID fileID = file.ID
fileName = file.Name fileName = file.Name

View File

@ -268,7 +268,7 @@ func (r modResultsList) Len() int {
func searchCurseforgeInternal(args []string, mcVersion string) (bool, modInfo) { func searchCurseforgeInternal(args []string, mcVersion string) (bool, modInfo) {
fmt.Println("Searching CurseForge...") fmt.Println("Searching CurseForge...")
searchTerm := strings.Join(args, " ") searchTerm := strings.Join(args, " ")
results, err := getSearch(searchTerm, mcVersion) results, err := getSearch(searchTerm, fixThisLater(mcVersion))
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
os.Exit(1) os.Exit(1)
@ -326,12 +326,36 @@ func searchCurseforgeInternal(args []string, mcVersion string) (bool, modInfo) {
} }
} }
func sliceContainsString(slice []string, elem string) bool {
for _, a := range slice {
if a == elem {
return true
}
}
return false
}
func getLatestFile(modInfoData modInfo, mcVersion string, fileID int) (modFileInfo, error) { func getLatestFile(modInfoData modInfo, mcVersion string, fileID int) (modFileInfo, error) {
// For snapshots, curseforge doesn't put them in GameVersionLatestFiles
if fileID == 0 {
var fileInfoData modFileInfo
for _, v := range modInfoData.LatestFiles {
// Choose "newest" version by largest ID
if sliceContainsString(v.GameVersions, fixThisLater(mcVersion)) && v.ID > fileID {
fileID = v.ID
fileInfoData = v
}
}
if fileID != 0 {
return fileInfoData, nil
}
}
if fileID == 0 { if fileID == 0 {
// TODO: change to timestamp-based comparison?? // TODO: change to timestamp-based comparison??
for _, v := range modInfoData.GameVersionLatestFiles { for _, v := range modInfoData.GameVersionLatestFiles {
// Choose "newest" version by largest ID // Choose "newest" version by largest ID
if v.GameVersion == mcVersion && v.ID > fileID { if v.GameVersion == fixThisLater(mcVersion) && v.ID > fileID {
fileID = v.ID fileID = v.ID
} }
} }