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
|
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
|
package core
|
||||||
|
|
||||||
import "github.com/BurntSushi/toml"
|
import "github.com/BurntSushi/toml"
|
||||||
|
|
||||||
// Mod stores metadata about a mod. This is written to a TOML file for each mod.
|
// Mod stores metadata about a mod. This is written to a TOML file for each mod.
|
||||||
type Mod struct {
|
type Mod struct {
|
||||||
metaFilename string
|
metaFilename string // The filename for the metadata file, used as an ID
|
||||||
Name string `toml:"name"`
|
Name string `toml:"name"`
|
||||||
FileName string `toml:"filename"`
|
FileName string `toml:"filename"`
|
||||||
Side string `toml:"side"`
|
Side string `toml:"side,omitempty"`
|
||||||
Optional bool `toml:"optional"`
|
Optional bool `toml:"optional,omitempty"`
|
||||||
Download struct {
|
Download struct {
|
||||||
URL string `toml:"url"`
|
URL string `toml:"url"`
|
||||||
HashFormat string `toml:"hash-format"`
|
HashFormat string `toml:"hash-format"`
|
||||||
Hash string `toml:"hash"`
|
Hash string `toml:"hash"`
|
||||||
} `toml:"download"`
|
} `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".
|
// The three possible values of Side (the side that the mod is on) are "server", "client", and "both".
|
||||||
const (
|
const (
|
||||||
ServerSide = "server"
|
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)
|
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() {
|
func init() {
|
||||||
core.Commands = append(core.Commands, cli.Command{
|
core.Commands = append(core.Commands, cli.Command{
|
||||||
Name: "delete",
|
Name: "remove",
|
||||||
Aliases: []string{"remove"},
|
Aliases: []string{"delete", "uninstall"},
|
||||||
Usage: "Delete a mod from the modpack",
|
Usage: "Remove a mod from the modpack",
|
||||||
Action: func(c *cli.Context) error {
|
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
|
return nil
|
||||||
},
|
},
|
||||||
}, cli.Command{
|
}, cli.Command{
|
||||||
Name: "delet",
|
Name: "refresh",
|
||||||
Aliases: []string{"remov"},
|
Usage: "Refresh the index file",
|
||||||
Usage: "Delete a mod from the modpack",
|
|
||||||
Action: func(c *cli.Context) error {
|
Action: func(c *cli.Context) error {
|
||||||
cmdDelete(core.FlagsFromContext(c))
|
// TODO: implement
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@ -44,14 +50,14 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func cmdDelete(flags core.Flags) {
|
func cmdDelete(flags core.Flags) error {
|
||||||
mod := "demagnetize"
|
mod := "demagnetize"
|
||||||
err := os.Remove(core.ResolveMod(mod, flags))
|
err := os.Remove(core.ResolveMod(mod, flags))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Error removing mod: %s", err)
|
return cli.NewExitError(err, 1)
|
||||||
} else {
|
|
||||||
fmt.Printf("Mod %s removed successfully!", mod)
|
|
||||||
}
|
}
|
||||||
|
fmt.Printf("Mod %s removed successfully!", mod)
|
||||||
// TODO: update index
|
// TODO: update index
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user