mirror of
https://github.com/packwiz/packwiz.git
synced 2025-04-19 21:16:30 +02:00
Add update logic for single mods
This commit is contained in:
parent
b6c71191d4
commit
06c5b08813
@ -281,8 +281,8 @@ func (u cfUpdater) DoUpdate(mods []*core.Mod, cachedState []interface{}) error {
|
|||||||
Hash: strconv.Itoa(modState.fileInfo.Fingerprint),
|
Hash: strconv.Itoa(modState.fileInfo.Fingerprint),
|
||||||
}
|
}
|
||||||
|
|
||||||
v.Update["curseforge"]["ProjectID"] = modState.ID
|
v.Update["curseforge"]["project-id"] = modState.ID
|
||||||
v.Update["curseforge"]["FileID"] = modState.fileInfo.ID
|
v.Update["curseforge"]["file-id"] = modState.fileInfo.ID
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
98
main.go
98
main.go
@ -25,8 +25,7 @@ func init() {
|
|||||||
Aliases: []string{"upgrade"},
|
Aliases: []string{"upgrade"},
|
||||||
Usage: "Update a mod (or all mods) in the modpack",
|
Usage: "Update a mod (or all mods) in the modpack",
|
||||||
Action: func(c *cli.Context) error {
|
Action: func(c *cli.Context) error {
|
||||||
// TODO: implement
|
return cmdUpdate(core.FlagsFromContext(c), c.Args().Get(0))
|
||||||
return nil
|
|
||||||
},
|
},
|
||||||
}, cli.Command{
|
}, cli.Command{
|
||||||
Name: "refresh",
|
Name: "refresh",
|
||||||
@ -121,3 +120,98 @@ func cmdRefresh(flags core.Flags) error {
|
|||||||
fmt.Println("Index refreshed!")
|
fmt.Println("Index refreshed!")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func cmdUpdate(flags core.Flags, mod string) error {
|
||||||
|
fmt.Println("Loading modpack...")
|
||||||
|
pack, err := core.LoadPack(flags)
|
||||||
|
if err != nil {
|
||||||
|
return cli.NewExitError(err, 1)
|
||||||
|
}
|
||||||
|
index, err := pack.LoadIndex()
|
||||||
|
if err != nil {
|
||||||
|
return cli.NewExitError(err, 1)
|
||||||
|
}
|
||||||
|
mcVersion, err := pack.GetMCVersion()
|
||||||
|
if err != nil {
|
||||||
|
return cli.NewExitError(err, 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
multiple := false
|
||||||
|
var singleUpdatedName string
|
||||||
|
if len(mod) == 0 || mod == "*" {
|
||||||
|
multiple = true
|
||||||
|
// TODO: implement
|
||||||
|
return cli.NewExitError("Not implemented yet!", 1)
|
||||||
|
} else {
|
||||||
|
modPath, ok := index.FindMod(mod)
|
||||||
|
if !ok {
|
||||||
|
return cli.NewExitError("You don't have this mod installed.", 1)
|
||||||
|
}
|
||||||
|
modData, err := core.LoadMod(modPath)
|
||||||
|
if err != nil {
|
||||||
|
return cli.NewExitError(err, 1)
|
||||||
|
}
|
||||||
|
singleUpdatedName = modData.Name
|
||||||
|
updaterFound := false
|
||||||
|
for k := range modData.Update {
|
||||||
|
updater, ok := core.Updaters[k]
|
||||||
|
if !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
updaterFound = true
|
||||||
|
|
||||||
|
check, err := updater.CheckUpdate([]core.Mod{modData}, mcVersion)
|
||||||
|
if err != nil {
|
||||||
|
return cli.NewExitError(err, 1)
|
||||||
|
}
|
||||||
|
if len(check) != 1 {
|
||||||
|
return cli.NewExitError("Invalid update check response", 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
if check[0].UpdateAvailable {
|
||||||
|
fmt.Printf("Update available: %s\n", check[0].UpdateString)
|
||||||
|
|
||||||
|
err = updater.DoUpdate([]*core.Mod{&modData}, []interface{}{check[0].CachedState})
|
||||||
|
if err != nil {
|
||||||
|
return cli.NewExitError(err, 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
format, hash, err := modData.Write()
|
||||||
|
if err != nil {
|
||||||
|
return cli.NewExitError(err, 1)
|
||||||
|
}
|
||||||
|
err = index.RefreshFileWithHash(modPath, format, hash, true)
|
||||||
|
if err != nil {
|
||||||
|
return cli.NewExitError(err, 1)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
fmt.Printf("\"%s\" is already up to date!\n", modData.Name)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if !updaterFound {
|
||||||
|
return cli.NewExitError("A supported update system for this mod cannot be found.", 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
err = index.Write()
|
||||||
|
if err != nil {
|
||||||
|
return cli.NewExitError(err, 1)
|
||||||
|
}
|
||||||
|
err = pack.UpdateIndexHash()
|
||||||
|
if err != nil {
|
||||||
|
return cli.NewExitError(err, 1)
|
||||||
|
}
|
||||||
|
err = pack.Write()
|
||||||
|
if err != nil {
|
||||||
|
return cli.NewExitError(err, 1)
|
||||||
|
}
|
||||||
|
if multiple {
|
||||||
|
fmt.Println("Mods updated!")
|
||||||
|
} else {
|
||||||
|
fmt.Printf("\"%s\" updated!\n", singleUpdatedName)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user