Documentation
¶
Overview ¶
Package artwork reads a core's artwork index and decides which local artwork files to download. The index lists, per game ID, the images the artwork site serves: their type, the values that tell images of one type apart (disc number, region, variant), path relative to the index, size, and hashes. The index is used only when its signature file holds a valid signature by one of the core's artwork keys, and a downloaded image is kept only when its size and SHA-256 match the signed index. A game's images are stored in its own directory under names built from the entry's values, never from its path: <type>[_<disc>][_<region>][_<variant>].<ext>.
Index ¶
- Constants
- func BoxArtPath(dir, preferred string) string
- func Caption(f LocalFile) string
- func Download(baseURL, dir string, f File) error
- func DownloadTypes(setting string) []string
- func FileURL(baseURL, p string) (string, error)
- func Load(path string) (image.Image, error)
- func LocalName(f File) string
- func NeedsDownload(dir string, f File) bool
- func Size(path string) (width, height int, err error)
- func SupersededBoxArt(dir string) (path string, ok bool)
- func ValidPath(p string) bool
- func Verify(data []byte, f File) error
- type File
- type Index
- type LocalFile
Constants ¶
const IndexFile = "index.json"
IndexFile is the index's name, relative to the artwork base URL.
const IndexVersion = 1
IndexVersion is the index format this package reads.
const MaxImageDimension = 4096
MaxImageDimension is the largest width or height of an artwork image that is decoded.
const MaxImageSize = 10 * 1024 * 1024
MaxImageSize is the largest image accepted: 10 MiB.
const MaxIndexSize = 16 * 1024 * 1024
MaxIndexSize is the largest index accepted: 16 MiB.
const SignatureFile = "index.sig"
SignatureFile is the name of the index's signature file, relative to the artwork base URL. See the signing package for its format.
Variables ¶
This section is empty.
Functions ¶
func BoxArtPath ¶
BoxArtPath returns the path of the front cover shown for a game in its game directory dir: the first front in LocalFiles order for preferred, one of region.All. That is the preferred region's front, then the other regions' in regionRank order, then a front with no region, then the legacy boxart.png. When the game has no front, the boxart.webp path is returned.
func Caption ¶
Caption returns the on-screen name of a local image, such as "Front", "Disc 2 (USA)" or "Flyer B". A region other than USA, Japan and Europe is shown as "Other".
func Download ¶
Download fetches f from baseURL, checks it against the index entry, and writes it atomically to the game directory dir under LocalName. Nothing is written when the download fails or does not match.
func DownloadTypes ¶
DownloadTypes returns the image types a scan downloads for an artwork download setting (storage.ArtworkDownload*): every type this build knows, the front cover, the covers, or none. Any other value downloads every type.
func FileURL ¶
FileURL returns the URL of an index path under baseURL, which must be an absolute HTTPS URL with a host. The path's segments are escaped, so names with spaces are fetched correctly.
func Load ¶
Load decodes the artwork image file at path. The dimensions are read from the image header first and an image larger than MaxImageDimension on either side is refused before it is decoded, so the memory a file can take is bounded by the dimension limit, whatever the file size.
func LocalName ¶
LocalName returns the file name an image is stored under in its game's directory, built from the entry's values and its path's extension: <type>[_<disc>][_<region>][_<variant>].<ext>, such as "disc_2_eu.webp". Parse has checked the values, so the name is a plain file name.
func NeedsDownload ¶
NeedsDownload reports whether the game directory dir lacks f or holds a copy whose size or CRC-32 differs from the index.
func Size ¶
Size returns the width and height of the artwork image file at path, read from its header alone, so it is cheap enough to call before deciding on a layout. It returns an error for a file Load refuses on its dimensions.
func SupersededBoxArt ¶
SupersededBoxArt returns the legacy boxart.png in the game directory dir when boxart.webp is also there, the only artwork Clean Library removes. ok is false when either file is missing.
Types ¶
type File ¶
type File struct {
Type string `json:"type"`
Path string `json:"path"`
Disc int `json:"disc,omitempty"` // disc number, 1 and up
Region string `json:"region,omitempty"` // lower case letters, such as "us"
Variant string `json:"variant,omitempty"` // one lower case letter
Size int64 `json:"size"`
CRC32 string `json:"crc32"`
SHA256 string `json:"sha256"`
}
File is one image in the index. Disc, Region and Variant tell images of one type apart; each is set only on the types it applies to (see typeFields). Disc is set when the game has more than one disc, Region when the game was released in more than one region (even when only one region's image is available), and Variant when the game has more than one image of that type.
type Index ¶
Index is a parsed artwork index.
func FetchIndex ¶
FetchIndex downloads the index and its signature file under baseURL, checks that the signature file holds a valid signature of the index by one of keys, and only then parses the index. Without keys, or when the signature does not verify, no index is returned.
type LocalFile ¶
LocalFile is an artwork image in a game's directory, with the values its name carries
func LocalFiles ¶
LocalFiles returns the artwork images in the game directory dir whose names follow LocalName for a known type, in display order: the covers, then the discs, flyers and posters. Covers are grouped by region, each region's front before its back; discs are grouped by region, each in disc number order; flyers and posters are in variant order. Regions are ordered by regionRank with preferred, a storage.BoxArtRegion* setting, first. The legacy boxart.png is listed only when the game has no other front, after the other covers. When two files carry the same values, the .webp one is used. Other files are ignored. A missing or empty directory gives nil.