gamescan

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 14, 2026 License: AGPL-3.0 Imports: 24 Imported by: 0

Documentation

Overview

Package gamescan is what a scan of a games library finds (module API 5, scan.identify): the server walks the library's folders and sends WittyPlay every file; this decides which are games, for which console, and which files are one game (a sheet and its tracks, the discs of a set, copies of one file, versions of one game). See docs/GAMING.md in the server.

ROM files are only listed here, never opened beyond a look at their headers and at which files an archive, .cue or .m3u names. Archives are only read in a worker process.

Index

Constants

View Source
const DecryptedCopyPlays = "A copy you decrypted yourself, from a console you own, will play."

DecryptedCopyPlays is what a person with an encrypted game can do: nothing here decrypts one, or looks for keys, but a copy they decrypted themselves plays like any other game.

Variables

View Source
var ErrNotFound = errors.New("not found")

ErrNotFound: no such line on the review list, or no such game.

Functions

func CleanName

func CleanName(base string) (title, tags string)

CleanName splits a file's base name into the game's title and what else the name says, e.g. "Mega Game, The (USA) (Rev 1)" -> "The Mega Game", "USA, Rev 1".

func Decide

func Decide(ctx context.Context, db *sql.DB, library int64, p, action, console string) error

Decide records what a person said about a file, and the next scan goes by it. action is add (with a console), ignore, own (never put it under another version), or forget, which takes back whatever was said.

func DecideReviewed

func DecideReviewed(ctx context.Context, db *sql.DB, library, reviewID int64, action, console string) (string, error)

DecideReviewed records what a person said about a file on the review list, by its line. It returns the file's path.

func Entry

func Entry(ctx context.Context, db *sql.DB, library int64, p string) string

Entry says which file in a game's archive someone chose, or "".

func ForgetLibrary

func ForgetLibrary(ctx context.Context, db *sql.DB, library int64) error

ForgetLibrary drops everything kept about a library's files, once it's gone.

func ItemAt

func ItemAt(ctx context.Context, db *sql.DB, library int64, p string) int64

ItemAt is the server's id for the game at a path, or 0 when it isn't known.

func NameKey

func NameKey(name string) string

NameKey is what two names of the same game have in common.

func NoteItem

func NoteItem(ctx context.Context, db *sql.DB, library int64, p string, item int64) error

NoteItem remembers the server's id for a game's path, as the server says it (an item it sent).

func ParseGameName

func ParseGameName(base string) (title, note string)

ParseGameName splits a game's file name into its title and a short note made of its tags, e.g. "Mega Game, The (USA) (Rev 1)" -> "The Mega Game", "USA, Rev 1".

func PinEntry

func PinEntry(ctx context.Context, db *sql.DB, library int64, p, entry string) error

PinEntry says which file in a game's archive to play, or "" to choose by the rules.

func ProblemText

func ProblemText(problem, proof string) string

ProblemText says why a game can't play as it is, from what the scan found ("encrypted").

func RegionsChanged

func RegionsChanged(ctx context.Context, db *sql.DB, library int64) error

RegionsChanged makes the owner's new order of regions count at a library's next scan: an archive's file is worked out again, unless someone chose it, and so is which version leads a game.

func RereadAll

func RereadAll(ctx context.Context, db *sql.DB, library int64) error

