Fix installing by file ID, allow using --file-id with slug

This commit is contained in:
comp500 2022-04-30 21:02:00 +01:00
parent e29c3022b3
commit efb434dadc

View File

@ -47,10 +47,11 @@ var installCmd = &cobra.Command{
var done bool var done bool
var modID, fileID int var modID, fileID int
// If mod/file IDs are provided in command line, use those // If mod/file IDs are provided in command line, use those
// TODO: use file id with slug if it exists? if fileIDFlag != 0 {
fileID = fileIDFlag
}
if addonIDFlag != 0 { if addonIDFlag != 0 {
modID = addonIDFlag modID = addonIDFlag
fileID = fileIDFlag
done = true done = true
} }
if (len(args) == 0 || len(args[0]) == 0) && !done { if (len(args) == 0 || len(args[0]) == 0) && !done {
@ -334,12 +335,12 @@ func searchCurseforgeInternal(args []string, mcVersion string, packLoaderType in
} }
func getLatestFile(modInfoData modInfo, mcVersion string, fileID int, packLoaderType int) (modFileInfo, error) { func getLatestFile(modInfoData modInfo, mcVersion string, fileID int, packLoaderType int) (modFileInfo, error) {
anyFileObtained := false
// For snapshots, curseforge doesn't put them in GameVersionLatestFiles
if fileID == 0 { if fileID == 0 {
var fileInfoData modFileInfo var fileInfoData modFileInfo
fileInfoObtained := false fileInfoObtained := false
anyFileObtained := false
// For snapshots, curseforge doesn't put them in GameVersionLatestFiles
for _, v := range modInfoData.LatestFiles { for _, v := range modInfoData.LatestFiles {
anyFileObtained = true anyFileObtained = true
// Choose "newest" version by largest ID // Choose "newest" version by largest ID
@ -361,13 +362,10 @@ func getLatestFile(modInfoData modInfo, mcVersion string, fileID int, packLoader
if fileInfoObtained { if fileInfoObtained {
return fileInfoData, nil return fileInfoData, nil
} }
}
if !anyFileObtained { if !anyFileObtained {
return modFileInfo{}, fmt.Errorf("addon %d has no files", modInfoData.ID) return modFileInfo{}, fmt.Errorf("addon %d has no files", modInfoData.ID)
} }
if fileID == 0 {
return modFileInfo{}, errors.New("mod not available for the configured Minecraft version(s) (use the acceptable-game-versions option to accept more) or loader") return modFileInfo{}, errors.New("mod not available for the configured Minecraft version(s) (use the acceptable-game-versions option to accept more) or loader")
} }