mirror of
https://github.com/packwiz/packwiz.git
synced 2025-04-19 13:06:30 +02:00
Move locating mods to index
This commit is contained in:
parent
91693cd3eb
commit
adcde05693
@ -8,6 +8,7 @@ import (
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"time"
|
||||
"strings"
|
||||
|
||||
"github.com/BurntSushi/toml"
|
||||
"github.com/vbauerster/mpb/v4"
|
||||
@ -266,3 +267,17 @@ func (in *Index) RefreshFileWithHash(path, format, hash string, mod bool) error
|
||||
in.resortIndex()
|
||||
return nil
|
||||
}
|
||||
|
||||
// FindMod finds a mod in the index and returns it's path and whether it has been found
|
||||
func (in Index) FindMod(modName string) (string, bool) {
|
||||
for _, v := range in.Files {
|
||||
if v.MetaFile {
|
||||
_, file := filepath.Split(v.File);
|
||||
fileTrimmed := strings.TrimSuffix(file, ModExtension)
|
||||
if fileTrimmed == modName {
|
||||
return v.File, true
|
||||
}
|
||||
}
|
||||
}
|
||||
return "", false
|
||||
}
|
@ -29,7 +29,8 @@ func init() {
|
||||
return cmdImport(core.FlagsFromContext(c), c.Args().Get(0))
|
||||
},
|
||||
}, {
|
||||
Name: "open",
|
||||
Name: "open",
|
||||
// TODO: change semantics to "project" rather than "mod", as this supports texture packs and misc content as well
|
||||
Usage: "Open the project page for a curseforge mod in your browser",
|
||||
Aliases: []string{"doc"},
|
||||
Action: func(c *cli.Context) error {
|
||||
@ -143,7 +144,21 @@ func cmdDoc(flags core.Flags, mod string) error {
|
||||
return cli.NewExitError("You must specify a mod.", 1)
|
||||
}
|
||||
|
||||
modData, err := core.LoadMod(core.ResolveMod(mod, flags))
|
||||
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)
|
||||
}
|
||||
resolvedMod, ok := index.FindMod(mod)
|
||||
if !ok {
|
||||
// TODO: should this auto-refresh???????
|
||||
return cli.NewExitError("You don't have this mod installed.", 1)
|
||||
}
|
||||
modData, err := core.LoadMod(resolvedMod)
|
||||
if err != nil {
|
||||
return cli.NewExitError(err, 1)
|
||||
}
|
||||
@ -152,6 +167,7 @@ func cmdDoc(flags core.Flags, mod string) error {
|
||||
return cli.NewExitError("This mod doesn't seem to be a curseforge mod!", 1)
|
||||
}
|
||||
cfUpdateData := updateData.(cfUpdater)
|
||||
fmt.Println("Opening browser...")
|
||||
url := "https://minecraft.curseforge.com/projects/" + strconv.Itoa(cfUpdateData.ProjectID)
|
||||
err = open.Start(url)
|
||||
if err != nil {
|
||||
@ -178,6 +194,11 @@ type cfUpdater struct {
|
||||
|
||||
func (u cfUpdater) DoUpdate(mod core.Mod) (bool, error) {
|
||||
// TODO: implement updating
|
||||
// modInfoData, err := getModInfo(u.ProjectID)
|
||||
// if err != nil {
|
||||
// return false, err
|
||||
// }
|
||||
|
||||
return false, nil
|
||||
}
|
||||
|
||||
|
15
main.go
15
main.go
@ -1,4 +1,5 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
@ -52,11 +53,6 @@ func cmdDelete(flags core.Flags, mod string) error {
|
||||
if len(mod) == 0 {
|
||||
return cli.NewExitError("You must specify a mod.", 1)
|
||||
}
|
||||
resolvedMod := core.ResolveMod(mod, flags)
|
||||
err := os.Remove(resolvedMod)
|
||||
if err != nil {
|
||||
return cli.NewExitError(err, 1)
|
||||
}
|
||||
fmt.Println("Loading modpack...")
|
||||
pack, err := core.LoadPack(flags)
|
||||
if err != nil {
|
||||
@ -66,6 +62,14 @@ func cmdDelete(flags core.Flags, mod string) error {
|
||||
if err != nil {
|
||||
return cli.NewExitError(err, 1)
|
||||
}
|
||||
resolvedMod, ok := index.FindMod(mod)
|
||||
if !ok {
|
||||
return cli.NewExitError("You don't have this mod installed.", 1)
|
||||
}
|
||||
err = os.Remove(resolvedMod)
|
||||
if err != nil {
|
||||
return cli.NewExitError(err, 1)
|
||||
}
|
||||
fmt.Println("Removing mod from index...")
|
||||
err = index.RemoveFile(resolvedMod)
|
||||
if err != nil {
|
||||
@ -117,4 +121,3 @@ func cmdRefresh(flags core.Flags) error {
|
||||
fmt.Println("Index refreshed!")
|
||||
return nil
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user