RereadAll makes a library's next scan work out every file again from the start, as a full rescan asks: what's kept about each file is set aside (as an older version's would be) and replaced as each is judged again, so a full rescan that's stopped carries on from where it got to. What people said about files stays.

func ReviewCounts

func ReviewCounts(ctx context.Context, db *sql.DB, library int64) (map[string]int, error)

ReviewCounts says how many files of each kind a library's review list has.

func SearchTitle

func SearchTitle(title string) string

SearchTitle takes off what no database calls a game: which disc this is, and a product code left in the name. "Dashes-for-spaces" names become words.

func Serial

func Serial(ctx context.Context, db *sql.DB, library int64, p string) string

Serial is the product code a scan read in a game's file (or what else set it), or "".

func SetSerial

func SetSerial(ctx context.Context, db *sql.DB, library int64, p, serial string) error

SetSerial keeps a game's product code. An empty one changes nothing.

func SortTitle

func SortTitle(t string) string

SortTitle strips leading articles.

Types

type Detected

type Detected struct {
	How, Proof, Problem, ProblemText string
	Sure                             int
	Title, Serial, Name, Entry       string // what the file calls itself; the archive entry played
}

Detected is how a game's file was identified, as its metadata pages show it.

func Detection

func Detection(ctx context.Context, db *sql.DB, library int64, p string) (Detected, bool)

Detection is how the file at a path was identified, from the verdict the scan kept.

type GameDisc

type GameDisc struct {
	Disc int    `json:"disc"`
	Path string `json:"-"`
	Name string `json:"name"`
}

GameDisc is one disc of a game, as far as anyone asking needs to know.

type GameReview

type GameReview struct {
	Items  []GameReviewItem `json:"items"`
	Counts map[string]int   `json:"counts"`
	Total  int              `json:"total"`
}

GameReview is the review list, with how many of each kind there are.

func ReviewList

func ReviewList(ctx context.Context, db *sql.DB, library int64, roots []string, kind string, limit, offset int) (*GameReview, error)

ReviewList reads the list for a library, whose folders are roots. kind narrows it: "needs", "blocked" or "left" for everything left out.

type GameReviewItem

type GameReviewItem struct {
	ID int64 `json:"id"`
	// Path is relative to the library's folder, Name the file's own name.
	Path string `json:"path"`
	Name string `json:"name"`
	Size int64  `json:"size"`
	// Kind is needs (a person should look), blocked (it's listed, and can't play as it is),
	// or what it was left out as: bios, update, dlc, utility, audio, data, other, duplicate,
	// or ignored.
	Kind   string `json:"kind"`
	Reason string `json:"reason"`
	// Suggest lists consoles it might be, best first, each with a name to show.
	Suggest []GameSuggestion `json:"suggest"`
	// ItemID is the game this file is listed as, when it is.
	ItemID int64 `json:"itemId,omitempty"`
}

GameReviewItem is one line of the review list.

type GameSuggestion

type GameSuggestion struct {
	Console string `json:"console"`
	Name    string `json:"name"`
	Short   string `json:"short"`
}

GameSuggestion is a console a file might be for.

type Listed

type Listed struct {
	Library   int64
	Path      string
	VersionOf string     // the path of the game it's another version of, or ""
	Label     string     // which version it is, when it's under another
	Tagline   string     // what the scan made of its name: region, revision
	Discs     []GameDisc // only for a game on several discs
	Item      int64      // the server's id for it, once known
}

Listed is a game as the last scan answered it.

func ListedGame

func ListedGame(ctx context.Context, db *sql.DB, library int64, p string) (*Listed, error)

ListedGame is the game the last scan of a library answered at this path.

func ListedItem

func ListedItem(ctx context.Context, db *sql.DB, item int64) (*Listed, error)

ListedItem is the game the last scan answered that the server knows by this id.

func VersionsOf

func VersionsOf(ctx context.Context, db *sql.DB, library int64, head string) ([]Listed, error)

VersionsOf are the games the last scan put under head, by path.

type Scan

type Scan struct {
	ID      string
	Library wittymodule.ScanLibrary
	Started time.Time

	// Report, when set, is told how far the scan has got whenever that moves: the files of
	// a batch judged, of the scan's total, and then Finish's work, also counted in files. It's
	// called often, from the call's goroutine, and has to be quick (it's for the server's
	// progress and its watch for a stuck scan: see api/scan_progress.go).
	Report func(done, total int)
	// contains filtered or unexported fields
}

Scan is one scan of one library, from its first batch of files to its last call (Done).

func Begin

func Begin(db *sql.DB, id string, lib wittymodule.ScanLibrary) *Scan

Begin starts a scan of a library. db may be nil: nothing is remembered past the scan.

func (*Scan) Add

func (s *Scan) Add(ctx context.Context, files []wittymodule.ScanFile, total int) error

Add takes in a batch of files, in the order the walk found them. total is how many the walk found in all, when it says.

func (*Scan) Close

func (s *Scan) Close()

Close lets go of what the scan holds open (its archive reader).

func (*Scan) Finish

func (s *Scan) Finish(ctx context.Context, offline []string) (wittymodule.ScanIdentified, error)

Finish works out every game the library holds now, keeps what the scan learned, and answers the server. offline are folders that couldn't be read this time: what's known about their files stays.

func (*Scan) LastHeard

func (s *Scan) LastHeard() time.Time

LastHeard is when the server last sent this scan something.

func (*Scan) Progress

func (s *Scan) Progress() (done, total int, current string)

Progress says how far the scan has got: the files received, of how many, and the archive being read.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL