mirror of
https://github.com/packwiz/packwiz.git
synced 2025-10-24 17:44:32 +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:
52
cmdshared/mcversion.go
Normal file
52
cmdshared/mcversion.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package cmdshared
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/packwiz/packwiz/core"
|
||||
"os"
|
||||
"sort"
|
||||
"time"
|
||||
)
|
||||
|
||||
type McVersionManifest struct {
|
||||
Latest struct {
|
||||
Release string `json:"release"`
|
||||
Snapshot string `json:"snapshot"`
|
||||
} `json:"latest"`
|
||||
Versions []struct {
|
||||
ID string `json:"id"`
|
||||
Type string `json:"type"`
|
||||
URL string `json:"url"`
|
||||
Time time.Time `json:"time"`
|
||||
ReleaseTime time.Time `json:"releaseTime"`
|
||||
} `json:"versions"`
|
||||
}
|
||||
|
||||
func (m McVersionManifest) CheckValid(version string) {
|
||||
for _, v := range m.Versions {
|
||||
if v.ID == version {
|
||||
return
|
||||
}
|
||||
}
|
||||
fmt.Println("Given version is not a valid Minecraft version!")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
func GetValidMCVersions() (McVersionManifest, error) {
|
||||
res, err := core.GetWithUA("https://launchermeta.mojang.com/mc/game/version_manifest.json", "application/json")
|
||||
if err != nil {
|
||||
return McVersionManifest{}, err
|
||||
}
|
||||
dec := json.NewDecoder(res.Body)
|
||||
out := McVersionManifest{}
|
||||
err = dec.Decode(&out)
|
||||
if err != nil {
|
||||
return McVersionManifest{}, err
|
||||
}
|
||||
// Sort by newest to oldest
|
||||
sort.Slice(out.Versions, func(i, j int) bool {
|
||||
return out.Versions[i].ReleaseTime.Before(out.Versions[j].ReleaseTime)
|
||||
})
|
||||
return out, nil
|
||||
}
|
||||
16
cmdshared/utils.go
Normal file
16
cmdshared/utils.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package cmdshared
|
||||
|
||||
import "strings"
|
||||
|
||||
func GetRawForgeVersion(version string) string {
|
||||
var wantedVersion string
|
||||
// Check if we have a "-" in the version
|
||||
if strings.Contains(version, "-") {
|
||||
// We have a mcVersion-loaderVersion format
|
||||
// Strip the mcVersion
|
||||
wantedVersion = strings.Split(version, "-")[1]
|
||||
} else {
|
||||
wantedVersion = version
|
||||
}
|
||||
return wantedVersion
|
||||
}
|
||||
Reference in New Issue
Block a user