Documentation
¶
Overview ¶
Package playnite integrates the Playnite game library manager. Playnite keeps its library in LiteDB files it holds open exclusively, and only code running inside it sees a game start or stop, so everything except launching goes through the Zaparoo extension: it connects to a pipe Core serves and exchanges newline-delimited JSON. Everything except the Win32 bindings is free of build tags so the behaviour can be tested on any platform.
Index ¶
- Constants
- Variables
- func DefaultInstallDirs(localAppData string) []string
- func GamePath(gameID, name string) string
- func HasSystem(systemID string) bool
- func IndexedSystem(game *Game, skipSteam bool) (string, bool)
- func NewLauncher(i *Integration) platforms.Launcher
- func NormalizeGameID(id string) (string, error)
- func ParseGamePath(path string) (string, error)
- func ScanResults(games []Game, systemID string, skipSteam bool) []platforms.ScanResult
- func SystemForGame(game *Game) (string, bool)
- func Systems() []string
- type Command
- type Deps
- type Event
- type Frontend
- type Game
- type Handlers
- type Install
- type Integration
- func (i *Integration) Available(cfg *config.Instance) error
- func (i *Integration) Connected() bool
- func (i *Integration) GameRunning() bool
- func (i *Integration) Launch(cfg *config.Instance, path string) error
- func (i *Integration) LibraryDetails(ctx context.Context) ([]Game, error)
- func (i *Integration) Locate(cfg *config.Instance) (Install, error)
- func (i *Integration) Preflight(path string) error
- func (i *Integration) Scan(ctx context.Context, cfg *config.Instance, systemID string) ([]platforms.ScanResult, error)
- func (i *Integration) Serve(cfg *config.Instance, listener net.Listener)
- func (i *Integration) Stop()
- func (i *Integration) StopGame() error
- type Locator
- type Platform
- type Server
- func (s *Server) Check(ctx context.Context, gameID string, timeout time.Duration) error
- func (s *Server) Close()
- func (s *Server) Connected() bool
- func (s *Server) Games(ctx context.Context, details bool, timeout time.Duration) ([]Game, error)
- func (s *Server) Hello() Event
- func (s *Server) Launch(ctx context.Context, gameID string, timeout time.Duration) error
- func (s *Server) Serve(listener net.Listener)
- func (s *Server) Session() uint64
- func (s *Server) StopGame(ctx context.Context, gameID string, timeout time.Duration) error
- type Timeouts
Constants ¶
const ( EventHello = "Hello" EventGames = "Games" EventLaunchResult = "LaunchResult" EventCheckResult = "CheckResult" EventMediaStarted = "MediaStarted" EventMediaStopped = "MediaStopped" EventMediaStopResult = "MediaStopResult" EventWrite = "Write" EventError = "Error" )
Event names sent by the extension.
const ( CommandPing = "Ping" CommandGetGames = "GetGames" CommandLaunch = "Launch" CommandCheck = "Check" CommandStop = "Stop" )
Command names sent to the extension.
const ( StatusCompleted = "completed" StatusFailed = "failed" StatusUnsupported = "unsupported" )
Result statuses reported by the extension.
const LauncherID = "Playnite"
LauncherID identifies the Playnite launcher to users and in ActiveMedia.
const MaxLineSize = 8 * 1024 * 1024
MaxLineSize bounds one message from the extension. A games chunk carrying descriptions is the largest message; the extension sends libraries in chunks so a line stays well inside this.
const PipeName = `\\.\pipe\zaparoo-playnite-ipc`
PipeName is the named pipe Core serves for the extension.
const ProtocolVersion = 1
ProtocolVersion is the wire protocol this build of Core speaks. The extension reports its own in Hello.
const SteamLibraryPluginID = "cb91dfc9-b977-43bf-8e70-55f46e410fab"
SteamLibraryPluginID is the library plugin Playnite imports Steam games with. Core indexes Steam itself, so those games are left to that launcher.
Variables ¶
var ( // ErrNotConnected is returned when the extension has no open connection. ErrNotConnected = errors.New("the Playnite extension is not connected") // ErrStopUnsupported is returned when the extension cannot stop the game // because Playnite never told it which process the game is. ErrStopUnsupported = errors.New("no process reported by Playnite to stop") // ErrGameRejected is returned by Check when Playnite answered that it // cannot launch the game. ErrGameRejected = errors.New("game rejected by Playnite") )
var ErrNoActiveGame = errors.New("no active Playnite game")
ErrNoActiveGame is returned by StopGame when Core is not tracking a running Playnite game.
var ErrNotInstalled = errors.New("no Playnite install found")
ErrNotInstalled is returned when no Playnite folder can be found.
Functions ¶
func DefaultInstallDirs ¶
DefaultInstallDirs lists where Playnite's installer puts it for a user whose local application data folder is localAppData.
func GamePath ¶
GamePath builds the virtual path indexed for a game and written to tokens. The ID is Playnite's own database ID and survives renames; the name is cosmetic.
func IndexedSystem ¶
IndexedSystem returns the system a game is indexed under, or false when Core leaves the game out: hidden and uninstalled entries cannot be played, a game on an unknown platform has no system, and a Steam game is already indexed by the Steam launcher when skipSteam is set.
func NewLauncher ¶
func NewLauncher(i *Integration) platforms.Launcher
NewLauncher builds the Playnite launcher around an integration. It has no system of its own: Playnite holds games for many systems, so the scanner runs for each and returns the games Playnite files under it. The lifecycle is external: Playnite starts and owns the game, and the integration publishes ActiveMedia when the extension reports it running.
func NormalizeGameID ¶
NormalizeGameID validates a game ID and returns its canonical form. Only the hyphenated form is accepted: the ID goes onto Playnite's command line.
func ParseGamePath ¶
ParseGamePath extracts the Playnite game ID from a playnite:// virtual path, in the lowercase hyphenated form Playnite prints.
func ScanResults ¶
func ScanResults(games []Game, systemID string, skipSteam bool) []platforms.ScanResult
ScanResults converts the games that belong to systemID into indexable media. Every game becomes a playnite:// virtual path keyed by its ID.
func SystemForGame ¶
SystemForGame returns the Zaparoo system a game belongs to. A game with no platform at all is a PC game: that is how Playnite leaves a manually added program. Otherwise the first platform with a known specification decides, and a game whose platforms are all unknown has no system.
Types ¶
type Command ¶
type Command struct {
Command string `json:"Command"`
ID string `json:"Id,omitempty"`
RequestID string `json:"RequestId,omitempty"`
Details bool `json:"Details,omitempty"`
}
Command is a message from Core to the extension.
type Deps ¶
type Deps struct {
ActiveMedia func() *models.ActiveMedia
SetActiveMedia func(*models.ActiveMedia)
// TrackProcess hands the platform the process Playnite started for the
// running game, so the platform can end its tree if the extension cannot.
// exe is the process image the extension saw, for the platform to check
// the PID still names that program.
TrackProcess func(pid int, exe string)
// UntrackProcess tells the platform the game's process has gone.
UntrackProcess func(pid int)
// WriteTag asks Core to write a game's path to a token.
WriteTag func(cfg *config.Instance, path string)
// SteamIndexed reports whether Core indexes Steam games itself.
SteamIndexed func(cfg *config.Instance) bool
Frontend Frontend
Clock clockwork.Clock
Locator Locator
Timeouts Timeouts
}
Deps are the platform hooks and external boundaries the integration uses. Every boundary is an interface or function so tests can script Playnite and the clock.
type Event ¶
type Event struct {
// Game describes the game a MediaStarted event is for.
Game *Game `json:"Game,omitempty"`
// Event names the message.
Event string `json:"Event"`
// ID is the game a lifecycle or result event concerns.
ID string `json:"Id,omitempty"`
// Name is the game's name on a Write event.
Name string `json:"Name,omitempty"`
// RequestID echoes the GetGames request a Games chunk answers.
RequestID string `json:"RequestId,omitempty"`
// Status is the outcome on LaunchResult and MediaStopResult.
Status string `json:"Status,omitempty"`
// Error explains a failed result, a failed games request or an Error.
Error string `json:"Error,omitempty"`
// Command names the command an Error event rejects.
Command string `json:"Command,omitempty"`
// Exe is the image path of the started process, when Pid is set.
Exe string `json:"Exe,omitempty"`
// PluginVersion, PlayniteVersion and Mode describe the extension in Hello.
PluginVersion string `json:"PluginVersion,omitempty"`
PlayniteVersion string `json:"PlayniteVersion,omitempty"`
Mode string `json:"Mode,omitempty"`
// Games is one chunk of the library on a Games event.
Games []Game `json:"Games,omitempty"`
// ProtocolVersion is the extension's wire protocol, in Hello.
ProtocolVersion int `json:"ProtocolVersion,omitempty"`
// Pid is the process Playnite started for the game; zero when Playnite
// did not report one.
Pid int `json:"Pid,omitempty"`
// Session numbers one run of a game inside the extension. MediaStarted
// and the MediaStopped that ends the same run carry the same value.
Session int `json:"Session,omitempty"`
// Final marks the last Games chunk of a request.
Final bool `json:"Final,omitempty"`
}
Event is a message from the extension. One struct carries every event's fields; which are set depends on Event.
func ParseEvent ¶
ParseEvent decodes one line from the extension. The line is untrusted: anything that is not a JSON object naming an event is rejected.
type Frontend ¶
type Frontend interface {
// StartGame runs Playnite with its --start argument. A running Playnite
// receives the request from the new process, which then exits; otherwise
// Playnite starts and launches the game once it has loaded.
StartGame(ctx context.Context, inst *Install, gameID string) error
}
Frontend starts Playnite. It is an interface so tests can observe the command without running anything.
type Game ¶
type Game struct {
ID string `json:"Id"`
Name string `json:"Name"`
LibraryPluginID string `json:"LibraryPluginId,omitempty"`
RomPath string `json:"RomPath,omitempty"`
Description string `json:"Description,omitempty"`
Cover string `json:"Cover,omitempty"`
Background string `json:"Background,omitempty"`
Icon string `json:"Icon,omitempty"`
Platforms []Platform `json:"Platforms,omitempty"`
Developers []string `json:"Developers,omitempty"`
Publishers []string `json:"Publishers,omitempty"`
Genres []string `json:"Genres,omitempty"`
ReleaseYear int `json:"ReleaseYear,omitempty"`
IsInstalled bool `json:"IsInstalled,omitempty"`
Hidden bool `json:"Hidden,omitempty"`
}
Game is one Playnite library entry as the extension reports it. The metadata and image fields are only filled when details were requested. Image fields are absolute paths to files in Playnite's library folder.
type Handlers ¶
type Handlers struct {
Started func(event *Event)
Stopped func(event *Event)
Write func(id, name string)
Disconnected func()
}
Handlers receive the extension's unsolicited events. They run on the connection's reader, so they must not wait on another message from it.
type Install ¶
Install is a located Playnite folder. FullscreenExe is empty when the install does not ship Fullscreen mode.
type Integration ¶
type Integration struct {
// contains filtered or unexported fields
}
Integration indexes and launches games through Playnite and follows the games Playnite reports running. It owns ActiveMedia for Playnite launches, as the launcher has an external lifecycle.
func NewIntegration ¶
func NewIntegration(deps *Deps) *Integration
NewIntegration wires the integration; a nil clock and zero timeouts get real ones.
func (*Integration) Available ¶
func (i *Integration) Available(cfg *config.Instance) error
Available reports whether Playnite can be reached: either its extension is connected, which also covers a portable copy Core cannot find on disk, or an install exists for Core to start.
func (*Integration) Connected ¶
func (i *Integration) Connected() bool
Connected reports whether the Playnite extension is connected.
func (*Integration) GameRunning ¶
func (i *Integration) GameRunning() bool
GameRunning reports whether the extension has reported a game running and not yet stopped. It lets the platform refuse to report a stop it cannot confirm.
func (*Integration) Launch ¶
func (i *Integration) Launch(cfg *config.Instance, path string) error
Launch asks Playnite to start a game. With the extension connected the request goes over the pipe; otherwise Playnite itself is run with the game to start. Either way ActiveMedia is published only when the extension reports the game running.
func (*Integration) LibraryDetails ¶
func (i *Integration) LibraryDetails(ctx context.Context) ([]Game, error)
LibraryDetails reads the whole library with metadata and image paths.
func (*Integration) Locate ¶
func (i *Integration) Locate(cfg *config.Instance) (Install, error)
Locate resolves the install from config, registry and default paths.
func (*Integration) Preflight ¶
func (i *Integration) Preflight(path string) error
Preflight rejects a launch Playnite would refuse, before Core stops the media that is running. It can only ask a connected extension; without one the launch goes ahead and Playnite reports the problem itself.
func (*Integration) Scan ¶
func (i *Integration) Scan(ctx context.Context, cfg *config.Instance, systemID string) ([]platforms.ScanResult, error)
Scan returns the indexable games that belong to systemID. An absent install contributes nothing. An install whose extension is not connected cannot be read, which is reported as an unavailable source so the games already indexed are kept. An unavailable source leaves the whole system's scan incomplete, so that is only reported for systems Playnite games can belong to.
func (*Integration) Serve ¶
func (i *Integration) Serve(cfg *config.Instance, listener net.Listener)
Serve starts accepting the extension on listener, which the integration then owns. cfg is used for work the extension starts, such as tag writes.
func (*Integration) Stop ¶
func (i *Integration) Stop()
Stop closes the connection and forgets the game it followed.
func (*Integration) StopGame ¶
func (i *Integration) StopGame() error
StopGame asks the extension to end the running game and waits for it to confirm. It never clears ActiveMedia itself: the platform does that once the stop is confirmed.
type Locator ¶
Locator finds the Playnite folder. Registry, when set, resolves the folder the installer registered; Candidates are the default install locations tried last.
type Platform ¶
type Platform struct {
SpecificationID string `json:"SpecificationId,omitempty"`
Name string `json:"Name,omitempty"`
}
Platform is one of a game's Playnite platforms.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server talks to the Playnite extension over one connection at a time. The extension is the client: it reconnects whenever Playnite restarts, and a new connection replaces the previous one.
func (*Server) Check ¶
Check asks the extension whether Playnite would accept a launch of the game, without starting it. Only a refusal from the extension returns ErrGameRejected; a lost or silent connection returns another error, as it says nothing about the game.
func (*Server) Close ¶
func (s *Server) Close()
Close stops accepting, drops the connection and waits for the readers.
func (*Server) Games ¶
Games asks the extension for the whole library and waits for every chunk. With details set, each game carries its metadata and image paths.
func (*Server) Launch ¶
Launch asks the extension to start a game and waits for it to say whether Playnite accepted the request. The game starting is reported separately.
func (*Server) Serve ¶
Serve accepts extension connections on listener until Close. It takes ownership of the listener.
type Timeouts ¶
type Timeouts struct {
// Library is how long the extension may take to send the whole library.
Library time.Duration
// LaunchAccept is how long the extension may take to say whether
// Playnite accepted a launch. The game starting is reported separately.
LaunchAccept time.Duration
// Check is how long the extension may take to say whether Playnite
// would launch a game. A launch waits on it before stopping the running
// media, and goes ahead when it runs out.
Check time.Duration
// Stop is how long the extension may take to end a game. It has to fit
// inside the platform's stop budget with room for the fallback.
Stop time.Duration
// LibraryCache is how long a library snapshot serves later scans. An
// index asks once per system, and the answer is the same every time.
LibraryCache time.Duration
}
Timeouts bound every wait the integration performs.
func DefaultTimeouts ¶
func DefaultTimeouts() Timeouts
DefaultTimeouts returns the production waits.