mirror of
https://github.com/packwiz/packwiz.git
synced 2025-10-14 15:04:32 +02:00
Commit some stuff
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user