mirror of
https://github.com/packwiz/packwiz.git
synced 2025-10-17 00:04:31 +02:00
Add migrate command (#207)
* Add base and loader command * Support updating to latest * Support explicit fabric versions * Support explicit Forge version * Support quilt * Add support for updating Minecraft * Add support for Forge recommended * Fix Forge version sorting * Various fixes * Add documentation to the use * More suggestions
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"encoding/xml"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/unascribed/FlexVer/go/flexver"
|
||||
"strings"
|
||||
)
|
||||
@@ -95,7 +97,7 @@ func FetchMavenVersionPrefixedList(url string, friendlyName string) func(mcVersi
|
||||
return allowedVersions, out.Versioning.Latest, nil
|
||||
}
|
||||
// Sort list to get largest version
|
||||
flexver.VersionSlice(out.Versioning.Versions.Version).Sort()
|
||||
flexver.VersionSlice(allowedVersions).Sort()
|
||||
return allowedVersions, allowedVersions[len(allowedVersions)-1], nil
|
||||
}
|
||||
}
|
||||
@@ -158,3 +160,34 @@ func HighestSliceIndex(slice []string, values []string) int {
|
||||
}
|
||||
return highest
|
||||
}
|
||||
|
||||
type ForgeRecommended struct {
|
||||
Homepage string `json:"homepage"`
|
||||
Versions map[string]string `json:"promos"`
|
||||
}
|
||||
|
||||
// GetForgeRecommended gets the recommended version of Forge for the given Minecraft version
|
||||
func GetForgeRecommended(mcVersion string) string {
|
||||
res, err := GetWithUA("https://files.minecraftforge.net/net/minecraftforge/forge/promotions_slim.json", "application/json")
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
dec := json.NewDecoder(res.Body)
|
||||
out := ForgeRecommended{}
|
||||
err = dec.Decode(&out)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return ""
|
||||
}
|
||||
// Get mcVersion-recommended, if it doesn't exist then get mcVersion-latest
|
||||
// If neither exist, return empty string
|
||||
recommendedString := fmt.Sprintf("%s-recommended", mcVersion)
|
||||
if out.Versions[recommendedString] != "" {
|
||||
return out.Versions[recommendedString]
|
||||
}
|
||||
latestString := fmt.Sprintf("%s-latest", mcVersion)
|
||||
if out.Versions[latestString] != "" {
|
||||
return out.Versions[latestString]
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
Reference in New Issue
Block a user