Bump current pack format version number and auto-migrate loaded packs

This commit is contained in:
comp500 2022-05-21 05:05:08 +01:00
parent dae133b73c
commit fc3b5ff8ea

View File

@ -31,10 +31,10 @@ type Pack struct {
Options map[string]interface{} `toml:"options"` Options map[string]interface{} `toml:"options"`
} }
const CurrentPackFormat = "packwiz:1.0.0" const CurrentPackFormat = "packwiz:1.1.0"
var PackFormatConstraintAccepted = mustParseConstraint("~1") var PackFormatConstraintAccepted = mustParseConstraint("~1")
var PackFormatConstraintSuggestUpgrade = mustParseConstraint("~1.0") var PackFormatConstraintSuggestUpgrade = mustParseConstraint("~1.1")
func mustParseConstraint(s string) *semver.Constraints { func mustParseConstraint(s string) *semver.Constraints {
c, err := semver.NewConstraint(s) c, err := semver.NewConstraint(s)
@ -53,8 +53,13 @@ func LoadPack() (Pack, error) {
// Check pack-format // Check pack-format
if len(modpack.PackFormat) == 0 { if len(modpack.PackFormat) == 0 {
fmt.Println("Modpack manifest has no pack-format field; assuming packwiz:1.0.0") fmt.Println("Modpack manifest has no pack-format field; assuming packwiz:1.1.0")
modpack.PackFormat = "packwiz:1.0.0" modpack.PackFormat = "packwiz:1.1.0"
}
// Auto-migrate versions
if modpack.PackFormat == "packwiz:1.0.0" {
fmt.Println("Automatically migrating pack to packwiz:1.1.0 format...")
modpack.PackFormat = "packwiz:1.1.0"
} }
if !strings.HasPrefix(modpack.PackFormat, "packwiz:") { if !strings.HasPrefix(modpack.PackFormat, "packwiz:") {
return Pack{}, errors.New("pack-format field does not indicate a valid packwiz pack") return Pack{}, errors.New("pack-format field does not indicate a valid packwiz pack")