From be6c98da2074669db3bc94524b4c60d3b9ba9d02 Mon Sep 17 00:00:00 2001 From: Callan Barrett Date: Sat, 14 Dec 2024 21:32:21 +0800 Subject: [PATCH] Add SteamOS as a supported platform (#121) * Update readme * Rename core go module path * Add steamos platform * Add steamos build tasks * Add steamos udev rules * Add deploy-steamos task to Taskfile * Refactor Steam library scanning into reusable utility function * Refactor platform methods to use anonymous parameters * Refactor service handling and configuration structure * Update SteamOS launch command and add Zaparoo service file * Added module blacklist for acr122 * Remove acr122_pcsc * Refactor service handling and update configuration files * Add install and uninstall commands for SteamOS service * Fix zaparoo.service to run tapto without -daemon flag * Switch to xdg for paths and update dependency versions * Refactor install logic and update systemd service configuration * Update service template to use dynamic paths for exec and working dir * Add optical_drive reader and clean up dependencies * Remove sudo from steam launch --- Taskfile.dist.yml | 25 +++ cmd/batocera/main.go | 8 +- cmd/mac/main.go | 10 +- cmd/mister/gui.go | 9 +- cmd/mister/main.go | 12 +- cmd/mistex/main.go | 14 +- cmd/steamos/conf/60-zaparoo.rules | 4 + cmd/steamos/conf/blacklist-zaparoo.conf | 2 + cmd/steamos/conf/zaparoo.service | 15 ++ cmd/steamos/install.go | 115 +++++++++++ cmd/steamos/main.go | 118 ++++++++++++ cmd/windows/main.go | 8 +- go.mod | 19 +- go.sum | 25 +-- pkg/api/client/client.go | 6 +- pkg/api/methods/games.go | 12 +- pkg/api/methods/history.go | 4 +- pkg/api/methods/launch.go | 8 +- pkg/api/methods/mappings.go | 8 +- pkg/api/methods/readers.go | 4 +- pkg/api/methods/settings.go | 4 +- pkg/api/methods/status.go | 10 +- pkg/api/methods/systems.go | 8 +- pkg/api/models/requests/requests.go | 10 +- pkg/api/server.go | 16 +- pkg/cli/cli.go | 12 +- pkg/config/tapto.go | 29 ++- pkg/database/database.go | 4 +- pkg/database/gamesdb/gamesdb.go | 6 +- pkg/database/gamesdb/indexing.go | 6 +- pkg/database/gamesdb/systems.go | 2 +- pkg/database/mappings.go | 2 +- pkg/launcher/commands.go | 8 +- pkg/launcher/http.go | 2 +- pkg/launcher/input.go | 2 +- pkg/launcher/launch.go | 8 +- pkg/launcher/utils.go | 2 +- pkg/platforms/batocera/platform.go | 18 +- pkg/platforms/mac/platform.go | 16 +- pkg/platforms/mister/commands.go | 2 +- pkg/platforms/mister/config.go | 2 +- pkg/platforms/mister/launchers.go | 6 +- pkg/platforms/mister/methods.go | 4 +- pkg/platforms/mister/platform.go | 22 +-- pkg/platforms/mister/socket.go | 4 +- pkg/platforms/mister/tracker.go | 2 +- pkg/platforms/mistex/commands.go | 4 +- pkg/platforms/mistex/platform.go | 18 +- pkg/platforms/platforms.go | 10 +- pkg/platforms/steamos/platform.go | 213 +++++++++++++++++++++ pkg/platforms/windows/platform.go | 73 ++----- pkg/readers/acr122_pcsc/acr122_pcsc.go | 8 +- pkg/readers/file/file.go | 8 +- pkg/readers/libnfc/libnfc.go | 10 +- pkg/readers/libnfc/tags/mifare.go | 2 +- pkg/readers/libnfc/tags/ntag.go | 2 +- pkg/readers/libnfc/tags/tags.go | 2 +- pkg/readers/optical_drive/optical_drive.go | 8 +- pkg/readers/pn532_uart/pn532.go | 2 +- pkg/readers/pn532_uart/pn532_uart.go | 8 +- pkg/readers/readers.go | 2 +- pkg/readers/simple_serial/simple_serial.go | 8 +- pkg/service/mappings.go | 6 +- pkg/service/readers.go | 12 +- pkg/service/service.go | 16 +- pkg/service/state/state.go | 10 +- pkg/utils/logging.go | 7 +- pkg/utils/paths.go | 80 +++++++- pkg/{platforms/mister => utils}/service.go | 79 ++++---- pkg/utils/utils.go | 2 +- 70 files changed, 875 insertions(+), 348 deletions(-) create mode 100644 cmd/steamos/conf/60-zaparoo.rules create mode 100644 cmd/steamos/conf/blacklist-zaparoo.conf create mode 100644 cmd/steamos/conf/zaparoo.service create mode 100644 cmd/steamos/install.go create mode 100755 cmd/steamos/main.go create mode 100644 pkg/platforms/steamos/platform.go rename pkg/{platforms/mister => utils}/service.go (71%) diff --git a/Taskfile.dist.yml b/Taskfile.dist.yml index 305ae5c2..61e679f3 100644 --- a/Taskfile.dist.yml +++ b/Taskfile.dist.yml @@ -41,6 +41,13 @@ tasks: cmds: - docker build --platform linux/amd64 -t {{.IMAGE_NAME}} {{.DOCKERFILE}} + build-image-steamos-amd64: + vars: + IMAGE_NAME: zaparoo/steamos-amd64-build + DOCKERFILE: "./scripts/linux_amd64/build" + cmds: + - docker build --platform linux/amd64 -t {{.IMAGE_NAME}} {{.DOCKERFILE}} + build-mister: vars: BUILD_DIR: "./_build/mister_arm" @@ -104,6 +111,19 @@ tasks: - rm -f {{.BUILD_DIR}}/tapto-batocera_amd64.zip - zip -j {{.BUILD_DIR}}/tapto-batocera_amd64.zip {{.BUILD_DIR}}/tapto + build-steamos-amd64: + vars: + BUILD_DIR: "./_build/steamos_amd64" + BUILDCACHE: "{{.BUILD_DIR}}/.go-buildcache" + MODCACHE: "{{.BUILD_DIR}}/.go-modcache" + IMAGE_NAME: zaparoo/steamos-amd64-build + IMG_BUILDCACHE: /home/build/.cache/go-build + IMG_MODCACHE: /home/build/go/pkg/mod + cmds: + - docker run --rm --platform linux/amd64 -v {{.BUILDCACHE}}:{{.IMG_BUILDCACHE}} -v {{.MODCACHE}}:{{.IMG_MODCACHE}} -v ${PWD}:/build --user 1000:1000 {{.IMAGE_NAME}} bash -c "PLATFORM=steamos TAPTO_BIN=tapto task build" + - rm -f {{.BUILD_DIR}}/zaparoo-steamos_amd64.zip + - zip -j {{.BUILD_DIR}}/zaparoo-steamos_amd64.zip {{.BUILD_DIR}}/tapto + build-windows: vars: BUILD_DIR: "./_build/windows_{{.ARCH}}" @@ -138,6 +158,11 @@ tasks: - scp _build/mistex_arm64/tapto.sh root@${MISTEX_IP}:/media/fat/Scripts/tapto.sh - ssh root@${MISTEX_IP} /media/fat/Scripts/tapto.sh -service restart + deploy-steamos: + cmds: + - task: build-steamos-amd64 + - scp _build/steamos_amd64/tapto deck@${STEAMOS_IP}:/home/deck/zaparoo/tapto + clean: rm -rf _build test: go test ./... diff --git a/cmd/batocera/main.go b/cmd/batocera/main.go index f8bd94af..99f92ce7 100755 --- a/cmd/batocera/main.go +++ b/cmd/batocera/main.go @@ -31,11 +31,11 @@ import ( "github.com/rs/zerolog" "github.com/rs/zerolog/log" - "github.com/wizzomafizzo/tapto/pkg/platforms/batocera" - "github.com/wizzomafizzo/tapto/pkg/utils" + "github.com/ZaparooProject/zaparoo-core/pkg/platforms/batocera" + "github.com/ZaparooProject/zaparoo-core/pkg/utils" - "github.com/wizzomafizzo/tapto/pkg/config" - "github.com/wizzomafizzo/tapto/pkg/service" + "github.com/ZaparooProject/zaparoo-core/pkg/config" + "github.com/ZaparooProject/zaparoo-core/pkg/service" ) const appName = "tapto" diff --git a/cmd/mac/main.go b/cmd/mac/main.go index b7570f59..c744b7b2 100755 --- a/cmd/mac/main.go +++ b/cmd/mac/main.go @@ -31,11 +31,11 @@ import ( "github.com/rs/zerolog" "github.com/rs/zerolog/log" - "github.com/wizzomafizzo/tapto/pkg/platforms/mac" - "github.com/wizzomafizzo/tapto/pkg/utils" + "github.com/ZaparooProject/zaparoo-core/pkg/platforms/mac" + "github.com/ZaparooProject/zaparoo-core/pkg/utils" - "github.com/wizzomafizzo/tapto/pkg/config" - "github.com/wizzomafizzo/tapto/pkg/service" + "github.com/ZaparooProject/zaparoo-core/pkg/config" + "github.com/ZaparooProject/zaparoo-core/pkg/service" ) const appName = "tapto" @@ -49,7 +49,7 @@ func main() { os.Exit(0) } - cfg, err := config.NewUserConfig(appName, &config.UserConfig{ + cfg, err := config.NewUserConfig(&config.UserConfig{ TapTo: config.TapToConfig{ ProbeDevice: true, }, diff --git a/cmd/mister/gui.go b/cmd/mister/gui.go index 1fb5213a..5f0d05a9 100644 --- a/cmd/mister/gui.go +++ b/cmd/mister/gui.go @@ -25,14 +25,13 @@ import ( "path" "strings" + "github.com/ZaparooProject/zaparoo-core/pkg/config" + "github.com/ZaparooProject/zaparoo-core/pkg/platforms" + "github.com/ZaparooProject/zaparoo-core/pkg/utils" "github.com/rs/zerolog/log" "github.com/rthornton128/goncurses" "github.com/wizzomafizzo/mrext/pkg/curses" mrextMister "github.com/wizzomafizzo/mrext/pkg/mister" - "github.com/wizzomafizzo/tapto/pkg/config" - "github.com/wizzomafizzo/tapto/pkg/platforms" - "github.com/wizzomafizzo/tapto/pkg/platforms/mister" - "github.com/wizzomafizzo/tapto/pkg/utils" ) func tryAddStartup(stdscr *goncurses.Window) error { @@ -308,7 +307,7 @@ func exportLog(pl platforms.Platform, stdscr *goncurses.Window) error { return nil } -func displayServiceInfo(pl platforms.Platform, cfg *config.UserConfig, stdscr *goncurses.Window, service *mister.Service) error { +func displayServiceInfo(pl platforms.Platform, cfg *config.UserConfig, stdscr *goncurses.Window, service *utils.Service) error { width := 50 height := 8 diff --git a/cmd/mister/main.go b/cmd/mister/main.go index b353ecfe..d987a681 100755 --- a/cmd/mister/main.go +++ b/cmd/mister/main.go @@ -24,16 +24,17 @@ package main import ( "flag" "fmt" + "github.com/ZaparooProject/zaparoo-core/pkg/cli" + "github.com/ZaparooProject/zaparoo-core/pkg/utils" "github.com/rs/zerolog/log" - "github.com/wizzomafizzo/tapto/pkg/cli" "os" + "github.com/ZaparooProject/zaparoo-core/pkg/platforms/mister" gc "github.com/rthornton128/goncurses" "github.com/wizzomafizzo/mrext/pkg/curses" - "github.com/wizzomafizzo/tapto/pkg/platforms/mister" - "github.com/wizzomafizzo/tapto/pkg/config" - "github.com/wizzomafizzo/tapto/pkg/service" + "github.com/ZaparooProject/zaparoo-core/pkg/config" + "github.com/ZaparooProject/zaparoo-core/pkg/service" mrextMister "github.com/wizzomafizzo/mrext/pkg/mister" ) @@ -95,10 +96,11 @@ func main() { }, }) - svc, err := mister.NewService(mister.ServiceArgs{ + svc, err := utils.NewService(utils.ServiceArgs{ Entry: func() (func() error, error) { return service.Start(pl, cfg) }, + Platform: pl, }) if err != nil { log.Error().Err(err).Msg("error creating service") diff --git a/cmd/mistex/main.go b/cmd/mistex/main.go index 65c6f69d..b912ff24 100755 --- a/cmd/mistex/main.go +++ b/cmd/mistex/main.go @@ -26,17 +26,16 @@ package main import ( "flag" "fmt" - "github.com/wizzomafizzo/tapto/pkg/cli" - "github.com/wizzomafizzo/tapto/pkg/platforms/mistex" - "github.com/wizzomafizzo/tapto/pkg/utils" + "github.com/ZaparooProject/zaparoo-core/pkg/cli" + "github.com/ZaparooProject/zaparoo-core/pkg/platforms/mistex" + "github.com/ZaparooProject/zaparoo-core/pkg/utils" "os" "os/exec" "github.com/rs/zerolog/log" - "github.com/wizzomafizzo/tapto/pkg/config" - "github.com/wizzomafizzo/tapto/pkg/platforms/mister" - "github.com/wizzomafizzo/tapto/pkg/service" + "github.com/ZaparooProject/zaparoo-core/pkg/config" + "github.com/ZaparooProject/zaparoo-core/pkg/service" ) func tryAddToStartup() (bool, error) { @@ -112,10 +111,11 @@ func main() { }, }) - svc, err := mister.NewService(mister.ServiceArgs{ + svc, err := utils.NewService(utils.ServiceArgs{ Entry: func() (func() error, error) { return service.Start(pl, cfg) }, + Platform: pl, }) if err != nil { log.Error().Err(err).Msg("error creating service") diff --git a/cmd/steamos/conf/60-zaparoo.rules b/cmd/steamos/conf/60-zaparoo.rules new file mode 100644 index 00000000..1c933d69 --- /dev/null +++ b/cmd/steamos/conf/60-zaparoo.rules @@ -0,0 +1,4 @@ +# Allow user (deck) access to NFC readers + +# CH340 serial devices (PN532 V2, ESP32, DIY Reader, etc.) +SUBSYSTEMS=="usb", ATTRS{idProduct}=="7523", ATTRS{idVendor}=="1a86", MODE="0660", GROUP="deck" diff --git a/cmd/steamos/conf/blacklist-zaparoo.conf b/cmd/steamos/conf/blacklist-zaparoo.conf new file mode 100644 index 00000000..33930733 --- /dev/null +++ b/cmd/steamos/conf/blacklist-zaparoo.conf @@ -0,0 +1,2 @@ +blacklist pn533 +blacklist pn533_usb diff --git a/cmd/steamos/conf/zaparoo.service b/cmd/steamos/conf/zaparoo.service new file mode 100644 index 00000000..d8384ef2 --- /dev/null +++ b/cmd/steamos/conf/zaparoo.service @@ -0,0 +1,15 @@ +[Unit] +Description=Zaparoo Core service + +[Service] +Type=exec +Restart=on-failure +RestartSec=5 +StandardError=syslog +User=deck +Group=deck +WorkingDirectory=%%WORKING%% +ExecStart=%%EXEC%% + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/cmd/steamos/install.go b/cmd/steamos/install.go new file mode 100644 index 00000000..56630e3d --- /dev/null +++ b/cmd/steamos/install.go @@ -0,0 +1,115 @@ +package main + +import ( + _ "embed" + "github.com/ZaparooProject/zaparoo-core/pkg/config" + "os" + "os/exec" + "path/filepath" + "strings" +) + +// TODO: allow updating if files have changed + +//go:embed conf/zaparoo.service +var serviceFile string + +//go:embed conf/blacklist-zaparoo.conf +var modprobeFile string + +//go:embed conf/60-zaparoo.rules +var udevFile string + +const ( + servicePath = "/etc/systemd/system/zaparoo.service" + modprobePath = "/etc/modprobe.d/blacklist-zaparoo.conf" + udevPath = "/etc/udev/rules.d/60-zaparoo.rules" +) + +func install() error { + // install and prep systemd service + if _, err := os.Stat(servicePath); os.IsNotExist(err) { + exe, err := os.Executable() + if err != nil { + exe = "/home/deck/zaparoo/" + config.AppName + } + serviceFile = strings.ReplaceAll(serviceFile, "%%EXEC%%", exe) + serviceFile = strings.ReplaceAll(serviceFile, "%%WORKING%%", filepath.Dir(exe)) + + err = os.WriteFile(servicePath, []byte(serviceFile), 0644) + if err != nil { + return err + } + err = exec.Command("systemctl", "daemon-reload").Run() + if err != nil { + return err + } + err = exec.Command("systemctl", "enable", "zaparoo").Run() + if err != nil { + return err + } + } + + // install udev rules and refresh + if _, err := os.Stat(udevPath); os.IsNotExist(err) { + err = os.WriteFile(udevPath, []byte(udevFile), 0644) + if err != nil { + return err + } + err = exec.Command("udevadm", "control", "--reload-rules").Run() + if err != nil { + return err + } + err = exec.Command("udevadm", "trigger").Run() + if err != nil { + return err + } + } + + // install modprobe blacklist + if _, err := os.Stat(modprobePath); os.IsNotExist(err) { + err = os.WriteFile(modprobePath, []byte(modprobeFile), 0644) + if err != nil { + return err + } + } + + return nil +} + +func uninstall() error { + if _, err := os.Stat(servicePath); !os.IsNotExist(err) { + err = exec.Command("systemctl", "disable", "zaparoo").Run() + if err != nil { + return err + } + err = exec.Command("systemctl", "stop", "zaparoo").Run() + if err != nil { + return err + } + err = exec.Command("systemctl", "daemon-reload").Run() + if err != nil { + return err + } + err = os.Remove(servicePath) + if err != nil { + return err + } + } + + if _, err := os.Stat(modprobePath); !os.IsNotExist(err) { + err = os.Remove(modprobePath) + if err != nil { + return err + } + } + + if _, err := os.Stat(udevPath); !os.IsNotExist(err) { + err = os.Remove(udevPath) + if err != nil { + return err + } + } + + return nil +} diff --git a/cmd/steamos/main.go b/cmd/steamos/main.go new file mode 100755 index 00000000..87a4e349 --- /dev/null +++ b/cmd/steamos/main.go @@ -0,0 +1,118 @@ +/* +Zaparoo Core +Copyright (C) 2023 Gareth Jones +Copyright (C) 2023, 2024 Callan Barrett + +This file is part of Zaparoo Core. + +Zaparoo Core is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Zaparoo Core is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Zaparoo Core. If not, see . +*/ + +package main + +import ( + "flag" + "fmt" + "github.com/ZaparooProject/zaparoo-core/pkg/cli" + "github.com/ZaparooProject/zaparoo-core/pkg/config" + "github.com/ZaparooProject/zaparoo-core/pkg/platforms/steamos" + "github.com/ZaparooProject/zaparoo-core/pkg/service" + "github.com/adrg/xdg" + "github.com/rs/zerolog/log" + "os" + "os/signal" + "path/filepath" + "syscall" + + _ "embed" +) + +// TODO: fix permissions on files in ~/zaparoo so root doesn't lock them + +func main() { + sigs := make(chan os.Signal, 1) + defer close(sigs) + signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM) + + pl := &steamos.Platform{} + flags := cli.SetupFlags() + + doInstall := flag.Bool("install", false, "install zaparoo service") + doUninstall := flag.Bool("uninstall", false, "uninstall zaparoo service") + + flags.Pre(pl) + + uid := os.Getuid() + if *doInstall { + if uid != 0 { + _, _ = fmt.Fprintf(os.Stderr, "Install must be run as root\n") + os.Exit(1) + } + err := install() + if err != nil { + _, _ = fmt.Fprintf(os.Stderr, "Error installing service: %v\n", err) + os.Exit(1) + } + os.Exit(0) + } else if *doUninstall { + if uid != 0 { + _, _ = fmt.Fprintf(os.Stderr, "Uninstall must be run as root\n") + os.Exit(1) + } + err := uninstall() + if err != nil { + _, _ = fmt.Fprintf(os.Stderr, "Error uninstalling service: %v\n", err) + os.Exit(1) + } + os.Exit(0) + } + + if uid == 0 { + _, _ = fmt.Fprintf(os.Stderr, "Service must not be run as root\n") + os.Exit(1) + } + + err := os.MkdirAll(filepath.Join(xdg.DataHome, config.AppName), 0755) + if err != nil { + _, _ = fmt.Fprintf(os.Stderr, "Error creating data directory: %v\n", err) + os.Exit(1) + } + + cfg := cli.Setup(pl, &config.UserConfig{ + TapTo: config.TapToConfig{ + ProbeDevice: true, + ConsoleLogging: true, + }, + Api: config.ApiConfig{ + Port: config.DefaultApiPort, + }, + }) + + flags.Post(cfg) + + stop, err := service.Start(pl, cfg) + if err != nil { + log.Error().Err(err).Msg("error starting service") + os.Exit(1) + } + + <-sigs + err = stop() + if err != nil { + log.Error().Err(err).Msg("error stopping service") + os.Exit(1) + } + + os.Exit(0) +} diff --git a/cmd/windows/main.go b/cmd/windows/main.go index 3494f3b0..1911bc8d 100755 --- a/cmd/windows/main.go +++ b/cmd/windows/main.go @@ -31,11 +31,11 @@ import ( "github.com/rs/zerolog" "github.com/rs/zerolog/log" - "github.com/wizzomafizzo/tapto/pkg/platforms/windows" - "github.com/wizzomafizzo/tapto/pkg/utils" + "github.com/ZaparooProject/zaparoo-core/pkg/platforms/windows" + "github.com/ZaparooProject/zaparoo-core/pkg/utils" - "github.com/wizzomafizzo/tapto/pkg/config" - "github.com/wizzomafizzo/tapto/pkg/service" + "github.com/ZaparooProject/zaparoo-core/pkg/config" + "github.com/ZaparooProject/zaparoo-core/pkg/service" ) func main() { diff --git a/go.mod b/go.mod index 79a7c74e..01e1da3b 100755 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/wizzomafizzo/tapto +module github.com/ZaparooProject/zaparoo-core go 1.19 @@ -17,44 +17,37 @@ require ( github.com/txn2/txeh v1.4.0 // indirect golang.org/x/mod v0.18.0 // indirect golang.org/x/net v0.26.0 // indirect - golang.org/x/sys v0.22.0 // indirect + golang.org/x/sys v0.26.0 // indirect golang.org/x/tools v0.22.0 // indirect gopkg.in/natefinch/lumberjack.v2 v2.0.0 ) require ( - github.com/ajg/form v1.5.1 // indirect github.com/creack/goselect v0.1.2 // indirect - github.com/gorilla/websocket v1.5.3 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.20 // indirect - github.com/mattn/go-runewidth v0.0.9 // indirect - github.com/mdp/qrterminal/v3 v3.2.0 // indirect - github.com/nsf/termbox-go v1.1.1 // indirect - github.com/stretchr/testify v1.9.0 // indirect - github.com/yeqown/go-qrcode/v2 v2.2.4 // indirect - github.com/yeqown/go-qrcode/writer/terminal v1.1.1 // indirect - github.com/yeqown/reedsolomon v1.0.0 // indirect golang.org/x/term v0.22.0 // indirect - golang.org/x/text v0.19.0 // indirect rsc.io/qr v0.2.0 // indirect ) require ( + github.com/adrg/xdg v0.5.3 github.com/andygrunwald/vdf v1.1.0 github.com/clausecker/nfc/v2 v2.1.4 github.com/ebfe/scard v0.0.0-20230420082256-7db3f9b7c8a7 github.com/go-chi/chi/v5 v5.0.12 github.com/go-chi/cors v1.2.1 - github.com/go-chi/render v1.0.3 github.com/gobwas/glob v0.2.3 github.com/gocarina/gocsv v0.0.0-20230616125104-99d496ca653d github.com/google/uuid v1.6.0 + github.com/gorilla/websocket v1.5.3 github.com/hsanjuan/go-ndef v0.0.1 + github.com/mdp/qrterminal/v3 v3.2.0 github.com/olahol/melody v1.2.1 github.com/rs/zerolog v1.31.0 github.com/wizzomafizzo/mrext v0.0.0-20240804073054-39dcc9bccc81 go.bug.st/serial v1.6.2 go.etcd.io/bbolt v1.3.9 golang.org/x/sync v0.8.0 + golang.org/x/text v0.19.0 ) diff --git a/go.sum b/go.sum index a9d067a1..cd581498 100644 --- a/go.sum +++ b/go.sum @@ -1,6 +1,6 @@ github.com/BurntSushi/toml v1.2.1 h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak= -github.com/ajg/form v1.5.1 h1:t9c7v8JUKu/XxOGBU0yjNpaMloxGEJhUkqFRq0ibGeU= -github.com/ajg/form v1.5.1/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY= +github.com/adrg/xdg v0.5.3 h1:xRnxJXne7+oWDatRhR1JLnvuccuIeCoBu2rtuLqQB78= +github.com/adrg/xdg v0.5.3/go.mod h1:nlTsY+NNiCBGCK2tpm09vRqfVzrc2fLmXGpBLF0zlTQ= github.com/andygrunwald/vdf v1.1.0 h1:gmstp0R7DOepIZvWoSJY97ix7QOrsxpGPU6KusKXqvw= github.com/andygrunwald/vdf v1.1.0/go.mod h1:f31AAs7HOKvs5B167iwLHwKuqKc4bE46Vdt7xQogA0o= github.com/bendahl/uinput v1.7.0 h1:nA4fm8Wu8UYNOPykIZm66nkWEyvxzfmJ8YC02PM40jg= @@ -21,8 +21,6 @@ github.com/go-chi/chi/v5 v5.0.12 h1:9euLV5sTrTNTRUU9POmDUvfxyj6LAABLUcEWO+JJb4s= github.com/go-chi/chi/v5 v5.0.12/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= github.com/go-chi/cors v1.2.1 h1:xEC8UT3Rlp2QuWNEr4Fs/c2EAGVKBwy/1vHx3bppil4= github.com/go-chi/cors v1.2.1/go.mod h1:sSbTewc+6wYHBBCW7ytsFSn836hqM7JxpglAy2Vzc58= -github.com/go-chi/render v1.0.3 h1:AsXqd2a1/INaIfUSKq3G5uA8weYx20FOsM7uSoCyyt4= -github.com/go-chi/render v1.0.3/go.mod h1:/gr3hVkmYR0YlEy3LxCuVRFzEu9Ruok+gFqbIofjao0= github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y= github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8= github.com/gocarina/gocsv v0.0.0-20230616125104-99d496ca653d h1:KbPOUXFUDJxwZ04vbmDOc3yuruGvVO+LOa7cVER3yWw= @@ -30,8 +28,6 @@ github.com/gocarina/gocsv v0.0.0-20230616125104-99d496ca653d/go.mod h1:5YoVOkjYA github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY= -github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY= github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg= github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/hsanjuan/go-ndef v0.0.1 h1:un1E9jEVa0t8j33qT2JFfseOAI3MikbrkmMEn9Lx0Wk= @@ -44,15 +40,11 @@ github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/ github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= -github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0= -github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mdp/qrterminal/v3 v3.2.0 h1:qteQMXO3oyTK4IHwj2mWsKYYRBOp1Pj2WRYFYYNTCdk= github.com/mdp/qrterminal/v3 v3.2.0/go.mod h1:XGGuua4Lefrl7TLEsSONiD+UEjQXJZ4mPzF+gWYIJkk= github.com/miekg/dns v1.1.43/go.mod h1:+evo5L0630/F6ca/Z9+GAqzhjGyn8/c+TBaOyfEl0V4= github.com/miekg/dns v1.1.55 h1:GoQ4hpsj0nFLYe+bWiCToyrBEJXkQfOOIvFGFy0lEgo= github.com/miekg/dns v1.1.55/go.mod h1:uInx36IzPl7FYnDcMeVWxj9byh7DutNykX4G9Sj60FY= -github.com/nsf/termbox-go v1.1.1 h1:nksUPLCb73Q++DwbYUBEglYBRPZyoXJdrj5L+TkjyZY= -github.com/nsf/termbox-go v1.1.1/go.mod h1:T0cTdVuOwf7pHQNtfhnEbzHbcNyCEcVU4YPpouCbVxo= github.com/olahol/melody v1.2.1 h1:xdwRkzHxf+B0w4TKbGpUSSkV516ZucQZJIWLztOWICQ= github.com/olahol/melody v1.2.1/go.mod h1:GgkTl6Y7yWj/HtfD48Q5vLKPVoZOH+Qqgfa7CvJgJM4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= @@ -68,17 +60,10 @@ github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSS github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= -github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/txn2/txeh v1.4.0 h1:0tdvpA4HGJrj8X3kmrU6o/JFStI009nKxwDpMK5CnRU= github.com/txn2/txeh v1.4.0/go.mod h1:Mgq0hY184zCrDBLgvkIp+9NYGHoYbJcu4xKqUcx1shc= github.com/wizzomafizzo/mrext v0.0.0-20240804073054-39dcc9bccc81 h1:j9tZjWiwt0JeKHYIxbJ9a+25K7v+bks696i4Cx5Thbk= github.com/wizzomafizzo/mrext v0.0.0-20240804073054-39dcc9bccc81/go.mod h1:pWjoPIzJIXlDfEmdf++eUqsZKrEsYVkOHy39s/H7WLA= -github.com/yeqown/go-qrcode/v2 v2.2.4 h1:cXdYlrhzHzVAnJHiwr/T6lAUmS9MtEStjEZBjArrvnc= -github.com/yeqown/go-qrcode/v2 v2.2.4/go.mod h1:uHpt9CM0V1HeXLz+Wg5MN50/sI/fQhfkZlOM+cOTHxw= -github.com/yeqown/go-qrcode/writer/terminal v1.1.1 h1:hNyyddHy+S5gG2A9PoeFN9P3exKJYCSnnxyaprwBH8A= -github.com/yeqown/go-qrcode/writer/terminal v1.1.1/go.mod h1:7Fn5MU6v2Eq1Mx/EOn2OMt2NmaWYSeM+Iu9w2SrY338= -github.com/yeqown/reedsolomon v1.0.0 h1:x1h/Ej/uJnNu8jaX7GLHBWmZKCAWjEJTetkqaabr4B0= -github.com/yeqown/reedsolomon v1.0.0/go.mod h1:P76zpcn2TCuL0ul1Fso373qHRc69LKwAw/Iy6g1WiiM= go.bug.st/serial v1.6.2 h1:kn9LRX3sdm+WxWKufMlIRndwGfPWsH1/9lCWXQCasq8= go.bug.st/serial v1.6.2/go.mod h1:UABfsluHAiaNI+La2iESysd9Vetq7VRdpxvjx7CmmOE= go.etcd.io/bbolt v1.3.9 h1:8x7aARPEXiXbHmtUwAIv7eV2fQFHrLLavdiJ3uzJXoI= @@ -92,8 +77,6 @@ golang.org/x/net v0.0.0-20210423184538-5f58ad60dda6/go.mod h1:OJAsFXCWl8Ukc7SiCT golang.org/x/net v0.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ= golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= -golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -104,8 +87,8 @@ golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI= -golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo= +golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.22.0 h1:BbsgPEJULsl2fV/AT3v15Mjva5yXKQDyKf+TbDz7QJk= golang.org/x/term v0.22.0/go.mod h1:F3qCibpT5AMpCRfhfT53vVJwhLtIVHhB9XDjfFvnMI4= diff --git a/pkg/api/client/client.go b/pkg/api/client/client.go index 5eac3f9c..a4096939 100644 --- a/pkg/api/client/client.go +++ b/pkg/api/client/client.go @@ -3,12 +3,12 @@ package client import ( "encoding/json" "errors" + "github.com/ZaparooProject/zaparoo-core/pkg/api" + "github.com/ZaparooProject/zaparoo-core/pkg/api/models" + "github.com/ZaparooProject/zaparoo-core/pkg/config" "github.com/google/uuid" "github.com/gorilla/websocket" "github.com/rs/zerolog/log" - "github.com/wizzomafizzo/tapto/pkg/api" - "github.com/wizzomafizzo/tapto/pkg/api/models" - "github.com/wizzomafizzo/tapto/pkg/config" "net/url" "time" ) diff --git a/pkg/api/methods/games.go b/pkg/api/methods/games.go index 178b918f..e0e39c2d 100644 --- a/pkg/api/methods/games.go +++ b/pkg/api/methods/games.go @@ -3,15 +3,15 @@ package methods import ( "encoding/json" "errors" - "github.com/wizzomafizzo/tapto/pkg/api/models" - "github.com/wizzomafizzo/tapto/pkg/api/models/requests" + "github.com/ZaparooProject/zaparoo-core/pkg/api/models" + "github.com/ZaparooProject/zaparoo-core/pkg/api/models/requests" "sync" + "github.com/ZaparooProject/zaparoo-core/pkg/assets" + "github.com/ZaparooProject/zaparoo-core/pkg/config" + "github.com/ZaparooProject/zaparoo-core/pkg/database/gamesdb" + "github.com/ZaparooProject/zaparoo-core/pkg/platforms" "github.com/rs/zerolog/log" - "github.com/wizzomafizzo/tapto/pkg/assets" - "github.com/wizzomafizzo/tapto/pkg/config" - "github.com/wizzomafizzo/tapto/pkg/database/gamesdb" - "github.com/wizzomafizzo/tapto/pkg/platforms" ) const defaultMaxResults = 250 diff --git a/pkg/api/methods/history.go b/pkg/api/methods/history.go index ad6efcc7..41a9e603 100644 --- a/pkg/api/methods/history.go +++ b/pkg/api/methods/history.go @@ -2,9 +2,9 @@ package methods import ( "errors" + "github.com/ZaparooProject/zaparoo-core/pkg/api/models" + "github.com/ZaparooProject/zaparoo-core/pkg/api/models/requests" "github.com/rs/zerolog/log" - "github.com/wizzomafizzo/tapto/pkg/api/models" - "github.com/wizzomafizzo/tapto/pkg/api/models/requests" ) func HandleHistory(env requests.RequestEnv) (any, error) { diff --git a/pkg/api/methods/launch.go b/pkg/api/methods/launch.go index 3d088295..44cad44b 100644 --- a/pkg/api/methods/launch.go +++ b/pkg/api/methods/launch.go @@ -3,17 +3,17 @@ package methods import ( "encoding/json" "errors" - "github.com/wizzomafizzo/tapto/pkg/api/models" - "github.com/wizzomafizzo/tapto/pkg/api/models/requests" - "github.com/wizzomafizzo/tapto/pkg/service/tokens" + "github.com/ZaparooProject/zaparoo-core/pkg/api/models" + "github.com/ZaparooProject/zaparoo-core/pkg/api/models/requests" + "github.com/ZaparooProject/zaparoo-core/pkg/service/tokens" "golang.org/x/text/unicode/norm" "net/http" "net/url" "time" + "github.com/ZaparooProject/zaparoo-core/pkg/service/state" "github.com/go-chi/chi/v5" "github.com/rs/zerolog/log" - "github.com/wizzomafizzo/tapto/pkg/service/state" ) var ( diff --git a/pkg/api/methods/mappings.go b/pkg/api/methods/mappings.go index bb64e22c..65b41134 100644 --- a/pkg/api/methods/mappings.go +++ b/pkg/api/methods/mappings.go @@ -3,15 +3,15 @@ package methods import ( "encoding/json" "errors" - "github.com/wizzomafizzo/tapto/pkg/api/models" - "github.com/wizzomafizzo/tapto/pkg/api/models/requests" + "github.com/ZaparooProject/zaparoo-core/pkg/api/models" + "github.com/ZaparooProject/zaparoo-core/pkg/api/models/requests" "regexp" "strconv" "time" + "github.com/ZaparooProject/zaparoo-core/pkg/database" + "github.com/ZaparooProject/zaparoo-core/pkg/utils" "github.com/rs/zerolog/log" - "github.com/wizzomafizzo/tapto/pkg/database" - "github.com/wizzomafizzo/tapto/pkg/utils" ) func HandleMappings(env requests.RequestEnv) (any, error) { diff --git a/pkg/api/methods/readers.go b/pkg/api/methods/readers.go index 9bf36962..c920bbf7 100644 --- a/pkg/api/methods/readers.go +++ b/pkg/api/methods/readers.go @@ -3,9 +3,9 @@ package methods import ( "encoding/json" "errors" + "github.com/ZaparooProject/zaparoo-core/pkg/api/models" + "github.com/ZaparooProject/zaparoo-core/pkg/api/models/requests" "github.com/rs/zerolog/log" - "github.com/wizzomafizzo/tapto/pkg/api/models" - "github.com/wizzomafizzo/tapto/pkg/api/models/requests" ) func HandleReaderWrite(env requests.RequestEnv) (any, error) { diff --git a/pkg/api/methods/settings.go b/pkg/api/methods/settings.go index e4e42619..3fbd5aab 100644 --- a/pkg/api/methods/settings.go +++ b/pkg/api/methods/settings.go @@ -2,9 +2,9 @@ package methods import ( "encoding/json" + "github.com/ZaparooProject/zaparoo-core/pkg/api/models" + "github.com/ZaparooProject/zaparoo-core/pkg/api/models/requests" "github.com/rs/zerolog/log" - "github.com/wizzomafizzo/tapto/pkg/api/models" - "github.com/wizzomafizzo/tapto/pkg/api/models/requests" ) func HandleSettings(env requests.RequestEnv) (any, error) { diff --git a/pkg/api/methods/status.go b/pkg/api/methods/status.go index 21481f10..f5ae1c45 100644 --- a/pkg/api/methods/status.go +++ b/pkg/api/methods/status.go @@ -1,12 +1,12 @@ package methods import ( + "github.com/ZaparooProject/zaparoo-core/pkg/api/models" + "github.com/ZaparooProject/zaparoo-core/pkg/api/models/requests" + "github.com/ZaparooProject/zaparoo-core/pkg/config" + "github.com/ZaparooProject/zaparoo-core/pkg/platforms" + "github.com/ZaparooProject/zaparoo-core/pkg/service/state" "github.com/rs/zerolog/log" - "github.com/wizzomafizzo/tapto/pkg/api/models" - "github.com/wizzomafizzo/tapto/pkg/api/models/requests" - "github.com/wizzomafizzo/tapto/pkg/config" - "github.com/wizzomafizzo/tapto/pkg/platforms" - "github.com/wizzomafizzo/tapto/pkg/service/state" ) func newStatus( diff --git a/pkg/api/methods/systems.go b/pkg/api/methods/systems.go index f16e8995..96b73375 100644 --- a/pkg/api/methods/systems.go +++ b/pkg/api/methods/systems.go @@ -1,11 +1,11 @@ package methods import ( + "github.com/ZaparooProject/zaparoo-core/pkg/api/models" + "github.com/ZaparooProject/zaparoo-core/pkg/api/models/requests" + "github.com/ZaparooProject/zaparoo-core/pkg/assets" + "github.com/ZaparooProject/zaparoo-core/pkg/database/gamesdb" "github.com/rs/zerolog/log" - "github.com/wizzomafizzo/tapto/pkg/api/models" - "github.com/wizzomafizzo/tapto/pkg/api/models/requests" - "github.com/wizzomafizzo/tapto/pkg/assets" - "github.com/wizzomafizzo/tapto/pkg/database/gamesdb" ) func HandleSystems(env requests.RequestEnv) (any, error) { diff --git a/pkg/api/models/requests/requests.go b/pkg/api/models/requests/requests.go index 50637350..46eb54de 100644 --- a/pkg/api/models/requests/requests.go +++ b/pkg/api/models/requests/requests.go @@ -1,12 +1,12 @@ package requests import ( + "github.com/ZaparooProject/zaparoo-core/pkg/config" + "github.com/ZaparooProject/zaparoo-core/pkg/database" + "github.com/ZaparooProject/zaparoo-core/pkg/platforms" + "github.com/ZaparooProject/zaparoo-core/pkg/service/state" + "github.com/ZaparooProject/zaparoo-core/pkg/service/tokens" "github.com/google/uuid" - "github.com/wizzomafizzo/tapto/pkg/config" - "github.com/wizzomafizzo/tapto/pkg/database" - "github.com/wizzomafizzo/tapto/pkg/platforms" - "github.com/wizzomafizzo/tapto/pkg/service/state" - "github.com/wizzomafizzo/tapto/pkg/service/tokens" ) type RequestEnv struct { diff --git a/pkg/api/server.go b/pkg/api/server.go index 442540d4..3f7d0f95 100644 --- a/pkg/api/server.go +++ b/pkg/api/server.go @@ -4,25 +4,25 @@ import ( "bytes" "encoding/json" "errors" - "github.com/wizzomafizzo/tapto/pkg/api/methods" - "github.com/wizzomafizzo/tapto/pkg/api/models" - "github.com/wizzomafizzo/tapto/pkg/api/models/requests" - "github.com/wizzomafizzo/tapto/pkg/service/tokens" + "github.com/ZaparooProject/zaparoo-core/pkg/api/methods" + "github.com/ZaparooProject/zaparoo-core/pkg/api/models" + "github.com/ZaparooProject/zaparoo-core/pkg/api/models/requests" + "github.com/ZaparooProject/zaparoo-core/pkg/service/tokens" "net" "net/http" "strings" "time" + "github.com/ZaparooProject/zaparoo-core/pkg/config" + "github.com/ZaparooProject/zaparoo-core/pkg/database" + "github.com/ZaparooProject/zaparoo-core/pkg/platforms" + "github.com/ZaparooProject/zaparoo-core/pkg/service/state" "github.com/go-chi/chi/v5" "github.com/go-chi/chi/v5/middleware" "github.com/go-chi/cors" "github.com/google/uuid" "github.com/olahol/melody" "github.com/rs/zerolog/log" - "github.com/wizzomafizzo/tapto/pkg/config" - "github.com/wizzomafizzo/tapto/pkg/database" - "github.com/wizzomafizzo/tapto/pkg/platforms" - "github.com/wizzomafizzo/tapto/pkg/service/state" ) // TODO: should there be a TTL for request timestamps? what about offline misters? diff --git a/pkg/cli/cli.go b/pkg/cli/cli.go index 8e417d08..cedfb5f8 100644 --- a/pkg/cli/cli.go +++ b/pkg/cli/cli.go @@ -4,14 +4,14 @@ import ( "encoding/json" "flag" "fmt" + "github.com/ZaparooProject/zaparoo-core/pkg/api/client" + "github.com/ZaparooProject/zaparoo-core/pkg/api/models" + "github.com/ZaparooProject/zaparoo-core/pkg/config" + "github.com/ZaparooProject/zaparoo-core/pkg/platforms" + "github.com/ZaparooProject/zaparoo-core/pkg/utils" "github.com/google/uuid" "github.com/mdp/qrterminal/v3" "github.com/rs/zerolog/log" - "github.com/wizzomafizzo/tapto/pkg/api/client" - "github.com/wizzomafizzo/tapto/pkg/api/models" - "github.com/wizzomafizzo/tapto/pkg/config" - "github.com/wizzomafizzo/tapto/pkg/platforms" - "github.com/wizzomafizzo/tapto/pkg/utils" "os" "strings" ) @@ -79,7 +79,7 @@ func (f *Flags) Pre(pl platforms.Platform) { flag.Parse() if *f.Version { - fmt.Printf("TapTo v%s (%s)\n", config.Version, pl.Id()) + fmt.Printf("Zaparoo v%s (%s)\n", config.Version, pl.Id()) os.Exit(0) } } diff --git a/pkg/config/tapto.go b/pkg/config/tapto.go index 1c694368..8177505d 100644 --- a/pkg/config/tapto.go +++ b/pkg/config/tapto.go @@ -1,10 +1,27 @@ package config +import ( + "github.com/rs/zerolog/log" + "os" + "path/filepath" +) + const ( - Version = "2.0.1" - GamesDbFilename = "games.db" - TapToDbFilename = "tapto.db" - DefaultApiPort = "7497" - LogFilename = "tapto.log" - AppName = "tapto" + Version = "2.0.1" + GamesDbFilename = "games.db" + TapToDbFilename = "tapto.db" + DefaultApiPort = "7497" + LogFilename = "tapto.log" + AppName = "tapto" + UserConfigFilename = "tapto.ini" + PidFilename = "tapto.pid" ) + +func TempDir() string { + path := filepath.Join(os.TempDir(), AppName) + err := os.MkdirAll(path, 0755) + if err != nil { + log.Error().Err(err).Msg("error creating temp folder") + } + return path +} diff --git a/pkg/database/database.go b/pkg/database/database.go index e44933d2..db579d8f 100644 --- a/pkg/database/database.go +++ b/pkg/database/database.go @@ -6,8 +6,8 @@ import ( "path/filepath" "time" - "github.com/wizzomafizzo/tapto/pkg/config" - "github.com/wizzomafizzo/tapto/pkg/platforms" + "github.com/ZaparooProject/zaparoo-core/pkg/config" + "github.com/ZaparooProject/zaparoo-core/pkg/platforms" bolt "go.etcd.io/bbolt" ) diff --git a/pkg/database/gamesdb/gamesdb.go b/pkg/database/gamesdb/gamesdb.go index e976feef..103ccb14 100644 --- a/pkg/database/gamesdb/gamesdb.go +++ b/pkg/database/gamesdb/gamesdb.go @@ -12,11 +12,11 @@ import ( bolt "go.etcd.io/bbolt" "golang.org/x/sync/errgroup" + "github.com/ZaparooProject/zaparoo-core/pkg/config" + "github.com/ZaparooProject/zaparoo-core/pkg/platforms" + "github.com/ZaparooProject/zaparoo-core/pkg/utils" "github.com/gobwas/glob" "github.com/rs/zerolog/log" - "github.com/wizzomafizzo/tapto/pkg/config" - "github.com/wizzomafizzo/tapto/pkg/platforms" - "github.com/wizzomafizzo/tapto/pkg/utils" ) const ( diff --git a/pkg/database/gamesdb/indexing.go b/pkg/database/gamesdb/indexing.go index 4d9163c9..f768770d 100644 --- a/pkg/database/gamesdb/indexing.go +++ b/pkg/database/gamesdb/indexing.go @@ -2,14 +2,14 @@ package gamesdb import ( "fmt" - "github.com/wizzomafizzo/tapto/pkg/config" + "github.com/ZaparooProject/zaparoo-core/pkg/config" "io/fs" "os" "path/filepath" "strings" - "github.com/wizzomafizzo/tapto/pkg/platforms" - "github.com/wizzomafizzo/tapto/pkg/utils" + "github.com/ZaparooProject/zaparoo-core/pkg/platforms" + "github.com/ZaparooProject/zaparoo-core/pkg/utils" ) type PathResult struct { diff --git a/pkg/database/gamesdb/systems.go b/pkg/database/gamesdb/systems.go index 73aff4c3..79b07133 100644 --- a/pkg/database/gamesdb/systems.go +++ b/pkg/database/gamesdb/systems.go @@ -4,7 +4,7 @@ import ( "fmt" "strings" - "github.com/wizzomafizzo/tapto/pkg/utils" + "github.com/ZaparooProject/zaparoo-core/pkg/utils" ) // The Systems list contains all the supported systems such as consoles, diff --git a/pkg/database/mappings.go b/pkg/database/mappings.go index eeb3a9a9..4f2fe3b9 100644 --- a/pkg/database/mappings.go +++ b/pkg/database/mappings.go @@ -9,7 +9,7 @@ import ( "strings" "time" - "github.com/wizzomafizzo/tapto/pkg/utils" + "github.com/ZaparooProject/zaparoo-core/pkg/utils" bolt "go.etcd.io/bbolt" ) diff --git a/pkg/launcher/commands.go b/pkg/launcher/commands.go index 88b0f8d6..c7d5c07c 100644 --- a/pkg/launcher/commands.go +++ b/pkg/launcher/commands.go @@ -22,8 +22,8 @@ package launcher import ( "fmt" - "github.com/wizzomafizzo/tapto/pkg/service/playlists" - "github.com/wizzomafizzo/tapto/pkg/service/tokens" + "github.com/ZaparooProject/zaparoo-core/pkg/service/playlists" + "github.com/ZaparooProject/zaparoo-core/pkg/service/tokens" "net/url" "os" "path/filepath" @@ -33,8 +33,8 @@ import ( "github.com/rs/zerolog/log" - "github.com/wizzomafizzo/tapto/pkg/config" - "github.com/wizzomafizzo/tapto/pkg/platforms" + "github.com/ZaparooProject/zaparoo-core/pkg/config" + "github.com/ZaparooProject/zaparoo-core/pkg/platforms" ) // TODO: adding some logging for each command diff --git a/pkg/launcher/http.go b/pkg/launcher/http.go index a73fbdae..acd45fe7 100644 --- a/pkg/launcher/http.go +++ b/pkg/launcher/http.go @@ -7,7 +7,7 @@ import ( "github.com/rs/zerolog/log" - "github.com/wizzomafizzo/tapto/pkg/platforms" + "github.com/ZaparooProject/zaparoo-core/pkg/platforms" ) func cmdHttpGet(_ platforms.Platform, env platforms.CmdEnv) error { diff --git a/pkg/launcher/input.go b/pkg/launcher/input.go index 01bb1bf9..0c10cc27 100644 --- a/pkg/launcher/input.go +++ b/pkg/launcher/input.go @@ -7,7 +7,7 @@ import ( "github.com/rs/zerolog/log" - "github.com/wizzomafizzo/tapto/pkg/platforms" + "github.com/ZaparooProject/zaparoo-core/pkg/platforms" ) // DEPRECATED diff --git a/pkg/launcher/launch.go b/pkg/launcher/launch.go index 3f3c02d0..f7f522de 100644 --- a/pkg/launcher/launch.go +++ b/pkg/launcher/launch.go @@ -2,7 +2,7 @@ package launcher import ( "fmt" - "github.com/wizzomafizzo/tapto/pkg/service/playlists" + "github.com/ZaparooProject/zaparoo-core/pkg/service/playlists" "os" "path/filepath" "regexp" @@ -10,9 +10,9 @@ import ( "github.com/rs/zerolog/log" - "github.com/wizzomafizzo/tapto/pkg/database/gamesdb" - "github.com/wizzomafizzo/tapto/pkg/platforms" - "github.com/wizzomafizzo/tapto/pkg/utils" + "github.com/ZaparooProject/zaparoo-core/pkg/database/gamesdb" + "github.com/ZaparooProject/zaparoo-core/pkg/platforms" + "github.com/ZaparooProject/zaparoo-core/pkg/utils" ) func cmdSystem(pl platforms.Platform, env platforms.CmdEnv) error { diff --git a/pkg/launcher/utils.go b/pkg/launcher/utils.go index 1d18dcd5..0af68437 100644 --- a/pkg/launcher/utils.go +++ b/pkg/launcher/utils.go @@ -7,7 +7,7 @@ import ( "github.com/rs/zerolog/log" - "github.com/wizzomafizzo/tapto/pkg/platforms" + "github.com/ZaparooProject/zaparoo-core/pkg/platforms" ) func cmdDelay(pl platforms.Platform, env platforms.CmdEnv) error { diff --git a/pkg/platforms/batocera/platform.go b/pkg/platforms/batocera/platform.go index 6c46489c..8fa99a8e 100644 --- a/pkg/platforms/batocera/platform.go +++ b/pkg/platforms/batocera/platform.go @@ -2,21 +2,21 @@ package batocera import ( "errors" - "github.com/wizzomafizzo/tapto/pkg/api/models" - "github.com/wizzomafizzo/tapto/pkg/service/tokens" + "github.com/ZaparooProject/zaparoo-core/pkg/api/models" + "github.com/ZaparooProject/zaparoo-core/pkg/service/tokens" "os" "os/exec" "path/filepath" "strings" + "github.com/ZaparooProject/zaparoo-core/pkg/config" + "github.com/ZaparooProject/zaparoo-core/pkg/database/gamesdb" + "github.com/ZaparooProject/zaparoo-core/pkg/platforms" + "github.com/ZaparooProject/zaparoo-core/pkg/readers" + "github.com/ZaparooProject/zaparoo-core/pkg/readers/file" + "github.com/ZaparooProject/zaparoo-core/pkg/readers/libnfc" + "github.com/ZaparooProject/zaparoo-core/pkg/readers/simple_serial" "github.com/rs/zerolog/log" - "github.com/wizzomafizzo/tapto/pkg/config" - "github.com/wizzomafizzo/tapto/pkg/database/gamesdb" - "github.com/wizzomafizzo/tapto/pkg/platforms" - "github.com/wizzomafizzo/tapto/pkg/readers" - "github.com/wizzomafizzo/tapto/pkg/readers/file" - "github.com/wizzomafizzo/tapto/pkg/readers/libnfc" - "github.com/wizzomafizzo/tapto/pkg/readers/simple_serial" ) type Platform struct { diff --git a/pkg/platforms/mac/platform.go b/pkg/platforms/mac/platform.go index d451ef59..505e3838 100644 --- a/pkg/platforms/mac/platform.go +++ b/pkg/platforms/mac/platform.go @@ -1,19 +1,19 @@ package mac import ( - "github.com/wizzomafizzo/tapto/pkg/api/models" - "github.com/wizzomafizzo/tapto/pkg/service/tokens" + "github.com/ZaparooProject/zaparoo-core/pkg/api/models" + "github.com/ZaparooProject/zaparoo-core/pkg/service/tokens" "os" "os/exec" "path/filepath" + "github.com/ZaparooProject/zaparoo-core/pkg/config" + "github.com/ZaparooProject/zaparoo-core/pkg/platforms" + "github.com/ZaparooProject/zaparoo-core/pkg/readers" + "github.com/ZaparooProject/zaparoo-core/pkg/readers/file" + "github.com/ZaparooProject/zaparoo-core/pkg/readers/pn532_uart" + "github.com/ZaparooProject/zaparoo-core/pkg/readers/simple_serial" "github.com/rs/zerolog/log" - "github.com/wizzomafizzo/tapto/pkg/config" - "github.com/wizzomafizzo/tapto/pkg/platforms" - "github.com/wizzomafizzo/tapto/pkg/readers" - "github.com/wizzomafizzo/tapto/pkg/readers/file" - "github.com/wizzomafizzo/tapto/pkg/readers/pn532_uart" - "github.com/wizzomafizzo/tapto/pkg/readers/simple_serial" ) type Platform struct { diff --git a/pkg/platforms/mister/commands.go b/pkg/platforms/mister/commands.go index 82cb297f..65f96c74 100644 --- a/pkg/platforms/mister/commands.go +++ b/pkg/platforms/mister/commands.go @@ -10,9 +10,9 @@ import ( "strings" "time" + "github.com/ZaparooProject/zaparoo-core/pkg/platforms" "github.com/rs/zerolog/log" "github.com/wizzomafizzo/mrext/pkg/mister" - "github.com/wizzomafizzo/tapto/pkg/platforms" ) func CmdIni(_ platforms.Platform, env platforms.CmdEnv) error { diff --git a/pkg/platforms/mister/config.go b/pkg/platforms/mister/config.go index 5d3479ef..abdf8c55 100644 --- a/pkg/platforms/mister/config.go +++ b/pkg/platforms/mister/config.go @@ -3,8 +3,8 @@ package mister import ( + "github.com/ZaparooProject/zaparoo-core/pkg/config" mrextConfig "github.com/wizzomafizzo/mrext/pkg/config" - "github.com/wizzomafizzo/tapto/pkg/config" ) const ( diff --git a/pkg/platforms/mister/launchers.go b/pkg/platforms/mister/launchers.go index 4e21e36b..f6a2f205 100644 --- a/pkg/platforms/mister/launchers.go +++ b/pkg/platforms/mister/launchers.go @@ -4,12 +4,12 @@ package mister import ( "fmt" + "github.com/ZaparooProject/zaparoo-core/pkg/config" + "github.com/ZaparooProject/zaparoo-core/pkg/database/gamesdb" + "github.com/ZaparooProject/zaparoo-core/pkg/platforms" "github.com/rs/zerolog/log" "github.com/wizzomafizzo/mrext/pkg/games" "github.com/wizzomafizzo/mrext/pkg/mister" - "github.com/wizzomafizzo/tapto/pkg/config" - "github.com/wizzomafizzo/tapto/pkg/database/gamesdb" - "github.com/wizzomafizzo/tapto/pkg/platforms" "os" "os/exec" "path/filepath" diff --git a/pkg/platforms/mister/methods.go b/pkg/platforms/mister/methods.go index d1dbb1c0..6b087b11 100644 --- a/pkg/platforms/mister/methods.go +++ b/pkg/platforms/mister/methods.go @@ -7,13 +7,13 @@ import ( "os/exec" "strings" + "github.com/ZaparooProject/zaparoo-core/pkg/assets" + "github.com/ZaparooProject/zaparoo-core/pkg/config" "github.com/rs/zerolog/log" mrextConfig "github.com/wizzomafizzo/mrext/pkg/config" "github.com/wizzomafizzo/mrext/pkg/games" mrextMister "github.com/wizzomafizzo/mrext/pkg/mister" "github.com/wizzomafizzo/mrext/pkg/utils" - "github.com/wizzomafizzo/tapto/pkg/assets" - "github.com/wizzomafizzo/tapto/pkg/config" ) // TODO: don't want to depend on external aplay command, but i'm out of diff --git a/pkg/platforms/mister/platform.go b/pkg/platforms/mister/platform.go index 5fb75588..41be6731 100644 --- a/pkg/platforms/mister/platform.go +++ b/pkg/platforms/mister/platform.go @@ -7,11 +7,11 @@ import ( "encoding/xml" "errors" "fmt" - "github.com/wizzomafizzo/tapto/pkg/api/models" - "github.com/wizzomafizzo/tapto/pkg/database/gamesdb" - "github.com/wizzomafizzo/tapto/pkg/readers/optical_drive" - "github.com/wizzomafizzo/tapto/pkg/service/tokens" - "github.com/wizzomafizzo/tapto/pkg/utils" + "github.com/ZaparooProject/zaparoo-core/pkg/api/models" + "github.com/ZaparooProject/zaparoo-core/pkg/database/gamesdb" + "github.com/ZaparooProject/zaparoo-core/pkg/readers/optical_drive" + "github.com/ZaparooProject/zaparoo-core/pkg/service/tokens" + "github.com/ZaparooProject/zaparoo-core/pkg/utils" "os" "os/exec" "path/filepath" @@ -20,18 +20,18 @@ import ( "strings" "time" + "github.com/ZaparooProject/zaparoo-core/pkg/config" + "github.com/ZaparooProject/zaparoo-core/pkg/platforms" + "github.com/ZaparooProject/zaparoo-core/pkg/readers" + "github.com/ZaparooProject/zaparoo-core/pkg/readers/file" + "github.com/ZaparooProject/zaparoo-core/pkg/readers/libnfc" + "github.com/ZaparooProject/zaparoo-core/pkg/readers/simple_serial" "github.com/bendahl/uinput" "github.com/rs/zerolog/log" mrextConfig "github.com/wizzomafizzo/mrext/pkg/config" "github.com/wizzomafizzo/mrext/pkg/games" "github.com/wizzomafizzo/mrext/pkg/input" "github.com/wizzomafizzo/mrext/pkg/mister" - "github.com/wizzomafizzo/tapto/pkg/config" - "github.com/wizzomafizzo/tapto/pkg/platforms" - "github.com/wizzomafizzo/tapto/pkg/readers" - "github.com/wizzomafizzo/tapto/pkg/readers/file" - "github.com/wizzomafizzo/tapto/pkg/readers/libnfc" - "github.com/wizzomafizzo/tapto/pkg/readers/simple_serial" ) type Platform struct { diff --git a/pkg/platforms/mister/socket.go b/pkg/platforms/mister/socket.go index 7e1a778d..ccbf700d 100644 --- a/pkg/platforms/mister/socket.go +++ b/pkg/platforms/mister/socket.go @@ -4,12 +4,12 @@ package mister import ( "fmt" - "github.com/wizzomafizzo/tapto/pkg/service/tokens" + "github.com/ZaparooProject/zaparoo-core/pkg/service/tokens" "net" "strings" + "github.com/ZaparooProject/zaparoo-core/pkg/readers" "github.com/rs/zerolog/log" - "github.com/wizzomafizzo/tapto/pkg/readers" ) const ( diff --git a/pkg/platforms/mister/tracker.go b/pkg/platforms/mister/tracker.go index 09c0a39b..d87efb24 100644 --- a/pkg/platforms/mister/tracker.go +++ b/pkg/platforms/mister/tracker.go @@ -7,7 +7,7 @@ package mister import ( "fmt" - "github.com/wizzomafizzo/tapto/pkg/api/models" + "github.com/ZaparooProject/zaparoo-core/pkg/api/models" "os" "path/filepath" "strings" diff --git a/pkg/platforms/mistex/commands.go b/pkg/platforms/mistex/commands.go index 85375517..272607bf 100644 --- a/pkg/platforms/mistex/commands.go +++ b/pkg/platforms/mistex/commands.go @@ -3,8 +3,8 @@ package mistex import ( - "github.com/wizzomafizzo/tapto/pkg/platforms" - "github.com/wizzomafizzo/tapto/pkg/platforms/mister" + "github.com/ZaparooProject/zaparoo-core/pkg/platforms" + "github.com/ZaparooProject/zaparoo-core/pkg/platforms/mister" ) var commandsMappings = map[string]func(platforms.Platform, platforms.CmdEnv) error{ diff --git a/pkg/platforms/mistex/platform.go b/pkg/platforms/mistex/platform.go index b41d1bfc..a094de9d 100644 --- a/pkg/platforms/mistex/platform.go +++ b/pkg/platforms/mistex/platform.go @@ -4,26 +4,26 @@ package mistex import ( "fmt" - "github.com/wizzomafizzo/tapto/pkg/api/models" - "github.com/wizzomafizzo/tapto/pkg/service/tokens" + "github.com/ZaparooProject/zaparoo-core/pkg/api/models" + "github.com/ZaparooProject/zaparoo-core/pkg/service/tokens" "os" "os/exec" "path/filepath" "strconv" "time" + "github.com/ZaparooProject/zaparoo-core/pkg/config" + "github.com/ZaparooProject/zaparoo-core/pkg/platforms" + "github.com/ZaparooProject/zaparoo-core/pkg/platforms/mister" + "github.com/ZaparooProject/zaparoo-core/pkg/readers" + "github.com/ZaparooProject/zaparoo-core/pkg/readers/file" + "github.com/ZaparooProject/zaparoo-core/pkg/readers/libnfc" + "github.com/ZaparooProject/zaparoo-core/pkg/readers/simple_serial" "github.com/bendahl/uinput" mrextConfig "github.com/wizzomafizzo/mrext/pkg/config" "github.com/wizzomafizzo/mrext/pkg/games" "github.com/wizzomafizzo/mrext/pkg/input" mm "github.com/wizzomafizzo/mrext/pkg/mister" - "github.com/wizzomafizzo/tapto/pkg/config" - "github.com/wizzomafizzo/tapto/pkg/platforms" - "github.com/wizzomafizzo/tapto/pkg/platforms/mister" - "github.com/wizzomafizzo/tapto/pkg/readers" - "github.com/wizzomafizzo/tapto/pkg/readers/file" - "github.com/wizzomafizzo/tapto/pkg/readers/libnfc" - "github.com/wizzomafizzo/tapto/pkg/readers/simple_serial" ) type Platform struct { diff --git a/pkg/platforms/platforms.go b/pkg/platforms/platforms.go index ac1a4a3a..5b5e8742 100644 --- a/pkg/platforms/platforms.go +++ b/pkg/platforms/platforms.go @@ -1,11 +1,11 @@ package platforms import ( - "github.com/wizzomafizzo/tapto/pkg/api/models" - "github.com/wizzomafizzo/tapto/pkg/config" - "github.com/wizzomafizzo/tapto/pkg/readers" - "github.com/wizzomafizzo/tapto/pkg/service/playlists" - "github.com/wizzomafizzo/tapto/pkg/service/tokens" + "github.com/ZaparooProject/zaparoo-core/pkg/api/models" + "github.com/ZaparooProject/zaparoo-core/pkg/config" + "github.com/ZaparooProject/zaparoo-core/pkg/readers" + "github.com/ZaparooProject/zaparoo-core/pkg/service/playlists" + "github.com/ZaparooProject/zaparoo-core/pkg/service/tokens" ) type CmdEnv struct { diff --git a/pkg/platforms/steamos/platform.go b/pkg/platforms/steamos/platform.go new file mode 100644 index 00000000..4dc3abe3 --- /dev/null +++ b/pkg/platforms/steamos/platform.go @@ -0,0 +1,213 @@ +/* +Zaparoo Core +Copyright (C) 2024 Callan Barrett + +This file is part of Zaparoo Core. + +Zaparoo Core is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Zaparoo Core is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Zaparoo Core. If not, see . +*/ + +package steamos + +import ( + "errors" + "github.com/ZaparooProject/zaparoo-core/pkg/readers/libnfc" + "github.com/ZaparooProject/zaparoo-core/pkg/readers/optical_drive" + "github.com/ZaparooProject/zaparoo-core/pkg/service/tokens" + "github.com/ZaparooProject/zaparoo-core/pkg/utils" + "github.com/adrg/xdg" + "os/exec" + "path/filepath" + "strings" + + "github.com/ZaparooProject/zaparoo-core/pkg/api/models" + + "github.com/ZaparooProject/zaparoo-core/pkg/config" + "github.com/ZaparooProject/zaparoo-core/pkg/database/gamesdb" + "github.com/ZaparooProject/zaparoo-core/pkg/platforms" + "github.com/ZaparooProject/zaparoo-core/pkg/readers" + "github.com/ZaparooProject/zaparoo-core/pkg/readers/file" + "github.com/ZaparooProject/zaparoo-core/pkg/readers/simple_serial" + "github.com/rs/zerolog/log" +) + +type Platform struct{} + +func (p *Platform) Id() string { + return "steamos" +} + +func (p *Platform) SupportedReaders(cfg *config.UserConfig) []readers.Reader { + return []readers.Reader{ + file.NewReader(cfg), + simple_serial.NewReader(cfg), + libnfc.NewReader(cfg), + optical_drive.NewReader(cfg), + } +} + +func (p *Platform) Setup(_ *config.UserConfig, _ chan<- models.Notification) error { + return nil +} + +func (p *Platform) Stop() error { + return nil +} + +func (p *Platform) AfterScanHook(_ tokens.Token) error { + return nil +} + +func (p *Platform) ReadersUpdateHook(_ map[string]*readers.Reader) error { + return nil +} + +func (p *Platform) RootFolders(_ *config.UserConfig) []string { + return []string{} +} + +func (p *Platform) ZipsAsFolders() bool { + return false +} + +func (p *Platform) ConfigFolder() string { + return filepath.Join(xdg.DataHome, config.AppName) +} + +func (p *Platform) LogFolder() string { + return filepath.Join(xdg.DataHome, config.AppName) +} + +func (p *Platform) NormalizePath(_ *config.UserConfig, path string) string { + return path +} + +func LaunchMenu() error { + return nil +} + +func (p *Platform) KillLauncher() error { + return nil +} + +func (p *Platform) LaunchingEnabled() bool { + return true +} + +func (p *Platform) SetLaunching(_ bool) error { + return nil +} + +func (p *Platform) GetActiveLauncher() string { + // TODO: is this possible? + return "" +} + +func (p *Platform) PlayFailSound(_ *config.UserConfig) { +} + +func (p *Platform) PlaySuccessSound(_ *config.UserConfig) { +} + +func (p *Platform) ActiveSystem() string { + return "" +} + +func (p *Platform) ActiveGame() string { + // TODO: can this go? + return "" +} + +func (p *Platform) ActiveGameName() string { + return "" +} + +func (p *Platform) ActiveGamePath() string { + return "" +} + +func (p *Platform) LaunchSystem(_ *config.UserConfig, _ string) error { + return nil +} + +func (p *Platform) LaunchFile(cfg *config.UserConfig, path string) error { + log.Info().Msgf("launching file: %s", path) + launchers := utils.PathToLaunchers(cfg, p, path) + if len(launchers) == 0 { + return errors.New("no launcher found") + } + return launchers[0].Launch(cfg, path) +} + +func (p *Platform) Shell(cmd string) error { + return exec.Command("bash", "-c", cmd).Start() +} + +func (p *Platform) KeyboardInput(_ string) error { + return nil +} + +func (p *Platform) KeyboardPress(name string) error { + return nil +} + +func (p *Platform) GamepadPress(name string) error { + return nil +} + +func (p *Platform) ForwardCmd(_ platforms.CmdEnv) error { + return nil +} + +func (p *Platform) LookupMapping(_ tokens.Token) (string, bool) { + return "", false +} + +func (p *Platform) Launchers() []platforms.Launcher { + return []platforms.Launcher{ + { + Id: "Steam", + SystemId: gamesdb.SystemPC, + Schemes: []string{"steam"}, + Scanner: func( + cfg *config.UserConfig, + systemId string, + results []platforms.ScanResult, + ) ([]platforms.ScanResult, error) { + root := "/home/deck/.steam/steam/steamapps" + appResults, err := utils.ScanSteamApps(root) + if err != nil { + return nil, err + } + return append(results, appResults...), nil + }, + Launch: func(cfg *config.UserConfig, path string) error { + id := strings.TrimPrefix(path, "steam://") + id = strings.TrimPrefix(id, "rungameid/") + return exec.Command( + "steam", + "steam://rungameid/"+id, + ).Start() + }, + }, + { + Id: "Generic", + Extensions: []string{".sh"}, + AllowListOnly: true, + Launch: func(cfg *config.UserConfig, path string) error { + return exec.Command("bash", "-c", path).Start() + }, + }, + } +} diff --git a/pkg/platforms/windows/platform.go b/pkg/platforms/windows/platform.go index 50ae99bd..7567b88a 100644 --- a/pkg/platforms/windows/platform.go +++ b/pkg/platforms/windows/platform.go @@ -4,25 +4,25 @@ import ( "encoding/xml" "errors" "fmt" - "github.com/wizzomafizzo/tapto/pkg/service/tokens" + "github.com/ZaparooProject/zaparoo-core/pkg/service/tokens" + "github.com/ZaparooProject/zaparoo-core/pkg/utils" "io" "os" "os/exec" "path/filepath" "strings" - "github.com/wizzomafizzo/tapto/pkg/api/models" + "github.com/ZaparooProject/zaparoo-core/pkg/api/models" - "github.com/andygrunwald/vdf" + "github.com/ZaparooProject/zaparoo-core/pkg/config" + "github.com/ZaparooProject/zaparoo-core/pkg/database/gamesdb" + "github.com/ZaparooProject/zaparoo-core/pkg/platforms" + "github.com/ZaparooProject/zaparoo-core/pkg/readers" + "github.com/ZaparooProject/zaparoo-core/pkg/readers/acr122_pcsc" + "github.com/ZaparooProject/zaparoo-core/pkg/readers/file" + "github.com/ZaparooProject/zaparoo-core/pkg/readers/pn532_uart" + "github.com/ZaparooProject/zaparoo-core/pkg/readers/simple_serial" "github.com/rs/zerolog/log" - "github.com/wizzomafizzo/tapto/pkg/config" - "github.com/wizzomafizzo/tapto/pkg/database/gamesdb" - "github.com/wizzomafizzo/tapto/pkg/platforms" - "github.com/wizzomafizzo/tapto/pkg/readers" - "github.com/wizzomafizzo/tapto/pkg/readers/acr122_pcsc" - "github.com/wizzomafizzo/tapto/pkg/readers/file" - "github.com/wizzomafizzo/tapto/pkg/readers/pn532_uart" - "github.com/wizzomafizzo/tapto/pkg/readers/simple_serial" ) type Platform struct { @@ -444,56 +444,11 @@ func (p *Platform) Launchers() []platforms.Launcher { ) ([]platforms.ScanResult, error) { // TODO: detect this path from registry root := "C:\\Program Files (x86)\\Steam\\steamapps" - - f, err := os.Open(filepath.Join(root, "libraryfolders.vdf")) - if err != nil { - log.Error().Err(err).Msg("error opening libraryfolders.vdf") - return results, nil - } - - p := vdf.NewParser(f) - m, err := p.Parse() + appResults, err := utils.ScanSteamApps(root) if err != nil { - log.Error().Err(err).Msg("error parsing libraryfolders.vdf") - return results, nil + return nil, err } - - lfs := m["libraryfolders"].(map[string]interface{}) - for l, v := range lfs { - log.Debug().Msgf("library id: %s", l) - ls := v.(map[string]interface{}) - - libraryPath := ls["path"].(string) - apps := ls["apps"].(map[string]interface{}) - - for id := range apps { - log.Debug().Msgf("app id: %s", id) - - manifestPath := filepath.Join(libraryPath, "steamapps", "appmanifest_"+id+".acf") - af, err := os.Open(manifestPath) - if err != nil { - log.Error().Err(err).Msgf("error opening manifest: %s", manifestPath) - return results, nil - } - - ap := vdf.NewParser(af) - am, err := ap.Parse() - if err != nil { - log.Error().Err(err).Msgf("error parsing manifest: %s", manifestPath) - return results, nil - } - - appState := am["AppState"].(map[string]interface{}) - log.Debug().Msgf("app name: %v", appState["name"]) - - results = append(results, platforms.ScanResult{ - Path: "steam://" + id, - Name: appState["name"].(string), - }) - } - } - - return results, nil + return append(results, appResults...), nil }, Launch: func(cfg *config.UserConfig, path string) error { id := strings.TrimPrefix(path, "steam://") diff --git a/pkg/readers/acr122_pcsc/acr122_pcsc.go b/pkg/readers/acr122_pcsc/acr122_pcsc.go index 9c04df1b..266a7abd 100644 --- a/pkg/readers/acr122_pcsc/acr122_pcsc.go +++ b/pkg/readers/acr122_pcsc/acr122_pcsc.go @@ -4,15 +4,15 @@ import ( "bytes" "encoding/hex" "errors" - "github.com/wizzomafizzo/tapto/pkg/service/tokens" + "github.com/ZaparooProject/zaparoo-core/pkg/service/tokens" "strings" "time" + "github.com/ZaparooProject/zaparoo-core/pkg/config" + "github.com/ZaparooProject/zaparoo-core/pkg/readers" + "github.com/ZaparooProject/zaparoo-core/pkg/utils" "github.com/ebfe/scard" "github.com/rs/zerolog/log" - "github.com/wizzomafizzo/tapto/pkg/config" - "github.com/wizzomafizzo/tapto/pkg/readers" - "github.com/wizzomafizzo/tapto/pkg/utils" ) type Acr122Pcsc struct { diff --git a/pkg/readers/file/file.go b/pkg/readers/file/file.go index 99660189..4c16f2d6 100644 --- a/pkg/readers/file/file.go +++ b/pkg/readers/file/file.go @@ -3,16 +3,16 @@ package file import ( "encoding/hex" "errors" - "github.com/wizzomafizzo/tapto/pkg/service/tokens" + "github.com/ZaparooProject/zaparoo-core/pkg/service/tokens" "os" "path/filepath" "strings" "time" + "github.com/ZaparooProject/zaparoo-core/pkg/config" + "github.com/ZaparooProject/zaparoo-core/pkg/readers" + "github.com/ZaparooProject/zaparoo-core/pkg/utils" "github.com/rs/zerolog/log" - "github.com/wizzomafizzo/tapto/pkg/config" - "github.com/wizzomafizzo/tapto/pkg/readers" - "github.com/wizzomafizzo/tapto/pkg/utils" ) const TokenType = "file" diff --git a/pkg/readers/libnfc/libnfc.go b/pkg/readers/libnfc/libnfc.go index bdab9593..0abbbcfe 100644 --- a/pkg/readers/libnfc/libnfc.go +++ b/pkg/readers/libnfc/libnfc.go @@ -6,19 +6,19 @@ import ( "encoding/hex" "errors" "fmt" - "github.com/wizzomafizzo/tapto/pkg/service/tokens" + "github.com/ZaparooProject/zaparoo-core/pkg/service/tokens" "os" "path/filepath" "strings" "sync" "time" + "github.com/ZaparooProject/zaparoo-core/pkg/config" + "github.com/ZaparooProject/zaparoo-core/pkg/readers" + "github.com/ZaparooProject/zaparoo-core/pkg/readers/libnfc/tags" + "github.com/ZaparooProject/zaparoo-core/pkg/utils" "github.com/clausecker/nfc/v2" "github.com/rs/zerolog/log" - "github.com/wizzomafizzo/tapto/pkg/config" - "github.com/wizzomafizzo/tapto/pkg/readers" - "github.com/wizzomafizzo/tapto/pkg/readers/libnfc/tags" - "github.com/wizzomafizzo/tapto/pkg/utils" ) const ( diff --git a/pkg/readers/libnfc/tags/mifare.go b/pkg/readers/libnfc/tags/mifare.go index a43659dd..c021d1a7 100644 --- a/pkg/readers/libnfc/tags/mifare.go +++ b/pkg/readers/libnfc/tags/mifare.go @@ -27,8 +27,8 @@ import ( "encoding/hex" "errors" "fmt" + "github.com/ZaparooProject/zaparoo-core/pkg/service/tokens" "github.com/rs/zerolog/log" - "github.com/wizzomafizzo/tapto/pkg/service/tokens" "github.com/clausecker/nfc/v2" "golang.org/x/exp/slices" diff --git a/pkg/readers/libnfc/tags/ntag.go b/pkg/readers/libnfc/tags/ntag.go index ede7968d..1f2ae6de 100644 --- a/pkg/readers/libnfc/tags/ntag.go +++ b/pkg/readers/libnfc/tags/ntag.go @@ -27,7 +27,7 @@ import ( "encoding/hex" "errors" "fmt" - "github.com/wizzomafizzo/tapto/pkg/service/tokens" + "github.com/ZaparooProject/zaparoo-core/pkg/service/tokens" "github.com/clausecker/nfc/v2" "github.com/rs/zerolog/log" diff --git a/pkg/readers/libnfc/tags/tags.go b/pkg/readers/libnfc/tags/tags.go index f9c9390d..ffeca9f3 100644 --- a/pkg/readers/libnfc/tags/tags.go +++ b/pkg/readers/libnfc/tags/tags.go @@ -26,7 +26,7 @@ package tags import ( "encoding/hex" "fmt" - "github.com/wizzomafizzo/tapto/pkg/service/tokens" + "github.com/ZaparooProject/zaparoo-core/pkg/service/tokens" "github.com/clausecker/nfc/v2" ) diff --git a/pkg/readers/optical_drive/optical_drive.go b/pkg/readers/optical_drive/optical_drive.go index c6387d3c..341c57f7 100644 --- a/pkg/readers/optical_drive/optical_drive.go +++ b/pkg/readers/optical_drive/optical_drive.go @@ -2,11 +2,11 @@ package optical_drive import ( "errors" + "github.com/ZaparooProject/zaparoo-core/pkg/config" + "github.com/ZaparooProject/zaparoo-core/pkg/readers" + "github.com/ZaparooProject/zaparoo-core/pkg/service/tokens" + "github.com/ZaparooProject/zaparoo-core/pkg/utils" "github.com/rs/zerolog/log" - "github.com/wizzomafizzo/tapto/pkg/config" - "github.com/wizzomafizzo/tapto/pkg/readers" - "github.com/wizzomafizzo/tapto/pkg/service/tokens" - "github.com/wizzomafizzo/tapto/pkg/utils" "os" "os/exec" "path/filepath" diff --git a/pkg/readers/pn532_uart/pn532.go b/pkg/readers/pn532_uart/pn532.go index 420258f0..f849c2d1 100644 --- a/pkg/readers/pn532_uart/pn532.go +++ b/pkg/readers/pn532_uart/pn532.go @@ -4,7 +4,7 @@ import ( "bytes" "errors" "fmt" - "github.com/wizzomafizzo/tapto/pkg/service/tokens" + "github.com/ZaparooProject/zaparoo-core/pkg/service/tokens" "time" "github.com/rs/zerolog/log" diff --git a/pkg/readers/pn532_uart/pn532_uart.go b/pkg/readers/pn532_uart/pn532_uart.go index c41b9726..82b49c5e 100644 --- a/pkg/readers/pn532_uart/pn532_uart.go +++ b/pkg/readers/pn532_uart/pn532_uart.go @@ -4,7 +4,7 @@ import ( "bytes" "encoding/hex" "errors" - "github.com/wizzomafizzo/tapto/pkg/service/tokens" + "github.com/ZaparooProject/zaparoo-core/pkg/service/tokens" "os" "path/filepath" "runtime" @@ -12,10 +12,10 @@ import ( "sync" "time" + "github.com/ZaparooProject/zaparoo-core/pkg/config" + "github.com/ZaparooProject/zaparoo-core/pkg/readers" + "github.com/ZaparooProject/zaparoo-core/pkg/utils" "github.com/rs/zerolog/log" - "github.com/wizzomafizzo/tapto/pkg/config" - "github.com/wizzomafizzo/tapto/pkg/readers" - "github.com/wizzomafizzo/tapto/pkg/utils" "go.bug.st/serial" ) diff --git a/pkg/readers/readers.go b/pkg/readers/readers.go index d57bb440..07f3b996 100644 --- a/pkg/readers/readers.go +++ b/pkg/readers/readers.go @@ -1,7 +1,7 @@ package readers import ( - "github.com/wizzomafizzo/tapto/pkg/service/tokens" + "github.com/ZaparooProject/zaparoo-core/pkg/service/tokens" ) type Scan struct { diff --git a/pkg/readers/simple_serial/simple_serial.go b/pkg/readers/simple_serial/simple_serial.go index 1bd802f1..12fe324f 100644 --- a/pkg/readers/simple_serial/simple_serial.go +++ b/pkg/readers/simple_serial/simple_serial.go @@ -2,16 +2,16 @@ package simple_serial import ( "errors" - "github.com/wizzomafizzo/tapto/pkg/service/tokens" + "github.com/ZaparooProject/zaparoo-core/pkg/service/tokens" "os" "runtime" "strings" "time" + "github.com/ZaparooProject/zaparoo-core/pkg/config" + "github.com/ZaparooProject/zaparoo-core/pkg/readers" + "github.com/ZaparooProject/zaparoo-core/pkg/utils" "github.com/rs/zerolog/log" - "github.com/wizzomafizzo/tapto/pkg/config" - "github.com/wizzomafizzo/tapto/pkg/readers" - "github.com/wizzomafizzo/tapto/pkg/utils" "go.bug.st/serial" ) diff --git a/pkg/service/mappings.go b/pkg/service/mappings.go index 8eca39f2..63575c86 100644 --- a/pkg/service/mappings.go +++ b/pkg/service/mappings.go @@ -22,13 +22,13 @@ along with TapTo. If not, see . package service import ( - "github.com/wizzomafizzo/tapto/pkg/service/tokens" + "github.com/ZaparooProject/zaparoo-core/pkg/service/tokens" "regexp" "strings" + "github.com/ZaparooProject/zaparoo-core/pkg/database" + "github.com/ZaparooProject/zaparoo-core/pkg/platforms" "github.com/rs/zerolog/log" - "github.com/wizzomafizzo/tapto/pkg/database" - "github.com/wizzomafizzo/tapto/pkg/platforms" ) func checkMappingUid(m database.Mapping, t tokens.Token) bool { diff --git a/pkg/service/readers.go b/pkg/service/readers.go index 3b994535..0a9fcf8e 100644 --- a/pkg/service/readers.go +++ b/pkg/service/readers.go @@ -2,16 +2,16 @@ package service import ( "errors" - "github.com/wizzomafizzo/tapto/pkg/service/tokens" + "github.com/ZaparooProject/zaparoo-core/pkg/service/tokens" "strings" "time" + "github.com/ZaparooProject/zaparoo-core/pkg/config" + "github.com/ZaparooProject/zaparoo-core/pkg/platforms" + "github.com/ZaparooProject/zaparoo-core/pkg/readers" + "github.com/ZaparooProject/zaparoo-core/pkg/service/state" + "github.com/ZaparooProject/zaparoo-core/pkg/utils" "github.com/rs/zerolog/log" - "github.com/wizzomafizzo/tapto/pkg/config" - "github.com/wizzomafizzo/tapto/pkg/platforms" - "github.com/wizzomafizzo/tapto/pkg/readers" - "github.com/wizzomafizzo/tapto/pkg/service/state" - "github.com/wizzomafizzo/tapto/pkg/utils" ) func shouldExit( diff --git a/pkg/service/service.go b/pkg/service/service.go index 3a039c17..07248794 100644 --- a/pkg/service/service.go +++ b/pkg/service/service.go @@ -23,20 +23,20 @@ package service import ( "fmt" - "github.com/wizzomafizzo/tapto/pkg/api" - "github.com/wizzomafizzo/tapto/pkg/service/playlists" - "github.com/wizzomafizzo/tapto/pkg/service/tokens" + "github.com/ZaparooProject/zaparoo-core/pkg/api" + "github.com/ZaparooProject/zaparoo-core/pkg/service/playlists" + "github.com/ZaparooProject/zaparoo-core/pkg/service/tokens" "strings" "time" "golang.org/x/exp/slices" + "github.com/ZaparooProject/zaparoo-core/pkg/config" + "github.com/ZaparooProject/zaparoo-core/pkg/database" + "github.com/ZaparooProject/zaparoo-core/pkg/launcher" + "github.com/ZaparooProject/zaparoo-core/pkg/platforms" + "github.com/ZaparooProject/zaparoo-core/pkg/service/state" "github.com/rs/zerolog/log" - "github.com/wizzomafizzo/tapto/pkg/config" - "github.com/wizzomafizzo/tapto/pkg/database" - "github.com/wizzomafizzo/tapto/pkg/launcher" - "github.com/wizzomafizzo/tapto/pkg/platforms" - "github.com/wizzomafizzo/tapto/pkg/service/state" ) func inExitGameBlocklist(platform platforms.Platform, cfg *config.UserConfig) bool { diff --git a/pkg/service/state/state.go b/pkg/service/state/state.go index 3b10f5e0..14eb6422 100644 --- a/pkg/service/state/state.go +++ b/pkg/service/state/state.go @@ -1,14 +1,14 @@ package state import ( - "github.com/wizzomafizzo/tapto/pkg/api/models" - "github.com/wizzomafizzo/tapto/pkg/service/tokens" + "github.com/ZaparooProject/zaparoo-core/pkg/api/models" + "github.com/ZaparooProject/zaparoo-core/pkg/service/tokens" "sync" + "github.com/ZaparooProject/zaparoo-core/pkg/platforms" + "github.com/ZaparooProject/zaparoo-core/pkg/readers" + "github.com/ZaparooProject/zaparoo-core/pkg/utils" "github.com/rs/zerolog/log" - "github.com/wizzomafizzo/tapto/pkg/platforms" - "github.com/wizzomafizzo/tapto/pkg/readers" - "github.com/wizzomafizzo/tapto/pkg/utils" ) type State struct { diff --git a/pkg/utils/logging.go b/pkg/utils/logging.go index d732d07f..28325744 100644 --- a/pkg/utils/logging.go +++ b/pkg/utils/logging.go @@ -5,10 +5,10 @@ import ( "os" "path/filepath" + "github.com/ZaparooProject/zaparoo-core/pkg/config" + "github.com/ZaparooProject/zaparoo-core/pkg/platforms" "github.com/rs/zerolog" "github.com/rs/zerolog/log" - "github.com/wizzomafizzo/tapto/pkg/config" - "github.com/wizzomafizzo/tapto/pkg/platforms" "gopkg.in/natefinch/lumberjack.v2" ) @@ -27,7 +27,8 @@ func InitLogging(cfg *config.UserConfig, pl platforms.Platform) error { }} if cfg.TapTo.ConsoleLogging { - BaseLogWriters = append(BaseLogWriters, zerolog.ConsoleWriter{Out: os.Stderr}) + // BaseLogWriters = append(BaseLogWriters, zerolog.ConsoleWriter{Out: os.Stderr}) + BaseLogWriters = append(BaseLogWriters, os.Stderr) } zerolog.TimeFieldFormat = zerolog.TimeFormatUnix diff --git a/pkg/utils/paths.go b/pkg/utils/paths.go index 6a775831..bce214ab 100644 --- a/pkg/utils/paths.go +++ b/pkg/utils/paths.go @@ -1,8 +1,11 @@ package utils import ( - "github.com/wizzomafizzo/tapto/pkg/config" - "github.com/wizzomafizzo/tapto/pkg/platforms" + "github.com/ZaparooProject/zaparoo-core/pkg/config" + "github.com/ZaparooProject/zaparoo-core/pkg/platforms" + "github.com/andygrunwald/vdf" + "github.com/rs/zerolog/log" + "os" "path/filepath" "strings" ) @@ -93,3 +96,76 @@ func PathToLaunchers( } return launchers } + +func ExeDir() string { + exe, err := os.Executable() + if err != nil { + return "" + } + + return filepath.Dir(exe) +} + +func ScanSteamApps(steamDir string) ([]platforms.ScanResult, error) { + var results []platforms.ScanResult + + f, err := os.Open(filepath.Join(steamDir, "libraryfolders.vdf")) + if err != nil { + log.Error().Err(err).Msg("error opening libraryfolders.vdf") + return results, nil + } + + p := vdf.NewParser(f) + m, err := p.Parse() + if err != nil { + log.Error().Err(err).Msg("error parsing libraryfolders.vdf") + return results, nil + } + + lfs := m["libraryfolders"].(map[string]interface{}) + for l, v := range lfs { + log.Debug().Msgf("library id: %s", l) + ls := v.(map[string]interface{}) + + libraryPath := ls["path"].(string) + steamApps, err := os.ReadDir(filepath.Join(libraryPath, "steamapps")) + if err != nil { + log.Error().Err(err).Msg("error listing steamapps folder") + continue + } + + var manifestFiles []string + for _, mf := range steamApps { + if strings.HasPrefix(mf.Name(), "appmanifest_") { + manifestFiles = append(manifestFiles, filepath.Join(libraryPath, "steamapps", mf.Name())) + } + } + + for _, mf := range manifestFiles { + log.Debug().Msgf("manifest file: %s", mf) + + af, err := os.Open(mf) + if err != nil { + log.Error().Err(err).Msgf("error opening manifest: %s", mf) + return results, nil + } + + ap := vdf.NewParser(af) + am, err := ap.Parse() + if err != nil { + log.Error().Err(err).Msgf("error parsing manifest: %s", mf) + return results, nil + } + + appState := am["AppState"].(map[string]interface{}) + log.Debug().Msgf("app name: %v", appState["name"]) + + results = append(results, platforms.ScanResult{ + Path: "steam://" + appState["appid"].(string), + Name: appState["name"].(string), + }) + } + } + + return results, nil +} diff --git a/pkg/platforms/mister/service.go b/pkg/utils/service.go similarity index 71% rename from pkg/platforms/mister/service.go rename to pkg/utils/service.go index 7aeeae67..6711c17d 100644 --- a/pkg/platforms/mister/service.go +++ b/pkg/utils/service.go @@ -1,9 +1,10 @@ //go:build linux || darwin -package mister +package utils import ( "fmt" + "github.com/ZaparooProject/zaparoo-core/pkg/platforms" "io" "os" "os/exec" @@ -14,36 +15,38 @@ import ( "syscall" "time" + "github.com/ZaparooProject/zaparoo-core/pkg/config" "github.com/rs/zerolog/log" - "github.com/wizzomafizzo/tapto/pkg/config" ) type ServiceEntry func() (func() error, error) type Service struct { - Name string daemon bool start ServiceEntry stop func() error + pl platforms.Platform } type ServiceArgs struct { Entry ServiceEntry NoDaemon bool + Platform platforms.Platform } func NewService(args ServiceArgs) (*Service, error) { return &Service{ - Name: config.AppName, daemon: !args.NoDaemon, start: args.Entry, + pl: args.Platform, }, nil } // Create new PID file using current process PID. func (s *Service) createPidFile() error { + path := filepath.Join(config.TempDir(), config.PidFilename) pid := os.Getpid() - err := os.WriteFile(PidFile, []byte(fmt.Sprintf("%d", pid)), 0644) + err := os.WriteFile(path, []byte(fmt.Sprintf("%d", pid)), 0644) if err != nil { return err } @@ -51,19 +54,20 @@ func (s *Service) createPidFile() error { } func (s *Service) removePidFile() error { - err := os.Remove(PidFile) + err := os.Remove(filepath.Join(config.TempDir(), config.PidFilename)) if err != nil { return err } return nil } -// Return the process ID of the current running service daemon. +// Pid returns the process ID of the current running service daemon. func (s *Service) Pid() (int, error) { pid := 0 + path := filepath.Join(config.TempDir(), config.PidFilename) - if _, err := os.Stat(PidFile); err == nil { - pidFile, err := os.ReadFile(PidFile) + if _, err := os.Stat(path); err == nil { + pidFile, err := os.ReadFile(path) if err != nil { return pid, fmt.Errorf("error reading pid file: %w", err) } @@ -79,7 +83,7 @@ func (s *Service) Pid() (int, error) { return pid, nil } -// Returns true if the service is running. +// Running returns true if the service is running. func (s *Service) Running() bool { pid, err := s.Pid() if err != nil { @@ -101,35 +105,36 @@ func (s *Service) Running() bool { } func (s *Service) stopService() error { - log.Info().Msgf("stopping %s service", s.Name) + log.Info().Msgf("stopping service") err := s.stop() if err != nil { - log.Error().Msgf("error stopping %s service: %s", s.Name, err) + log.Error().Err(err).Msg("error stopping service") return err } err = s.removePidFile() if err != nil { - log.Error().Msgf("error removing pid file: %s", err) + log.Error().Err(err).Msgf("error removing pid file") return err } // remove temporary binary tempPath, err := os.Executable() if err != nil { - log.Error().Msgf("error getting executable path: %s", err) - } else if strings.HasPrefix(tempPath, TempFolder) { + log.Error().Err(err).Msg("error getting executable path") + } else if strings.HasPrefix(tempPath, config.TempDir()) { err = os.Remove(tempPath) if err != nil { - log.Error().Msgf("error removing temporary binary: %s", err) + log.Error().Err(err).Msg("error removing temporary binary") } } return nil } -// Set up signal handler to stop service on SIGINT or SIGTERM. Exits the application on signal. +// Set up signal handler to stop service on SIGINT or SIGTERM. +// Exits the application on signal. func (s *Service) setupStopService() { sigs := make(chan os.Signal, 1) signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM) @@ -149,30 +154,30 @@ func (s *Service) setupStopService() { // Starts the service and blocks until the service is stopped. func (s *Service) startService() { if s.Running() { - log.Error().Msgf("%s service already running", s.Name) + log.Error().Msg("service already running") os.Exit(1) } - log.Info().Msgf("starting %s service", s.Name) + log.Info().Msg("starting service") err := s.createPidFile() if err != nil { - log.Error().Msgf("error creating pid file: %s", err) + log.Error().Err(err).Msg("error creating pid file") os.Exit(1) } err = syscall.Setpriority(syscall.PRIO_PROCESS, 0, 1) if err != nil { - log.Error().Msgf("error setting nice level: %s", err) + log.Error().Err(err).Msg("error setting nice level") } stop, err := s.start() if err != nil { - log.Error().Msgf("error starting service: %s", err) + log.Error().Err(err).Msg("error starting service") err = s.removePidFile() if err != nil { - log.Error().Msgf("error removing pid file: %s", err) + log.Error().Err(err).Msg("error removing pid file") } os.Exit(1) @@ -196,7 +201,7 @@ func (s *Service) startService() { // Start a new service daemon in the background. func (s *Service) Start() error { if s.Running() { - return fmt.Errorf("%s service already running", s.Name) + return fmt.Errorf("service already running") } // create a copy in binary in tmp so the original can be updated @@ -217,7 +222,7 @@ func (s *Service) Start() error { return fmt.Errorf("error opening binary: %w", err) } - tempPath := filepath.Join(TempFolder, filepath.Base(binPath)) + tempPath := filepath.Join(config.TempDir(), filepath.Base(binPath)) tempFile, err := os.OpenFile(tempPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0755) if err != nil { return fmt.Errorf("error creating temp binary: %w", err) @@ -228,15 +233,21 @@ func (s *Service) Start() error { return fmt.Errorf("error copying binary to temp: %w", err) } - tempFile.Close() - binFile.Close() + err = tempFile.Close() + if err != nil { + return err + } + err = binFile.Close() + if err != nil { + return err + } cmd := exec.Command(tempPath, "-service", "exec", "&") env := os.Environ() cmd.Env = env // point new binary to existing config file - configPath := filepath.Join(filepath.Dir(binPath), s.Name+".ini") + configPath := filepath.Join(filepath.Dir(binPath), config.UserConfigFilename) if _, err := os.Stat(configPath); err == nil { cmd.Env = append(cmd.Env, fmt.Sprintf("%s=%s", config.UserConfigEnv, configPath)) @@ -245,7 +256,7 @@ func (s *Service) Start() error { err = cmd.Start() if err != nil { - return fmt.Errorf("error starting %s service: %w", s.Name, err) + return fmt.Errorf("error starting service: %w", err) } return nil @@ -254,7 +265,7 @@ func (s *Service) Start() error { // Stop the service daemon. func (s *Service) Stop() error { if !s.Running() { - return fmt.Errorf("%s service not running", s.Name) + return fmt.Errorf("service not running") } pid, err := s.Pid() @@ -325,14 +336,12 @@ func (s *Service) ServiceHandler(cmd *string) { os.Exit(0) } else if *cmd == "status" { if s.Running() { - fmt.Printf("%s service running\n", s.Name) + os.Exit(0) } else { - fmt.Printf("%s service not running\n", s.Name) + os.Exit(1) } - - os.Exit(0) } else if *cmd != "" { - fmt.Printf("Invalid service command: %s", *cmd) + fmt.Printf("Unknown service argument: %s", *cmd) os.Exit(1) } } diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index baf332a2..12860e0d 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -24,8 +24,8 @@ import ( "archive/zip" "crypto/md5" "fmt" + "github.com/ZaparooProject/zaparoo-core/pkg/service/tokens" "github.com/rs/zerolog/log" - "github.com/wizzomafizzo/tapto/pkg/service/tokens" "io" "math/rand" "net"