mirror of
https://github.com/OpenFactorioServerManager/factorio-server-manager.git
synced 2025-01-10 04:19:38 +02:00
list of installed mods now built out of mod-list.json
This commit is contained in:
parent
a3d0a2e888
commit
98ba7bc9e5
30
src/mods.go
30
src/mods.go
@ -9,41 +9,33 @@ import (
|
|||||||
|
|
||||||
type Mod struct {
|
type Mod struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Enabled bool `json:"enabled,string"`
|
Enabled bool `json:"enabled"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ModsList struct {
|
||||||
|
Mods []Mod `json:"mods"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// List mods installed in the factorio/mods directory
|
// List mods installed in the factorio/mods directory
|
||||||
func listInstalledMods(modDir string) ([]Mod, error) {
|
func listInstalledMods(modDir string) ([]Mod, error) {
|
||||||
result := []Mod{}
|
file, err := ioutil.ReadFile(modDir + "/mod-list.json")
|
||||||
|
|
||||||
file, err := ioutil.ReadFile(modDir + "mod-list.json")
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err.Error())
|
log.Println(err.Error())
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Print(file)
|
||||||
|
|
||||||
|
var result ModsList
|
||||||
err_json := json.Unmarshal(file, &result)
|
err_json := json.Unmarshal(file, &result)
|
||||||
|
|
||||||
if err_json != nil {
|
if err_json != nil {
|
||||||
log.Println(err.Error())
|
log.Println(err_json.Error())
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("%v", result)
|
log.Printf("%v", result)
|
||||||
|
|
||||||
|
return result.Mods, nil
|
||||||
//files, err := ioutil.ReadDir(modDir)
|
|
||||||
//if err != nil {
|
|
||||||
// log.Printf("Error listing installed mods: %s", err)
|
|
||||||
// return result, err
|
|
||||||
//}
|
|
||||||
//for _, f := range files {
|
|
||||||
// if f.Name() == "mod-list.json" {
|
|
||||||
// continue
|
|
||||||
// }
|
|
||||||
// result = append(result, f.Name())
|
|
||||||
//}
|
|
||||||
|
|
||||||
return result, nil
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user