Compare commits
No commits in common. "main" and "v0.1.0" have entirely different histories.
30
main.go
30
main.go
|
@ -3,7 +3,6 @@ package main
|
|||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Command struct {
|
||||
|
@ -104,35 +103,6 @@ var commands = []Command{
|
|||
return "cleaned", nil
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
Name: "list",
|
||||
Description: "List all known game associations by name followed by data path in a newline-separated list",
|
||||
Arguments: []string{},
|
||||
IsVarargs: false,
|
||||
|
||||
Action: func(requiredArguments []string, arguments []string) (string, error) {
|
||||
if len(arguments) != 0 {
|
||||
return "", fmt.Errorf("expected zero arguments")
|
||||
}
|
||||
|
||||
var gameDataPaths, loadError = LoadGames()
|
||||
|
||||
if loadError != nil {
|
||||
return "", loadError
|
||||
}
|
||||
|
||||
var stringBuilder = strings.Builder{}
|
||||
|
||||
for game, dataPath := range gameDataPaths {
|
||||
if _, printError := fmt.Printf("%s %s\n", game, dataPath); printError != nil {
|
||||
return "", printError
|
||||
}
|
||||
}
|
||||
|
||||
return stringBuilder.String(), nil
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
|
34
manager.go
34
manager.go
|
@ -117,6 +117,10 @@ func CreateGame(gameName string, gameDataPath string) error {
|
|||
}
|
||||
|
||||
if iniFile, openError := os.Open(gamesIniPath); openError == nil {
|
||||
if (openError != nil) && !(os.IsNotExist(openError)) {
|
||||
return openError
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if closeError := iniFile.Close(); closeError != nil {
|
||||
panic(closeError)
|
||||
|
@ -317,36 +321,6 @@ func DeployGameMods(gameName string, modArchivePaths []string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func LoadGames() (map[string]string, error) {
|
||||
var gameDataPaths = make(map[string]string)
|
||||
|
||||
if iniFile, openError := os.Open(gamesIniPath); openError == nil {
|
||||
defer func() {
|
||||
if closeError := iniFile.Close(); closeError != nil {
|
||||
panic(closeError)
|
||||
}
|
||||
}()
|
||||
|
||||
var parser = ini.NewParser(iniFile)
|
||||
|
||||
for entry := parser.Parse(); !(parser.IsEnd()); entry = parser.Parse() {
|
||||
var section = parser.Section()
|
||||
|
||||
if entry.Key == "path" {
|
||||
gameDataPaths[section] = entry.Value
|
||||
}
|
||||
}
|
||||
|
||||
if parseError := parser.Err(); parseError != nil {
|
||||
return gameDataPaths, parseError
|
||||
}
|
||||
} else if !(os.IsNotExist(openError)) {
|
||||
return gameDataPaths, openError
|
||||
}
|
||||
|
||||
return gameDataPaths, nil
|
||||
}
|
||||
|
||||
func RemoveGame(gameName string) error {
|
||||
if cleanError := CleanGameMods(gameName); cleanError != nil {
|
||||
return cleanError
|
||||
|
|
Loading…
Reference in New Issue