-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmod.go
69 lines (55 loc) · 1.03 KB
/
mod.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package main
import (
"errors"
"os"
"path"
"path/filepath"
"github.com/dstmodders/mod-cli/modinfo"
)
type Mod struct {
modinfo *modinfo.ModInfo
name string
path string
pathAbs string
version string
}
func NewMod() *Mod {
return &Mod{}
}
func (m *Mod) Load(modPath string) error {
stat, err := os.Stat(modPath)
if err != nil {
return err
}
if !stat.IsDir() {
return errors.New("not a directory")
}
absPath, err := filepath.Abs(stat.Name())
if err != nil {
return err
}
info := modinfo.New()
if err := info.Load(path.Join(absPath, "modinfo.lua")); err != nil {
return err
}
name, err := info.FieldByName("name")
if err != nil {
return err
}
if name == nil {
return errors.New("mod info field name doesn't have any value")
}
v, err := info.FieldByName("version")
if err != nil {
return err
}
if v == nil {
return errors.New("mod info field version doesn't have any value")
}
m.modinfo = info
m.name = name.String()
m.path = modPath
m.pathAbs = absPath
m.version = v.String()
return nil
}