96 lines
2.1 KiB
Go
96 lines
2.1 KiB
Go
package oplcli
|
|
|
|
import (
|
|
"log/slog"
|
|
"os"
|
|
)
|
|
|
|
type Config struct {
|
|
GameListLocation string
|
|
}
|
|
|
|
func Scan(files []string, config Config) {
|
|
gameList, err := loadGamelist(config.GameListLocation)
|
|
if err != nil {
|
|
slog.Error("Failed to load game list", "file", config.GameListLocation)
|
|
os.Exit(1)
|
|
}
|
|
|
|
for _, file := range files {
|
|
slog.Info("Scanning file", "file", file)
|
|
gameID, err := scanGameFileForID(file)
|
|
if err != nil {
|
|
slog.Error("Failed to scan game file", "file", file)
|
|
os.Exit(1)
|
|
}
|
|
|
|
slog.Info("Found game ID", "id", gameID)
|
|
|
|
gameName := gameList[gameID]
|
|
slog.Info("Found game name", "name", gameName)
|
|
}
|
|
}
|
|
|
|
func Rename(files []string, config Config) {
|
|
gameList, err := loadGamelist(config.GameListLocation)
|
|
if err != nil {
|
|
slog.Error("Failed to load game list", "file", config.GameListLocation)
|
|
os.Exit(1)
|
|
}
|
|
|
|
for _, file := range files {
|
|
slog.Info("Scanning file", "file", file)
|
|
|
|
gameID, err := scanGameFileForID(file)
|
|
if err != nil {
|
|
slog.Error("Failed to scan game file", "file", file)
|
|
os.Exit(1)
|
|
}
|
|
|
|
slog.Info("Found game ID", "id", gameID)
|
|
|
|
gameName := gameList[gameID]
|
|
slog.Info("Found game name", "name", gameName)
|
|
|
|
newPath, err := renameGameFile(file, gameName)
|
|
if err != nil {
|
|
slog.Error("Failed to reanme file", "file", file, "gameName", gameName, "err", err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
slog.Info("Renamed file", "file", file, "to", newPath)
|
|
}
|
|
}
|
|
|
|
func DownloadGameArt(files []string, output string, config Config) {
|
|
for _, file := range files {
|
|
slog.Info("Scanning file", "file", file)
|
|
|
|
gameID, err := scanGameFileForID(file)
|
|
if err != nil {
|
|
slog.Error("Failed to scan game file", "file", file)
|
|
os.Exit(1)
|
|
}
|
|
|
|
slog.Info("Found game ID", "id", gameID)
|
|
|
|
downloadArtForGame(gameID, output)
|
|
}
|
|
}
|
|
|
|
func DownloadCfg(files []string, output string, mode FileMode, config Config) {
|
|
for _, file := range files {
|
|
slog.Info("Scanning file", "file", file)
|
|
|
|
gameID, err := scanGameFileForID(file)
|
|
if err != nil {
|
|
slog.Error("Failed to scan game file", "file", file)
|
|
os.Exit(1)
|
|
}
|
|
|
|
slog.Info("Found game ID", "id", gameID)
|
|
|
|
downloadCfgForGame(gameID, output, mode)
|
|
}
|
|
}
|