Files
opl-cli/internal/oplcli.go

96 lines
2.0 KiB
Go

package oplcli
import (
"fmt"
"os"
)
type Config struct {
GameListLocation string
}
func Scan(files []string, config Config) {
gameList, err := loadGamelist(config.GameListLocation)
if err != nil {
fmt.Printf("Failed to load game list: %v", err)
os.Exit(1)
}
for _, file := range files {
fmt.Printf("Scanning file: %s\n", file)
gameID, err := scanGameFileForID(file)
if err != nil {
fmt.Printf("Failed to scan game file: %s", err)
os.Exit(1)
}
fmt.Printf("Found game ID: %s\n", gameID)
gameName := gameList[gameID]
fmt.Printf("Found game name: %s\n", gameName)
}
}
func Rename(files []string, config Config) {
gameList, err := loadGamelist(config.GameListLocation)
if err != nil {
fmt.Printf("Failed to load game list: %v", err)
os.Exit(1)
}
for _, file := range files {
fmt.Printf("Scanning file: %s\n", file)
gameID, err := scanGameFileForID(file)
if err != nil {
fmt.Printf("Failed to scan game file: %s", err)
os.Exit(1)
}
fmt.Printf("Found game ID: %s\n", gameID)
gameName := gameList[gameID]
fmt.Printf("Found game name: %s\n", gameName)
newPath, err := renameGameFile(file, gameName)
if err != nil {
fmt.Printf("Failed to rename file: %v", err)
os.Exit(1)
}
fmt.Printf("Renamed %s to %s", file, newPath)
}
}
func DownloadGameArt(files []string, output string, config Config) {
for _, file := range files {
fmt.Printf("Scanning file: %s\n", file)
gameID, err := scanGameFileForID(file)
if err != nil {
fmt.Printf("Failed to scan game file: %s", err)
os.Exit(1)
}
fmt.Printf("Found game ID: %s\n", gameID)
downloadArtForGame(gameID, output)
}
}
func DownloadCfg(files []string, output string, mode FileMode, config Config) {
for _, file := range files {
fmt.Printf("Scanning file: %s\n", file)
gameID, err := scanGameFileForID(file)
if err != nil {
fmt.Printf("Failed to scan game file: %s", err)
os.Exit(1)
}
fmt.Printf("Found game ID: %s\n", gameID)
downloadCfgForGame(gameID, output, mode)
}
}