Fix paths in index querying

This commit is contained in:
comp500 2019-06-16 19:33:21 +01:00
parent 5c82486016
commit 7880488bf1
No known key found for this signature in database
GPG Key ID: 214C822FFEC586B5
2 changed files with 33 additions and 24 deletions

View File

@ -276,9 +276,21 @@ func (in Index) FindMod(modName string) (string, bool) {
_, file := filepath.Split(v.File)
fileTrimmed := strings.TrimSuffix(file, ModExtension)
if fileTrimmed == modName {
return v.File, true
return filepath.Join(filepath.Dir(in.indexFile), filepath.FromSlash(v.File)), true
}
}
}
return "", false
}
// GetAllMods finds paths to every metadata file (Mod) in the index
func (in Index) GetAllMods() []string {
var list []string
baseDir := filepath.Dir(in.indexFile)
for _, v := range in.Files {
if v.MetaFile {
list = append(list, filepath.Join(baseDir, filepath.FromSlash(v.File)))
}
}
return list
}

41
main.go
View File

@ -147,31 +147,28 @@ func cmdUpdate(flags core.Flags, mod string) error {
updaterMap := make(map[string][]core.Mod)
fmt.Println("Reading mod files...")
for _, v := range index.Files {
if v.MetaFile {
// TODO: check fromslash stuff aaa
modData, err := core.LoadMod(v.File)
if err != nil {
fmt.Printf("Error reading mod file: %s", err.Error())
continue
}
for _, v := range index.GetAllMods() {
modData, err := core.LoadMod(v)
if err != nil {
fmt.Printf("Error reading mod file: %s", err.Error())
continue
}
updaterFound := false
for k := range modData.Update {
slice, ok := updaterMap[k]
updaterFound := false
for k := range modData.Update {
slice, ok := updaterMap[k]
if !ok {
_, ok = core.Updaters[k]
if !ok {
_, ok = core.Updaters[k]
if !ok {
continue
}
slice = []core.Mod{}
continue
}
updaterFound = true
updaterMap[k] = append(slice, modData)
}
if !updaterFound {
fmt.Printf("A supported update system for \"%s\" cannot be found.", modData.Name)
slice = []core.Mod{}
}
updaterFound = true
updaterMap[k] = append(slice, modData)
}
if !updaterFound {
fmt.Printf("A supported update system for \"%s\" cannot be found.", modData.Name)
}
}
@ -294,7 +291,7 @@ func cmdUpdate(flags core.Flags, mod string) error {
}
if !updaterFound {
// TODO: use file name instead of Name when len(Name) == 0 in all places?
return cli.NewExitError("A supported update system for \""+ modData.Name +"\" cannot be found.", 1)
return cli.NewExitError("A supported update system for \""+modData.Name+"\" cannot be found.", 1)
}
}