mirror of
https://github.com/packwiz/packwiz.git
synced 2025-04-19 13:06:30 +02:00
Commit some stuff
This commit is contained in:
parent
a531e36713
commit
d6b55b8032
@ -1 +1,34 @@
|
||||
package core
|
||||
// Index is a representation of the index.toml file for referencing all the files in a pack.
|
||||
type Index struct {
|
||||
HashFormat string `toml:"hash-format"`
|
||||
Files []struct {
|
||||
File string `toml:"file"`
|
||||
Hash string `toml:"hash"`
|
||||
HashFormat string `toml:"hash-format,omitempty"`
|
||||
Alias string `toml:"alias,omitempty"`
|
||||
} `toml:"files"`
|
||||
}
|
||||
|
||||
// LoadIndex loads the index file
|
||||
func LoadIndex(flags Flags) (Index, error) {
|
||||
indexFile, err := ResolveIndex(flags)
|
||||
if err != nil {
|
||||
return Index{}, err
|
||||
}
|
||||
|
||||
_ = indexFile // TODO finish
|
||||
return Index{}, nil
|
||||
}
|
||||
|
||||
// RemoveFile removes a file from the index.
|
||||
func (in Index) RemoveFile(path string) {
|
||||
newFiles := in.Files[:0]
|
||||
for _, v := range in.Files {
|
||||
if v.File != path {
|
||||
newFiles = append(newFiles, v)
|
||||
}
|
||||
}
|
||||
in.Files = newFiles
|
||||
}
|
||||
|
||||
|
16
core/mod.go
16
core/mod.go
@ -1,21 +1,21 @@
|
||||
package core
|
||||
|
||||
import "github.com/BurntSushi/toml"
|
||||
|
||||
// Mod stores metadata about a mod. This is written to a TOML file for each mod.
|
||||
type Mod struct {
|
||||
metaFilename string
|
||||
Name string `toml:"name"`
|
||||
FileName string `toml:"filename"`
|
||||
Side string `toml:"side"`
|
||||
Optional bool `toml:"optional"`
|
||||
Download struct {
|
||||
metaFilename string // The filename for the metadata file, used as an ID
|
||||
Name string `toml:"name"`
|
||||
FileName string `toml:"filename"`
|
||||
Side string `toml:"side,omitempty"`
|
||||
Optional bool `toml:"optional,omitempty"`
|
||||
Download struct {
|
||||
URL string `toml:"url"`
|
||||
HashFormat string `toml:"hash-format"`
|
||||
Hash string `toml:"hash"`
|
||||
} `toml:"download"`
|
||||
Update map[string]toml.Primitive
|
||||
Update map[string]toml.Primitive `toml:"update"`
|
||||
}
|
||||
|
||||
// The three possible values of Side (the side that the mod is on) are "server", "client", and "both".
|
||||
const (
|
||||
ServerSide = "server"
|
||||
|
27
core/pack.go
Normal file
27
core/pack.go
Normal file
@ -0,0 +1,27 @@
|
||||
package core
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/BurntSushi/toml"
|
||||
)
|
||||
|
||||
// Pack stores the modpack metadata, usually in pack.toml
|
||||
type Pack struct {
|
||||
Name string `toml:"name"`
|
||||
Index struct {
|
||||
File string `toml:"file"`
|
||||
HashFormat string `toml:"hash-format"`
|
||||
Hash string `toml:"hash"`
|
||||
} `toml:"index"`
|
||||
Versions map[string]string `toml:"versions"`
|
||||
Client map[string]toml.Primitive `toml:"client"`
|
||||
Server map[string]toml.Primitive `toml:"server"`
|
||||
}
|
||||
|
||||
// LoadPack loads the modpack metadata to a Pack struct
|
||||
func LoadPack(flags Flags) (Pack, error) {
|
||||
fmt.Println(flags.PackFile)
|
||||
// TODO implement
|
||||
return Pack{}, nil
|
||||
}
|
||||
|
@ -13,3 +13,15 @@ func ResolveMod(modName string, flags Flags) string {
|
||||
return filepath.Join(flags.ModsFolder, fileName)
|
||||
}
|
||||
|
||||
// ResolveIndex returns the path to the index file
|
||||
func ResolveIndex(flags Flags) (string, error) {
|
||||
pack, err := LoadPack(flags)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if filepath.IsAbs(pack.Index.File) {
|
||||
return pack.Index.File, nil
|
||||
}
|
||||
return filepath.Join(flags.PackFile, pack.Index.File), nil
|
||||
}
|
||||
|
||||
|
30
main.go
30
main.go
@ -13,19 +13,25 @@ import (
|
||||
|
||||
func init() {
|
||||
core.Commands = append(core.Commands, cli.Command{
|
||||
Name: "delete",
|
||||
Aliases: []string{"remove"},
|
||||
Usage: "Delete a mod from the modpack",
|
||||
Name: "remove",
|
||||
Aliases: []string{"delete", "uninstall"},
|
||||
Usage: "Remove a mod from the modpack",
|
||||
Action: func(c *cli.Context) error {
|
||||
cmdDelete(core.FlagsFromContext(c))
|
||||
return cmdDelete(core.FlagsFromContext(c))
|
||||
},
|
||||
}, cli.Command{
|
||||
Name: "update",
|
||||
Aliases: []string{"upgrade"},
|
||||
Usage: "Update a mod (or all mods) in the modpack",
|
||||
Action: func(c *cli.Context) error {
|
||||
// TODO: implement
|
||||
return nil
|
||||
},
|
||||
}, cli.Command{
|
||||
Name: "delet",
|
||||
Aliases: []string{"remov"},
|
||||
Usage: "Delete a mod from the modpack",
|
||||
Name: "refresh",
|
||||
Usage: "Refresh the index file",
|
||||
Action: func(c *cli.Context) error {
|
||||
cmdDelete(core.FlagsFromContext(c))
|
||||
// TODO: implement
|
||||
return nil
|
||||
},
|
||||
})
|
||||
@ -44,14 +50,14 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
func cmdDelete(flags core.Flags) {
|
||||
func cmdDelete(flags core.Flags) error {
|
||||
mod := "demagnetize"
|
||||
err := os.Remove(core.ResolveMod(mod, flags))
|
||||
if err != nil {
|
||||
fmt.Printf("Error removing mod: %s", err)
|
||||
} else {
|
||||
fmt.Printf("Mod %s removed successfully!", mod)
|
||||
return cli.NewExitError(err, 1)
|
||||
}
|
||||
fmt.Printf("Mod %s removed successfully!", mod)
|
||||
// TODO: update index
|
||||
return nil
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user